diff --git a/js/rhino/org/mozilla/javascript/tools/shell/Global.java b/js/rhino/org/mozilla/javascript/tools/shell/Global.java index 49f1aa672fc9..45b9a15c9d5f 100644 --- a/js/rhino/org/mozilla/javascript/tools/shell/Global.java +++ b/js/rhino/org/mozilla/javascript/tools/shell/Global.java @@ -127,7 +127,13 @@ public class Global extends ImporterTopLevel { * * This method is defined as a JavaScript function. */ - public static void quit() { + public static void quit(Context cx, Scriptable thisObj, + Object[] args, Function funObj) + { + + if (args.length > 0) + Main.global.exitCode = (int) Context.toNumber(args[0]); + Main.global.quitting = true; } @@ -277,6 +283,7 @@ public class Global extends ImporterTopLevel { boolean debug = false; boolean processStdin = true; boolean quitting; + int exitCode = 0; NativeArray history; boolean showDebuggerUI = false; } diff --git a/js/rhino/org/mozilla/javascript/tools/shell/Main.java b/js/rhino/org/mozilla/javascript/tools/shell/Main.java index 2c5c6ff34035..bf3f148bbae8 100644 --- a/js/rhino/org/mozilla/javascript/tools/shell/Main.java +++ b/js/rhino/org/mozilla/javascript/tools/shell/Main.java @@ -21,6 +21,7 @@ * Contributor(s): * Patrick Beard * Norris Boyd + * Rob Ginda * Kurt Westerfeld * * Alternatively, the contents of this file may be used under the @@ -137,6 +138,7 @@ public class Main { processSource(cx, args.length == 0 ? null : args[0]); cx.exit(); + System.exit(global.exitCode); } /** @@ -314,6 +316,7 @@ public class Main { Context.reportError(ToolErrorReporter.getMessage( "msg.couldnt.open", filename)); + global.exitCode = EXITCODE_FILE_NOT_FOUND; return; } catch (IOException ioe) { err.println(ioe.toString()); @@ -342,6 +345,7 @@ public class Main { catch (EcmaError ee) { String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ee.toString()); + global.exitCode = EXITCODE_RUNTIME_ERROR; if (ee.getSourceName() != null) { Context.reportError(msg, ee.getSourceName(), ee.getLineNumber(), null, 0); @@ -396,6 +400,8 @@ public class Main { static public InputStream in = System.in; static public PrintStream out = System.out; static public PrintStream err = System.err; + static private final int EXITCODE_RUNTIME_ERROR = 125; + static private final int EXITCODE_FILE_NOT_FOUND = 126; SourceTextManager debug_stm; //DebugManager debug_dm; // TODO: enable debugger diff --git a/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Global.java b/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Global.java index 49f1aa672fc9..45b9a15c9d5f 100644 --- a/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Global.java +++ b/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Global.java @@ -127,7 +127,13 @@ public class Global extends ImporterTopLevel { * * This method is defined as a JavaScript function. */ - public static void quit() { + public static void quit(Context cx, Scriptable thisObj, + Object[] args, Function funObj) + { + + if (args.length > 0) + Main.global.exitCode = (int) Context.toNumber(args[0]); + Main.global.quitting = true; } @@ -277,6 +283,7 @@ public class Global extends ImporterTopLevel { boolean debug = false; boolean processStdin = true; boolean quitting; + int exitCode = 0; NativeArray history; boolean showDebuggerUI = false; } diff --git a/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Main.java b/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Main.java index 2c5c6ff34035..bf3f148bbae8 100644 --- a/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Main.java +++ b/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Main.java @@ -21,6 +21,7 @@ * Contributor(s): * Patrick Beard * Norris Boyd + * Rob Ginda * Kurt Westerfeld * * Alternatively, the contents of this file may be used under the @@ -137,6 +138,7 @@ public class Main { processSource(cx, args.length == 0 ? null : args[0]); cx.exit(); + System.exit(global.exitCode); } /** @@ -314,6 +316,7 @@ public class Main { Context.reportError(ToolErrorReporter.getMessage( "msg.couldnt.open", filename)); + global.exitCode = EXITCODE_FILE_NOT_FOUND; return; } catch (IOException ioe) { err.println(ioe.toString()); @@ -342,6 +345,7 @@ public class Main { catch (EcmaError ee) { String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ee.toString()); + global.exitCode = EXITCODE_RUNTIME_ERROR; if (ee.getSourceName() != null) { Context.reportError(msg, ee.getSourceName(), ee.getLineNumber(), null, 0); @@ -396,6 +400,8 @@ public class Main { static public InputStream in = System.in; static public PrintStream out = System.out; static public PrintStream err = System.err; + static private final int EXITCODE_RUNTIME_ERROR = 125; + static private final int EXITCODE_FILE_NOT_FOUND = 126; SourceTextManager debug_stm; //DebugManager debug_dm; // TODO: enable debugger