fix: should throw engine exceptions, not java exceptions

This commit is contained in:
TopchetoEU 2024-12-09 22:15:38 +02:00
parent 4992d0211b
commit 611be55bbb
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4

View File

@ -7,6 +7,7 @@ import java.util.List;
import me.topchetoeu.jscript.common.environment.Environment;
import me.topchetoeu.jscript.runtime.debug.DebugContext;
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;
@ -55,11 +56,11 @@ public abstract class FunctionValue extends ObjectValue {
@Override public String toString() { return String.format("function %s(...)", name); }
@Override public Value apply(Environment env, Value self, Value... args) {
if (!enableApply) throw new RuntimeException("Function cannot be applied");
if (!enableApply) throw EngineException.ofType("Function cannot be applied");
return onCall(env, false, self, args);
}
@Override public Value construct(Environment env, Value self, Value... args) {
if (!enableConstruct) throw new RuntimeException("Function cannot be constructed");
if (!enableConstruct) throw EngineException.ofType("Function cannot be constructed");
return onCall(env, true, self, args);
}