fix: environment pushed when it shouldn't be

This commit is contained in:
TopchetoEU 2023-12-24 15:17:38 +02:00
parent 4b0bbf5190
commit e9e020512e
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
6 changed files with 5 additions and 10 deletions

View File

@ -26,11 +26,11 @@ public class Context {
return env.empty() ? null : env.peek(); return env.empty() ? null : env.peek();
} }
public Context pushEnv(Environment env) { private Context pushEnv(Environment env) {
this.env.push(env); this.env.push(env);
return this; return this;
} }
public void popEnv() { private void popEnv() {
if (!env.empty()) this.env.pop(); if (!env.empty()) this.env.pop();
} }

View File

@ -106,10 +106,6 @@ public class Environment implements PermissionsProvider {
return permissions == null || permissions.hasPermission(perm); return permissions == null || permissions.hasPermission(perm);
} }
public Context context(Engine engine) {
return new Context(engine).pushEnv(this);
}
public static Symbol getSymbol(String name) { public static Symbol getSymbol(String name) {
if (symbols.containsKey(name)) return symbols.get(name); if (symbols.containsKey(name)) return symbols.get(name);
else { else {

View File

@ -482,7 +482,7 @@ public class SimpleDebugger implements Debugger {
env.global = new GlobalScope(codeFrame.local); env.global = new GlobalScope(codeFrame.local);
var ctx = new Context(engine).pushEnv(env); var ctx = new Context(engine, env);
var awaiter = engine.pushMsg(false, ctx.environment(), new Filename("jscript", "eval"), code, codeFrame.frame.thisArg, codeFrame.frame.args); var awaiter = engine.pushMsg(false, ctx.environment(), new Filename("jscript", "eval"), code, codeFrame.frame.thisArg, codeFrame.frame.args);
engine.run(true); engine.run(true);

View File

@ -741,7 +741,7 @@ public class Values {
try { try {
if (err instanceof EngineException) { if (err instanceof EngineException) {
var ee = ((EngineException)err); var ee = ((EngineException)err);
System.out.println(prefix + " " + ee.toString(new Context(ee.engine).pushEnv(ee.env))); System.out.println(prefix + " " + ee.toString(new Context(ee.engine, ee.env)));
} }
else if (err instanceof SyntaxException) { else if (err instanceof SyntaxException) {
System.out.println("Syntax error:" + ((SyntaxException)err).msg); System.out.println("Syntax error:" + ((SyntaxException)err).msg);

View File

@ -37,7 +37,7 @@ public class EngineException extends RuntimeException {
if (function.equals("")) function = null; if (function.equals("")) function = null;
if (ctx == null) this.ctx = null; if (ctx == null) this.ctx = null;
else this.ctx = new Context(ctx.engine).pushEnv(ctx.environment()); else this.ctx = new Context(ctx.engine, ctx.environment());
this.location = location; this.location = location;
this.function = function; this.function = function;
} }

View File

@ -21,7 +21,6 @@ import me.topchetoeu.jscript.interop.Native;
private void next(Context ctx, Object inducedValue, Object inducedError) { private void next(Context ctx, Object inducedValue, Object inducedError) {
Object res = null; Object res = null;
ctx.pushFrame(frame); ctx.pushFrame(frame);
ctx.pushEnv(frame.function.environment);
awaiting = false; awaiting = false;
while (!awaiting) { while (!awaiting) {