From 9afcbdf452b0dac38291c32efd27815d7537d6a4 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 2 Mar 2023 20:10:16 +0000 Subject: [PATCH] LibWeb: Update generated code in Bindings/FetchMethod.cpp Also update the incomplete and slightly incorrect dummy interface code snippet I used to generate this. --- .../Libraries/LibWeb/Bindings/FetchMethod.cpp | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/Userland/Libraries/LibWeb/Bindings/FetchMethod.cpp b/Userland/Libraries/LibWeb/Bindings/FetchMethod.cpp index 1d1a1c7db6..40a9b6de9b 100644 --- a/Userland/Libraries/LibWeb/Bindings/FetchMethod.cpp +++ b/Userland/Libraries/LibWeb/Bindings/FetchMethod.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Linus Groh + * Copyright (c) 2022-2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -21,9 +21,14 @@ #include // NOTE: This file contains code generated by BindingsGenerator from the following input: +// ```idl +// #import +// #import +// [Exposed=Window] // interface Dummy { -// static Promise fetch(RequestInfo input, optional RequestInfo init = {}); +// static Promise fetch(RequestInfo input, optional RequestInit init = {}); // }; +// ``` // This is because the spec defines the fetch() method as a 'partial interface mixin' on // WindowOrWorkerGlobalScope, which we don't support yet - and even if we did, the Window object is // not generated from IDL currently, so we couldn't add a mixin to it that way. The generated code @@ -102,19 +107,19 @@ JS::ThrowCompletionOr fetch(JS::VM& vm) if (!cache_property_value.is_undefined()) { RequestCache cache_value { RequestCache::Default }; if (!cache_property_value.is_undefined()) { - auto cache_property_value_string = TRY(cache_property_value.to_deprecated_string(vm)); - if (cache_property_value_string == "only-if-cached"sv) - cache_value = RequestCache::OnlyIfCached; - else if (cache_property_value_string == "default"sv) + auto cache_property_value_string = TRY(cache_property_value.to_string(vm)); + if (cache_property_value_string == "default"sv) cache_value = RequestCache::Default; else if (cache_property_value_string == "no-store"sv) cache_value = RequestCache::NoStore; - else if (cache_property_value_string == "force-cache"sv) - cache_value = RequestCache::ForceCache; else if (cache_property_value_string == "reload"sv) cache_value = RequestCache::Reload; else if (cache_property_value_string == "no-cache"sv) cache_value = RequestCache::NoCache; + else if (cache_property_value_string == "force-cache"sv) + cache_value = RequestCache::ForceCache; + else if (cache_property_value_string == "only-if-cached"sv) + cache_value = RequestCache::OnlyIfCached; else return vm.throw_completion(JS::ErrorType::InvalidEnumerationValue, cache_property_value_string, "RequestCache"); } @@ -126,13 +131,13 @@ JS::ThrowCompletionOr fetch(JS::VM& vm) if (!credentials_property_value.is_undefined()) { RequestCredentials credentials_value { RequestCredentials::Omit }; if (!credentials_property_value.is_undefined()) { - auto credentials_property_value_string = TRY(credentials_property_value.to_deprecated_string(vm)); - if (credentials_property_value_string == "same-origin"sv) + auto credentials_property_value_string = TRY(credentials_property_value.to_string(vm)); + if (credentials_property_value_string == "omit"sv) + credentials_value = RequestCredentials::Omit; + else if (credentials_property_value_string == "same-origin"sv) credentials_value = RequestCredentials::SameOrigin; else if (credentials_property_value_string == "include"sv) credentials_value = RequestCredentials::Include; - else if (credentials_property_value_string == "omit"sv) - credentials_value = RequestCredentials::Omit; else return vm.throw_completion(JS::ErrorType::InvalidEnumerationValue, credentials_property_value_string, "RequestCredentials"); } @@ -144,7 +149,7 @@ JS::ThrowCompletionOr fetch(JS::VM& vm) if (!duplex_property_value.is_undefined()) { RequestDuplex duplex_value { RequestDuplex::Half }; if (!duplex_property_value.is_undefined()) { - auto duplex_property_value_string = TRY(duplex_property_value.to_deprecated_string(vm)); + auto duplex_property_value_string = TRY(duplex_property_value.to_string(vm)); if (duplex_property_value_string == "half"sv) duplex_value = RequestDuplex::Half; else @@ -267,7 +272,7 @@ JS::ThrowCompletionOr fetch(JS::VM& vm) if (!mode_property_value.is_undefined()) { RequestMode mode_value { RequestMode::Navigate }; if (!mode_property_value.is_undefined()) { - auto mode_property_value_string = TRY(mode_property_value.to_deprecated_string(vm)); + auto mode_property_value_string = TRY(mode_property_value.to_string(vm)); if (mode_property_value_string == "navigate"sv) mode_value = RequestMode::Navigate; else if (mode_property_value_string == "same-origin"sv) @@ -287,13 +292,13 @@ JS::ThrowCompletionOr fetch(JS::VM& vm) if (!redirect_property_value.is_undefined()) { RequestRedirect redirect_value { RequestRedirect::Follow }; if (!redirect_property_value.is_undefined()) { - auto redirect_property_value_string = TRY(redirect_property_value.to_deprecated_string(vm)); + auto redirect_property_value_string = TRY(redirect_property_value.to_string(vm)); if (redirect_property_value_string == "follow"sv) redirect_value = RequestRedirect::Follow; - else if (redirect_property_value_string == "manual"sv) - redirect_value = RequestRedirect::Manual; else if (redirect_property_value_string == "error"sv) redirect_value = RequestRedirect::Error; + else if (redirect_property_value_string == "manual"sv) + redirect_value = RequestRedirect::Manual; else return vm.throw_completion(JS::ErrorType::InvalidEnumerationValue, redirect_property_value_string, "RequestRedirect"); } @@ -318,25 +323,25 @@ JS::ThrowCompletionOr fetch(JS::VM& vm) if (!referrer_policy_property_value.is_undefined()) { ReferrerPolicy referrer_policy_value { ReferrerPolicy::Empty }; if (!referrer_policy_property_value.is_undefined()) { - auto referrer_policy_property_value_string = TRY(referrer_policy_property_value.to_deprecated_string(vm)); + auto referrer_policy_property_value_string = TRY(referrer_policy_property_value.to_string(vm)); if (referrer_policy_property_value_string == ""sv) referrer_policy_value = ReferrerPolicy::Empty; + else if (referrer_policy_property_value_string == "no-referrer"sv) + referrer_policy_value = ReferrerPolicy::NoReferrer; + else if (referrer_policy_property_value_string == "no-referrer-when-downgrade"sv) + referrer_policy_value = ReferrerPolicy::NoReferrerWhenDowngrade; else if (referrer_policy_property_value_string == "same-origin"sv) referrer_policy_value = ReferrerPolicy::SameOrigin; else if (referrer_policy_property_value_string == "origin"sv) referrer_policy_value = ReferrerPolicy::Origin; - else if (referrer_policy_property_value_string == "origin-when-cross-origin"sv) - referrer_policy_value = ReferrerPolicy::OriginWhenCrossOrigin; else if (referrer_policy_property_value_string == "strict-origin"sv) referrer_policy_value = ReferrerPolicy::StrictOrigin; - else if (referrer_policy_property_value_string == "no-referrer"sv) - referrer_policy_value = ReferrerPolicy::NoReferrer; - else if (referrer_policy_property_value_string == "unsafe-url"sv) - referrer_policy_value = ReferrerPolicy::UnsafeUrl; - else if (referrer_policy_property_value_string == "no-referrer-when-downgrade"sv) - referrer_policy_value = ReferrerPolicy::NoReferrerWhenDowngrade; + else if (referrer_policy_property_value_string == "origin-when-cross-origin"sv) + referrer_policy_value = ReferrerPolicy::OriginWhenCrossOrigin; else if (referrer_policy_property_value_string == "strict-origin-when-cross-origin"sv) referrer_policy_value = ReferrerPolicy::StrictOriginWhenCrossOrigin; + else if (referrer_policy_property_value_string == "unsafe-url"sv) + referrer_policy_value = ReferrerPolicy::UnsafeUrl; else return vm.throw_completion(JS::ErrorType::InvalidEnumerationValue, referrer_policy_property_value_string, "ReferrerPolicy"); }