Example usage for jdk.nashorn.internal.objects NativeArray pop

List of usage examples for jdk.nashorn.internal.objects NativeArray pop

Introduction

In this page you can find the example usage for jdk.nashorn.internal.objects NativeArray pop.

Prototype

@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object pop(final Object self) 

Source Link

Document

ECMA 15.4.4.6 Array.prototype.pop ()

Usage

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));
    }
}