mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
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.
This commit is contained in:
parent
faef802229
commit
c49819cced
5 changed files with 6 additions and 21 deletions
|
@ -241,14 +241,6 @@ bool JsonObject::has_object(StringView key) const
|
||||||
return value.has_value() && value->is_object();
|
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)
|
void JsonObject::set(ByteString const& key, JsonValue value)
|
||||||
{
|
{
|
||||||
m_members.set(key, move(value));
|
m_members.set(key, move(value));
|
||||||
|
|
|
@ -51,9 +51,6 @@ public:
|
||||||
[[nodiscard]] bool has_number(StringView key) const;
|
[[nodiscard]] bool has_number(StringView key) const;
|
||||||
[[nodiscard]] bool has_array(StringView key) const;
|
[[nodiscard]] bool has_array(StringView key) const;
|
||||||
[[nodiscard]] bool has_object(StringView key) const;
|
[[nodiscard]] bool has_object(StringView key) const;
|
||||||
#ifndef KERNEL
|
|
||||||
[[nodiscard]] bool has_double(StringView key) const;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Optional<JsonValue const&> get(StringView key) const;
|
Optional<JsonValue const&> get(StringView key) const;
|
||||||
|
|
||||||
|
|
|
@ -182,11 +182,6 @@ public:
|
||||||
bool is_null() const { return m_type == Type::Null; }
|
bool is_null() const { return m_type == Type::Null; }
|
||||||
bool is_bool() const { return m_type == Type::Bool; }
|
bool is_bool() const { return m_type == Type::Bool; }
|
||||||
bool is_string() const { return m_type == Type::String; }
|
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_array() const { return m_type == Type::Array; }
|
||||||
bool is_object() const { return m_type == Type::Object; }
|
bool is_object() const { return m_type == Type::Object; }
|
||||||
bool is_number() const
|
bool is_number() const
|
||||||
|
@ -206,7 +201,7 @@ public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T to_number(T default_value = 0) const
|
T to_number(T default_value = 0) const
|
||||||
{
|
{
|
||||||
if (is_double())
|
if (type() == Type::Double)
|
||||||
return (T)m_value.as_double;
|
return (T)m_value.as_double;
|
||||||
if (type() == Type::Int32)
|
if (type() == Type::Int32)
|
||||||
return (T)m_value.as_i32;
|
return (T)m_value.as_i32;
|
||||||
|
|
|
@ -235,7 +235,8 @@ static ErrorOr<String> generate_initializer_for(Optional<StringView> property_na
|
||||||
HANDLE_TYPE(i64, is_integer<i64>)
|
HANDLE_TYPE(i64, is_integer<i64>)
|
||||||
HANDLE_TYPE(u64, is_integer<u64>)
|
HANDLE_TYPE(u64, is_integer<u64>)
|
||||||
HANDLE_TYPE(bool, is_bool)
|
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);
|
return Error::from_string_view("Inconsistent contained type in JSON array"sv);
|
||||||
#undef HANDLE_TYPE
|
#undef HANDLE_TYPE
|
||||||
}
|
}
|
||||||
|
|
|
@ -764,11 +764,11 @@ size_t property_maximum_value_count(PropertyID property_id)
|
||||||
properties.for_each_member([&](auto& name, auto& value) {
|
properties.for_each_member([&](auto& name, auto& value) {
|
||||||
VERIFY(value.is_object());
|
VERIFY(value.is_object());
|
||||||
if (value.as_object().has("max-values"sv)) {
|
if (value.as_object().has("max-values"sv)) {
|
||||||
auto max_values = value.as_object().get("max-values"sv);
|
JsonValue max_values = value.as_object().get("max-values"sv).release_value();
|
||||||
VERIFY(max_values.has_value() && max_values->is_number() && !max_values->is_double());
|
VERIFY(max_values.is_integer<size_t>());
|
||||||
auto property_generator = generator.fork();
|
auto property_generator = generator.fork();
|
||||||
property_generator.set("name:titlecase", title_casify(name));
|
property_generator.set("name:titlecase", title_casify(name));
|
||||||
property_generator.set("max_values", max_values->template serialized<StringBuilder>());
|
property_generator.set("max_values", MUST(String::formatted("{}", max_values.as_integer<size_t>())));
|
||||||
property_generator.append(R"~~~(
|
property_generator.append(R"~~~(
|
||||||
case PropertyID::@name:titlecase@:
|
case PropertyID::@name:titlecase@:
|
||||||
return @max_values@;
|
return @max_values@;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue