mirror of
https://github.com/SerenityOS/serenity
synced 2024-11-05 17:46:52 +00:00
AK+WebContent: Remove JsonValue::as_{i,u}{32,64}()
This commit is contained in:
parent
0388c828be
commit
5230d2af91
4 changed files with 16 additions and 37 deletions
|
@ -162,16 +162,16 @@ inline void JsonValue::serialize(Builder& builder) const
|
|||
break;
|
||||
#endif
|
||||
case Type::Int32:
|
||||
builder.appendff("{}", as_i32());
|
||||
builder.appendff("{}", m_value.as_i32);
|
||||
break;
|
||||
case Type::Int64:
|
||||
builder.appendff("{}", as_i64());
|
||||
builder.appendff("{}", m_value.as_i64);
|
||||
break;
|
||||
case Type::UnsignedInt32:
|
||||
builder.appendff("{}", as_u32());
|
||||
builder.appendff("{}", m_value.as_u32);
|
||||
break;
|
||||
case Type::UnsignedInt64:
|
||||
builder.appendff("{}", as_u64());
|
||||
builder.appendff("{}", m_value.as_u64);
|
||||
break;
|
||||
case Type::Null:
|
||||
builder.append("null"sv);
|
||||
|
|
|
@ -118,30 +118,6 @@ public:
|
|||
return as_bool();
|
||||
}
|
||||
|
||||
i32 as_i32() const
|
||||
{
|
||||
VERIFY(is_i32());
|
||||
return m_value.as_i32;
|
||||
}
|
||||
|
||||
u32 as_u32() const
|
||||
{
|
||||
VERIFY(is_u32());
|
||||
return m_value.as_u32;
|
||||
}
|
||||
|
||||
i64 as_i64() const
|
||||
{
|
||||
VERIFY(is_i64());
|
||||
return m_value.as_i64;
|
||||
}
|
||||
|
||||
u64 as_u64() const
|
||||
{
|
||||
VERIFY(is_u64());
|
||||
return m_value.as_u64;
|
||||
}
|
||||
|
||||
bool as_bool() const
|
||||
{
|
||||
VERIFY(is_bool());
|
||||
|
@ -217,15 +193,15 @@ public:
|
|||
T to_number(T default_value = 0) const
|
||||
{
|
||||
if (is_double())
|
||||
return (T)as_double();
|
||||
return (T)m_value.as_double;
|
||||
if (type() == Type::Int32)
|
||||
return (T)as_i32();
|
||||
return (T)m_value.as_i32;
|
||||
if (type() == Type::UnsignedInt32)
|
||||
return (T)as_u32();
|
||||
return (T)m_value.as_u32;
|
||||
if (type() == Type::Int64)
|
||||
return (T)as_i64();
|
||||
return (T)m_value.as_i64;
|
||||
if (type() == Type::UnsignedInt64)
|
||||
return (T)as_u64();
|
||||
return (T)m_value.as_u64;
|
||||
return default_value;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,8 +99,11 @@ TEST_CASE(json_64_bit_value)
|
|||
{
|
||||
auto big_value = 0x12345678aabbccddull;
|
||||
JsonValue big_json_value(big_value);
|
||||
EXPECT(big_json_value.is_integer<u64>());
|
||||
EXPECT_EQ(big_json_value.as_integer<u64>(), big_value);
|
||||
|
||||
JsonValue big_json_value_copy = big_json_value;
|
||||
EXPECT_EQ(big_json_value.as_u64(), big_json_value_copy.as_u64());
|
||||
EXPECT(big_json_value.equals(big_json_value_copy));
|
||||
}
|
||||
|
||||
TEST_CASE(json_duplicate_keys)
|
||||
|
@ -118,7 +121,7 @@ TEST_CASE(json_u64_roundtrip)
|
|||
auto json = JsonValue(big_value).serialized<StringBuilder>();
|
||||
auto value = JsonValue::from_string(json);
|
||||
EXPECT_EQ_FORCE(value.is_error(), false);
|
||||
EXPECT_EQ(value.value().as_u64(), big_value);
|
||||
EXPECT_EQ(value.value().as_integer<u64>(), big_value);
|
||||
}
|
||||
|
||||
TEST_CASE(json_parse_empty_string)
|
||||
|
|
|
@ -247,9 +247,9 @@ static ErrorOr<PropertyType, Web::WebDriver::Error> get_property(JsonValue const
|
|||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, ByteString::formatted("Property '{}' is not a Boolean", key));
|
||||
return property->as_bool();
|
||||
} else if constexpr (IsSame<PropertyType, u32>) {
|
||||
if (!property->is_u32())
|
||||
if (!property->is_integer<u32>())
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, ByteString::formatted("Property '{}' is not a Number", key));
|
||||
return property->as_u32();
|
||||
return property->to_u32();
|
||||
} else if constexpr (IsSame<PropertyType, JsonArray const*>) {
|
||||
if (!property->is_array())
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, ByteString::formatted("Property '{}' is not an Array", key));
|
||||
|
|
Loading…
Reference in a new issue