From 30f5d619c39e725b7ee56220ea8cc000c1f90251 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Tue, 14 Nov 2023 09:22:56 +0200 Subject: [PATCH] fix: errors now have the right prototype and name --- src/me/topchetoeu/jscript/lib/ErrorLib.java | 3 ++- src/me/topchetoeu/jscript/lib/RangeErrorLib.java | 2 ++ src/me/topchetoeu/jscript/lib/SyntaxErrorLib.java | 2 ++ src/me/topchetoeu/jscript/lib/TypeErrorLib.java | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/me/topchetoeu/jscript/lib/ErrorLib.java b/src/me/topchetoeu/jscript/lib/ErrorLib.java index aeefa63..c681ed4 100644 --- a/src/me/topchetoeu/jscript/lib/ErrorLib.java +++ b/src/me/topchetoeu/jscript/lib/ErrorLib.java @@ -5,6 +5,7 @@ import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.engine.values.ObjectValue; 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.Native; import me.topchetoeu.jscript.interop.NativeConstructor; @@ -50,8 +51,8 @@ import me.topchetoeu.jscript.interop.NativeInit; var target = new ObjectValue(); if (thisArg instanceof ObjectValue) target = (ObjectValue)thisArg; + target.setPrototype(PlaceholderProto.ERROR); target.defineProperty(ctx, "stack", ArrayValue.of(ctx, ctx.stackTrace())); - target.defineProperty(ctx, "name", "Error"); if (message == null) target.defineProperty(ctx, "message", ""); else target.defineProperty(ctx, "message", Values.toString(ctx, message)); diff --git a/src/me/topchetoeu/jscript/lib/RangeErrorLib.java b/src/me/topchetoeu/jscript/lib/RangeErrorLib.java index 540fec3..3c48d42 100644 --- a/src/me/topchetoeu/jscript/lib/RangeErrorLib.java +++ b/src/me/topchetoeu/jscript/lib/RangeErrorLib.java @@ -3,6 +3,7 @@ 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.ObjectValue.PlaceholderProto; import me.topchetoeu.jscript.interop.InitType; import me.topchetoeu.jscript.interop.Native; import me.topchetoeu.jscript.interop.NativeConstructor; @@ -11,6 +12,7 @@ import me.topchetoeu.jscript.interop.NativeInit; @Native("RangeError") public class RangeErrorLib extends ErrorLib { @NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) { var target = ErrorLib.constructor(ctx, thisArg, message); + target.setPrototype(PlaceholderProto.SYNTAX_ERROR); target.defineProperty(ctx, "name", "RangeError"); return target; } diff --git a/src/me/topchetoeu/jscript/lib/SyntaxErrorLib.java b/src/me/topchetoeu/jscript/lib/SyntaxErrorLib.java index 2d8df7f..d47feb3 100644 --- a/src/me/topchetoeu/jscript/lib/SyntaxErrorLib.java +++ b/src/me/topchetoeu/jscript/lib/SyntaxErrorLib.java @@ -3,6 +3,7 @@ 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.ObjectValue.PlaceholderProto; import me.topchetoeu.jscript.interop.InitType; import me.topchetoeu.jscript.interop.Native; import me.topchetoeu.jscript.interop.NativeConstructor; @@ -11,6 +12,7 @@ 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.setPrototype(PlaceholderProto.SYNTAX_ERROR); return target; } @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) { diff --git a/src/me/topchetoeu/jscript/lib/TypeErrorLib.java b/src/me/topchetoeu/jscript/lib/TypeErrorLib.java index 906b096..7e4179c 100644 --- a/src/me/topchetoeu/jscript/lib/TypeErrorLib.java +++ b/src/me/topchetoeu/jscript/lib/TypeErrorLib.java @@ -3,6 +3,7 @@ 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.ObjectValue.PlaceholderProto; import me.topchetoeu.jscript.interop.InitType; import me.topchetoeu.jscript.interop.Native; import me.topchetoeu.jscript.interop.NativeConstructor; @@ -11,6 +12,7 @@ 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.setPrototype(PlaceholderProto.SYNTAX_ERROR); return target; } @NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {