Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Unified Diff: test/unittests/value-serializer-unittest.cc

Issue 2660093002: ValueSerializer: Distinguish between 'undefined' and an absent property. (Closed)
Patch Set: remove TODO Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/value-serializer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/value-serializer-unittest.cc
diff --git a/test/unittests/value-serializer-unittest.cc b/test/unittests/value-serializer-unittest.cc
index db663fafd83f4882b0eaf8eec4bcd07245400ea1..ec2df077f57021ad0e12d6f4c7c68519bbcc12dd 100644
--- a/test/unittests/value-serializer-unittest.cc
+++ b/test/unittests/value-serializer-unittest.cc
@@ -1245,6 +1245,36 @@ TEST_F(ValueSerializerTest, DecodeSparseArrayVersion0) {
});
}
+TEST_F(ValueSerializerTest, RoundTripDenseArrayContainingUndefined) {
+ // In previous serialization versions, this would be interpreted as an absent
+ // property.
+ RoundTripTest("[undefined]", [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsArray());
+ EXPECT_EQ(1u, Array::Cast(*value)->Length());
+ EXPECT_TRUE(EvaluateScriptForResultBool("result.hasOwnProperty(0)"));
+ EXPECT_TRUE(EvaluateScriptForResultBool("result[0] === undefined"));
+ });
+}
+
+TEST_F(ValueSerializerTest, DecodeDenseArrayContainingUndefined) {
+ // In previous versions, "undefined" in a dense array signified absence of the
+ // element (for compatibility). In new versions, it has a separate encoding.
+ DecodeTest({0xff, 0x09, 0x41, 0x01, 0x5f, 0x24, 0x00, 0x01},
+ [this](Local<Value> value) {
+ EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result)"));
+ });
+ DecodeTest(
+ {0xff, 0x0b, 0x41, 0x01, 0x5f, 0x24, 0x00, 0x01},
+ [this](Local<Value> value) {
+ EXPECT_TRUE(EvaluateScriptForResultBool("0 in result"));
+ EXPECT_TRUE(EvaluateScriptForResultBool("result[0] === undefined"));
+ });
+ DecodeTest({0xff, 0x0b, 0x41, 0x01, 0x2d, 0x24, 0x00, 0x01},
+ [this](Local<Value> value) {
+ EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result)"));
+ });
+}
+
TEST_F(ValueSerializerTest, RoundTripDate) {
RoundTripTest("new Date(1e6)", [](Local<Value> value) {
ASSERT_TRUE(value->IsDate());
« no previous file with comments | « src/value-serializer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698