From 70eb0ba1cd61796558eb1ed228446e2ac6fad273 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 17 Feb 2025 11:59:45 -0500 Subject: [PATCH] AK+Everywhere: Remove the `char const*` JSON value constructor --- AK/JsonValue.cpp | 5 ----- AK/JsonValue.h | 1 - Libraries/LibCore/ArgsParser.cpp | 4 ++-- Libraries/LibDevTools/Actors/DeviceActor.cpp | 17 +++++++++------ Libraries/LibDevTools/Actors/WalkerActor.cpp | 2 +- Libraries/LibGC/Heap.cpp | 8 +++---- Libraries/LibWeb/WebDriver/Capabilities.cpp | 3 ++- Libraries/LibWeb/WebDriver/Client.cpp | 2 +- Tests/AK/TestJSON.cpp | 6 +++--- Tests/LibJS/test262-runner.cpp | 22 ++++++++++---------- 10 files changed, 35 insertions(+), 35 deletions(-) diff --git a/AK/JsonValue.cpp b/AK/JsonValue.cpp index ca2a1413407..0430b9d3960 100644 --- a/AK/JsonValue.cpp +++ b/AK/JsonValue.cpp @@ -152,11 +152,6 @@ JsonValue::JsonValue(long long unsigned value) { } -JsonValue::JsonValue(char const* cstring) - : m_value(ByteString { cstring }) -{ -} - JsonValue::JsonValue(double value) : m_value(double { value }) { diff --git a/AK/JsonValue.h b/AK/JsonValue.h index 0dff0f6e738..7979261bf41 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -55,7 +55,6 @@ public: JsonValue(long long unsigned); JsonValue(double); - JsonValue(char const*); JsonValue(ByteString const&); JsonValue(StringView); diff --git a/Libraries/LibCore/ArgsParser.cpp b/Libraries/LibCore/ArgsParser.cpp index 3d37d9d7cf4..3a9ecece403 100644 --- a/Libraries/LibCore/ArgsParser.cpp +++ b/Libraries/LibCore/ArgsParser.cpp @@ -752,8 +752,8 @@ void ArgsParser::autocomplete(FILE* file, StringView program_name, ReadonlySpan< object.set("completion", ByteString::formatted(StringView { format, strlen(format) }, args...)); object.set("static_offset", 0); object.set("invariant_offset", has_invariant ? option_to_complete.length() : 0u); - object.set("display_trivia", option.help_string); - object.set("trailing_trivia", option.argument_mode == OptionArgumentMode::Required ? " " : ""); + object.set("display_trivia", StringView { option.help_string, strlen(option.help_string) }); + object.set("trailing_trivia", option.argument_mode == OptionArgumentMode::Required ? " "sv : ""sv); outln(file, "{}", object.to_byte_string()); }; diff --git a/Libraries/LibDevTools/Actors/DeviceActor.cpp b/Libraries/LibDevTools/Actors/DeviceActor.cpp index 858fd4a919c..b0fb4b83414 100644 --- a/Libraries/LibDevTools/Actors/DeviceActor.cpp +++ b/Libraries/LibDevTools/Actors/DeviceActor.cpp @@ -29,18 +29,23 @@ void DeviceActor::handle_message(StringView type, JsonObject const&) if (type == "getDescription"sv) { auto build_id = Core::Version::read_long_version_string().to_byte_string(); + static constexpr auto browser_name = StringView { BROWSER_NAME, __builtin_strlen(BROWSER_NAME) }; + static constexpr auto browser_version = StringView { BROWSER_VERSION, __builtin_strlen(BROWSER_VERSION) }; + static constexpr auto platform_name = StringView { OS_STRING, __builtin_strlen(OS_STRING) }; + static constexpr auto arch = StringView { CPU_STRING, __builtin_strlen(CPU_STRING) }; + // https://github.com/mozilla/gecko-dev/blob/master/devtools/shared/system.js JsonObject value; - value.set("apptype"sv, "ladybird"sv); - value.set("name"sv, BROWSER_NAME); - value.set("brandName"sv, BROWSER_NAME); - value.set("version"sv, BROWSER_VERSION); + value.set("apptype"sv, browser_name.to_lowercase_string()); + value.set("name"sv, browser_name); + value.set("brandName"sv, browser_name); + value.set("version"sv, browser_version); value.set("appbuildid"sv, build_id); value.set("platformbuildid"sv, build_id); value.set("platformversion"sv, "135.0"sv); value.set("useragent"sv, Web::default_user_agent); - value.set("os"sv, OS_STRING); - value.set("arch"sv, CPU_STRING); + value.set("os"sv, platform_name); + value.set("arch"sv, arch); JsonObject response; response.set("from"sv, name()); diff --git a/Libraries/LibDevTools/Actors/WalkerActor.cpp b/Libraries/LibDevTools/Actors/WalkerActor.cpp index 328440510e8..ae67321866c 100644 --- a/Libraries/LibDevTools/Actors/WalkerActor.cpp +++ b/Libraries/LibDevTools/Actors/WalkerActor.cpp @@ -193,7 +193,7 @@ JsonValue WalkerActor::serialize_node(JsonObject const& node) const serialized.set("causesOverflow"sv, false); serialized.set("containerType"sv, JsonValue {}); serialized.set("displayName"sv, name.to_lowercase()); - serialized.set("displayType"sv, "block"); + serialized.set("displayType"sv, "block"sv); serialized.set("host"sv, JsonValue {}); serialized.set("isAfterPseudoElement"sv, false); serialized.set("isAnonymous"sv, false); diff --git a/Libraries/LibGC/Heap.cpp b/Libraries/LibGC/Heap.cpp index 3c907b608cb..27aa0e4cd35 100644 --- a/Libraries/LibGC/Heap.cpp +++ b/Libraries/LibGC/Heap.cpp @@ -188,16 +188,16 @@ public: node.set("root"sv, ByteString::formatted("Root {} {}:{}", location->function_name(), location->filename(), location->line_number())); break; case HeapRoot::Type::RootVector: - node.set("root"sv, "RootVector"); + node.set("root"sv, "RootVector"sv); break; case HeapRoot::Type::RegisterPointer: - node.set("root"sv, "RegisterPointer"); + node.set("root"sv, "RegisterPointer"sv); break; case HeapRoot::Type::StackPointer: - node.set("root"sv, "StackPointer"); + node.set("root"sv, "StackPointer"sv); break; case HeapRoot::Type::VM: - node.set("root"sv, "VM"); + node.set("root"sv, "VM"sv); break; default: VERIFY_NOT_REACHED(); diff --git a/Libraries/LibWeb/WebDriver/Capabilities.cpp b/Libraries/LibWeb/WebDriver/Capabilities.cpp index 233d2461cac..2d655bf9d34 100644 --- a/Libraries/LibWeb/WebDriver/Capabilities.cpp +++ b/Libraries/LibWeb/WebDriver/Capabilities.cpp @@ -236,6 +236,7 @@ static bool matches_platform_name(StringView requested_platform_name, StringView 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(); // 1. Let matched capabilities be a JSON Object with the following entries: @@ -245,7 +246,7 @@ static JsonValue match_capabilities(JsonObject const& capabilities, SessionFlags matched_capabilities.set("browserName"sv, browser_name); // "browserVersion" // The user agent version, as a string. - matched_capabilities.set("browserVersion"sv, BROWSER_VERSION); + matched_capabilities.set("browserVersion"sv, browser_version); // "platformName" // ASCII Lowercase name of the current platform as a string. matched_capabilities.set("platformName"sv, platform_name); diff --git a/Libraries/LibWeb/WebDriver/Client.cpp b/Libraries/LibWeb/WebDriver/Client.cpp index 8405938142c..3117630c9c8 100644 --- a/Libraries/LibWeb/WebDriver/Client.cpp +++ b/Libraries/LibWeb/WebDriver/Client.cpp @@ -331,7 +331,7 @@ ErrorOr Client::send_error_response(HTTP::HttpReques JsonObject error_response; error_response.set("error", error.error); error_response.set("message", error.message); - error_response.set("stacktrace", ""); + error_response.set("stacktrace", ""sv); if (error.data.has_value()) error_response.set("data", *error.data); diff --git a/Tests/AK/TestJSON.cpp b/Tests/AK/TestJSON.cpp index 438f9901672..82f7c3b7b23 100644 --- a/Tests/AK/TestJSON.cpp +++ b/Tests/AK/TestJSON.cpp @@ -158,9 +158,9 @@ TEST_CASE(json_64_bit_value_coerced_to_32_bit) TEST_CASE(json_duplicate_keys) { JsonObject json; - json.set("test", "foo"); - json.set("test", "bar"); - json.set("test", "baz"); + json.set("test", "foo"sv); + json.set("test", "bar"sv); + json.set("test", "baz"sv); EXPECT_EQ(json.to_byte_string(), "{\"test\":\"baz\"}"); } diff --git a/Tests/LibJS/test262-runner.cpp b/Tests/LibJS/test262-runner.cpp index a83a565dc49..c1d8de98a01 100644 --- a/Tests/LibJS/test262-runner.cpp +++ b/Tests/LibJS/test262-runner.cpp @@ -403,14 +403,14 @@ static bool verify_test(ErrorOr& result, TestMetadata const& me if (result.error().phase == NegativePhase::Harness) { output.set("harness_error", true); output.set("harness_file", result.error().harness_file); - output.set("result", "harness_error"); + output.set("result", "harness_error"sv); } else if (result.error().phase == NegativePhase::Runtime) { auto& error_type = result.error().type; auto& error_details = result.error().details; if ((error_type == "InternalError"sv && error_details.starts_with("TODO("sv)) || (error_type == "Test262Error"sv && error_details.ends_with(" but got a InternalError"sv))) { output.set("todo_error", true); - output.set("result", "todo_error"); + output.set("result", "todo_error"sv); } } } @@ -420,20 +420,20 @@ static bool verify_test(ErrorOr& result, TestMetadata const& me VERIFY(output_messages.has_value()); if (output_messages->contains("AsyncTestFailure:InternalError: TODO("sv)) { output.set("todo_error", true); - output.set("result", "todo_error"); + output.set("result", "todo_error"sv); } } auto phase_to_string = [](NegativePhase phase) { switch (phase) { case NegativePhase::ParseOrEarly: - return "parse"; + return "parse"sv; case NegativePhase::Resolution: - return "resolution"; + return "resolution"sv; case NegativePhase::Runtime: - return "runtime"; + return "runtime"sv; case NegativePhase::Harness: - return "harness"; + return "harness"sv; } VERIFY_NOT_REACHED(); }; @@ -530,8 +530,8 @@ static bool g_in_assert = false; JsonObject assert_fail_result; assert_fail_result.set("test", s_current_test); assert_fail_result.set("assert_fail", true); - assert_fail_result.set("result", "assert_fail"); - assert_fail_result.set("output", assert_failed_message); + assert_fail_result.set("result", "assert_fail"sv); + assert_fail_result.set("output", StringView { assert_failed_message, strlen(assert_failed_message) }); outln(saved_stdout_fd, "RESULT {}{}", assert_fail_result.to_byte_string(), '\0'); // (Attempt to) Ensure that messages are written before quitting. fflush(saved_stdout_fd); @@ -739,7 +739,7 @@ int main(int argc, char** argv) auto metadata_or_error = extract_metadata(original_contents); if (metadata_or_error.is_error()) { - result_object.set("result", "metadata_error"); + result_object.set("result", "metadata_error"sv); result_object.set("metadata_error", true); result_object.set("metadata_output", metadata_or_error.error()); continue; @@ -747,7 +747,7 @@ int main(int argc, char** argv) auto& metadata = metadata_or_error.value(); if (metadata.skip_test == SkipTest::Yes) { - result_object.set("result", "skipped"); + result_object.set("result", "skipped"sv); continue; }