Search in sources :

Example 6 with Global

use of org.mozilla.javascript.tools.shell.Global in project hackpad by dropbox.

the class Main method mainEmbeddedImpl.

/**
     * Helper method for {@link #mainEmbedded(String)}, etc.
     */
private static Main mainEmbeddedImpl(ContextFactory factory, Object scopeProvider, String title) {
    if (title == null) {
        title = "Rhino JavaScript Debugger (embedded usage)";
    }
    Main main = new Main(title);
    main.doBreak();
    main.setExitAction(new IProxy(IProxy.EXIT_ACTION));
    main.attachTo(factory);
    if (scopeProvider instanceof ScopeProvider) {
        main.setScopeProvider((ScopeProvider) scopeProvider);
    } else {
        Scriptable scope = (Scriptable) scopeProvider;
        if (scope instanceof Global) {
            Global global = (Global) scope;
            global.setIn(main.getIn());
            global.setOut(main.getOut());
            global.setErr(main.getErr());
        }
        main.setScope(scope);
    }
    main.pack();
    main.setSize(600, 460);
    main.setVisible(true);
    return main;
}
Also used : Global(org.mozilla.javascript.tools.shell.Global)

Example 7 with Global

use of org.mozilla.javascript.tools.shell.Global in project cuke4duke by cucumber.

the class JsLanguage method begin_scenario.

protected void begin_scenario(Scenario scenario) throws Throwable {
    clearHooksAndStepDefinitions();
    cx = Context.enter();
    // This gives us access to global functions like load()
    scope = new Global(cx);
    scope.put("jsLanguage", scope, this);
    cx.evaluateReader(scope, new InputStreamReader(getClass().getResourceAsStream(JS_DSL)), JS_DSL, 1, null);
    for (String jsFile : jsFiles) {
        cx.evaluateReader(scope, new FileReader(jsFile), jsFile, 1, null);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileReader(java.io.FileReader) Global(org.mozilla.javascript.tools.shell.Global)

Aggregations

Global (org.mozilla.javascript.tools.shell.Global)7 InputStreamReader (java.io.InputStreamReader)3 Context (org.mozilla.javascript.Context)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 URL (java.net.URL)1 Test (org.junit.Test)1 ContextFactory (org.mozilla.javascript.ContextFactory)1 EcmaError (org.mozilla.javascript.EcmaError)1