From c6dc031cfd1806c2dfaea692b011afbf26f05689 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Wed, 21 Feb 2024 11:01:33 +0200 Subject: [PATCH] fix: respect return value of constructors --- .../me/topchetoeu/jscript/core/engine/values/FunctionValue.java | 1 - src/java/me/topchetoeu/jscript/core/engine/values/Values.java | 2 +- .../topchetoeu/jscript/utils/interop/NativeWrapperProvider.java | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/java/me/topchetoeu/jscript/core/engine/values/FunctionValue.java b/src/java/me/topchetoeu/jscript/core/engine/values/FunctionValue.java index dbc3e53..61178dc 100644 --- a/src/java/me/topchetoeu/jscript/core/engine/values/FunctionValue.java +++ b/src/java/me/topchetoeu/jscript/core/engine/values/FunctionValue.java @@ -6,7 +6,6 @@ import me.topchetoeu.jscript.core.engine.Context; public abstract class FunctionValue extends ObjectValue { public String name = ""; - public boolean special = false; public int length; @Override diff --git a/src/java/me/topchetoeu/jscript/core/engine/values/Values.java b/src/java/me/topchetoeu/jscript/core/engine/values/Values.java index 39cd674..e2c1be7 100644 --- a/src/java/me/topchetoeu/jscript/core/engine/values/Values.java +++ b/src/java/me/topchetoeu/jscript/core/engine/values/Values.java @@ -411,7 +411,7 @@ public class Values { var ret = call(ctx, func, res, args); - if (ret != null && func instanceof FunctionValue && ((FunctionValue)func).special) return ret; + if (!isPrimitive(ret)) return ret; return res; } catch (IllegalArgumentException e) { diff --git a/src/java/me/topchetoeu/jscript/utils/interop/NativeWrapperProvider.java b/src/java/me/topchetoeu/jscript/utils/interop/NativeWrapperProvider.java index 9cf7dd1..bf2ef51 100644 --- a/src/java/me/topchetoeu/jscript/utils/interop/NativeWrapperProvider.java +++ b/src/java/me/topchetoeu/jscript/utils/interop/NativeWrapperProvider.java @@ -247,8 +247,6 @@ public class NativeWrapperProvider implements WrapperProvider { new NativeFunction(getName(clazz), args -> { throw EngineException.ofError("This constructor is not invokable."); }) : create(getName(clazz), constr); - res.special = true; - apply(res, ctx, ExposeTarget.CONSTRUCTOR, clazz); return res;