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 243679 6d9a99b090f5
parent 243678 8f1e0a224fb4
child 243680 a6b21fce4c12
push id4433
push userryanvm@gmail.com
push date2015-02-04 15:40 +0000
treeherdermozilla-beta@a6b21fce4c12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu, sledru
bugs1123394
milestone36.0
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
@@ -351,16 +351,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))
@@ -373,20 +379,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.
  */