Search in sources :

Example 51 with SimpleScriptContext

use of javax.script.SimpleScriptContext in project Lucee by lucee.

the class AbstractScriptEngine method getScriptContext.

/**
 * Returns a <code>SimpleScriptContext</code>.  The <code>SimpleScriptContext</code>:
 *<br><br>
 * <ul>
 * <li>Uses the specified <code>Bindings</code> for its <code>ENGINE_SCOPE</code>
 * </li>
 * <li>Uses the <code>Bindings</code> returned by the abstract <code>getGlobalScope</code>
 * method as its <code>GLOBAL_SCOPE</code>
 * </li>
 * <li>Uses the Reader and Writer in the default <code>ScriptContext</code> of this
 * <code>ScriptEngine</code>
 * </li>
 * </ul>
 * <br><br>
 * A <code>SimpleScriptContext</code> returned by this method is used to implement eval methods
 * using the abstract <code>eval(Reader,Bindings)</code> and <code>eval(String,Bindings)</code>
 * versions.
 *
 * @param nn Bindings to use for the <code>ENGINE_SCOPE</code>
 * @return The <code>SimpleScriptContext</code>
 */
protected ScriptContext getScriptContext(Bindings nn) {
    SimpleScriptContext ctxt = new SimpleScriptContext();
    Bindings gs = getBindings(ScriptContext.GLOBAL_SCOPE);
    if (gs != null) {
        ctxt.setBindings(gs, ScriptContext.GLOBAL_SCOPE);
    }
    if (nn != null) {
        ctxt.setBindings(nn, ScriptContext.ENGINE_SCOPE);
    } else {
        throw new NullPointerException("Engine scope Bindings may not be null.");
    }
    ctxt.setReader(context.getReader());
    ctxt.setWriter(context.getWriter());
    ctxt.setErrorWriter(context.getErrorWriter());
    return ctxt;
}
Also used : SimpleScriptContext(javax.script.SimpleScriptContext) Bindings(javax.script.Bindings)

Example 52 with SimpleScriptContext

use of javax.script.SimpleScriptContext in project Lucee by lucee.

the class ScriptEngineImpl method getContext.

@Override
public ScriptContext getContext() {
    if (context == null) {
        context = new SimpleScriptContext();
        // we do our own
        context.setBindings(new VariablesBinding(), ScriptContext.ENGINE_SCOPE);
    }
    return context;
}
Also used : SimpleScriptContext(javax.script.SimpleScriptContext)

Aggregations

SimpleScriptContext (javax.script.SimpleScriptContext)52 ScriptContext (javax.script.ScriptContext)47 Test (org.junit.Test)25 Bindings (javax.script.Bindings)23 SimpleBindings (javax.script.SimpleBindings)23 NashornScriptEngine (jdk.nashorn.api.scripting.NashornScriptEngine)7 CompiledScript (javax.script.CompiledScript)5 Test (org.testng.annotations.Test)5 ScriptEngine (javax.script.ScriptEngine)4 ScriptException (javax.script.ScriptException)4 PrintWriter (java.io.PrintWriter)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 Map (java.util.Map)2 ScriptEngineManager (javax.script.ScriptEngineManager)2 Rectangle (java.awt.Rectangle)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 OutputStreamWriter (java.io.OutputStreamWriter)1