| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/value-serializer.h" | 5 #include "src/value-serializer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "include/v8.h" | 10 #include "include/v8.h" |
| (...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 [this](Local<Value> value) { | 1238 [this](Local<Value> value) { |
| 1239 ASSERT_TRUE(value->IsArray()); | 1239 ASSERT_TRUE(value->IsArray()); |
| 1240 EXPECT_EQ(2u, Array::Cast(*value)->Length()); | 1240 EXPECT_EQ(2u, Array::Cast(*value)->Length()); |
| 1241 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result)")); | 1241 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result)")); |
| 1242 EXPECT_TRUE(EvaluateScriptForResultBool("result[1] instanceof Array")); | 1242 EXPECT_TRUE(EvaluateScriptForResultBool("result[1] instanceof Array")); |
| 1243 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result[1])")); | 1243 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result[1])")); |
| 1244 EXPECT_TRUE(EvaluateScriptForResultBool("result[1][1] === true")); | 1244 EXPECT_TRUE(EvaluateScriptForResultBool("result[1][1] === true")); |
| 1245 }); | 1245 }); |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 TEST_F(ValueSerializerTest, RoundTripDenseArrayContainingUndefined) { |
| 1249 // In previous serialization versions, this would be interpreted as an absent |
| 1250 // property. |
| 1251 RoundTripTest("[undefined]", [this](Local<Value> value) { |
| 1252 ASSERT_TRUE(value->IsArray()); |
| 1253 EXPECT_EQ(1u, Array::Cast(*value)->Length()); |
| 1254 EXPECT_TRUE(EvaluateScriptForResultBool("result.hasOwnProperty(0)")); |
| 1255 EXPECT_TRUE(EvaluateScriptForResultBool("result[0] === undefined")); |
| 1256 }); |
| 1257 } |
| 1258 |
| 1259 TEST_F(ValueSerializerTest, DecodeDenseArrayContainingUndefined) { |
| 1260 // In previous versions, "undefined" in a dense array signified absence of the |
| 1261 // element (for compatibility). In new versions, it has a separate encoding. |
| 1262 DecodeTest({0xff, 0x09, 0x41, 0x01, 0x5f, 0x24, 0x00, 0x01}, |
| 1263 [this](Local<Value> value) { |
| 1264 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result)")); |
| 1265 }); |
| 1266 DecodeTest( |
| 1267 {0xff, 0x0b, 0x41, 0x01, 0x5f, 0x24, 0x00, 0x01}, |
| 1268 [this](Local<Value> value) { |
| 1269 EXPECT_TRUE(EvaluateScriptForResultBool("0 in result")); |
| 1270 EXPECT_TRUE(EvaluateScriptForResultBool("result[0] === undefined")); |
| 1271 }); |
| 1272 DecodeTest({0xff, 0x0b, 0x41, 0x01, 0x2d, 0x24, 0x00, 0x01}, |
| 1273 [this](Local<Value> value) { |
| 1274 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result)")); |
| 1275 }); |
| 1276 } |
| 1277 |
| 1248 TEST_F(ValueSerializerTest, RoundTripDate) { | 1278 TEST_F(ValueSerializerTest, RoundTripDate) { |
| 1249 RoundTripTest("new Date(1e6)", [](Local<Value> value) { | 1279 RoundTripTest("new Date(1e6)", [](Local<Value> value) { |
| 1250 ASSERT_TRUE(value->IsDate()); | 1280 ASSERT_TRUE(value->IsDate()); |
| 1251 EXPECT_EQ(1e6, Date::Cast(*value)->ValueOf()); | 1281 EXPECT_EQ(1e6, Date::Cast(*value)->ValueOf()); |
| 1252 EXPECT_TRUE("Object.getPrototypeOf(result) === Date.prototype"); | 1282 EXPECT_TRUE("Object.getPrototypeOf(result) === Date.prototype"); |
| 1253 }); | 1283 }); |
| 1254 RoundTripTest("new Date(Date.UTC(1867, 6, 1))", [](Local<Value> value) { | 1284 RoundTripTest("new Date(Date.UTC(1867, 6, 1))", [](Local<Value> value) { |
| 1255 ASSERT_TRUE(value->IsDate()); | 1285 ASSERT_TRUE(value->IsDate()); |
| 1256 EXPECT_TRUE("result.toISOString() === '1867-07-01T00:00:00.000Z'"); | 1286 EXPECT_TRUE("result.toISOString() === '1867-07-01T00:00:00.000Z'"); |
| 1257 }); | 1287 }); |
| (...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2634 InvalidDecodeTest(raw); | 2664 InvalidDecodeTest(raw); |
| 2635 } | 2665 } |
| 2636 | 2666 |
| 2637 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { | 2667 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { |
| 2638 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); | 2668 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); |
| 2639 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); | 2669 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); |
| 2640 } | 2670 } |
| 2641 | 2671 |
| 2642 } // namespace | 2672 } // namespace |
| 2643 } // namespace v8 | 2673 } // namespace v8 |
| OLD | NEW |