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>
|
|
|
|
|
|
|
|
#include "src/factory.h"
|
2016-09-01 12:01:33 +00:00
|
|
|
#include "src/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);
|
|
|
|
Handle<ArrayList> array(
|
|
|
|
ArrayList::cast(isolate->heap()->empty_fixed_array()));
|
|
|
|
CHECK_EQ(0, array->Length());
|
|
|
|
array = ArrayList::Add(array, handle(Smi::FromInt(100), isolate));
|
|
|
|
CHECK_EQ(1, array->Length());
|
2017-07-10 12:58:27 +00:00
|
|
|
CHECK_EQ(100, Smi::ToInt(array->Get(0)));
|
2015-03-06 12:36:16 +00:00
|
|
|
array = ArrayList::Add(array, handle(Smi::FromInt(200), isolate),
|
|
|
|
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)));
|
2015-03-06 12:36:16 +00:00
|
|
|
array->Clear(2, isolate->heap()->undefined_value());
|
|
|
|
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
|