feat: js引擎调试成功
This commit is contained in:
@@ -27,6 +27,9 @@ public class MultiThreadedCapture {
|
||||
try {
|
||||
result = task.execute();
|
||||
} catch (Exception e) {
|
||||
if (e instanceof CustomException){
|
||||
throw (CustomException) e;
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
System.setOut(oldOut);
|
||||
|
||||
@@ -47,10 +47,17 @@ public class JavaScriptEngine {
|
||||
return MultiThreadedCapture.capture(() -> {
|
||||
Context context = Context.newBuilder()
|
||||
.allowAllAccess(true)
|
||||
.allowHostClassLoading(true)
|
||||
.allowIO(true)
|
||||
.allowNativeAccess(true).build();
|
||||
context.eval("js", script);
|
||||
// .allowHostClassLoading(true)
|
||||
// .allowIO(true)
|
||||
// .allowNativeAccess(true)
|
||||
.build();
|
||||
try {
|
||||
context.eval("js", script);
|
||||
} catch (Exception e) {
|
||||
String message = e.getMessage();
|
||||
message = message.replace("java.lang.RuntimeException: org.graalvm.polyglot.PolyglotException: SyntaxError:", "");
|
||||
throw new CustomException("js has error : " + message);
|
||||
}
|
||||
Value executeFunction = context.getBindings("js").getMember(functionName);
|
||||
Value javaObjectAsValue = Value.asValue(args);
|
||||
Value result = executeFunction.execute(javaObjectAsValue);
|
||||
|
||||
Reference in New Issue
Block a user