src/jdk/nashorn/api/scripting/NashornScriptEngine.java

Print this page

        

*** 325,335 **** return UNDEFINED; } private void evalEngineScript() throws ScriptException { ! final URL url = NashornScriptEngine.class.getResource("resources/engine.js"); try { final InputStream is = url.openStream(); put(ScriptEngine.FILENAME, url); try (final InputStreamReader isr = new InputStreamReader(is)) { eval(isr); --- 325,339 ---- return UNDEFINED; } private void evalEngineScript() throws ScriptException { ! evalSupportScript("resources/engine.js"); ! } ! ! private void evalSupportScript(String script) throws ScriptException { ! final URL url = NashornScriptEngine.class.getResource(script); try { final InputStream is = url.openStream(); put(ScriptEngine.FILENAME, url); try (final InputStreamReader isr = new InputStreamReader(is)) { eval(isr);
*** 433,442 **** --- 437,455 ---- if (globalChanged) { setNashornGlobal(global); } setContextVariables(ctxt); + final Object val = ctxt.getAttribute(ScriptEngine.FILENAME); + final String fileName = (val != null) ? val.toString() : "<eval>"; + + // if this is jrunscript's init.js, we want to run the replacement + if ("<system-init>".equals(fileName)) { + evalSupportScript("resources/init.js"); + return null; + } + Object res = ScriptRuntime.apply(script, global); res = ScriptObjectMirror.wrap(res, global); return (res == UNDEFINED) ? null : res; } catch (final Exception e) { throwAsScriptException(e);
*** 484,498 **** final boolean globalChanged = (oldGlobal != global); try { final Object val = ctxt.getAttribute(ScriptEngine.FILENAME); final String fileName = (val != null) ? val.toString() : "<eval>"; - // !!HACK!! do not evaluate "init.js" from jrunscript tool!! - if ("<system-init>".equals(fileName)) { - return null; - } - final Source source = new Source(fileName, buf); if (globalChanged) { setNashornGlobal(global); } --- 497,506 ----