some minor restructuring
This commit is contained in:
parent
4389d115b6
commit
1e982cd2ef
@ -72,7 +72,7 @@ export interface BufferPrimordials {
|
|||||||
export interface FunctionPrimordials {
|
export interface FunctionPrimordials {
|
||||||
invokeType(args: IArguments, self: any): "new" | "call";
|
invokeType(args: IArguments, self: any): "new" | "call";
|
||||||
invokeTypeInfer(): "new" | "call";
|
invokeTypeInfer(): "new" | "call";
|
||||||
target(): Function | null | undefined;
|
target(level?: number): Function | null | undefined;
|
||||||
setConstructable(func: Function, flag: boolean): void;
|
setConstructable(func: Function, flag: boolean): void;
|
||||||
setCallable(func: Function, flag: boolean): void;
|
setCallable(func: Function, flag: boolean): void;
|
||||||
invoke(func: Function, self: any, args: any[]): any;
|
invoke(func: Function, self: any, args: any[]): any;
|
||||||
|
@ -58,6 +58,10 @@ export const Function = (() => {
|
|||||||
public static compile(src: string, filename?: string) {
|
public static compile(src: string, filename?: string) {
|
||||||
return compile(String(src), filename);
|
return compile(String(src), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static newTarget() {
|
||||||
|
return func.target(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func.setCallable(Function, true);
|
func.setCallable(Function, true);
|
||||||
|
@ -7,7 +7,7 @@ import java.util.concurrent.CancellationException;
|
|||||||
import me.topchetoeu.j2s.common.Environment;
|
import me.topchetoeu.j2s.common.Environment;
|
||||||
import me.topchetoeu.j2s.common.Instruction;
|
import me.topchetoeu.j2s.common.Instruction;
|
||||||
import me.topchetoeu.j2s.common.Key;
|
import me.topchetoeu.j2s.common.Key;
|
||||||
import me.topchetoeu.j2s.runtime.debug.DebugContext;
|
import me.topchetoeu.j2s.runtime.debug.DebugHandler;
|
||||||
import me.topchetoeu.j2s.runtime.exceptions.EngineException;
|
import me.topchetoeu.j2s.runtime.exceptions.EngineException;
|
||||||
import me.topchetoeu.j2s.runtime.values.Value;
|
import me.topchetoeu.j2s.runtime.values.Value;
|
||||||
import me.topchetoeu.j2s.runtime.values.functions.CodeFunction;
|
import me.topchetoeu.j2s.runtime.values.functions.CodeFunction;
|
||||||
@ -17,6 +17,9 @@ import me.topchetoeu.j2s.runtime.values.primitives.numbers.IntValue;
|
|||||||
|
|
||||||
public final class Frame {
|
public final class Frame {
|
||||||
public static final Key<Stack<Frame>> KEY = new Key<>();
|
public static final Key<Stack<Frame>> KEY = new Key<>();
|
||||||
|
public static final Key<Integer> MAX_STACK_COUNT = new Key<>();
|
||||||
|
public static final Key<Boolean> HIDE_STACK = new Key<>();
|
||||||
|
|
||||||
public static final EngineException STACK_OVERFLOW;
|
public static final EngineException STACK_OVERFLOW;
|
||||||
static {
|
static {
|
||||||
STACK_OVERFLOW = EngineException.ofRange("Stack overflow!");
|
STACK_OVERFLOW = EngineException.ofRange("Stack overflow!");
|
||||||
@ -120,7 +123,7 @@ public final class Frame {
|
|||||||
public final Stack<TryCtx> tryStack = new Stack<>();
|
public final Stack<TryCtx> tryStack = new Stack<>();
|
||||||
public final CodeFunction function;
|
public final CodeFunction function;
|
||||||
public final Environment env;
|
public final Environment env;
|
||||||
private final DebugContext dbg;
|
private final DebugHandler dbg;
|
||||||
|
|
||||||
public Value getVar(int i) {
|
public Value getVar(int i) {
|
||||||
if (i < 0) return captures[~i][0];
|
if (i < 0) return captures[~i][0];
|
||||||
@ -206,7 +209,7 @@ public final class Frame {
|
|||||||
returnValue = InstructionRunner.exec(env, instr, this);
|
returnValue = InstructionRunner.exec(env, instr, this);
|
||||||
}
|
}
|
||||||
catch (EngineException e) {
|
catch (EngineException e) {
|
||||||
error = e.add(env, function.name, dbg.getMapOrEmpty(function).toLocation(codePtr, true));
|
error = e.add(env, function.name, dbg.getMapOrEmpty(env, function).toLocation(codePtr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,7 +217,7 @@ public final class Frame {
|
|||||||
catch (EngineException e) { error = e; }
|
catch (EngineException e) { error = e; }
|
||||||
catch (RuntimeException e) {
|
catch (RuntimeException e) {
|
||||||
if (!(e instanceof CancellationException)) {
|
if (!(e instanceof CancellationException)) {
|
||||||
System.out.println(dbg.getMapOrEmpty(function).toLocation(codePtr, true));
|
System.out.println(dbg.getMapOrEmpty(env, function).toLocation(codePtr));
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@ -352,10 +355,10 @@ public final class Frame {
|
|||||||
|
|
||||||
public void onPush() {
|
public void onPush() {
|
||||||
get(env).push(this);
|
get(env).push(this);
|
||||||
DebugContext.get(env).onFramePush(env, this);
|
DebugHandler.get(env).onFramePush(env, this);
|
||||||
}
|
}
|
||||||
public void onPop() {
|
public void onPop() {
|
||||||
DebugContext.get(env).onFramePop(env, this);
|
DebugHandler.get(env).onFramePop(env, this);
|
||||||
get(env).pop();
|
get(env).pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +379,7 @@ public final class Frame {
|
|||||||
|
|
||||||
public Frame(Environment env, boolean isNew, Value target, Value self, Value[] args, CodeFunction func) {
|
public Frame(Environment env, boolean isNew, Value target, Value self, Value[] args, CodeFunction func) {
|
||||||
this.env = env;
|
this.env = env;
|
||||||
this.dbg = DebugContext.get(env);
|
this.dbg = DebugHandler.get(env);
|
||||||
this.function = func;
|
this.function = func;
|
||||||
this.isNew = isNew;
|
this.isNew = isNew;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
@ -14,6 +14,7 @@ import me.topchetoeu.j2s.runtime.values.primitives.numbers.NumberValue;
|
|||||||
|
|
||||||
public class InstructionRunner {
|
public class InstructionRunner {
|
||||||
private static Value execReturn(Environment env, Instruction instr, Frame frame) {
|
private static Value execReturn(Environment env, Instruction instr, Frame frame) {
|
||||||
|
frame.codePtr++;
|
||||||
return frame.pop();
|
return frame.pop();
|
||||||
}
|
}
|
||||||
private static Value execThrow(Environment env, Instruction instr, Frame frame) {
|
private static Value execThrow(Environment env, Instruction instr, Frame frame) {
|
||||||
|
@ -48,9 +48,6 @@ public abstract class Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Key<Integer> MAX_STACK_COUNT = new Key<>();
|
|
||||||
public static final Key<Boolean> HIDE_STACK = new Key<>();
|
|
||||||
|
|
||||||
public static final Key<ObjectValue> BOOL_PROTO = new Key<>();
|
public static final Key<ObjectValue> BOOL_PROTO = new Key<>();
|
||||||
public static final Key<ObjectValue> NUMBER_PROTO = new Key<>();
|
public static final Key<ObjectValue> NUMBER_PROTO = new Key<>();
|
||||||
public static final Key<ObjectValue> STRING_PROTO = new Key<>();
|
public static final Key<ObjectValue> STRING_PROTO = new Key<>();
|
||||||
|
@ -44,6 +44,7 @@ public class ObjectValue extends Value {
|
|||||||
private HashMap<SymbolValue, FieldMember> symbolFields = new HashMap<>();
|
private HashMap<SymbolValue, FieldMember> symbolFields = new HashMap<>();
|
||||||
private HashMap<String, PropertyMember> properties = new HashMap<>();
|
private HashMap<String, PropertyMember> properties = new HashMap<>();
|
||||||
private HashMap<SymbolValue, PropertyMember> symbolProperties = new HashMap<>();
|
private HashMap<SymbolValue, PropertyMember> symbolProperties = new HashMap<>();
|
||||||
|
private State state = State.NORMAL;
|
||||||
|
|
||||||
private LinkedHashMap<String, Boolean> keys = new LinkedHashMap<>();
|
private LinkedHashMap<String, Boolean> keys = new LinkedHashMap<>();
|
||||||
private LinkedHashMap<SymbolValue, Boolean> symbols = new LinkedHashMap<>();
|
private LinkedHashMap<SymbolValue, Boolean> symbols = new LinkedHashMap<>();
|
||||||
@ -72,8 +73,6 @@ public class ObjectValue extends Value {
|
|||||||
@Override public NumberValue toNumber(Environment env) { return toPrimitive(env).toNumber(env); }
|
@Override public NumberValue toNumber(Environment env) { return toPrimitive(env).toNumber(env); }
|
||||||
@Override public StringValue type() { return StringValue.of("object"); }
|
@Override public StringValue type() { return StringValue.of("object"); }
|
||||||
|
|
||||||
private State state = State.NORMAL;
|
|
||||||
|
|
||||||
@Override public State getState() { return state; }
|
@Override public State getState() { return state; }
|
||||||
|
|
||||||
public final void preventExtensions() {
|
public final void preventExtensions() {
|
||||||
|
Loading…
Reference in New Issue
Block a user