Wed, 06 Feb 2013 11:57:51 -0400
8007629: Remove extraneous quit from shell.js
Reviewed-by: sundar, hannesw
Contributed-by: james.laskey@oracle.com
1.1 --- a/src/jdk/nashorn/api/scripting/resources/init.js Wed Feb 06 08:42:19 2013 -0400 1.2 +++ b/src/jdk/nashorn/api/scripting/resources/init.js Wed Feb 06 11:57:51 2013 -0400 1.3 @@ -119,7 +119,7 @@ 1.4 }, 1.5 toString: function() { 1.6 return map.toString(); 1.7 - } 1.8 + } 1.9 }); 1.10 } 1.11 1.12 @@ -705,27 +705,6 @@ 1.13 $exit = process.exitValue(); 1.14 } 1.15 1.16 -/** 1.17 - * Exit the shell program. 1.18 - * 1.19 - * @param exitCode integer code returned to OS shell. 1.20 - * optional, defaults to 0 1.21 - */ 1.22 -function exit(code) { 1.23 - if (code) { 1.24 - java.lang.System.exit(code + 0); 1.25 - } else { 1.26 - java.lang.System.exit(0); 1.27 - } 1.28 -} 1.29 - 1.30 -/** 1.31 - * synonym for exit 1.32 - */ 1.33 -function quit(code) { 1.34 - exit(code); 1.35 -} 1.36 - 1.37 // XML utilities 1.38 1.39 /**
2.1 --- a/src/jdk/nashorn/internal/objects/Global.java Wed Feb 06 08:42:19 2013 -0400 2.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Wed Feb 06 11:57:51 2013 -0400 2.3 @@ -115,6 +115,14 @@ 2.4 @Property(attributes = Attribute.NOT_ENUMERABLE) 2.5 public Object load; 2.6 2.7 + /** Nashorn extension: global.exit */ 2.8 + @Property(attributes = Attribute.NOT_ENUMERABLE) 2.9 + public Object exit; 2.10 + 2.11 + /** Nashorn extension: global.quit */ 2.12 + @Property(attributes = Attribute.NOT_ENUMERABLE) 2.13 + public Object quit; 2.14 + 2.15 /** Value property NaN of the Global Object - ECMA 15.1.1.1 NaN */ 2.16 @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) 2.17 public final Object NaN = Double.NaN; 2.18 @@ -333,6 +341,7 @@ 2.19 private static final MethodHandle PRINT = findOwnMH("print", Object.class, Object.class, Object[].class); 2.20 private static final MethodHandle PRINTLN = findOwnMH("println", Object.class, Object.class, Object[].class); 2.21 private static final MethodHandle LOAD = findOwnMH("load", Object.class, Object.class, Object.class); 2.22 + private static final MethodHandle EXIT = findOwnMH("exit", Object.class, Object.class, Object.class); 2.23 2.24 /** 2.25 * Constructor 2.26 @@ -688,6 +697,19 @@ 2.27 return global.getContext().load(scope, source); 2.28 } 2.29 2.30 + /** 2.31 + * Global exit and quit implementation - Nashorn extension: perform a {@code System.exit} call from the script 2.32 + * 2.33 + * @param self self reference 2.34 + * @param code exit code 2.35 + * 2.36 + * @return undefined (will never be reacheD) 2.37 + */ 2.38 + public static Object exit(final Object self, final Object code) { 2.39 + System.exit(JSType.toInt32(code)); 2.40 + return UNDEFINED; 2.41 + } 2.42 + 2.43 ScriptObject getFunctionPrototype() { 2.44 return ScriptFunction.getPrototype(builtinFunction); 2.45 } 2.46 @@ -1320,6 +1342,8 @@ 2.47 this.unescape = ScriptFunctionImpl.makeFunction("unescape", GlobalFunctions.UNESCAPE); 2.48 this.print = ScriptFunctionImpl.makeFunction("print", getContext()._print_no_newline ? PRINT : PRINTLN); 2.49 this.load = ScriptFunctionImpl.makeFunction("load", LOAD); 2.50 + this.exit = ScriptFunctionImpl.makeFunction("exit", EXIT); 2.51 + this.quit = ScriptFunctionImpl.makeFunction("quit", EXIT); 2.52 2.53 // built-in constructors 2.54 this.builtinArray = (ScriptFunction)initConstructor("Array"); 2.55 @@ -1454,9 +1478,6 @@ 2.56 value = ScriptFunctionImpl.makeFunction("readFully", ScriptingFunctions.READFULLY); 2.57 addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value); 2.58 2.59 - value = ScriptFunctionImpl.makeFunction("quit", ScriptingFunctions.QUIT); 2.60 - addOwnProperty("quit", Attribute.NOT_ENUMERABLE, value); 2.61 - 2.62 final String execName = ScriptingFunctions.EXEC_NAME; 2.63 value = ScriptFunctionImpl.makeFunction(execName, ScriptingFunctions.EXEC); 2.64 addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value);
3.1 --- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Wed Feb 06 08:42:19 2013 -0400 3.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Wed Feb 06 11:57:51 2013 -0400 3.3 @@ -53,10 +53,7 @@ 3.4 /** Handle to implementation of {@link ScriptingFunctions#readFully} - Nashorn extension */ 3.5 public static final MethodHandle READFULLY = findOwnMH("readFully", Object.class, Object.class, Object.class); 3.6 3.7 - /** Handle to implementation of {@link ScriptingFunctions#quit} - Nashorn extension */ 3.8 - public static final MethodHandle QUIT = findOwnMH("quit", Object.class, Object.class, Object.class); 3.9 - 3.10 - /** Handle to implementation of {@link ScriptingFunctions#quit} - Nashorn extension */ 3.11 + /** Handle to implementation of {@link ScriptingFunctions#exec} - Nashorn extension */ 3.12 public static final MethodHandle EXEC = findOwnMH("exec", Object.class, Object.class, Object.class, Object.class); 3.13 3.14 /** Names of special properties used by $EXEC API. */ 3.15 @@ -115,19 +112,6 @@ 3.16 } 3.17 3.18 /** 3.19 - * Nashorn extension: perform a {@code System.exit} call from the script 3.20 - * 3.21 - * @param self self reference 3.22 - * @param code exit code 3.23 - * 3.24 - * @return undefined (will never be reacheD) 3.25 - */ 3.26 - public static Object quit(final Object self, final Object code) { 3.27 - System.exit(JSType.toInt32(code)); 3.28 - return UNDEFINED; 3.29 - } 3.30 - 3.31 - /** 3.32 * Nashorn extension: exec a string in a separate process. 3.33 * 3.34 * @param self self reference
4.1 --- a/src/jdk/nashorn/tools/resources/shell.js Wed Feb 06 08:42:19 2013 -0400 4.2 +++ b/src/jdk/nashorn/tools/resources/shell.js Wed Feb 06 11:57:51 2013 -0400 4.3 @@ -81,18 +81,3 @@ 4.4 writable: true, 4.5 configurable: true 4.6 }); 4.7 - 4.8 - 4.9 -/** 4.10 - * Elegantly exits the current session 4.11 - */ 4.12 -if (!quit) { 4.13 -Object.defineProperty(this, "quit", { 4.14 - value: function quit() { 4.15 - java.lang.System.exit(0); 4.16 - }, 4.17 - enumerable: false, 4.18 - writable: true, 4.19 - configurable: true 4.20 -}); 4.21 -}