Debugging support #7
@ -16,6 +16,7 @@ import me.topchetoeu.jscript.events.Observer;
|
|||||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||||
import me.topchetoeu.jscript.exceptions.InterruptException;
|
import me.topchetoeu.jscript.exceptions.InterruptException;
|
||||||
import me.topchetoeu.jscript.exceptions.SyntaxException;
|
import me.topchetoeu.jscript.exceptions.SyntaxException;
|
||||||
|
import me.topchetoeu.jscript.exceptions.UncheckedException;
|
||||||
import me.topchetoeu.jscript.lib.Internals;
|
import me.topchetoeu.jscript.lib.Internals;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
@ -35,9 +36,7 @@ public class Main {
|
|||||||
br.close();
|
br.close();
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (Throwable e) { throw new UncheckedException(e); }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public static String resourceToString(String name) {
|
public static String resourceToString(String name) {
|
||||||
var str = Main.class.getResourceAsStream("/me/topchetoeu/jscript/" + name);
|
var str = Main.class.getResourceAsStream("/me/topchetoeu/jscript/" + name);
|
||||||
@ -97,20 +96,17 @@ public class Main {
|
|||||||
catch (EngineException e) { Values.printError(e, ""); }
|
catch (EngineException e) { Values.printError(e, ""); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (InterruptException e) { return; }
|
||||||
e.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
catch (SyntaxException ex) {
|
catch (SyntaxException ex) {
|
||||||
if (exited[0]) return;
|
if (exited[0]) return;
|
||||||
System.out.println("Syntax error:" + ex.msg);
|
System.out.println("Syntax error:" + ex.msg);
|
||||||
}
|
}
|
||||||
catch (InterruptException e) { return; }
|
|
||||||
catch (RuntimeException ex) {
|
catch (RuntimeException ex) {
|
||||||
if (exited[0]) return;
|
if (exited[0]) return;
|
||||||
System.out.println("Internal error ocurred:");
|
System.out.println("Internal error ocurred:");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
catch (Throwable e) { throw new UncheckedException(e); }
|
||||||
if (exited[0]) return;
|
if (exited[0]) return;
|
||||||
});
|
});
|
||||||
reader.setDaemon(true);
|
reader.setDaemon(true);
|
||||||
|
@ -49,13 +49,8 @@ public class OperationStatement extends Statement {
|
|||||||
vals[i] = ((ConstantStatement)args[i]).value;
|
vals[i] = ((ConstantStatement)args[i]).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try { return new ConstantStatement(loc(), Values.operation(null, operation, vals)); }
|
||||||
return new ConstantStatement(loc(), Values.operation(null, operation, vals));
|
catch (EngineException e) { return new ThrowStatement(loc(), new ConstantStatement(loc(), e.value)); }
|
||||||
}
|
|
||||||
catch (EngineException e) {
|
|
||||||
return new ThrowStatement(loc(), new ConstantStatement(loc(), e.value));
|
|
||||||
}
|
|
||||||
catch (InterruptedException e) { return null; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new OperationStatement(loc(), operation, args);
|
return new OperationStatement(loc(), operation, args);
|
||||||
|
@ -8,6 +8,7 @@ import me.topchetoeu.jscript.engine.values.FunctionValue;
|
|||||||
import me.topchetoeu.jscript.events.Awaitable;
|
import me.topchetoeu.jscript.events.Awaitable;
|
||||||
import me.topchetoeu.jscript.events.DataNotifier;
|
import me.topchetoeu.jscript.events.DataNotifier;
|
||||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||||
|
import me.topchetoeu.jscript.exceptions.InterruptException;
|
||||||
|
|
||||||
public class Engine {
|
public class Engine {
|
||||||
private class UncompiledFunction extends FunctionValue {
|
private class UncompiledFunction extends FunctionValue {
|
||||||
@ -76,7 +77,7 @@ public class Engine {
|
|||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
for (var msg : macroTasks) {
|
for (var msg : macroTasks) {
|
||||||
msg.notifier.error(new RuntimeException(e));
|
msg.notifier.error(new InterruptException(e));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -155,9 +155,7 @@ public class ObjectValue {
|
|||||||
if (prototype == SYNTAX_ERR_PROTO) return ctx.environment().proto("syntaxErr");
|
if (prototype == SYNTAX_ERR_PROTO) return ctx.environment().proto("syntaxErr");
|
||||||
if (prototype == TYPE_ERR_PROTO) return ctx.environment().proto("typeErr");
|
if (prototype == TYPE_ERR_PROTO) return ctx.environment().proto("typeErr");
|
||||||
}
|
}
|
||||||
catch (NullPointerException e) {
|
catch (NullPointerException e) { return null; }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (ObjectValue)prototype;
|
return (ObjectValue)prototype;
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@ import me.topchetoeu.jscript.engine.Operation;
|
|||||||
import me.topchetoeu.jscript.engine.frame.ConvertHint;
|
import me.topchetoeu.jscript.engine.frame.ConvertHint;
|
||||||
import me.topchetoeu.jscript.exceptions.ConvertException;
|
import me.topchetoeu.jscript.exceptions.ConvertException;
|
||||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||||
import me.topchetoeu.jscript.exceptions.InterruptException;
|
|
||||||
import me.topchetoeu.jscript.exceptions.SyntaxException;
|
import me.topchetoeu.jscript.exceptions.SyntaxException;
|
||||||
|
import me.topchetoeu.jscript.exceptions.UncheckedException;
|
||||||
|
|
||||||
public class Values {
|
public class Values {
|
||||||
public static final Object NULL = new Object();
|
public static final Object NULL = new Object();
|
||||||
@ -97,12 +97,8 @@ public class Values {
|
|||||||
var second = hint == ConvertHint.VALUEOF ? "toString" : "valueOf";
|
var second = hint == ConvertHint.VALUEOF ? "toString" : "valueOf";
|
||||||
|
|
||||||
if (ctx != null) {
|
if (ctx != null) {
|
||||||
try {
|
try { return tryCallConvertFunc(ctx, obj, first); }
|
||||||
return tryCallConvertFunc(ctx, obj, first);
|
catch (EngineException unused) { return tryCallConvertFunc(ctx, obj, second); }
|
||||||
}
|
|
||||||
catch (EngineException unused) {
|
|
||||||
return tryCallConvertFunc(ctx, obj, second);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw EngineException.ofType("Value couldn't be converted to a primitive.");
|
throw EngineException.ofType("Value couldn't be converted to a primitive.");
|
||||||
@ -120,10 +116,8 @@ public class Values {
|
|||||||
if (val instanceof Number) return number(val);
|
if (val instanceof Number) return number(val);
|
||||||
if (val instanceof Boolean) return ((Boolean)val) ? 1 : 0;
|
if (val instanceof Boolean) return ((Boolean)val) ? 1 : 0;
|
||||||
if (val instanceof String) {
|
if (val instanceof String) {
|
||||||
try {
|
try { return Double.parseDouble((String)val); }
|
||||||
return Double.parseDouble((String)val);
|
catch (Throwable e) { throw new UncheckedException(e); }
|
||||||
}
|
|
||||||
catch (NumberFormatException e) { }
|
|
||||||
}
|
}
|
||||||
return Double.NaN;
|
return Double.NaN;
|
||||||
}
|
}
|
||||||
@ -565,10 +559,6 @@ public class Values {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (InterruptException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException | NullPointerException e) {
|
catch (IllegalArgumentException | NullPointerException e) {
|
||||||
return Collections.emptyIterator();
|
return Collections.emptyIterator();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package me.topchetoeu.jscript.events;
|
package me.topchetoeu.jscript.events;
|
||||||
|
|
||||||
|
import me.topchetoeu.jscript.exceptions.InterruptException;
|
||||||
|
|
||||||
public interface Awaitable<T> {
|
public interface Awaitable<T> {
|
||||||
T await() throws FinishedException, InterruptedException;
|
T await() throws FinishedException;
|
||||||
|
|
||||||
default Observable<T> toObservable() {
|
default Observable<T> toObservable() {
|
||||||
return sub -> {
|
return sub -> {
|
||||||
@ -10,9 +12,7 @@ public interface Awaitable<T> {
|
|||||||
sub.next(await());
|
sub.next(await());
|
||||||
sub.finish();
|
sub.finish();
|
||||||
}
|
}
|
||||||
catch (InterruptedException | FinishedException e) {
|
catch (InterruptException | FinishedException e) { sub.finish(); }
|
||||||
sub.finish();
|
|
||||||
}
|
|
||||||
catch (RuntimeException e) {
|
catch (RuntimeException e) {
|
||||||
sub.error(e);
|
sub.error(e);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package me.topchetoeu.jscript.exceptions;
|
||||||
|
|
||||||
|
public class UncheckedException extends RuntimeException {
|
||||||
|
public UncheckedException(Throwable err) {
|
||||||
|
super(err);
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ import me.topchetoeu.jscript.engine.values.FunctionValue;
|
|||||||
import me.topchetoeu.jscript.engine.values.NativeFunction;
|
import me.topchetoeu.jscript.engine.values.NativeFunction;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||||
|
import me.topchetoeu.jscript.exceptions.UncheckedException;
|
||||||
|
|
||||||
public class NativeWrapperProvider implements WrappersProvider {
|
public class NativeWrapperProvider implements WrappersProvider {
|
||||||
private final HashMap<Class<?>, FunctionValue> constructors = new HashMap<>();
|
private final HashMap<Class<?>, FunctionValue> constructors = new HashMap<>();
|
||||||
@ -120,7 +121,7 @@ public class NativeWrapperProvider implements WrappersProvider {
|
|||||||
var init = overload.getAnnotation(NativeInit.class);
|
var init = overload.getAnnotation(NativeInit.class);
|
||||||
if (init == null || init.value() != InitType.PROTOTYPE) continue;
|
if (init == null || init.value() != InitType.PROTOTYPE) continue;
|
||||||
try { overload.invoke(null, ctx, res); }
|
try { overload.invoke(null, ctx, res); }
|
||||||
catch (ReflectiveOperationException e) { e.printStackTrace(); }
|
catch (Throwable e) { throw new UncheckedException(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
applyMethods(ctx, true, res, clazz);
|
applyMethods(ctx, true, res, clazz);
|
||||||
@ -152,7 +153,7 @@ public class NativeWrapperProvider implements WrappersProvider {
|
|||||||
var init = overload.getAnnotation(NativeInit.class);
|
var init = overload.getAnnotation(NativeInit.class);
|
||||||
if (init == null || init.value() != InitType.CONSTRUCTOR) continue;
|
if (init == null || init.value() != InitType.CONSTRUCTOR) continue;
|
||||||
try { overload.invoke(null, ctx, func); }
|
try { overload.invoke(null, ctx, func); }
|
||||||
catch (ReflectiveOperationException e) { e.printStackTrace(); }
|
catch (Throwable e) { throw new UncheckedException(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((OverloadFunction)func).overloads.size() == 0) {
|
if (((OverloadFunction)func).overloads.size() == 0) {
|
||||||
@ -180,7 +181,7 @@ public class NativeWrapperProvider implements WrappersProvider {
|
|||||||
var init = overload.getAnnotation(NativeInit.class);
|
var init = overload.getAnnotation(NativeInit.class);
|
||||||
if (init == null || init.value() != InitType.NAMESPACE) continue;
|
if (init == null || init.value() != InitType.NAMESPACE) continue;
|
||||||
try { overload.invoke(null, ctx, res); }
|
try { overload.invoke(null, ctx, res); }
|
||||||
catch (ReflectiveOperationException e) { e.printStackTrace(); }
|
catch (Throwable e) { throw new UncheckedException(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
applyMethods(ctx, false, res, clazz);
|
applyMethods(ctx, false, res, clazz);
|
||||||
|
@ -76,12 +76,8 @@ public class OverloadFunction extends FunctionValue {
|
|||||||
try {
|
try {
|
||||||
return Values.normalize(ctx, overload.runner.run(ctx, _this, newArgs));
|
return Values.normalize(ctx, overload.runner.run(ctx, _this, newArgs));
|
||||||
}
|
}
|
||||||
catch (InstantiationException e) {
|
catch (InstantiationException e) { throw EngineException.ofError("The class may not be instantiated."); }
|
||||||
throw EngineException.ofError("The class may not be instantiated.");
|
catch (IllegalAccessException | IllegalArgumentException e) { continue; }
|
||||||
}
|
|
||||||
catch (IllegalAccessException | IllegalArgumentException e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
catch (InvocationTargetException e) {
|
catch (InvocationTargetException e) {
|
||||||
var loc = new Location(0, 0, "<internal>");
|
var loc = new Location(0, 0, "<internal>");
|
||||||
if (e.getTargetException() instanceof EngineException) {
|
if (e.getTargetException() instanceof EngineException) {
|
||||||
|
@ -74,9 +74,7 @@ public class JSONLib {
|
|||||||
try {
|
try {
|
||||||
return toJS(me.topchetoeu.jscript.json.JSON.parse("<value>", val));
|
return toJS(me.topchetoeu.jscript.json.JSON.parse("<value>", val));
|
||||||
}
|
}
|
||||||
catch (SyntaxException e) {
|
catch (SyntaxException e) { throw EngineException.ofSyntax(e.msg); }
|
||||||
throw EngineException.ofSyntax(e.msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@Native
|
@Native
|
||||||
public static String stringify(Context ctx, Object val) {
|
public static String stringify(Context ctx, Object val) {
|
||||||
|
@ -186,9 +186,7 @@ public class PromiseLib {
|
|||||||
if (thisArg instanceof PromiseLib) ((PromiseLib)thisArg).handle(ctx, fulfillHandle, rejectHandle);
|
if (thisArg instanceof PromiseLib) ((PromiseLib)thisArg).handle(ctx, fulfillHandle, rejectHandle);
|
||||||
else {
|
else {
|
||||||
Object next;
|
Object next;
|
||||||
try {
|
try { next = Values.getMember(ctx, thisArg, "then"); }
|
||||||
next = Values.getMember(ctx, thisArg, "then");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) { next = null; }
|
catch (IllegalArgumentException e) { next = null; }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -97,9 +97,7 @@ public class RegExpLib {
|
|||||||
var groups = new ObjectValue();
|
var groups = new ObjectValue();
|
||||||
|
|
||||||
for (var el : namedGroups) {
|
for (var el : namedGroups) {
|
||||||
try {
|
try { groups.defineProperty(null, el, matcher.group(el)); }
|
||||||
groups.defineProperty(null, el, matcher.group(el));
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) { }
|
catch (IllegalArgumentException e) { }
|
||||||
}
|
}
|
||||||
if (groups.values.size() == 0) groups = null;
|
if (groups.values.size() == 0) groups = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user