Bug 1123394 - Stop spurious re-entry of shell interrupt callback. r=shu, a=sledru
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 21 Jan 2015 10:53:32 +0000
changeset 240481 6b38a91ae086f02d92f1dec83d97d95a78d35734
parent 240480 17acc8fbe6b4e95c20a2d49b946cb2eb072a97ee
child 240482 f9d325184938e576ce29095891b9ce88a1c7749e
push id7565
push userryanvm@gmail.com
push dateWed, 04 Feb 2015 15:32:33 +0000
treeherdermozilla-aurora@d4082de0ab03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu, sledru
bugs1123394
milestone37.0a2
Bug 1123394 - Stop spurious re-entry of shell interrupt callback. r=shu, a=sledru
js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -352,16 +352,22 @@ GetContextData(JSContext *cx)
 }
 
 static bool
 ShellInterruptCallback(JSContext *cx)
 {
     if (!gServiceInterrupt)
         return true;
 
+    // Reset gServiceInterrupt. CancelExecution or InterruptIf will set it to
+    // true to distinguish watchdog or user triggered interrupts.
+    // Do this first to prevent other interrupts that may occur while the
+    // user-supplied callback is executing from re-entering the handler.
+    gServiceInterrupt = false;
+
     bool result;
     RootedValue interruptFunc(cx, *gInterruptFunc);
     if (!interruptFunc.isNull()) {
         JS::AutoSaveExceptionState savedExc(cx);
         JSAutoCompartment ac(cx, &interruptFunc.toObject());
         RootedValue rval(cx);
         if (!JS_CallFunctionValue(cx, JS::NullPtr(), interruptFunc,
                                   JS::HandleValueArray::empty(), &rval))
@@ -374,20 +380,16 @@ ShellInterruptCallback(JSContext *cx)
             result = false;
     } else {
         result = false;
     }
 
     if (!result && gExitCode == 0)
         gExitCode = EXITCODE_TIMEOUT;
 
-    // Reset gServiceInterrupt. CancelExecution or InterruptIf will set it to
-    // true to distinguish watchdog or user triggered interrupts.
-    gServiceInterrupt = false;
-
     return result;
 }
 
 /*
  * Some UTF-8 files, notably those written using Notepad, have a Unicode
  * Byte-Order-Mark (BOM) as their first character. This is useless (byte-order
  * is meaningless for UTF-8) but causes a syntax error unless we skip it.
  */