Skip to content

Commit c49819c

Browse files
DanShadersADKaster
authored andcommitted
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.
1 parent faef802 commit c49819c

File tree

5 files changed

+6
-21
lines changed

5 files changed

+6
-21
lines changed

AK/JsonObject.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,6 @@ bool JsonObject::has_object(StringView key) const
241241
return value.has_value() && value->is_object();
242242
}
243243

244-
#ifndef KERNEL
245-
bool JsonObject::has_double(StringView key) const
246-
{
247-
auto value = get(key);
248-
return value.has_value() && value->is_double();
249-
}
250-
#endif
251-
252244
void JsonObject::set(ByteString const& key, JsonValue value)
253245
{
254246
m_members.set(key, move(value));

AK/JsonObject.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ class JsonObject {
5151
[[nodiscard]] bool has_number(StringView key) const;
5252
[[nodiscard]] bool has_array(StringView key) const;
5353
[[nodiscard]] bool has_object(StringView key) const;
54-
#ifndef KERNEL
55-
[[nodiscard]] bool has_double(StringView key) const;
56-
#endif
5754

5855
Optional<JsonValue const&> get(StringView key) const;
5956

AK/JsonValue.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,6 @@ class JsonValue {
182182
bool is_null() const { return m_type == Type::Null; }
183183
bool is_bool() const { return m_type == Type::Bool; }
184184
bool is_string() const { return m_type == Type::String; }
185-
bool is_i32() const { return m_type == Type::Int32; }
186-
bool is_u32() const { return m_type == Type::UnsignedInt32; }
187-
bool is_i64() const { return m_type == Type::Int64; }
188-
bool is_u64() const { return m_type == Type::UnsignedInt64; }
189-
bool is_double() const { return m_type == Type::Double; }
190185
bool is_array() const { return m_type == Type::Array; }
191186
bool is_object() const { return m_type == Type::Object; }
192187
bool is_number() const
@@ -206,7 +201,7 @@ class JsonValue {
206201
template<typename T>
207202
T to_number(T default_value = 0) const
208203
{
209-
if (is_double())
204+
if (type() == Type::Double)
210205
return (T)m_value.as_double;
211206
if (type() == Type::Int32)
212207
return (T)m_value.as_i32;

Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ static ErrorOr<String> generate_initializer_for(Optional<StringView> property_na
235235
HANDLE_TYPE(i64, is_integer<i64>)
236236
HANDLE_TYPE(u64, is_integer<u64>)
237237
HANDLE_TYPE(bool, is_bool)
238-
HANDLE_TYPE(double, is_double)
238+
// FIXME: Do we want to allow precision loss when C++ compiler parses these doubles?
239+
HANDLE_TYPE(double, is_number)
239240
return Error::from_string_view("Inconsistent contained type in JSON array"sv);
240241
#undef HANDLE_TYPE
241242
}

Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,11 @@ size_t property_maximum_value_count(PropertyID property_id)
764764
properties.for_each_member([&](auto& name, auto& value) {
765765
VERIFY(value.is_object());
766766
if (value.as_object().has("max-values"sv)) {
767-
auto max_values = value.as_object().get("max-values"sv);
768-
VERIFY(max_values.has_value() && max_values->is_number() && !max_values->is_double());
767+
JsonValue max_values = value.as_object().get("max-values"sv).release_value();
768+
VERIFY(max_values.is_integer<size_t>());
769769
auto property_generator = generator.fork();
770770
property_generator.set("name:titlecase", title_casify(name));
771-
property_generator.set("max_values", max_values->template serialized<StringBuilder>());
771+
property_generator.set("max_values", MUST(String::formatted("{}", max_values.as_integer<size_t>())));
772772
property_generator.append(R"~~~(
773773
case PropertyID::@name:titlecase@:
774774
return @max_values@;

0 commit comments

Comments
 (0)