From d8fde14324c8318363b68573bcd9b51c17e6b7e0 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 21 Dec 2022 17:28:20 +0000 Subject: [PATCH] LibWeb: Replace uses of JsonObject::get_deprecated()/get_ptr() --- .../LibWeb/WebDriver/Capabilities.cpp | 32 +++++++++---------- .../WebDriver/TimeoutsConfiguration.cpp | 20 ++++++------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp b/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp index 125feeab3f..e5e96c42ba 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp @@ -52,7 +52,7 @@ static Response deserialize_as_ladybird_options(JsonValue value) auto const& object = value.as_object(); - if (auto const* headless = object.get_ptr("headless"sv); headless && !headless->is_bool()) + if (auto headless = object.get_bool("headless"sv); headless.has_value()) return Error::from_code(ErrorCode::InvalidArgument, "Extension capability serenity:ladybird/headless must be a boolean"sv); return value; @@ -188,10 +188,10 @@ static ErrorOr merge_capabilities(JsonObject const& primary, // b. Let value be the result of getting a property named name from secondary. // c. Let primary value be the result of getting the property name from primary. - auto const* primary_value = primary.get_ptr(name); + auto primary_value = primary.get(name); // d. If primary value is not undefined, return an error with error code invalid argument. - if (primary_value != nullptr) + if (primary_value.has_value()) return Error::from_code(ErrorCode::InvalidArgument, DeprecatedString::formatted("Unable to merge capability {}", name)); // e. Set a property on result with name name and value value. @@ -267,20 +267,20 @@ static JsonValue match_capabilities(JsonObject const& capabilities) // -> "browserName" if (name == "browserName"sv) { // If value is not a string equal to the "browserName" entry in matched capabilities, return success with data null. - if (value.as_string() != matched_capabilities.get_deprecated(name).as_string()) + if (value.as_string() != matched_capabilities.get_deprecated_string(name).value()) return AK::Error::from_string_view("browserName"sv); } // -> "browserVersion" else if (name == "browserVersion"sv) { // Compare value to the "browserVersion" entry in matched capabilities using an implementation-defined comparison algorithm. The comparison is to accept a value that places constraints on the version using the "<", "<=", ">", and ">=" operators. // If the two values do not match, return success with data null. - if (!matches_browser_version(value.as_string(), matched_capabilities.get_deprecated(name).as_string())) + if (!matches_browser_version(value.as_string(), matched_capabilities.get_deprecated_string(name).value())) return AK::Error::from_string_view("browserVersion"sv); } // -> "platformName" else if (name == "platformName"sv) { // If value is not a string equal to the "platformName" entry in matched capabilities, return success with data null. - if (!matches_platform_name(value.as_string(), matched_capabilities.get_deprecated(name).as_string())) + if (!matches_platform_name(value.as_string(), matched_capabilities.get_deprecated_string(name).value())) return AK::Error::from_string_view("platformName"sv); } // -> "acceptInsecureCerts" @@ -321,17 +321,17 @@ Response process_capabilities(JsonValue const& parameters) // 1. Let capabilities request be the result of getting the property "capabilities" from parameters. // a. If capabilities request is not a JSON Object, return error with error code invalid argument. - auto const* capabilities_request_ptr = parameters.as_object().get_ptr("capabilities"sv); - if (!capabilities_request_ptr || !capabilities_request_ptr->is_object()) + auto maybe_capabilities_request = parameters.as_object().get_object("capabilities"sv); + if (!maybe_capabilities_request.has_value()) return Error::from_code(ErrorCode::InvalidArgument, "Capabilities is not an object"sv); - auto const& capabilities_request = capabilities_request_ptr->as_object(); + auto const& capabilities_request = maybe_capabilities_request.value(); // 2. Let required capabilities be the result of getting the property "alwaysMatch" from capabilities request. // a. If required capabilities is undefined, set the value to an empty JSON Object. JsonObject required_capabilities; - if (auto const* capability = capabilities_request.get_ptr("alwaysMatch"sv)) { + if (auto capability = capabilities_request.get("alwaysMatch"sv); capability.has_value()) { // b. Let required capabilities be the result of trying to validate capabilities with argument required capabilities. required_capabilities = TRY(validate_capabilities(*capability)); } @@ -339,7 +339,7 @@ Response process_capabilities(JsonValue const& parameters) // 3. Let all first match capabilities be the result of getting the property "firstMatch" from capabilities request. JsonArray all_first_match_capabilities; - if (auto const* capabilities = capabilities_request.get_ptr("firstMatch"sv)) { + if (auto capabilities = capabilities_request.get("firstMatch"sv); capabilities.has_value()) { // b. If all first match capabilities is not a JSON List with one or more entries, return error with error code invalid argument. if (!capabilities->is_array() || capabilities->as_array().is_empty()) return Error::from_code(ErrorCode::InvalidArgument, "Capability firstMatch must be an array with at least one entry"sv); @@ -394,13 +394,13 @@ Response process_capabilities(JsonValue const& parameters) LadybirdOptions::LadybirdOptions(JsonObject const& capabilities) { - auto const* options = capabilities.get_ptr("serenity:ladybird"sv); - if (!options || !options->is_object()) + auto options = capabilities.get_object("serenity:ladybird"sv); + if (!options.has_value()) return; - auto const* headless = options->as_object().get_ptr("headless"sv); - if (headless && headless->is_bool()) - this->headless = headless->as_bool(); + auto headless = options->get_bool("headless"sv); + if (headless.has_value()) + this->headless = headless.value(); } } diff --git a/Userland/Libraries/LibWeb/WebDriver/TimeoutsConfiguration.cpp b/Userland/Libraries/LibWeb/WebDriver/TimeoutsConfiguration.cpp index dd129616f5..21866fe82a 100644 --- a/Userland/Libraries/LibWeb/WebDriver/TimeoutsConfiguration.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/TimeoutsConfiguration.cpp @@ -48,42 +48,42 @@ ErrorOr json_deserialize_as_a_timeouts_configurati // 3. If value has a property with the key "script": if (value.as_object().has("script"sv)) { // 1. Let script duration be the value of property "script". - auto const& script_duration = value.as_object().get_deprecated("script"sv); + auto script_duration = value.as_object().get("script"sv); // 2. If script duration is a number and less than 0 or greater than maximum safe integer, or it is not null, return error with error code invalid argument. - if (script_duration.is_number() && (script_duration.to_i64() < 0 || script_duration.to_i64() > max_safe_integer)) + if (script_duration.has_value() && script_duration->is_number() && (script_duration->to_i64() < 0 || script_duration->to_i64() > max_safe_integer)) return Error::from_code(ErrorCode::InvalidArgument, "Invalid script duration"); - if (!script_duration.is_number() && !script_duration.is_null()) + if (script_duration.has_value() && !script_duration->is_number() && !script_duration->is_null()) return Error::from_code(ErrorCode::InvalidArgument, "Invalid script duration"); // 3. Set timeouts’s script timeout to script duration. - timeouts.script_timeout = script_duration.is_null() ? Optional {} : script_duration.to_u64(); + timeouts.script_timeout = (!script_duration.has_value() || script_duration->is_null()) ? Optional {} : script_duration->to_u64(); } // 4. If value has a property with the key "pageLoad": if (value.as_object().has("pageLoad"sv)) { // 1. Let page load duration be the value of property "pageLoad". - auto const& page_load_duration = value.as_object().get_deprecated("pageLoad"sv); + auto page_load_duration = value.as_object().get_i64("pageLoad"sv); // 2. If page load duration is less than 0 or greater than maximum safe integer, return error with error code invalid argument. - if (!page_load_duration.is_number() || page_load_duration.to_i64() < 0 || page_load_duration.to_i64() > max_safe_integer) + if (!page_load_duration.has_value() || *page_load_duration < 0 || *page_load_duration > max_safe_integer) return Error::from_code(ErrorCode::InvalidArgument, "Invalid page load duration"); // 3. Set timeouts’s page load timeout to page load duration. - timeouts.page_load_timeout = page_load_duration.to_u64(); + timeouts.page_load_timeout = static_cast(*page_load_duration); } // 5. If value has a property with the key "implicit": if (value.as_object().has("implicit"sv)) { // 1. Let implicit duration be the value of property "implicit". - auto const& implicit_duration = value.as_object().get_deprecated("implicit"sv); + auto implicit_duration = value.as_object().get_i64("implicit"sv); // 2. If implicit duration is less than 0 or greater than maximum safe integer, return error with error code invalid argument. - if (!implicit_duration.is_number() || implicit_duration.to_i64() < 0 || implicit_duration.to_i64() > max_safe_integer) + if (!implicit_duration.has_value() || *implicit_duration < 0 || *implicit_duration > max_safe_integer) return Error::from_code(ErrorCode::InvalidArgument, "Invalid implicit duration"); // 3. Set timeouts’s implicit wait timeout to implicit duration. - timeouts.implicit_wait_timeout = implicit_duration.to_u64(); + timeouts.implicit_wait_timeout = static_cast(*implicit_duration); } // 6. Return success with data timeouts.