fix: some annoying bugs, as well as splice
This commit is contained in:
parent
15f4278cb1
commit
f5d1287948
2
.github/workflows/tagged-release.yml
vendored
2
.github/workflows/tagged-release.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
|||||||
uses: actions/setup-java@v3
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
java-version: '17'
|
java-version: '11'
|
||||||
- name: Clone repository
|
- name: Clone repository
|
||||||
uses: GuillaumeFalourd/clone-github-repo-action@main
|
uses: GuillaumeFalourd/clone-github-repo-action@main
|
||||||
with:
|
with:
|
||||||
|
@ -58,7 +58,7 @@ public class Engine implements DebugController {
|
|||||||
private LinkedBlockingDeque<Task> microTasks = new LinkedBlockingDeque<>();
|
private LinkedBlockingDeque<Task> microTasks = new LinkedBlockingDeque<>();
|
||||||
|
|
||||||
public final int id = ++nextId;
|
public final int id = ++nextId;
|
||||||
public final Data data = new Data().set(StackData.MAX_FRAMES, 200);
|
public final Data data = new Data().set(StackData.MAX_FRAMES, 10000);
|
||||||
public final boolean debugging;
|
public final boolean debugging;
|
||||||
private final HashMap<Filename, String> sources = new HashMap<>();
|
private final HashMap<Filename, String> sources = new HashMap<>();
|
||||||
private final HashMap<Filename, TreeSet<Location>> bpts = new HashMap<>();
|
private final HashMap<Filename, TreeSet<Location>> bpts = new HashMap<>();
|
||||||
|
@ -17,7 +17,8 @@ public class StackData {
|
|||||||
public static void pushFrame(Context ctx, CodeFrame frame) {
|
public static void pushFrame(Context ctx, CodeFrame frame) {
|
||||||
var frames = ctx.data.get(FRAMES, new ArrayList<>());
|
var frames = ctx.data.get(FRAMES, new ArrayList<>());
|
||||||
frames.add(frame);
|
frames.add(frame);
|
||||||
if (frames.size() > ctx.data.get(MAX_FRAMES, 10000)) throw EngineException.ofRange("Stack overflow!");
|
if (frames.size() > ctx.data.get(MAX_FRAMES, 10000))
|
||||||
|
throw EngineException.ofRange("Stack overflow!");
|
||||||
ctx.pushEnv(frame.function.environment);
|
ctx.pushEnv(frame.function.environment);
|
||||||
}
|
}
|
||||||
public static boolean popFrame(Context ctx, CodeFrame frame) {
|
public static boolean popFrame(Context ctx, CodeFrame frame) {
|
||||||
|
@ -596,6 +596,16 @@ public class Values {
|
|||||||
return fromJavaIterator(ctx, it.iterator());
|
return fromJavaIterator(ctx, it.iterator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isEmptyFunc(ObjectValue val) {
|
||||||
|
if (!(val instanceof FunctionValue)) return false;
|
||||||
|
if (!val.values.containsKey("prototype") || val.values.size() + val.properties.size() > 1) return false;
|
||||||
|
var proto = val.values.get("prototype");
|
||||||
|
if (!(proto instanceof ObjectValue)) return false;
|
||||||
|
var protoObj = (ObjectValue)proto;
|
||||||
|
if (protoObj.values.get("constructor") != val) return false;
|
||||||
|
if (protoObj.values.size() + protoObj.properties.size() != 1) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
private static void printValue(Context ctx, Object val, HashSet<Object> passed, int tab) {
|
private static void printValue(Context ctx, Object val, HashSet<Object> passed, int tab) {
|
||||||
if (tab == 0 && val instanceof String) {
|
if (tab == 0 && val instanceof String) {
|
||||||
System.out.print(val);
|
System.out.print(val);
|
||||||
@ -643,7 +653,7 @@ public class Values {
|
|||||||
passed.add(val);
|
passed.add(val);
|
||||||
|
|
||||||
var obj = (ObjectValue)val;
|
var obj = (ObjectValue)val;
|
||||||
if (obj.values.size() + obj.properties.size() == 0) {
|
if (obj.values.size() + obj.properties.size() == 0 || isEmptyFunc(obj)) {
|
||||||
if (!printed) System.out.println("{}");
|
if (!printed) System.out.println("{}");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -661,12 +671,13 @@ public class Values {
|
|||||||
printValue(ctx, el.getKey(), passed, tab + 1);
|
printValue(ctx, el.getKey(), passed, tab + 1);
|
||||||
System.out.println(": [prop],");
|
System.out.println(": [prop],");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < tab; i++) System.out.print(" ");
|
for (int i = 0; i < tab; i++) System.out.print(" ");
|
||||||
System.out.print("}");
|
System.out.print("}");
|
||||||
|
|
||||||
passed.remove(val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
passed.remove(val);
|
||||||
}
|
}
|
||||||
else if (val == null) System.out.print("undefined");
|
else if (val == null) System.out.print("undefined");
|
||||||
else if (val == Values.NULL) System.out.print("null");
|
else if (val == Values.NULL) System.out.print("null");
|
||||||
|
15
src/me/topchetoeu/jscript/js/bootstrap.js
vendored
15
src/me/topchetoeu/jscript/js/bootstrap.js
vendored
@ -1,6 +1,6 @@
|
|||||||
(function (_arguments) {
|
(function (_arguments) {
|
||||||
var ts = _arguments[0];
|
var ts = _arguments[0];
|
||||||
var src = '', lib = _arguments[2].concat([ 'declare const exit: never;' ]).join(''), decls = '', version = 0;
|
var src = '', lib = _arguments[2].concat([ 'declare const exit: never; declare const go: any;' ]).join(''), decls = '', version = 0;
|
||||||
var libSnapshot = ts.ScriptSnapshot.fromString(lib);
|
var libSnapshot = ts.ScriptSnapshot.fromString(lib);
|
||||||
|
|
||||||
var settings = {
|
var settings = {
|
||||||
@ -20,11 +20,11 @@
|
|||||||
var reg = ts.createDocumentRegistry();
|
var reg = ts.createDocumentRegistry();
|
||||||
var service = ts.createLanguageService({
|
var service = ts.createLanguageService({
|
||||||
getCurrentDirectory: function() { return "/"; },
|
getCurrentDirectory: function() { return "/"; },
|
||||||
getDefaultLibFileName: function() { return "/lib_.d.ts"; },
|
getDefaultLibFileName: function() { return "/lib.d.ts"; },
|
||||||
getScriptFileNames: function() { return [ "/src.ts", "/lib.d.ts", "/glob.d.ts" ]; },
|
getScriptFileNames: function() { return [ "/src.ts", "/lib.d.ts", "/glob.d.ts" ]; },
|
||||||
getCompilationSettings: function () { return settings; },
|
getCompilationSettings: function () { return settings; },
|
||||||
fileExists: function(filename) { return filename === "/lib.d.ts" || filename === "/src.ts" || filename === "/glob.d.ts"; },
|
fileExists: function(filename) { return filename === "/lib.d.ts" || filename === "/src.ts" || filename === "/glob.d.ts"; },
|
||||||
|
|
||||||
getScriptSnapshot: function(filename) {
|
getScriptSnapshot: function(filename) {
|
||||||
if (filename === "/lib.d.ts") return libSnapshot;
|
if (filename === "/lib.d.ts") return libSnapshot;
|
||||||
if (filename === "/src.ts") return ts.ScriptSnapshot.fromString(src);
|
if (filename === "/src.ts") return ts.ScriptSnapshot.fromString(src);
|
||||||
@ -37,11 +37,12 @@
|
|||||||
},
|
},
|
||||||
}, reg);
|
}, reg);
|
||||||
|
|
||||||
service.getEmitOutput('/lib.d.ts');
|
service.getEmitOutput("/lib.d.ts");
|
||||||
log('Loaded libraries!');
|
log("Loaded libraries!");
|
||||||
|
|
||||||
function compile(code, filename) {
|
function compile(code, filename) {
|
||||||
src = code, version++;
|
src = code;
|
||||||
|
version++;
|
||||||
|
|
||||||
var emit = service.getEmitOutput("/src.ts");
|
var emit = service.getEmitOutput("/src.ts");
|
||||||
|
|
||||||
@ -61,7 +62,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (diagnostics.length > 0) {
|
if (diagnostics.length > 0) {
|
||||||
throw new SyntaxError(diagnostics.join('\n'));
|
throw new SyntaxError(diagnostics.join("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
File diff suppressed because one or more lines are too long
@ -309,8 +309,9 @@ import me.topchetoeu.jscript.interop.NativeSetter;
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Native(thisArg = true) public static ArrayValue splice(Context ctx, ArrayValue arr, int start, int deleteCount, Object ...items) {
|
@Native(thisArg = true) public static ArrayValue splice(Context ctx, ArrayValue arr, int start, Object _deleteCount, Object ...items) {
|
||||||
start = normalizeI(arr.size(), start, true);
|
start = normalizeI(arr.size(), start, true);
|
||||||
|
int deleteCount = _deleteCount == null ? arr.size() - 1 : (int)Values.toNumber(ctx, _deleteCount);
|
||||||
deleteCount = normalizeI(arr.size(), deleteCount, true);
|
deleteCount = normalizeI(arr.size(), deleteCount, true);
|
||||||
if (start + deleteCount >= arr.size()) deleteCount = arr.size() - start;
|
if (start + deleteCount >= arr.size()) deleteCount = arr.size() - start;
|
||||||
|
|
||||||
@ -323,9 +324,6 @@ import me.topchetoeu.jscript.interop.NativeSetter;
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@Native(thisArg = true) public static ArrayValue splice(Context ctx, ArrayValue arr, int start) {
|
|
||||||
return splice(ctx, arr, start, arr.size() - start);
|
|
||||||
}
|
|
||||||
@Native(thisArg = true) public static String toString(Context ctx, ArrayValue arr) {
|
@Native(thisArg = true) public static String toString(Context ctx, ArrayValue arr) {
|
||||||
return join(ctx, arr, ",");
|
return join(ctx, arr, ",");
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,15 @@ public class Internals {
|
|||||||
private static final DataKey<Integer> I = new DataKey<>();
|
private static final DataKey<Integer> I = new DataKey<>();
|
||||||
|
|
||||||
|
|
||||||
@Native public static void log(Context ctx, Object ...args) {
|
@Native public static Object log(Context ctx, Object ...args) {
|
||||||
for (var arg : args) {
|
for (var arg : args) {
|
||||||
Values.printValue(ctx, arg);
|
Values.printValue(ctx, arg);
|
||||||
System.out.print(" ");
|
System.out.print(" ");
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
|
||||||
|
if (args.length == 0) return null;
|
||||||
|
else return args[0];
|
||||||
}
|
}
|
||||||
@Native public static String readline(Context ctx) {
|
@Native public static String readline(Context ctx) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user