From b4e7a429757f1b32ec6c0d54bbd583f986765264 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Sat, 23 Nov 2024 20:11:57 +0200 Subject: [PATCH] regress: remove ES6 stuff (except apply and construct constraints) from funcs --- .../values/functions/CodeFunction.java | 10 ++------ .../values/functions/FunctionValue.java | 25 ++++++++----------- .../values/functions/NativeFunction.java | 2 +- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/main/java/me/topchetoeu/jscript/runtime/values/functions/CodeFunction.java b/src/main/java/me/topchetoeu/jscript/runtime/values/functions/CodeFunction.java index e72a38a..5183b62 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/values/functions/CodeFunction.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/values/functions/CodeFunction.java @@ -10,9 +10,6 @@ public final class CodeFunction extends FunctionValue { public final Value[][] captures; public Environment env; - public Value self; - public Value argsVal; - private Value onCall(Frame frame) { frame.onPush(); @@ -27,11 +24,8 @@ public final class CodeFunction extends FunctionValue { } } - @Override public Value onCall(Environment env, boolean isNew, String name, Value thisArg, Value ...args) { - var frame = new Frame(env, isNew, thisArg, args, this); - if (argsVal != null) frame.fakeArgs = argsVal; - if (self != null) frame.self = self; - if (mustCallSuper && isNew) frame.self = null; + @Override public Value onCall(Environment env, boolean isNew, Value self, Value ...args) { + var frame = new Frame(env, isNew, self, args, this); var res = onCall(frame); 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 b44c76b..3038536 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 @@ -7,7 +7,6 @@ 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; @@ -21,9 +20,8 @@ public abstract class FunctionValue extends ObjectValue { public int length; public Value prototype = new ObjectValue(); - public boolean enableCall = true; - public boolean enableNew = true; - public boolean mustCallSuper = false; + public boolean enableApply = true; + public boolean enableConstruct = true; private final FieldMember nameField = new FieldMember(this, true, false, false) { @Override public Value get(Environment env, Value self) { @@ -53,18 +51,17 @@ public abstract class FunctionValue extends ObjectValue { } }; - protected abstract Value onCall(Environment ext, boolean isNew, String name, Value thisArg, Value ...args); + protected abstract Value onCall(Environment ext, boolean isNew, Value thisArg, Value ...args); @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) { - if (name == null || name.equals("")) name = "(intermediate value)"; - throw EngineException.ofType(name + " is not invokable"); - } - - return onCall(ext, isNew, name, thisArg, args); - } + @Override public Value apply(Environment env, Value self, Value... args) { + if (!enableApply) throw new RuntimeException("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"); + return onCall(env, true, self, args); + } @Override public Member getOwnMember(Environment env, KeyCache key) { switch (key.toString(env)) { diff --git a/src/main/java/me/topchetoeu/jscript/runtime/values/functions/NativeFunction.java b/src/main/java/me/topchetoeu/jscript/runtime/values/functions/NativeFunction.java index 0ad250a..f2bdc47 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/values/functions/NativeFunction.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/values/functions/NativeFunction.java @@ -10,7 +10,7 @@ public final class NativeFunction extends FunctionValue { public final NativeFunctionRunner action; - @Override public Value onCall(Environment env, boolean isNew, String name, Value self, Value ...args) { + @Override public Value onCall(Environment env, boolean isNew, Value self, Value ...args) { return action.run(new Arguments(env, isNew, self, args)); }