Bug 1773237 - Mark ignored promise as handled to avoid spurious unhandled rejection error r=evilpie

Differential Revision: https://phabricator.services.mozilla.com/D158589
This commit is contained in:
Matthew Gaudet 2022-10-24 19:53:15 +00:00
parent 0333dda462
commit 242794868d
3 changed files with 19 additions and 1 deletions

View File

@ -146,10 +146,16 @@ void FetchStreamReader::CloseAndRelease(JSContext* aCx, nsresult aStatus) {
// comments in ReadableStream::cancel() conveying the spec, step 2 of
// 3.4.3 that specified ReadableStreamCancel is: If stream.[[state]] is
// "closed", return a new promise resolved with undefined.
RefPtr<Promise> ignoredResultPromise =
RefPtr<Promise> cancelResultPromise =
MOZ_KnownLive(mReader)->Cancel(aCx, errorValue, ignoredError);
NS_WARNING_ASSERTION(!ignoredError.Failed(),
"Failed to cancel stream during close and release");
if (cancelResultPromise) {
bool setHandled = cancelResultPromise->SetAnyPromiseIsHandled();
NS_WARNING_ASSERTION(setHandled,
"Failed to mark cancel promise as handled.");
(void)setHandled;
}
}
// We don't want to propagate exceptions during the cleanup.

View File

@ -0,0 +1,11 @@
// This test fails if there is an unhandled promise rejection
var stream = new ReadableStream({
pull() {
return Promise.reject("foobar");
},
});
var response = new Response(stream);
var text = response.text().then(
() => {},
e => {}
);

View File

@ -19,3 +19,4 @@ skip-if =
tsan # Causes claim expired errors; see Bug 1770170.
run-sequentially = very high failure rate in parallel
[too-big-array-buffer.js]
[bug-1773237.js]