public Object eval(Reader scriptFileReader, String javascriptPath) throws IOException { File file = new File(javascriptPath); loadFunction.putContextPath(file.getParent()); return context.evaluateReader(scope, scriptFileReader, javascriptPath, 1, null); }
private void loadScript(Context cx, Scriptable scope, String fullPath) throws IOException { InputStream is = retrieveScriptAsInputStream(fullPath); String fileId = GalenUtils.calculateFileId(fullPath, is); if (!loadedFileIds.contains(fileId)) { File file = new File(fullPath); String parentPath = file.getParent(); if (parentPath != null) { contextPathStack.push(file.getParent()); } cx.evaluateReader(scope, new InputStreamReader(is), file.getAbsolutePath(), 1, null); loadedFileIds.add(fileId); if (!contextPathStack.isEmpty()) { contextPathStack.pop(); } } }
try { inStream = new InputStreamReader( KettleVFS.getInputStream( fileName ) ); actualContext.evaluateReader( eval_scope, inStream, fileName, 1, null ); } catch ( FileNotFoundException Signal ) { Context.reportError( "Unable to open file \"" + fileName + "\" (reason: \"" + Signal.getMessage() + "\")" );
@Override public Object eval(Reader reader, ScriptContext context) throws ScriptException { Scriptable scope = setupScope(cx, context); String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null ? "<unknown>" : filename; try { return cx.evaluateReader(scope, reader, filename, 1, null); } catch (RhinoException e) { String msg; int line = (line = e.lineNumber()) == 0 ? -1 : line; if (e instanceof JavaScriptException) { msg = String.valueOf(((JavaScriptException) e).getValue()); } else { msg = e.getMessage(); } ScriptException scriptException = new ScriptException(msg, e.sourceName(), line); scriptException.initCause(e); throw scriptException; } catch (IOException e) { throw new ScriptException(e); } finally { Context.exit(); } }
public class RJsDemo { @Test public void simpleRhinoTest() throws FileNotFoundException, IOException { Context cx = Context.enter(); final JsRuntimeSupport browserSupport = new JsRuntimeSupport(); final ScriptableObject sharedScope = cx.initStandardObjects(browserSupport, true); String[] names = { "print", "load" }; sharedScope.defineFunctionProperties(names, sharedScope.getClass(), ScriptableObject.DONTENUM); Scriptable argsObj = cx.newArray(sharedScope, new Object[] {}); sharedScope.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM); cx.evaluateReader(sharedScope, new FileReader("./r.js"), "require", 1, null); cx.evaluateReader(sharedScope, new FileReader("./loader.js"), "loader", 1, null); Context.exit(); } }
private void loadJavascriptLibrary(final Context cx, final Scriptable scope, final Reader reader, final String libraryName) { try { cx.evaluateReader(scope, reader, libraryName, 1, null); } catch (final IOException e) { throw new IllegalStateException("Could not load script <" + libraryName + ">", e); } } }
private void loadJavascriptLibrary(final Context cx, final Scriptable scope, final Reader reader, final String libraryName) { try { cx.evaluateReader(scope, reader, libraryName, 1, null); } catch (final IOException e) { throw new IllegalStateException("Could not load script <" + libraryName + ">", e); } } }
private void loadScript(Context cx, Scriptable scope, String name) { FileReader readerJQ = null; try { readerJQ = new FileReader(name); cx.evaluateReader(scope, readerJQ, name, 1, null); readerJQ.close(); } catch (IOException e) { throw new RuntimeException(e); } }
private void loadJs(Scriptable topScope, Context cx, String name) throws IOException { final InputStream in = getClass().getResourceAsStream(name); if (in == null) { throw new FileNotFoundException("Could not find JS resource " + name); } InputStreamReader reader = new InputStreamReader(in, "UTF-8"); cx.evaluateReader(topScope, reader, name, 1, null); }
public static void loadModule(Context cx, Scriptable scope, Path modulePath) { try (java.io.FileReader module = new java.io.FileReader( modulePath.toFile() ) ) { cx.evaluateReader(scope, module, modulePath.toString(), 0, null); } catch (IOException e) { throw new RuntimeException(format("error evaluating [%s]!", modulePath.toString()), e); } }
@SuppressWarnings("unchecked") @Override protected T doCall(Context cx, Scriptable scope) throws IOException { Object val = cx.evaluateReader(scope, reader, sourceName, 1, null); val = unwrappedValue(val); return (T) val; } });
/** * evaluate javascript from a reader * @param name the name of the script (for error messages) * @param scriptReader the content of the script * @return the result */ public Object jsEval(String name, Reader scriptReader) { try { return getContext().evaluateReader(scope, scriptReader, name, 1, null); } catch (IOException e) { throw new RuntimeException(e); } }
public Object eval(Reader scriptFileReader, String javascriptPath) throws IOException { File file = new File(javascriptPath); loadFunction.putContextPath(file.getParent()); return context.evaluateReader(scope, scriptFileReader, javascriptPath, 1, null); }
public Object run(Context cx) { try { return cx.evaluateReader(globalObject, scriptReader, description, 1, rhinoClassLoader); } catch (IOException ioe) { throw new WrappedException(ioe); } } };
public Object run(Context cx) { try { return cx.evaluateReader(globalObject, scriptReader, description, 1, rhinoClassLoader); } catch (IOException ioe) { throw new WrappedException(ioe); } } };
public Object run(Context cx) { try { return cx.evaluateReader(globalObject, scriptReader, description, 1, rhinoClassLoader); } catch (IOException ioe) { throw new WrappedException(ioe); } } };
public MiniumBackend(ResourceLoader resourceLoader, Context cx, Scriptable scope) throws IOException { try { this.resourceLoader = resourceLoader; this.cx = cx; this.scope = scope; this.scope.put("jsBackend", this.scope, this); InputStreamReader dsl = new InputStreamReader(getClass().getResourceAsStream(JS_DSL), Charsets.UTF_8.toString()); this.cx.evaluateReader(this.scope, dsl, JS_DSL, 1, null); } catch (Exception e) { throw Throwables.propagate(e); } }
// Execution environment for Rhino // there should be only one context in a giver thread Context cx = Context.enter(); // Object.prototype, Function prototype, etc. Scriptable scope = cx.initStandardObjects(); // Execute script from a given java.io.Reader Object result = cx.evaluateReader(scope, reader, 0, null); // If returning result isn't sufficient for your needs // you can do something like this: Object someVar = scope.get("someVar"); // Don't forget to close the context when you're done Context.exit();
private void runScript(Resource resource) { try { cx.evaluateReader(scope, new InputStreamReader(resource.getInputStream(), "UTF-8"), resource.getAbsolutePath(), 1, null); } catch (IOException e) { throw new CucumberException("Failed to evaluate JavaScript in " + resource.getAbsolutePath(), e); } }
private void runScript(Resource resource) { try { cx.evaluateReader(scope, new InputStreamReader(resource.getInputStream(), "UTF-8"), resource.getAbsolutePath(), 1, null); } catch (IOException e) { throw new CucumberException("Failed to evaluate JavaScript in " + resource.getAbsolutePath(), e); } }