From 0424de52a79d57132a35d450f6083df5a0cd48cf Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Mon, 23 Jan 2012 17:44:30 -0800 Subject: [PATCH] Bug 717417: Add 'terminate' shell primitive. r=jorendorff --- js/src/jit-test/tests/basic/terminate.js | 9 +++++++++ js/src/shell/js.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 js/src/jit-test/tests/basic/terminate.js diff --git a/js/src/jit-test/tests/basic/terminate.js b/js/src/jit-test/tests/basic/terminate.js new file mode 100644 index 000000000000..05b63431de45 --- /dev/null +++ b/js/src/jit-test/tests/basic/terminate.js @@ -0,0 +1,9 @@ +try { + terminate(); + assertEq("execution continued", "execution should not continue"); +} catch (x) { + assertEq("caught exception", "uncatchable"); +} finally { + assertEq("'finally' clause ran", "'finally' clause should not run"); +} +assertEq("top-level execution continued", "top-level execution should not continue"); diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 22ba64954f8b..ff9682b21a68 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -3958,6 +3958,13 @@ GetMaxArgs(JSContext *cx, uintN arg, jsval *vp) return JS_TRUE; } +static JSBool +Terminate(JSContext *cx, uintN arg, jsval *vp) +{ + JS_ClearPendingException(cx); + return JS_FALSE; +} + static JSFunctionSpec shell_functions[] = { JS_FN("version", Version, 0,0), JS_FN("revertVersion", RevertVersion, 0,0), @@ -4046,6 +4053,7 @@ static JSFunctionSpec shell_functions[] = { JS_FN("parseLegacyJSON",ParseLegacyJSON,1,0), JS_FN("enableStackWalkingAssertion",EnableStackWalkingAssertion,1,0), JS_FN("getMaxArgs", GetMaxArgs, 0,0), + JS_FN("terminate", Terminate, 0,0), JS_FS_END }; @@ -4200,6 +4208,8 @@ static const char *const shell_help_messages[] = { " assertion increases test duration by an order of magnitude, you shouldn't\n" " use this.", "getMaxArgs() Return the maximum number of supported args for a call.", +"terminate() Terminate JavaScript execution, as if we had run out of\n" +" memory or been terminated by the slow script dialog.", /* Keep these last: see the static assertion below. */ #ifdef MOZ_PROFILING