From b5b99e684e04d2ef9676eb08579e4fdfc14ca6a0 Mon Sep 17 00:00:00 2001 From: Paolo Amadini Date: Thu, 6 Nov 2014 14:00:06 +0000 Subject: [PATCH] Bug 1094248 - Process remaining Promise microtasks before blocking inside a nested event loop in the main thread. r=bz --- js/xpconnect/src/nsXPConnect.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index cba5414e2c9a..049557815087 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -1026,6 +1026,13 @@ NS_IMETHODIMP nsXPConnect::OnProcessNextEvent(nsIThreadInternal *aThread, bool aMayWait, uint32_t aRecursionDepth) { + // If ProcessNextEvent was called during a Promise "then" callback, we + // must process any pending microtasks before blocking in the event loop, + // otherwise we may deadlock until an event enters the queue later. + if (aMayWait) { + Promise::PerformMicroTaskCheckpoint(); + } + // Record this event. mEventDepth++;