AK+Everywhere: Remove the char const* JSON value constructor

This commit is contained in:
Timothy Flynn 2025-02-17 11:59:45 -05:00 committed by Tim Flynn
commit 70eb0ba1cd
Notes: github-actions[bot] 2025-02-21 00:29:35 +00:00
10 changed files with 35 additions and 35 deletions

View file

@ -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 })
{

View file

@ -55,7 +55,6 @@ public:
JsonValue(long long unsigned);
JsonValue(double);
JsonValue(char const*);
JsonValue(ByteString const&);
JsonValue(StringView);

View file

@ -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());
};

View file

@ -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());

View file

@ -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);

View file

@ -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();

View file

@ -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);

View file

@ -331,7 +331,7 @@ ErrorOr<void, Client::WrappedError> 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);

View file

@ -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\"}");
}

View file

@ -403,14 +403,14 @@ static bool verify_test(ErrorOr<void, TestError>& 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<void, TestError>& 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;
}