refactor: rename callNew -> construct and call -> invoke
This commit is contained in:
parent
b9268518f6
commit
5f88061ee7
@ -28,9 +28,9 @@ public interface EventLoop {
|
||||
}
|
||||
|
||||
public default Future<Value> pushMsg(boolean micro, Environment env, FunctionValue func, Value thisArg, Value ...args) {
|
||||
return pushMsg(() -> func.call(env, thisArg, args), micro);
|
||||
return pushMsg(() -> func.invoke(env, thisArg, args), micro);
|
||||
}
|
||||
public default Future<Value> pushMsg(boolean micro, Environment env, Filename filename, String raw, Value thisArg, Value ...args) {
|
||||
return pushMsg(() -> Compiler.compileFunc(env, filename, raw).call(env, thisArg, args), micro);
|
||||
return pushMsg(() -> Compiler.compileFunc(env, filename, raw).invoke(env, thisArg, args), micro);
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class InstructionRunner {
|
||||
var callArgs = frame.take(instr.get(0));
|
||||
var funcObj = frame.pop();
|
||||
|
||||
frame.push(funcObj.callNew(env, instr.get(1), callArgs));
|
||||
frame.push(funcObj.construct(env, instr.get(1), callArgs));
|
||||
|
||||
frame.codePtr++;
|
||||
return null;
|
||||
@ -82,7 +82,7 @@ public class InstructionRunner {
|
||||
private static Value execKeys(Environment env, Instruction instr, Frame frame) {
|
||||
var val = frame.pop();
|
||||
|
||||
var members = new ArrayList<>(val.getMembers(env, false, true));
|
||||
var members = new ArrayList<>(val.getMembers(env, instr.get(0), instr.get(1)));
|
||||
Collections.reverse(members);
|
||||
|
||||
frame.push(null);
|
||||
@ -115,9 +115,12 @@ public class InstructionRunner {
|
||||
|
||||
private static Value execDup(Environment env, Instruction instr, Frame frame) {
|
||||
int count = instr.get(0);
|
||||
int offset = instr.get(1);
|
||||
|
||||
var el = frame.stack[frame.stackPtr - offset - 1];
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
frame.push(frame.peek());
|
||||
frame.push(el);
|
||||
}
|
||||
|
||||
frame.codePtr++;
|
||||
@ -230,7 +233,7 @@ public class InstructionRunner {
|
||||
}
|
||||
private static Value execLoadRegEx(Environment env, Instruction instr, Frame frame) {
|
||||
if (env.hasNotNull(Value.REGEX_CONSTR)) {
|
||||
frame.push(env.get(Value.REGEX_CONSTR).callNew(env, instr.get(0), instr.get(1)));
|
||||
frame.push(env.get(Value.REGEX_CONSTR).construct(env, instr.get(0), instr.get(1)));
|
||||
}
|
||||
else {
|
||||
throw EngineException.ofSyntax("Regex is not supported.");
|
||||
|
@ -83,7 +83,11 @@ public abstract class Value {
|
||||
if (isNew) throw EngineException.ofType(name + " is not a constructor");
|
||||
else throw EngineException.ofType(name + " is not a function");
|
||||
}
|
||||
public final Value callNew(Environment env, String name, Value ...args) {
|
||||
|
||||
public final Value invoke(Environment env, String name, Value self, Value ...args) {
|
||||
return call(env, false, name, self, args);
|
||||
}
|
||||
public final Value construct(Environment env, String name, Value ...args) {
|
||||
var res = new ObjectValue();
|
||||
var proto = getMember(env, new StringValue("prototype"));
|
||||
|
||||
@ -96,11 +100,11 @@ public abstract class Value {
|
||||
return res;
|
||||
}
|
||||
|
||||
public final Value call(Environment env, Value self, Value ...args) {
|
||||
return call(env, false, "", self, args);
|
||||
public final Value invoke(Environment env, Value self, Value ...args) {
|
||||
return invoke(env, "", self, args);
|
||||
}
|
||||
public final Value callNew(Environment env, Value ...args) {
|
||||
return callNew(env, "", args);
|
||||
public final Value construct(Environment env, Value ...args) {
|
||||
return construct(env, "", args);
|
||||
}
|
||||
|
||||
public abstract Value toPrimitive(Environment env);
|
||||
@ -378,7 +382,7 @@ public abstract class Value {
|
||||
private void loadNext() {
|
||||
if (supplier == null) value = null;
|
||||
else if (consumed) {
|
||||
var curr = supplier.call(env, Value.UNDEFINED);
|
||||
var curr = supplier.invoke(env, Value.UNDEFINED);
|
||||
|
||||
if (curr == null) { supplier = null; value = null; }
|
||||
if (curr.getMember(env, new StringValue("done")).toBoolean()) { supplier = null; value = null; }
|
||||
@ -406,12 +410,12 @@ public abstract class Value {
|
||||
|
||||
public void callWith(Environment env, Iterable<? extends Value> it) {
|
||||
for (var el : it) {
|
||||
this.call(env, Value.UNDEFINED, el);
|
||||
this.invoke(env, Value.UNDEFINED, el);
|
||||
}
|
||||
}
|
||||
public void callWithAsync(Environment env, Iterable<? extends Value> it, boolean async) {
|
||||
for (var el : it) {
|
||||
env.get(EventLoop.KEY).pushMsg(() -> this.call(env, Value.UNDEFINED, el), true);
|
||||
env.get(EventLoop.KEY).pushMsg(() -> this.invoke(env, Value.UNDEFINED, el), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,13 +52,13 @@ public class ObjectValue extends Value {
|
||||
var valueOf = getMember(env, new StringValue("valueOf"));
|
||||
|
||||
if (valueOf instanceof FunctionValue) {
|
||||
var res = valueOf.call(env, this);
|
||||
var res = valueOf.invoke(env, this);
|
||||
if (res.isPrimitive()) return res;
|
||||
}
|
||||
|
||||
var toString = getMember(env, new StringValue("toString"));
|
||||
if (toString instanceof FunctionValue) {
|
||||
var res = toString.call(env, this);
|
||||
var res = toString.invoke(env, this);
|
||||
if (res.isPrimitive()) return res;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user