2012-03-05 16:14:34 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2011-08-03 11:12:46 +00:00
|
|
|
|
2015-08-20 07:44:00 +00:00
|
|
|
#include "src/elements.h"
|
2011-08-03 11:12:46 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/arguments.h"
|
|
|
|
#include "src/conversions.h"
|
2015-08-20 07:44:00 +00:00
|
|
|
#include "src/factory.h"
|
2015-05-06 07:51:56 +00:00
|
|
|
#include "src/messages.h"
|
2015-08-20 07:44:00 +00:00
|
|
|
#include "src/objects-inl.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/utils.h"
|
2011-11-08 11:59:56 +00:00
|
|
|
|
|
|
|
// Each concrete ElementsAccessor can handle exactly one ElementsKind,
|
|
|
|
// several abstract ElementsAccessor classes are used to allow sharing
|
|
|
|
// common code.
|
|
|
|
//
|
|
|
|
// Inheritance hierarchy:
|
|
|
|
// - ElementsAccessorBase (abstract)
|
|
|
|
// - FastElementsAccessor (abstract)
|
2012-05-23 14:24:29 +00:00
|
|
|
// - FastSmiOrObjectElementsAccessor
|
|
|
|
// - FastPackedSmiElementsAccessor
|
|
|
|
// - FastHoleySmiElementsAccessor
|
|
|
|
// - FastPackedObjectElementsAccessor
|
|
|
|
// - FastHoleyObjectElementsAccessor
|
2011-11-08 11:59:56 +00:00
|
|
|
// - FastDoubleElementsAccessor
|
2012-05-23 14:24:29 +00:00
|
|
|
// - FastPackedDoubleElementsAccessor
|
|
|
|
// - FastHoleyDoubleElementsAccessor
|
2014-01-24 16:01:15 +00:00
|
|
|
// - TypedElementsAccessor: template, with instantiations:
|
|
|
|
// - FixedUint8ElementsAccessor
|
|
|
|
// - FixedInt8ElementsAccessor
|
|
|
|
// - FixedUint16ElementsAccessor
|
|
|
|
// - FixedInt16ElementsAccessor
|
|
|
|
// - FixedUint32ElementsAccessor
|
|
|
|
// - FixedInt32ElementsAccessor
|
|
|
|
// - FixedFloat32ElementsAccessor
|
|
|
|
// - FixedFloat64ElementsAccessor
|
|
|
|
// - FixedUint8ClampedElementsAccessor
|
2011-11-08 11:59:56 +00:00
|
|
|
// - DictionaryElementsAccessor
|
2014-03-11 14:39:08 +00:00
|
|
|
// - SloppyArgumentsElementsAccessor
|
2015-07-02 14:38:37 +00:00
|
|
|
// - FastSloppyArgumentsElementsAccessor
|
|
|
|
// - SlowSloppyArgumentsElementsAccessor
|
2011-11-08 11:59:56 +00:00
|
|
|
|
|
|
|
|
2011-08-03 11:12:46 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
2015-07-06 10:40:24 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
2012-06-12 15:30:16 +00:00
|
|
|
static const int kPackedSizeNotKnown = -1;
|
|
|
|
|
|
|
|
|
2012-03-09 13:48:29 +00:00
|
|
|
// First argument in list is the accessor class, the second argument is the
|
|
|
|
// accessor ElementsKind, and the third is the backing store class. Use the
|
|
|
|
// fast element handler for smi-only arrays. The implementation is currently
|
|
|
|
// identical. Note that the order must match that of the ElementsKind enum for
|
|
|
|
// the |accessor_array[]| below to work.
|
2015-07-02 14:38:37 +00:00
|
|
|
#define ELEMENTS_LIST(V) \
|
|
|
|
V(FastPackedSmiElementsAccessor, FAST_SMI_ELEMENTS, FixedArray) \
|
|
|
|
V(FastHoleySmiElementsAccessor, FAST_HOLEY_SMI_ELEMENTS, FixedArray) \
|
|
|
|
V(FastPackedObjectElementsAccessor, FAST_ELEMENTS, FixedArray) \
|
|
|
|
V(FastHoleyObjectElementsAccessor, FAST_HOLEY_ELEMENTS, FixedArray) \
|
|
|
|
V(FastPackedDoubleElementsAccessor, FAST_DOUBLE_ELEMENTS, FixedDoubleArray) \
|
|
|
|
V(FastHoleyDoubleElementsAccessor, FAST_HOLEY_DOUBLE_ELEMENTS, \
|
|
|
|
FixedDoubleArray) \
|
|
|
|
V(DictionaryElementsAccessor, DICTIONARY_ELEMENTS, SeededNumberDictionary) \
|
|
|
|
V(FastSloppyArgumentsElementsAccessor, FAST_SLOPPY_ARGUMENTS_ELEMENTS, \
|
|
|
|
FixedArray) \
|
|
|
|
V(SlowSloppyArgumentsElementsAccessor, SLOW_SLOPPY_ARGUMENTS_ELEMENTS, \
|
|
|
|
FixedArray) \
|
|
|
|
V(FixedUint8ElementsAccessor, UINT8_ELEMENTS, FixedUint8Array) \
|
|
|
|
V(FixedInt8ElementsAccessor, INT8_ELEMENTS, FixedInt8Array) \
|
|
|
|
V(FixedUint16ElementsAccessor, UINT16_ELEMENTS, FixedUint16Array) \
|
|
|
|
V(FixedInt16ElementsAccessor, INT16_ELEMENTS, FixedInt16Array) \
|
|
|
|
V(FixedUint32ElementsAccessor, UINT32_ELEMENTS, FixedUint32Array) \
|
|
|
|
V(FixedInt32ElementsAccessor, INT32_ELEMENTS, FixedInt32Array) \
|
|
|
|
V(FixedFloat32ElementsAccessor, FLOAT32_ELEMENTS, FixedFloat32Array) \
|
|
|
|
V(FixedFloat64ElementsAccessor, FLOAT64_ELEMENTS, FixedFloat64Array) \
|
|
|
|
V(FixedUint8ClampedElementsAccessor, UINT8_CLAMPED_ELEMENTS, \
|
2014-01-16 17:08:45 +00:00
|
|
|
FixedUint8ClampedArray)
|
2012-03-09 13:48:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
template<ElementsKind Kind> class ElementsKindTraits {
|
|
|
|
public:
|
|
|
|
typedef FixedArrayBase BackingStore;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ELEMENTS_TRAITS(Class, KindParam, Store) \
|
|
|
|
template<> class ElementsKindTraits<KindParam> { \
|
2014-05-09 12:59:24 +00:00
|
|
|
public: /* NOLINT */ \
|
2012-03-09 13:48:29 +00:00
|
|
|
static const ElementsKind Kind = KindParam; \
|
|
|
|
typedef Store BackingStore; \
|
|
|
|
};
|
|
|
|
ELEMENTS_LIST(ELEMENTS_TRAITS)
|
|
|
|
#undef ELEMENTS_TRAITS
|
|
|
|
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static bool HasIndex(Handle<FixedArray> array, Handle<Object> index_handle) {
|
2014-04-09 12:56:24 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2015-07-07 11:52:51 +00:00
|
|
|
Object* index = *index_handle;
|
2011-08-10 10:51:01 +00:00
|
|
|
int len0 = array->length();
|
|
|
|
for (int i = 0; i < len0; i++) {
|
|
|
|
Object* element = array->get(i);
|
2015-07-07 11:52:51 +00:00
|
|
|
if (index->KeyEquals(element)) return true;
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-09 13:16:19 +00:00
|
|
|
MUST_USE_RESULT
|
2015-08-27 13:05:50 +00:00
|
|
|
MaybeHandle<Object> ThrowArrayLengthRangeError(Isolate* isolate) {
|
2015-05-06 07:51:56 +00:00
|
|
|
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kInvalidArrayLength),
|
2014-09-01 09:11:44 +00:00
|
|
|
Object);
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-25 11:18:29 +00:00
|
|
|
|
2015-08-27 13:05:50 +00:00
|
|
|
void CopyObjectToObjectElements(FixedArrayBase* from_base,
|
|
|
|
ElementsKind from_kind, uint32_t from_start,
|
|
|
|
FixedArrayBase* to_base, ElementsKind to_kind,
|
|
|
|
uint32_t to_start, int raw_copy_size) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(to_base->map() !=
|
2013-09-10 14:30:36 +00:00
|
|
|
from_base->GetIsolate()->heap()->fixed_cow_array_map());
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2012-03-16 13:59:59 +00:00
|
|
|
int copy_size = raw_copy_size;
|
|
|
|
if (raw_copy_size < 0) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
2012-03-16 13:59:59 +00:00
|
|
|
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
|
2012-11-29 15:58:16 +00:00
|
|
|
copy_size = Min(from_base->length() - from_start,
|
|
|
|
to_base->length() - to_start);
|
2012-03-16 13:59:59 +00:00
|
|
|
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
|
2012-11-27 12:01:14 +00:00
|
|
|
int start = to_start + copy_size;
|
2012-11-29 15:58:16 +00:00
|
|
|
int length = to_base->length() - start;
|
2012-11-27 12:01:14 +00:00
|
|
|
if (length > 0) {
|
2012-11-29 15:58:16 +00:00
|
|
|
Heap* heap = from_base->GetHeap();
|
2014-07-25 13:00:06 +00:00
|
|
|
MemsetPointer(FixedArray::cast(to_base)->data_start() + start,
|
2012-11-29 15:58:16 +00:00
|
|
|
heap->the_hole_value(), length);
|
2012-03-16 13:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
2012-11-29 15:58:16 +00:00
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2012-03-09 13:48:29 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedArray* from = FixedArray::cast(from_base);
|
|
|
|
FixedArray* to = FixedArray::cast(to_base);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsFastSmiOrObjectElementsKind(from_kind));
|
|
|
|
DCHECK(IsFastSmiOrObjectElementsKind(to_kind));
|
2012-03-16 13:59:59 +00:00
|
|
|
Address to_address = to->address() + FixedArray::kHeaderSize;
|
|
|
|
Address from_address = from->address() + FixedArray::kHeaderSize;
|
|
|
|
CopyWords(reinterpret_cast<Object**>(to_address) + to_start,
|
|
|
|
reinterpret_cast<Object**>(from_address) + from_start,
|
2013-04-16 12:30:51 +00:00
|
|
|
static_cast<size_t>(copy_size));
|
2012-05-23 14:24:29 +00:00
|
|
|
if (IsFastObjectElementsKind(from_kind) &&
|
|
|
|
IsFastObjectElementsKind(to_kind)) {
|
2012-03-16 13:59:59 +00:00
|
|
|
Heap* heap = from->GetHeap();
|
2014-07-25 13:00:06 +00:00
|
|
|
if (!heap->InNewSpace(to)) {
|
2012-03-16 13:59:59 +00:00
|
|
|
heap->RecordWrites(to->address(),
|
|
|
|
to->OffsetOfElementAt(to_start),
|
2012-03-09 13:48:29 +00:00
|
|
|
copy_size);
|
|
|
|
}
|
2014-07-25 13:00:06 +00:00
|
|
|
heap->incremental_marking()->RecordWrites(to);
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-25 13:00:06 +00:00
|
|
|
static void CopyDictionaryToObjectElements(
|
|
|
|
FixedArrayBase* from_base, uint32_t from_start, FixedArrayBase* to_base,
|
|
|
|
ElementsKind to_kind, uint32_t to_start, int raw_copy_size) {
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2014-07-25 13:00:06 +00:00
|
|
|
SeededNumberDictionary* from = SeededNumberDictionary::cast(from_base);
|
2012-03-16 13:59:59 +00:00
|
|
|
int copy_size = raw_copy_size;
|
|
|
|
Heap* heap = from->GetHeap();
|
|
|
|
if (raw_copy_size < 0) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
2012-03-16 13:59:59 +00:00
|
|
|
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
|
|
|
|
copy_size = from->max_number_key() + 1 - from_start;
|
|
|
|
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
|
2012-11-27 12:01:14 +00:00
|
|
|
int start = to_start + copy_size;
|
2012-11-29 15:58:16 +00:00
|
|
|
int length = to_base->length() - start;
|
2012-11-27 12:01:14 +00:00
|
|
|
if (length > 0) {
|
|
|
|
Heap* heap = from->GetHeap();
|
2014-07-25 13:00:06 +00:00
|
|
|
MemsetPointer(FixedArray::cast(to_base)->data_start() + start,
|
2012-11-29 15:58:16 +00:00
|
|
|
heap->the_hole_value(), length);
|
2012-03-16 13:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(to_base != from_base);
|
|
|
|
DCHECK(IsFastSmiOrObjectElementsKind(to_kind));
|
2012-03-16 13:59:59 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedArray* to = FixedArray::cast(to_base);
|
2012-04-03 08:13:59 +00:00
|
|
|
uint32_t to_length = to->length();
|
|
|
|
if (to_start + copy_size > to_length) {
|
|
|
|
copy_size = to_length - to_start;
|
|
|
|
}
|
2012-03-16 13:59:59 +00:00
|
|
|
for (int i = 0; i < copy_size; i++) {
|
|
|
|
int entry = from->FindEntry(i + from_start);
|
|
|
|
if (entry != SeededNumberDictionary::kNotFound) {
|
|
|
|
Object* value = from->ValueAt(entry);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!value->IsTheHole());
|
2012-03-16 13:59:59 +00:00
|
|
|
to->set(i + to_start, value, SKIP_WRITE_BARRIER);
|
|
|
|
} else {
|
|
|
|
to->set_the_hole(i + to_start);
|
|
|
|
}
|
|
|
|
}
|
2012-05-23 14:24:29 +00:00
|
|
|
if (IsFastObjectElementsKind(to_kind)) {
|
2014-07-25 13:00:06 +00:00
|
|
|
if (!heap->InNewSpace(to)) {
|
2012-03-16 13:59:59 +00:00
|
|
|
heap->RecordWrites(to->address(),
|
|
|
|
to->OffsetOfElementAt(to_start),
|
|
|
|
copy_size);
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
2014-07-25 13:00:06 +00:00
|
|
|
heap->incremental_marking()->RecordWrites(to);
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-29 08:22:24 +00:00
|
|
|
// NOTE: this method violates the handlified function signature convention:
|
|
|
|
// raw pointer parameters in the function that allocates.
|
|
|
|
// See ElementsAccessorBase::CopyElements() for details.
|
|
|
|
static void CopyDoubleToObjectElements(FixedArrayBase* from_base,
|
2014-03-27 16:41:09 +00:00
|
|
|
uint32_t from_start,
|
2014-09-29 08:22:24 +00:00
|
|
|
FixedArrayBase* to_base,
|
|
|
|
ElementsKind to_kind, uint32_t to_start,
|
2014-03-27 16:41:09 +00:00
|
|
|
int raw_copy_size) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsFastSmiOrObjectElementsKind(to_kind));
|
2012-03-16 13:59:59 +00:00
|
|
|
int copy_size = raw_copy_size;
|
|
|
|
if (raw_copy_size < 0) {
|
2014-09-29 08:22:24 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
2012-03-16 13:59:59 +00:00
|
|
|
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
|
2012-11-29 15:58:16 +00:00
|
|
|
copy_size = Min(from_base->length() - from_start,
|
|
|
|
to_base->length() - to_start);
|
2012-03-16 13:59:59 +00:00
|
|
|
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
|
2012-11-27 12:01:14 +00:00
|
|
|
// Also initialize the area that will be copied over since HeapNumber
|
|
|
|
// allocation below can cause an incremental marking step, requiring all
|
|
|
|
// existing heap objects to be propertly initialized.
|
|
|
|
int start = to_start;
|
2012-11-29 15:58:16 +00:00
|
|
|
int length = to_base->length() - start;
|
2012-11-27 12:01:14 +00:00
|
|
|
if (length > 0) {
|
2012-11-29 15:58:16 +00:00
|
|
|
Heap* heap = from_base->GetHeap();
|
2014-09-29 08:22:24 +00:00
|
|
|
MemsetPointer(FixedArray::cast(to_base)->data_start() + start,
|
2012-11-29 15:58:16 +00:00
|
|
|
heap->the_hole_value(), length);
|
2012-03-16 13:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
2015-07-31 16:10:37 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
2012-11-29 15:58:16 +00:00
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2014-03-27 16:41:09 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-09-29 08:22:24 +00:00
|
|
|
|
|
|
|
// From here on, the code below could actually allocate. Therefore the raw
|
|
|
|
// values are wrapped into handles.
|
2014-04-03 09:12:59 +00:00
|
|
|
Isolate* isolate = from_base->GetIsolate();
|
2014-09-29 08:22:24 +00:00
|
|
|
Handle<FixedDoubleArray> from(FixedDoubleArray::cast(from_base), isolate);
|
|
|
|
Handle<FixedArray> to(FixedArray::cast(to_base), isolate);
|
2012-03-09 13:48:29 +00:00
|
|
|
for (int i = 0; i < copy_size; ++i) {
|
2014-04-03 09:12:59 +00:00
|
|
|
HandleScope scope(isolate);
|
2012-05-23 14:24:29 +00:00
|
|
|
if (IsFastSmiElementsKind(to_kind)) {
|
2012-03-09 13:48:29 +00:00
|
|
|
UNIMPLEMENTED();
|
|
|
|
} else {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsFastObjectElementsKind(to_kind));
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<Object> value = FixedDoubleArray::get(from, i + from_start);
|
2014-03-27 16:41:09 +00:00
|
|
|
to->set(i + to_start, *value, UPDATE_WRITE_BARRIER);
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-25 13:00:06 +00:00
|
|
|
static void CopyDoubleToDoubleElements(FixedArrayBase* from_base,
|
2012-03-09 13:48:29 +00:00
|
|
|
uint32_t from_start,
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedArrayBase* to_base,
|
|
|
|
uint32_t to_start, int raw_copy_size) {
|
2014-03-27 16:41:09 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2012-03-16 13:59:59 +00:00
|
|
|
int copy_size = raw_copy_size;
|
|
|
|
if (raw_copy_size < 0) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
2012-03-16 13:59:59 +00:00
|
|
|
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
|
2012-11-29 15:58:16 +00:00
|
|
|
copy_size = Min(from_base->length() - from_start,
|
|
|
|
to_base->length() - to_start);
|
2012-03-16 13:59:59 +00:00
|
|
|
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
|
2012-11-29 15:58:16 +00:00
|
|
|
for (int i = to_start + copy_size; i < to_base->length(); ++i) {
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedDoubleArray::cast(to_base)->set_the_hole(i);
|
2012-03-16 13:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
2012-11-29 15:58:16 +00:00
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2012-03-09 13:48:29 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedDoubleArray* from = FixedDoubleArray::cast(from_base);
|
|
|
|
FixedDoubleArray* to = FixedDoubleArray::cast(to_base);
|
2012-03-16 13:59:59 +00:00
|
|
|
Address to_address = to->address() + FixedDoubleArray::kHeaderSize;
|
|
|
|
Address from_address = from->address() + FixedDoubleArray::kHeaderSize;
|
|
|
|
to_address += kDoubleSize * to_start;
|
|
|
|
from_address += kDoubleSize * from_start;
|
2012-03-09 13:48:29 +00:00
|
|
|
int words_per_double = (kDoubleSize / kPointerSize);
|
2012-03-16 13:59:59 +00:00
|
|
|
CopyWords(reinterpret_cast<Object**>(to_address),
|
|
|
|
reinterpret_cast<Object**>(from_address),
|
2013-04-16 12:30:51 +00:00
|
|
|
static_cast<size_t>(words_per_double * copy_size));
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-25 13:00:06 +00:00
|
|
|
static void CopySmiToDoubleElements(FixedArrayBase* from_base,
|
2012-06-12 15:30:16 +00:00
|
|
|
uint32_t from_start,
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedArrayBase* to_base, uint32_t to_start,
|
2012-06-12 15:30:16 +00:00
|
|
|
int raw_copy_size) {
|
2014-03-27 16:41:09 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2012-06-12 15:30:16 +00:00
|
|
|
int copy_size = raw_copy_size;
|
|
|
|
if (raw_copy_size < 0) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
2012-06-12 15:30:16 +00:00
|
|
|
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
|
2012-11-29 15:58:16 +00:00
|
|
|
copy_size = from_base->length() - from_start;
|
2012-06-12 15:30:16 +00:00
|
|
|
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
|
2012-11-29 15:58:16 +00:00
|
|
|
for (int i = to_start + copy_size; i < to_base->length(); ++i) {
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedDoubleArray::cast(to_base)->set_the_hole(i);
|
2012-06-12 15:30:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
2012-11-29 15:58:16 +00:00
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2012-06-12 15:30:16 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedArray* from = FixedArray::cast(from_base);
|
|
|
|
FixedDoubleArray* to = FixedDoubleArray::cast(to_base);
|
|
|
|
Object* the_hole = from->GetHeap()->the_hole_value();
|
2012-06-12 15:30:16 +00:00
|
|
|
for (uint32_t from_end = from_start + static_cast<uint32_t>(copy_size);
|
|
|
|
from_start < from_end; from_start++, to_start++) {
|
|
|
|
Object* hole_or_smi = from->get(from_start);
|
2014-07-25 13:00:06 +00:00
|
|
|
if (hole_or_smi == the_hole) {
|
2012-06-12 15:30:16 +00:00
|
|
|
to->set_the_hole(to_start);
|
|
|
|
} else {
|
|
|
|
to->set(to_start, Smi::cast(hole_or_smi)->value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-25 13:00:06 +00:00
|
|
|
static void CopyPackedSmiToDoubleElements(FixedArrayBase* from_base,
|
2012-06-12 15:30:16 +00:00
|
|
|
uint32_t from_start,
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedArrayBase* to_base,
|
|
|
|
uint32_t to_start, int packed_size,
|
2012-06-12 15:30:16 +00:00
|
|
|
int raw_copy_size) {
|
2014-03-27 16:41:09 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2012-06-12 15:30:16 +00:00
|
|
|
int copy_size = raw_copy_size;
|
|
|
|
uint32_t to_end;
|
|
|
|
if (raw_copy_size < 0) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
2012-06-12 15:30:16 +00:00
|
|
|
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
|
2012-11-29 08:34:19 +00:00
|
|
|
copy_size = packed_size - from_start;
|
2012-06-12 15:30:16 +00:00
|
|
|
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
|
2012-11-29 15:58:16 +00:00
|
|
|
to_end = to_base->length();
|
2012-11-26 14:29:21 +00:00
|
|
|
for (uint32_t i = to_start + copy_size; i < to_end; ++i) {
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedDoubleArray::cast(to_base)->set_the_hole(i);
|
2012-11-26 14:29:21 +00:00
|
|
|
}
|
2012-06-12 15:30:16 +00:00
|
|
|
} else {
|
|
|
|
to_end = to_start + static_cast<uint32_t>(copy_size);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
to_end = to_start + static_cast<uint32_t>(copy_size);
|
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(static_cast<int>(to_end) <= to_base->length());
|
|
|
|
DCHECK(packed_size >= 0 && packed_size <= copy_size);
|
|
|
|
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
2012-11-29 15:58:16 +00:00
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2012-06-12 15:30:16 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedArray* from = FixedArray::cast(from_base);
|
|
|
|
FixedDoubleArray* to = FixedDoubleArray::cast(to_base);
|
2012-06-12 15:30:16 +00:00
|
|
|
for (uint32_t from_end = from_start + static_cast<uint32_t>(packed_size);
|
|
|
|
from_start < from_end; from_start++, to_start++) {
|
|
|
|
Object* smi = from->get(from_start);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!smi->IsTheHole());
|
2012-06-12 15:30:16 +00:00
|
|
|
to->set(to_start, Smi::cast(smi)->value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-25 13:00:06 +00:00
|
|
|
static void CopyObjectToDoubleElements(FixedArrayBase* from_base,
|
2012-03-16 13:59:59 +00:00
|
|
|
uint32_t from_start,
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedArrayBase* to_base,
|
|
|
|
uint32_t to_start, int raw_copy_size) {
|
2014-03-27 16:41:09 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2012-03-16 13:59:59 +00:00
|
|
|
int copy_size = raw_copy_size;
|
|
|
|
if (raw_copy_size < 0) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
2012-03-16 13:59:59 +00:00
|
|
|
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
|
2012-11-29 15:58:16 +00:00
|
|
|
copy_size = from_base->length() - from_start;
|
2012-03-16 13:59:59 +00:00
|
|
|
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
|
2012-11-29 15:58:16 +00:00
|
|
|
for (int i = to_start + copy_size; i < to_base->length(); ++i) {
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedDoubleArray::cast(to_base)->set_the_hole(i);
|
2012-03-16 13:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
2012-11-29 15:58:16 +00:00
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2012-03-16 13:59:59 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedArray* from = FixedArray::cast(from_base);
|
|
|
|
FixedDoubleArray* to = FixedDoubleArray::cast(to_base);
|
|
|
|
Object* the_hole = from->GetHeap()->the_hole_value();
|
2012-06-12 15:30:16 +00:00
|
|
|
for (uint32_t from_end = from_start + copy_size;
|
|
|
|
from_start < from_end; from_start++, to_start++) {
|
|
|
|
Object* hole_or_object = from->get(from_start);
|
2014-07-25 13:00:06 +00:00
|
|
|
if (hole_or_object == the_hole) {
|
2012-06-12 15:30:16 +00:00
|
|
|
to->set_the_hole(to_start);
|
2012-03-16 13:59:59 +00:00
|
|
|
} else {
|
2012-06-12 15:30:16 +00:00
|
|
|
to->set(to_start, hole_or_object->Number());
|
2012-03-16 13:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-25 13:00:06 +00:00
|
|
|
static void CopyDictionaryToDoubleElements(FixedArrayBase* from_base,
|
2012-03-16 13:59:59 +00:00
|
|
|
uint32_t from_start,
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedArrayBase* to_base,
|
2012-03-16 13:59:59 +00:00
|
|
|
uint32_t to_start,
|
|
|
|
int raw_copy_size) {
|
2014-03-27 16:41:09 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2014-07-25 13:00:06 +00:00
|
|
|
SeededNumberDictionary* from = SeededNumberDictionary::cast(from_base);
|
2012-03-16 13:59:59 +00:00
|
|
|
int copy_size = raw_copy_size;
|
|
|
|
if (copy_size < 0) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(copy_size == ElementsAccessor::kCopyToEnd ||
|
2012-03-16 13:59:59 +00:00
|
|
|
copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
|
|
|
|
copy_size = from->max_number_key() + 1 - from_start;
|
|
|
|
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
|
2012-11-29 15:58:16 +00:00
|
|
|
for (int i = to_start + copy_size; i < to_base->length(); ++i) {
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedDoubleArray::cast(to_base)->set_the_hole(i);
|
2012-03-16 13:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (copy_size == 0) return;
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedDoubleArray* to = FixedDoubleArray::cast(to_base);
|
2012-04-03 08:13:59 +00:00
|
|
|
uint32_t to_length = to->length();
|
|
|
|
if (to_start + copy_size > to_length) {
|
|
|
|
copy_size = to_length - to_start;
|
|
|
|
}
|
2012-03-16 13:59:59 +00:00
|
|
|
for (int i = 0; i < copy_size; i++) {
|
|
|
|
int entry = from->FindEntry(i + from_start);
|
|
|
|
if (entry != SeededNumberDictionary::kNotFound) {
|
|
|
|
to->set(i + to_start, from->ValueAt(entry)->Number());
|
|
|
|
} else {
|
|
|
|
to->set_the_hole(i + to_start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
static void TraceTopFrame(Isolate* isolate) {
|
|
|
|
StackFrameIterator it(isolate);
|
2013-02-07 07:56:11 +00:00
|
|
|
if (it.done()) {
|
|
|
|
PrintF("unknown location (no JavaScript frames present)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StackFrame* raw_frame = it.frame();
|
|
|
|
if (raw_frame->is_internal()) {
|
|
|
|
Code* apply_builtin = isolate->builtins()->builtin(
|
|
|
|
Builtins::kFunctionApply);
|
|
|
|
if (raw_frame->unchecked_code() == apply_builtin) {
|
|
|
|
PrintF("apply from ");
|
|
|
|
it.Advance();
|
|
|
|
raw_frame = it.frame();
|
|
|
|
}
|
|
|
|
}
|
2013-02-15 09:27:10 +00:00
|
|
|
JavaScriptFrame::PrintTop(isolate, stdout, false, true);
|
2013-02-07 07:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-03 11:12:46 +00:00
|
|
|
// Base class for element handler implementations. Contains the
|
|
|
|
// the common logic for objects with different ElementsKinds.
|
|
|
|
// Subclasses must specialize method for which the element
|
|
|
|
// implementation differs from the base class implementation.
|
|
|
|
//
|
|
|
|
// This class is intended to be used in the following way:
|
|
|
|
//
|
|
|
|
// class SomeElementsAccessor :
|
|
|
|
// public ElementsAccessorBase<SomeElementsAccessor,
|
|
|
|
// BackingStoreClass> {
|
|
|
|
// ...
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// This is an example of the Curiously Recurring Template Pattern (see
|
|
|
|
// http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). We use
|
|
|
|
// CRTP to guarantee aggressive compile time optimizations (i.e. inlining and
|
|
|
|
// specialization of SomeElementsAccessor methods).
|
2012-03-09 13:48:29 +00:00
|
|
|
template <typename ElementsAccessorSubclass,
|
|
|
|
typename ElementsTraitsParam>
|
2011-08-03 11:12:46 +00:00
|
|
|
class ElementsAccessorBase : public ElementsAccessor {
|
2015-07-02 16:44:17 +00:00
|
|
|
public:
|
2012-03-09 13:48:29 +00:00
|
|
|
explicit ElementsAccessorBase(const char* name)
|
|
|
|
: ElementsAccessor(name) { }
|
|
|
|
|
|
|
|
typedef ElementsTraitsParam ElementsTraits;
|
|
|
|
typedef typename ElementsTraitsParam::BackingStore BackingStore;
|
|
|
|
|
2015-06-23 09:44:15 +00:00
|
|
|
static ElementsKind kind() { return ElementsTraits::Kind; }
|
2012-03-06 12:22:18 +00:00
|
|
|
|
2014-04-16 06:18:37 +00:00
|
|
|
static void ValidateContents(Handle<JSObject> holder, int length) {
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 06:18:37 +00:00
|
|
|
static void ValidateImpl(Handle<JSObject> holder) {
|
|
|
|
Handle<FixedArrayBase> fixed_array_base(holder->elements());
|
2012-05-23 14:24:29 +00:00
|
|
|
if (!fixed_array_base->IsHeapObject()) return;
|
|
|
|
// Arrays that have been shifted in place can't be verified.
|
2013-08-21 13:39:20 +00:00
|
|
|
if (fixed_array_base->IsFiller()) return;
|
2012-05-23 14:24:29 +00:00
|
|
|
int length = 0;
|
|
|
|
if (holder->IsJSArray()) {
|
2014-04-16 06:18:37 +00:00
|
|
|
Object* length_obj = Handle<JSArray>::cast(holder)->length();
|
2012-05-23 14:24:29 +00:00
|
|
|
if (length_obj->IsSmi()) {
|
|
|
|
length = Smi::cast(length_obj)->value();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
length = fixed_array_base->length();
|
|
|
|
}
|
|
|
|
ElementsAccessorSubclass::ValidateContents(holder, length);
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:08:11 +00:00
|
|
|
void Validate(Handle<JSObject> holder) final {
|
2014-04-07 10:00:14 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2014-04-16 06:18:37 +00:00
|
|
|
ElementsAccessorSubclass::ValidateImpl(holder);
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
virtual bool HasElement(Handle<JSObject> holder, uint32_t index,
|
2015-04-20 13:08:11 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) final {
|
2015-07-07 11:52:51 +00:00
|
|
|
return ElementsAccessorSubclass::GetEntryForIndexImpl(
|
|
|
|
*holder, *backing_store, index) != kMaxUInt32;
|
2012-03-06 12:22:18 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 14:13:27 +00:00
|
|
|
virtual Handle<Object> Get(Handle<FixedArrayBase> backing_store,
|
|
|
|
uint32_t entry) final {
|
|
|
|
return ElementsAccessorSubclass::GetImpl(backing_store, entry);
|
2011-08-18 09:51:08 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 14:13:27 +00:00
|
|
|
static Handle<Object> GetImpl(Handle<FixedArrayBase> backing_store,
|
|
|
|
uint32_t entry) {
|
|
|
|
uint32_t index = GetIndexForEntryImpl(*backing_store, entry);
|
|
|
|
return BackingStore::get(Handle<BackingStore>::cast(backing_store), index);
|
2011-08-03 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 12:56:36 +00:00
|
|
|
virtual void Set(FixedArrayBase* backing_store, uint32_t entry,
|
2015-06-19 09:25:16 +00:00
|
|
|
Object* value) final {
|
2015-07-10 12:56:36 +00:00
|
|
|
ElementsAccessorSubclass::SetImpl(backing_store, entry, value);
|
2015-06-11 15:07:00 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 12:56:36 +00:00
|
|
|
static void SetImpl(FixedArrayBase* backing_store, uint32_t entry,
|
2015-06-19 09:25:16 +00:00
|
|
|
Object* value) {
|
2015-07-10 12:56:36 +00:00
|
|
|
BackingStore::cast(backing_store)->SetValue(entry, value);
|
2015-06-11 15:07:00 +00:00
|
|
|
}
|
|
|
|
|
2015-06-25 11:25:59 +00:00
|
|
|
virtual void Reconfigure(Handle<JSObject> object,
|
2015-07-07 11:52:51 +00:00
|
|
|
Handle<FixedArrayBase> store, uint32_t entry,
|
2015-06-25 11:25:59 +00:00
|
|
|
Handle<Object> value,
|
|
|
|
PropertyAttributes attributes) final {
|
2015-07-07 11:52:51 +00:00
|
|
|
ElementsAccessorSubclass::ReconfigureImpl(object, store, entry, value,
|
2015-06-25 11:25:59 +00:00
|
|
|
attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReconfigureImpl(Handle<JSObject> object,
|
2015-07-07 11:52:51 +00:00
|
|
|
Handle<FixedArrayBase> store, uint32_t entry,
|
2015-06-25 11:25:59 +00:00
|
|
|
Handle<Object> value,
|
|
|
|
PropertyAttributes attributes) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2015-07-10 12:56:36 +00:00
|
|
|
virtual void Add(Handle<JSObject> object, uint32_t index,
|
2015-06-25 14:17:10 +00:00
|
|
|
Handle<Object> value, PropertyAttributes attributes,
|
|
|
|
uint32_t new_capacity) final {
|
2015-07-10 12:56:36 +00:00
|
|
|
ElementsAccessorSubclass::AddImpl(object, index, value, attributes,
|
2015-06-25 14:17:10 +00:00
|
|
|
new_capacity);
|
|
|
|
}
|
|
|
|
|
2015-07-10 12:56:36 +00:00
|
|
|
static void AddImpl(Handle<JSObject> object, uint32_t index,
|
2015-06-25 14:17:10 +00:00
|
|
|
Handle<Object> value, PropertyAttributes attributes,
|
|
|
|
uint32_t new_capacity) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2015-07-31 16:10:37 +00:00
|
|
|
virtual uint32_t Push(Handle<JSArray> receiver,
|
|
|
|
Handle<FixedArrayBase> backing_store, Object** objects,
|
|
|
|
uint32_t push_size, int direction) {
|
|
|
|
return ElementsAccessorSubclass::PushImpl(receiver, backing_store, objects,
|
|
|
|
push_size, direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t PushImpl(Handle<JSArray> receiver,
|
|
|
|
Handle<FixedArrayBase> elms_obj, Object** objects,
|
|
|
|
uint32_t push_size, int direction) {
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-27 13:05:50 +00:00
|
|
|
virtual Handle<JSArray> Splice(Handle<JSArray> receiver,
|
|
|
|
Handle<FixedArrayBase> backing_store,
|
|
|
|
uint32_t start, uint32_t delete_count,
|
|
|
|
Arguments args, uint32_t add_count) {
|
|
|
|
return ElementsAccessorSubclass::SpliceImpl(receiver, backing_store, start,
|
|
|
|
delete_count, args, add_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver,
|
|
|
|
Handle<FixedArrayBase> backing_store,
|
|
|
|
uint32_t start, uint32_t delete_count,
|
|
|
|
Arguments args, uint32_t add_count) {
|
|
|
|
UNREACHABLE();
|
|
|
|
return Handle<JSArray>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-19 14:56:57 +00:00
|
|
|
virtual void SetLength(Handle<JSArray> array, uint32_t length) final {
|
|
|
|
ElementsAccessorSubclass::SetLengthImpl(array, length,
|
|
|
|
handle(array->elements()));
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 14:56:57 +00:00
|
|
|
static void SetLengthImpl(Handle<JSArray> array, uint32_t length,
|
|
|
|
Handle<FixedArrayBase> backing_store);
|
2011-11-08 11:59:56 +00:00
|
|
|
|
2015-06-23 09:44:15 +00:00
|
|
|
static Handle<FixedArrayBase> ConvertElementsWithCapacity(
|
|
|
|
Handle<JSObject> object, Handle<FixedArrayBase> old_elements,
|
|
|
|
ElementsKind from_kind, uint32_t capacity) {
|
2015-08-27 13:05:50 +00:00
|
|
|
return ConvertElementsWithCapacity(
|
|
|
|
object, old_elements, from_kind, capacity,
|
|
|
|
ElementsAccessor::kCopyToEndAndInitializeToHole);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Handle<FixedArrayBase> ConvertElementsWithCapacity(
|
|
|
|
Handle<JSObject> object, Handle<FixedArrayBase> old_elements,
|
|
|
|
ElementsKind from_kind, uint32_t capacity, int copy_size) {
|
2015-06-23 09:44:15 +00:00
|
|
|
Isolate* isolate = object->GetIsolate();
|
2015-08-27 13:05:50 +00:00
|
|
|
Handle<FixedArrayBase> new_elements;
|
2015-06-23 09:44:15 +00:00
|
|
|
if (IsFastDoubleElementsKind(kind())) {
|
2015-08-27 13:05:50 +00:00
|
|
|
new_elements = isolate->factory()->NewFixedDoubleArray(capacity);
|
2015-06-23 09:44:15 +00:00
|
|
|
} else {
|
2015-08-27 13:05:50 +00:00
|
|
|
new_elements = isolate->factory()->NewUninitializedFixedArray(capacity);
|
2015-06-23 09:44:15 +00:00
|
|
|
}
|
|
|
|
|
2015-08-27 13:05:50 +00:00
|
|
|
int packed_size = kPackedSizeNotKnown;
|
2015-06-23 09:44:15 +00:00
|
|
|
if (IsFastPackedElementsKind(from_kind) && object->IsJSArray()) {
|
2015-08-27 13:05:50 +00:00
|
|
|
packed_size = Smi::cast(JSArray::cast(*object)->length())->value();
|
2015-06-23 09:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ElementsAccessorSubclass::CopyElementsImpl(
|
2015-08-27 13:05:50 +00:00
|
|
|
*old_elements, 0, *new_elements, from_kind, 0, packed_size, copy_size);
|
|
|
|
|
|
|
|
return new_elements;
|
2015-06-23 09:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void GrowCapacityAndConvertImpl(Handle<JSObject> object,
|
2015-06-22 11:24:03 +00:00
|
|
|
uint32_t capacity) {
|
2015-06-23 09:44:15 +00:00
|
|
|
ElementsKind from_kind = object->GetElementsKind();
|
|
|
|
if (IsFastSmiOrObjectElementsKind(from_kind)) {
|
|
|
|
// Array optimizations rely on the prototype lookups of Array objects
|
|
|
|
// always returning undefined. If there is a store to the initial
|
|
|
|
// prototype object, make sure all of these optimizations are invalidated.
|
|
|
|
object->GetIsolate()->UpdateArrayProtectorOnSetLength(object);
|
|
|
|
}
|
|
|
|
Handle<FixedArrayBase> old_elements(object->elements());
|
|
|
|
// This method should only be called if there's a reason to update the
|
|
|
|
// elements.
|
|
|
|
DCHECK(IsFastDoubleElementsKind(from_kind) !=
|
|
|
|
IsFastDoubleElementsKind(kind()) ||
|
|
|
|
IsDictionaryElementsKind(from_kind) ||
|
|
|
|
static_cast<uint32_t>(old_elements->length()) < capacity);
|
|
|
|
Handle<FixedArrayBase> elements =
|
|
|
|
ConvertElementsWithCapacity(object, old_elements, from_kind, capacity);
|
|
|
|
|
|
|
|
ElementsKind to_kind = kind();
|
|
|
|
if (IsHoleyElementsKind(from_kind)) to_kind = GetHoleyElementsKind(to_kind);
|
|
|
|
Handle<Map> new_map = JSObject::GetElementsTransitionMap(object, to_kind);
|
|
|
|
JSObject::SetMapAndElements(object, new_map, elements);
|
|
|
|
|
|
|
|
// Transition through the allocation site as well if present.
|
|
|
|
JSObject::UpdateAllocationSite(object, to_kind);
|
|
|
|
|
|
|
|
if (FLAG_trace_elements_transitions) {
|
|
|
|
JSObject::PrintElementsTransition(stdout, object, from_kind, old_elements,
|
|
|
|
to_kind, elements);
|
|
|
|
}
|
2014-03-25 09:29:48 +00:00
|
|
|
}
|
|
|
|
|
2015-06-22 11:24:03 +00:00
|
|
|
virtual void GrowCapacityAndConvert(Handle<JSObject> object,
|
|
|
|
uint32_t capacity) final {
|
|
|
|
ElementsAccessorSubclass::GrowCapacityAndConvertImpl(object, capacity);
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
virtual void Delete(Handle<JSObject> obj, uint32_t entry) final {
|
|
|
|
ElementsAccessorSubclass::DeleteImpl(obj, entry);
|
2015-07-06 08:53:41 +00:00
|
|
|
}
|
2011-08-04 11:42:14 +00:00
|
|
|
|
2014-09-29 08:22:24 +00:00
|
|
|
static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
|
|
|
|
FixedArrayBase* to, ElementsKind from_kind,
|
|
|
|
uint32_t to_start, int packed_size,
|
2014-03-27 16:41:09 +00:00
|
|
|
int copy_size) {
|
2012-03-09 13:48:29 +00:00
|
|
|
UNREACHABLE();
|
2014-03-21 11:22:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 10:44:12 +00:00
|
|
|
virtual void CopyElements(Handle<FixedArrayBase> from, uint32_t from_start,
|
|
|
|
ElementsKind from_kind, Handle<FixedArrayBase> to,
|
2015-04-20 13:08:11 +00:00
|
|
|
uint32_t to_start, int copy_size) final {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!from.is_null());
|
2014-09-29 08:22:24 +00:00
|
|
|
// NOTE: the ElementsAccessorSubclass::CopyElementsImpl() methods
|
|
|
|
// violate the handlified function signature convention:
|
|
|
|
// raw pointer parameters in the function that allocates. This is done
|
|
|
|
// intentionally to avoid ArrayConcat() builtin performance degradation.
|
|
|
|
// See the comment in another ElementsAccessorBase::CopyElements() for
|
|
|
|
// details.
|
|
|
|
ElementsAccessorSubclass::CopyElementsImpl(*from, from_start, *to,
|
|
|
|
from_kind, to_start,
|
|
|
|
kPackedSizeNotKnown, copy_size);
|
2014-04-03 09:12:59 +00:00
|
|
|
}
|
2012-06-12 15:30:16 +00:00
|
|
|
|
2014-12-12 10:44:12 +00:00
|
|
|
virtual void CopyElements(JSObject* from_holder, uint32_t from_start,
|
|
|
|
ElementsKind from_kind, Handle<FixedArrayBase> to,
|
2015-04-20 13:08:11 +00:00
|
|
|
uint32_t to_start, int copy_size) final {
|
2014-04-03 09:12:59 +00:00
|
|
|
int packed_size = kPackedSizeNotKnown;
|
|
|
|
bool is_packed = IsFastPackedElementsKind(from_kind) &&
|
|
|
|
from_holder->IsJSArray();
|
|
|
|
if (is_packed) {
|
|
|
|
packed_size =
|
|
|
|
Smi::cast(JSArray::cast(from_holder)->length())->value();
|
|
|
|
if (copy_size >= 0 && packed_size > copy_size) {
|
|
|
|
packed_size = copy_size;
|
2012-06-12 15:30:16 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-29 08:22:24 +00:00
|
|
|
FixedArrayBase* from = from_holder->elements();
|
|
|
|
// NOTE: the ElementsAccessorSubclass::CopyElementsImpl() methods
|
|
|
|
// violate the handlified function signature convention:
|
|
|
|
// raw pointer parameters in the function that allocates. This is done
|
|
|
|
// intentionally to avoid ArrayConcat() builtin performance degradation.
|
|
|
|
//
|
|
|
|
// Details: The idea is that allocations actually happen only in case of
|
|
|
|
// copying from object with fast double elements to object with object
|
|
|
|
// elements. In all the other cases there are no allocations performed and
|
|
|
|
// handle creation causes noticeable performance degradation of the builtin.
|
2014-03-27 16:41:09 +00:00
|
|
|
ElementsAccessorSubclass::CopyElementsImpl(
|
2014-09-29 08:22:24 +00:00
|
|
|
from, from_start, *to, from_kind, to_start, packed_size, copy_size);
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
virtual Handle<FixedArray> AddElementsToFixedArray(
|
2015-05-20 17:03:21 +00:00
|
|
|
Handle<JSObject> receiver, Handle<FixedArray> to,
|
|
|
|
FixedArray::KeyFilter filter) final {
|
|
|
|
Handle<FixedArrayBase> from(receiver->elements());
|
|
|
|
|
2011-08-12 14:52:03 +00:00
|
|
|
int len0 = to->length();
|
2014-08-04 11:34:54 +00:00
|
|
|
#ifdef ENABLE_SLOW_DCHECKS
|
2011-08-10 10:51:01 +00:00
|
|
|
if (FLAG_enable_slow_asserts) {
|
|
|
|
for (int i = 0; i < len0; i++) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!to->get(i)->IsTheHole());
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Optimize if 'other' is empty.
|
2011-08-12 14:52:03 +00:00
|
|
|
// We cannot optimize if 'this' is empty, as other may have holes.
|
2015-05-21 12:19:39 +00:00
|
|
|
uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(*receiver, *from);
|
2011-08-12 14:52:03 +00:00
|
|
|
if (len1 == 0) return to;
|
2011-08-10 10:51:01 +00:00
|
|
|
|
2014-04-10 09:20:11 +00:00
|
|
|
Isolate* isolate = from->GetIsolate();
|
|
|
|
|
2011-08-10 10:51:01 +00:00
|
|
|
// Compute how many elements are not in other.
|
2012-03-05 16:14:34 +00:00
|
|
|
uint32_t extra = 0;
|
2011-08-17 16:15:30 +00:00
|
|
|
for (uint32_t y = 0; y < len1; y++) {
|
2015-07-07 11:52:51 +00:00
|
|
|
if (ElementsAccessorSubclass::HasEntryImpl(*from, y)) {
|
2015-07-10 14:13:27 +00:00
|
|
|
Handle<Object> value = ElementsAccessorSubclass::GetImpl(from, y);
|
2014-04-08 14:20:29 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!value->IsTheHole());
|
2015-06-02 10:42:16 +00:00
|
|
|
DCHECK(!value->IsAccessorPair());
|
|
|
|
DCHECK(!value->IsExecutableAccessorInfo());
|
2014-11-27 10:21:32 +00:00
|
|
|
if (filter == FixedArray::NON_SYMBOL_KEYS && value->IsSymbol()) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-07 11:52:51 +00:00
|
|
|
if (!HasIndex(to, value)) {
|
2011-08-17 16:15:30 +00:00
|
|
|
extra++;
|
|
|
|
}
|
|
|
|
}
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 14:52:03 +00:00
|
|
|
if (extra == 0) return to;
|
2011-08-10 10:51:01 +00:00
|
|
|
|
|
|
|
// Allocate the result
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<FixedArray> result = isolate->factory()->NewFixedArray(len0 + extra);
|
2011-08-10 10:51:01 +00:00
|
|
|
|
|
|
|
// Fill in the content
|
|
|
|
{
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2011-08-10 10:51:01 +00:00
|
|
|
WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
|
|
|
|
for (int i = 0; i < len0; i++) {
|
2011-08-12 14:52:03 +00:00
|
|
|
Object* e = to->get(i);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(e->IsString() || e->IsNumber());
|
2011-08-10 10:51:01 +00:00
|
|
|
result->set(i, e, mode);
|
|
|
|
}
|
|
|
|
}
|
2011-08-12 14:52:03 +00:00
|
|
|
// Fill in the extra values.
|
2015-07-07 11:52:51 +00:00
|
|
|
uint32_t entry = 0;
|
2011-08-17 16:15:30 +00:00
|
|
|
for (uint32_t y = 0; y < len1; y++) {
|
2015-07-07 11:52:51 +00:00
|
|
|
if (ElementsAccessorSubclass::HasEntryImpl(*from, y)) {
|
2015-07-10 14:13:27 +00:00
|
|
|
Handle<Object> value = ElementsAccessorSubclass::GetImpl(from, y);
|
2015-06-02 10:42:16 +00:00
|
|
|
DCHECK(!value->IsAccessorPair());
|
|
|
|
DCHECK(!value->IsExecutableAccessorInfo());
|
2014-11-27 10:21:32 +00:00
|
|
|
if (filter == FixedArray::NON_SYMBOL_KEYS && value->IsSymbol()) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-07 11:52:51 +00:00
|
|
|
if (!value->IsTheHole() && !HasIndex(to, value)) {
|
|
|
|
result->set(len0 + entry, *value);
|
|
|
|
entry++;
|
2011-08-17 16:15:30 +00:00
|
|
|
}
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-07 11:52:51 +00:00
|
|
|
DCHECK(extra == entry);
|
2011-08-10 10:51:01 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-05-21 12:19:39 +00:00
|
|
|
static uint32_t GetCapacityImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store) {
|
2011-08-12 14:52:03 +00:00
|
|
|
return backing_store->length();
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 12:19:39 +00:00
|
|
|
uint32_t GetCapacity(JSObject* holder, FixedArrayBase* backing_store) final {
|
2015-04-27 09:28:16 +00:00
|
|
|
return ElementsAccessorSubclass::GetCapacityImpl(holder, backing_store);
|
2011-08-03 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static bool HasEntryImpl(FixedArrayBase* backing_store, uint32_t entry) {
|
2015-06-02 10:42:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static uint32_t GetIndexForEntryImpl(FixedArrayBase* backing_store,
|
|
|
|
uint32_t entry) {
|
|
|
|
return entry;
|
2011-08-17 16:15:30 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static uint32_t GetEntryForIndexImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store,
|
|
|
|
uint32_t index) {
|
2015-07-10 14:13:27 +00:00
|
|
|
if (IsHoleyElementsKind(kind())) {
|
|
|
|
return index < ElementsAccessorSubclass::GetCapacityImpl(holder,
|
|
|
|
backing_store) &&
|
|
|
|
!BackingStore::cast(backing_store)->is_the_hole(index)
|
|
|
|
? index
|
|
|
|
: kMaxUInt32;
|
|
|
|
} else {
|
|
|
|
Smi* smi_length = Smi::cast(JSArray::cast(holder)->length());
|
|
|
|
uint32_t length = static_cast<uint32_t>(smi_length->value());
|
|
|
|
return index < length ? index : kMaxUInt32;
|
|
|
|
}
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
virtual uint32_t GetEntryForIndex(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store,
|
|
|
|
uint32_t index) final {
|
|
|
|
return ElementsAccessorSubclass::GetEntryForIndexImpl(holder, backing_store,
|
|
|
|
index);
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store,
|
2015-07-07 11:52:51 +00:00
|
|
|
uint32_t entry) {
|
2015-05-21 12:19:39 +00:00
|
|
|
return PropertyDetails(NONE, DATA, 0, PropertyCellType::kNoCell);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual PropertyDetails GetDetails(FixedArrayBase* backing_store,
|
2015-07-07 11:52:51 +00:00
|
|
|
uint32_t entry) final {
|
|
|
|
return ElementsAccessorSubclass::GetDetailsImpl(backing_store, entry);
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
2011-08-03 11:12:46 +00:00
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-02 16:44:17 +00:00
|
|
|
class DictionaryElementsAccessor
|
|
|
|
: public ElementsAccessorBase<DictionaryElementsAccessor,
|
|
|
|
ElementsKindTraits<DICTIONARY_ELEMENTS> > {
|
|
|
|
public:
|
|
|
|
explicit DictionaryElementsAccessor(const char* name)
|
|
|
|
: ElementsAccessorBase<DictionaryElementsAccessor,
|
|
|
|
ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {}
|
|
|
|
|
|
|
|
static void SetLengthImpl(Handle<JSArray> array, uint32_t length,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
|
|
|
Handle<SeededNumberDictionary> dict =
|
|
|
|
Handle<SeededNumberDictionary>::cast(backing_store);
|
|
|
|
Isolate* isolate = array->GetIsolate();
|
|
|
|
int capacity = dict->Capacity();
|
|
|
|
uint32_t old_length = 0;
|
|
|
|
CHECK(array->length()->ToArrayLength(&old_length));
|
|
|
|
if (length < old_length) {
|
|
|
|
if (dict->requires_slow_elements()) {
|
|
|
|
// Find last non-deletable element in range of elements to be
|
|
|
|
// deleted and adjust range accordingly.
|
2015-07-07 11:52:51 +00:00
|
|
|
for (int entry = 0; entry < capacity; entry++) {
|
2015-07-02 16:44:17 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2015-07-07 11:52:51 +00:00
|
|
|
Object* index = dict->KeyAt(entry);
|
|
|
|
if (index->IsNumber()) {
|
|
|
|
uint32_t number = static_cast<uint32_t>(index->Number());
|
2015-07-02 16:44:17 +00:00
|
|
|
if (length <= number && number < old_length) {
|
2015-07-07 11:52:51 +00:00
|
|
|
PropertyDetails details = dict->DetailsAt(entry);
|
2015-07-02 16:44:17 +00:00
|
|
|
if (!details.IsConfigurable()) length = number + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length == 0) {
|
|
|
|
// Flush the backing store.
|
|
|
|
JSObject::ResetElements(array);
|
|
|
|
} else {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
// Remove elements that should be deleted.
|
|
|
|
int removed_entries = 0;
|
|
|
|
Handle<Object> the_hole_value = isolate->factory()->the_hole_value();
|
2015-07-07 11:52:51 +00:00
|
|
|
for (int entry = 0; entry < capacity; entry++) {
|
|
|
|
Object* index = dict->KeyAt(entry);
|
|
|
|
if (index->IsNumber()) {
|
|
|
|
uint32_t number = static_cast<uint32_t>(index->Number());
|
2015-07-02 16:44:17 +00:00
|
|
|
if (length <= number && number < old_length) {
|
2015-07-07 11:52:51 +00:00
|
|
|
dict->SetEntry(entry, the_hole_value, the_hole_value);
|
2015-07-02 16:44:17 +00:00
|
|
|
removed_entries++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the number of elements.
|
|
|
|
dict->ElementsRemoved(removed_entries);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Object> length_obj = isolate->factory()->NewNumberFromUint(length);
|
|
|
|
array->set_length(*length_obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
|
|
|
|
FixedArrayBase* to, ElementsKind from_kind,
|
|
|
|
uint32_t to_start, int packed_size,
|
|
|
|
int copy_size) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static void DeleteImpl(Handle<JSObject> obj, uint32_t entry) {
|
|
|
|
// TODO(verwaest): Remove reliance on index in Shrink.
|
2015-07-06 08:53:41 +00:00
|
|
|
Handle<SeededNumberDictionary> dict(
|
|
|
|
SeededNumberDictionary::cast(obj->elements()));
|
2015-07-07 11:52:51 +00:00
|
|
|
uint32_t index = GetIndexForEntryImpl(*dict, entry);
|
|
|
|
Handle<Object> result = SeededNumberDictionary::DeleteProperty(dict, entry);
|
2015-07-06 08:53:41 +00:00
|
|
|
USE(result);
|
|
|
|
DCHECK(result->IsTrue());
|
2015-07-07 11:52:51 +00:00
|
|
|
Handle<FixedArray> new_elements =
|
|
|
|
SeededNumberDictionary::Shrink(dict, index);
|
2015-07-06 08:53:41 +00:00
|
|
|
obj->set_elements(*new_elements);
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 15:51:57 +00:00
|
|
|
static Object* GetRaw(FixedArrayBase* store, uint32_t entry) {
|
|
|
|
SeededNumberDictionary* backing_store = SeededNumberDictionary::cast(store);
|
|
|
|
return backing_store->ValueAt(entry);
|
|
|
|
}
|
|
|
|
|
2015-07-10 14:13:27 +00:00
|
|
|
static Handle<Object> GetImpl(Handle<FixedArrayBase> store, uint32_t entry) {
|
2015-07-10 15:51:57 +00:00
|
|
|
Isolate* isolate = store->GetIsolate();
|
|
|
|
return handle(GetRaw(*store, entry), isolate);
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 12:56:36 +00:00
|
|
|
static void SetImpl(FixedArrayBase* store, uint32_t entry, Object* value) {
|
2015-07-02 16:44:17 +00:00
|
|
|
SeededNumberDictionary* dictionary = SeededNumberDictionary::cast(store);
|
|
|
|
dictionary->ValueAtPut(entry, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReconfigureImpl(Handle<JSObject> object,
|
2015-07-07 11:52:51 +00:00
|
|
|
Handle<FixedArrayBase> store, uint32_t entry,
|
2015-07-02 16:44:17 +00:00
|
|
|
Handle<Object> value,
|
|
|
|
PropertyAttributes attributes) {
|
|
|
|
SeededNumberDictionary* dictionary = SeededNumberDictionary::cast(*store);
|
2015-07-15 12:06:20 +00:00
|
|
|
if (attributes != NONE) object->RequireSlowElements(dictionary);
|
2015-07-07 11:52:51 +00:00
|
|
|
dictionary->ValueAtPut(entry, *value);
|
|
|
|
PropertyDetails details = dictionary->DetailsAt(entry);
|
2015-07-02 16:44:17 +00:00
|
|
|
details = PropertyDetails(attributes, DATA, details.dictionary_index(),
|
|
|
|
PropertyCellType::kNoCell);
|
2015-07-07 11:52:51 +00:00
|
|
|
dictionary->DetailsAtPut(entry, details);
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 12:56:36 +00:00
|
|
|
static void AddImpl(Handle<JSObject> object, uint32_t index,
|
2015-07-02 16:44:17 +00:00
|
|
|
Handle<Object> value, PropertyAttributes attributes,
|
|
|
|
uint32_t new_capacity) {
|
|
|
|
PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell);
|
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
object->HasFastElements()
|
|
|
|
? JSObject::NormalizeElements(object)
|
|
|
|
: handle(SeededNumberDictionary::cast(object->elements()));
|
|
|
|
Handle<SeededNumberDictionary> new_dictionary =
|
2015-08-07 22:44:55 +00:00
|
|
|
SeededNumberDictionary::AddNumberEntry(
|
|
|
|
dictionary, index, value, details,
|
|
|
|
object->map()->is_prototype_map());
|
2015-07-15 12:06:20 +00:00
|
|
|
if (attributes != NONE) object->RequireSlowElements(*new_dictionary);
|
2015-07-02 16:44:17 +00:00
|
|
|
if (dictionary.is_identical_to(new_dictionary)) return;
|
|
|
|
object->set_elements(*new_dictionary);
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static bool HasEntryImpl(FixedArrayBase* store, uint32_t entry) {
|
2015-07-02 16:44:17 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
SeededNumberDictionary* dict = SeededNumberDictionary::cast(store);
|
2015-07-07 11:52:51 +00:00
|
|
|
Object* index = dict->KeyAt(entry);
|
|
|
|
return !index->IsTheHole();
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static uint32_t GetIndexForEntryImpl(FixedArrayBase* store, uint32_t entry) {
|
2015-07-02 16:44:17 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
SeededNumberDictionary* dict = SeededNumberDictionary::cast(store);
|
|
|
|
uint32_t result = 0;
|
2015-07-07 11:52:51 +00:00
|
|
|
CHECK(dict->KeyAt(entry)->ToArrayIndex(&result));
|
2015-07-02 16:44:17 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static uint32_t GetEntryForIndexImpl(JSObject* holder, FixedArrayBase* store,
|
|
|
|
uint32_t index) {
|
2015-07-02 16:44:17 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
SeededNumberDictionary* dict = SeededNumberDictionary::cast(store);
|
2015-07-07 11:52:51 +00:00
|
|
|
int entry = dict->FindEntry(index);
|
2015-07-02 16:44:17 +00:00
|
|
|
return entry == SeededNumberDictionary::kNotFound
|
|
|
|
? kMaxUInt32
|
|
|
|
: static_cast<uint32_t>(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store,
|
2015-07-07 11:52:51 +00:00
|
|
|
uint32_t entry) {
|
|
|
|
return SeededNumberDictionary::cast(backing_store)->DetailsAt(entry);
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-02 14:38:37 +00:00
|
|
|
|
2011-11-08 11:59:56 +00:00
|
|
|
// Super class for all fast element arrays.
|
|
|
|
template<typename FastElementsAccessorSubclass,
|
2014-08-05 11:16:11 +00:00
|
|
|
typename KindTraits>
|
2011-08-03 11:12:46 +00:00
|
|
|
class FastElementsAccessor
|
2012-03-09 13:48:29 +00:00
|
|
|
: public ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits> {
|
2012-03-06 12:03:14 +00:00
|
|
|
public:
|
|
|
|
explicit FastElementsAccessor(const char* name)
|
|
|
|
: ElementsAccessorBase<FastElementsAccessorSubclass,
|
2012-03-09 13:48:29 +00:00
|
|
|
KindTraits>(name) {}
|
2015-06-25 11:25:59 +00:00
|
|
|
|
2012-03-09 13:48:29 +00:00
|
|
|
typedef typename KindTraits::BackingStore BackingStore;
|
2011-11-08 11:59:56 +00:00
|
|
|
|
2015-07-07 16:02:30 +00:00
|
|
|
static void DeleteAtEnd(Handle<JSObject> obj,
|
|
|
|
Handle<BackingStore> backing_store, uint32_t entry) {
|
|
|
|
uint32_t length = static_cast<uint32_t>(backing_store->length());
|
|
|
|
Heap* heap = obj->GetHeap();
|
|
|
|
for (; entry > 0; entry--) {
|
|
|
|
if (!backing_store->is_the_hole(entry - 1)) break;
|
|
|
|
}
|
|
|
|
if (entry == 0) {
|
|
|
|
FixedArray* empty = heap->empty_fixed_array();
|
|
|
|
if (obj->HasFastArgumentsElements()) {
|
|
|
|
FixedArray::cast(obj->elements())->set(1, empty);
|
|
|
|
} else {
|
|
|
|
obj->set_elements(empty);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
heap->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(*backing_store,
|
|
|
|
length - entry);
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static void DeleteCommon(Handle<JSObject> obj, uint32_t entry,
|
2015-07-06 08:53:41 +00:00
|
|
|
Handle<FixedArrayBase> store) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(obj->HasFastSmiOrObjectElements() ||
|
2012-05-23 14:24:29 +00:00
|
|
|
obj->HasFastDoubleElements() ||
|
2011-09-22 11:30:04 +00:00
|
|
|
obj->HasFastArgumentsElements());
|
2015-07-06 08:53:41 +00:00
|
|
|
Handle<BackingStore> backing_store = Handle<BackingStore>::cast(store);
|
2015-07-07 16:02:30 +00:00
|
|
|
if (!obj->IsJSArray() &&
|
|
|
|
entry == static_cast<uint32_t>(store->length()) - 1) {
|
|
|
|
DeleteAtEnd(obj, backing_store, entry);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
backing_store->set_the_hole(entry);
|
2015-07-06 08:53:41 +00:00
|
|
|
|
|
|
|
// TODO(verwaest): Move this out of elements.cc.
|
|
|
|
// If an old space backing store is larger than a certain size and
|
|
|
|
// has too few used values, normalize it.
|
|
|
|
// To avoid doing the check on every delete we require at least
|
|
|
|
// one adjacent hole to the value being deleted.
|
|
|
|
const int kMinLengthForSparsenessCheck = 64;
|
|
|
|
if (backing_store->length() < kMinLengthForSparsenessCheck) return;
|
|
|
|
if (backing_store->GetHeap()->InNewSpace(*backing_store)) return;
|
|
|
|
uint32_t length = 0;
|
|
|
|
if (obj->IsJSArray()) {
|
|
|
|
JSArray::cast(*obj)->length()->ToArrayLength(&length);
|
|
|
|
} else {
|
|
|
|
length = static_cast<uint32_t>(store->length());
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
2015-07-07 11:52:51 +00:00
|
|
|
if ((entry > 0 && backing_store->is_the_hole(entry - 1)) ||
|
|
|
|
(entry + 1 < length && backing_store->is_the_hole(entry + 1))) {
|
2015-07-07 16:02:30 +00:00
|
|
|
if (!obj->IsJSArray()) {
|
|
|
|
uint32_t i;
|
|
|
|
for (i = entry + 1; i < length; i++) {
|
|
|
|
if (!backing_store->is_the_hole(i)) break;
|
|
|
|
}
|
|
|
|
if (i == length) {
|
|
|
|
DeleteAtEnd(obj, backing_store, entry);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-07-06 08:53:41 +00:00
|
|
|
int num_used = 0;
|
|
|
|
for (int i = 0; i < backing_store->length(); ++i) {
|
|
|
|
if (!backing_store->is_the_hole(i)) ++num_used;
|
|
|
|
// Bail out early if more than 1/4 is used.
|
|
|
|
if (4 * num_used > backing_store->length()) break;
|
2012-11-02 10:24:56 +00:00
|
|
|
}
|
2015-07-06 08:53:41 +00:00
|
|
|
if (4 * num_used <= backing_store->length()) {
|
|
|
|
JSObject::NormalizeElements(obj);
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-25 14:17:10 +00:00
|
|
|
static void ReconfigureImpl(Handle<JSObject> object,
|
2015-07-07 11:52:51 +00:00
|
|
|
Handle<FixedArrayBase> store, uint32_t entry,
|
2015-06-25 14:17:10 +00:00
|
|
|
Handle<Object> value,
|
|
|
|
PropertyAttributes attributes) {
|
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
JSObject::NormalizeElements(object);
|
2015-07-07 11:52:51 +00:00
|
|
|
entry = dictionary->FindEntry(entry);
|
|
|
|
DictionaryElementsAccessor::ReconfigureImpl(object, dictionary, entry,
|
2015-07-02 16:44:17 +00:00
|
|
|
value, attributes);
|
2015-06-25 14:17:10 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 12:56:36 +00:00
|
|
|
static void AddImpl(Handle<JSObject> object, uint32_t index,
|
2015-06-25 14:17:10 +00:00
|
|
|
Handle<Object> value, PropertyAttributes attributes,
|
|
|
|
uint32_t new_capacity) {
|
|
|
|
DCHECK_EQ(NONE, attributes);
|
|
|
|
ElementsKind from_kind = object->GetElementsKind();
|
|
|
|
ElementsKind to_kind = FastElementsAccessorSubclass::kind();
|
|
|
|
if (IsDictionaryElementsKind(from_kind) ||
|
|
|
|
IsFastDoubleElementsKind(from_kind) !=
|
|
|
|
IsFastDoubleElementsKind(to_kind) ||
|
|
|
|
FastElementsAccessorSubclass::GetCapacityImpl(
|
|
|
|
*object, object->elements()) != new_capacity) {
|
|
|
|
FastElementsAccessorSubclass::GrowCapacityAndConvertImpl(object,
|
|
|
|
new_capacity);
|
|
|
|
} else {
|
|
|
|
if (from_kind != to_kind) {
|
|
|
|
JSObject::TransitionElementsKind(object, to_kind);
|
|
|
|
}
|
|
|
|
if (IsFastSmiOrObjectElementsKind(from_kind)) {
|
|
|
|
DCHECK(IsFastSmiOrObjectElementsKind(to_kind));
|
|
|
|
JSObject::EnsureWritableFastElements(object);
|
|
|
|
}
|
|
|
|
}
|
2015-07-10 12:56:36 +00:00
|
|
|
FastElementsAccessorSubclass::SetImpl(object->elements(), index, *value);
|
2015-06-25 14:17:10 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static void DeleteImpl(Handle<JSObject> obj, uint32_t entry) {
|
2015-07-06 08:53:41 +00:00
|
|
|
ElementsKind kind = KindTraits::Kind;
|
|
|
|
if (IsFastPackedElementsKind(kind)) {
|
|
|
|
JSObject::TransitionElementsKind(obj, GetHoleyElementsKind(kind));
|
|
|
|
}
|
|
|
|
if (IsFastSmiOrObjectElementsKind(KindTraits::Kind)) {
|
|
|
|
JSObject::EnsureWritableFastElements(obj);
|
|
|
|
}
|
2015-07-07 11:52:51 +00:00
|
|
|
DeleteCommon(obj, entry, handle(obj->elements()));
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static bool HasEntryImpl(FixedArrayBase* backing_store, uint32_t entry) {
|
|
|
|
return !BackingStore::cast(backing_store)->is_the_hole(entry);
|
2015-06-02 10:42:16 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 06:18:37 +00:00
|
|
|
static void ValidateContents(Handle<JSObject> holder, int length) {
|
2012-05-23 14:24:29 +00:00
|
|
|
#if DEBUG
|
2014-04-16 06:18:37 +00:00
|
|
|
Isolate* isolate = holder->GetIsolate();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<FixedArrayBase> elements(holder->elements(), isolate);
|
2012-05-23 14:24:29 +00:00
|
|
|
Map* map = elements->map();
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK((IsFastSmiOrObjectElementsKind(KindTraits::Kind) &&
|
2014-04-16 06:18:37 +00:00
|
|
|
(map == isolate->heap()->fixed_array_map() ||
|
|
|
|
map == isolate->heap()->fixed_cow_array_map())) ||
|
2012-05-23 14:24:29 +00:00
|
|
|
(IsFastDoubleElementsKind(KindTraits::Kind) ==
|
2014-04-16 06:18:37 +00:00
|
|
|
((map == isolate->heap()->fixed_array_map() && length == 0) ||
|
|
|
|
map == isolate->heap()->fixed_double_array_map())));
|
2015-03-13 10:47:31 +00:00
|
|
|
if (length == 0) return; // nothing to do!
|
2014-04-16 06:18:37 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2015-03-13 10:47:31 +00:00
|
|
|
Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements);
|
2015-06-23 13:35:07 +00:00
|
|
|
if (IsFastSmiElementsKind(KindTraits::Kind)) {
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
DCHECK(BackingStore::get(backing_store, i)->IsSmi() ||
|
|
|
|
(IsFastHoleyElementsKind(KindTraits::Kind) &&
|
|
|
|
backing_store->is_the_hole(i)));
|
|
|
|
}
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2015-07-31 16:10:37 +00:00
|
|
|
|
|
|
|
static uint32_t PushImpl(Handle<JSArray> receiver,
|
|
|
|
Handle<FixedArrayBase> backing_store,
|
|
|
|
Object** objects, uint32_t push_size,
|
|
|
|
int direction) {
|
|
|
|
uint32_t len = Smi::cast(receiver->length())->value();
|
|
|
|
if (push_size == 0) {
|
|
|
|
return len;
|
|
|
|
}
|
2015-08-25 11:11:18 +00:00
|
|
|
uint32_t elms_len = backing_store->length();
|
2015-07-31 16:10:37 +00:00
|
|
|
// Currently fixed arrays cannot grow too big, so
|
|
|
|
// we should never hit this case.
|
|
|
|
DCHECK(push_size <= static_cast<uint32_t>(Smi::kMaxValue - len));
|
|
|
|
uint32_t new_length = len + push_size;
|
|
|
|
Handle<FixedArrayBase> new_elms;
|
|
|
|
|
2015-08-25 11:11:18 +00:00
|
|
|
if (new_length > elms_len) {
|
2015-07-31 16:10:37 +00:00
|
|
|
// New backing storage is needed.
|
|
|
|
uint32_t capacity = new_length + (new_length >> 1) + 16;
|
|
|
|
new_elms = FastElementsAccessorSubclass::ConvertElementsWithCapacity(
|
|
|
|
receiver, backing_store, KindTraits::Kind, capacity);
|
|
|
|
} else {
|
|
|
|
// push_size is > 0 and new_length <= elms_len, so backing_store cannot be
|
2015-08-27 13:05:50 +00:00
|
|
|
// the empty_fixed_array.
|
2015-07-31 16:10:37 +00:00
|
|
|
new_elms = backing_store;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the provided values.
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
DCHECK(direction == ElementsAccessor::kDirectionForward ||
|
|
|
|
direction == ElementsAccessor::kDirectionReverse);
|
|
|
|
STATIC_ASSERT(ElementsAccessor::kDirectionForward == 1);
|
|
|
|
STATIC_ASSERT(ElementsAccessor::kDirectionReverse == -1);
|
|
|
|
for (uint32_t index = 0; index < push_size; index++) {
|
|
|
|
int offset = direction * index;
|
|
|
|
Object* object = objects[offset];
|
|
|
|
FastElementsAccessorSubclass::SetImpl(*new_elms, index + len, object);
|
|
|
|
}
|
|
|
|
if (!new_elms.is_identical_to(backing_store)) {
|
|
|
|
receiver->set_elements(*new_elms);
|
|
|
|
}
|
|
|
|
DCHECK(*new_elms == receiver->elements());
|
|
|
|
// Set the length.
|
|
|
|
receiver->set_length(Smi::FromInt(new_length));
|
|
|
|
return new_length;
|
|
|
|
}
|
2015-08-27 13:05:50 +00:00
|
|
|
|
|
|
|
static void MoveElements(Heap* heap, Handle<FixedArrayBase> backing_store,
|
|
|
|
int dst_index, int src_index, int len,
|
|
|
|
int hole_start, int hole_end) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver,
|
|
|
|
Handle<FixedArrayBase> backing_store,
|
|
|
|
uint32_t start, uint32_t delete_count,
|
|
|
|
Arguments args, uint32_t add_count) {
|
|
|
|
Isolate* isolate = receiver->GetIsolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
const uint32_t len = Smi::cast(receiver->length())->value();
|
|
|
|
const uint32_t new_length = len - delete_count + add_count;
|
|
|
|
|
|
|
|
if (new_length == 0) {
|
|
|
|
receiver->set_elements(heap->empty_fixed_array());
|
|
|
|
receiver->set_length(Smi::FromInt(0));
|
|
|
|
return isolate->factory()->NewJSArrayWithElements(
|
|
|
|
backing_store, KindTraits::Kind, delete_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
// construct the result array which holds the deleted elements
|
|
|
|
Handle<JSArray> deleted_elements = isolate->factory()->NewJSArray(
|
|
|
|
KindTraits::Kind, delete_count, delete_count);
|
|
|
|
if (delete_count > 0) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
FastElementsAccessorSubclass::CopyElementsImpl(
|
|
|
|
*backing_store, start, deleted_elements->elements(), KindTraits::Kind,
|
|
|
|
0, kPackedSizeNotKnown, delete_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete and move elements to make space for add_count new elements
|
|
|
|
bool elms_changed = false;
|
|
|
|
if (add_count < delete_count) {
|
|
|
|
elms_changed = SpliceShrinkStep(backing_store, heap, start, delete_count,
|
|
|
|
add_count, len, new_length);
|
|
|
|
} else if (add_count > delete_count) {
|
|
|
|
elms_changed =
|
|
|
|
SpliceGrowStep(receiver, backing_store, isolate, heap, start,
|
|
|
|
delete_count, add_count, len, new_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy new Elements from args
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
for (uint32_t index = start; index < start + add_count; index++) {
|
|
|
|
Object* arg = args[3 + index - start];
|
|
|
|
FastElementsAccessorSubclass::SetImpl(*backing_store, index, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elms_changed) {
|
|
|
|
receiver->set_elements(*backing_store);
|
|
|
|
}
|
|
|
|
receiver->set_length(Smi::FromInt(new_length));
|
|
|
|
return deleted_elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool SpliceShrinkStep(Handle<FixedArrayBase>& backing_store,
|
|
|
|
Heap* heap, uint32_t start,
|
|
|
|
uint32_t delete_count, uint32_t add_count,
|
|
|
|
uint32_t len, uint32_t new_length) {
|
|
|
|
const int move_left_count = len - delete_count - start;
|
|
|
|
const int move_left_dst_index = start + add_count;
|
|
|
|
const bool left_trim_array = heap->CanMoveObjectStart(*backing_store) &&
|
|
|
|
(move_left_dst_index < move_left_count);
|
|
|
|
if (left_trim_array) {
|
|
|
|
const int delta = delete_count - add_count;
|
|
|
|
// shift from before the insertion point to the right
|
|
|
|
FastElementsAccessorSubclass::MoveElements(heap, backing_store, delta, 0,
|
|
|
|
start, 0, 0);
|
|
|
|
backing_store = handle(heap->LeftTrimFixedArray(*backing_store, delta));
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// No left-trim needed or possible (in this case we left-move and store
|
|
|
|
// the hole)
|
|
|
|
FastElementsAccessorSubclass::MoveElements(
|
|
|
|
heap, backing_store, move_left_dst_index, start + delete_count,
|
|
|
|
move_left_count, new_length, len);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool SpliceGrowStep(Handle<JSArray> receiver,
|
|
|
|
Handle<FixedArrayBase>& backing_store,
|
|
|
|
Isolate* isolate, Heap* heap, uint32_t start,
|
|
|
|
uint32_t delete_count, uint32_t add_count,
|
|
|
|
uint32_t len, uint32_t new_length) {
|
|
|
|
// Currently fixed arrays cannot grow too big, so
|
|
|
|
// we should never hit this case.
|
|
|
|
DCHECK((add_count - delete_count) <= (Smi::kMaxValue - len));
|
|
|
|
// Check if backing_store needs to grow.
|
|
|
|
if (new_length > static_cast<uint32_t>(backing_store->length())) {
|
|
|
|
// New backing storage is needed.
|
|
|
|
int capacity = new_length + (new_length >> 1) + 16;
|
|
|
|
// partially copy all elements up to start
|
|
|
|
Handle<FixedArrayBase> new_elms =
|
|
|
|
FastElementsAccessorSubclass::ConvertElementsWithCapacity(
|
|
|
|
receiver, backing_store, KindTraits::Kind, capacity, start);
|
|
|
|
// Copy the trailing elements after start + delete_count
|
|
|
|
FastElementsAccessorSubclass::CopyElementsImpl(
|
|
|
|
*backing_store, start + delete_count, *new_elms, KindTraits::Kind,
|
|
|
|
start + add_count, kPackedSizeNotKnown,
|
|
|
|
ElementsAccessor::kCopyToEndAndInitializeToHole);
|
|
|
|
|
|
|
|
backing_store = new_elms;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
FastElementsAccessorSubclass::MoveElements(
|
|
|
|
heap, backing_store, start + add_count, start + delete_count,
|
|
|
|
(len - delete_count - start), 0, 0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-23 14:24:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<typename FastElementsAccessorSubclass,
|
|
|
|
typename KindTraits>
|
|
|
|
class FastSmiOrObjectElementsAccessor
|
2014-08-05 11:16:11 +00:00
|
|
|
: public FastElementsAccessor<FastElementsAccessorSubclass, KindTraits> {
|
2012-05-23 14:24:29 +00:00
|
|
|
public:
|
|
|
|
explicit FastSmiOrObjectElementsAccessor(const char* name)
|
|
|
|
: FastElementsAccessor<FastElementsAccessorSubclass,
|
2014-08-05 11:16:11 +00:00
|
|
|
KindTraits>(name) {}
|
2012-05-23 14:24:29 +00:00
|
|
|
|
2015-07-10 15:51:57 +00:00
|
|
|
static Object* GetRaw(FixedArray* backing_store, uint32_t entry) {
|
|
|
|
uint32_t index = FastElementsAccessorSubclass::GetIndexForEntryImpl(
|
|
|
|
backing_store, entry);
|
|
|
|
return backing_store->get(index);
|
|
|
|
}
|
|
|
|
|
2015-08-27 13:05:50 +00:00
|
|
|
static void MoveElements(Heap* heap, Handle<FixedArrayBase> backing_store,
|
|
|
|
int dst_index, int src_index, int len,
|
|
|
|
int hole_start, int hole_end) {
|
|
|
|
Handle<FixedArray> dst_elms = Handle<FixedArray>::cast(backing_store);
|
|
|
|
if (len != 0) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
heap->MoveElements(*dst_elms, dst_index, src_index, len);
|
|
|
|
}
|
|
|
|
if (hole_start != hole_end) {
|
|
|
|
dst_elms->FillWithHoles(hole_start, hole_end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 08:22:24 +00:00
|
|
|
// NOTE: this method violates the handlified function signature convention:
|
|
|
|
// raw pointer parameters in the function that allocates.
|
|
|
|
// See ElementsAccessor::CopyElements() for details.
|
|
|
|
// This method could actually allocate if copying from double elements to
|
|
|
|
// object elements.
|
|
|
|
static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
|
|
|
|
FixedArrayBase* to, ElementsKind from_kind,
|
|
|
|
uint32_t to_start, int packed_size,
|
2014-03-27 16:41:09 +00:00
|
|
|
int copy_size) {
|
2014-09-29 08:22:24 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2013-01-02 10:09:42 +00:00
|
|
|
ElementsKind to_kind = KindTraits::Kind;
|
|
|
|
switch (from_kind) {
|
|
|
|
case FAST_SMI_ELEMENTS:
|
|
|
|
case FAST_HOLEY_SMI_ELEMENTS:
|
|
|
|
case FAST_ELEMENTS:
|
|
|
|
case FAST_HOLEY_ELEMENTS:
|
2014-09-29 08:22:24 +00:00
|
|
|
CopyObjectToObjectElements(from, from_kind, from_start, to, to_kind,
|
2014-07-25 13:00:06 +00:00
|
|
|
to_start, copy_size);
|
2014-03-27 16:41:09 +00:00
|
|
|
break;
|
2013-01-02 10:09:42 +00:00
|
|
|
case FAST_DOUBLE_ELEMENTS:
|
2014-09-29 08:22:24 +00:00
|
|
|
case FAST_HOLEY_DOUBLE_ELEMENTS: {
|
|
|
|
AllowHeapAllocation allow_allocation;
|
2014-03-27 16:41:09 +00:00
|
|
|
CopyDoubleToObjectElements(
|
2013-01-02 10:09:42 +00:00
|
|
|
from, from_start, to, to_kind, to_start, copy_size);
|
2014-03-27 16:41:09 +00:00
|
|
|
break;
|
2014-09-29 08:22:24 +00:00
|
|
|
}
|
2013-01-02 10:09:42 +00:00
|
|
|
case DICTIONARY_ELEMENTS:
|
2014-09-29 08:22:24 +00:00
|
|
|
CopyDictionaryToObjectElements(from, from_start, to, to_kind, to_start,
|
|
|
|
copy_size);
|
2014-03-27 16:41:09 +00:00
|
|
|
break;
|
2015-07-02 14:38:37 +00:00
|
|
|
case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
|
|
|
|
case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
|
|
|
|
UNREACHABLE();
|
2014-01-24 16:01:15 +00:00
|
|
|
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
|
|
|
|
case TYPE##_ELEMENTS: \
|
2013-01-02 10:09:42 +00:00
|
|
|
UNREACHABLE();
|
2014-01-24 16:01:15 +00:00
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_CASE)
|
|
|
|
#undef TYPED_ARRAY_CASE
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-23 14:24:29 +00:00
|
|
|
};
|
2011-11-08 11:59:56 +00:00
|
|
|
|
2011-12-09 08:50:19 +00:00
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
class FastPackedSmiElementsAccessor
|
|
|
|
: public FastSmiOrObjectElementsAccessor<
|
|
|
|
FastPackedSmiElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_SMI_ELEMENTS> > {
|
|
|
|
public:
|
|
|
|
explicit FastPackedSmiElementsAccessor(const char* name)
|
|
|
|
: FastSmiOrObjectElementsAccessor<
|
|
|
|
FastPackedSmiElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_SMI_ELEMENTS> >(name) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FastHoleySmiElementsAccessor
|
|
|
|
: public FastSmiOrObjectElementsAccessor<
|
|
|
|
FastHoleySmiElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_HOLEY_SMI_ELEMENTS> > {
|
|
|
|
public:
|
|
|
|
explicit FastHoleySmiElementsAccessor(const char* name)
|
|
|
|
: FastSmiOrObjectElementsAccessor<
|
|
|
|
FastHoleySmiElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_HOLEY_SMI_ELEMENTS> >(name) {}
|
2011-08-03 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
class FastPackedObjectElementsAccessor
|
|
|
|
: public FastSmiOrObjectElementsAccessor<
|
|
|
|
FastPackedObjectElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_ELEMENTS> > {
|
|
|
|
public:
|
|
|
|
explicit FastPackedObjectElementsAccessor(const char* name)
|
|
|
|
: FastSmiOrObjectElementsAccessor<
|
|
|
|
FastPackedObjectElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_ELEMENTS> >(name) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FastHoleyObjectElementsAccessor
|
|
|
|
: public FastSmiOrObjectElementsAccessor<
|
|
|
|
FastHoleyObjectElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_HOLEY_ELEMENTS> > {
|
|
|
|
public:
|
|
|
|
explicit FastHoleyObjectElementsAccessor(const char* name)
|
|
|
|
: FastSmiOrObjectElementsAccessor<
|
|
|
|
FastHoleyObjectElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_HOLEY_ELEMENTS> >(name) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<typename FastElementsAccessorSubclass,
|
|
|
|
typename KindTraits>
|
2011-08-03 11:12:46 +00:00
|
|
|
class FastDoubleElementsAccessor
|
2014-08-05 11:16:11 +00:00
|
|
|
: public FastElementsAccessor<FastElementsAccessorSubclass, KindTraits> {
|
2012-03-06 12:03:14 +00:00
|
|
|
public:
|
|
|
|
explicit FastDoubleElementsAccessor(const char* name)
|
2012-05-23 14:24:29 +00:00
|
|
|
: FastElementsAccessor<FastElementsAccessorSubclass,
|
2014-08-05 11:16:11 +00:00
|
|
|
KindTraits>(name) {}
|
2012-03-06 12:03:14 +00:00
|
|
|
|
2015-08-27 13:05:50 +00:00
|
|
|
static void MoveElements(Heap* heap, Handle<FixedArrayBase> backing_store,
|
|
|
|
int dst_index, int src_index, int len,
|
|
|
|
int hole_start, int hole_end) {
|
|
|
|
Handle<FixedDoubleArray> dst_elms =
|
|
|
|
Handle<FixedDoubleArray>::cast(backing_store);
|
|
|
|
if (len != 0) {
|
|
|
|
MemMove(dst_elms->data_start() + dst_index,
|
|
|
|
dst_elms->data_start() + src_index, len * kDoubleSize);
|
|
|
|
}
|
|
|
|
if (hole_start != hole_end) {
|
|
|
|
dst_elms->FillWithHoles(hole_start, hole_end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 08:22:24 +00:00
|
|
|
static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
|
|
|
|
FixedArrayBase* to, ElementsKind from_kind,
|
|
|
|
uint32_t to_start, int packed_size,
|
2014-03-27 16:41:09 +00:00
|
|
|
int copy_size) {
|
2014-09-29 08:22:24 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2013-01-02 10:09:42 +00:00
|
|
|
switch (from_kind) {
|
2012-05-23 14:24:29 +00:00
|
|
|
case FAST_SMI_ELEMENTS:
|
2014-09-29 08:22:24 +00:00
|
|
|
CopyPackedSmiToDoubleElements(from, from_start, to, to_start,
|
2014-07-25 13:00:06 +00:00
|
|
|
packed_size, copy_size);
|
2013-01-02 10:09:42 +00:00
|
|
|
break;
|
2012-05-23 14:24:29 +00:00
|
|
|
case FAST_HOLEY_SMI_ELEMENTS:
|
2014-09-29 08:22:24 +00:00
|
|
|
CopySmiToDoubleElements(from, from_start, to, to_start, copy_size);
|
2013-01-02 10:09:42 +00:00
|
|
|
break;
|
2012-03-09 13:48:29 +00:00
|
|
|
case FAST_DOUBLE_ELEMENTS:
|
2012-05-23 14:24:29 +00:00
|
|
|
case FAST_HOLEY_DOUBLE_ELEMENTS:
|
2014-09-29 08:22:24 +00:00
|
|
|
CopyDoubleToDoubleElements(from, from_start, to, to_start, copy_size);
|
2013-01-02 10:09:42 +00:00
|
|
|
break;
|
|
|
|
case FAST_ELEMENTS:
|
|
|
|
case FAST_HOLEY_ELEMENTS:
|
2014-09-29 08:22:24 +00:00
|
|
|
CopyObjectToDoubleElements(from, from_start, to, to_start, copy_size);
|
2013-01-02 10:09:42 +00:00
|
|
|
break;
|
|
|
|
case DICTIONARY_ELEMENTS:
|
2014-09-29 08:22:24 +00:00
|
|
|
CopyDictionaryToDoubleElements(from, from_start, to, to_start,
|
2014-07-25 13:00:06 +00:00
|
|
|
copy_size);
|
2013-01-02 10:09:42 +00:00
|
|
|
break;
|
2015-07-02 14:38:37 +00:00
|
|
|
case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
|
|
|
|
case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
|
2012-03-09 13:48:29 +00:00
|
|
|
UNREACHABLE();
|
2014-01-24 16:01:15 +00:00
|
|
|
|
|
|
|
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
|
|
|
|
case TYPE##_ELEMENTS: \
|
|
|
|
UNREACHABLE();
|
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_CASE)
|
|
|
|
#undef TYPED_ARRAY_CASE
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-23 14:24:29 +00:00
|
|
|
};
|
2012-03-09 13:48:29 +00:00
|
|
|
|
2011-08-17 16:15:30 +00:00
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
class FastPackedDoubleElementsAccessor
|
|
|
|
: public FastDoubleElementsAccessor<
|
|
|
|
FastPackedDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_DOUBLE_ELEMENTS> > {
|
|
|
|
public:
|
|
|
|
explicit FastPackedDoubleElementsAccessor(const char* name)
|
|
|
|
: FastDoubleElementsAccessor<
|
|
|
|
FastPackedDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_DOUBLE_ELEMENTS> >(name) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FastHoleyDoubleElementsAccessor
|
|
|
|
: public FastDoubleElementsAccessor<
|
|
|
|
FastHoleyDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_HOLEY_DOUBLE_ELEMENTS> > {
|
|
|
|
public:
|
|
|
|
explicit FastHoleyDoubleElementsAccessor(const char* name)
|
|
|
|
: FastDoubleElementsAccessor<
|
|
|
|
FastHoleyDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_HOLEY_DOUBLE_ELEMENTS> >(name) {}
|
2011-08-03 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Super class for all external element arrays.
|
2014-01-24 16:01:15 +00:00
|
|
|
template<ElementsKind Kind>
|
2014-01-16 17:08:45 +00:00
|
|
|
class TypedElementsAccessor
|
2014-01-24 16:01:15 +00:00
|
|
|
: public ElementsAccessorBase<TypedElementsAccessor<Kind>,
|
2012-03-09 13:48:29 +00:00
|
|
|
ElementsKindTraits<Kind> > {
|
2012-03-06 12:03:14 +00:00
|
|
|
public:
|
2014-01-16 17:08:45 +00:00
|
|
|
explicit TypedElementsAccessor(const char* name)
|
2014-01-24 16:01:15 +00:00
|
|
|
: ElementsAccessorBase<AccessorClass,
|
2012-03-09 13:48:29 +00:00
|
|
|
ElementsKindTraits<Kind> >(name) {}
|
2012-03-06 12:03:14 +00:00
|
|
|
|
2012-03-09 13:48:29 +00:00
|
|
|
typedef typename ElementsKindTraits<Kind>::BackingStore BackingStore;
|
2014-01-24 16:01:15 +00:00
|
|
|
typedef TypedElementsAccessor<Kind> AccessorClass;
|
2012-03-09 13:48:29 +00:00
|
|
|
|
2015-07-10 14:13:27 +00:00
|
|
|
static Handle<Object> GetImpl(Handle<FixedArrayBase> backing_store,
|
|
|
|
uint32_t entry) {
|
|
|
|
uint32_t index = GetIndexForEntryImpl(*backing_store, entry);
|
|
|
|
return BackingStore::get(Handle<BackingStore>::cast(backing_store), index);
|
2011-08-03 11:12:46 +00:00
|
|
|
}
|
2011-08-04 11:42:14 +00:00
|
|
|
|
2015-06-11 15:07:00 +00:00
|
|
|
static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store,
|
2015-07-07 11:52:51 +00:00
|
|
|
uint32_t entry) {
|
2015-06-11 15:07:00 +00:00
|
|
|
return PropertyDetails(DONT_DELETE, DATA, 0, PropertyCellType::kNoCell);
|
2012-11-15 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 14:56:57 +00:00
|
|
|
static void SetLengthImpl(Handle<JSArray> array, uint32_t length,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2011-11-08 11:59:56 +00:00
|
|
|
// External arrays do not support changing their length.
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static void DeleteImpl(Handle<JSObject> obj, uint32_t entry) {
|
2015-07-06 08:53:41 +00:00
|
|
|
UNREACHABLE();
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
2012-03-05 16:14:34 +00:00
|
|
|
|
2015-07-10 14:13:27 +00:00
|
|
|
static uint32_t GetIndexForEntryImpl(FixedArrayBase* backing_store,
|
|
|
|
uint32_t entry) {
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static uint32_t GetEntryForIndexImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store,
|
|
|
|
uint32_t index) {
|
|
|
|
return index < AccessorClass::GetCapacityImpl(holder, backing_store)
|
|
|
|
? index
|
2015-06-11 20:17:25 +00:00
|
|
|
: kMaxUInt32;
|
2012-03-05 16:14:34 +00:00
|
|
|
}
|
2015-04-27 09:28:16 +00:00
|
|
|
|
2015-05-21 12:19:39 +00:00
|
|
|
static uint32_t GetCapacityImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store) {
|
|
|
|
JSArrayBufferView* view = JSArrayBufferView::cast(holder);
|
2015-04-27 09:28:16 +00:00
|
|
|
if (view->WasNeutered()) return 0;
|
|
|
|
return backing_store->length();
|
|
|
|
}
|
2011-08-03 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-24 16:01:15 +00:00
|
|
|
#define FIXED_ELEMENTS_ACCESSOR(Type, type, TYPE, ctype, size) \
|
|
|
|
typedef TypedElementsAccessor<TYPE##_ELEMENTS > \
|
|
|
|
Fixed##Type##ElementsAccessor;
|
2011-08-03 11:12:46 +00:00
|
|
|
|
2014-01-24 16:01:15 +00:00
|
|
|
TYPED_ARRAYS(FIXED_ELEMENTS_ACCESSOR)
|
|
|
|
#undef FIXED_ELEMENTS_ACCESSOR
|
2011-08-03 11:12:46 +00:00
|
|
|
|
|
|
|
|
2015-07-02 16:44:17 +00:00
|
|
|
template <typename SloppyArgumentsElementsAccessorSubclass,
|
|
|
|
typename ArgumentsAccessor, typename KindTraits>
|
|
|
|
class SloppyArgumentsElementsAccessor
|
|
|
|
: public ElementsAccessorBase<SloppyArgumentsElementsAccessorSubclass,
|
|
|
|
KindTraits> {
|
|
|
|
public:
|
|
|
|
explicit SloppyArgumentsElementsAccessor(const char* name)
|
|
|
|
: ElementsAccessorBase<SloppyArgumentsElementsAccessorSubclass,
|
2015-07-10 14:13:27 +00:00
|
|
|
KindTraits>(name) {
|
|
|
|
USE(KindTraits::Kind);
|
|
|
|
}
|
2015-07-02 14:38:37 +00:00
|
|
|
|
2015-07-10 14:13:27 +00:00
|
|
|
static Handle<Object> GetImpl(Handle<FixedArrayBase> parameters,
|
|
|
|
uint32_t entry) {
|
|
|
|
Isolate* isolate = parameters->GetIsolate();
|
2015-07-02 16:44:17 +00:00
|
|
|
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters);
|
2015-07-10 14:13:27 +00:00
|
|
|
uint32_t length = parameter_map->length() - 2;
|
|
|
|
if (entry < length) {
|
2015-07-02 16:44:17 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2015-07-10 14:13:27 +00:00
|
|
|
Object* probe = parameter_map->get(entry + 2);
|
2015-07-02 16:44:17 +00:00
|
|
|
Context* context = Context::cast(parameter_map->get(0));
|
2015-07-10 14:13:27 +00:00
|
|
|
int context_entry = Smi::cast(probe)->value();
|
2015-07-07 11:52:51 +00:00
|
|
|
DCHECK(!context->get(context_entry)->IsTheHole());
|
|
|
|
return handle(context->get(context_entry), isolate);
|
2015-07-02 16:44:17 +00:00
|
|
|
} else {
|
|
|
|
// Object is not mapped, defer to the arguments.
|
|
|
|
Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)),
|
|
|
|
isolate);
|
2015-07-10 14:13:27 +00:00
|
|
|
Handle<Object> result =
|
|
|
|
ArgumentsAccessor::GetImpl(arguments, entry - length);
|
2015-07-02 16:44:17 +00:00
|
|
|
// Elements of the arguments object in slow mode might be slow aliases.
|
|
|
|
if (result->IsAliasedArgumentsEntry()) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
2015-07-10 15:51:57 +00:00
|
|
|
AliasedArgumentsEntry* alias = AliasedArgumentsEntry::cast(*result);
|
2015-07-02 16:44:17 +00:00
|
|
|
Context* context = Context::cast(parameter_map->get(0));
|
2015-07-10 15:51:57 +00:00
|
|
|
int context_entry = alias->aliased_context_slot();
|
2015-07-07 11:52:51 +00:00
|
|
|
DCHECK(!context->get(context_entry)->IsTheHole());
|
|
|
|
return handle(context->get(context_entry), isolate);
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
2015-07-10 14:13:27 +00:00
|
|
|
return result;
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-03 11:12:46 +00:00
|
|
|
|
2015-06-23 09:44:15 +00:00
|
|
|
static void GrowCapacityAndConvertImpl(Handle<JSObject> object,
|
|
|
|
uint32_t capacity) {
|
2015-07-02 14:38:37 +00:00
|
|
|
UNREACHABLE();
|
2015-06-23 09:44:15 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 12:56:36 +00:00
|
|
|
static void SetImpl(FixedArrayBase* store, uint32_t entry, Object* value) {
|
2015-06-19 09:25:16 +00:00
|
|
|
FixedArray* parameter_map = FixedArray::cast(store);
|
2015-07-10 12:56:36 +00:00
|
|
|
uint32_t length = parameter_map->length() - 2;
|
|
|
|
if (entry < length) {
|
|
|
|
Object* probe = parameter_map->get(entry + 2);
|
2015-06-11 15:07:00 +00:00
|
|
|
Context* context = Context::cast(parameter_map->get(0));
|
2015-07-07 11:52:51 +00:00
|
|
|
int context_entry = Smi::cast(probe)->value();
|
|
|
|
DCHECK(!context->get(context_entry)->IsTheHole());
|
|
|
|
context->set(context_entry, value);
|
2015-06-18 12:51:49 +00:00
|
|
|
} else {
|
2015-06-19 09:25:16 +00:00
|
|
|
FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
|
2015-07-10 15:51:57 +00:00
|
|
|
Object* current = ArgumentsAccessor::GetRaw(arguments, entry - length);
|
|
|
|
if (current->IsAliasedArgumentsEntry()) {
|
|
|
|
AliasedArgumentsEntry* alias = AliasedArgumentsEntry::cast(current);
|
|
|
|
Context* context = Context::cast(parameter_map->get(0));
|
|
|
|
int context_entry = alias->aliased_context_slot();
|
|
|
|
DCHECK(!context->get(context_entry)->IsTheHole());
|
|
|
|
context->set(context_entry, value);
|
|
|
|
} else {
|
|
|
|
ArgumentsAccessor::SetImpl(arguments, entry - length, value);
|
|
|
|
}
|
2015-06-11 15:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 14:56:57 +00:00
|
|
|
static void SetLengthImpl(Handle<JSArray> array, uint32_t length,
|
|
|
|
Handle<FixedArrayBase> parameter_map) {
|
|
|
|
// Sloppy arguments objects are not arrays.
|
|
|
|
UNREACHABLE();
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 12:19:39 +00:00
|
|
|
static uint32_t GetCapacityImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store) {
|
|
|
|
FixedArray* parameter_map = FixedArray::cast(backing_store);
|
|
|
|
FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1));
|
2015-06-02 10:42:16 +00:00
|
|
|
return parameter_map->length() - 2 +
|
2015-07-02 14:38:37 +00:00
|
|
|
ArgumentsAccessor::GetCapacityImpl(holder, arguments);
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static bool HasEntryImpl(FixedArrayBase* parameters, uint32_t entry) {
|
2015-06-02 10:42:16 +00:00
|
|
|
FixedArray* parameter_map = FixedArray::cast(parameters);
|
|
|
|
uint32_t length = parameter_map->length() - 2;
|
2015-07-07 11:52:51 +00:00
|
|
|
if (entry < length) {
|
|
|
|
return !GetParameterMapArg(parameter_map, entry)->IsTheHole();
|
2015-06-02 10:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1));
|
2015-07-07 11:52:51 +00:00
|
|
|
return ArgumentsAccessor::HasEntryImpl(arguments, entry - length);
|
2011-08-17 16:15:30 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static uint32_t GetIndexForEntryImpl(FixedArrayBase* parameters,
|
|
|
|
uint32_t entry) {
|
2015-06-02 10:42:16 +00:00
|
|
|
FixedArray* parameter_map = FixedArray::cast(parameters);
|
|
|
|
uint32_t length = parameter_map->length() - 2;
|
2015-07-07 11:52:51 +00:00
|
|
|
if (entry < length) return entry;
|
2015-06-02 10:42:16 +00:00
|
|
|
|
|
|
|
FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
|
2015-07-07 11:52:51 +00:00
|
|
|
return ArgumentsAccessor::GetIndexForEntryImpl(arguments, entry - length);
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static uint32_t GetEntryForIndexImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* parameters,
|
|
|
|
uint32_t index) {
|
2015-06-02 10:42:16 +00:00
|
|
|
FixedArray* parameter_map = FixedArray::cast(parameters);
|
2015-07-07 11:52:51 +00:00
|
|
|
Object* probe = GetParameterMapArg(parameter_map, index);
|
|
|
|
if (!probe->IsTheHole()) return index;
|
2015-06-02 10:42:16 +00:00
|
|
|
|
|
|
|
FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
|
2015-07-07 11:52:51 +00:00
|
|
|
uint32_t entry =
|
|
|
|
ArgumentsAccessor::GetEntryForIndexImpl(holder, arguments, index);
|
|
|
|
if (entry == kMaxUInt32) return entry;
|
|
|
|
return (parameter_map->length() - 2) + entry;
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static PropertyDetails GetDetailsImpl(FixedArrayBase* parameters,
|
2015-07-07 11:52:51 +00:00
|
|
|
uint32_t entry) {
|
2015-06-02 10:42:16 +00:00
|
|
|
FixedArray* parameter_map = FixedArray::cast(parameters);
|
|
|
|
uint32_t length = parameter_map->length() - 2;
|
2015-07-07 11:52:51 +00:00
|
|
|
if (entry < length) {
|
2015-06-02 10:42:16 +00:00
|
|
|
return PropertyDetails(NONE, DATA, 0, PropertyCellType::kNoCell);
|
|
|
|
}
|
|
|
|
FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
|
2015-07-10 12:56:36 +00:00
|
|
|
return ArgumentsAccessor::GetDetailsImpl(arguments, entry - length);
|
2015-06-02 10:42:16 +00:00
|
|
|
}
|
2015-05-21 12:19:39 +00:00
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static Object* GetParameterMapArg(FixedArray* parameter_map, uint32_t index) {
|
2015-06-02 10:42:16 +00:00
|
|
|
uint32_t length = parameter_map->length() - 2;
|
2015-07-07 11:52:51 +00:00
|
|
|
return index < length
|
|
|
|
? parameter_map->get(index + 2)
|
2015-06-02 10:42:16 +00:00
|
|
|
: Object::cast(parameter_map->GetHeap()->the_hole_value());
|
2014-03-20 10:52:22 +00:00
|
|
|
}
|
2015-07-06 08:53:41 +00:00
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static void DeleteImpl(Handle<JSObject> obj, uint32_t entry) {
|
2015-07-06 08:53:41 +00:00
|
|
|
FixedArray* parameter_map = FixedArray::cast(obj->elements());
|
|
|
|
uint32_t length = static_cast<uint32_t>(parameter_map->length()) - 2;
|
2015-07-07 11:52:51 +00:00
|
|
|
if (entry < length) {
|
2015-07-06 08:53:41 +00:00
|
|
|
// TODO(kmillikin): We could check if this was the last aliased
|
|
|
|
// parameter, and revert to normal elements in that case. That
|
|
|
|
// would enable GC of the context.
|
2015-07-07 11:52:51 +00:00
|
|
|
parameter_map->set_the_hole(entry + 2);
|
2015-07-06 08:53:41 +00:00
|
|
|
} else {
|
|
|
|
SloppyArgumentsElementsAccessorSubclass::DeleteFromArguments(
|
2015-07-07 11:52:51 +00:00
|
|
|
obj, entry - length);
|
2015-07-06 08:53:41 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-03 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-02 16:44:17 +00:00
|
|
|
class SlowSloppyArgumentsElementsAccessor
|
|
|
|
: public SloppyArgumentsElementsAccessor<
|
|
|
|
SlowSloppyArgumentsElementsAccessor, DictionaryElementsAccessor,
|
|
|
|
ElementsKindTraits<SLOW_SLOPPY_ARGUMENTS_ELEMENTS> > {
|
|
|
|
public:
|
|
|
|
explicit SlowSloppyArgumentsElementsAccessor(const char* name)
|
|
|
|
: SloppyArgumentsElementsAccessor<
|
|
|
|
SlowSloppyArgumentsElementsAccessor, DictionaryElementsAccessor,
|
|
|
|
ElementsKindTraits<SLOW_SLOPPY_ARGUMENTS_ELEMENTS> >(name) {}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static void DeleteFromArguments(Handle<JSObject> obj, uint32_t entry) {
|
2015-07-06 08:53:41 +00:00
|
|
|
Handle<FixedArray> parameter_map(FixedArray::cast(obj->elements()));
|
|
|
|
Handle<SeededNumberDictionary> dict(
|
|
|
|
SeededNumberDictionary::cast(parameter_map->get(1)));
|
2015-07-07 11:52:51 +00:00
|
|
|
// TODO(verwaest): Remove reliance on index in Shrink.
|
|
|
|
uint32_t index = GetIndexForEntryImpl(*dict, entry);
|
|
|
|
Handle<Object> result = SeededNumberDictionary::DeleteProperty(dict, entry);
|
2015-07-06 08:53:41 +00:00
|
|
|
USE(result);
|
|
|
|
DCHECK(result->IsTrue());
|
2015-07-07 11:52:51 +00:00
|
|
|
Handle<FixedArray> new_elements =
|
|
|
|
SeededNumberDictionary::Shrink(dict, index);
|
2015-07-06 08:53:41 +00:00
|
|
|
parameter_map->set(1, *new_elements);
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static void AddImpl(Handle<JSObject> object, uint32_t index,
|
2015-07-02 16:44:17 +00:00
|
|
|
Handle<Object> value, PropertyAttributes attributes,
|
|
|
|
uint32_t new_capacity) {
|
|
|
|
Handle<FixedArray> parameter_map(FixedArray::cast(object->elements()));
|
|
|
|
Handle<FixedArrayBase> old_elements(
|
|
|
|
FixedArrayBase::cast(parameter_map->get(1)));
|
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
old_elements->IsSeededNumberDictionary()
|
|
|
|
? Handle<SeededNumberDictionary>::cast(old_elements)
|
|
|
|
: JSObject::NormalizeElements(object);
|
|
|
|
PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell);
|
|
|
|
Handle<SeededNumberDictionary> new_dictionary =
|
2015-08-07 22:44:55 +00:00
|
|
|
SeededNumberDictionary::AddNumberEntry(
|
|
|
|
dictionary, index, value, details,
|
|
|
|
object->map()->is_prototype_map());
|
2015-07-15 12:06:20 +00:00
|
|
|
if (attributes != NONE) object->RequireSlowElements(*new_dictionary);
|
2015-07-02 16:44:17 +00:00
|
|
|
if (*dictionary != *new_dictionary) {
|
|
|
|
FixedArray::cast(object->elements())->set(1, *new_dictionary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReconfigureImpl(Handle<JSObject> object,
|
2015-07-07 11:52:51 +00:00
|
|
|
Handle<FixedArrayBase> store, uint32_t entry,
|
2015-07-02 16:44:17 +00:00
|
|
|
Handle<Object> value,
|
|
|
|
PropertyAttributes attributes) {
|
|
|
|
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(store);
|
|
|
|
uint32_t length = parameter_map->length() - 2;
|
2015-07-07 11:52:51 +00:00
|
|
|
if (entry < length) {
|
|
|
|
Object* probe = parameter_map->get(entry + 2);
|
2015-07-02 16:44:17 +00:00
|
|
|
DCHECK(!probe->IsTheHole());
|
|
|
|
Context* context = Context::cast(parameter_map->get(0));
|
2015-07-07 11:52:51 +00:00
|
|
|
int context_entry = Smi::cast(probe)->value();
|
|
|
|
DCHECK(!context->get(context_entry)->IsTheHole());
|
|
|
|
context->set(context_entry, *value);
|
2015-07-02 16:44:17 +00:00
|
|
|
|
|
|
|
// Redefining attributes of an aliased element destroys fast aliasing.
|
2015-07-07 11:52:51 +00:00
|
|
|
parameter_map->set_the_hole(entry + 2);
|
2015-07-02 16:44:17 +00:00
|
|
|
// For elements that are still writable we re-establish slow aliasing.
|
|
|
|
if ((attributes & READ_ONLY) == 0) {
|
|
|
|
Isolate* isolate = store->GetIsolate();
|
2015-07-07 11:52:51 +00:00
|
|
|
value = isolate->factory()->NewAliasedArgumentsEntry(context_entry);
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell);
|
|
|
|
Handle<SeededNumberDictionary> arguments(
|
|
|
|
SeededNumberDictionary::cast(parameter_map->get(1)));
|
2015-08-07 22:44:55 +00:00
|
|
|
arguments = SeededNumberDictionary::AddNumberEntry(
|
|
|
|
arguments, entry, value, details, object->map()->is_prototype_map());
|
2015-07-15 12:06:20 +00:00
|
|
|
// If the attributes were NONE, we would have called set rather than
|
|
|
|
// reconfigure.
|
|
|
|
DCHECK_NE(NONE, attributes);
|
|
|
|
object->RequireSlowElements(*arguments);
|
2015-07-02 16:44:17 +00:00
|
|
|
parameter_map->set(1, *arguments);
|
|
|
|
} else {
|
|
|
|
Handle<FixedArrayBase> arguments(
|
|
|
|
FixedArrayBase::cast(parameter_map->get(1)));
|
|
|
|
DictionaryElementsAccessor::ReconfigureImpl(
|
2015-07-07 11:52:51 +00:00
|
|
|
object, arguments, entry - length, value, attributes);
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-02 14:38:37 +00:00
|
|
|
class FastSloppyArgumentsElementsAccessor
|
|
|
|
: public SloppyArgumentsElementsAccessor<
|
|
|
|
FastSloppyArgumentsElementsAccessor, FastHoleyObjectElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_SLOPPY_ARGUMENTS_ELEMENTS> > {
|
|
|
|
public:
|
|
|
|
explicit FastSloppyArgumentsElementsAccessor(const char* name)
|
|
|
|
: SloppyArgumentsElementsAccessor<
|
|
|
|
FastSloppyArgumentsElementsAccessor,
|
|
|
|
FastHoleyObjectElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_SLOPPY_ARGUMENTS_ELEMENTS> >(name) {}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static void DeleteFromArguments(Handle<JSObject> obj, uint32_t entry) {
|
2015-07-06 08:53:41 +00:00
|
|
|
FixedArray* parameter_map = FixedArray::cast(obj->elements());
|
|
|
|
Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
|
2015-07-07 11:52:51 +00:00
|
|
|
FastHoleyObjectElementsAccessor::DeleteCommon(obj, entry, arguments);
|
2015-07-06 08:53:41 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static void AddImpl(Handle<JSObject> object, uint32_t index,
|
2015-07-02 14:38:37 +00:00
|
|
|
Handle<Object> value, PropertyAttributes attributes,
|
|
|
|
uint32_t new_capacity) {
|
|
|
|
DCHECK_EQ(NONE, attributes);
|
|
|
|
Handle<FixedArray> parameter_map(FixedArray::cast(object->elements()));
|
|
|
|
Handle<FixedArrayBase> old_elements(
|
|
|
|
FixedArrayBase::cast(parameter_map->get(1)));
|
|
|
|
if (old_elements->IsSeededNumberDictionary() ||
|
|
|
|
static_cast<uint32_t>(old_elements->length()) < new_capacity) {
|
|
|
|
GrowCapacityAndConvertImpl(object, new_capacity);
|
|
|
|
}
|
2015-07-10 12:56:36 +00:00
|
|
|
FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
|
|
|
|
// For fast holey objects, the entry equals the index. The code above made
|
|
|
|
// sure that there's enough space to store the value. We cannot convert
|
|
|
|
// index to entry explicitly since the slot still contains the hole, so the
|
|
|
|
// current EntryForIndex would indicate that it is "absent" by returning
|
|
|
|
// kMaxUInt32.
|
|
|
|
FastHoleyObjectElementsAccessor::SetImpl(arguments, index, *value);
|
2015-07-02 14:38:37 +00:00
|
|
|
}
|
2015-05-21 12:19:39 +00:00
|
|
|
|
2015-07-02 14:38:37 +00:00
|
|
|
static void ReconfigureImpl(Handle<JSObject> object,
|
2015-07-07 11:52:51 +00:00
|
|
|
Handle<FixedArrayBase> store, uint32_t entry,
|
2015-07-02 14:38:37 +00:00
|
|
|
Handle<Object> value,
|
|
|
|
PropertyAttributes attributes) {
|
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
JSObject::NormalizeElements(object);
|
|
|
|
FixedArray::cast(*store)->set(1, *dictionary);
|
|
|
|
uint32_t length = static_cast<uint32_t>(store->length()) - 2;
|
2015-07-07 11:52:51 +00:00
|
|
|
if (entry >= length) {
|
|
|
|
entry = dictionary->FindEntry(entry - length) + length;
|
2015-07-02 14:38:37 +00:00
|
|
|
}
|
2015-07-07 11:52:51 +00:00
|
|
|
SlowSloppyArgumentsElementsAccessor::ReconfigureImpl(object, store, entry,
|
2015-07-02 16:44:17 +00:00
|
|
|
value, attributes);
|
2015-07-02 14:38:37 +00:00
|
|
|
}
|
2015-05-21 12:19:39 +00:00
|
|
|
|
2015-07-02 14:38:37 +00:00
|
|
|
static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
|
|
|
|
FixedArrayBase* to, ElementsKind from_kind,
|
|
|
|
uint32_t to_start, int packed_size,
|
|
|
|
int copy_size) {
|
|
|
|
DCHECK(!to->IsDictionary());
|
|
|
|
if (from_kind == SLOW_SLOPPY_ARGUMENTS_ELEMENTS) {
|
|
|
|
CopyDictionaryToObjectElements(from, from_start, to, FAST_HOLEY_ELEMENTS,
|
|
|
|
to_start, copy_size);
|
|
|
|
} else {
|
|
|
|
DCHECK_EQ(FAST_SLOPPY_ARGUMENTS_ELEMENTS, from_kind);
|
|
|
|
CopyObjectToObjectElements(from, FAST_HOLEY_ELEMENTS, from_start, to,
|
|
|
|
FAST_HOLEY_ELEMENTS, to_start, copy_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GrowCapacityAndConvertImpl(Handle<JSObject> object,
|
|
|
|
uint32_t capacity) {
|
|
|
|
Handle<FixedArray> parameter_map(FixedArray::cast(object->elements()));
|
|
|
|
Handle<FixedArray> old_elements(FixedArray::cast(parameter_map->get(1)));
|
|
|
|
ElementsKind from_kind = object->GetElementsKind();
|
|
|
|
// This method should only be called if there's a reason to update the
|
|
|
|
// elements.
|
|
|
|
DCHECK(from_kind == SLOW_SLOPPY_ARGUMENTS_ELEMENTS ||
|
|
|
|
static_cast<uint32_t>(old_elements->length()) < capacity);
|
|
|
|
Handle<FixedArrayBase> elements =
|
|
|
|
ConvertElementsWithCapacity(object, old_elements, from_kind, capacity);
|
|
|
|
Handle<Map> new_map = JSObject::GetElementsTransitionMap(
|
|
|
|
object, FAST_SLOPPY_ARGUMENTS_ELEMENTS);
|
|
|
|
JSObject::MigrateToMap(object, new_map);
|
|
|
|
parameter_map->set(1, *elements);
|
|
|
|
JSObject::ValidateElements(object);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-03-09 13:48:29 +00:00
|
|
|
template <typename ElementsAccessorSubclass, typename ElementsKindTraits>
|
2015-06-19 14:56:57 +00:00
|
|
|
void ElementsAccessorBase<ElementsAccessorSubclass, ElementsKindTraits>::
|
|
|
|
SetLengthImpl(Handle<JSArray> array, uint32_t length,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2015-06-25 15:04:46 +00:00
|
|
|
DCHECK(!array->SetLengthWouldNormalize(length));
|
2015-06-19 18:59:11 +00:00
|
|
|
DCHECK(IsFastElementsKind(array->GetElementsKind()));
|
|
|
|
uint32_t old_length = 0;
|
|
|
|
CHECK(array->length()->ToArrayIndex(&old_length));
|
|
|
|
|
|
|
|
if (old_length < length) {
|
|
|
|
ElementsKind kind = array->GetElementsKind();
|
|
|
|
if (!IsFastHoleyElementsKind(kind)) {
|
|
|
|
kind = GetHoleyElementsKind(kind);
|
|
|
|
JSObject::TransitionElementsKind(array, kind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the backing store should be shrunk.
|
|
|
|
uint32_t capacity = backing_store->length();
|
|
|
|
if (length == 0) {
|
|
|
|
array->initialize_elements();
|
|
|
|
} else if (length <= capacity) {
|
|
|
|
if (array->HasFastSmiOrObjectElements()) {
|
|
|
|
backing_store = JSObject::EnsureWritableFastElements(array);
|
|
|
|
}
|
|
|
|
if (2 * length <= capacity) {
|
|
|
|
// If more than half the elements won't be used, trim the array.
|
|
|
|
array->GetHeap()->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(
|
|
|
|
*backing_store, capacity - length);
|
|
|
|
} else {
|
|
|
|
// Otherwise, fill the unused tail with holes.
|
|
|
|
for (uint32_t i = length; i < old_length; i++) {
|
|
|
|
BackingStore::cast(*backing_store)->set_the_hole(i);
|
|
|
|
}
|
|
|
|
}
|
2015-06-19 14:56:57 +00:00
|
|
|
} else {
|
2015-06-19 18:59:11 +00:00
|
|
|
// Check whether the backing store should be expanded.
|
|
|
|
capacity = Max(length, JSObject::NewElementsCapacity(capacity));
|
2015-06-22 11:24:03 +00:00
|
|
|
ElementsAccessorSubclass::GrowCapacityAndConvertImpl(array, capacity);
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
2015-06-19 18:59:11 +00:00
|
|
|
|
|
|
|
array->set_length(Smi::FromInt(length));
|
|
|
|
JSObject::ValidateElements(array);
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
2015-07-06 10:40:24 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
void CheckArrayAbuse(Handle<JSObject> obj, const char* op, uint32_t index,
|
2015-07-06 10:40:24 +00:00
|
|
|
bool allow_appending) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
Object* raw_length = NULL;
|
|
|
|
const char* elements_type = "array";
|
|
|
|
if (obj->IsJSArray()) {
|
|
|
|
JSArray* array = JSArray::cast(*obj);
|
|
|
|
raw_length = array->length();
|
|
|
|
} else {
|
|
|
|
raw_length = Smi::FromInt(obj->elements()->length());
|
|
|
|
elements_type = "object";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (raw_length->IsNumber()) {
|
|
|
|
double n = raw_length->Number();
|
|
|
|
if (FastI2D(FastD2UI(n)) == n) {
|
|
|
|
int32_t int32_length = DoubleToInt32(n);
|
|
|
|
uint32_t compare_length = static_cast<uint32_t>(int32_length);
|
|
|
|
if (allow_appending) compare_length++;
|
2015-07-07 11:52:51 +00:00
|
|
|
if (index >= compare_length) {
|
2015-07-06 10:40:24 +00:00
|
|
|
PrintF("[OOB %s %s (%s length = %d, element accessed = %d) in ",
|
|
|
|
elements_type, op, elements_type, static_cast<int>(int32_length),
|
2015-07-07 11:52:51 +00:00
|
|
|
static_cast<int>(index));
|
2015-07-06 10:40:24 +00:00
|
|
|
TraceTopFrame(obj->GetIsolate());
|
|
|
|
PrintF("]\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PrintF("[%s elements length not integer value in ", elements_type);
|
|
|
|
TraceTopFrame(obj->GetIsolate());
|
|
|
|
PrintF("]\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PrintF("[%s elements length not a number in ", elements_type);
|
|
|
|
TraceTopFrame(obj->GetIsolate());
|
|
|
|
PrintF("]\n");
|
|
|
|
}
|
|
|
|
}
|
2011-11-08 11:59:56 +00:00
|
|
|
|
|
|
|
|
2014-04-09 13:16:19 +00:00
|
|
|
MaybeHandle<Object> ArrayConstructInitializeElements(Handle<JSArray> array,
|
|
|
|
Arguments* args) {
|
2015-06-19 11:21:26 +00:00
|
|
|
if (args->length() == 0) {
|
|
|
|
// Optimize the case where there are no parameters passed.
|
|
|
|
JSArray::Initialize(array, JSArray::kPreallocatedArrayElements);
|
|
|
|
return array;
|
|
|
|
|
|
|
|
} else if (args->length() == 1 && args->at<Object>(0)->IsNumber()) {
|
|
|
|
uint32_t length;
|
|
|
|
if (!args->at<Object>(0)->ToArrayLength(&length)) {
|
|
|
|
return ThrowArrayLengthRangeError(array->GetIsolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Optimize the case where there is one argument and the argument is a small
|
|
|
|
// smi.
|
|
|
|
if (length > 0 && length < JSObject::kInitialMaxFastElementArray) {
|
|
|
|
ElementsKind elements_kind = array->GetElementsKind();
|
|
|
|
JSArray::Initialize(array, length, length);
|
|
|
|
|
|
|
|
if (!IsFastHoleyElementsKind(elements_kind)) {
|
|
|
|
elements_kind = GetHoleyElementsKind(elements_kind);
|
|
|
|
JSObject::TransitionElementsKind(array, elements_kind);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
2015-06-19 11:21:26 +00:00
|
|
|
} else if (length == 0) {
|
|
|
|
JSArray::Initialize(array, JSArray::kPreallocatedArrayElements);
|
2015-06-19 14:56:57 +00:00
|
|
|
} else {
|
|
|
|
// Take the argument as the length.
|
|
|
|
JSArray::Initialize(array, 0);
|
|
|
|
JSArray::SetLength(array, length);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
2015-06-19 14:56:57 +00:00
|
|
|
return array;
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 11:38:27 +00:00
|
|
|
Factory* factory = array->GetIsolate()->factory();
|
|
|
|
|
2013-03-01 16:06:34 +00:00
|
|
|
// Set length and elements on the array.
|
|
|
|
int number_of_elements = args->length();
|
2014-03-18 11:38:27 +00:00
|
|
|
JSObject::EnsureCanContainElements(
|
|
|
|
array, args, 0, number_of_elements, ALLOW_CONVERTED_DOUBLE_ELEMENTS);
|
2013-03-01 16:06:34 +00:00
|
|
|
|
|
|
|
// Allocate an appropriately typed elements array.
|
|
|
|
ElementsKind elements_kind = array->GetElementsKind();
|
2014-03-18 11:38:27 +00:00
|
|
|
Handle<FixedArrayBase> elms;
|
2013-03-01 16:06:34 +00:00
|
|
|
if (IsFastDoubleElementsKind(elements_kind)) {
|
2014-03-18 11:38:27 +00:00
|
|
|
elms = Handle<FixedArrayBase>::cast(
|
|
|
|
factory->NewFixedDoubleArray(number_of_elements));
|
2013-03-01 16:06:34 +00:00
|
|
|
} else {
|
2014-03-18 11:38:27 +00:00
|
|
|
elms = Handle<FixedArrayBase>::cast(
|
|
|
|
factory->NewFixedArrayWithHoles(number_of_elements));
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fill in the content
|
|
|
|
switch (array->GetElementsKind()) {
|
|
|
|
case FAST_HOLEY_SMI_ELEMENTS:
|
|
|
|
case FAST_SMI_ELEMENTS: {
|
2014-03-18 11:38:27 +00:00
|
|
|
Handle<FixedArray> smi_elms = Handle<FixedArray>::cast(elms);
|
2015-07-07 11:52:51 +00:00
|
|
|
for (int entry = 0; entry < number_of_elements; entry++) {
|
|
|
|
smi_elms->set(entry, (*args)[entry], SKIP_WRITE_BARRIER);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FAST_HOLEY_ELEMENTS:
|
|
|
|
case FAST_ELEMENTS: {
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2013-03-01 16:06:34 +00:00
|
|
|
WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
|
2014-03-18 11:38:27 +00:00
|
|
|
Handle<FixedArray> object_elms = Handle<FixedArray>::cast(elms);
|
2015-07-07 11:52:51 +00:00
|
|
|
for (int entry = 0; entry < number_of_elements; entry++) {
|
|
|
|
object_elms->set(entry, (*args)[entry], mode);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FAST_HOLEY_DOUBLE_ELEMENTS:
|
|
|
|
case FAST_DOUBLE_ELEMENTS: {
|
2014-03-18 11:38:27 +00:00
|
|
|
Handle<FixedDoubleArray> double_elms =
|
|
|
|
Handle<FixedDoubleArray>::cast(elms);
|
2015-07-07 11:52:51 +00:00
|
|
|
for (int entry = 0; entry < number_of_elements; entry++) {
|
|
|
|
double_elms->set(entry, (*args)[entry]->Number());
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-18 11:38:27 +00:00
|
|
|
array->set_elements(*elms);
|
2013-03-01 16:06:34 +00:00
|
|
|
array->set_length(Smi::FromInt(number_of_elements));
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
2015-07-06 10:40:24 +00:00
|
|
|
|
|
|
|
void ElementsAccessor::InitializeOncePerProcess() {
|
|
|
|
static ElementsAccessor* accessor_array[] = {
|
|
|
|
#define ACCESSOR_ARRAY(Class, Kind, Store) new Class(#Kind),
|
|
|
|
ELEMENTS_LIST(ACCESSOR_ARRAY)
|
|
|
|
#undef ACCESSOR_ARRAY
|
|
|
|
};
|
|
|
|
|
|
|
|
STATIC_ASSERT((sizeof(accessor_array) / sizeof(*accessor_array)) ==
|
|
|
|
kElementsKindCount);
|
|
|
|
|
|
|
|
elements_accessors_ = accessor_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ElementsAccessor::TearDown() {
|
|
|
|
if (elements_accessors_ == NULL) return;
|
|
|
|
#define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind];
|
|
|
|
ELEMENTS_LIST(ACCESSOR_DELETE)
|
|
|
|
#undef ACCESSOR_DELETE
|
|
|
|
elements_accessors_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL;
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|