8007629: Remove extraneous quit from shell.js
authorjlaskey
Wed, 06 Feb 2013 11:57:51 -0400
changeset 16219 ccf1c34f26d9
parent 16218 87059b530a33
child 16220 f5502e7b3b71
8007629: Remove extraneous quit from shell.js Reviewed-by: sundar, hannesw Contributed-by: james.laskey@oracle.com
nashorn/src/jdk/nashorn/api/scripting/resources/init.js
nashorn/src/jdk/nashorn/internal/objects/Global.java
nashorn/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java
nashorn/src/jdk/nashorn/tools/resources/shell.js
--- a/nashorn/src/jdk/nashorn/api/scripting/resources/init.js	Wed Feb 06 08:42:19 2013 -0400
+++ b/nashorn/src/jdk/nashorn/api/scripting/resources/init.js	Wed Feb 06 11:57:51 2013 -0400
@@ -119,7 +119,7 @@
         },
         toString: function() {
             return map.toString();
-        } 
+        }
     });
 }
 
@@ -705,27 +705,6 @@
     $exit = process.exitValue();
 }
 
-/**
- * Exit the shell program.
- *
- * @param exitCode integer code returned to OS shell.
- * optional, defaults to 0
- */
-function exit(code) {
-    if (code) {
-        java.lang.System.exit(code + 0);
-    } else {
-        java.lang.System.exit(0);
-    }
-}
-
-/**
- * synonym for exit
- */
-function quit(code) {
-    exit(code);
-}
-
 // XML utilities
 
 /**
--- a/nashorn/src/jdk/nashorn/internal/objects/Global.java	Wed Feb 06 08:42:19 2013 -0400
+++ b/nashorn/src/jdk/nashorn/internal/objects/Global.java	Wed Feb 06 11:57:51 2013 -0400
@@ -115,6 +115,14 @@
     @Property(attributes = Attribute.NOT_ENUMERABLE)
     public Object load;
 
+    /** Nashorn extension: global.exit */
+    @Property(attributes = Attribute.NOT_ENUMERABLE)
+    public Object exit;
+
+    /** Nashorn extension: global.quit */
+    @Property(attributes = Attribute.NOT_ENUMERABLE)
+    public Object quit;
+
     /** Value property NaN of the Global Object - ECMA 15.1.1.1 NaN */
     @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
     public final Object NaN = Double.NaN;
@@ -333,6 +341,7 @@
     private static final MethodHandle PRINT   = findOwnMH("print",   Object.class, Object.class, Object[].class);
     private static final MethodHandle PRINTLN = findOwnMH("println", Object.class, Object.class, Object[].class);
     private static final MethodHandle LOAD    = findOwnMH("load",    Object.class, Object.class, Object.class);
+    private static final MethodHandle EXIT    = findOwnMH("exit",    Object.class, Object.class, Object.class);
 
     /**
      * Constructor
@@ -688,6 +697,19 @@
         return global.getContext().load(scope, source);
     }
 
+    /**
+     * Global exit and quit implementation - Nashorn extension: perform a {@code System.exit} call from the script
+     *
+     * @param self  self reference
+     * @param code  exit code
+     *
+     * @return undefined (will never be reacheD)
+     */
+    public static Object exit(final Object self, final Object code) {
+        System.exit(JSType.toInt32(code));
+        return UNDEFINED;
+    }
+
     ScriptObject getFunctionPrototype() {
         return ScriptFunction.getPrototype(builtinFunction);
     }
@@ -1320,6 +1342,8 @@
         this.unescape           = ScriptFunctionImpl.makeFunction("unescape",   GlobalFunctions.UNESCAPE);
         this.print              = ScriptFunctionImpl.makeFunction("print",      getContext()._print_no_newline ? PRINT : PRINTLN);
         this.load               = ScriptFunctionImpl.makeFunction("load",       LOAD);
+        this.exit               = ScriptFunctionImpl.makeFunction("exit",       EXIT);
+        this.quit               = ScriptFunctionImpl.makeFunction("quit",       EXIT);
 
         // built-in constructors
         this.builtinArray     = (ScriptFunction)initConstructor("Array");
@@ -1454,9 +1478,6 @@
         value = ScriptFunctionImpl.makeFunction("readFully", ScriptingFunctions.READFULLY);
         addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value);
 
-        value = ScriptFunctionImpl.makeFunction("quit", ScriptingFunctions.QUIT);
-        addOwnProperty("quit", Attribute.NOT_ENUMERABLE, value);
-
         final String execName = ScriptingFunctions.EXEC_NAME;
         value = ScriptFunctionImpl.makeFunction(execName, ScriptingFunctions.EXEC);
         addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value);
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Wed Feb 06 08:42:19 2013 -0400
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Wed Feb 06 11:57:51 2013 -0400
@@ -53,10 +53,7 @@
     /** Handle to implementation of {@link ScriptingFunctions#readFully} - Nashorn extension */
     public static final MethodHandle READFULLY = findOwnMH("readFully",     Object.class, Object.class, Object.class);
 
-    /** Handle to implementation of {@link ScriptingFunctions#quit} - Nashorn extension */
-    public static final MethodHandle QUIT = findOwnMH("quit",     Object.class, Object.class, Object.class);
-
-    /** Handle to implementation of {@link ScriptingFunctions#quit} - Nashorn extension */
+    /** Handle to implementation of {@link ScriptingFunctions#exec} - Nashorn extension */
     public static final MethodHandle EXEC = findOwnMH("exec",     Object.class, Object.class, Object.class, Object.class);
 
     /** Names of special properties used by $EXEC API. */
@@ -115,19 +112,6 @@
     }
 
     /**
-     * Nashorn extension: perform a {@code System.exit} call from the script
-     *
-     * @param self  self reference
-     * @param code  exit code
-     *
-     * @return undefined (will never be reacheD)
-     */
-    public static Object quit(final Object self, final Object code) {
-        System.exit(JSType.toInt32(code));
-        return UNDEFINED;
-    }
-
-    /**
      * Nashorn extension: exec a string in a separate process.
      *
      * @param self   self reference
--- a/nashorn/src/jdk/nashorn/tools/resources/shell.js	Wed Feb 06 08:42:19 2013 -0400
+++ b/nashorn/src/jdk/nashorn/tools/resources/shell.js	Wed Feb 06 11:57:51 2013 -0400
@@ -81,18 +81,3 @@
     writable: true,
     configurable: true
 });
-
-
-/**
- * Elegantly exits the current session
- */
-if (!quit) {
-Object.defineProperty(this, "quit", {
-    value: function quit() {
-        java.lang.System.exit(0);
-    },
-    enumerable: false,
-    writable: true,
-    configurable: true
-});
-}