fix: errors now have the right prototype and name
This commit is contained in:
parent
e7dbe91374
commit
30f5d619c3
@ -5,6 +5,7 @@ import me.topchetoeu.jscript.engine.Environment;
|
|||||||
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
import me.topchetoeu.jscript.engine.values.Values;
|
import me.topchetoeu.jscript.engine.values.Values;
|
||||||
|
import me.topchetoeu.jscript.engine.values.ObjectValue.PlaceholderProto;
|
||||||
import me.topchetoeu.jscript.interop.InitType;
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.interop.NativeConstructor;
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
@ -50,8 +51,8 @@ import me.topchetoeu.jscript.interop.NativeInit;
|
|||||||
var target = new ObjectValue();
|
var target = new ObjectValue();
|
||||||
if (thisArg instanceof ObjectValue) target = (ObjectValue)thisArg;
|
if (thisArg instanceof ObjectValue) target = (ObjectValue)thisArg;
|
||||||
|
|
||||||
|
target.setPrototype(PlaceholderProto.ERROR);
|
||||||
target.defineProperty(ctx, "stack", ArrayValue.of(ctx, ctx.stackTrace()));
|
target.defineProperty(ctx, "stack", ArrayValue.of(ctx, ctx.stackTrace()));
|
||||||
target.defineProperty(ctx, "name", "Error");
|
|
||||||
if (message == null) target.defineProperty(ctx, "message", "");
|
if (message == null) target.defineProperty(ctx, "message", "");
|
||||||
else target.defineProperty(ctx, "message", Values.toString(ctx, message));
|
else target.defineProperty(ctx, "message", Values.toString(ctx, message));
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package me.topchetoeu.jscript.lib;
|
|||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
import me.topchetoeu.jscript.engine.Environment;
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
|
import me.topchetoeu.jscript.engine.values.ObjectValue.PlaceholderProto;
|
||||||
import me.topchetoeu.jscript.interop.InitType;
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.interop.NativeConstructor;
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
@ -11,6 +12,7 @@ import me.topchetoeu.jscript.interop.NativeInit;
|
|||||||
@Native("RangeError") public class RangeErrorLib extends ErrorLib {
|
@Native("RangeError") public class RangeErrorLib extends ErrorLib {
|
||||||
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) {
|
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) {
|
||||||
var target = ErrorLib.constructor(ctx, thisArg, message);
|
var target = ErrorLib.constructor(ctx, thisArg, message);
|
||||||
|
target.setPrototype(PlaceholderProto.SYNTAX_ERROR);
|
||||||
target.defineProperty(ctx, "name", "RangeError");
|
target.defineProperty(ctx, "name", "RangeError");
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package me.topchetoeu.jscript.lib;
|
|||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
import me.topchetoeu.jscript.engine.Environment;
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
|
import me.topchetoeu.jscript.engine.values.ObjectValue.PlaceholderProto;
|
||||||
import me.topchetoeu.jscript.interop.InitType;
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.interop.NativeConstructor;
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
@ -11,6 +12,7 @@ import me.topchetoeu.jscript.interop.NativeInit;
|
|||||||
@Native("SyntaxError") public class SyntaxErrorLib extends ErrorLib {
|
@Native("SyntaxError") public class SyntaxErrorLib extends ErrorLib {
|
||||||
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) {
|
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) {
|
||||||
var target = ErrorLib.constructor(ctx, thisArg, message);
|
var target = ErrorLib.constructor(ctx, thisArg, message);
|
||||||
|
target.setPrototype(PlaceholderProto.SYNTAX_ERROR);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
@ -3,6 +3,7 @@ package me.topchetoeu.jscript.lib;
|
|||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
import me.topchetoeu.jscript.engine.Environment;
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
|
import me.topchetoeu.jscript.engine.values.ObjectValue.PlaceholderProto;
|
||||||
import me.topchetoeu.jscript.interop.InitType;
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.interop.NativeConstructor;
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
@ -11,6 +12,7 @@ import me.topchetoeu.jscript.interop.NativeInit;
|
|||||||
@Native("TypeError") public class TypeErrorLib extends ErrorLib {
|
@Native("TypeError") public class TypeErrorLib extends ErrorLib {
|
||||||
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) {
|
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) {
|
||||||
var target = ErrorLib.constructor(ctx, thisArg, message);
|
var target = ErrorLib.constructor(ctx, thisArg, message);
|
||||||
|
target.setPrototype(PlaceholderProto.SYNTAX_ERROR);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
Loading…
Reference in New Issue
Block a user