2015-03-06 12:36:16 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2018-04-09 19:11:22 +00:00
|
|
|
#include "src/heap/factory.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2015-03-06 12:36:16 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
2017-08-31 12:34:55 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2015-03-06 12:36:16 +00:00
|
|
|
|
|
|
|
TEST(ArrayList) {
|
|
|
|
LocalContext context;
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope scope(isolate);
|
2018-07-04 09:10:05 +00:00
|
|
|
Handle<ArrayList> array(
|
|
|
|
ArrayList::cast(ReadOnlyRoots(isolate).empty_fixed_array()), isolate);
|
2015-03-06 12:36:16 +00:00
|
|
|
CHECK_EQ(0, array->Length());
|
2018-07-13 09:32:35 +00:00
|
|
|
array = ArrayList::Add(isolate, array, handle(Smi::FromInt(100), isolate));
|
2015-03-06 12:36:16 +00:00
|
|
|
CHECK_EQ(1, array->Length());
|
2017-07-10 12:58:27 +00:00
|
|
|
CHECK_EQ(100, Smi::ToInt(array->Get(0)));
|
2018-07-13 09:32:35 +00:00
|
|
|
array = ArrayList::Add(isolate, array, handle(Smi::FromInt(200), isolate),
|
2015-03-06 12:36:16 +00:00
|
|
|
handle(Smi::FromInt(300), isolate));
|
|
|
|
CHECK_EQ(3, array->Length());
|
2017-07-10 12:58:27 +00:00
|
|
|
CHECK_EQ(100, Smi::ToInt(array->Get(0)));
|
|
|
|
CHECK_EQ(200, Smi::ToInt(array->Get(1)));
|
|
|
|
CHECK_EQ(300, Smi::ToInt(array->Get(2)));
|
2015-03-06 12:36:16 +00:00
|
|
|
array->Set(2, Smi::FromInt(400));
|
2017-07-10 12:58:27 +00:00
|
|
|
CHECK_EQ(400, Smi::ToInt(array->Get(2)));
|
2018-07-04 09:10:05 +00:00
|
|
|
array->Clear(2, ReadOnlyRoots(isolate).undefined_value());
|
2015-03-06 12:36:16 +00:00
|
|
|
array->SetLength(2);
|
|
|
|
CHECK_EQ(2, array->Length());
|
2017-07-10 12:58:27 +00:00
|
|
|
CHECK_EQ(100, Smi::ToInt(array->Get(0)));
|
|
|
|
CHECK_EQ(200, Smi::ToInt(array->Get(1)));
|
2015-03-06 12:36:16 +00:00
|
|
|
}
|
2015-09-30 13:46:56 +00:00
|
|
|
|
2017-08-31 12:34:55 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|