diff --git a/AK/JsonObject.h b/AK/JsonObject.h index ff09afb464..31721abc6a 100644 --- a/AK/JsonObject.h +++ b/AK/JsonObject.h @@ -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); diff --git a/AK/JsonValue.h b/AK/JsonValue.h index 9cdfc16b4a..efb7a35a32 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -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; } diff --git a/Tests/AK/TestJSON.cpp b/Tests/AK/TestJSON.cpp index 8455615c5c..26097e4613 100644 --- a/Tests/AK/TestJSON.cpp +++ b/Tests/AK/TestJSON.cpp @@ -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()); + EXPECT_EQ(big_json_value.as_integer(), 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(); 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(), big_value); } TEST_CASE(json_parse_empty_string) diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index a2170a74ac..116112f47c 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -247,9 +247,9 @@ static ErrorOr 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) { - if (!property->is_u32()) + if (!property->is_integer()) 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) { if (!property->is_array()) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, ByteString::formatted("Property '{}' is not an Array", key));