Refine search
public Rhino1_7R3Context() { Context ctx = Context.enter(); try { ctx.setOptimizationLevel(1); ctx.setLanguageVersion(Context.VERSION_1_7); // Global global = new Global(); global.init(ctx); this.global = global; this.ctx = ctx; this.scope = ctx.initStandardObjects(global); this.classCache = new HashMap<String, Class<?>>(); this.codeCache = new HashMap<String, byte[]>(); } finally { Context.exit(); } }
public void initContext(Context cx, Scriptable scope, Script script) { this.cx = cx; this.scope = scope; this.script = script; if (global == null || !global.isInitialized()) { global = new Global(cx); global.setIn(System.in); global.setOut(System.out); global.setErr(System.err); } // dim.setScopeProvider(new LscScopeProvider(global)); }
Global myGlobal = new Global(); String[][][] myArray = myGlobal.getMyarray(); // returns the array reference myArray[2][2][1] = "me"; // set the value of a single array element final String name = myArray[2][2][1];
protected void compress() throws IOException { URL cssmin = getClass().getClassLoader().getResource( "META-INF/cssmin.js"); Context cx = Context.enter(); cx.setOptimizationLevel(9); Global global = new Global(); global.init(cx); Scriptable scope = cx.initStandardObjects(global); cx.evaluateString(scope, "var exports = {};", "exports", 1, null); cx.evaluateReader(scope, new InputStreamReader(cssmin.openConnection() .getInputStream()), cssmin.getFile(), 1, null); Scriptable exports = (Scriptable) scope.get("exports", scope); Scriptable compressor = (Scriptable) exports.get("compressor", exports); Function fn = (Function) compressor.get("cssmin", compressor); content = ((String) Context.call(null, fn, compressor, compressor, new Object[] { new String(content, charset).replaceFirst( "^/\\*", "/*!") })).getBytes(charset); Context.exit(); }
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(); } }
public RhinoCompiler(LessOptions options, ResourceLoader loader, URL less, URL env, URL engine, URL cssmin, URL sourceMap) throws IOException { Context cx = Context.enter(); logger.debug("Using implementation version: " + cx.getImplementationVersion()); cx.setOptimizationLevel(-1); Global global = new Global(); global.init(cx); scope = cx.initStandardObjects(global); cx.evaluateReader(scope, new InputStreamReader(sourceMap
public void initialize() throws Exception { if (enableDebugger) { if (getLogger().isDebugEnabled()) { getLogger().debug("Flow debugger enabled, creating"); } getDebugger().doBreak(); } Context context = Context.enter(); context.setOptimizationLevel(OPTIMIZATION_LEVEL); context.setCompileFunctionsWithDynamicScope(true); context.setGeneratingDebug(true); // add support for Rhino objects to JXPath JXPathIntrospector.registerDynamicClass(Scriptable.class, ScriptablePropertyHandler.class); JXPathContextReferenceImpl.addNodePointerFactory(new ScriptablePointerFactory()); try { scope = new Global(context); // Access to Cocoon internal objects FOM_Cocoon.init(scope); } catch (Exception e) { Context.exit(); throw e; } }
i++; PrintStream savedOut = this.getOut(); PrintStream savedErr = this.getErr(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); this.setOut(new PrintStream(out)); this.setErr(new PrintStream(err)); String resultString = ""; ErrorReporter savedErrorReporter = cx.getErrorReporter(); cx.setErrorReporter(new ToolErrorReporter(false, this.getErr())); try { testCount++; Object result = cx.evaluateString(scope, inputString, "doctest input", 1, null); if (result != Context.getUndefinedValue() && ToolErrorReporter.reportException(cx.getErrorReporter(), e); } finally { this.setOut(savedOut); this.setErr(savedErr); cx.setErrorReporter(savedErrorReporter); resultString += err.toString() + out.toString(); if (!doctestOutputMatches(expectedString, resultString)) { String message = "doctest failure running:\n" + inputString +
synchronized void init() { if ( ! inited ) { Context c = Context.enter(); c.setOptimizationLevel( -1 ); Global g = Main.getGlobal(); g.init( c ); inited = true; } }
public CommonJSEngineFactory(List<String> modulePaths) { this.modulePaths = modulePaths; Context cx = CommonJSEngine.enterContext(); try { global = new Global(); global.initStandardObjects(cx, true); global.installRequire(cx, modulePaths, true); } finally { Context.exit(); } }
public RhinoBackend(ResourceLoader resourceLoader) throws IOException { this.resourceLoader = resourceLoader; cx = Context.enter(); scope = new Global(cx); // This gives us access to global functions like load() scope.put("jsBackend", scope, this); for (Resource resource : resourceLoader.resources("classpath:cucumber/runtime/rhino", ".js")) { runScript(resource); } }
/** * Entry point for embedded applications. This method attaches * to the global {@link ContextFactory} with a scope of a newly * created {@link Global} object. No I/O redirection is performed * as with {@link #main(String[])}. */ public static Dim mainEmbedded(String title) { ContextFactory factory = ContextFactory.getGlobal(); Global global = new Global(); global.init(factory); return mainEmbedded(factory, global, title); }
/** * Activate the Debugger */ public synchronized void activate() { factory = ContextFactory.getGlobal(); Global global = new Global(); global.init(factory); global.setIn(System.in); global.setOut(System.out); global.setErr(System.err); initDebugger(); ScopeProvider sp = new AlfrescoScopeProvider((Scriptable)global); dim.setScopeProvider(sp); gui = new AlfrescoGui(dim, getTitle(), this); gui.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); gui.setExitAction(this); }
throw reportRuntimeError("msg.runCommand.bad.args"); } else { if (!(envObj instanceof Scriptable)) { throw reportRuntimeError("msg.runCommand.bad.env"); in = toInputStream(inObj); out = toOutputStream(outObj); if (out == null) { outBytes = new ByteArrayOutputStream(); err = toOutputStream(errObj); if (err == null) { errBytes = new ByteArrayOutputStream(); Scriptable s = Context.toObject(addArgsObj, getTopLevelScope(thisObj)); addArgs = cx.getElements(s); Global global = getInstance(funObj); if (out == null) { out = (global != null) ? global.getOut() : System.out; err = (global != null) ? global.getErr() : System.err; int exitCode = runProcess(cmd, environment, in, out, err); if (outBytes != null) { String s = ScriptRuntime.toString(outObj) + outBytes.toString();
@Override protected Void doCall(Context cx, Scriptable s) { try { Global global = new Global(cx); RequireProperties require = rhinoProperties.getRequire(); if (require != null) { List<String> modulePathURIs = getModulePathURIs(require); LOGGER.debug("Module paths: {}", modulePathURIs); global.installRequire(cx, modulePathURIs, require.isSandboxed()); } // we need to load compat/timeout.js because rhino does not have setTimeout, setInterval, etc. try (Reader in = new InputStreamReader(classloader.getResourceAsStream("compat/timeout.js"))) { cx.evaluateReader(global, in, "compat/timeout.js", 1, null); } scope = global; prototype = new NativeObject(); scope.put("__prototype", scope, prototype); return null; } catch (IOException e) { throw Throwables.propagate(e); } } });
break goodUsage; if (!Context.isValidLanguageVersion(version)) { usageError = args[i]; break goodUsage; global.init(shellContextFactory); errorReporter.setIsReportingWarnings(true); continue; global.setSealedStdLib(true); continue; arg.equals("-help")) { global.getOut().println( ToolErrorReporter.getMessage("msg.shell.usage", Main.class.getName())); System.exit(1); global.getOut().println( ToolErrorReporter.getMessage("msg.shell.invalid", usageError)); global.getOut().println( ToolErrorReporter.getMessage("msg.shell.usage", Main.class.getName())); System.exit(1);
public static void main(String[] args) { errorReporter = new ToolErrorReporter(false, global.getErr()); shellContextFactory.setErrorReporter(errorReporter); IProxy iproxy = new IProxy(IProxy.PROCESS_FILES, processOptions(args)); global.init(shellContextFactory); shellContextFactory.call(iproxy); }
public Object run(Context cx) { init(cx); return null; } });
/** * Main entry point. Creates a debugger attached to a Rhino * {@link org.mozilla.javascript.tools.shell.Main} shell session. */ public static void main(String[] args) { Main main = new Main("Rhino JavaScript Debugger"); main.doBreak(); main.setExitAction(new IProxy(IProxy.EXIT_ACTION)); System.setIn(main.getIn()); System.setOut(main.getOut()); System.setErr(main.getErr()); Global global = org.mozilla.javascript.tools.shell.Main.getGlobal(); global.setIn(main.getIn()); global.setOut(main.getOut()); global.setErr(main.getErr()); main.attachTo( org.mozilla.javascript.tools.shell.Main.shellContextFactory); main.setScope(global); main.pack(); main.setSize(600, 460); main.setVisible(true); org.mozilla.javascript.tools.shell.Main.exec(args); }