From 631ef9db4a281915748376027a4d0cb26ffc7e69 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Thu, 19 Sep 2024 18:10:50 +0300 Subject: [PATCH] fix: differenciate between non-functions and non-invokables in messages --- .../jscript/runtime/values/functions/FunctionValue.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/topchetoeu/jscript/runtime/values/functions/FunctionValue.java b/src/main/java/me/topchetoeu/jscript/runtime/values/functions/FunctionValue.java index 9714be9..7e49161 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/values/functions/FunctionValue.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/values/functions/FunctionValue.java @@ -1,6 +1,7 @@ package me.topchetoeu.jscript.runtime.values.functions; import me.topchetoeu.jscript.common.environment.Environment; +import me.topchetoeu.jscript.runtime.exceptions.EngineException; import me.topchetoeu.jscript.runtime.values.KeyCache; import me.topchetoeu.jscript.runtime.values.Member; import me.topchetoeu.jscript.runtime.values.Value; @@ -50,7 +51,10 @@ public abstract class FunctionValue extends ObjectValue { @Override public String toString() { return String.format("function %s(...)", name); } @Override public Value call(Environment ext, boolean isNew, String name, Value thisArg, Value ...args) { if (isNew && !enableNew) super.call(ext, isNew, name, thisArg, args); - if (!isNew && !enableCall) super.call(ext, isNew, name, thisArg, args); + if (!isNew && !enableCall) { + if (name == null || name.equals("")) name = "(intermediate value)"; + throw EngineException.ofType(name + " is not invokable"); + } return onCall(ext, isNew, name, thisArg, args); }