mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
connect function node with compiled function
This commit is contained in:
parent
363a20049a
commit
56d140a2c7
10
build.gradle
10
build.gradle
@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "org.bdware.sc"
|
||||
version = "1.6.4"
|
||||
version = "1.6.5"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
@ -58,11 +58,11 @@ jar {
|
||||
libs = libs + " libs/" + it.name
|
||||
}
|
||||
from {
|
||||
// uncomment this when publish,
|
||||
// while develop at local use "false"
|
||||
// uncomment this when publish,
|
||||
//while develop at local use "false"
|
||||
configurations.runtimeClasspath.filter {
|
||||
// it.getAbsolutePath().contains("/lib/")
|
||||
false
|
||||
it.getAbsolutePath().contains("/lib/")
|
||||
// false
|
||||
}.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ import wrp.jdk.nashorn.internal.runtime.*;
|
||||
|
||||
import javax.script.*;
|
||||
import java.io.*;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
@ -271,7 +272,7 @@ public class DesktopEngine extends JSEngine {
|
||||
fun.getFileName(),
|
||||
ScriptContext.ENGINE_SCOPE);
|
||||
LOGGER.info("loadFun:" + str);
|
||||
compileFunction(str, isInsnLimit);
|
||||
compileFunction(fun, str, isInsnLimit);
|
||||
} catch (ScriptException e) {
|
||||
return wrapperException(e, fun);
|
||||
} catch (Exception e) {
|
||||
@ -321,13 +322,13 @@ public class DesktopEngine extends JSEngine {
|
||||
"function %s(arg) { YancloudUtil.pubEventConstraint(\"%s\", arg, \"%s\"); }",
|
||||
name, topic, semantics.name());
|
||||
}
|
||||
compileFunction(str, false);
|
||||
compileFunction(null, str, false);
|
||||
LOGGER.debug("compile function " + name + " success!");
|
||||
str =
|
||||
String.format(
|
||||
"function %ss(arg0, arg1) { YancloudUtil.pubEventConstraint(\"%s\", arg0, arg1); }",
|
||||
name, topic);
|
||||
compileFunction(str, false);
|
||||
compileFunction(null, str, false);
|
||||
LOGGER.debug("compile function " + name + "s success!");
|
||||
} catch (ScriptException e) {
|
||||
e.printStackTrace();
|
||||
@ -406,7 +407,7 @@ public class DesktopEngine extends JSEngine {
|
||||
//
|
||||
// return new ContractResult(Status.Success, new JsonPrimitive(""));
|
||||
// }
|
||||
private void compileFunction(ScriptObjectMirror sf, boolean instrumentBranch) {
|
||||
private void compileFunction(FunctionNode functionNode, ScriptObjectMirror sf, boolean instrumentBranch) {
|
||||
Global oldGlobal = Context.getGlobal();
|
||||
boolean globalChanged = (oldGlobal != global);
|
||||
try {
|
||||
@ -418,6 +419,23 @@ public class DesktopEngine extends JSEngine {
|
||||
Context.TRACEMETHOD = true;
|
||||
}
|
||||
sf.compileScriptFunction();
|
||||
ScriptFunction scriptFunction = (ScriptFunction) sf.getScriptObject();
|
||||
Field f = ScriptFunction.class.getDeclaredField("data");
|
||||
f.setAccessible(true);
|
||||
ScriptFunctionData scriptFunctioNData = (ScriptFunctionData) f.get(scriptFunction);
|
||||
Object scope = scriptFunction.getScope();
|
||||
Method getGeneric = ScriptFunctionData.class.getDeclaredMethod("getGenericInvoker", ScriptObject.class);
|
||||
getGeneric.setAccessible(true);
|
||||
MethodHandle methodHandle = (MethodHandle) getGeneric.invoke(scriptFunctioNData, scope);
|
||||
Field memberNameField = methodHandle.getClass().getDeclaredField("member");
|
||||
memberNameField.setAccessible(true);
|
||||
Object memberName = memberNameField.get(methodHandle);
|
||||
Field clazz = memberName.getClass().getDeclaredField("clazz");
|
||||
clazz.setAccessible(true);
|
||||
Class clazz2 = (Class) clazz.get(memberName);
|
||||
if (functionNode != null)
|
||||
functionNode.compiledClazz = clazz2;
|
||||
//functionNode==null --> event functions
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
@ -426,8 +444,8 @@ public class DesktopEngine extends JSEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public void compileFunction(String snippet, boolean instrumentBranch) throws ScriptException {
|
||||
compileFunction((ScriptObjectMirror) engine.eval(snippet), instrumentBranch);
|
||||
public void compileFunction(FunctionNode functionNode, String snippet, boolean instrumentBranch) throws ScriptException {
|
||||
compileFunction(functionNode, (ScriptObjectMirror) engine.eval(snippet), instrumentBranch);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user