use of jdk.nashorn.api.scripting.ScriptObjectMirror in project molgenis by molgenis.
the class NashornScriptEngine method convertNashornValue.
private Object convertNashornValue(Object nashornValue) {
if (nashornValue == null) {
return null;
}
Object convertedValue;
String idValueKey = "_idValue";
if (nashornValue instanceof ScriptObjectMirror) {
ScriptObjectMirror scriptObjectMirror = (ScriptObjectMirror) nashornValue;
if (scriptObjectMirror.isArray()) {
convertedValue = scriptObjectMirror.values().stream().map(this::convertNashornValue).collect(Collectors.toList());
} else {
if ("Date".equals(scriptObjectMirror.getClassName())) {
// convert to Java Interface
JsDate jsDate = ((Invocable) scriptEngine).getInterface(scriptObjectMirror, JsDate.class);
return jsDate.getTime();
} else if (((ScriptObjectMirror) nashornValue).containsKey(idValueKey)) {
// entity object returned from script
return ((ScriptObjectMirror) nashornValue).get(idValueKey);
} else {
throw new RuntimeException("Unable to convert [ScriptObjectMirror]");
}
}
} else if (nashornValue instanceof Map) {
Map mapValue = (Map) (nashornValue);
if (mapValue.get(idValueKey) != null) {
convertedValue = mapValue.get(idValueKey);
} else {
convertedValue = nashornValue;
}
} else {
convertedValue = nashornValue;
}
return convertedValue;
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project POL-POM-5 by PhoenicisOrg.
the class EnginesController method deleteEngine.
private void deleteEngine(EngineDTO engineDTO, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + engineDTO.getCategory() + "\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
final ScriptObjectMirror wine = (ScriptObjectMirror) output;
wine.callMember("delete", engineDTO.getCategory(), engineDTO.getSubCategory(), engineDTO.getVersion(), engineDTO.getUserData());
}, errorCallback), errorCallback);
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project POL-POM-5 by PhoenicisOrg.
the class LibraryController method createShortcut.
/**
* creates a new shortcut
* @param shortcutCreationDTO DTO describing the new shortcut
*/
private void createShortcut(ShortcutCreationDTO shortcutCreationDTO) {
// get container
// TODO: smarter way using container manager
final String executablePath = shortcutCreationDTO.getExecutable().getAbsolutePath();
final String pathInContainers = executablePath.replace(containersPath, "");
final String[] split = pathInContainers.split("/");
final String engineContainer = split[0];
final String engine = (Character.toUpperCase(engineContainer.charAt(0)) + engineContainer.substring(1)).replace("prefix", "");
final String container = split[1];
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + engine + "\", \"Shortcuts\", \"" + engine + "\"]);", ignored -> interactiveScriptSession.eval("new " + engine + "Shortcut()", output -> {
final ScriptObjectMirror shortcutObject = (ScriptObjectMirror) output;
shortcutObject.callMember("name", shortcutCreationDTO.getName());
shortcutObject.callMember("category", shortcutCreationDTO.getCategory());
shortcutObject.callMember("description", shortcutCreationDTO.getDescription());
shortcutObject.callMember("miniature", shortcutCreationDTO.getMiniature());
shortcutObject.callMember("search", shortcutCreationDTO.getExecutable().getName());
shortcutObject.callMember("prefix", container);
shortcutObject.callMember("create");
}, e -> this.showErrorMessage(e, tr("Error while creating shortcut"))), e -> this.showErrorMessage(e, tr("Error while creating shortcut")));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project POL-POM-5 by PhoenicisOrg.
the class WinePrefixContainerController method runInContainer.
public void runInContainer(ContainerDTO container, String command, Runnable doneCallback, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + container.getEngine() + "\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new " + container.getEngine() + "()", output -> {
final ScriptObjectMirror wine = (ScriptObjectMirror) output;
wine.callMember("prefix", container.getName());
wine.callMember("run", command);
wine.callMember("wait");
doneCallback.run();
}, errorCallback), errorCallback);
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldWrapForConditionVariable.
@Test
public void shouldWrapForConditionVariable() throws Exception {
StringBuilder script = new StringBuilder("var x = true;\n");
script.append("for (var i = 0; x; i++)\n");
script.append(" x = false;\n");
runScript(script.toString(), false);
ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][1]");
assertThat(coverageData.get("evalTrue"), equalTo(1.0));
assertThat(coverageData.get("evalFalse"), equalTo(1.0));
}
Aggregations