|
@@ -25,7 +25,10 @@ public final class JsScriptEngineUtil {
|
|
|
}
|
|
|
""";
|
|
|
private static final String ARGS = """
|
|
|
- let args = JSON.parse(paramsArgsObject)
|
|
|
+ let args = []
|
|
|
+ if(paramsArgsObject){
|
|
|
+ args =JSON.parse(paramsArgsObject)
|
|
|
+ }
|
|
|
""";
|
|
|
private static final KeyedObjectPool<String, Source> sourcePool = new GenericKeyedObjectPool<>(new BaseKeyedPooledObjectFactory<>() {
|
|
|
@Override
|
|
@@ -47,6 +50,17 @@ public final class JsScriptEngineUtil {
|
|
|
|
|
|
public static Map<String, Object> eval(String script, List<Map<String, Object>> args) throws Exception {
|
|
|
|
|
|
+ try {
|
|
|
+ return UniReturnUtil.success(exec(script, args));
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println(script);
|
|
|
+ e.printStackTrace();
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Object exec(String script, List<Map<String, Object>> args) throws Exception {
|
|
|
+
|
|
|
String sc = ARGS + script;
|
|
|
|
|
|
Source source = Source.create("js", sc);
|
|
@@ -56,14 +70,10 @@ public final class JsScriptEngineUtil {
|
|
|
Value function = context.eval(source);
|
|
|
if (function.canExecute()) {
|
|
|
Value result = function.execute();
|
|
|
- return UniReturnUtil.success(toHostObject(result));
|
|
|
+ return toHostObject(result);
|
|
|
} else {
|
|
|
- return UniReturnUtil.success(toHostObject(function));
|
|
|
+ return toHostObject(function);
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println(script);
|
|
|
- e.printStackTrace();
|
|
|
- throw e;
|
|
|
}
|
|
|
}
|
|
|
|