Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #include <stdlib.h>
6 :
7 : #include "src/heap/factory.h"
8 : #include "src/objects-inl.h"
9 : #include "test/cctest/cctest.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 :
14 26644 : TEST(ArrayList) {
15 5 : LocalContext context;
16 : Isolate* isolate = CcTest::i_isolate();
17 : HandleScope scope(isolate);
18 : Handle<ArrayList> array(
19 : ArrayList::cast(ReadOnlyRoots(isolate).empty_fixed_array()), isolate);
20 5 : CHECK_EQ(0, array->Length());
21 5 : array = ArrayList::Add(isolate, array, handle(Smi::FromInt(100), isolate));
22 5 : CHECK_EQ(1, array->Length());
23 5 : CHECK_EQ(100, Smi::ToInt(array->Get(0)));
24 : array = ArrayList::Add(isolate, array, handle(Smi::FromInt(200), isolate),
25 5 : handle(Smi::FromInt(300), isolate));
26 5 : CHECK_EQ(3, array->Length());
27 5 : CHECK_EQ(100, Smi::ToInt(array->Get(0)));
28 5 : CHECK_EQ(200, Smi::ToInt(array->Get(1)));
29 5 : CHECK_EQ(300, Smi::ToInt(array->Get(2)));
30 : array->Set(2, Smi::FromInt(400));
31 5 : CHECK_EQ(400, Smi::ToInt(array->Get(2)));
32 : array->Clear(2, ReadOnlyRoots(isolate).undefined_value());
33 : array->SetLength(2);
34 5 : CHECK_EQ(2, array->Length());
35 5 : CHECK_EQ(100, Smi::ToInt(array->Get(0)));
36 5 : CHECK_EQ(200, Smi::ToInt(array->Get(1)));
37 5 : }
38 :
39 : } // namespace internal
40 79917 : } // namespace v8
|