Bug 1575306 - Suppress reporting of uncaught testing sentinel, r=bzbarsky.

Differential Revision: https://phabricator.services.mozilla.com/D45964

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brian Hackett 2019-09-16 20:17:17 +00:00
parent 18ac180309
commit 0a791285af
3 changed files with 14 additions and 5 deletions

View File

@ -32,13 +32,14 @@ enum PromiseDebuggingState { "pending", "fulfilled", "rejected" };
callback interface UncaughtRejectionObserver { callback interface UncaughtRejectionObserver {
/** /**
* A Promise has been left in `rejected` state and is the * 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 * @param p A currently uncaught Promise. If `p` is is eventually
* caught, i.e. if its `then` callback is called, `onConsumed` will * caught, i.e. if its `then` callback is called, `onConsumed` will
* be called. * be called.
*/ */
void onLeftUncaught(object p); boolean onLeftUncaught(object p);
/** /**
* A Promise previously left uncaught is not the last in its * A Promise previously left uncaught is not the last in its

View File

@ -265,14 +265,20 @@ void PromiseDebugging::FlushUncaughtRejectionsInternal() {
continue; continue;
} }
bool suppressReporting = false;
for (size_t j = 0; j < observers.Length(); ++j) { for (size_t j = 0; j < observers.Length(); ++j) {
RefPtr<UncaughtRejectionObserver> obs = RefPtr<UncaughtRejectionObserver> obs =
static_cast<UncaughtRejectionObserver*>(observers[j].get()); static_cast<UncaughtRejectionObserver*>(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(); storage->mUncaughtRejections.clear();

View File

@ -102,7 +102,9 @@ var PromiseTestUtils = {
this._ensureDOMPromiseRejectionsProcessedReason this._ensureDOMPromiseRejectionsProcessedReason
) { ) {
observed = true; observed = true;
return true;
} }
return false;
}, },
onConsumed() {}, onConsumed() {},
}; };