From 0a791285af96d1d7d64249045275ea42e7e7d3a7 Mon Sep 17 00:00:00 2001 From: Brian Hackett Date: Mon, 16 Sep 2019 20:17:17 +0000 Subject: [PATCH] Bug 1575306 - Suppress reporting of uncaught testing sentinel, r=bzbarsky. Differential Revision: https://phabricator.services.mozilla.com/D45964 --HG-- extra : moz-landing-system : lando --- dom/chrome-webidl/PromiseDebugging.webidl | 5 +++-- dom/promise/PromiseDebugging.cpp | 12 +++++++++--- toolkit/modules/tests/modules/PromiseTestUtils.jsm | 2 ++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dom/chrome-webidl/PromiseDebugging.webidl b/dom/chrome-webidl/PromiseDebugging.webidl index 5a4dde4397ef..3bc291728f4e 100644 --- a/dom/chrome-webidl/PromiseDebugging.webidl +++ b/dom/chrome-webidl/PromiseDebugging.webidl @@ -32,13 +32,14 @@ enum PromiseDebuggingState { "pending", "fulfilled", "rejected" }; callback interface UncaughtRejectionObserver { /** * A Promise has been left in `rejected` state and is the - * last in its chain. + * last in its chain. If this callback returns true, the rejection + * will not be reported. * * @param p A currently uncaught Promise. If `p` is is eventually * caught, i.e. if its `then` callback is called, `onConsumed` will * be called. */ - void onLeftUncaught(object p); + boolean onLeftUncaught(object p); /** * A Promise previously left uncaught is not the last in its diff --git a/dom/promise/PromiseDebugging.cpp b/dom/promise/PromiseDebugging.cpp index 77e070de4884..a5133cafa64f 100644 --- a/dom/promise/PromiseDebugging.cpp +++ b/dom/promise/PromiseDebugging.cpp @@ -265,14 +265,20 @@ void PromiseDebugging::FlushUncaughtRejectionsInternal() { continue; } + bool suppressReporting = false; for (size_t j = 0; j < observers.Length(); ++j) { RefPtr obs = static_cast(observers[j].get()); - obs->OnLeftUncaught(promise, IgnoreErrors()); + if (obs->OnLeftUncaught(promise, IgnoreErrors())) { + suppressReporting = true; + } + } + + if (!suppressReporting) { + JSAutoRealm ar(cx, promise); + Promise::ReportRejectedPromise(cx, promise); } - JSAutoRealm ar(cx, promise); - Promise::ReportRejectedPromise(cx, promise); } storage->mUncaughtRejections.clear(); diff --git a/toolkit/modules/tests/modules/PromiseTestUtils.jsm b/toolkit/modules/tests/modules/PromiseTestUtils.jsm index be8e00816efc..697890b156c1 100644 --- a/toolkit/modules/tests/modules/PromiseTestUtils.jsm +++ b/toolkit/modules/tests/modules/PromiseTestUtils.jsm @@ -102,7 +102,9 @@ var PromiseTestUtils = { this._ensureDOMPromiseRejectionsProcessedReason ) { observed = true; + return true; } + return false; }, onConsumed() {}, };