Bug 717417: Add 'terminate' shell primitive. r=jorendorff
authorJim Blandy <jimb@mozilla.com>
Mon, 23 Jan 2012 17:44:30 -0800
changeset 86390 93602e4ac4d9f8bce5594f72bfdfaa2190da2c24
parent 86389 6c5229914ef986dc2cc98bdf9336c6b5fde26c67
child 86391 650f4fa9ca1244e9538edb4daabebbc805e6eee5
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs717417
milestone12.0a1
Bug 717417: Add 'terminate' shell primitive. r=jorendorff
js/src/jit-test/tests/basic/terminate.js
js/src/shell/js.cpp
new file mode 100644
--- /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");
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -3953,16 +3953,23 @@ EnableStackWalkingAssertion(JSContext *c
 
 static JSBool
 GetMaxArgs(JSContext *cx, uintN arg, jsval *vp)
 {
     JS_SET_RVAL(cx, vp, INT_TO_JSVAL(StackSpace::ARGS_LENGTH_MAX));
     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),
     JS_FN("options",        Options,        0,0),
     JS_FN("load",           Load,           1,0),
     JS_FN("evaluate",       Evaluate,       1,0),
     JS_FN("run",            Run,            1,0),
     JS_FN("readline",       ReadLine,       0,0),
@@ -4041,16 +4048,17 @@ static JSFunctionSpec shell_functions[] 
     JS_FN("mjitdatastats",  MJitDataStats,  0,0),
 #endif
     JS_FN("mjitChunkLimit", MJitChunkLimit, 1,0),
     JS_FN("stringstats",    StringStats,    0,0),
     JS_FN("newGlobal",      NewGlobal,      1,0),
     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
 };
 
 static const char shell_help_header[] =
 "Command                  Description\n"
 "=======                  ===========\n";
 
 static const char *const shell_help_messages[] = {
@@ -4195,16 +4203,18 @@ static const char *const shell_help_mess
 "parseLegacyJSON(str)     Parse str as legacy JSON, returning the result if the\n"
 "                         parse succeeded and throwing a SyntaxError if not.",
 "enableStackWalkingAssertion(enabled)\n"
 "  Enables or disables a particularly expensive assertion in stack-walking\n"
 "  code.  If your test isn't ridiculously thorough, such that performing this\n"
 "  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
 "startProfiling([profileName])\n"
 "                         Start a profiling session\n"
 "                         Profiler must be running with programatic sampling",
 "stopProfiling([profileName])\n"
 "                         Stop a running profiling session",