/** * Evaluate an expression from the command line. * * @param expr the JavaScript expression to evaluate * @return the return value * @throws IOException an I/O related error occurred * @throws JavaScriptException the script threw an error during compilation or execution */ public Object evaluateExpression(String expr) throws IOException, JavaScriptException { Context cx = contextFactory.enterContext(); cx.setOptimizationLevel(-1); try { Object retval; Repository repository = repositories.get(0); Scriptable parentScope = mainScope != null ? mainScope : globalScope; ModuleScope scope = new ModuleScope("<expr>", repository, parentScope, mainWorker); Resource res = new StringResource("<expr>", expr, 1); ReloadableScript script = new ReloadableScript(res, this); retval = mainWorker.evaluateScript(cx, script, scope); return retval instanceof Wrapper ? ((Wrapper) retval).unwrap() : retval; } finally { Context.exit(); } }