From ecd4c6718ee4d1dd7f7ded22c3717a6fabec406d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 6 Jul 2020 17:17:46 +0200 Subject: [PATCH] AK: Fix JsonValue copy constructor behavior for 64-bit values The fact that JsonValues can contain 64-bit values isn't a JavaScript compatible behavior in the first place, but as long as we're supporting this, we should make sure it works correctly. --- AK/JsonValue.cpp | 6 +++--- AK/Tests/TestJSON.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/AK/JsonValue.cpp b/AK/JsonValue.cpp index 8a1bc99f04..e9007bf870 100644 --- a/AK/JsonValue.cpp +++ b/AK/JsonValue.cpp @@ -68,7 +68,7 @@ void JsonValue::copy_from(const JsonValue& other) m_value.as_array = new JsonArray(*other.m_value.as_array); break; default: - m_value.as_string = other.m_value.as_string; + m_value.as_u64 = other.m_value.as_u64; break; } } @@ -76,7 +76,7 @@ void JsonValue::copy_from(const JsonValue& other) JsonValue::JsonValue(JsonValue&& other) { m_type = exchange(other.m_type, Type::Null); - m_value.as_string = exchange(other.m_value.as_string, nullptr); + m_value.as_u64 = exchange(other.m_value.as_u64, 0); } JsonValue& JsonValue::operator=(JsonValue&& other) @@ -84,7 +84,7 @@ JsonValue& JsonValue::operator=(JsonValue&& other) if (this != &other) { clear(); m_type = exchange(other.m_type, Type::Null); - m_value.as_string = exchange(other.m_value.as_string, nullptr); + m_value.as_u64 = exchange(other.m_value.as_u64, 0); } return *this; } diff --git a/AK/Tests/TestJSON.cpp b/AK/Tests/TestJSON.cpp index 31dc2c508f..ba196e4cdb 100644 --- a/AK/Tests/TestJSON.cpp +++ b/AK/Tests/TestJSON.cpp @@ -128,4 +128,12 @@ TEST_CASE(json_utf8_multibyte) EXPECT_EQ(json.as_string() == "\xc5\xa1", true); } +TEST_CASE(json_64_bit_value) +{ + auto big_value = 0x12345678aabbccddull; + JsonValue big_json_value(big_value); + JsonValue big_json_value_copy = big_json_value; + EXPECT_EQ(big_json_value.as_u64(), big_json_value_copy.as_u64()); +} + TEST_MAIN(JSON)