Java Code Examples for org.graalvm.polyglot.Context#Builder

The following examples show how to use org.graalvm.polyglot.Context#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraalContext.java    From netbeans with Apache License 2.0 6 votes vote down vote up
synchronized final Context ctx() {
    if (ctx == null) {
        final Context.Builder b = Context.newBuilder();
        b.out(writer);
        b.err(errorWriter);
        if (reader != null) {
            try {
                b.in(new ReaderInputStream(reader, "UTF-8"));
            } catch (IOException ex) {
                throw raise(RuntimeException.class, ex);
            }
        }
        b.allowPolyglotAccess(PolyglotAccess.ALL);
        if (Boolean.TRUE.equals(getAttribute(ALLOW_ALL_ACCESS, ScriptContext.GLOBAL_SCOPE))) {
            b.allowHostAccess(HostAccess.ALL);
            b.allowAllAccess(true);
        } else {
            b.allowHostAccess(SANDBOX);
        }
        ctx = b.build();
    }
    return ctx;
}
 
Example 2
Source File: GraalJsEngineWrapper.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public ScriptEngine getEngine() {
    Context.Builder contextBuilder =
            Context.newBuilder("js")
                    .allowExperimentalOptions(true)
                    .option("js.syntax-extensions", "true")
                    .option("js.load", "true")
                    .option("js.print", "true")
                    .option("js.nashorn-compat", "true")
                    .allowAllAccess(true);

    ScriptEngine se = GraalJSScriptEngine.create(null, contextBuilder);

    // Force use of own (add-on) class loader
    // https://github.com/graalvm/graaljs/issues/182
    ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    try {
        se.eval("");
    } catch (ScriptException ignore) {
    } finally {
        Thread.currentThread().setContextClassLoader(previousContextClassLoader);
    }
    return se;
}
 
Example 3
Source File: TruffleSqueakLauncher.java    From trufflesqueak with MIT License 4 votes vote down vote up
@Override
protected void launch(final Context.Builder contextBuilder) {
    System.exit(execute(contextBuilder));
}