feat: js引擎调试成功

This commit is contained in:
clay
2024-04-24 10:48:14 +08:00
parent 450ed63e60
commit f3c2ef4cd9
12 changed files with 112 additions and 24 deletions

View File

@@ -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);

View File

@@ -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);