OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/factory.h" | 7 #include "src/factory.h" |
8 #include "src/handles-inl.h" | 8 #include "src/handles-inl.h" |
9 #include "src/interpreter/constant-array-builder.h" | 9 #include "src/interpreter/constant-array-builder.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 STATIC_CONST_MEMBER_DEFINITION const size_t | 27 STATIC_CONST_MEMBER_DEFINITION const size_t |
28 ConstantArrayBuilderTest::kMaxCapacity; | 28 ConstantArrayBuilderTest::kMaxCapacity; |
29 STATIC_CONST_MEMBER_DEFINITION const size_t | 29 STATIC_CONST_MEMBER_DEFINITION const size_t |
30 ConstantArrayBuilderTest::kLowCapacity; | 30 ConstantArrayBuilderTest::kLowCapacity; |
31 | 31 |
32 | 32 |
33 TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) { | 33 TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) { |
34 ConstantArrayBuilder builder(isolate(), zone()); | 34 ConstantArrayBuilder builder(isolate(), zone()); |
35 for (size_t i = 0; i < kMaxCapacity; i++) { | 35 for (size_t i = 0; i < kMaxCapacity; i++) { |
36 Handle<Object> object = isolate()->factory()->NewNumberFromSize(i); | 36 builder.Insert(handle(Smi::FromInt(static_cast<int>(i)), isolate())); |
37 builder.Insert(object); | |
38 CHECK_EQ(builder.size(), i + 1); | |
39 CHECK(builder.At(i)->SameValue(*object)); | |
40 } | 37 } |
| 38 CHECK_EQ(builder.size(), kMaxCapacity); |
41 for (size_t i = 0; i < kMaxCapacity; i++) { | 39 for (size_t i = 0; i < kMaxCapacity; i++) { |
42 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), static_cast<double>(i)); | 40 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), i); |
43 } | 41 } |
44 } | 42 } |
45 | 43 |
46 | 44 |
47 TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) { | 45 TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) { |
48 for (size_t reserved = 1; reserved < kLowCapacity; reserved *= 3) { | 46 for (size_t reserved = 1; reserved < kLowCapacity; reserved *= 3) { |
49 ConstantArrayBuilder builder(isolate(), zone()); | 47 ConstantArrayBuilder builder(isolate(), zone()); |
50 for (size_t i = 0; i < reserved; i++) { | 48 for (size_t i = 0; i < reserved; i++) { |
51 OperandSize operand_size = builder.CreateReservedEntry(); | 49 OperandSize operand_size = builder.CreateReservedEntry(); |
52 CHECK(operand_size == OperandSize::kByte); | 50 CHECK(operand_size == OperandSize::kByte); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 Handle<Object> original = builder.At(kLowCapacity + i); | 213 Handle<Object> original = builder.At(kLowCapacity + i); |
216 CHECK(original->SameValue(*reference)); | 214 CHECK(original->SameValue(*reference)); |
217 Handle<Object> duplicate = builder.At(i); | 215 Handle<Object> duplicate = builder.At(i); |
218 CHECK(duplicate->SameValue(*isolate()->factory()->the_hole_value())); | 216 CHECK(duplicate->SameValue(*isolate()->factory()->the_hole_value())); |
219 } | 217 } |
220 } | 218 } |
221 | 219 |
222 } // namespace interpreter | 220 } // namespace interpreter |
223 } // namespace internal | 221 } // namespace internal |
224 } // namespace v8 | 222 } // namespace v8 |
OLD | NEW |