8021773: print function as defined by jrunscript's init.js script is incompatible with nashorn's definition
authorsundar
Mon, 29 Jul 2013 21:39:21 +0530
changeset 19064 5a45b684b8b1
parent 19063 0aa7087394a1
child 19065 f7c941aa63ee
8021773: print function as defined by jrunscript's init.js script is incompatible with nashorn's definition Reviewed-by: hannesw, lagergren
jdk/src/share/classes/com/sun/tools/script/shell/init.js
--- a/jdk/src/share/classes/com/sun/tools/script/shell/init.js	Sat Jul 27 12:26:01 2013 -0700
+++ b/jdk/src/share/classes/com/sun/tools/script/shell/init.js	Mon Jul 29 21:39:21 2013 +0530
@@ -332,7 +332,7 @@
  * @param str input from which script is loaded and evaluated
  */
 if (typeof(load) == 'undefined') {
-    var load = function(str) {
+    this.load = function(str) {
         var stream = inStream(str);
         var bstream = new BufferedInputStream(stream);
         var reader = new BufferedReader(new InputStreamReader(bstream));
@@ -712,7 +712,7 @@
      * @param exitCode integer code returned to OS shell.
      * optional, defaults to 0
      */
-    var exit = function (code) {
+    this.exit = function (code) {
         if (code) {
             java.lang.System.exit(code + 0);
         } else {
@@ -725,7 +725,7 @@
     /**
      * synonym for exit
      */
-    var quit = function (code) {
+    this.quit = function (code) {
         exit(code);
     }
 }
@@ -881,7 +881,7 @@
      * @param format string to format the rest of the print items
      * @param args variadic argument list
      */
-    var printf = function (format, args/*, more args*/) {  
+    this.printf = function (format, args/*, more args*/) {  
         var array = java.lang.reflect.Array.newInstance(java.lang.Object, 
                     arguments.length - 1);
         for (var i = 0; i < array.length; i++) {
@@ -921,25 +921,7 @@
 }
 
 if (typeof(println) == 'undefined') {
-    var print = function(str, newline) {
-        if (typeof(str) == 'undefined') {
-            str = 'undefined';
-        } else if (str == null) {
-            str = 'null';
-        }
-
-        if (!(out instanceof java.io.PrintWriter)) {
-            out = new java.io.PrintWriter(out);
-        }
+    // just synonym to print
+    this.println = print;
+}
 
-        out.print(String(str));
-        if (newline) {
-            out.print('\n');
-        }
-        out.flush();
-    }
-
-    var println = function(str) {
-        print(str, true);
-    };
-}