fix: use linked hashmap for object statement

This commit is contained in:
2023-08-21 01:01:57 +03:00
parent 5629b9ab25
commit 7e6a1e03c8
8 changed files with 21 additions and 150 deletions

View File

@@ -12,6 +12,7 @@ import me.topchetoeu.jscript.events.Observer;
import me.topchetoeu.jscript.exceptions.EngineException;
import me.topchetoeu.jscript.exceptions.SyntaxException;
import me.topchetoeu.jscript.polyfills.PolyfillEngine;
import me.topchetoeu.jscript.polyfills.TypescriptEngine;
public class Main {
static Thread task;
@@ -51,7 +52,7 @@ public class Main {
public static void main(String args[]) {
var in = new BufferedReader(new InputStreamReader(System.in));
engine = new PolyfillEngine(new File("."));
engine = new TypescriptEngine(new File("."));
var scope = engine.global().globalChild();
var exited = new boolean[1];

View File

@@ -50,8 +50,8 @@ public class ObjectStatement extends Statement {
public ObjectStatement(Location loc, Map<Object, Statement> map, Map<Object, FunctionStatement> getters, Map<Object, FunctionStatement> setters) {
super(loc);
this.map = Map.copyOf(map);
this.getters = Map.copyOf(getters);
this.setters = Map.copyOf(setters);
this.map = map;
this.getters = getters;
this.setters = setters;
}
}

View File

@@ -21,14 +21,16 @@ public class CallContext {
return this;
}
public <T> CallContext setData(DataKey<T> key, T val) {
data.put(key, val);
if (val == null) data.remove(key);
else data.put(key, val);
return this;
}
@SuppressWarnings("unchecked")
public <T> T addData(DataKey<T> key, T val) {
if (data.containsKey(key)) return (T)data.get(key);
else {
data.put(key, val);
if (val == null) data.remove(key);
else data.put(key, val);
return val;
}
}

View File

@@ -532,6 +532,7 @@ public class Runners {
}
public static Object exec(DebugCommand state, Instruction instr, CodeFrame frame, CallContext ctx) throws InterruptedException {
// System.out.println(instr + "@" + instr.location);
switch (instr.type) {
case NOP: return execNop(instr, frame, ctx);
case RETURN: return execReturn(instr, frame, ctx);

View File

@@ -25,6 +25,12 @@ public class CodeFunction extends FunctionValue {
}
return null;
}
public String readable() {
var loc = loc();
if (loc == null) return name;
else if (name.equals("")) return loc.toString();
else return name + "@" + loc;
}
@Override
public Object call(CallContext ctx, Object thisArg, Object... args) throws InterruptedException {

View File

@@ -205,6 +205,10 @@ public class ObjectValue {
else return null;
}
protected boolean setField(CallContext ctx, Object key, Object val) throws InterruptedException {
if (val instanceof FunctionValue && ((FunctionValue)val).name.equals("")) {
((FunctionValue)val).name = Values.toString(ctx, key);
}
values.put(key, val);
return true;
}