| 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 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 "(() => {" | 940 "(() => {" |
| 941 " var x = [1, { get a() { x.length = 0; }}, 3, 4];" | 941 " var x = [1, { get a() { x.length = 0; }}, 3, 4];" |
| 942 " return x;" | 942 " return x;" |
| 943 "})()", | 943 "})()", |
| 944 [this](Local<Value> value) { | 944 [this](Local<Value> value) { |
| 945 ASSERT_TRUE(value->IsArray()); | 945 ASSERT_TRUE(value->IsArray()); |
| 946 ASSERT_EQ(4, Array::Cast(*value)->Length()); | 946 ASSERT_EQ(4, Array::Cast(*value)->Length()); |
| 947 EXPECT_TRUE(EvaluateScriptForResultBool("result[0] === 1")); | 947 EXPECT_TRUE(EvaluateScriptForResultBool("result[0] === 1")); |
| 948 EXPECT_TRUE(EvaluateScriptForResultBool("!result.hasOwnProperty(2)")); | 948 EXPECT_TRUE(EvaluateScriptForResultBool("!result.hasOwnProperty(2)")); |
| 949 }); | 949 }); |
| 950 // The same is true if the length is shortened, but there are still items |
| 951 // remaining. |
| 952 RoundTripTest( |
| 953 "(() => {" |
| 954 " var x = [1, { get a() { x.length = 3; }}, 3, 4];" |
| 955 " return x;" |
| 956 "})()", |
| 957 [this](Local<Value> value) { |
| 958 ASSERT_TRUE(value->IsArray()); |
| 959 ASSERT_EQ(4, Array::Cast(*value)->Length()); |
| 960 EXPECT_TRUE(EvaluateScriptForResultBool("result[2] === 3")); |
| 961 EXPECT_TRUE(EvaluateScriptForResultBool("!result.hasOwnProperty(3)")); |
| 962 }); |
| 950 // Same for sparse arrays. | 963 // Same for sparse arrays. |
| 951 RoundTripTest( | 964 RoundTripTest( |
| 952 "(() => {" | 965 "(() => {" |
| 953 " var x = [1, { get a() { x.length = 0; }}, 3, 4];" | 966 " var x = [1, { get a() { x.length = 0; }}, 3, 4];" |
| 954 " x.length = 1000;" | 967 " x.length = 1000;" |
| 955 " return x;" | 968 " return x;" |
| 956 "})()", | 969 "})()", |
| 957 [this](Local<Value> value) { | 970 [this](Local<Value> value) { |
| 958 ASSERT_TRUE(value->IsArray()); | 971 ASSERT_TRUE(value->IsArray()); |
| 959 ASSERT_EQ(1000, Array::Cast(*value)->Length()); | 972 ASSERT_EQ(1000, Array::Cast(*value)->Length()); |
| 960 EXPECT_TRUE(EvaluateScriptForResultBool("result[0] === 1")); | 973 EXPECT_TRUE(EvaluateScriptForResultBool("result[0] === 1")); |
| 961 EXPECT_TRUE(EvaluateScriptForResultBool("!result.hasOwnProperty(2)")); | 974 EXPECT_TRUE(EvaluateScriptForResultBool("!result.hasOwnProperty(2)")); |
| 962 }); | 975 }); |
| 976 RoundTripTest( |
| 977 "(() => {" |
| 978 " var x = [1, { get a() { x.length = 3; }}, 3, 4];" |
| 979 " x.length = 1000;" |
| 980 " return x;" |
| 981 "})()", |
| 982 [this](Local<Value> value) { |
| 983 ASSERT_TRUE(value->IsArray()); |
| 984 ASSERT_EQ(1000, Array::Cast(*value)->Length()); |
| 985 EXPECT_TRUE(EvaluateScriptForResultBool("result[2] === 3")); |
| 986 EXPECT_TRUE(EvaluateScriptForResultBool("!result.hasOwnProperty(3)")); |
| 987 }); |
| 963 // If a getter makes a property non-enumerable, it should still be enumerated | 988 // If a getter makes a property non-enumerable, it should still be enumerated |
| 964 // as enumeration happens once before getters are invoked. | 989 // as enumeration happens once before getters are invoked. |
| 965 RoundTripTest( | 990 RoundTripTest( |
| 966 "(() => {" | 991 "(() => {" |
| 967 " var x = [{ get a() {" | 992 " var x = [{ get a() {" |
| 968 " Object.defineProperty(x, '1', { value: 3, enumerable: false });" | 993 " Object.defineProperty(x, '1', { value: 3, enumerable: false });" |
| 969 " }}, 2];" | 994 " }}, 2];" |
| 970 " return x;" | 995 " return x;" |
| 971 "})()", | 996 "})()", |
| 972 [this](Local<Value> value) { | 997 [this](Local<Value> value) { |
| (...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1994 } | 2019 } |
| 1995 | 2020 |
| 1996 TEST_F(ValueSerializerTestWithSharedArrayBufferTransfer, | 2021 TEST_F(ValueSerializerTestWithSharedArrayBufferTransfer, |
| 1997 SharedArrayBufferMustBeTransferred) { | 2022 SharedArrayBufferMustBeTransferred) { |
| 1998 // A SharedArrayBuffer which was not marked for transfer should fail encoding. | 2023 // A SharedArrayBuffer which was not marked for transfer should fail encoding. |
| 1999 InvalidEncodeTest("new SharedArrayBuffer(32)"); | 2024 InvalidEncodeTest("new SharedArrayBuffer(32)"); |
| 2000 } | 2025 } |
| 2001 | 2026 |
| 2002 } // namespace | 2027 } // namespace |
| 2003 } // namespace v8 | 2028 } // namespace v8 |
| OLD | NEW |