fix: don't use Context.NULL in global scope

This commit is contained in:
TopchetoEU 2024-03-05 16:51:50 +02:00
parent 662dcc1ac1
commit ccf75d6066
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
3 changed files with 6 additions and 6 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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);
}