48 import javax.script.ScriptContext;
49 import javax.script.ScriptEngine;
50 import javax.script.ScriptEngineFactory;
51 import javax.script.ScriptException;
52 import javax.script.SimpleBindings;
53 import jdk.nashorn.internal.objects.Global;
54 import jdk.nashorn.internal.runtime.Context;
55 import jdk.nashorn.internal.runtime.ErrorManager;
56 import jdk.nashorn.internal.runtime.ScriptFunction;
57 import jdk.nashorn.internal.runtime.ScriptObject;
58 import jdk.nashorn.internal.runtime.ScriptRuntime;
59 import jdk.nashorn.internal.runtime.Source;
60 import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory;
61 import jdk.nashorn.internal.runtime.options.Options;
62
63 /**
64 * JSR-223 compliant script engine for Nashorn. Instances are not created directly, but rather returned through
65 * {@link NashornScriptEngineFactory#getScriptEngine()}. Note that this engine implements the {@link Compilable} and
66 * {@link Invocable} interfaces, allowing for efficient precompilation and repeated execution of scripts.
67 * @see NashornScriptEngineFactory
68 */
69
70 public final class NashornScriptEngine extends AbstractScriptEngine implements Compilable, Invocable {
71 /**
72 * Key used to associate Nashorn global object mirror with arbitrary Bindings instance.
73 */
74 public static final String NASHORN_GLOBAL = "nashorn.global";
75
76 // commonly used access control context objects
77 private static AccessControlContext createPermAccCtxt(final String permName) {
78 final Permissions perms = new Permissions();
79 perms.add(new RuntimePermission(permName));
80 return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, perms) });
81 }
82
83 private static final AccessControlContext CREATE_CONTEXT_ACC_CTXT = createPermAccCtxt(Context.NASHORN_CREATE_CONTEXT);
84 private static final AccessControlContext CREATE_GLOBAL_ACC_CTXT = createPermAccCtxt(Context.NASHORN_CREATE_GLOBAL);
85
86 // the factory that created this engine
87 private final ScriptEngineFactory factory;
88 // underlying nashorn Context - 1:1 with engine instance
89 private final Context nashornContext;
|
48 import javax.script.ScriptContext;
49 import javax.script.ScriptEngine;
50 import javax.script.ScriptEngineFactory;
51 import javax.script.ScriptException;
52 import javax.script.SimpleBindings;
53 import jdk.nashorn.internal.objects.Global;
54 import jdk.nashorn.internal.runtime.Context;
55 import jdk.nashorn.internal.runtime.ErrorManager;
56 import jdk.nashorn.internal.runtime.ScriptFunction;
57 import jdk.nashorn.internal.runtime.ScriptObject;
58 import jdk.nashorn.internal.runtime.ScriptRuntime;
59 import jdk.nashorn.internal.runtime.Source;
60 import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory;
61 import jdk.nashorn.internal.runtime.options.Options;
62
63 /**
64 * JSR-223 compliant script engine for Nashorn. Instances are not created directly, but rather returned through
65 * {@link NashornScriptEngineFactory#getScriptEngine()}. Note that this engine implements the {@link Compilable} and
66 * {@link Invocable} interfaces, allowing for efficient precompilation and repeated execution of scripts.
67 * @see NashornScriptEngineFactory
68 *
69 * @since 1.8u40
70 */
71 @jdk.Exported
72 public final class NashornScriptEngine extends AbstractScriptEngine implements Compilable, Invocable {
73 /**
74 * Key used to associate Nashorn global object mirror with arbitrary Bindings instance.
75 */
76 public static final String NASHORN_GLOBAL = "nashorn.global";
77
78 // commonly used access control context objects
79 private static AccessControlContext createPermAccCtxt(final String permName) {
80 final Permissions perms = new Permissions();
81 perms.add(new RuntimePermission(permName));
82 return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, perms) });
83 }
84
85 private static final AccessControlContext CREATE_CONTEXT_ACC_CTXT = createPermAccCtxt(Context.NASHORN_CREATE_CONTEXT);
86 private static final AccessControlContext CREATE_GLOBAL_ACC_CTXT = createPermAccCtxt(Context.NASHORN_CREATE_GLOBAL);
87
88 // the factory that created this engine
89 private final ScriptEngineFactory factory;
90 // underlying nashorn Context - 1:1 with engine instance
91 private final Context nashornContext;
|