mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-04 08:36:12 +00:00
AK+Everywhere: Store JSON strings as String
This commit is contained in:
parent
e591636419
commit
bc54c0cdfb
Notes:
github-actions[bot]
2025-02-21 00:29:21 +00:00
Author: https://github.com/trflynn89
Commit: bc54c0cdfb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3631
Reviewed-by: https://github.com/awesomekling ✅
33 changed files with 163 additions and 152 deletions
|
@ -235,9 +235,9 @@ static bool matches_platform_name(StringView requested_platform_name, StringView
|
|||
// https://w3c.github.io/webdriver/#dfn-matching-capabilities
|
||||
static JsonValue match_capabilities(JsonObject const& capabilities, SessionFlags flags)
|
||||
{
|
||||
static auto browser_name = StringView { BROWSER_NAME, strlen(BROWSER_NAME) }.to_lowercase_string();
|
||||
static constexpr auto browser_version = StringView { BROWSER_VERSION, __builtin_strlen(BROWSER_VERSION) };
|
||||
static auto platform_name = StringView { OS_STRING, strlen(OS_STRING) }.to_lowercase_string();
|
||||
static auto browser_name = String::from_utf8_without_validation({ BROWSER_NAME, __builtin_strlen(BROWSER_NAME) }).to_ascii_lowercase();
|
||||
static auto browser_version = String::from_utf8_without_validation({ BROWSER_VERSION, __builtin_strlen(BROWSER_VERSION) });
|
||||
static auto platform_name = String::from_utf8_without_validation({ OS_STRING, __builtin_strlen(OS_STRING) }).to_ascii_lowercase();
|
||||
|
||||
// 1. Let matched capabilities be a JSON Object with the following entries:
|
||||
JsonObject matched_capabilities;
|
||||
|
@ -283,7 +283,7 @@ static JsonValue match_capabilities(JsonObject const& capabilities, SessionFlags
|
|||
// -> "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_byte_string(name).value())
|
||||
if (value.as_string() != matched_capabilities.get_string(name).value())
|
||||
return AK::Error::from_string_literal("browserName");
|
||||
}
|
||||
// -> "browserVersion"
|
||||
|
|
|
@ -329,8 +329,8 @@ ErrorOr<void, Client::WrappedError> Client::send_error_response(HTTP::HttpReques
|
|||
auto reason = HTTP::HttpResponse::reason_phrase_for_code(error.http_status);
|
||||
|
||||
JsonObject error_response;
|
||||
error_response.set("error"sv, error.error);
|
||||
error_response.set("message"sv, error.message);
|
||||
error_response.set("error"sv, MUST(String::from_byte_string(error.error)));
|
||||
error_response.set("message"sv, MUST(String::from_byte_string(error.message)));
|
||||
error_response.set("stacktrace"sv, ""sv);
|
||||
if (error.data.has_value())
|
||||
error_response.set("data"sv, *error.data);
|
||||
|
|
|
@ -39,7 +39,7 @@ JsonObject window_proxy_reference_object(HTML::WindowProxy const& window)
|
|||
|
||||
// identifier
|
||||
// Associated window handle of the window’s browsing context.
|
||||
object.set(identifier, navigable->traversable_navigable()->window_handle().to_byte_string());
|
||||
object.set(identifier, navigable->traversable_navigable()->window_handle());
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ JsonObject web_element_reference_object(HTML::BrowsingContext const& browsing_co
|
|||
|
||||
// 3. Return a JSON Object initialized with a property with name identifier and value reference.
|
||||
JsonObject object;
|
||||
object.set(identifier, reference);
|
||||
object.set(identifier, MUST(String::from_byte_string(reference)));
|
||||
return object;
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,7 @@ JsonObject shadow_root_reference_object(HTML::BrowsingContext const& browsing_co
|
|||
|
||||
// 3. Return a JSON Object initialized with a property with name identifier and value reference.
|
||||
JsonObject object;
|
||||
object.set(identifier, reference);
|
||||
object.set(identifier, MUST(String::from_byte_string(reference)));
|
||||
return object;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ static ErrorOr<PropertyType, WebDriver::Error> get_property(JsonObject const& pa
|
|||
if constexpr (IsSame<PropertyType, ByteString>) {
|
||||
if (!property->is_string())
|
||||
return WebDriver::Error::from_code(ErrorCode::InvalidArgument, ByteString::formatted("Property '{}' is not a String", key));
|
||||
return property->as_string();
|
||||
return property->as_string().to_byte_string();
|
||||
} else if constexpr (IsSame<PropertyType, bool>) {
|
||||
if (!property->is_bool())
|
||||
return WebDriver::Error::from_code(ErrorCode::InvalidArgument, ByteString::formatted("Property '{}' is not a Boolean", key));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue