diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp index 7b2ddb2be277..aa472b8d7a7a 100644 --- a/dom/promise/Promise.cpp +++ b/dom/promise/Promise.cpp @@ -561,12 +561,16 @@ Promise::MaybeReportRejected() } // Now post an event to do the real reporting async - NS_DispatchToMainThread( + // Since Promises preserve their wrapper, it is essential to nsRefPtr<> the + // AsyncErrorReporter, otherwise if the call to DispatchToMainThread fails, it + // will leak. See Bug 958684. + nsRefPtr r = new AsyncErrorReporter(JS_GetObjectRuntime(&mResult.toObject()), report, nullptr, isChromeError, - win)); + win); + NS_DispatchToMainThread(r); } void