55 import jdk.nashorn.internal.runtime.ScriptObject;
56 import jdk.nashorn.internal.runtime.ScriptRuntime;
57 import jdk.nashorn.internal.runtime.Source;
58 import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory;
59 import jdk.nashorn.internal.runtime.options.Options;
60
61 /**
62 * JSR-223 compliant script engine for Nashorn. Instances are not created directly, but rather returned through
63 * {@link NashornScriptEngineFactory#getScriptEngine()}. Note that this engine implements the {@link Compilable} and
64 * {@link Invocable} interfaces, allowing for efficient precompilation and repeated execution of scripts.
65 * @see NashornScriptEngineFactory
66 */
67
68 public final class NashornScriptEngine extends AbstractScriptEngine implements Compilable, Invocable {
69
70 private final ScriptEngineFactory factory;
71 private final Context nashornContext;
72 private final ScriptObject global;
73
74 // default options passed to Nashorn Options object
75 private static final String[] DEFAULT_OPTIONS = new String[] { "-scripting", "-af", "-doe" };
76
77 NashornScriptEngine(final NashornScriptEngineFactory factory, final ClassLoader appLoader) {
78 this(factory, DEFAULT_OPTIONS, appLoader);
79 }
80
81 NashornScriptEngine(final NashornScriptEngineFactory factory, final String[] args, final ClassLoader appLoader) {
82 this.factory = factory;
83 final Options options = new Options("nashorn");
84 options.process(args);
85
86 // throw ParseException on first error from script
87 final ErrorManager errMgr = new Context.ThrowErrorManager();
88 // create new Nashorn Context
89 this.nashornContext = AccessController.doPrivileged(new PrivilegedAction<Context>() {
90 @Override
91 public Context run() {
92 try {
93 return new Context(options, errMgr, appLoader);
94 } catch (final RuntimeException e) {
95 if (Context.DEBUG) {
|
55 import jdk.nashorn.internal.runtime.ScriptObject;
56 import jdk.nashorn.internal.runtime.ScriptRuntime;
57 import jdk.nashorn.internal.runtime.Source;
58 import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory;
59 import jdk.nashorn.internal.runtime.options.Options;
60
61 /**
62 * JSR-223 compliant script engine for Nashorn. Instances are not created directly, but rather returned through
63 * {@link NashornScriptEngineFactory#getScriptEngine()}. Note that this engine implements the {@link Compilable} and
64 * {@link Invocable} interfaces, allowing for efficient precompilation and repeated execution of scripts.
65 * @see NashornScriptEngineFactory
66 */
67
68 public final class NashornScriptEngine extends AbstractScriptEngine implements Compilable, Invocable {
69
70 private final ScriptEngineFactory factory;
71 private final Context nashornContext;
72 private final ScriptObject global;
73
74 // default options passed to Nashorn Options object
75 private static final String[] DEFAULT_OPTIONS = new String[] { "-scripting", "-doe" };
76
77 NashornScriptEngine(final NashornScriptEngineFactory factory, final ClassLoader appLoader) {
78 this(factory, DEFAULT_OPTIONS, appLoader);
79 }
80
81 NashornScriptEngine(final NashornScriptEngineFactory factory, final String[] args, final ClassLoader appLoader) {
82 this.factory = factory;
83 final Options options = new Options("nashorn");
84 options.process(args);
85
86 // throw ParseException on first error from script
87 final ErrorManager errMgr = new Context.ThrowErrorManager();
88 // create new Nashorn Context
89 this.nashornContext = AccessController.doPrivileged(new PrivilegedAction<Context>() {
90 @Override
91 public Context run() {
92 try {
93 return new Context(options, errMgr, appLoader);
94 } catch (final RuntimeException e) {
95 if (Context.DEBUG) {
|