mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
feat: support exception thrown in applyFunction
This commit is contained in:
parent
cf097ce7fd
commit
6064882843
@ -144,8 +144,8 @@ public class JavaScriptEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void executeFunction(ScriptFunction callback, Object arg) {
|
public static Object executeFunction(ScriptFunction callback, Object arg) {
|
||||||
DesktopEngine.applyWithGlobal(callback, currentEngine.getNashornGlobal(), arg);
|
return DesktopEngine.applyWithGlobal(callback, currentEngine.getNashornGlobal(), arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ApiGate createAPIGate(String ip) {
|
public static ApiGate createAPIGate(String ip) {
|
||||||
@ -330,10 +330,12 @@ public class JavaScriptEntry {
|
|||||||
return bo.toString();
|
return bo.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//YancloudUtil.exceptionReturn({"msg":"missing arguments repoId ","code":1});
|
//YancloudUtil.exceptionReturn({"msg":"missing arguments repoId ","code":1});
|
||||||
public static void exceptionReturn(Object obj) throws ScriptReturnException {
|
public static void exceptionReturn(Object obj) throws ScriptReturnException {
|
||||||
throw new ScriptReturnException(JSONTool.convertMirrorToJson(obj));
|
throw new ScriptReturnException(JSONTool.convertMirrorToJson(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* publish an event with semantic AT_LEAST_ONCE
|
* publish an event with semantic AT_LEAST_ONCE
|
||||||
*
|
*
|
||||||
|
@ -32,6 +32,7 @@ import org.bdware.sc.util.HashUtil;
|
|||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
import wrp.jdk.nashorn.api.scripting.NashornException;
|
||||||
import wrp.jdk.nashorn.api.scripting.NashornScriptEngine;
|
import wrp.jdk.nashorn.api.scripting.NashornScriptEngine;
|
||||||
import wrp.jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
import wrp.jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
||||||
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
@ -84,7 +85,7 @@ public class DesktopEngine extends JSEngine {
|
|||||||
startEngine();
|
startEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void applyWithGlobal(ScriptFunction script, Global global, Object... obj) {
|
public static Object applyWithGlobal(ScriptFunction script, Global global, Object... obj) {
|
||||||
Global oldGlobal = Context.getGlobal();
|
Global oldGlobal = Context.getGlobal();
|
||||||
boolean globalChanged = (oldGlobal != global);
|
boolean globalChanged = (oldGlobal != global);
|
||||||
try {
|
try {
|
||||||
@ -93,8 +94,10 @@ public class DesktopEngine extends JSEngine {
|
|||||||
}
|
}
|
||||||
// System.out.println("[DesktopEngine]" + script.getName() + " -->\n" +
|
// System.out.println("[DesktopEngine]" + script.getName() + " -->\n" +
|
||||||
// script.safeToString());
|
// script.safeToString());
|
||||||
ScriptRuntime.apply(script, global, obj);
|
Object ret = ScriptRuntime.apply(script, global, obj);
|
||||||
|
return ret;
|
||||||
|
} catch (NashornException e) {
|
||||||
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@ -102,6 +105,7 @@ public class DesktopEngine extends JSEngine {
|
|||||||
Context.setGlobal(oldGlobal);
|
Context.setGlobal(oldGlobal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRecovering(boolean b) {
|
public void setRecovering(boolean b) {
|
||||||
|
Loading…
Reference in New Issue
Block a user