Bug 1249351 part 1. When doing importScripts of multiple scripts in a service worker, make sure to track the cache streams per-loadinfo, instead of trying to make them all wait on the same stream. r=bkelly
This commit is contained in:
@@ -240,6 +240,10 @@ struct ScriptLoadInfo
|
|||||||
// resolution.
|
// resolution.
|
||||||
RefPtr<Promise> mCachePromise;
|
RefPtr<Promise> mCachePromise;
|
||||||
|
|
||||||
|
// The reader stream the cache entry should be filled from, for those cases
|
||||||
|
// when we're going to have an mCachePromise.
|
||||||
|
nsCOMPtr<nsIInputStream> mCacheReadStream;
|
||||||
|
|
||||||
nsCOMPtr<nsIChannel> mChannel;
|
nsCOMPtr<nsIChannel> mChannel;
|
||||||
char16_t* mScriptTextBuf;
|
char16_t* mScriptTextBuf;
|
||||||
size_t mScriptTextLength;
|
size_t mScriptTextLength;
|
||||||
@@ -534,7 +538,6 @@ class ScriptLoaderRunnable final : public WorkerFeature
|
|||||||
nsCOMPtr<nsIEventTarget> mSyncLoopTarget;
|
nsCOMPtr<nsIEventTarget> mSyncLoopTarget;
|
||||||
nsTArray<ScriptLoadInfo> mLoadInfos;
|
nsTArray<ScriptLoadInfo> mLoadInfos;
|
||||||
RefPtr<CacheCreator> mCacheCreator;
|
RefPtr<CacheCreator> mCacheCreator;
|
||||||
nsCOMPtr<nsIInputStream> mReader;
|
|
||||||
bool mIsMainScript;
|
bool mIsMainScript;
|
||||||
WorkerScriptType mWorkerScriptType;
|
WorkerScriptType mWorkerScriptType;
|
||||||
bool mCanceled;
|
bool mCanceled;
|
||||||
@@ -641,7 +644,10 @@ private:
|
|||||||
// We synthesize the result code, but its never exposed to content.
|
// We synthesize the result code, but its never exposed to content.
|
||||||
RefPtr<mozilla::dom::InternalResponse> ir =
|
RefPtr<mozilla::dom::InternalResponse> ir =
|
||||||
new mozilla::dom::InternalResponse(200, NS_LITERAL_CSTRING("OK"));
|
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
|
// Set the channel info of the channel on the response so that it's
|
||||||
// saved in the cache.
|
// saved in the cache.
|
||||||
@@ -917,7 +923,8 @@ private:
|
|||||||
// In case we return early.
|
// In case we return early.
|
||||||
loadInfo.mCacheStatus = ScriptLoadInfo::Cancel;
|
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
|
UINT32_MAX, // unlimited size to avoid writer WOULD_BLOCK case
|
||||||
true, false); // non-blocking reader, blocking writer
|
true, false); // non-blocking reader, blocking writer
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
|||||||
Reference in New Issue
Block a user