diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index a837cf982ca0..3fa4b8c2ae54 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -240,6 +240,10 @@ struct ScriptLoadInfo // resolution. RefPtr mCachePromise; + // The reader stream the cache entry should be filled from, for those cases + // when we're going to have an mCachePromise. + nsCOMPtr mCacheReadStream; + nsCOMPtr mChannel; char16_t* mScriptTextBuf; size_t mScriptTextLength; @@ -534,7 +538,6 @@ class ScriptLoaderRunnable final : public WorkerFeature nsCOMPtr mSyncLoopTarget; nsTArray mLoadInfos; RefPtr mCacheCreator; - nsCOMPtr mReader; bool mIsMainScript; WorkerScriptType mWorkerScriptType; bool mCanceled; @@ -641,7 +644,10 @@ private: // We synthesize the result code, but its never exposed to content. RefPtr ir = new mozilla::dom::InternalResponse(200, NS_LITERAL_CSTRING("OK")); - ir->SetBody(mReader); + ir->SetBody(loadInfo.mCacheReadStream); + // Drop our reference to the stream now that we've passed it along, so it + // doesn't hang around once the cache is done with it and keep data alive. + loadInfo.mCacheReadStream = nullptr; // Set the channel info of the channel on the response so that it's // saved in the cache. @@ -917,7 +923,8 @@ private: // In case we return early. loadInfo.mCacheStatus = ScriptLoadInfo::Cancel; - rv = NS_NewPipe(getter_AddRefs(mReader), getter_AddRefs(writer), 0, + rv = NS_NewPipe(getter_AddRefs(loadInfo.mCacheReadStream), + getter_AddRefs(writer), 0, UINT32_MAX, // unlimited size to avoid writer WOULD_BLOCK case true, false); // non-blocking reader, blocking writer if (NS_WARN_IF(NS_FAILED(rv))) {