Graal.JS/JDK-15 Fixes
Dropped Rhino to fully support Nashorn fallback with Graal.JS. this should work for pre-jdk-8 and jdk-15+
This commit is contained in:
parent
605721b378
commit
6a121dd9e1
10
pom.xml
10
pom.xml
|
@ -243,6 +243,16 @@
|
|||
<artifactId>webp-imageio</artifactId>
|
||||
<version>0.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js</artifactId>
|
||||
<version>21.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js-scriptengine</artifactId>
|
||||
<version>21.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -36,8 +36,10 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class JavascriptPluginLaunchStrategy implements PluginLaunchStrategy
|
||||
{
|
||||
public static final String firstPickEngine = "rhino";
|
||||
public static final String fallBackEngine = "nashorn";
|
||||
//attempt to use nashorn
|
||||
public static final String firstPickEngine = "nashorn";
|
||||
//fallback to graal.js
|
||||
public static final String fallBackEngine = "graal.js";
|
||||
|
||||
@Override
|
||||
public Plugin run(File file) throws Throwable
|
||||
|
@ -45,26 +47,29 @@ public class JavascriptPluginLaunchStrategy implements PluginLaunchStrategy
|
|||
ScriptEngineManager manager = new ScriptEngineManager();
|
||||
ScriptEngine engine = manager.getEngineByName(firstPickEngine);
|
||||
|
||||
//nashorn compatability with graal
|
||||
if (engine == null)
|
||||
{
|
||||
engine = manager.getEngineByName(fallBackEngine);
|
||||
|
||||
if (engine == null)
|
||||
throw new Exception("Cannot find Javascript script engine! Please contact Konloch.");
|
||||
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
|
||||
bindings.put("polyglot.js.allowHostAccess", true);
|
||||
bindings.put("polyglot.js.allowAllAccess", true);
|
||||
bindings.put("polyglot.js.allowHostClassLookup", true);
|
||||
bindings.put("activeContainer", activeContainer);
|
||||
}
|
||||
|
||||
Reader reader = new FileReader(file);
|
||||
engine.eval(reader);
|
||||
|
||||
ScriptEngine finalEngine = engine;
|
||||
return new Plugin()
|
||||
|
||||
Plugin plugin = new Plugin()
|
||||
{
|
||||
@Override
|
||||
public void execute(ArrayList<ClassNode> classNodeList)
|
||||
{
|
||||
try
|
||||
{
|
||||
//add the active container as a global variable to the JS script
|
||||
finalEngine.put("activeContainer", activeContainer);
|
||||
|
||||
//invoke the JS function
|
||||
((Invocable) finalEngine).invokeFunction("execute", classNodeList);
|
||||
}
|
||||
|
@ -74,5 +79,7 @@ public class JavascriptPluginLaunchStrategy implements PluginLaunchStrategy
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
plugin.setupJSContainer(finalEngine);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user