List of usage examples for jdk.nashorn.internal.objects NativeArray pop
@Function(attributes = Attribute.NOT_ENUMERABLE) public static Object pop(final Object self)
From source file:org.siphon.common.js.JsEngineUtil.java
License:Open Source License
public static Object eval(ScriptEngine jsEngine, String srcFile, boolean onlyOnce, boolean preservePathInStack) throws Exception { ScriptObjectMirror importedFiles = (ScriptObjectMirror) jsEngine.get("IMPORTED_FILES"); if (importedFiles.containsKey(srcFile)) { if (onlyOnce) return null; } else {/*from w w w . j ava 2s . com*/ importedFiles.put(srcFile, true); } ScriptObjectMirror stk = (ScriptObjectMirror) jsEngine.get("IMPORTS_PATH_STACK"); // NativeArray.pushObject(stk.to(NativeArray.class), srcFile); //stk.callMember("push", srcFile); try { String code = FileUtils.readFileToString(new File(srcFile), "utf-8"); return eval(jsEngine, srcFile, code); } catch (ScriptException | FileNotFoundException e) { throw e; } finally { if (!preservePathInStack) NativeArray.pop(stk.to(NativeArray.class)); } }
From source file:org.siphon.common.js.JsEngineUtil.java
License:Open Source License
public static Object eval(ScriptEngine jsEngine, String srcFile, String aliasPath, String script, boolean onlyOnce, boolean preservePathInStack) throws NoSuchMethodException, ScriptException { ScriptObjectMirror importedFiles = (ScriptObjectMirror) jsEngine.get("IMPORTED_FILES"); if (importedFiles.containsKey(srcFile)) { if (onlyOnce) return null; } else {/* w w w . j ava 2 s . co m*/ importedFiles.put(srcFile, true); } ScriptObjectMirror stk = (ScriptObjectMirror) jsEngine.get("IMPORTS_PATH_STACK"); //NativeArray.pushObject((Object)(stk.to(NativeArray.class)), (Object)srcFile); stk.callMember("push", srcFile); try { return eval(jsEngine, aliasPath, script); } catch (ScriptException e) { throw e; } finally { if (!preservePathInStack) NativeArray.pop(stk.to(NativeArray.class)); } }