List of usage examples for jdk.nashorn.internal.runtime ScriptObject putAll
public void putAll(final Map<?, ?> otherMap, final boolean strict)
From source file:com.threecrickets.scripturian.adapter.NashornAdapter.java
License:LGPL
/** * Gets the Nashorn global scope associated with the execution context, * creating it if it doesn't exist. Each execution context is guaranteed to * have its own global scope.//from w w w. ja v a 2 s. co m * * @param executionContext * The execution context * @return The global scope */ public ScriptObject getGlobalScope(ExecutionContext executionContext) { ScriptObject globalScope = (ScriptObject) executionContext.getAttributes().get(NASHORN_GLOBAL_SCOPE); boolean init = false; if (globalScope == null) { globalScope = context.createGlobal(); executionContext.getAttributes().put(NASHORN_GLOBAL_SCOPE, globalScope); init = true; } Context.setGlobal(globalScope); // Define services as properties in scope globalScope.putAll(executionContext.getServices(), false); if (init) { ScriptFunction script = context.compileScript( Source.sourceFor(getClass().getCanonicalName() + ".getGlobalScope", INIT_SOURCE), globalScope); ScriptRuntime.apply(script, globalScope); } return globalScope; }