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"
|
group = "org.bdware.sc"
|
||||||
version = "1.6.4"
|
version = "1.6.5"
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
@ -58,11 +58,11 @@ jar {
|
|||||||
libs = libs + " libs/" + it.name
|
libs = libs + " libs/" + it.name
|
||||||
}
|
}
|
||||||
from {
|
from {
|
||||||
// uncomment this when publish,
|
// uncomment this when publish,
|
||||||
// while develop at local use "false"
|
//while develop at local use "false"
|
||||||
configurations.runtimeClasspath.filter {
|
configurations.runtimeClasspath.filter {
|
||||||
// it.getAbsolutePath().contains("/lib/")
|
it.getAbsolutePath().contains("/lib/")
|
||||||
false
|
// false
|
||||||
}.collect {
|
}.collect {
|
||||||
it.isDirectory() ? it : zipTree(it)
|
it.isDirectory() ? it : zipTree(it)
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ import wrp.jdk.nashorn.internal.runtime.*;
|
|||||||
|
|
||||||
import javax.script.*;
|
import javax.script.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -271,7 +272,7 @@ public class DesktopEngine extends JSEngine {
|
|||||||
fun.getFileName(),
|
fun.getFileName(),
|
||||||
ScriptContext.ENGINE_SCOPE);
|
ScriptContext.ENGINE_SCOPE);
|
||||||
LOGGER.info("loadFun:" + str);
|
LOGGER.info("loadFun:" + str);
|
||||||
compileFunction(str, isInsnLimit);
|
compileFunction(fun, str, isInsnLimit);
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
return wrapperException(e, fun);
|
return wrapperException(e, fun);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -321,13 +322,13 @@ public class DesktopEngine extends JSEngine {
|
|||||||
"function %s(arg) { YancloudUtil.pubEventConstraint(\"%s\", arg, \"%s\"); }",
|
"function %s(arg) { YancloudUtil.pubEventConstraint(\"%s\", arg, \"%s\"); }",
|
||||||
name, topic, semantics.name());
|
name, topic, semantics.name());
|
||||||
}
|
}
|
||||||
compileFunction(str, false);
|
compileFunction(null, str, false);
|
||||||
LOGGER.debug("compile function " + name + " success!");
|
LOGGER.debug("compile function " + name + " success!");
|
||||||
str =
|
str =
|
||||||
String.format(
|
String.format(
|
||||||
"function %ss(arg0, arg1) { YancloudUtil.pubEventConstraint(\"%s\", arg0, arg1); }",
|
"function %ss(arg0, arg1) { YancloudUtil.pubEventConstraint(\"%s\", arg0, arg1); }",
|
||||||
name, topic);
|
name, topic);
|
||||||
compileFunction(str, false);
|
compileFunction(null, str, false);
|
||||||
LOGGER.debug("compile function " + name + "s success!");
|
LOGGER.debug("compile function " + name + "s success!");
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -406,7 +407,7 @@ public class DesktopEngine extends JSEngine {
|
|||||||
//
|
//
|
||||||
// return new ContractResult(Status.Success, new JsonPrimitive(""));
|
// 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();
|
Global oldGlobal = Context.getGlobal();
|
||||||
boolean globalChanged = (oldGlobal != global);
|
boolean globalChanged = (oldGlobal != global);
|
||||||
try {
|
try {
|
||||||
@ -418,6 +419,23 @@ public class DesktopEngine extends JSEngine {
|
|||||||
Context.TRACEMETHOD = true;
|
Context.TRACEMETHOD = true;
|
||||||
}
|
}
|
||||||
sf.compileScriptFunction();
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@ -426,8 +444,8 @@ public class DesktopEngine extends JSEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void compileFunction(String snippet, boolean instrumentBranch) throws ScriptException {
|
public void compileFunction(FunctionNode functionNode, String snippet, boolean instrumentBranch) throws ScriptException {
|
||||||
compileFunction((ScriptObjectMirror) engine.eval(snippet), instrumentBranch);
|
compileFunction(functionNode, (ScriptObjectMirror) engine.eval(snippet), instrumentBranch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user