fix: access env via context
This commit is contained in:
parent
38acc20a6f
commit
802f2f3f52
@ -1,21 +1,14 @@
|
||||
package me.topchetoeu.jscript.engine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import me.topchetoeu.jscript.Filename;
|
||||
import me.topchetoeu.jscript.Location;
|
||||
import me.topchetoeu.jscript.compilation.FunctionBody;
|
||||
import me.topchetoeu.jscript.compilation.Instruction;
|
||||
import me.topchetoeu.jscript.engine.debug.DebugController;
|
||||
import me.topchetoeu.jscript.engine.frame.CodeFrame;
|
||||
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
||||
import me.topchetoeu.jscript.events.Awaitable;
|
||||
import me.topchetoeu.jscript.events.DataNotifier;
|
||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||
import me.topchetoeu.jscript.exceptions.InterruptException;
|
||||
import me.topchetoeu.jscript.mapping.SourceMap;
|
||||
|
||||
public class Engine {
|
||||
private class UncompiledFunction extends FunctionValue {
|
||||
|
@ -342,7 +342,7 @@ public class SimpleDebugger implements Debugger {
|
||||
try {
|
||||
defaultToString =
|
||||
Values.getMember(ctx, obj, "toString") ==
|
||||
Values.getMember(ctx, ctx.environment().get(Environment.OBJECT_PROTO), "toString");
|
||||
Values.getMember(ctx, ctx.get(Environment.OBJECT_PROTO), "toString");
|
||||
}
|
||||
catch (Exception e) { }
|
||||
|
||||
|
@ -198,9 +198,8 @@ public class Runners {
|
||||
return execLoadMember(ctx, instr, frame);
|
||||
}
|
||||
public static Object execLoadRegEx(Context ctx, Instruction instr, CodeFrame frame) {
|
||||
var env = ctx.environment();
|
||||
if (env.has(Environment.REGEX_CONSTR)) {
|
||||
frame.push(ctx, Values.callNew(ctx, env.get(Environment.REGEX_CONSTR)));
|
||||
if (ctx.has(Environment.REGEX_CONSTR)) {
|
||||
frame.push(ctx, Values.callNew(ctx, ctx.get(Environment.REGEX_CONSTR)));
|
||||
}
|
||||
else {
|
||||
throw EngineException.ofSyntax("Regex is not supported.");
|
||||
|
@ -147,13 +147,13 @@ public class ObjectValue {
|
||||
|
||||
public ObjectValue getPrototype(Context ctx) {
|
||||
try {
|
||||
if (prototype == OBJ_PROTO) return ctx.environment().get(Environment.OBJECT_PROTO);
|
||||
if (prototype == ARR_PROTO) return ctx.environment().get(Environment.ARRAY_PROTO);
|
||||
if (prototype == FUNC_PROTO) return ctx.environment().get(Environment.FUNCTION_PROTO);
|
||||
if (prototype == ERR_PROTO) return ctx.environment().get(Environment.ERROR_PROTO);
|
||||
if (prototype == RANGE_ERR_PROTO) return ctx.environment().get(Environment.RANGE_ERR_PROTO);
|
||||
if (prototype == SYNTAX_ERR_PROTO) return ctx.environment().get(Environment.SYNTAX_ERR_PROTO);
|
||||
if (prototype == TYPE_ERR_PROTO) return ctx.environment().get(Environment.TYPE_ERR_PROTO);
|
||||
if (prototype == OBJ_PROTO) return ctx.get(Environment.OBJECT_PROTO);
|
||||
if (prototype == ARR_PROTO) return ctx.get(Environment.ARRAY_PROTO);
|
||||
if (prototype == FUNC_PROTO) return ctx.get(Environment.FUNCTION_PROTO);
|
||||
if (prototype == ERR_PROTO) return ctx.get(Environment.ERROR_PROTO);
|
||||
if (prototype == RANGE_ERR_PROTO) return ctx.get(Environment.RANGE_ERR_PROTO);
|
||||
if (prototype == SYNTAX_ERR_PROTO) return ctx.get(Environment.SYNTAX_ERR_PROTO);
|
||||
if (prototype == TYPE_ERR_PROTO) return ctx.get(Environment.TYPE_ERR_PROTO);
|
||||
}
|
||||
catch (NullPointerException e) { return null; }
|
||||
|
||||
@ -170,14 +170,14 @@ public class ObjectValue {
|
||||
else if (Values.isObject(val)) {
|
||||
var obj = Values.object(val);
|
||||
|
||||
if (ctx != null && ctx.environment() != null) {
|
||||
if (obj == ctx.environment().get(Environment.OBJECT_PROTO)) prototype = OBJ_PROTO;
|
||||
else if (obj == ctx.environment().get(Environment.ARRAY_PROTO)) prototype = ARR_PROTO;
|
||||
else if (obj == ctx.environment().get(Environment.FUNCTION_PROTO)) prototype = FUNC_PROTO;
|
||||
else if (obj == ctx.environment().get(Environment.ERROR_PROTO)) prototype = ERR_PROTO;
|
||||
else if (obj == ctx.environment().get(Environment.SYNTAX_ERR_PROTO)) prototype = SYNTAX_ERR_PROTO;
|
||||
else if (obj == ctx.environment().get(Environment.TYPE_ERR_PROTO)) prototype = TYPE_ERR_PROTO;
|
||||
else if (obj == ctx.environment().get(Environment.RANGE_ERR_PROTO)) prototype = RANGE_ERR_PROTO;
|
||||
if (ctx != null) {
|
||||
if (obj == ctx.get(Environment.OBJECT_PROTO)) prototype = OBJ_PROTO;
|
||||
else if (obj == ctx.get(Environment.ARRAY_PROTO)) prototype = ARR_PROTO;
|
||||
else if (obj == ctx.get(Environment.FUNCTION_PROTO)) prototype = FUNC_PROTO;
|
||||
else if (obj == ctx.get(Environment.ERROR_PROTO)) prototype = ERR_PROTO;
|
||||
else if (obj == ctx.get(Environment.SYNTAX_ERR_PROTO)) prototype = SYNTAX_ERR_PROTO;
|
||||
else if (obj == ctx.get(Environment.TYPE_ERR_PROTO)) prototype = TYPE_ERR_PROTO;
|
||||
else if (obj == ctx.get(Environment.RANGE_ERR_PROTO)) prototype = RANGE_ERR_PROTO;
|
||||
else prototype = obj;
|
||||
}
|
||||
else prototype = obj;
|
||||
|
@ -347,10 +347,10 @@ public class Values {
|
||||
if (isObject(obj)) return object(obj).getPrototype(ctx);
|
||||
if (ctx == null) return null;
|
||||
|
||||
if (obj instanceof String) return ctx.environment().get(Environment.STRING_PROTO);
|
||||
else if (obj instanceof Number) return ctx.environment().get(Environment.NUMBER_PROTO);
|
||||
else if (obj instanceof Boolean) return ctx.environment().get(Environment.BOOL_PROTO);
|
||||
else if (obj instanceof Symbol) return ctx.environment().get(Environment.SYMBOL_PROTO);
|
||||
if (obj instanceof String) return ctx.get(Environment.STRING_PROTO);
|
||||
else if (obj instanceof Number) return ctx.get(Environment.NUMBER_PROTO);
|
||||
else if (obj instanceof Boolean) return ctx.get(Environment.BOOL_PROTO);
|
||||
else if (obj instanceof Symbol) return ctx.get(Environment.SYMBOL_PROTO);
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -605,7 +605,7 @@ public class Values {
|
||||
var res = new ObjectValue();
|
||||
|
||||
try {
|
||||
var key = getMember(ctx, getMember(ctx, ctx.environment().get(Environment.SYMBOL_PROTO), "constructor"), "iterator");
|
||||
var key = getMember(ctx, getMember(ctx, ctx.get(Environment.SYMBOL_PROTO), "constructor"), "iterator");
|
||||
res.defineProperty(ctx, key, new NativeFunction("", (_ctx, thisArg, args) -> thisArg));
|
||||
}
|
||||
catch (IllegalArgumentException | NullPointerException e) { }
|
||||
@ -630,7 +630,7 @@ public class Values {
|
||||
var res = new ObjectValue();
|
||||
|
||||
try {
|
||||
var key = getMemberPath(ctx, ctx.environment().get(Environment.SYMBOL_PROTO), "constructor", "asyncIterator");
|
||||
var key = getMemberPath(ctx, ctx.get(Environment.SYMBOL_PROTO), "constructor", "asyncIterator");
|
||||
res.defineProperty(ctx, key, new NativeFunction("", (_ctx, thisArg, args) -> thisArg));
|
||||
}
|
||||
catch (IllegalArgumentException | NullPointerException e) { }
|
||||
|
@ -19,7 +19,7 @@ public class EngineException extends RuntimeException {
|
||||
public final Context ctx;
|
||||
|
||||
public boolean visible() {
|
||||
return ctx == null || ctx.environment() == null || !ctx.environment().get(Environment.HIDE_STACK, false);
|
||||
return ctx == null || !ctx.get(Environment.HIDE_STACK, false);
|
||||
}
|
||||
public String toString() {
|
||||
var res = "";
|
||||
|
@ -140,8 +140,8 @@ import me.topchetoeu.jscript.interop.NativeGetter;
|
||||
try {
|
||||
var _match = Values.getMember(ctx, term, Symbol.get("Symbol.match"));
|
||||
if (_match instanceof FunctionValue) match = (FunctionValue)_match;
|
||||
else if (ctx.environment().has(Environment.REGEX_CONSTR)) {
|
||||
var regex = Values.callNew(ctx, ctx.environment().get(Environment.REGEX_CONSTR), Values.toString(ctx, term), "");
|
||||
else if (ctx.has(Environment.REGEX_CONSTR)) {
|
||||
var regex = Values.callNew(ctx, ctx.get(Environment.REGEX_CONSTR), Values.toString(ctx, term), "");
|
||||
_match = Values.getMember(ctx, regex, Symbol.get("Symbol.match"));
|
||||
if (_match instanceof FunctionValue) match = (FunctionValue)_match;
|
||||
else throw EngineException.ofError("Regular expressions don't support matching.");
|
||||
@ -165,8 +165,8 @@ import me.topchetoeu.jscript.interop.NativeGetter;
|
||||
}
|
||||
catch (IllegalArgumentException e) { }
|
||||
|
||||
if (match == null && ctx.environment().has(Environment.REGEX_CONSTR)) {
|
||||
var regex = Values.callNew(ctx, ctx.environment().get(Environment.REGEX_CONSTR), Values.toString(ctx, term), "g");
|
||||
if (match == null && ctx.has(Environment.REGEX_CONSTR)) {
|
||||
var regex = Values.callNew(ctx, ctx.get(Environment.REGEX_CONSTR), Values.toString(ctx, term), "g");
|
||||
var _match = Values.getMember(ctx, regex, Symbol.get("Symbol.matchAll"));
|
||||
if (_match instanceof FunctionValue) match = (FunctionValue)_match;
|
||||
else throw EngineException.ofError("Regular expressions don't support matching.");
|
||||
|
Loading…
Reference in New Issue
Block a user