8023210: jjs tools should support a mode where it will load few command line scripts and then entering into interactive shell
authorsundar
Mon, 19 Aug 2013 17:16:54 +0530
changeset 19473 8b2ee6bf9c62
parent 19472 9476460521b3
child 19474 70c91fc38cb4
child 19617 310246d552b7
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
nashorn/src/jdk/nashorn/internal/runtime/options/Options.java
nashorn/src/jdk/nashorn/tools/Shell.java
--- a/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java	Fri Aug 16 18:51:53 2013 +0200
+++ b/nashorn/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/nashorn/src/jdk/nashorn/tools/Shell.java	Fri Aug 16 18:51:53 2013 +0200
+++ b/nashorn/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) {