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