already_AddRefed<Promise> CacheStorage::Match(const RequestOrUSVString& aRequest, const CacheQueryOptions& aOptions, ErrorResult& aRv) { NS_ASSERT_OWNINGTHREAD(CacheStorage); if (NS_WARN_IF(NS_FAILED(mStatus))) { aRv.Throw(mStatus); return nullptr; } RefPtr<InternalRequest> request = ToInternalRequest(aRequest, IgnoreBody, aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } RefPtr<Promise> promise = Promise::Create(mGlobal, aRv); if (NS_WARN_IF(!promise)) { return nullptr; } CacheQueryParams params; ToCacheQueryParams(params, aOptions); nsAutoPtr<Entry> entry(new Entry()); entry->mPromise = promise; entry->mArgs = StorageMatchArgs(CacheRequest(), params); entry->mRequest = request; mPendingRequests.AppendElement(entry.forget()); MaybeRunPendingRequests(); return promise.forget(); }
already_AddRefed<Promise> CacheStorage::Match(JSContext* aCx, const RequestOrUSVString& aRequest, const CacheQueryOptions& aOptions, ErrorResult& aRv) { NS_ASSERT_OWNINGTHREAD(CacheStorage); if (!HasStorageAccess()) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); return nullptr; } if (NS_WARN_IF(NS_FAILED(mStatus))) { aRv.Throw(mStatus); return nullptr; } RefPtr<InternalRequest> request = ToInternalRequest(aCx, aRequest, IgnoreBody, aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } RefPtr<Promise> promise = Promise::Create(mGlobal, aRv); if (NS_WARN_IF(!promise)) { return nullptr; } CacheQueryParams params; ToCacheQueryParams(params, aOptions); nsAutoPtr<Entry> entry(new Entry()); entry->mPromise = promise; entry->mArgs = StorageMatchArgs(CacheRequest(), params, GetOpenMode()); entry->mRequest = request; RunRequest(std::move(entry)); return promise.forget(); }