Skip to content

Commit

Permalink
Bug 1814644 - Remove GetIncumbentGlobal use in SetUpReadableByteStrea…
Browse files Browse the repository at this point in the history
…mController r=smaug

That was the only case that Promise::CreateInfallible may possibly get nullptr in dom/streams case, so it now just asserts the existence of nsIGlobalObject.

Differential Revision: https://phabricator.services.mozilla.com/D168678
  • Loading branch information
saschanaz committed Feb 2, 2023
1 parent b64c99f commit 22e6361
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions dom/promise/Promise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,19 @@ already_AddRefed<Promise> Promise::Create(
already_AddRefed<Promise> Promise::CreateInfallible(
nsIGlobalObject* aGlobal,
PropagateUserInteraction aPropagateUserInteraction) {
MOZ_ASSERT(aGlobal);
RefPtr<Promise> p = new Promise(aGlobal);
IgnoredErrorResult rv;
p->CreateWrapper(rv, aPropagateUserInteraction);
if (rv.Failed() && rv.ErrorCodeIs(NS_ERROR_OUT_OF_MEMORY)) {
MOZ_CRASH("Out of memory");
}

// We may have failed to init the wrapper here, either because nsIGlobalObject
// was null (e.g. when caller passed GetIncumbentGlobal()) or had null
// GlobalJSObject. We consider JSContext is dead here, which means:
// We may have failed to init the wrapper here, because nsIGlobalObject had
// null GlobalJSObject. In that case we consider the JS realm is dead, which
// means:
// 1. This promise can't be settled.
// 2. Nothing can subscribe this promise anymore from that context.
// 2. Nothing can subscribe this promise anymore from that realm.
// Such condition makes this promise a no-op object.
(void)NS_WARN_IF(!p->PromiseObj());

Expand Down
2 changes: 1 addition & 1 deletion dom/streams/ReadableByteStreamController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,7 @@ void SetUpReadableByteStreamController(

// Let startPromise be a promise resolved with startResult.
RefPtr<Promise> startPromise =
Promise::CreateInfallible(GetIncumbentGlobal());
Promise::CreateInfallible(aStream->GetParentObject());
startPromise->MaybeResolve(startResult);

// Step 16+17
Expand Down

0 comments on commit 22e6361

Please sign in to comment.