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 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 " x.length = 1000;" | 1032 " x.length = 1000;" |
1033 " return x;" | 1033 " return x;" |
1034 "})()", | 1034 "})()", |
1035 [this](Local<Value> value) { | 1035 [this](Local<Value> value) { |
1036 ASSERT_TRUE(value->IsArray()); | 1036 ASSERT_TRUE(value->IsArray()); |
1037 ASSERT_EQ(1000, Array::Cast(*value)->Length()); | 1037 ASSERT_EQ(1000, Array::Cast(*value)->Length()); |
1038 EXPECT_TRUE(EvaluateScriptForResultBool("!(1 in result)")); | 1038 EXPECT_TRUE(EvaluateScriptForResultBool("!(1 in result)")); |
1039 }); | 1039 }); |
1040 } | 1040 } |
1041 | 1041 |
| 1042 TEST_F(ValueSerializerTest, DecodeSparseArrayVersion0) { |
| 1043 // Empty (sparse) array. |
| 1044 DecodeTestForVersion0({0x40, 0x00, 0x00, 0x00}, |
| 1045 [this](Local<Value> value) { |
| 1046 ASSERT_TRUE(value->IsArray()); |
| 1047 ASSERT_EQ(0, Array::Cast(*value)->Length()); |
| 1048 }); |
| 1049 // Sparse array with a mixture of elements and properties. |
| 1050 DecodeTestForVersion0( |
| 1051 {0x55, 0x00, 0x53, 0x01, 'a', 0x55, 0x02, 0x55, 0x05, 0x53, |
| 1052 0x03, 'f', 'o', 'o', 0x53, 0x03, 'b', 'a', 'r', 0x53, |
| 1053 0x03, 'b', 'a', 'z', 0x49, 0x0b, 0x40, 0x04, 0x03, 0x00}, |
| 1054 [this](Local<Value> value) { |
| 1055 ASSERT_TRUE(value->IsArray()); |
| 1056 EXPECT_EQ(3, Array::Cast(*value)->Length()); |
| 1057 EXPECT_TRUE( |
| 1058 EvaluateScriptForResultBool("result.toString() === 'a,,5'")); |
| 1059 EXPECT_TRUE(EvaluateScriptForResultBool("!(1 in result)")); |
| 1060 EXPECT_TRUE(EvaluateScriptForResultBool("result.foo === 'bar'")); |
| 1061 EXPECT_TRUE(EvaluateScriptForResultBool("result.baz === -6")); |
| 1062 }); |
| 1063 // Sparse array in a sparse array (sanity check of nesting). |
| 1064 DecodeTestForVersion0( |
| 1065 {0x55, 0x01, 0x55, 0x01, 0x54, 0x40, 0x01, 0x02, 0x40, 0x01, 0x02, 0x00}, |
| 1066 [this](Local<Value> value) { |
| 1067 ASSERT_TRUE(value->IsArray()); |
| 1068 EXPECT_EQ(2, Array::Cast(*value)->Length()); |
| 1069 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result)")); |
| 1070 EXPECT_TRUE(EvaluateScriptForResultBool("result[1] instanceof Array")); |
| 1071 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result[1])")); |
| 1072 EXPECT_TRUE(EvaluateScriptForResultBool("result[1][1] === true")); |
| 1073 }); |
| 1074 } |
| 1075 |
1042 } // namespace | 1076 } // namespace |
1043 } // namespace v8 | 1077 } // namespace v8 |
OLD | NEW |