From c49819cced304f19b11836c84b0012f16ca5aeee Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Tue, 14 Nov 2023 01:15:54 -0500 Subject: [PATCH] AK+GMLCompiler+LibWeb: Remove JsonValue::is_double This concludes a series of patches which remove the ability to observe which arithmetic type is used to store number in JsonValue. --- AK/JsonObject.cpp | 8 -------- AK/JsonObject.h | 3 --- AK/JsonValue.h | 7 +------ Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp | 3 ++- .../Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp | 6 +++--- 5 files changed, 6 insertions(+), 21 deletions(-) diff --git a/AK/JsonObject.cpp b/AK/JsonObject.cpp index 261b97dd0be..9df2543e9fd 100644 --- a/AK/JsonObject.cpp +++ b/AK/JsonObject.cpp @@ -241,14 +241,6 @@ bool JsonObject::has_object(StringView key) const return value.has_value() && value->is_object(); } -#ifndef KERNEL -bool JsonObject::has_double(StringView key) const -{ - auto value = get(key); - return value.has_value() && value->is_double(); -} -#endif - void JsonObject::set(ByteString const& key, JsonValue value) { m_members.set(key, move(value)); diff --git a/AK/JsonObject.h b/AK/JsonObject.h index 31721abc6a9..a985ab4dbf7 100644 --- a/AK/JsonObject.h +++ b/AK/JsonObject.h @@ -51,9 +51,6 @@ public: [[nodiscard]] bool has_number(StringView key) const; [[nodiscard]] bool has_array(StringView key) const; [[nodiscard]] bool has_object(StringView key) const; -#ifndef KERNEL - [[nodiscard]] bool has_double(StringView key) const; -#endif Optional get(StringView key) const; diff --git a/AK/JsonValue.h b/AK/JsonValue.h index b123e59beb7..fcddd67aef5 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -182,11 +182,6 @@ public: bool is_null() const { return m_type == Type::Null; } bool is_bool() const { return m_type == Type::Bool; } bool is_string() const { return m_type == Type::String; } - bool is_i32() const { return m_type == Type::Int32; } - bool is_u32() const { return m_type == Type::UnsignedInt32; } - bool is_i64() const { return m_type == Type::Int64; } - bool is_u64() const { return m_type == Type::UnsignedInt64; } - bool is_double() const { return m_type == Type::Double; } bool is_array() const { return m_type == Type::Array; } bool is_object() const { return m_type == Type::Object; } bool is_number() const @@ -206,7 +201,7 @@ public: template T to_number(T default_value = 0) const { - if (is_double()) + if (type() == Type::Double) return (T)m_value.as_double; if (type() == Type::Int32) return (T)m_value.as_i32; diff --git a/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp index 2c19ce3f673..c45b1a7e41a 100644 --- a/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp @@ -235,7 +235,8 @@ static ErrorOr generate_initializer_for(Optional property_na HANDLE_TYPE(i64, is_integer) HANDLE_TYPE(u64, is_integer) HANDLE_TYPE(bool, is_bool) - HANDLE_TYPE(double, is_double) + // FIXME: Do we want to allow precision loss when C++ compiler parses these doubles? + HANDLE_TYPE(double, is_number) return Error::from_string_view("Inconsistent contained type in JSON array"sv); #undef HANDLE_TYPE } diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp index f56e6345b00..775b35c52e7 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp @@ -764,11 +764,11 @@ size_t property_maximum_value_count(PropertyID property_id) properties.for_each_member([&](auto& name, auto& value) { VERIFY(value.is_object()); if (value.as_object().has("max-values"sv)) { - auto max_values = value.as_object().get("max-values"sv); - VERIFY(max_values.has_value() && max_values->is_number() && !max_values->is_double()); + JsonValue max_values = value.as_object().get("max-values"sv).release_value(); + VERIFY(max_values.is_integer()); auto property_generator = generator.fork(); property_generator.set("name:titlecase", title_casify(name)); - property_generator.set("max_values", max_values->template serialized()); + property_generator.set("max_values", MUST(String::formatted("{}", max_values.as_integer()))); property_generator.append(R"~~~( case PropertyID::@name:titlecase@: return @max_values@;