Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp
Warning:line 1001, column 14
Value stored to 'rv' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_dom_serviceworkers2.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dom/serviceworkers -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dom/serviceworkers -resource-dir /usr/lib/llvm-18/lib/clang/18 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dom/serviceworkers -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/base -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/protocol/http -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -fdeprecated-macro -ferror-limit 19 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-05-16-034744-15991-1 -x c++ Unified_cpp_dom_serviceworkers2.cpp
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7#include "ServiceWorkerScriptCache.h"
8
9#include "js/Array.h" // JS::GetArrayLength
10#include "js/PropertyAndElement.h" // JS_GetElement
11#include "js/Utility.h" // JS::FreePolicy
12#include "mozilla/TaskQueue.h"
13#include "mozilla/Unused.h"
14#include "mozilla/UniquePtr.h"
15#include "mozilla/dom/CacheBinding.h"
16#include "mozilla/dom/cache/CacheStorage.h"
17#include "mozilla/dom/cache/Cache.h"
18#include "mozilla/dom/Promise.h"
19#include "mozilla/dom/PromiseWorkerProxy.h"
20#include "mozilla/dom/ScriptLoader.h"
21#include "mozilla/dom/WorkerCommon.h"
22#include "mozilla/ipc/BackgroundUtils.h"
23#include "mozilla/ipc/PBackgroundSharedTypes.h"
24#include "mozilla/net/CookieJarSettings.h"
25#include "mozilla/ScopeExit.h"
26#include "mozilla/StaticPrefs_extensions.h"
27#include "nsICacheInfoChannel.h"
28#include "nsIHttpChannel.h"
29#include "nsIStreamLoader.h"
30#include "nsIThreadRetargetableRequest.h"
31#include "nsIUUIDGenerator.h"
32#include "nsIXPConnect.h"
33
34#include "nsIInputStreamPump.h"
35#include "nsIPrincipal.h"
36#include "nsIScriptSecurityManager.h"
37#include "nsContentUtils.h"
38#include "nsNetUtil.h"
39#include "ServiceWorkerManager.h"
40#include "nsStringStream.h"
41
42using mozilla::dom::cache::Cache;
43using mozilla::dom::cache::CacheStorage;
44using mozilla::ipc::PrincipalInfo;
45
46namespace mozilla::dom::serviceWorkerScriptCache {
47
48namespace {
49
50already_AddRefed<CacheStorage> CreateCacheStorage(JSContext* aCx,
51 nsIPrincipal* aPrincipal,
52 ErrorResult& aRv) {
53 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 53); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 53; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
54 MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPrincipal)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 54); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal" ")"
); do { *((volatile int*)__null) = 54; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
55
56 nsIXPConnect* xpc = nsContentUtils::XPConnect();
57 MOZ_ASSERT(xpc, "This should never be null!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(xpc)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(xpc))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("xpc" " (" "This should never be null!"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 57); AnnotateMozCrashReason("MOZ_ASSERT" "(" "xpc" ") (" "This should never be null!"
")"); do { *((volatile int*)__null) = 57; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
58 JS::Rooted<JSObject*> sandbox(aCx);
59 aRv = xpc->CreateSandbox(aCx, aPrincipal, sandbox.address());
60 if (NS_WARN_IF(aRv.Failed())NS_warn_if_impl(aRv.Failed(), "aRv.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 60)
) {
61 return nullptr;
62 }
63
64 // This is called when the JSContext is not in a realm, so CreateSandbox
65 // returned an unwrapped global.
66 MOZ_ASSERT(JS_IsGlobalObject(sandbox))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(JS_IsGlobalObject(sandbox))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(JS_IsGlobalObject(sandbox)))
), 0))) { do { } while (false); MOZ_ReportAssertionFailure("JS_IsGlobalObject(sandbox)"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 66); AnnotateMozCrashReason("MOZ_ASSERT" "(" "JS_IsGlobalObject(sandbox)"
")"); do { *((volatile int*)__null) = 66; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
67
68 nsCOMPtr<nsIGlobalObject> sandboxGlobalObject = xpc::NativeGlobal(sandbox);
69 if (!sandboxGlobalObject) {
70 aRv.Throw(NS_ERROR_FAILURE);
71 return nullptr;
72 }
73
74 // We assume private browsing is not enabled here. The ScriptLoader
75 // explicitly fails for private browsing so there should never be
76 // a service worker running in private browsing mode. Therefore if
77 // we are purging scripts or running a comparison algorithm we cannot
78 // be in private browsing.
79 //
80 // Also, bypass the CacheStorage trusted origin checks. The ServiceWorker
81 // has validated the origin prior to this point. All the information
82 // to revalidate is not available now.
83 return CacheStorage::CreateOnMainThread(cache::CHROME_ONLY_NAMESPACE,
84 sandboxGlobalObject, aPrincipal,
85 true /* force trusted origin */, aRv);
86}
87
88class CompareManager;
89class CompareCache;
90
91// This class downloads a URL from the network, compare the downloaded script
92// with an existing cache if provided, and report to CompareManager via calling
93// ComparisonFinished().
94class CompareNetwork final : public nsIStreamLoaderObserver,
95 public nsIRequestObserver {
96 public:
97 NS_DECL_ISUPPORTSpublic: virtual nsresult QueryInterface(const nsIID& aIID
, void** aInstancePtr) override; virtual MozExternalRefCountType
AddRef(void) override; virtual MozExternalRefCountType Release
(void) override; using HasThreadSafeRefCnt = std::false_type;
protected: nsAutoRefCnt mRefCnt; nsAutoOwningThread _mOwningThread
; public:
98 NS_DECL_NSISTREAMLOADEROBSERVERvirtual nsresult OnStreamComplete(nsIStreamLoader *loader, nsISupports
*ctxt, nsresult status, uint32_t resultLength, const uint8_t
*result) override;
99 NS_DECL_NSIREQUESTOBSERVERvirtual nsresult OnStartRequest(nsIRequest *aRequest) override
; virtual nsresult OnStopRequest(nsIRequest *aRequest, nsresult
aStatusCode) override;
100
101 CompareNetwork(CompareManager* aManager,
102 ServiceWorkerRegistrationInfo* aRegistration,
103 bool aIsMainScript)
104 : mManager(aManager),
105 mRegistration(aRegistration),
106 mInternalHeaders(new InternalHeaders()),
107 mLoadFlags(nsIChannel::LOAD_BYPASS_SERVICE_WORKER),
108 mState(WaitingForInitialization),
109 mNetworkResult(NS_OK),
110 mCacheResult(NS_OK),
111 mIsMainScript(aIsMainScript),
112 mIsFromCache(false) {
113 MOZ_ASSERT(aManager)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aManager)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aManager))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aManager", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 113); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aManager" ")"
); do { *((volatile int*)__null) = 113; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
114 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 114); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 114; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
115 }
116
117 nsresult Initialize(nsIPrincipal* aPrincipal, const nsACString& aURL,
118 Cache* const aCache);
119
120 void Abort();
121
122 void NetworkFinish(nsresult aRv);
123
124 void CacheFinish(nsresult aRv);
125
126 const nsCString& URL() const {
127 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 127); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 127; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
128 return mURL;
129 }
130
131 const nsString& Buffer() const {
132 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 132); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 132; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
133 return mBuffer;
134 }
135
136 const ChannelInfo& GetChannelInfo() const { return mChannelInfo; }
137
138 already_AddRefed<InternalHeaders> GetInternalHeaders() const {
139 RefPtr<InternalHeaders> internalHeaders = mInternalHeaders;
140 return internalHeaders.forget();
141 }
142
143 UniquePtr<PrincipalInfo> TakePrincipalInfo() {
144 return std::move(mPrincipalInfo);
145 }
146
147 bool Succeeded() const { return NS_SUCCEEDED(mNetworkResult)((bool)(__builtin_expect(!!(!NS_FAILED_impl(mNetworkResult)),
1)))
; }
148
149 const nsTArray<nsCString>& URLList() const { return mURLList; }
150
151 private:
152 ~CompareNetwork() {
153 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 153); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 153; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
154 MOZ_ASSERT(!mCC)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mCC)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(!mCC))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("!mCC", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 154); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mCC" ")"); do
{ *((volatile int*)__null) = 154; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
155 }
156
157 void Finish();
158
159 nsresult SetPrincipalInfo(nsIChannel* aChannel);
160
161 RefPtr<CompareManager> mManager;
162 RefPtr<CompareCache> mCC;
163 RefPtr<ServiceWorkerRegistrationInfo> mRegistration;
164
165 nsCOMPtr<nsIChannel> mChannel;
166 nsString mBuffer;
167 nsCString mURL;
168 ChannelInfo mChannelInfo;
169 RefPtr<InternalHeaders> mInternalHeaders;
170 UniquePtr<PrincipalInfo> mPrincipalInfo;
171 nsTArray<nsCString> mURLList;
172
173 nsCString mMaxScope;
174 nsLoadFlags mLoadFlags;
175
176 enum {
177 WaitingForInitialization,
178 WaitingForBothFinished,
179 WaitingForNetworkFinished,
180 WaitingForCacheFinished,
181 Finished
182 } mState;
183
184 nsresult mNetworkResult;
185 nsresult mCacheResult;
186
187 const bool mIsMainScript;
188 bool mIsFromCache;
189};
190
191NS_IMPL_ISUPPORTS(CompareNetwork, nsIStreamLoaderObserver, nsIRequestObserver)MozExternalRefCountType CompareNetwork::AddRef(void) { static_assert
(!std::is_destructible_v<CompareNetwork>, "Reference-counted class "
"CompareNetwork" " should not have a public destructor. " "Make this class's destructor non-public"
); do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 191); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
191; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CompareNetwork" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CompareNetwork" != nullptr)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"CompareNetwork\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 191); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CompareNetwork\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 191; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("CompareNetwork" " not thread-safe"); nsrefcnt
count = ++mRefCnt; NS_LogAddRef((this), (count), ("CompareNetwork"
), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType
CompareNetwork::Release(void) { do { static_assert( mozilla::
detail::AssertionConditionType<decltype(int32_t(mRefCnt) >
0)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(int32_t(mRefCnt) > 0))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 191); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 191
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CompareNetwork" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CompareNetwork" != nullptr)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"CompareNetwork\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 191); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CompareNetwork\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 191; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("CompareNetwork" " not thread-safe"); const char
* const nametmp = "CompareNetwork"; nsrefcnt count = --mRefCnt
; NS_LogRelease((this), (count), (nametmp)); if (count == 0) {
mRefCnt = 1; delete (this); return 0; } return count; } nsresult
CompareNetwork::QueryInterface(const nsIID& aIID, void**
aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "QueryInterface requires a non-NULL destination!", "aInstancePtr"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 191); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(2 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<CompareNetwork, nsIStreamLoaderObserver>
, int32_t( reinterpret_cast<char*>(static_cast<nsIStreamLoaderObserver
*>((CompareNetwork*)0x1000)) - reinterpret_cast<char*>
((CompareNetwork*)0x1000))}, {&mozilla::detail::kImplementedIID
<CompareNetwork, nsIRequestObserver>, int32_t( reinterpret_cast
<char*>(static_cast<nsIRequestObserver*>((CompareNetwork
*)0x1000)) - reinterpret_cast<char*>((CompareNetwork*)0x1000
))}, {&mozilla::detail::kImplementedIID<CompareNetwork
, nsISupports>, int32_t(reinterpret_cast<char*>(static_cast
<nsISupports*>( static_cast<nsIStreamLoaderObserver*
>((CompareNetwork*)0x1000))) - reinterpret_cast<char*>
((CompareNetwork*)0x1000))}, { nullptr, 0 } } ; static_assert
((sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface"
); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID
, aInstancePtr, table); return rv; }
192
193// This class gets a cached Response from the CacheStorage and then it calls
194// CacheFinish() in the CompareNetwork.
195class CompareCache final : public PromiseNativeHandler,
196 public nsIStreamLoaderObserver {
197 public:
198 NS_DECL_ISUPPORTSpublic: virtual nsresult QueryInterface(const nsIID& aIID
, void** aInstancePtr) override; virtual MozExternalRefCountType
AddRef(void) override; virtual MozExternalRefCountType Release
(void) override; using HasThreadSafeRefCnt = std::false_type;
protected: nsAutoRefCnt mRefCnt; nsAutoOwningThread _mOwningThread
; public:
199 NS_DECL_NSISTREAMLOADEROBSERVERvirtual nsresult OnStreamComplete(nsIStreamLoader *loader, nsISupports
*ctxt, nsresult status, uint32_t resultLength, const uint8_t
*result) override;
200
201 explicit CompareCache(CompareNetwork* aCN)
202 : mCN(aCN), mState(WaitingForInitialization), mInCache(false) {
203 MOZ_ASSERT(aCN)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aCN)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(aCN))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("aCN", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 203); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCN" ")"); do
{ *((volatile int*)__null) = 203; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
204 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 204); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 204; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
205 }
206
207 nsresult Initialize(Cache* const aCache, const nsACString& aURL);
208
209 void Finish(nsresult aStatus, bool aInCache);
210
211 void Abort();
212
213 virtual void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
214 ErrorResult& aRv) override;
215
216 virtual void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
217 ErrorResult& aRv) override;
218
219 const nsString& Buffer() const {
220 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 220); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 220; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
221 return mBuffer;
222 }
223
224 bool InCache() { return mInCache; }
225
226 private:
227 ~CompareCache() { MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 227); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 227; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
; }
228
229 void ManageValueResult(JSContext* aCx, JS::Handle<JS::Value> aValue);
230
231 RefPtr<CompareNetwork> mCN;
232 nsCOMPtr<nsIInputStreamPump> mPump;
233
234 nsCString mURL;
235 nsString mBuffer;
236
237 enum {
238 WaitingForInitialization,
239 WaitingForScript,
240 Finished,
241 } mState;
242
243 bool mInCache;
244};
245
246NS_IMPL_ISUPPORTS(CompareCache, nsIStreamLoaderObserver)MozExternalRefCountType CompareCache::AddRef(void) { static_assert
(!std::is_destructible_v<CompareCache>, "Reference-counted class "
"CompareCache" " should not have a public destructor. " "Make this class's destructor non-public"
); do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 246); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
246; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CompareCache" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CompareCache" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"CompareCache\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 246); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CompareCache\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 246; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("CompareCache" " not thread-safe"); nsrefcnt
count = ++mRefCnt; NS_LogAddRef((this), (count), ("CompareCache"
), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType
CompareCache::Release(void) { do { static_assert( mozilla::detail
::AssertionConditionType<decltype(int32_t(mRefCnt) > 0)
>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(int32_t(mRefCnt) > 0))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 246); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 246
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CompareCache" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CompareCache" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"CompareCache\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 246); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CompareCache\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 246; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("CompareCache" " not thread-safe"); const char
* const nametmp = "CompareCache"; nsrefcnt count = --mRefCnt;
NS_LogRelease((this), (count), (nametmp)); if (count == 0) {
mRefCnt = 1; delete (this); return 0; } return count; } nsresult
CompareCache::QueryInterface(const nsIID& aIID, void** aInstancePtr
) { do { if (!(aInstancePtr)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "QueryInterface requires a non-NULL destination!", "aInstancePtr"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 246); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(1 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<CompareCache, nsIStreamLoaderObserver>
, int32_t( reinterpret_cast<char*>(static_cast<nsIStreamLoaderObserver
*>((CompareCache*)0x1000)) - reinterpret_cast<char*>
((CompareCache*)0x1000))}, {&mozilla::detail::kImplementedIID
<CompareCache, nsISupports>, int32_t(reinterpret_cast<
char*>(static_cast<nsISupports*>( static_cast<nsIStreamLoaderObserver
*>((CompareCache*)0x1000))) - reinterpret_cast<char*>
((CompareCache*)0x1000))}, { nullptr, 0 } } ; static_assert((
sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface"
); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID
, aInstancePtr, table); return rv; }
247
248class CompareManager final : public PromiseNativeHandler {
249 public:
250 NS_DECL_ISUPPORTSpublic: virtual nsresult QueryInterface(const nsIID& aIID
, void** aInstancePtr) override; virtual MozExternalRefCountType
AddRef(void) override; virtual MozExternalRefCountType Release
(void) override; using HasThreadSafeRefCnt = std::false_type;
protected: nsAutoRefCnt mRefCnt; nsAutoOwningThread _mOwningThread
; public:
251
252 explicit CompareManager(ServiceWorkerRegistrationInfo* aRegistration,
253 CompareCallback* aCallback)
254 : mRegistration(aRegistration),
255 mCallback(aCallback),
256 mLoadFlags(nsIChannel::LOAD_BYPASS_SERVICE_WORKER),
257 mState(WaitingForInitialization),
258 mPendingCount(0),
259 mOnFailure(OnFailure::DoNothing),
260 mAreScriptsEqual(true) {
261 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 261); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 261; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
262 MOZ_ASSERT(aRegistration)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aRegistration)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aRegistration))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("aRegistration",
"/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 262); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aRegistration"
")"); do { *((volatile int*)__null) = 262; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
263 }
264
265 nsresult Initialize(nsIPrincipal* aPrincipal, const nsACString& aURL,
266 const nsAString& aCacheName);
267
268 void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
269 ErrorResult& aRv) override;
270
271 void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
272 ErrorResult& aRv) override;
273
274 CacheStorage* CacheStorage_() {
275 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 275); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 275; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
276 MOZ_ASSERT(mCacheStorage)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mCacheStorage)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mCacheStorage))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("mCacheStorage",
"/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 276); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mCacheStorage"
")"); do { *((volatile int*)__null) = 276; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
277 return mCacheStorage;
278 }
279
280 void ComparisonFinished(nsresult aStatus, bool aIsMainScript, bool aIsEqual,
281 const nsACString& aMaxScope, nsLoadFlags aLoadFlags) {
282 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 282); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 282; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
283 if (mState == Finished) {
284 return;
285 }
286
287 MOZ_DIAGNOSTIC_ASSERT(mState == WaitingForScriptOrComparisonResult)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForScriptOrComparisonResult)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(mState == WaitingForScriptOrComparisonResult))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("mState == WaitingForScriptOrComparisonResult"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 287); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForScriptOrComparisonResult"
")"); do { *((volatile int*)__null) = 287; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
288
289 if (NS_WARN_IF(NS_FAILED(aStatus))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(aStatus
)), 0))), "NS_FAILED(aStatus)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 289)
) {
290 Fail(aStatus);
291 return;
292 }
293
294 mAreScriptsEqual = mAreScriptsEqual && aIsEqual;
295
296 if (aIsMainScript) {
297 mMaxScope = aMaxScope;
298 mLoadFlags = aLoadFlags;
299 }
300
301 // Check whether all CompareNetworks finished their jobs.
302 MOZ_DIAGNOSTIC_ASSERT(mPendingCount > 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mPendingCount > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mPendingCount > 0))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("mPendingCount > 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 302); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mPendingCount > 0"
")"); do { *((volatile int*)__null) = 302; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
303 if (--mPendingCount) {
304 return;
305 }
306
307 if (mAreScriptsEqual) {
308 MOZ_ASSERT(mCallback)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mCallback)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mCallback))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("mCallback", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 308); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mCallback" ")"
); do { *((volatile int*)__null) = 308; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
309 mCallback->ComparisonResult(aStatus, true /* aSameScripts */, mOnFailure,
310 u""_ns, mMaxScope, mLoadFlags);
311 Cleanup();
312 return;
313 }
314
315 // Write to Cache so ScriptLoader reads succeed.
316 WriteNetworkBufferToNewCache();
317 }
318
319 private:
320 ~CompareManager() {
321 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 321); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 321; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
322 MOZ_ASSERT(mCNList.Length() == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mCNList.Length() == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mCNList.Length() == 0))), 0)
)) { do { } while (false); MOZ_ReportAssertionFailure("mCNList.Length() == 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 322); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mCNList.Length() == 0"
")"); do { *((volatile int*)__null) = 322; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
323 }
324
325 void Fail(nsresult aStatus);
326
327 void Cleanup();
328
329 nsresult FetchScript(const nsACString& aURL, bool aIsMainScript,
330 Cache* const aCache = nullptr) {
331 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 331); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 331; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
332
333 MOZ_DIAGNOSTIC_ASSERT(mState == WaitingForInitialization ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForInitialization || mState == WaitingForScriptOrComparisonResult
)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mState == WaitingForInitialization || mState == WaitingForScriptOrComparisonResult
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mState == WaitingForInitialization || mState == WaitingForScriptOrComparisonResult"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 334); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForInitialization || mState == WaitingForScriptOrComparisonResult"
")"); do { *((volatile int*)__null) = 334; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
334 mState == WaitingForScriptOrComparisonResult)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForInitialization || mState == WaitingForScriptOrComparisonResult
)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mState == WaitingForInitialization || mState == WaitingForScriptOrComparisonResult
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mState == WaitingForInitialization || mState == WaitingForScriptOrComparisonResult"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 334); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForInitialization || mState == WaitingForScriptOrComparisonResult"
")"); do { *((volatile int*)__null) = 334; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
335
336 RefPtr<CompareNetwork> cn =
337 new CompareNetwork(this, mRegistration, aIsMainScript);
338 mCNList.AppendElement(cn);
339 mPendingCount += 1;
340
341 nsresult rv = cn->Initialize(mPrincipal, aURL, aCache);
342 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 342)
) {
343 return rv;
344 }
345
346 return NS_OK;
347 }
348
349 void ManageOldCache(JSContext* aCx, JS::Handle<JS::Value> aValue) {
350 MOZ_DIAGNOSTIC_ASSERT(mState == WaitingForExistingOpen)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForExistingOpen)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mState == WaitingForExistingOpen
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mState == WaitingForExistingOpen", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 350); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForExistingOpen"
")"); do { *((volatile int*)__null) = 350; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
351
352 // RAII Cleanup when fails.
353 nsresult rv = NS_ERROR_FAILURE;
354 auto guard = MakeScopeExit([&] { Fail(rv); });
355
356 if (NS_WARN_IF(!aValue.isObject())NS_warn_if_impl(!aValue.isObject(), "!aValue.isObject()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 356)
) {
357 return;
358 }
359
360 MOZ_ASSERT(!mOldCache)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mOldCache)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mOldCache))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!mOldCache", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 360); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOldCache" ")"
); do { *((volatile int*)__null) = 360; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
361 JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
362 if (NS_WARN_IF(!obj)NS_warn_if_impl(!obj, "!obj", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 362)
||
363 NS_WARN_IF(NS_FAILED(UNWRAP_OBJECT(Cache, obj, mOldCache)))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(mozilla
::dom::binding_detail::UnwrapObjectWithCrossOriginAsserts<
mozilla::dom::prototypes::id::Cache, mozilla::dom::Cache_Binding
::NativeType>(obj, mOldCache))), 0))), "NS_FAILED(UNWRAP_OBJECT(Cache, obj, mOldCache))"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 363)
) {
364 return;
365 }
366
367 Optional<RequestOrUTF8String> request;
368 CacheQueryOptions options;
369 ErrorResult error;
370 RefPtr<Promise> promise = mOldCache->Keys(aCx, request, options, error);
371 if (NS_WARN_IF(error.Failed())NS_warn_if_impl(error.Failed(), "error.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 371)
) {
372 // No exception here because there are no ReadableStreams involved here.
373 MOZ_ASSERT(!error.IsJSException())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!error.IsJSException())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!error.IsJSException()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!error.IsJSException()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 373); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!error.IsJSException()"
")"); do { *((volatile int*)__null) = 373; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
374 rv = error.StealNSResult();
375 return;
376 }
377
378 mState = WaitingForExistingKeys;
379 promise->AppendNativeHandler(this);
380 guard.release();
381 }
382
383 void ManageOldKeys(JSContext* aCx, JS::Handle<JS::Value> aValue) {
384 MOZ_DIAGNOSTIC_ASSERT(mState == WaitingForExistingKeys)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForExistingKeys)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mState == WaitingForExistingKeys
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mState == WaitingForExistingKeys", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 384); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForExistingKeys"
")"); do { *((volatile int*)__null) = 384; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
385
386 // RAII Cleanup when fails.
387 nsresult rv = NS_ERROR_FAILURE;
388 auto guard = MakeScopeExit([&] { Fail(rv); });
389
390 if (NS_WARN_IF(!aValue.isObject())NS_warn_if_impl(!aValue.isObject(), "!aValue.isObject()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 390)
) {
391 return;
392 }
393
394 JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
395 if (NS_WARN_IF(!obj)NS_warn_if_impl(!obj, "!obj", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 395)
) {
396 return;
397 }
398
399 uint32_t len = 0;
400 if (!JS::GetArrayLength(aCx, obj, &len)) {
401 return;
402 }
403
404 // Fetch and compare the source scripts.
405 MOZ_ASSERT(mPendingCount == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mPendingCount == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mPendingCount == 0))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("mPendingCount == 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 405); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingCount == 0"
")"); do { *((volatile int*)__null) = 405; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
406
407 mState = WaitingForScriptOrComparisonResult;
408
409 bool hasMainScript = false;
410 AutoTArray<nsCString, 8> urlList;
411
412 // Extract the list of URLs in the old cache.
413 for (uint32_t i = 0; i < len; ++i) {
414 JS::Rooted<JS::Value> val(aCx);
415 if (NS_WARN_IF(!JS_GetElement(aCx, obj, i, &val))NS_warn_if_impl(!JS_GetElement(aCx, obj, i, &val), "!JS_GetElement(aCx, obj, i, &val)"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 415)
||
416 NS_WARN_IF(!val.isObject())NS_warn_if_impl(!val.isObject(), "!val.isObject()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 416)
) {
417 return;
418 }
419
420 Request* request;
421 JS::Rooted<JSObject*> requestObj(aCx, &val.toObject());
422 if (NS_WARN_IF(NS_FAILED(UNWRAP_OBJECT(Request, &requestObj, request)))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(mozilla
::dom::binding_detail::UnwrapObjectWithCrossOriginAsserts<
mozilla::dom::prototypes::id::Request, mozilla::dom::Request_Binding
::NativeType>(&requestObj, request))), 0))), "NS_FAILED(UNWRAP_OBJECT(Request, &requestObj, request))"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 422)
) {
423 return;
424 };
425
426 nsCString url;
427 request->GetUrl(url);
428
429 if (!hasMainScript && url == mURL) {
430 hasMainScript = true;
431 }
432
433 urlList.AppendElement(std::move(url));
434 }
435
436 // If the main script is missing, then something has gone wrong. We
437 // will try to continue with the update process to trigger a new
438 // installation. If that fails, however, then uninstall the registration
439 // because it is broken in a way that cannot be fixed.
440 if (!hasMainScript) {
441 mOnFailure = OnFailure::Uninstall;
442 }
443
444 // Always make sure to fetch the main script. If the old cache has
445 // no entries or the main script entry is missing, then the loop below
446 // may not trigger it. This should not really happen, but we handle it
447 // gracefully if it does occur. Its possible the bad cache state is due
448 // to a crash or shutdown during an update, etc.
449 rv = FetchScript(mURL, true /* aIsMainScript */, mOldCache);
450 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 450)
) {
451 return;
452 }
453
454 for (const auto& url : urlList) {
455 // We explicitly start the fetch for the main script above.
456 if (mURL == url) {
457 continue;
458 }
459
460 rv = FetchScript(url, false /* aIsMainScript */, mOldCache);
461 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 461)
) {
462 return;
463 }
464 }
465
466 guard.release();
467 }
468
469 void ManageNewCache(JSContext* aCx, JS::Handle<JS::Value> aValue) {
470 MOZ_DIAGNOSTIC_ASSERT(mState == WaitingForOpen)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForOpen)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mState == WaitingForOpen))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("mState == WaitingForOpen"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 470); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForOpen"
")"); do { *((volatile int*)__null) = 470; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
471
472 // RAII Cleanup when fails.
473 nsresult rv = NS_ERROR_FAILURE;
474 auto guard = MakeScopeExit([&] { Fail(rv); });
475
476 if (NS_WARN_IF(!aValue.isObject())NS_warn_if_impl(!aValue.isObject(), "!aValue.isObject()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 476)
) {
477 return;
478 }
479
480 JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
481 if (NS_WARN_IF(!obj)NS_warn_if_impl(!obj, "!obj", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 481)
) {
482 return;
483 }
484
485 Cache* cache = nullptr;
486 rv = UNWRAP_OBJECT(Cache, &obj, cache)mozilla::dom::binding_detail::UnwrapObjectWithCrossOriginAsserts
< mozilla::dom::prototypes::id::Cache, mozilla::dom::Cache_Binding
::NativeType>(&obj, cache)
;
487 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 487)
) {
488 return;
489 }
490
491 // Just to be safe.
492 RefPtr<Cache> kungfuDeathGrip = cache;
493
494 MOZ_ASSERT(mPendingCount == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mPendingCount == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mPendingCount == 0))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("mPendingCount == 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 494); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingCount == 0"
")"); do { *((volatile int*)__null) = 494; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
495 for (uint32_t i = 0; i < mCNList.Length(); ++i) {
496 // We bail out immediately when something goes wrong.
497 rv = WriteToCache(aCx, cache, mCNList[i]);
498 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 498)
) {
499 return;
500 }
501 }
502
503 mState = WaitingForPut;
504 guard.release();
505 }
506
507 void WriteNetworkBufferToNewCache() {
508 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 508); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 508; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
509 MOZ_ASSERT(mCNList.Length() != 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mCNList.Length() != 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mCNList.Length() != 0))), 0)
)) { do { } while (false); MOZ_ReportAssertionFailure("mCNList.Length() != 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 509); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mCNList.Length() != 0"
")"); do { *((volatile int*)__null) = 509; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
510 MOZ_ASSERT(mCacheStorage)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mCacheStorage)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mCacheStorage))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("mCacheStorage",
"/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 510); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mCacheStorage"
")"); do { *((volatile int*)__null) = 510; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
511 MOZ_ASSERT(mNewCacheName.IsEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mNewCacheName.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mNewCacheName.IsEmpty()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("mNewCacheName.IsEmpty()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 511); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mNewCacheName.IsEmpty()"
")"); do { *((volatile int*)__null) = 511; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
512
513 ErrorResult result;
514 result = serviceWorkerScriptCache::GenerateCacheName(mNewCacheName);
515 if (NS_WARN_IF(result.Failed())NS_warn_if_impl(result.Failed(), "result.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 515)
) {
516 MOZ_ASSERT(!result.IsErrorWithMessage())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!result.IsErrorWithMessage())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!result.IsErrorWithMessage()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"!result.IsErrorWithMessage()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 516); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!result.IsErrorWithMessage()"
")"); do { *((volatile int*)__null) = 516; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
517 Fail(result.StealNSResult());
518 return;
519 }
520
521 RefPtr<Promise> cacheOpenPromise =
522 mCacheStorage->Open(mNewCacheName, result);
523 if (NS_WARN_IF(result.Failed())NS_warn_if_impl(result.Failed(), "result.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 523)
) {
524 MOZ_ASSERT(!result.IsErrorWithMessage())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!result.IsErrorWithMessage())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!result.IsErrorWithMessage()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"!result.IsErrorWithMessage()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 524); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!result.IsErrorWithMessage()"
")"); do { *((volatile int*)__null) = 524; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
525 Fail(result.StealNSResult());
526 return;
527 }
528
529 mState = WaitingForOpen;
530 cacheOpenPromise->AppendNativeHandler(this);
531 }
532
533 nsresult WriteToCache(JSContext* aCx, Cache* aCache, CompareNetwork* aCN) {
534 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 534); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 534; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
535 MOZ_ASSERT(aCache)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aCache)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aCache))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aCache", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 535); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCache" ")")
; do { *((volatile int*)__null) = 535; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
536 MOZ_ASSERT(aCN)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aCN)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(aCN))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("aCN", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 536); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCN" ")"); do
{ *((volatile int*)__null) = 536; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
537 MOZ_DIAGNOSTIC_ASSERT(mState == WaitingForOpen)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForOpen)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mState == WaitingForOpen))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("mState == WaitingForOpen"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 537); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForOpen"
")"); do { *((volatile int*)__null) = 537; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
538
539 // We don't have to save any information from a failed CompareNetwork.
540 if (!aCN->Succeeded()) {
541 return NS_OK;
542 }
543
544 nsCOMPtr<nsIInputStream> body;
545 nsresult rv = NS_NewCStringInputStream(
546 getter_AddRefs(body), NS_ConvertUTF16toUTF8(aCN->Buffer()));
547 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 547)
) {
548 return rv;
549 }
550
551 SafeRefPtr<InternalResponse> ir =
552 MakeSafeRefPtr<InternalResponse>(200, "OK"_ns);
553 ir->SetBody(body, aCN->Buffer().Length());
554 ir->SetURLList(aCN->URLList());
555
556 ir->InitChannelInfo(aCN->GetChannelInfo());
557 UniquePtr<PrincipalInfo> principalInfo = aCN->TakePrincipalInfo();
558 if (principalInfo) {
559 ir->SetPrincipalInfo(std::move(principalInfo));
560 }
561
562 RefPtr<InternalHeaders> internalHeaders = aCN->GetInternalHeaders();
563 ir->Headers()->Fill(*(internalHeaders.get()), IgnoreErrors());
564
565 RefPtr<Response> response =
566 new Response(aCache->GetGlobalObject(), std::move(ir), nullptr);
567
568 RequestOrUTF8String request;
569 request.SetAsUTF8String().ShareOrDependUpon(aCN->URL());
570
571 // For now we have to wait until the Put Promise is fulfilled before we can
572 // continue since Cache does not yet support starting a read that is being
573 // written to.
574 ErrorResult result;
575 RefPtr<Promise> cachePromise = aCache->Put(aCx, request, *response, result);
576 result.WouldReportJSException();
577 if (NS_WARN_IF(result.Failed())NS_warn_if_impl(result.Failed(), "result.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 577)
) {
578 // No exception here because there are no ReadableStreams involved here.
579 MOZ_ASSERT(!result.IsJSException())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!result.IsJSException())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!result.IsJSException()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!result.IsJSException()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 579); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!result.IsJSException()"
")"); do { *((volatile int*)__null) = 579; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
580 MOZ_ASSERT(!result.IsErrorWithMessage())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!result.IsErrorWithMessage())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!result.IsErrorWithMessage()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"!result.IsErrorWithMessage()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 580); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!result.IsErrorWithMessage()"
")"); do { *((volatile int*)__null) = 580; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
581 return result.StealNSResult();
582 }
583
584 mPendingCount += 1;
585 cachePromise->AppendNativeHandler(this);
586 return NS_OK;
587 }
588
589 RefPtr<ServiceWorkerRegistrationInfo> mRegistration;
590 RefPtr<CompareCallback> mCallback;
591 RefPtr<CacheStorage> mCacheStorage;
592
593 nsTArray<RefPtr<CompareNetwork>> mCNList;
594
595 nsCString mURL;
596 RefPtr<nsIPrincipal> mPrincipal;
597
598 // Used for the old cache where saves the old source scripts.
599 RefPtr<Cache> mOldCache;
600
601 // Only used if the network script has changed and needs to be cached.
602 nsString mNewCacheName;
603
604 nsCString mMaxScope;
605 nsLoadFlags mLoadFlags;
606
607 enum {
608 WaitingForInitialization,
609 WaitingForExistingOpen,
610 WaitingForExistingKeys,
611 WaitingForScriptOrComparisonResult,
612 WaitingForOpen,
613 WaitingForPut,
614 Finished
615 } mState;
616
617 uint32_t mPendingCount;
618 OnFailure mOnFailure;
619 bool mAreScriptsEqual;
620};
621
622NS_IMPL_ISUPPORTS0(CompareManager)MozExternalRefCountType CompareManager::AddRef(void) { static_assert
(!std::is_destructible_v<CompareManager>, "Reference-counted class "
"CompareManager" " should not have a public destructor. " "Make this class's destructor non-public"
); do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 622); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
622; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CompareManager" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CompareManager" != nullptr)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"CompareManager\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 622); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CompareManager\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 622; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("CompareManager" " not thread-safe"); nsrefcnt
count = ++mRefCnt; NS_LogAddRef((this), (count), ("CompareManager"
), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType
CompareManager::Release(void) { do { static_assert( mozilla::
detail::AssertionConditionType<decltype(int32_t(mRefCnt) >
0)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(int32_t(mRefCnt) > 0))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 622); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 622
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CompareManager" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CompareManager" != nullptr)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"CompareManager\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 622); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CompareManager\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 622; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("CompareManager" " not thread-safe"); const char
* const nametmp = "CompareManager"; nsrefcnt count = --mRefCnt
; NS_LogRelease((this), (count), (nametmp)); if (count == 0) {
mRefCnt = 1; delete (this); return 0; } return count; } nsresult
CompareManager::QueryInterface(const nsIID& aIID, void**
aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "QueryInterface requires a non-NULL destination!", "aInstancePtr"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 622); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<CompareManager, nsISupports>, int32_t
( reinterpret_cast<char*>(static_cast<nsISupports*>
((CompareManager*)0x1000)) - reinterpret_cast<char*>((CompareManager
*)0x1000))}, { nullptr, 0 } } ; static_assert((sizeof(table) /
sizeof(table[0])) > 1, "need at least 1 interface"); rv =
NS_TableDrivenQI(static_cast<void*>(this), aIID, aInstancePtr
, table); return rv; }
623
624nsresult CompareNetwork::Initialize(nsIPrincipal* aPrincipal,
625 const nsACString& aURL,
626 Cache* const aCache) {
627 MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPrincipal)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 627); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal" ")"
); do { *((volatile int*)__null) = 627; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
628 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 628); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 628; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
629
630 nsCOMPtr<nsIURI> uri;
631 nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL);
632 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 632)
) {
633 return rv;
634 }
635
636 mURL = aURL;
637 mURLList.AppendElement(mURL);
638
639 nsCOMPtr<nsILoadGroup> loadGroup;
640 rv = NS_NewLoadGroup(getter_AddRefs(loadGroup), aPrincipal);
641 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 641)
) {
642 return rv;
643 }
644
645 // Update LoadFlags for propagating to ServiceWorkerInfo.
646 mLoadFlags = nsIChannel::LOAD_BYPASS_SERVICE_WORKER;
647
648 ServiceWorkerUpdateViaCache uvc = mRegistration->GetUpdateViaCache();
649 if (uvc == ServiceWorkerUpdateViaCache::None ||
650 (uvc == ServiceWorkerUpdateViaCache::Imports && mIsMainScript)) {
651 mLoadFlags |= nsIRequest::VALIDATE_ALWAYS;
652 }
653
654 if (mRegistration->IsLastUpdateCheckTimeOverOneDay()) {
655 mLoadFlags |= nsIRequest::LOAD_BYPASS_CACHE;
656 }
657
658 // Different settings are needed for fetching imported scripts, since they
659 // might be cross-origin scripts.
660 uint32_t secFlags =
661 mIsMainScript ? nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED
662 : nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_INHERITS_SEC_CONTEXT;
663
664 nsContentPolicyType contentPolicyType =
665 mIsMainScript ? nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER
666 : nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS;
667
668 // Create a new cookieJarSettings.
669 nsCOMPtr<nsICookieJarSettings> cookieJarSettings =
670 mozilla::net::CookieJarSettings::Create(aPrincipal);
671
672 // Populate the partitionKey by using the given prinicpal. The ServiceWorkers
673 // are using the foreign partitioned principal, so we can get the partitionKey
674 // from it and the partitionKey will only exist if it's in the third-party
675 // context. In first-party context, we can still use the uri to set the
676 // partitionKey.
677 if (!aPrincipal->OriginAttributesRef().mPartitionKey.IsEmpty()) {
678 net::CookieJarSettings::Cast(cookieJarSettings)
679 ->SetPartitionKey(aPrincipal->OriginAttributesRef().mPartitionKey);
680 } else {
681 net::CookieJarSettings::Cast(cookieJarSettings)
682 ->SetPartitionKey(uri, false);
683 }
684
685 // Note that because there is no "serviceworker" RequestContext type, we can
686 // use the TYPE_INTERNAL_SCRIPT content policy types when loading a service
687 // worker.
688 rv = NS_NewChannel(getter_AddRefs(mChannel), uri, aPrincipal, secFlags,
689 contentPolicyType, cookieJarSettings,
690 nullptr /* aPerformanceStorage */, loadGroup,
691 nullptr /* aCallbacks */, mLoadFlags);
692 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 692)
) {
693 return rv;
694 }
695
696 nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mChannel);
697 if (httpChannel) {
698 // Spec says no redirects allowed for top-level SW scripts.
699 if (mIsMainScript) {
700 rv = httpChannel->SetRedirectionLimit(0);
701 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 701); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 701; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
702 }
703
704 rv = httpChannel->SetRequestHeader("Service-Worker"_ns, "script"_ns,
705 /* merge */ false);
706 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 706); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 706; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
707 }
708
709 nsCOMPtr<nsIStreamLoader> loader;
710 rv = NS_NewStreamLoader(getter_AddRefs(loader), this, this);
711 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 711)
) {
712 return rv;
713 }
714
715 rv = mChannel->AsyncOpen(loader);
716 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 716)
) {
717 return rv;
718 }
719
720 // If we do have an existing cache to compare with.
721 if (aCache) {
722 mCC = new CompareCache(this);
723 rv = mCC->Initialize(aCache, aURL);
724 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 724)
) {
725 Abort();
726 return rv;
727 }
728
729 mState = WaitingForBothFinished;
730 return NS_OK;
731 }
732
733 mState = WaitingForNetworkFinished;
734 return NS_OK;
735}
736
737void CompareNetwork::Finish() {
738 if (mState == Finished) {
739 return;
740 }
741
742 bool same = true;
743 nsresult rv = NS_OK;
744
745 // mNetworkResult is prior to mCacheResult, since it's needed for reporting
746 // various errors to web content.
747 if (NS_FAILED(mNetworkResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(mNetworkResult)), 0
)))
) {
748 // An imported script could become offline, since it might no longer be
749 // needed by the new importing script. In that case, the importing script
750 // must be different, and thus, it's okay to report same script found here.
751 rv = mIsMainScript ? mNetworkResult : NS_OK;
752 same = true;
753 } else if (mCC && NS_FAILED(mCacheResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(mCacheResult)), 0)
))
) {
754 rv = mCacheResult;
755 } else { // Both passed.
756 same = mCC && mCC->InCache() && mCC->Buffer().Equals(mBuffer);
757 }
758
759 mManager->ComparisonFinished(rv, mIsMainScript, same, mMaxScope, mLoadFlags);
760
761 // We have done with the CompareCache.
762 mCC = nullptr;
763}
764
765void CompareNetwork::NetworkFinish(nsresult aRv) {
766 MOZ_DIAGNOSTIC_ASSERT(mState == WaitingForBothFinished ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForBothFinished || mState == WaitingForNetworkFinished
)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mState == WaitingForBothFinished || mState == WaitingForNetworkFinished
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mState == WaitingForBothFinished || mState == WaitingForNetworkFinished"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 767); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForBothFinished || mState == WaitingForNetworkFinished"
")"); do { *((volatile int*)__null) = 767; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
767 mState == WaitingForNetworkFinished)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForBothFinished || mState == WaitingForNetworkFinished
)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mState == WaitingForBothFinished || mState == WaitingForNetworkFinished
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mState == WaitingForBothFinished || mState == WaitingForNetworkFinished"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 767); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForBothFinished || mState == WaitingForNetworkFinished"
")"); do { *((volatile int*)__null) = 767; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
768
769 mNetworkResult = aRv;
770
771 if (mState == WaitingForBothFinished) {
772 mState = WaitingForCacheFinished;
773 return;
774 }
775
776 if (mState == WaitingForNetworkFinished) {
777 Finish();
778 return;
779 }
780}
781
782void CompareNetwork::CacheFinish(nsresult aRv) {
783 MOZ_DIAGNOSTIC_ASSERT(mState == WaitingForBothFinished ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForBothFinished || mState == WaitingForCacheFinished
)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mState == WaitingForBothFinished || mState == WaitingForCacheFinished
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mState == WaitingForBothFinished || mState == WaitingForCacheFinished"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 784); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForBothFinished || mState == WaitingForCacheFinished"
")"); do { *((volatile int*)__null) = 784; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
784 mState == WaitingForCacheFinished)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForBothFinished || mState == WaitingForCacheFinished
)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mState == WaitingForBothFinished || mState == WaitingForCacheFinished
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mState == WaitingForBothFinished || mState == WaitingForCacheFinished"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 784); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForBothFinished || mState == WaitingForCacheFinished"
")"); do { *((volatile int*)__null) = 784; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
785
786 mCacheResult = aRv;
787
788 if (mState == WaitingForBothFinished) {
789 mState = WaitingForNetworkFinished;
790 return;
791 }
792
793 if (mState == WaitingForCacheFinished) {
794 Finish();
795 return;
796 }
797}
798
799void CompareNetwork::Abort() {
800 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 800); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 800; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
801
802 if (mState != Finished) {
803 mState = Finished;
804
805 MOZ_ASSERT(mChannel)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mChannel)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mChannel))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("mChannel", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 805); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mChannel" ")"
); do { *((volatile int*)__null) = 805; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
806 mChannel->CancelWithReason(NS_BINDING_ABORTED, "CompareNetwork::Abort"_ns);
807 mChannel = nullptr;
808
809 if (mCC) {
810 mCC->Abort();
811 mCC = nullptr;
812 }
813 }
814}
815
816NS_IMETHODIMPnsresult
817CompareNetwork::OnStartRequest(nsIRequest* aRequest) {
818 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 818); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 818; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
819
820 if (mState == Finished) {
821 return NS_OK;
822 }
823
824 nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
825 MOZ_ASSERT_IF(mIsMainScript, channel == mChannel)do { if (mIsMainScript) { do { static_assert( mozilla::detail
::AssertionConditionType<decltype(channel == mChannel)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(channel == mChannel))), 0))) { do { } while (false);
MOZ_ReportAssertionFailure("channel == mChannel", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 825); AnnotateMozCrashReason("MOZ_ASSERT" "(" "channel == mChannel"
")"); do { *((volatile int*)__null) = 825; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
826 mChannel = channel;
827
828 MOZ_ASSERT(!mChannelInfo.IsInitialized())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mChannelInfo.IsInitialized())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mChannelInfo.IsInitialized(
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!mChannelInfo.IsInitialized()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 828); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mChannelInfo.IsInitialized()"
")"); do { *((volatile int*)__null) = 828; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
829 mChannelInfo.InitFromChannel(mChannel);
830
831 nsresult rv = SetPrincipalInfo(mChannel);
832 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 832)
) {
833 return rv;
834 }
835
836 mInternalHeaders->FillResponseHeaders(mChannel);
837
838 nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(channel));
839 if (cacheChannel) {
840 cacheChannel->IsFromCache(&mIsFromCache);
841 }
842
843 return NS_OK;
844}
845
846nsresult CompareNetwork::SetPrincipalInfo(nsIChannel* aChannel) {
847 nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
848 if (!ssm) {
849 return NS_ERROR_FAILURE;
850 }
851
852 nsCOMPtr<nsIPrincipal> channelPrincipal;
853 nsresult rv = ssm->GetChannelResultPrincipal(
854 aChannel, getter_AddRefs(channelPrincipal));
855 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 855)
) {
856 return rv;
857 }
858
859 UniquePtr<PrincipalInfo> principalInfo = MakeUnique<PrincipalInfo>();
860 rv = PrincipalToPrincipalInfo(channelPrincipal, principalInfo.get());
861
862 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 862)
) {
863 return rv;
864 }
865
866 mPrincipalInfo = std::move(principalInfo);
867 return NS_OK;
868}
869
870NS_IMETHODIMPnsresult
871CompareNetwork::OnStopRequest(nsIRequest* aRequest, nsresult aStatusCode) {
872 // Nothing to do here!
873 return NS_OK;
874}
875
876NS_IMETHODIMPnsresult
877CompareNetwork::OnStreamComplete(nsIStreamLoader* aLoader,
878 nsISupports* aContext, nsresult aStatus,
879 uint32_t aLen, const uint8_t* aString) {
880 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 880); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 880; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
881
882 if (mState == Finished) {
883 return NS_OK;
884 }
885
886 nsresult rv = NS_ERROR_FAILURE;
887 auto guard = MakeScopeExit([&] { NetworkFinish(rv); });
888
889 if (NS_WARN_IF(NS_FAILED(aStatus))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(aStatus
)), 0))), "NS_FAILED(aStatus)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 889)
) {
890 rv = (aStatus == NS_ERROR_REDIRECT_LOOP) ? NS_ERROR_DOM_SECURITY_ERR
891 : aStatus;
892 return NS_OK;
893 }
894
895 nsCOMPtr<nsIRequest> request;
896 rv = aLoader->GetRequest(getter_AddRefs(request));
897 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 897)
) {
898 return NS_OK;
899 }
900
901 nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
902 MOZ_ASSERT(channel, "How come we don't have any channel?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(channel)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(channel))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("channel" " (" "How come we don't have any channel?"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 902); AnnotateMozCrashReason("MOZ_ASSERT" "(" "channel" ") ("
"How come we don't have any channel?" ")"); do { *((volatile
int*)__null) = 902; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
903
904 nsCOMPtr<nsIURI> uri;
905 channel->GetOriginalURI(getter_AddRefs(uri));
906 bool isExtension = uri->SchemeIs("moz-extension");
907
908 if (isExtension &&
909 !StaticPrefs::extensions_backgroundServiceWorker_enabled_AtStartup()) {
910 // Return earlier with error is the worker script is a moz-extension url
911 // but the feature isn't enabled by prefs.
912 return NS_ERROR_FAILURE;
913 }
914
915 if (isExtension) {
916 // NOTE: trying to register any moz-extension use that doesn't ends
917 // with .js/.jsm/.mjs seems to be already completing with an error
918 // in aStatus and they never reach this point.
919
920 // TODO: look into avoid duplicated parts that could be shared with the HTTP
921 // channel scenario.
922 nsCOMPtr<nsIURI> channelURL;
923 rv = channel->GetURI(getter_AddRefs(channelURL));
924 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 924)
) {
925 return rv;
926 }
927
928 nsCString channelURLSpec;
929 MOZ_ALWAYS_SUCCEEDS(channelURL->GetSpec(channelURLSpec))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(channelURL->GetSpec(channelURLSpec))), 1)))), 1))) { } else
{ do { static_assert( mozilla::detail::AssertionConditionType
<decltype(false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("false" " (" "NS_SUCCEEDED(channelURL->GetSpec(channelURLSpec))"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 929); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "NS_SUCCEEDED(channelURL->GetSpec(channelURLSpec))"
")"); do { *((volatile int*)__null) = 929; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
930
931 // Append the final URL (which for an extension worker script is going to
932 // be a file or jar url).
933 MOZ_DIAGNOSTIC_ASSERT(!mURLList.IsEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mURLList.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mURLList.IsEmpty()))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("!mURLList.IsEmpty()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 933); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mURLList.IsEmpty()"
")"); do { *((volatile int*)__null) = 933; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
934 if (channelURLSpec != mURLList[0]) {
935 mURLList.AppendElement(channelURLSpec);
936 }
937
938 UniquePtr<char16_t[], JS::FreePolicy> buffer;
939 size_t len = 0;
940
941 rv = ScriptLoader::ConvertToUTF16(channel, aString, aLen, u"UTF-8"_ns,
942 nullptr, buffer, len);
943 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 943)
) {
944 return rv;
945 }
946
947 mBuffer.Adopt(buffer.release(), len);
948
949 rv = NS_OK;
950 return NS_OK;
951 }
952
953 nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(request);
954
955 // Main scripts cannot be redirected successfully, however extensions
956 // may successfuly redirect imported scripts to a moz-extension url
957 // (if listed in the web_accessible_resources manifest property).
958 //
959 // When the service worker is initially registered the imported scripts
960 // will be loaded from the child process (see dom/workers/ScriptLoader.cpp)
961 // and in that case this method will only be called for the main script.
962 //
963 // When a registered worker is loaded again (e.g. when the webpage calls
964 // the ServiceWorkerRegistration's update method):
965 //
966 // - both the main and imported scripts are loaded by the
967 // CompareManager::FetchScript
968 // - the update requests for the imported scripts will also be calling this
969 // method and we should expect scripts redirected to an extension script
970 // to have a null httpChannel.
971 //
972 // The request that triggers this method is:
973 //
974 // - the one that is coming from the network (which may be intercepted by
975 // WebRequest listeners in extensions and redirected to a web_accessible
976 // moz-extension url)
977 // - it will then be compared with a previous response that we may have
978 // in the cache
979 //
980 // When the next service worker update occurs, if the request (for an imported
981 // script) is not redirected by an extension the cache entry is invalidated
982 // and a network request is triggered for the import.
983 if (!httpChannel) {
984 // Redirecting a service worker main script should fail before reaching this
985 // method.
986 // If a main script is somehow redirected, the diagnostic assert will crash
987 // in non-release builds. Release builds will return an explicit error.
988 MOZ_DIAGNOSTIC_ASSERT(!mIsMainScript,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mIsMainScript)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mIsMainScript))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!mIsMainScript"
" (" "Unexpected ServiceWorker main script redirected" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 989); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mIsMainScript"
") (" "Unexpected ServiceWorker main script redirected" ")")
; do { *((volatile int*)__null) = 989; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
989 "Unexpected ServiceWorker main script redirected")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mIsMainScript)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mIsMainScript))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!mIsMainScript"
" (" "Unexpected ServiceWorker main script redirected" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 989); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mIsMainScript"
") (" "Unexpected ServiceWorker main script redirected" ")")
; do { *((volatile int*)__null) = 989; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
990 if (mIsMainScript) {
991 return NS_ERROR_UNEXPECTED;
992 }
993
994 nsCOMPtr<nsIPrincipal> channelPrincipal;
995
996 nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
997 if (!ssm) {
998 return NS_ERROR_UNEXPECTED;
999 }
1000
1001 nsresult rv = ssm->GetChannelResultPrincipal(
Value stored to 'rv' during its initialization is never read
1002 channel, getter_AddRefs(channelPrincipal));
1003
1004 // An extension did redirect a non-MainScript request to a moz-extension url
1005 // (in that case the originalURL is the resolved jar URI and so we have to
1006 // look to the channel principal instead).
1007 if (channelPrincipal->SchemeIs("moz-extension")) {
1008 UniquePtr<char16_t[], JS::FreePolicy> buffer;
1009 size_t len = 0;
1010
1011 rv = ScriptLoader::ConvertToUTF16(channel, aString, aLen, u"UTF-8"_ns,
1012 nullptr, buffer, len);
1013 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1013)
) {
1014 return rv;
1015 }
1016
1017 mBuffer.Adopt(buffer.release(), len);
1018
1019 return NS_OK;
1020 }
1021
1022 // Make non-release and debug builds to crash if this happens and fail
1023 // explicitly on release builds.
1024 MOZ_DIAGNOSTIC_ASSERT(false,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "ServiceWorker imported script redirected to an url "
"with an unexpected scheme" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1026); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "ServiceWorker imported script redirected to an url " "with an unexpected scheme"
")"); do { *((volatile int*)__null) = 1026; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1025 "ServiceWorker imported script redirected to an url "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "ServiceWorker imported script redirected to an url "
"with an unexpected scheme" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1026); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "ServiceWorker imported script redirected to an url " "with an unexpected scheme"
")"); do { *((volatile int*)__null) = 1026; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1026 "with an unexpected scheme")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "ServiceWorker imported script redirected to an url "
"with an unexpected scheme" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1026); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "ServiceWorker imported script redirected to an url " "with an unexpected scheme"
")"); do { *((volatile int*)__null) = 1026; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1027 return NS_ERROR_UNEXPECTED;
1028 }
1029
1030 bool requestSucceeded;
1031 rv = httpChannel->GetRequestSucceeded(&requestSucceeded);
1032 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1032)
) {
1033 return NS_OK;
1034 }
1035
1036 if (NS_WARN_IF(!requestSucceeded)NS_warn_if_impl(!requestSucceeded, "!requestSucceeded", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1036)
) {
1037 // Get the stringified numeric status code, not statusText which could be
1038 // something misleading like OK for a 404.
1039 uint32_t status = 0;
1040 Unused << httpChannel->GetResponseStatus(
1041 &status); // don't care if this fails, use 0.
1042 nsAutoString statusAsText;
1043 statusAsText.AppendInt(status);
1044
1045 ServiceWorkerManager::LocalizeAndReportToAllClients(
1046 mRegistration->Scope(), "ServiceWorkerRegisterNetworkError",
1047 nsTArray<nsString>{NS_ConvertUTF8toUTF16(mRegistration->Scope()),
1048 statusAsText, NS_ConvertUTF8toUTF16(mURL)});
1049
1050 rv = NS_ERROR_FAILURE;
1051 return NS_OK;
1052 }
1053
1054 // Note: we explicitly don't check for the return value here, because the
1055 // absence of the header is not an error condition.
1056 Unused << httpChannel->GetResponseHeader("Service-Worker-Allowed"_ns,
1057 mMaxScope);
1058
1059 // [9.2 Update]4.13, If response's cache state is not "local",
1060 // set registration's last update check time to the current time
1061 if (!mIsFromCache) {
1062 mRegistration->RefreshLastUpdateCheckTime();
1063 }
1064
1065 nsAutoCString mimeType;
1066 rv = httpChannel->GetContentType(mimeType);
1067 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1067)
) {
1068 // We should only end up here if !mResponseHead in the channel. If headers
1069 // were received but no content type was specified, we'll be given
1070 // UNKNOWN_CONTENT_TYPE "application/x-unknown-content-type" and so fall
1071 // into the next case with its better error message.
1072 rv = NS_ERROR_DOM_SECURITY_ERR;
1073 return rv;
1074 }
1075
1076 if (mimeType.IsEmpty() ||
1077 !nsContentUtils::IsJavascriptMIMEType(NS_ConvertUTF8toUTF16(mimeType))) {
1078 ServiceWorkerManager::LocalizeAndReportToAllClients(
1079 mRegistration->Scope(), "ServiceWorkerRegisterMimeTypeError2",
1080 nsTArray<nsString>{NS_ConvertUTF8toUTF16(mRegistration->Scope()),
1081 NS_ConvertUTF8toUTF16(mimeType),
1082 NS_ConvertUTF8toUTF16(mURL)});
1083 rv = NS_ERROR_DOM_SECURITY_ERR;
1084 return rv;
1085 }
1086
1087 nsCOMPtr<nsIURI> channelURL;
1088 rv = httpChannel->GetURI(getter_AddRefs(channelURL));
1089 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1089)
) {
1090 return rv;
1091 }
1092
1093 nsCString channelURLSpec;
1094 MOZ_ALWAYS_SUCCEEDS(channelURL->GetSpec(channelURLSpec))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(channelURL->GetSpec(channelURLSpec))), 1)))), 1))) { } else
{ do { static_assert( mozilla::detail::AssertionConditionType
<decltype(false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("false" " (" "NS_SUCCEEDED(channelURL->GetSpec(channelURLSpec))"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1094); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "NS_SUCCEEDED(channelURL->GetSpec(channelURLSpec))"
")"); do { *((volatile int*)__null) = 1094; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
1095
1096 // Append the final URL if its different from the original
1097 // request URL. This lets us note that a redirect occurred
1098 // even though we don't track every redirect URL here.
1099 MOZ_DIAGNOSTIC_ASSERT(!mURLList.IsEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mURLList.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mURLList.IsEmpty()))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("!mURLList.IsEmpty()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1099); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mURLList.IsEmpty()"
")"); do { *((volatile int*)__null) = 1099; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1100 if (channelURLSpec != mURLList[0]) {
1101 mURLList.AppendElement(channelURLSpec);
1102 }
1103
1104 UniquePtr<char16_t[], JS::FreePolicy> buffer;
1105 size_t len = 0;
1106
1107 rv = ScriptLoader::ConvertToUTF16(httpChannel, aString, aLen, u"UTF-8"_ns,
1108 nullptr, buffer, len);
1109 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1109)
) {
1110 return rv;
1111 }
1112
1113 mBuffer.Adopt(buffer.release(), len);
1114
1115 rv = NS_OK;
1116 return NS_OK;
1117}
1118
1119nsresult CompareCache::Initialize(Cache* const aCache, const nsACString& aURL) {
1120 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1120); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1120; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1121 MOZ_ASSERT(aCache)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aCache)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aCache))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aCache", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1121); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCache" ")"
); do { *((volatile int*)__null) = 1121; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1122 MOZ_DIAGNOSTIC_ASSERT(mState == WaitingForInitialization)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForInitialization)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mState == WaitingForInitialization
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mState == WaitingForInitialization", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1122); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForInitialization"
")"); do { *((volatile int*)__null) = 1122; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1123
1124 // This JSContext will not end up executing JS code because here there are
1125 // no ReadableStreams involved.
1126 AutoJSAPI jsapi;
1127 jsapi.Init();
1128
1129 RequestOrUTF8String request;
1130 request.SetAsUTF8String().ShareOrDependUpon(aURL);
1131 ErrorResult error;
1132 CacheQueryOptions params;
1133 RefPtr<Promise> promise = aCache->Match(jsapi.cx(), request, params, error);
1134 if (NS_WARN_IF(error.Failed())NS_warn_if_impl(error.Failed(), "error.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1134)
) {
1135 // No exception here because there are no ReadableStreams involved here.
1136 MOZ_ASSERT(!error.IsJSException())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!error.IsJSException())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!error.IsJSException()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!error.IsJSException()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1136); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!error.IsJSException()"
")"); do { *((volatile int*)__null) = 1136; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1137 mState = Finished;
1138 return error.StealNSResult();
1139 }
1140
1141 // Retrieve the script from aCache.
1142 mState = WaitingForScript;
1143 promise->AppendNativeHandler(this);
1144 return NS_OK;
1145}
1146
1147void CompareCache::Finish(nsresult aStatus, bool aInCache) {
1148 if (mState != Finished) {
1149 mState = Finished;
1150 mInCache = aInCache;
1151 mCN->CacheFinish(aStatus);
1152 }
1153}
1154
1155void CompareCache::Abort() {
1156 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1156); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1156; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1157
1158 if (mState != Finished) {
1159 mState = Finished;
1160
1161 if (mPump) {
1162 mPump->CancelWithReason(NS_BINDING_ABORTED, "CompareCache::Abort"_ns);
1163 mPump = nullptr;
1164 }
1165 }
1166}
1167
1168NS_IMETHODIMPnsresult
1169CompareCache::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext,
1170 nsresult aStatus, uint32_t aLen,
1171 const uint8_t* aString) {
1172 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1172); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1172; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1173
1174 if (mState == Finished) {
1175 return aStatus;
1176 }
1177
1178 if (NS_WARN_IF(NS_FAILED(aStatus))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(aStatus
)), 0))), "NS_FAILED(aStatus)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1178)
) {
1179 Finish(aStatus, false);
1180 return aStatus;
1181 }
1182
1183 UniquePtr<char16_t[], JS::FreePolicy> buffer;
1184 size_t len = 0;
1185
1186 nsresult rv = ScriptLoader::ConvertToUTF16(nullptr, aString, aLen,
1187 u"UTF-8"_ns, nullptr, buffer, len);
1188 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1188)
) {
1189 Finish(rv, false);
1190 return rv;
1191 }
1192
1193 mBuffer.Adopt(buffer.release(), len);
1194
1195 Finish(NS_OK, true);
1196 return NS_OK;
1197}
1198
1199void CompareCache::ResolvedCallback(JSContext* aCx,
1200 JS::Handle<JS::Value> aValue,
1201 ErrorResult& aRv) {
1202 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1202); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1202; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1203
1204 switch (mState) {
1205 case Finished:
1206 return;
1207 case WaitingForScript:
1208 ManageValueResult(aCx, aValue);
1209 return;
1210 default:
1211 MOZ_CRASH("Unacceptable state.")do { do { } while (false); MOZ_ReportCrash("" "Unacceptable state."
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1211); AnnotateMozCrashReason("MOZ_CRASH(" "Unacceptable state."
")"); do { *((volatile int*)__null) = 1211; __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
1212 }
1213}
1214
1215void CompareCache::RejectedCallback(JSContext* aCx,
1216 JS::Handle<JS::Value> aValue,
1217 ErrorResult& aRv) {
1218 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1218); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1218; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1219
1220 if (mState != Finished) {
1221 Finish(NS_ERROR_FAILURE, false);
1222 return;
1223 }
1224}
1225
1226void CompareCache::ManageValueResult(JSContext* aCx,
1227 JS::Handle<JS::Value> aValue) {
1228 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1228); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1228; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1229
1230 // The cache returns undefined if the object is not stored.
1231 if (aValue.isUndefined()) {
1232 Finish(NS_OK, false);
1233 return;
1234 }
1235
1236 MOZ_ASSERT(aValue.isObject())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aValue.isObject())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aValue.isObject()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("aValue.isObject()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1236); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aValue.isObject()"
")"); do { *((volatile int*)__null) = 1236; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1237
1238 JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
1239 if (NS_WARN_IF(!obj)NS_warn_if_impl(!obj, "!obj", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1239)
) {
1240 Finish(NS_ERROR_FAILURE, false);
1241 return;
1242 }
1243
1244 Response* response = nullptr;
1245 nsresult rv = UNWRAP_OBJECT(Response, &obj, response)mozilla::dom::binding_detail::UnwrapObjectWithCrossOriginAsserts
< mozilla::dom::prototypes::id::Response, mozilla::dom::Response_Binding
::NativeType>(&obj, response)
;
1246 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1246)
) {
1247 Finish(rv, false);
1248 return;
1249 }
1250
1251 MOZ_ASSERT(response->Ok())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(response->Ok())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(response->Ok()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("response->Ok()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1251); AnnotateMozCrashReason("MOZ_ASSERT" "(" "response->Ok()"
")"); do { *((volatile int*)__null) = 1251; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1252
1253 nsCOMPtr<nsIInputStream> inputStream;
1254 response->GetBody(getter_AddRefs(inputStream));
1255 MOZ_ASSERT(inputStream)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(inputStream)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(inputStream))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("inputStream", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1255); AnnotateMozCrashReason("MOZ_ASSERT" "(" "inputStream"
")"); do { *((volatile int*)__null) = 1255; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1256
1257 MOZ_ASSERT(!mPump)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mPump)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(!mPump))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!mPump", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1257); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mPump" ")"
); do { *((volatile int*)__null) = 1257; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1258 rv = NS_NewInputStreamPump(getter_AddRefs(mPump), inputStream.forget(),
1259 0, /* default segsize */
1260 0, /* default segcount */
1261 false, /* default closeWhenDone */
1262 GetMainThreadSerialEventTarget());
1263 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1263)
) {
1264 Finish(rv, false);
1265 return;
1266 }
1267
1268 nsCOMPtr<nsIStreamLoader> loader;
1269 rv = NS_NewStreamLoader(getter_AddRefs(loader), this);
1270 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1270)
) {
1271 Finish(rv, false);
1272 return;
1273 }
1274
1275 rv = mPump->AsyncRead(loader);
1276 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1276)
) {
1277 mPump = nullptr;
1278 Finish(rv, false);
1279 return;
1280 }
1281
1282 nsCOMPtr<nsIThreadRetargetableRequest> rr = do_QueryInterface(mPump);
1283 if (rr) {
1284 nsCOMPtr<nsIEventTarget> sts =
1285 do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/stream-transport-service;1");
1286 RefPtr<TaskQueue> queue =
1287 TaskQueue::Create(sts.forget(), "CompareCache STS Delivery Queue");
1288 rv = rr->RetargetDeliveryTo(queue);
1289 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1289)
) {
1290 mPump = nullptr;
1291 Finish(rv, false);
1292 return;
1293 }
1294 }
1295}
1296
1297nsresult CompareManager::Initialize(nsIPrincipal* aPrincipal,
1298 const nsACString& aURL,
1299 const nsAString& aCacheName) {
1300 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1300); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1300; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1301 MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPrincipal)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1301); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal"
")"); do { *((volatile int*)__null) = 1301; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1302 MOZ_ASSERT(mPendingCount == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mPendingCount == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mPendingCount == 0))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("mPendingCount == 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1302); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingCount == 0"
")"); do { *((volatile int*)__null) = 1302; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1303 MOZ_DIAGNOSTIC_ASSERT(mState == WaitingForInitialization)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mState == WaitingForInitialization)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mState == WaitingForInitialization
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mState == WaitingForInitialization", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1303); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mState == WaitingForInitialization"
")"); do { *((volatile int*)__null) = 1303; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1304
1305 // RAII Cleanup when fails.
1306 auto guard = MakeScopeExit([&] { Cleanup(); });
1307
1308 mURL = aURL;
1309 mPrincipal = aPrincipal;
1310
1311 // Always create a CacheStorage since we want to write the network entry to
1312 // the cache even if there isn't an existing one.
1313 AutoJSAPI jsapi;
1314 jsapi.Init();
1315 ErrorResult result;
1316 mCacheStorage = CreateCacheStorage(jsapi.cx(), aPrincipal, result);
1317 if (NS_WARN_IF(result.Failed())NS_warn_if_impl(result.Failed(), "result.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1317)
) {
1318 MOZ_ASSERT(!result.IsErrorWithMessage())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!result.IsErrorWithMessage())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!result.IsErrorWithMessage()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"!result.IsErrorWithMessage()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1318); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!result.IsErrorWithMessage()"
")"); do { *((volatile int*)__null) = 1318; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1319 return result.StealNSResult();
1320 }
1321
1322 // If there is no existing cache, proceed to fetch the script directly.
1323 if (aCacheName.IsEmpty()) {
1324 mState = WaitingForScriptOrComparisonResult;
1325 nsresult rv = FetchScript(aURL, true /* aIsMainScript */);
1326 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1326)
) {
1327 return rv;
1328 }
1329
1330 guard.release();
1331 return NS_OK;
1332 }
1333
1334 // Open the cache saving the old source scripts.
1335 RefPtr<Promise> promise = mCacheStorage->Open(aCacheName, result);
1336 if (NS_WARN_IF(result.Failed())NS_warn_if_impl(result.Failed(), "result.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1336)
) {
1337 MOZ_ASSERT(!result.IsErrorWithMessage())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!result.IsErrorWithMessage())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!result.IsErrorWithMessage()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"!result.IsErrorWithMessage()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1337); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!result.IsErrorWithMessage()"
")"); do { *((volatile int*)__null) = 1337; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1338 return result.StealNSResult();
1339 }
1340
1341 mState = WaitingForExistingOpen;
1342 promise->AppendNativeHandler(this);
1343
1344 guard.release();
1345 return NS_OK;
1346}
1347
1348// This class manages 4 promises if needed:
1349// 1. Retrieve the Cache object by a given CacheName of OldCache.
1350// 2. Retrieve the URLs saved in OldCache.
1351// 3. Retrieve the Cache object of the NewCache for the newly created SW.
1352// 4. Put the value in the cache.
1353// For this reason we have mState to know what callback we are handling.
1354void CompareManager::ResolvedCallback(JSContext* aCx,
1355 JS::Handle<JS::Value> aValue,
1356 ErrorResult& aRv) {
1357 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1357); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1357; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1358 MOZ_ASSERT(mCallback)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mCallback)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mCallback))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("mCallback", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1358); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mCallback" ")"
); do { *((volatile int*)__null) = 1358; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1359
1360 switch (mState) {
1361 case Finished:
1362 return;
1363 case WaitingForExistingOpen:
1364 ManageOldCache(aCx, aValue);
1365 return;
1366 case WaitingForExistingKeys:
1367 ManageOldKeys(aCx, aValue);
1368 return;
1369 case WaitingForOpen:
1370 ManageNewCache(aCx, aValue);
1371 return;
1372 case WaitingForPut:
1373 MOZ_DIAGNOSTIC_ASSERT(mPendingCount > 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mPendingCount > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mPendingCount > 0))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("mPendingCount > 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1373); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "mPendingCount > 0"
")"); do { *((volatile int*)__null) = 1373; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1374 if (--mPendingCount == 0) {
1375 mCallback->ComparisonResult(NS_OK, false /* aIsEqual */, mOnFailure,
1376 mNewCacheName, mMaxScope, mLoadFlags);
1377 Cleanup();
1378 }
1379 return;
1380 default:
1381 MOZ_DIAGNOSTIC_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1381); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
")"); do { *((volatile int*)__null) = 1381; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1382 }
1383}
1384
1385void CompareManager::RejectedCallback(JSContext* aCx,
1386 JS::Handle<JS::Value> aValue,
1387 ErrorResult& aRv) {
1388 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1388); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1388; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1389 switch (mState) {
1390 case Finished:
1391 return;
1392 case WaitingForExistingOpen:
1393 NS_WARNING("Could not open the existing cache.")NS_DebugBreak(NS_DEBUG_WARNING, "Could not open the existing cache."
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1393)
;
1394 break;
1395 case WaitingForExistingKeys:
1396 NS_WARNING("Could not get the existing URLs.")NS_DebugBreak(NS_DEBUG_WARNING, "Could not get the existing URLs."
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1396)
;
1397 break;
1398 case WaitingForOpen:
1399 NS_WARNING("Could not open cache.")NS_DebugBreak(NS_DEBUG_WARNING, "Could not open cache.", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1399)
;
1400 break;
1401 case WaitingForPut:
1402 NS_WARNING("Could not write to cache.")NS_DebugBreak(NS_DEBUG_WARNING, "Could not write to cache.", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1402)
;
1403 break;
1404 default:
1405 MOZ_DIAGNOSTIC_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1405); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
")"); do { *((volatile int*)__null) = 1405; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1406 }
1407
1408 Fail(NS_ERROR_FAILURE);
1409}
1410
1411void CompareManager::Fail(nsresult aStatus) {
1412 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1412); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1412; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1413 mCallback->ComparisonResult(aStatus, false /* aIsEqual */, mOnFailure, u""_ns,
1414 ""_ns, mLoadFlags);
1415 Cleanup();
1416}
1417
1418void CompareManager::Cleanup() {
1419 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1419); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1419; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1420
1421 if (mState != Finished) {
1422 mState = Finished;
1423
1424 MOZ_ASSERT(mCallback)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mCallback)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mCallback))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("mCallback", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1424); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mCallback" ")"
); do { *((volatile int*)__null) = 1424; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1425 mCallback = nullptr;
1426
1427 // Abort and release CompareNetworks.
1428 for (uint32_t i = 0; i < mCNList.Length(); ++i) {
1429 mCNList[i]->Abort();
1430 }
1431 mCNList.Clear();
1432 }
1433}
1434
1435} // namespace
1436
1437nsresult PurgeCache(nsIPrincipal* aPrincipal, const nsAString& aCacheName) {
1438 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1438); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1438; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1439 MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPrincipal)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1439); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal"
")"); do { *((volatile int*)__null) = 1439; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1440
1441 if (aCacheName.IsEmpty()) {
1442 return NS_OK;
1443 }
1444
1445 AutoJSAPI jsapi;
1446 jsapi.Init();
1447 ErrorResult rv;
1448 RefPtr<CacheStorage> cacheStorage =
1449 CreateCacheStorage(jsapi.cx(), aPrincipal, rv);
1450 if (NS_WARN_IF(rv.Failed())NS_warn_if_impl(rv.Failed(), "rv.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1450)
) {
1451 return rv.StealNSResult();
1452 }
1453
1454 // We use the ServiceWorker scope as key for the cacheStorage.
1455 RefPtr<Promise> promise = cacheStorage->Delete(aCacheName, rv);
1456 if (NS_WARN_IF(rv.Failed())NS_warn_if_impl(rv.Failed(), "rv.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1456)
) {
1457 return rv.StealNSResult();
1458 }
1459
1460 // Set [[PromiseIsHandled]] to ensure that if this promise gets rejected,
1461 // we don't end up reporting a rejected promise to the console.
1462 MOZ_ALWAYS_TRUE(promise->SetAnyPromiseIsHandled())do { if ((__builtin_expect(!!(promise->SetAnyPromiseIsHandled
()), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("false" " (" "promise->SetAnyPromiseIsHandled()"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1462); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "promise->SetAnyPromiseIsHandled()" ")"); do { *((volatile
int*)__null) = 1462; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false); } } while (false)
;
1463
1464 // We don't actually care about the result of the delete operation.
1465 return NS_OK;
1466}
1467
1468nsresult GenerateCacheName(nsAString& aName) {
1469 nsresult rv;
1470 nsCOMPtr<nsIUUIDGenerator> uuidGenerator =
1471 do_GetService("@mozilla.org/uuid-generator;1", &rv);
1472 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1472)
) {
1473 return rv;
1474 }
1475
1476 nsID id;
1477 rv = uuidGenerator->GenerateUUIDInPlace(&id);
1478 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1478)
) {
1479 return rv;
1480 }
1481
1482 char chars[NSID_LENGTH39];
1483 id.ToProvidedString(chars);
1484
1485 // NSID_LENGTH counts the null terminator.
1486 aName.AssignASCII(chars, NSID_LENGTH39 - 1);
1487
1488 return NS_OK;
1489}
1490
1491nsresult Compare(ServiceWorkerRegistrationInfo* aRegistration,
1492 nsIPrincipal* aPrincipal, const nsAString& aCacheName,
1493 const nsACString& aURL, CompareCallback* aCallback) {
1494 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1494); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1494; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1495 MOZ_ASSERT(aRegistration)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aRegistration)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aRegistration))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("aRegistration",
"/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1495); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aRegistration"
")"); do { *((volatile int*)__null) = 1495; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1496 MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPrincipal)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1496); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal"
")"); do { *((volatile int*)__null) = 1496; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1497 MOZ_ASSERT(!aURL.IsEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aURL.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aURL.IsEmpty()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!aURL.IsEmpty()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1497); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aURL.IsEmpty()"
")"); do { *((volatile int*)__null) = 1497; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1498 MOZ_ASSERT(aCallback)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aCallback)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aCallback))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aCallback", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1498); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCallback" ")"
); do { *((volatile int*)__null) = 1498; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1499
1500 RefPtr<CompareManager> cm = new CompareManager(aRegistration, aCallback);
1501
1502 nsresult rv = cm->Initialize(aPrincipal, aURL, aCacheName);
1503 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/serviceworkers/ServiceWorkerScriptCache.cpp"
, 1503)
) {
1504 return rv;
1505 }
1506
1507 return NS_OK;
1508}
1509
1510} // namespace mozilla::dom::serviceWorkerScriptCache