TopchetoEU/revert-ES5 #31

Merged
TopchetoEU merged 41 commits from TopchetoEU/revert-ES5 into master 2024-12-09 21:39:57 +00:00
3 changed files with 14 additions and 23 deletions
Showing only changes of commit b4e7a42975 - Show all commits

View File

@ -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);

View File

@ -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)) {

View File

@ -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));
}