diff --git a/src/me/topchetoeu/jscript/engine/Context.java b/src/me/topchetoeu/jscript/engine/Context.java index fa46bbe..1f00eb2 100644 --- a/src/me/topchetoeu/jscript/engine/Context.java +++ b/src/me/topchetoeu/jscript/engine/Context.java @@ -18,7 +18,6 @@ import me.topchetoeu.jscript.parsing.Parsing; public class Context { private final Stack env = new Stack<>(); private final ArrayList frames = new ArrayList<>(); - public final Data data; public final Engine engine; public Environment environment() { @@ -101,7 +100,6 @@ public class Context { } public Context(Engine engine) { - this.data = new Data(); this.engine = engine; } public Context(Engine engine, Environment env) { diff --git a/src/me/topchetoeu/jscript/engine/Engine.java b/src/me/topchetoeu/jscript/engine/Engine.java index a48366f..a5c7dc6 100644 --- a/src/me/topchetoeu/jscript/engine/Engine.java +++ b/src/me/topchetoeu/jscript/engine/Engine.java @@ -81,20 +81,6 @@ public class Engine implements DebugController { return true; } - @Override public void onFramePop(Context ctx, CodeFrame frame) { - if (debugging && debugger != null) debugger.onFramePop(ctx, frame); - } - @Override public boolean onInstruction(Context ctx, CodeFrame frame, Instruction instruction, Object returnVal, EngineException error, boolean caught) { - if (debugging && debugger != null) return debugger.onInstruction(ctx, frame, instruction, returnVal, error, caught); - else return false; - } - @Override public void onSource(Filename filename, String source, TreeSet breakpoints) { - if (!debugging) return; - if (debugger != null) debugger.onSource(filename, source, breakpoints); - sources.put(filename, source); - bpts.put(filename, breakpoints); - } - private void runTask(Task task) { try { task.notifier.next(task.func.call(task.ctx, task.thisArg, task.args)); @@ -150,6 +136,20 @@ public class Engine implements DebugController { return pushMsg(micro, ctx, new UncompiledFunction(filename, raw), thisArg, args); } + @Override public void onFramePop(Context ctx, CodeFrame frame) { + if (debugging && debugger != null) debugger.onFramePop(ctx, frame); + } + @Override public boolean onInstruction(Context ctx, CodeFrame frame, Instruction instruction, Object returnVal, EngineException error, boolean caught) { + if (debugging && debugger != null) return debugger.onInstruction(ctx, frame, instruction, returnVal, error, caught); + else return false; + } + @Override public void onSource(Filename filename, String source, TreeSet breakpoints) { + if (!debugging) return; + if (debugger != null) debugger.onSource(filename, source, breakpoints); + sources.put(filename, source); + bpts.put(filename, breakpoints); + } + public Engine(boolean debugging) { this.debugging = debugging; } diff --git a/src/me/topchetoeu/jscript/interop/NativeWrapperProvider.java b/src/me/topchetoeu/jscript/interop/NativeWrapperProvider.java index a120171..11f7a61 100644 --- a/src/me/topchetoeu/jscript/interop/NativeWrapperProvider.java +++ b/src/me/topchetoeu/jscript/interop/NativeWrapperProvider.java @@ -117,6 +117,11 @@ public class NativeWrapperProvider implements WrappersProvider { public static ObjectValue makeProto(Environment ctx, Class clazz) { var res = new ObjectValue(); + var name = clazz.getName(); + var classNat = clazz.getAnnotation(Native.class); + if (classNat != null && !classNat.value().trim().equals("")) name = classNat.value().trim(); + res.defineProperty(null, ctx.symbol("Symbol.typeName"), name); + for (var overload : clazz.getDeclaredMethods()) { var init = overload.getAnnotation(NativeInit.class); if (init == null || init.value() != InitType.PROTOTYPE) continue; diff --git a/src/me/topchetoeu/jscript/lib/ArrayLib.java b/src/me/topchetoeu/jscript/lib/ArrayLib.java index 413e0c7..25756bc 100644 --- a/src/me/topchetoeu/jscript/lib/ArrayLib.java +++ b/src/me/topchetoeu/jscript/lib/ArrayLib.java @@ -4,16 +4,13 @@ import java.util.Iterator; import java.util.Stack; import me.topchetoeu.jscript.engine.Context; -import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.engine.values.FunctionValue; import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.engine.values.Values; -import me.topchetoeu.jscript.interop.InitType; import me.topchetoeu.jscript.interop.Native; import me.topchetoeu.jscript.interop.NativeConstructor; import me.topchetoeu.jscript.interop.NativeGetter; -import me.topchetoeu.jscript.interop.NativeInit; import me.topchetoeu.jscript.interop.NativeSetter; @Native("Array") public class ArrayLib { @@ -369,8 +366,4 @@ import me.topchetoeu.jscript.interop.NativeSetter; return res; } - - @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "Array"); - } } diff --git a/src/me/topchetoeu/jscript/lib/BooleanLib.java b/src/me/topchetoeu/jscript/lib/BooleanLib.java index e9c2a3f..2ac5e0d 100644 --- a/src/me/topchetoeu/jscript/lib/BooleanLib.java +++ b/src/me/topchetoeu/jscript/lib/BooleanLib.java @@ -1,13 +1,10 @@ package me.topchetoeu.jscript.lib; import me.topchetoeu.jscript.engine.Context; -import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.engine.values.Values; -import me.topchetoeu.jscript.interop.InitType; import me.topchetoeu.jscript.interop.Native; import me.topchetoeu.jscript.interop.NativeConstructor; -import me.topchetoeu.jscript.interop.NativeInit; @Native("Boolean") public class BooleanLib { public static final BooleanLib TRUE = new BooleanLib(true); @@ -30,7 +27,4 @@ import me.topchetoeu.jscript.interop.NativeInit; public BooleanLib(boolean val) { this.value = val; } - @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "Boolean"); - } } diff --git a/src/me/topchetoeu/jscript/lib/ErrorLib.java b/src/me/topchetoeu/jscript/lib/ErrorLib.java index 6952e97..aeefa63 100644 --- a/src/me/topchetoeu/jscript/lib/ErrorLib.java +++ b/src/me/topchetoeu/jscript/lib/ErrorLib.java @@ -59,7 +59,6 @@ import me.topchetoeu.jscript.interop.NativeInit; } @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "Error"); target.defineProperty(null, "name", "Error"); } } diff --git a/src/me/topchetoeu/jscript/lib/FunctionLib.java b/src/me/topchetoeu/jscript/lib/FunctionLib.java index 51581a0..ffa2ff7 100644 --- a/src/me/topchetoeu/jscript/lib/FunctionLib.java +++ b/src/me/topchetoeu/jscript/lib/FunctionLib.java @@ -2,16 +2,12 @@ package me.topchetoeu.jscript.lib; import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.engine.Context; -import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.engine.values.CodeFunction; import me.topchetoeu.jscript.engine.values.FunctionValue; import me.topchetoeu.jscript.engine.values.NativeFunction; -import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.exceptions.EngineException; -import me.topchetoeu.jscript.interop.InitType; import me.topchetoeu.jscript.interop.Native; -import me.topchetoeu.jscript.interop.NativeInit; @Native("Function") public class FunctionLib { @Native(thisArg = true) public static Object location(Context ctx, FunctionValue func) { @@ -55,8 +51,4 @@ import me.topchetoeu.jscript.interop.NativeInit; @Native public static FunctionValue generator(FunctionValue func) { return new GeneratorFunctionLib(func); } - - @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "Function"); - } } diff --git a/src/me/topchetoeu/jscript/lib/NumberLib.java b/src/me/topchetoeu/jscript/lib/NumberLib.java index 29e280a..53998e5 100644 --- a/src/me/topchetoeu/jscript/lib/NumberLib.java +++ b/src/me/topchetoeu/jscript/lib/NumberLib.java @@ -1,13 +1,10 @@ package me.topchetoeu.jscript.lib; import me.topchetoeu.jscript.engine.Context; -import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.engine.values.Values; -import me.topchetoeu.jscript.interop.InitType; import me.topchetoeu.jscript.interop.Native; import me.topchetoeu.jscript.interop.NativeConstructor; -import me.topchetoeu.jscript.interop.NativeInit; @Native("Number") public class NumberLib { @Native public static final double EPSILON = java.lang.Math.ulp(1.0); @@ -52,8 +49,4 @@ import me.topchetoeu.jscript.interop.NativeInit; public NumberLib(double val) { this.value = val; } - - @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "Number"); - } } diff --git a/src/me/topchetoeu/jscript/lib/ObjectLib.java b/src/me/topchetoeu/jscript/lib/ObjectLib.java index 165bee5..30bd47b 100644 --- a/src/me/topchetoeu/jscript/lib/ObjectLib.java +++ b/src/me/topchetoeu/jscript/lib/ObjectLib.java @@ -1,17 +1,14 @@ package me.topchetoeu.jscript.lib; import me.topchetoeu.jscript.engine.Context; -import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.engine.values.FunctionValue; import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.engine.values.Symbol; import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.exceptions.EngineException; -import me.topchetoeu.jscript.interop.InitType; import me.topchetoeu.jscript.interop.Native; import me.topchetoeu.jscript.interop.NativeConstructor; -import me.topchetoeu.jscript.interop.NativeInit; @Native("Object") public class ObjectLib { @Native public static ObjectValue assign(Context ctx, ObjectValue dst, Object... src) { @@ -212,8 +209,4 @@ import me.topchetoeu.jscript.interop.NativeInit; // else if (arg instanceof Symbol) return SymbolPolyfill.constructor(ctx, thisArg, arg); else return arg; } - - @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "Object"); - } } diff --git a/src/me/topchetoeu/jscript/lib/PromiseLib.java b/src/me/topchetoeu/jscript/lib/PromiseLib.java index 769fa80..f01cb01 100644 --- a/src/me/topchetoeu/jscript/lib/PromiseLib.java +++ b/src/me/topchetoeu/jscript/lib/PromiseLib.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Map; import me.topchetoeu.jscript.engine.Context; -import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.engine.values.FunctionValue; import me.topchetoeu.jscript.engine.values.NativeFunction; @@ -14,9 +13,7 @@ import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.exceptions.InterruptException; -import me.topchetoeu.jscript.interop.InitType; import me.topchetoeu.jscript.interop.Native; -import me.topchetoeu.jscript.interop.NativeInit; @Native("Promise") public class PromiseLib { private static class Handle { @@ -352,8 +349,4 @@ import me.topchetoeu.jscript.interop.NativeInit; public PromiseLib() { this(STATE_PENDING, null); } - - @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "Promise"); - } } diff --git a/src/me/topchetoeu/jscript/lib/RangeErrorLib.java b/src/me/topchetoeu/jscript/lib/RangeErrorLib.java index 9e24482..540fec3 100644 --- a/src/me/topchetoeu/jscript/lib/RangeErrorLib.java +++ b/src/me/topchetoeu/jscript/lib/RangeErrorLib.java @@ -15,7 +15,6 @@ import me.topchetoeu.jscript.interop.NativeInit; return target; } @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "RangeError"); target.defineProperty(null, "name", "RangeError"); } } \ No newline at end of file diff --git a/src/me/topchetoeu/jscript/lib/StringLib.java b/src/me/topchetoeu/jscript/lib/StringLib.java index 5e5df1f..eaee54b 100644 --- a/src/me/topchetoeu/jscript/lib/StringLib.java +++ b/src/me/topchetoeu/jscript/lib/StringLib.java @@ -3,17 +3,14 @@ package me.topchetoeu.jscript.lib; import java.util.regex.Pattern; import me.topchetoeu.jscript.engine.Context; -import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.engine.values.FunctionValue; import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.exceptions.EngineException; -import me.topchetoeu.jscript.interop.InitType; import me.topchetoeu.jscript.interop.Native; import me.topchetoeu.jscript.interop.NativeConstructor; import me.topchetoeu.jscript.interop.NativeGetter; -import me.topchetoeu.jscript.interop.NativeInit; // TODO: implement index wrapping properly @Native("String") public class StringLib { @@ -263,8 +260,4 @@ import me.topchetoeu.jscript.interop.NativeInit; public StringLib(String val) { this.value = val; } - - @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "String"); - } } diff --git a/src/me/topchetoeu/jscript/lib/SymbolLib.java b/src/me/topchetoeu/jscript/lib/SymbolLib.java index 03fed13..f8bb132 100644 --- a/src/me/topchetoeu/jscript/lib/SymbolLib.java +++ b/src/me/topchetoeu/jscript/lib/SymbolLib.java @@ -4,16 +4,13 @@ import java.util.HashMap; import java.util.Map; import me.topchetoeu.jscript.engine.Context; -import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.engine.values.Symbol; import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.exceptions.EngineException; -import me.topchetoeu.jscript.interop.InitType; import me.topchetoeu.jscript.interop.Native; import me.topchetoeu.jscript.interop.NativeConstructor; import me.topchetoeu.jscript.interop.NativeGetter; -import me.topchetoeu.jscript.interop.NativeInit; @Native("Symbol") public class SymbolLib { private static final Map symbols = new HashMap<>(); @@ -63,8 +60,4 @@ import me.topchetoeu.jscript.interop.NativeInit; public SymbolLib(Symbol val) { this.value = val; } - - @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "Symbol"); - } } diff --git a/src/me/topchetoeu/jscript/lib/SyntaxErrorLib.java b/src/me/topchetoeu/jscript/lib/SyntaxErrorLib.java index 7c2a1ef..2d8df7f 100644 --- a/src/me/topchetoeu/jscript/lib/SyntaxErrorLib.java +++ b/src/me/topchetoeu/jscript/lib/SyntaxErrorLib.java @@ -11,11 +11,9 @@ import me.topchetoeu.jscript.interop.NativeInit; @Native("SyntaxError") public class SyntaxErrorLib extends ErrorLib { @NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) { var target = ErrorLib.constructor(ctx, thisArg, message); - target.defineProperty(ctx, "name", "SyntaxError"); return target; } @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "SyntaxError"); target.defineProperty(null, "name", "SyntaxError"); } } \ No newline at end of file diff --git a/src/me/topchetoeu/jscript/lib/TypeErrorLib.java b/src/me/topchetoeu/jscript/lib/TypeErrorLib.java index 27298cd..906b096 100644 --- a/src/me/topchetoeu/jscript/lib/TypeErrorLib.java +++ b/src/me/topchetoeu/jscript/lib/TypeErrorLib.java @@ -11,11 +11,9 @@ import me.topchetoeu.jscript.interop.NativeInit; @Native("TypeError") public class TypeErrorLib extends ErrorLib { @NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) { var target = ErrorLib.constructor(ctx, thisArg, message); - target.defineProperty(ctx, "name", "TypeError"); return target; } @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { - target.defineProperty(null, env.symbol("Symbol.typeName"), "TypeError"); target.defineProperty(null, "name", "TypeError"); } } \ No newline at end of file