Bug 1291257, ensure slow script dialog is triggered when handling mutation observer callbacks, r=bholley
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Fri, 05 Aug 2016 23:07:56 +0300
changeset 308394 0ac120171cecdd3b347e84156fab9d2f49a204d9
parent 308393 0ceb4834ee8f544ba908031e279963c39be3b47b
child 308423 12b31a12d10a05db2aac65997c9bee7fe3f60b94
push id80333
push useropettay@mozilla.com
push dateFri, 05 Aug 2016 20:54:10 +0000
treeherdermozilla-inbound@0ac120171cec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1291257
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1291257, ensure slow script dialog is triggered when handling mutation observer callbacks, r=bholley
dom/base/nsDOMMutationObserver.cpp
--- a/dom/base/nsDOMMutationObserver.cpp
+++ b/dom/base/nsDOMMutationObserver.cpp
@@ -880,16 +880,21 @@ nsDOMMutationObserver::HandleMutationsIn
     // after previous mutations are handled. But in case some
     // callback calls a sync API, which spins the eventloop, we need to still
     // process other mutations happening during that sync call.
     // This does *not* catch all cases, but should work for stuff running
     // in separate tabs.
     return;
   }
 
+  // We need the AutoSafeJSContext to ensure the slow script dialog is
+  // triggered. AutoSafeJSContext does that by pushing JSAutoRequest to stack.
+  // This needs to be outside the while loop.
+  AutoSafeJSContext cx;
+
   nsTArray<RefPtr<nsDOMMutationObserver> >* suppressedObservers = nullptr;
 
   while (sScheduledMutationObservers) {
     AutoTArray<RefPtr<nsDOMMutationObserver>, 4>* observers =
       sScheduledMutationObservers;
     sScheduledMutationObservers = nullptr;
     for (uint32_t i = 0; i < observers->Length(); ++i) {
       sCurrentObserver = static_cast<nsDOMMutationObserver*>((*observers)[i]);
@@ -900,16 +905,17 @@ nsDOMMutationObserver::HandleMutationsIn
           suppressedObservers = new nsTArray<RefPtr<nsDOMMutationObserver> >;
         }
         if (!suppressedObservers->Contains(sCurrentObserver)) {
           suppressedObservers->AppendElement(sCurrentObserver);
         }
       }
     }
     delete observers;
+    JS_CheckForInterrupt(cx);
   }
 
   if (suppressedObservers) {
     for (uint32_t i = 0; i < suppressedObservers->Length(); ++i) {
       static_cast<nsDOMMutationObserver*>(suppressedObservers->ElementAt(i))->
         RescheduleForRun();
     }
     delete suppressedObservers;