/** * @deprecated * @see #compileReader(Reader in, String sourceName, int lineno, * Object securityDomain) */ public final Script compileReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) throws IOException { return compileReader(in, sourceName, lineno, securityDomain); }
/** * @deprecated * @see #compileReader(Reader in, String sourceName, int lineno, * Object securityDomain) */ public final Script compileReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) throws IOException { return compileReader(in, sourceName, lineno, securityDomain); }
/** * @deprecated * @see #compileReader(Reader in, String sourceName, int lineno, * Object securityDomain) */ public final Script compileReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) throws IOException { return compileReader(in, sourceName, lineno, securityDomain); }
/** * @deprecated * @see #compileReader(Reader in, String sourceName, int lineno, * Object securityDomain) */ public final Script compileReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) throws IOException { return compileReader(in, sourceName, lineno, securityDomain); }
/** * @deprecated * @see #compileReader(Reader in, String sourceName, int lineno, * Object securityDomain) */ public final Script compileReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) throws IOException { return compileReader(in, sourceName, lineno, securityDomain); }
/** * @deprecated * @see #compileReader(Reader in, String sourceName, int lineno, * Object securityDomain) */ @Deprecated public final Script compileReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) throws IOException { return compileReader(in, sourceName, lineno, securityDomain); }
throws IOException Script script = compileReader(scope, in, sourceName, lineno, securityDomain); if (script != null) {
/** * Evaluate a reader as JavaScript source. * * All characters of the reader are consumed. * * @param scope the scope to execute in * @param in the Reader to get JavaScript source from * @param sourceName a string describing the source, such as a filename * @param lineno the starting line number * @param securityDomain an arbitrary object that specifies security * information about the origin or owner of the script. For * implementations that don't care about security, this value * may be null. * @return the result of evaluating the source * * @exception IOException if an IOException was generated by the Reader */ public final Object evaluateReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) throws IOException { Script script = compileReader(scope, in, sourceName, lineno, securityDomain); if (script != null) { return script.exec(this, scope); } else { return null; } }
/** * Evaluate a reader as JavaScript source. * * All characters of the reader are consumed. * * @param scope the scope to execute in * @param in the Reader to get JavaScript source from * @param sourceName a string describing the source, such as a filename * @param lineno the starting line number * @param securityDomain an arbitrary object that specifies security * information about the origin or owner of the script. For * implementations that don't care about security, this value * may be null. * @return the result of evaluating the source * * @exception IOException if an IOException was generated by the Reader */ public final Object evaluateReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) throws IOException { Script script = compileReader(scope, in, sourceName, lineno, securityDomain); if (script != null) { return script.exec(this, scope); } else { return null; } }
/** * Evaluate a reader as JavaScript source. * * All characters of the reader are consumed. * * @param scope the scope to execute in * @param in the Reader to get JavaScript source from * @param sourceName a string describing the source, such as a filename * @param lineno the starting line number * @param securityDomain an arbitrary object that specifies security * information about the origin or owner of the script. For * implementations that don't care about security, this value * may be null. * @return the result of evaluating the source * * @exception IOException if an IOException was generated by the Reader */ public final Object evaluateReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) throws IOException { Script script = compileReader(scope, in, sourceName, lineno, securityDomain); if (script != null) { return script.exec(this, scope); } else { return null; } }
/** * Evaluate a reader as JavaScript source. * * All characters of the reader are consumed. * * @param scope the scope to execute in * @param in the Reader to get JavaScript source from * @param sourceName a string describing the source, such as a filename * @param lineno the starting line number * @param securityDomain an arbitrary object that specifies security * information about the origin or owner of the script. For * implementations that don't care about security, this value * may be null. * @return the result of evaluating the source * * @exception IOException if an IOException was generated by the Reader */ public final Object evaluateReader(Scriptable scope, Reader in, String sourceName, int lineno, Object securityDomain) throws IOException { Script script = compileReader(scope, in, sourceName, lineno, securityDomain); if (script != null) { return script.exec(this, scope); } else { return null; } }
protected Script compileScript(Context cx, Scriptable scope, Source src) throws Exception { PushbackInputStream is = new PushbackInputStream(src.getInputStream(), ENCODING_BUF_SIZE); try { String encoding = findEncoding(is); Reader reader = encoding == null ? new InputStreamReader(is) : new InputStreamReader(is, encoding); reader = new BufferedReader(reader); return cx.compileReader(reader, src.getURI(), 1, null); } finally { is.close(); } }
private void initialize() throws InitializationException { InputStreamReader reader = null; try { final Context context = Context.enter(); context.setLanguageVersion(Context.VERSION_1_8); final Global global = new Global(); global.init(context); scope = context.initStandardObjects(global); console = new ByteArrayOutputStream(); global.setOut(new PrintStream(console, false, CHARSET)); final URL lessFile = LessCompilerImpl.class.getResource("/less/less-rhino-1.7.5.js"); final URL lesscFile = LessCompilerImpl.class.getResource("/less/lessc-rhino-1.7.5.js"); final Collection<InputStream> streams = new ArrayList<InputStream>(); streams.add(lessFile.openConnection().getInputStream()); streams.add(lesscFile.openConnection().getInputStream()); reader = new InputStreamReader(new SequenceInputStream(Collections.enumeration(streams)), CHARSET); compiler = (Function) context.compileReader(reader, lessFile.toString(), 1, null); } catch (final Exception e) { throw new InitializationException("Failed to initialize Less compiler", e); } finally { IOUtils.closeQuietly(reader); Context.exit(); } }
/** * Build a script with the content of a DOM element. * * @param element the element containing the script * @return the compiled script * @throws IOException */ public static Script buildScript(Element element) throws IOException { String jsText = DomHelper.getElementText(element); String sourceName = DomHelper.getSystemIdLocation(element); Context ctx = Context.enter(); Script script; try { script = ctx.compileReader( // To use rhino1.5r4-continuations-R26.jar as a workaround for COCOON-1579: Uncomment the next line. // getRootScope(null), //scope new StringReader(jsText), // in sourceName == null ? "<unknown>" : sourceName, // sourceName DomHelper.getLineLocation(element), // lineNo null // securityDomain ); } finally { Context.exit(); } return script; }
public static synchronized void init() throws IOException { if (jsScope != null) return; try { Context jsContext = ContextFactory.getGlobal().enterContext(); jsContext.setClassShutter(new SecurityClassShutter()); jsScope = jsContext.initStandardObjects(null, true); Object o = Context.javaToJS(new TokenApi(), jsScope); ScriptableObject.putProperty(jsScope, "rptools_global_tokens", o); for (String script : JAVASCRIPT_FILES) { Reader reader = new InputStreamReader(ScriptManager.class.getClassLoader().getResourceAsStream(script)); Script compiled = jsContext.compileReader(reader, script, 1, null); compiled.exec(jsContext, jsScope); } // jsScope.sealObject(); } finally { Context.exit(); } }
public void addJavascript(Reader reader, String name, int lineno) throws Exception { try { Script script = cx.compileReader(reader, name, lineno, null); script.exec(cx, scope); } catch(EvaluatorException e) { for(JavascriptRunnerListener listener : listeners){ listener.compileError(e.details(), e.sourceName(), e.lineNumber(), e.columnNumber()); } throw e; } catch(Exception e) { reportUnexpectedError(e); throw e; } }
@Override public CompiledScript compile(java.io.Reader script) throws ScriptException { CompiledScript ret = null; Context cx = enterContext(); try { String filename = (String) get(RhinoScriptEngine.FILENAME); if (filename == null) { filename = "<Unknown Source>"; } Script scr = cx.compileReader(preProcessScriptSource(script), filename, 1, null); ret = new RhinoCompiledScript(this, scr); } catch (Exception e) { if (DEBUG) e.printStackTrace(); throw new ScriptException(e); } finally { Context.exit(); } return ret; }
public CompiledScript compile(java.io.Reader script) throws ScriptException { CompiledScript ret = null; Context cx = enterContext(); try { String fileName = (String) get(ScriptEngine.FILENAME); if (fileName == null) { fileName = "<Unknown Source>"; } Scriptable scope = getRuntimeScope(context); Script scr = cx.compileReader(scope, script, fileName, 1, null); ret = new RhinoCompiledScript(this, scr); } catch (Exception e) { if (DEBUG) e.printStackTrace(); throw new ScriptException(e); } finally { cx.exit(); } return ret; }
public CompiledScript compile(java.io.Reader script) throws ScriptException { CompiledScript ret = null; Context cx = enterContext(); try { String filename = (String) get(ScriptEngine.FILENAME); if (filename == null) { filename = "<Unknown Source>"; } Scriptable scope = getRuntimeScope(context); @SuppressWarnings("deprecation") Script scr = cx.compileReader(scope, preProcessScriptSource(script), filename, 1, null); ret = new RhinoCompiledScript(this, scr); } catch (Exception e) { if (DEBUG) e.printStackTrace(); throw new ScriptException(e); } finally { Context.exit(); } return ret; }
public CompiledScript compile(java.io.Reader script) throws ScriptException { CompiledScript ret = null; Context cx = enterContext(); try { String filename = (String) get(ScriptEngine.FILENAME); if (filename == null) { filename = "<Unknown Source>"; } Scriptable scope = getRuntimeScope(context); Script scr = cx.compileReader(scope, preProcessScriptSource(script), filename, 1, null); ret = new RhinoCompiledScript(this, scr); } catch (Exception e) { if (DEBUG) e.printStackTrace(); throw new ScriptException(e); } finally { cx.exit(); } return ret; }