diff options
Diffstat (limited to 'dom/fetch/Request.cpp')
-rw-r--r-- | dom/fetch/Request.cpp | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp index 8108d2522b..e042dd6271 100644 --- a/dom/fetch/Request.cpp +++ b/dom/fetch/Request.cpp @@ -329,27 +329,37 @@ SafeRefPtr<Request> Request::Constructor(nsIGlobalObject* aGlobal, if (NS_WARN_IF(aRv.Failed())) { return nullptr; } - RequestMode fallbackMode = RequestMode::EndGuard_; - RequestCredentials fallbackCredentials = RequestCredentials::EndGuard_; - RequestCache fallbackCache = RequestCache::EndGuard_; + Maybe<RequestMode> mode; + if (aInit.mMode.WasPassed()) { + if (aInit.mMode.Value() == RequestMode::Navigate) { + aRv.ThrowTypeError<MSG_INVALID_REQUEST_MODE>("navigate"); + return nullptr; + } + + mode.emplace(aInit.mMode.Value()); + } + Maybe<RequestCredentials> credentials; + if (aInit.mCredentials.WasPassed()) { + credentials.emplace(aInit.mCredentials.Value()); + } + Maybe<RequestCache> cache; + if (aInit.mCache.WasPassed()) { + cache.emplace(aInit.mCache.Value()); + } if (aInput.IsUSVString()) { - fallbackMode = RequestMode::Cors; - fallbackCredentials = RequestCredentials::Same_origin; - fallbackCache = RequestCache::Default; + if (mode.isNothing()) { + mode.emplace(RequestMode::Cors); + } + if (credentials.isNothing()) { + credentials.emplace(RequestCredentials::Same_origin); + } + if (cache.isNothing()) { + cache.emplace(RequestCache::Default); + } } - RequestMode mode = - aInit.mMode.WasPassed() ? aInit.mMode.Value() : fallbackMode; - RequestCredentials credentials = aInit.mCredentials.WasPassed() - ? aInit.mCredentials.Value() - : fallbackCredentials; - - if (mode == RequestMode::Navigate) { - aRv.ThrowTypeError<MSG_INVALID_REQUEST_MODE>("navigate"); - return nullptr; - } if (aInit.IsAnyMemberPresent() && request->Mode() == RequestMode::Navigate) { - mode = RequestMode::Same_origin; + mode = Some(RequestMode::Same_origin); } if (aInit.IsAnyMemberPresent()) { @@ -430,6 +440,13 @@ SafeRefPtr<Request> Request::Constructor(nsIGlobalObject* aGlobal, signal = aInit.mSignal.Value(); } + // https://fetch.spec.whatwg.org/#dom-global-fetch + // https://fetch.spec.whatwg.org/#dom-request + // The priority of init overrides input's priority. + if (aInit.mPriority.WasPassed()) { + request->SetPriorityMode(aInit.mPriority.Value()); + } + UniquePtr<mozilla::ipc::PrincipalInfo> principalInfo; nsILoadInfo::CrossOriginEmbedderPolicy coep = nsILoadInfo::EMBEDDER_POLICY_NULL; @@ -473,24 +490,22 @@ SafeRefPtr<Request> Request::Constructor(nsIGlobalObject* aGlobal, request->SetPrincipalInfo(std::move(principalInfo)); request->SetEmbedderPolicy(coep); - if (mode != RequestMode::EndGuard_) { - request->SetMode(mode); + if (mode.isSome()) { + request->SetMode(mode.value()); } - if (credentials != RequestCredentials::EndGuard_) { - request->SetCredentialsMode(credentials); + if (credentials.isSome()) { + request->SetCredentialsMode(credentials.value()); } - RequestCache cache = - aInit.mCache.WasPassed() ? aInit.mCache.Value() : fallbackCache; - if (cache != RequestCache::EndGuard_) { - if (cache == RequestCache::Only_if_cached && + if (cache.isSome()) { + if (cache.value() == RequestCache::Only_if_cached && request->Mode() != RequestMode::Same_origin) { - nsCString modeString(RequestModeValues::GetString(request->Mode())); - aRv.ThrowTypeError<MSG_ONLY_IF_CACHED_WITHOUT_SAME_ORIGIN>(modeString); + aRv.ThrowTypeError<MSG_ONLY_IF_CACHED_WITHOUT_SAME_ORIGIN>( + GetEnumString(request->Mode())); return nullptr; } - request->SetCacheMode(cache); + request->SetCacheMode(cache.value()); } if (aInit.mRedirect.WasPassed()) { |