From e9e020512ec16be3b980b827161ba3513f5ff971 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Sun, 24 Dec 2023 15:17:38 +0200 Subject: [PATCH] fix: environment pushed when it shouldn't be --- src/me/topchetoeu/jscript/engine/Context.java | 4 ++-- src/me/topchetoeu/jscript/engine/Environment.java | 4 ---- src/me/topchetoeu/jscript/engine/debug/SimpleDebugger.java | 2 +- src/me/topchetoeu/jscript/engine/values/Values.java | 2 +- src/me/topchetoeu/jscript/exceptions/EngineException.java | 2 +- src/me/topchetoeu/jscript/lib/AsyncFunctionLib.java | 1 - 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/me/topchetoeu/jscript/engine/Context.java b/src/me/topchetoeu/jscript/engine/Context.java index 3872541..5761c82 100644 --- a/src/me/topchetoeu/jscript/engine/Context.java +++ b/src/me/topchetoeu/jscript/engine/Context.java @@ -26,11 +26,11 @@ public class Context { return env.empty() ? null : env.peek(); } - public Context pushEnv(Environment env) { + private Context pushEnv(Environment env) { this.env.push(env); return this; } - public void popEnv() { + private void popEnv() { if (!env.empty()) this.env.pop(); } diff --git a/src/me/topchetoeu/jscript/engine/Environment.java b/src/me/topchetoeu/jscript/engine/Environment.java index da6a868..0eb322e 100644 --- a/src/me/topchetoeu/jscript/engine/Environment.java +++ b/src/me/topchetoeu/jscript/engine/Environment.java @@ -106,10 +106,6 @@ public class Environment implements PermissionsProvider { return permissions == null || permissions.hasPermission(perm); } - public Context context(Engine engine) { - return new Context(engine).pushEnv(this); - } - public static Symbol getSymbol(String name) { if (symbols.containsKey(name)) return symbols.get(name); else { diff --git a/src/me/topchetoeu/jscript/engine/debug/SimpleDebugger.java b/src/me/topchetoeu/jscript/engine/debug/SimpleDebugger.java index d2989b3..a21af73 100644 --- a/src/me/topchetoeu/jscript/engine/debug/SimpleDebugger.java +++ b/src/me/topchetoeu/jscript/engine/debug/SimpleDebugger.java @@ -482,7 +482,7 @@ public class SimpleDebugger implements Debugger { 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); engine.run(true); diff --git a/src/me/topchetoeu/jscript/engine/values/Values.java b/src/me/topchetoeu/jscript/engine/values/Values.java index 83646e6..d9031ee 100644 --- a/src/me/topchetoeu/jscript/engine/values/Values.java +++ b/src/me/topchetoeu/jscript/engine/values/Values.java @@ -741,7 +741,7 @@ public class Values { try { if (err instanceof EngineException) { 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) { System.out.println("Syntax error:" + ((SyntaxException)err).msg); diff --git a/src/me/topchetoeu/jscript/exceptions/EngineException.java b/src/me/topchetoeu/jscript/exceptions/EngineException.java index 8976ace..2639aab 100644 --- a/src/me/topchetoeu/jscript/exceptions/EngineException.java +++ b/src/me/topchetoeu/jscript/exceptions/EngineException.java @@ -37,7 +37,7 @@ public class EngineException extends RuntimeException { if (function.equals("")) function = 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.function = function; } diff --git a/src/me/topchetoeu/jscript/lib/AsyncFunctionLib.java b/src/me/topchetoeu/jscript/lib/AsyncFunctionLib.java index c352a20..385a9b4 100644 --- a/src/me/topchetoeu/jscript/lib/AsyncFunctionLib.java +++ b/src/me/topchetoeu/jscript/lib/AsyncFunctionLib.java @@ -21,7 +21,6 @@ import me.topchetoeu.jscript.interop.Native; private void next(Context ctx, Object inducedValue, Object inducedError) { Object res = null; ctx.pushFrame(frame); - ctx.pushEnv(frame.function.environment); awaiting = false; while (!awaiting) {