From a8775d212fd72f146790269cbfd6024f6298ea25 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:52:29 +0300 Subject: [PATCH] fix: clean up extensions at some points --- .../topchetoeu/jscript/runtime/Context.java | 21 ++----------------- .../jscript/runtime/values/CodeFunction.java | 2 +- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/java/me/topchetoeu/jscript/runtime/Context.java b/src/java/me/topchetoeu/jscript/runtime/Context.java index 950f068..8f51cf5 100644 --- a/src/java/me/topchetoeu/jscript/runtime/Context.java +++ b/src/java/me/topchetoeu/jscript/runtime/Context.java @@ -14,43 +14,26 @@ public class Context implements Extensions { public final Context parent; public final Extensions extensions; public final Frame frame; - // public final Engine engine; public final int stackSize; @Override public void add(Key key, T obj) { if (extensions != null) extensions.add(key, obj); - // else if (engine != null) engine.add(key, obj); } @Override public T get(Key key) { if (extensions != null && extensions.has(key)) return extensions.get(key); - // else if (engine != null && engine.has(key)) return engine.get(key); return null; } @Override public boolean has(Key key) { - return - extensions != null && extensions.has(key); - // engine != null && engine.has(key); + return extensions != null && extensions.has(key); } @Override public boolean remove(Key key) { var res = false; - if (extensions != null) res |= extensions.remove(key); - // else if (engine != null) res |= engine.remove(key); - return res; } @Override public Iterable> keys() { if (extensions == null) return List.of(); else return extensions.keys(); - - // if (engine == null && environment == null) return List.of(); - // if (engine == null) return environment.keys(); - // if (environment == null) return engine.keys(); - - // return () -> Stream.concat( - // StreamSupport.stream(engine.keys().spliterator(), false), - // StreamSupport.stream(environment.keys().spliterator(), false) - // ).distinct().iterator(); } public FunctionValue compile(Filename filename, String raw) { @@ -101,7 +84,7 @@ public class Context implements Extensions { this(null, null, null, 0); } public Context(Extensions ext) { - this(null, ext, null, 0); + this(null, clean(ext), null, 0); } public static Context of(Extensions ext) { diff --git a/src/java/me/topchetoeu/jscript/runtime/values/CodeFunction.java b/src/java/me/topchetoeu/jscript/runtime/values/CodeFunction.java index 607376b..2d0df77 100644 --- a/src/java/me/topchetoeu/jscript/runtime/values/CodeFunction.java +++ b/src/java/me/topchetoeu/jscript/runtime/values/CodeFunction.java @@ -44,7 +44,7 @@ public class CodeFunction extends FunctionValue { public CodeFunction(Extensions extensions, String name, FunctionBody body, ValueVariable[] captures) { super(name, body.argsN); this.captures = captures; - this.extensions = extensions; + this.extensions = Context.clean(extensions); this.body = body; } }