40 import jdk.nashorn.api.scripting.NashornException; |
40 import jdk.nashorn.api.scripting.NashornException; |
41 import jdk.nashorn.internal.codegen.Compiler; |
41 import jdk.nashorn.internal.codegen.Compiler; |
42 import jdk.nashorn.internal.ir.FunctionNode; |
42 import jdk.nashorn.internal.ir.FunctionNode; |
43 import jdk.nashorn.internal.ir.debug.ASTWriter; |
43 import jdk.nashorn.internal.ir.debug.ASTWriter; |
44 import jdk.nashorn.internal.ir.debug.PrintVisitor; |
44 import jdk.nashorn.internal.ir.debug.PrintVisitor; |
|
45 import jdk.nashorn.internal.objects.Global; |
45 import jdk.nashorn.internal.parser.Parser; |
46 import jdk.nashorn.internal.parser.Parser; |
46 import jdk.nashorn.internal.runtime.Context; |
47 import jdk.nashorn.internal.runtime.Context; |
47 import jdk.nashorn.internal.runtime.ErrorManager; |
48 import jdk.nashorn.internal.runtime.ErrorManager; |
48 import jdk.nashorn.internal.runtime.JSType; |
49 import jdk.nashorn.internal.runtime.JSType; |
49 import jdk.nashorn.internal.runtime.Property; |
50 import jdk.nashorn.internal.runtime.Property; |
146 final Context context = makeContext(in, out, err, args); |
147 final Context context = makeContext(in, out, err, args); |
147 if (context == null) { |
148 if (context == null) { |
148 return COMMANDLINE_ERROR; |
149 return COMMANDLINE_ERROR; |
149 } |
150 } |
150 |
151 |
151 final ScriptObject global = context.createGlobal(); |
152 final Global global = context.createGlobal(); |
152 final ScriptEnvironment env = context.getEnv(); |
153 final ScriptEnvironment env = context.getEnv(); |
153 final List<String> files = env.getFiles(); |
154 final List<String> files = env.getFiles(); |
154 if (files.isEmpty()) { |
155 if (files.isEmpty()) { |
155 return readEvalPrint(context, global); |
156 return readEvalPrint(context, global); |
156 } |
157 } |
229 * @param files the list of script files to compile |
230 * @param files the list of script files to compile |
230 * |
231 * |
231 * @return error code |
232 * @return error code |
232 * @throws IOException when any script file read results in I/O error |
233 * @throws IOException when any script file read results in I/O error |
233 */ |
234 */ |
234 private static int compileScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException { |
235 private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException { |
235 final ScriptObject oldGlobal = Context.getGlobal(); |
236 final Global oldGlobal = Context.getGlobal(); |
236 final boolean globalChanged = (oldGlobal != global); |
237 final boolean globalChanged = (oldGlobal != global); |
237 final ScriptEnvironment env = context.getEnv(); |
238 final ScriptEnvironment env = context.getEnv(); |
238 try { |
239 try { |
239 if (globalChanged) { |
240 if (globalChanged) { |
240 Context.setGlobal(global); |
241 Context.setGlobal(global); |
279 * @param files the list of script files to run |
280 * @param files the list of script files to run |
280 * |
281 * |
281 * @return error code |
282 * @return error code |
282 * @throws IOException when any script file read results in I/O error |
283 * @throws IOException when any script file read results in I/O error |
283 */ |
284 */ |
284 private int runScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException { |
285 private int runScripts(final Context context, final Global global, final List<String> files) throws IOException { |
285 final ScriptObject oldGlobal = Context.getGlobal(); |
286 final Global oldGlobal = Context.getGlobal(); |
286 final boolean globalChanged = (oldGlobal != global); |
287 final boolean globalChanged = (oldGlobal != global); |
287 try { |
288 try { |
288 if (globalChanged) { |
289 if (globalChanged) { |
289 Context.setGlobal(global); |
290 Context.setGlobal(global); |
290 } |
291 } |
337 * @param files the list of script files to provide |
338 * @param files the list of script files to provide |
338 * |
339 * |
339 * @return error code |
340 * @return error code |
340 * @throws IOException when any script file read results in I/O error |
341 * @throws IOException when any script file read results in I/O error |
341 */ |
342 */ |
342 private static int runFXScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException { |
343 private static int runFXScripts(final Context context, final Global global, final List<String> files) throws IOException { |
343 final ScriptObject oldGlobal = Context.getGlobal(); |
344 final Global oldGlobal = Context.getGlobal(); |
344 final boolean globalChanged = (oldGlobal != global); |
345 final boolean globalChanged = (oldGlobal != global); |
345 try { |
346 try { |
346 if (globalChanged) { |
347 if (globalChanged) { |
347 Context.setGlobal(global); |
348 Context.setGlobal(global); |
348 } |
349 } |
387 * @param context the nashorn context |
388 * @param context the nashorn context |
388 * @param global global scope object to use |
389 * @param global global scope object to use |
389 * @return return code |
390 * @return return code |
390 */ |
391 */ |
391 @SuppressWarnings("resource") |
392 @SuppressWarnings("resource") |
392 private static int readEvalPrint(final Context context, final ScriptObject global) { |
393 private static int readEvalPrint(final Context context, final Global global) { |
393 final String prompt = bundle.getString("shell.prompt"); |
394 final String prompt = bundle.getString("shell.prompt"); |
394 final BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); |
395 final BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); |
395 final PrintWriter err = context.getErr(); |
396 final PrintWriter err = context.getErr(); |
396 final ScriptObject oldGlobal = Context.getGlobal(); |
397 final Global oldGlobal = Context.getGlobal(); |
397 final boolean globalChanged = (oldGlobal != global); |
398 final boolean globalChanged = (oldGlobal != global); |
398 final ScriptEnvironment env = context.getEnv(); |
399 final ScriptEnvironment env = context.getEnv(); |
399 |
400 |
400 try { |
401 try { |
401 if (globalChanged) { |
402 if (globalChanged) { |