mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
AK+LibJS: Remove error-prone JsonValue constructor
Consider the following: JsonValue value { JsonValue::Type::Object }; value.as_object().set("foo"sv, "bar"sv); The JsonValue(Type) constructor does not initialize the underlying union that stores its value. Thus JsonValue::as_object() will A) refer to an uninitialized union member, B) deference that member. This constructor only has 2 users, both of which initialize the type to Type::Null. Rather than implementing unused functionality here, replace those uses with the default JsonValue constructor, and remove the faulty constructor.
This commit is contained in:
parent
53d73b95ce
commit
f630a5ca71
Notes:
sideshowbarker
2024-07-17 02:22:23 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/f630a5ca71 Pull-request: https://github.com/SerenityOS/serenity/pull/21720
4 changed files with 3 additions and 9 deletions
|
@ -304,7 +304,7 @@ ErrorOr<JsonValue> JsonParser::parse_null()
|
|||
{
|
||||
if (!consume_specific("null"))
|
||||
return Error::from_string_literal("JsonParser: Expected 'null'");
|
||||
return JsonValue(JsonValue::Type::Null);
|
||||
return JsonValue {};
|
||||
}
|
||||
|
||||
ErrorOr<JsonValue> JsonParser::parse_helper()
|
||||
|
|
|
@ -15,11 +15,6 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
JsonValue::JsonValue(Type type)
|
||||
: m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
JsonValue::JsonValue(JsonValue const& other)
|
||||
{
|
||||
copy_from(other);
|
||||
|
|
|
@ -36,7 +36,6 @@ public:
|
|||
static ErrorOr<JsonValue> from_string(StringView);
|
||||
|
||||
JsonValue() = default;
|
||||
explicit JsonValue(Type);
|
||||
~JsonValue() { clear(); }
|
||||
|
||||
JsonValue(JsonValue const&);
|
||||
|
|
|
@ -753,7 +753,7 @@ int main(int argc, char** argv)
|
|||
if (!output.contains("Test262:AsyncTestComplete"sv) || output.contains("Test262:AsyncTestFailure"sv)) {
|
||||
result_object.set("async_fail", true);
|
||||
if (!first_output.has_value())
|
||||
result_object.set("output", JsonValue { AK::JsonValue::Type::Null });
|
||||
result_object.set("output", JsonValue {});
|
||||
|
||||
passed = false;
|
||||
}
|
||||
|
@ -778,7 +778,7 @@ int main(int argc, char** argv)
|
|||
if (!output.contains("Test262:AsyncTestComplete"sv) || output.contains("Test262:AsyncTestFailure"sv)) {
|
||||
result_object.set("async_fail", true);
|
||||
if (!first_output.has_value())
|
||||
result_object.set("output", JsonValue { AK::JsonValue::Type::Null });
|
||||
result_object.set("output", JsonValue {});
|
||||
|
||||
passed = false;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue