Bug 1833790 - Ignore StrongWorkerRef callback if mWorkerRef is already cleared. r=dom-worker-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D180072
This commit is contained in:
Jens Stutte 2023-06-06 16:02:52 +00:00
parent 185a9f884d
commit a5cc86ed42

View file

@ -75,11 +75,18 @@ nsresult FetchStreamReader::Create(JSContext* aCx, nsIGlobalObject* aGlobal,
RefPtr<StrongWorkerRef> workerRef = StrongWorkerRef::Create(
workerPrivate, "FetchStreamReader", [streamReader]() {
MOZ_ASSERT(streamReader);
MOZ_ASSERT(streamReader->mWorkerRef);
streamReader->CloseAndRelease(
streamReader->mWorkerRef->Private()->GetJSContext(),
NS_ERROR_DOM_INVALID_STATE_ERR);
// mAsyncWaitWorkerRef may keep the (same) StrongWorkerRef alive even
// when mWorkerRef has already been nulled out by a previous call to
// CloseAndRelease, we can just safely ignore this callback then
// (as would the CloseAndRelease do on a second call).
if (streamReader->mWorkerRef) {
streamReader->CloseAndRelease(
streamReader->mWorkerRef->Private()->GetJSContext(),
NS_ERROR_DOM_INVALID_STATE_ERR);
} else {
MOZ_DIAGNOSTIC_ASSERT(streamReader->mAsyncWaitWorkerRef);
}
});
if (NS_WARN_IF(!workerRef)) {