From ccf75d60664ed238212851fb468c0327a9ae1cde Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:51:50 +0200 Subject: [PATCH] fix: don't use Context.NULL in global scope --- gradle.properties | 2 +- .../me/topchetoeu/jscript/core/scope/GlobalScope.java | 8 ++++---- .../me/topchetoeu/jscript/core/values/NativeWrapper.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 30804f7..003a423 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ project_group = me.topchetoeu project_name = jscript -project_version = 0.9.4-beta +project_version = 0.9.5-beta main_class = me.topchetoeu.jscript.utils.JScriptRepl diff --git a/src/java/me/topchetoeu/jscript/core/scope/GlobalScope.java b/src/java/me/topchetoeu/jscript/core/scope/GlobalScope.java index 8667ecc..83c3c66 100644 --- a/src/java/me/topchetoeu/jscript/core/scope/GlobalScope.java +++ b/src/java/me/topchetoeu/jscript/core/scope/GlobalScope.java @@ -24,12 +24,12 @@ public class GlobalScope { } public Object define(Context ctx, String name) { - if (Values.hasMember(Context.NULL, obj, name, false)) return name; - obj.defineProperty(Context.NULL, name, null); + if (Values.hasMember(ctx, obj, name, false)) return name; + obj.defineProperty(ctx, name, null); return name; } public void define(Context ctx, String name, Variable val) { - obj.defineProperty(Context.NULL, name, + obj.defineProperty(ctx, name, new NativeFunction("get " + name, args -> val.get(args.ctx)), new NativeFunction("set " + name, args -> { val.set(args.ctx, args.get(0)); return null; }), true, true @@ -42,7 +42,7 @@ public class GlobalScope { for (var n : names) define(ctx, n); } public void define(Context ctx, boolean readonly, FunctionValue val) { - define(null, val.name, readonly, val); + define(ctx, val.name, readonly, val); } public Object get(Context ctx, String name) { diff --git a/src/java/me/topchetoeu/jscript/core/values/NativeWrapper.java b/src/java/me/topchetoeu/jscript/core/values/NativeWrapper.java index cb7b6e3..ecf985a 100644 --- a/src/java/me/topchetoeu/jscript/core/values/NativeWrapper.java +++ b/src/java/me/topchetoeu/jscript/core/values/NativeWrapper.java @@ -8,7 +8,7 @@ public class NativeWrapper extends ObjectValue { @Override public ObjectValue getPrototype(Context ctx) { - if (prototype == NATIVE_PROTO) return ctx.environment.wrappers.getProto(wrapped.getClass()); + if (ctx.environment != null && prototype == NATIVE_PROTO) return ctx.environment.wrappers.getProto(wrapped.getClass()); else return super.getPrototype(ctx); }