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