changeset 505:bd0174b1a42f

8023210: jjs tools should support a mode where it will load few command line scripts and then entering into interactive shell Reviewed-by: hannesw, attila, lagergren, jlaskey
author sundar
date Mon, 19 Aug 2013 17:16:54 +0530
parents 36fb36217e1d
children e628aefac504 dbb0a20a6f27
files src/jdk/nashorn/internal/runtime/options/Options.java src/jdk/nashorn/tools/Shell.java
diffstat 2 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/runtime/options/Options.java	Fri Aug 16 18:51:53 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/options/Options.java	Mon Aug 19 17:16:54 2013 +0530
@@ -408,13 +408,13 @@
         final LinkedList<String> argList = new LinkedList<>();
         Collections.addAll(argList, args);
 
-    final String extra = getStringProperty(NASHORN_ARGS_PROPERTY, null);
-    if (extra != null) {
-        final StringTokenizer st = new StringTokenizer(extra);
-        while (st.hasMoreTokens()) {
-        argList.add(st.nextToken());
+        final String extra = getStringProperty(NASHORN_ARGS_PROPERTY, null);
+        if (extra != null) {
+            final StringTokenizer st = new StringTokenizer(extra);
+            while (st.hasMoreTokens()) {
+                argList.add(st.nextToken());
+            }
         }
-    }
 
         while (!argList.isEmpty()) {
             final String arg = argList.remove(0);
@@ -431,8 +431,9 @@
                 continue;
             }
 
-            // if it doesn't start with -, it's a file
-            if (!arg.startsWith("-")) {
+            // If it doesn't start with -, it's a file. But, if it is just "-",
+            // then it is a file representing standard input.
+            if (!arg.startsWith("-") || arg.length() == 1) {
                 files.add(arg);
                 continue;
             }
--- a/src/jdk/nashorn/tools/Shell.java	Fri Aug 16 18:51:53 2013 +0200
+++ b/src/jdk/nashorn/tools/Shell.java	Mon Aug 19 17:16:54 2013 +0530
@@ -292,6 +292,14 @@
 
             // For each file on the command line.
             for (final String fileName : files) {
+                if ("-".equals(fileName)) {
+                    final int res = readEvalPrint(context, global);
+                    if (res != SUCCESS) {
+                        return res;
+                    }
+                    continue;
+                }
+
                 final File file = new File(fileName);
                 final ScriptFunction script = context.compileScript(new Source(fileName, file.toURI().toURL()), global);
                 if (script == null || errors.getNumberOfErrors() != 0) {