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
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.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"
|
|
|
|
#include "src/elements.h"
|
2015-05-06 07:51:56 +00:00
|
|
|
#include "src/messages.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/objects.h"
|
|
|
|
#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:
|
|
|
|
// - ExternalInt8ElementsAccessor
|
|
|
|
// - ExternalUint8ElementsAccessor
|
|
|
|
// - ExternalInt16ElementsAccessor
|
|
|
|
// - ExternalUint16ElementsAccessor
|
|
|
|
// - ExternalInt32ElementsAccessor
|
|
|
|
// - ExternalUint32ElementsAccessor
|
|
|
|
// - ExternalFloat32ElementsAccessor
|
|
|
|
// - ExternalFloat64ElementsAccessor
|
|
|
|
// - ExternalUint8ClampedElementsAccessor
|
|
|
|
// - 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
|
2011-11-08 11:59:56 +00:00
|
|
|
|
|
|
|
|
2011-08-03 11:12:46 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
#define ELEMENTS_LIST(V) \
|
2012-05-23 14:24:29 +00:00
|
|
|
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) \
|
2012-03-09 13:48:29 +00:00
|
|
|
V(DictionaryElementsAccessor, DICTIONARY_ELEMENTS, \
|
|
|
|
SeededNumberDictionary) \
|
2014-03-11 14:39:08 +00:00
|
|
|
V(SloppyArgumentsElementsAccessor, SLOPPY_ARGUMENTS_ELEMENTS, \
|
2012-03-09 13:48:29 +00:00
|
|
|
FixedArray) \
|
2014-01-24 16:01:15 +00:00
|
|
|
V(ExternalInt8ElementsAccessor, EXTERNAL_INT8_ELEMENTS, \
|
|
|
|
ExternalInt8Array) \
|
|
|
|
V(ExternalUint8ElementsAccessor, \
|
|
|
|
EXTERNAL_UINT8_ELEMENTS, ExternalUint8Array) \
|
|
|
|
V(ExternalInt16ElementsAccessor, EXTERNAL_INT16_ELEMENTS, \
|
|
|
|
ExternalInt16Array) \
|
|
|
|
V(ExternalUint16ElementsAccessor, \
|
|
|
|
EXTERNAL_UINT16_ELEMENTS, ExternalUint16Array) \
|
|
|
|
V(ExternalInt32ElementsAccessor, EXTERNAL_INT32_ELEMENTS, \
|
|
|
|
ExternalInt32Array) \
|
|
|
|
V(ExternalUint32ElementsAccessor, \
|
|
|
|
EXTERNAL_UINT32_ELEMENTS, ExternalUint32Array) \
|
|
|
|
V(ExternalFloat32ElementsAccessor, \
|
|
|
|
EXTERNAL_FLOAT32_ELEMENTS, ExternalFloat32Array) \
|
|
|
|
V(ExternalFloat64ElementsAccessor, \
|
|
|
|
EXTERNAL_FLOAT64_ELEMENTS, ExternalFloat64Array) \
|
|
|
|
V(ExternalUint8ClampedElementsAccessor, \
|
|
|
|
EXTERNAL_UINT8_CLAMPED_ELEMENTS, \
|
|
|
|
ExternalUint8ClampedArray) \
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2014-08-26 13:07:18 +00:00
|
|
|
ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL;
|
2011-08-03 11:12:46 +00:00
|
|
|
|
|
|
|
|
2014-04-09 12:56:24 +00:00
|
|
|
static bool HasKey(Handle<FixedArray> array, Handle<Object> key_handle) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
Object* key = *key_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-05-20 17:03:21 +00:00
|
|
|
if (key->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
|
|
|
|
static 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-25 13:00:06 +00:00
|
|
|
static void CopyObjectToObjectElements(FixedArrayBase* from_base,
|
2012-11-15 12:19:14 +00:00
|
|
|
ElementsKind from_kind,
|
|
|
|
uint32_t from_start,
|
2014-07-25 13:00:06 +00:00
|
|
|
FixedArrayBase* to_base,
|
|
|
|
ElementsKind to_kind, uint32_t to_start,
|
2012-11-15 12:19:14 +00:00
|
|
|
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
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-08 14:20:29 +00:00
|
|
|
void CheckArrayAbuse(Handle<JSObject> obj, const char* op, uint32_t key,
|
2013-02-08 14:32:38 +00:00
|
|
|
bool allow_appending) {
|
2014-04-08 14:20:29 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2013-02-07 07:56:11 +00:00
|
|
|
Object* raw_length = NULL;
|
|
|
|
const char* elements_type = "array";
|
|
|
|
if (obj->IsJSArray()) {
|
2014-04-08 14:20:29 +00:00
|
|
|
JSArray* array = JSArray::cast(*obj);
|
2013-02-07 07:56:11 +00:00
|
|
|
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);
|
2013-02-08 14:32:38 +00:00
|
|
|
uint32_t compare_length = static_cast<uint32_t>(int32_length);
|
|
|
|
if (allow_appending) compare_length++;
|
|
|
|
if (key >= compare_length) {
|
2013-02-07 07:56:11 +00:00
|
|
|
PrintF("[OOB %s %s (%s length = %d, element accessed = %d) in ",
|
|
|
|
elements_type, op, elements_type,
|
|
|
|
static_cast<int>(int32_length),
|
|
|
|
static_cast<int>(key));
|
2013-02-15 09:27:10 +00:00
|
|
|
TraceTopFrame(obj->GetIsolate());
|
2013-02-07 07:56:11 +00:00
|
|
|
PrintF("]\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PrintF("[%s elements length not integer value in ", elements_type);
|
2013-02-15 09:27:10 +00:00
|
|
|
TraceTopFrame(obj->GetIsolate());
|
2013-02-07 07:56:11 +00:00
|
|
|
PrintF("]\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PrintF("[%s elements length not a number in ", elements_type);
|
2013-02-15 09:27:10 +00:00
|
|
|
TraceTopFrame(obj->GetIsolate());
|
2013-02-07 07:56:11 +00:00
|
|
|
PrintF("]\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 {
|
2011-08-17 16:15:30 +00:00
|
|
|
protected:
|
2012-03-09 13:48:29 +00:00
|
|
|
explicit ElementsAccessorBase(const char* name)
|
|
|
|
: ElementsAccessor(name) { }
|
|
|
|
|
|
|
|
typedef ElementsTraitsParam ElementsTraits;
|
|
|
|
typedef typename ElementsTraitsParam::BackingStore BackingStore;
|
|
|
|
|
2015-04-20 13:08:11 +00:00
|
|
|
ElementsKind kind() const final { 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-02-19 09:04:49 +00:00
|
|
|
virtual bool HasElement(Handle<JSObject> holder, uint32_t key,
|
2015-04-20 13:08:11 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) final {
|
2015-06-11 20:17:25 +00:00
|
|
|
return ElementsAccessorSubclass::GetIndexForKeyImpl(*holder, *backing_store,
|
|
|
|
key) != kMaxUInt32;
|
2012-03-06 12:22:18 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
virtual Handle<Object> Get(Handle<JSObject> holder, uint32_t key,
|
|
|
|
Handle<FixedArrayBase> backing_store) final {
|
2013-02-08 14:32:38 +00:00
|
|
|
if (!IsExternalArrayElementsKind(ElementsTraits::Kind) &&
|
|
|
|
FLAG_trace_js_array_abuse) {
|
|
|
|
CheckArrayAbuse(holder, "elements read", key);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsExternalArrayElementsKind(ElementsTraits::Kind) &&
|
|
|
|
FLAG_trace_external_array_abuse) {
|
|
|
|
CheckArrayAbuse(holder, "external elements read", key);
|
2013-02-07 07:56:11 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
return ElementsAccessorSubclass::GetImpl(holder, key, backing_store);
|
2011-08-18 09:51:08 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static Handle<Object> GetImpl(Handle<JSObject> obj, uint32_t key,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2015-05-21 12:19:39 +00:00
|
|
|
if (key < ElementsAccessorSubclass::GetCapacityImpl(*obj, *backing_store)) {
|
2014-04-08 14:20:29 +00:00
|
|
|
return BackingStore::get(Handle<BackingStore>::cast(backing_store), key);
|
|
|
|
} else {
|
|
|
|
return backing_store->GetIsolate()->factory()->the_hole_value();
|
|
|
|
}
|
2011-08-03 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 09:25:16 +00:00
|
|
|
virtual void Set(FixedArrayBase* backing_store, uint32_t key,
|
|
|
|
Object* value) final {
|
2015-06-18 19:49:31 +00:00
|
|
|
ElementsAccessorSubclass::SetImpl(backing_store, key, value);
|
2015-06-11 15:07:00 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 09:25:16 +00:00
|
|
|
static void SetImpl(FixedArrayBase* backing_store, uint32_t key,
|
|
|
|
Object* value) {
|
|
|
|
BackingStore::cast(backing_store)->SetValue(key, value);
|
2015-06-11 15:07:00 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
virtual MaybeHandle<AccessorPair> GetAccessorPair(
|
2015-02-19 08:13:33 +00:00
|
|
|
Handle<JSObject> holder, uint32_t key,
|
2015-04-20 13:08:11 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) final {
|
2015-02-19 08:13:33 +00:00
|
|
|
return ElementsAccessorSubclass::GetAccessorPairImpl(holder, key,
|
|
|
|
backing_store);
|
2012-11-15 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static MaybeHandle<AccessorPair> GetAccessorPairImpl(
|
|
|
|
Handle<JSObject> obj, uint32_t key,
|
2014-04-07 09:20:44 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) {
|
|
|
|
return MaybeHandle<AccessorPair>();
|
2012-11-15 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-12-12 10:44:12 +00:00
|
|
|
virtual void SetCapacityAndLength(Handle<JSArray> array, int capacity,
|
2015-04-20 13:08:11 +00:00
|
|
|
int length) final {
|
2014-03-25 15:33:22 +00:00
|
|
|
ElementsAccessorSubclass::
|
|
|
|
SetFastElementsCapacityAndLength(array, capacity, length);
|
2011-12-09 08:50:19 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 15:33:22 +00:00
|
|
|
static void SetFastElementsCapacityAndLength(
|
2014-03-25 09:29:48 +00:00
|
|
|
Handle<JSObject> obj,
|
|
|
|
int capacity,
|
|
|
|
int length) {
|
2014-03-25 15:33:22 +00:00
|
|
|
UNIMPLEMENTED();
|
2014-03-25 09:29:48 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 11:52:30 +00:00
|
|
|
virtual void Delete(Handle<JSObject> obj, uint32_t key,
|
|
|
|
LanguageMode language_mode) override = 0;
|
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-06-02 10:42:16 +00:00
|
|
|
if (ElementsAccessorSubclass::HasIndexImpl(*from, y)) {
|
|
|
|
uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(*from, y);
|
|
|
|
Handle<Object> value =
|
|
|
|
ElementsAccessorSubclass::GetImpl(receiver, key, from);
|
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;
|
|
|
|
}
|
2014-04-09 12:56:24 +00:00
|
|
|
if (!HasKey(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.
|
2012-03-05 16:14:34 +00:00
|
|
|
uint32_t index = 0;
|
2011-08-17 16:15:30 +00:00
|
|
|
for (uint32_t y = 0; y < len1; y++) {
|
2015-06-02 10:42:16 +00:00
|
|
|
if (ElementsAccessorSubclass::HasIndexImpl(*from, y)) {
|
|
|
|
uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(*from, y);
|
|
|
|
Handle<Object> value =
|
|
|
|
ElementsAccessorSubclass::GetImpl(receiver, key, from);
|
|
|
|
DCHECK(!value->IsAccessorPair());
|
|
|
|
DCHECK(!value->IsExecutableAccessorInfo());
|
2014-11-27 10:21:32 +00:00
|
|
|
if (filter == FixedArray::NON_SYMBOL_KEYS && value->IsSymbol()) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-04-09 12:56:24 +00:00
|
|
|
if (!value->IsTheHole() && !HasKey(to, value)) {
|
2014-04-08 14:20:29 +00:00
|
|
|
result->set(len0 + index, *value);
|
2011-08-17 16:15:30 +00:00
|
|
|
index++;
|
|
|
|
}
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(extra == index);
|
2011-08-10 10:51:01 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-08-17 16:15:30 +00:00
|
|
|
protected:
|
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-06-02 10:42:16 +00:00
|
|
|
static bool HasIndexImpl(FixedArrayBase* backing_store, uint32_t index) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool HasIndex(FixedArrayBase* backing_store, uint32_t index) final {
|
|
|
|
return ElementsAccessorSubclass::HasIndexImpl(backing_store, index);
|
|
|
|
}
|
|
|
|
|
2015-05-21 12:19:39 +00:00
|
|
|
static uint32_t GetKeyForIndexImpl(FixedArrayBase* backing_store,
|
2012-02-17 12:59:58 +00:00
|
|
|
uint32_t index) {
|
2011-08-17 16:15:30 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2015-05-21 12:19:39 +00:00
|
|
|
virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store,
|
2015-04-20 13:08:11 +00:00
|
|
|
uint32_t index) final {
|
2014-04-09 12:56:24 +00:00
|
|
|
return ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, index);
|
2011-08-03 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 20:17:25 +00:00
|
|
|
static uint32_t GetIndexForKeyImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store,
|
2015-05-21 12:19:39 +00:00
|
|
|
uint32_t key) {
|
2015-06-11 20:17:25 +00:00
|
|
|
return key < ElementsAccessorSubclass::GetCapacityImpl(holder,
|
|
|
|
backing_store) &&
|
|
|
|
!BackingStore::cast(backing_store)->is_the_hole(key)
|
|
|
|
? key
|
|
|
|
: kMaxUInt32;
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 20:17:25 +00:00
|
|
|
virtual uint32_t GetIndexForKey(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store,
|
2015-05-21 12:19:39 +00:00
|
|
|
uint32_t key) final {
|
2015-06-11 20:17:25 +00:00
|
|
|
return ElementsAccessorSubclass::GetIndexForKeyImpl(holder, backing_store,
|
|
|
|
key);
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store,
|
|
|
|
uint32_t index) {
|
|
|
|
return PropertyDetails(NONE, DATA, 0, PropertyCellType::kNoCell);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual PropertyDetails GetDetails(FixedArrayBase* backing_store,
|
|
|
|
uint32_t index) final {
|
|
|
|
return ElementsAccessorSubclass::GetDetailsImpl(backing_store, index);
|
|
|
|
}
|
|
|
|
|
2011-08-03 11:12:46 +00:00
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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) {}
|
2011-11-08 11:59:56 +00:00
|
|
|
protected:
|
2012-03-09 13:48:29 +00:00
|
|
|
friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>;
|
2014-03-11 14:39:08 +00:00
|
|
|
friend class SloppyArgumentsElementsAccessor;
|
2012-03-09 13:48:29 +00:00
|
|
|
|
|
|
|
typedef typename KindTraits::BackingStore BackingStore;
|
2011-11-08 11:59:56 +00:00
|
|
|
|
2014-07-28 13:12:26 +00:00
|
|
|
// Adjusts the length of the fast backing store.
|
2015-06-19 14:56:57 +00:00
|
|
|
static uint32_t SetLengthWithoutNormalize(
|
|
|
|
Handle<FixedArrayBase> backing_store, Handle<JSArray> array,
|
2014-03-25 09:29:48 +00:00
|
|
|
uint32_t length) {
|
|
|
|
Isolate* isolate = array->GetIsolate();
|
2011-11-08 11:59:56 +00:00
|
|
|
uint32_t old_capacity = backing_store->length();
|
2014-03-25 09:29:48 +00:00
|
|
|
Handle<Object> old_length(array->length(), isolate);
|
2012-11-02 10:24:56 +00:00
|
|
|
bool same_or_smaller_size = old_length->IsSmi() &&
|
2014-03-25 09:29:48 +00:00
|
|
|
static_cast<uint32_t>(Handle<Smi>::cast(old_length)->value()) >= length;
|
2012-05-23 14:24:29 +00:00
|
|
|
ElementsKind kind = array->GetElementsKind();
|
|
|
|
|
2012-11-02 10:24:56 +00:00
|
|
|
if (!same_or_smaller_size && IsFastElementsKind(kind) &&
|
2012-05-23 14:24:29 +00:00
|
|
|
!IsFastHoleyElementsKind(kind)) {
|
|
|
|
kind = GetHoleyElementsKind(kind);
|
2014-03-25 09:29:48 +00:00
|
|
|
JSObject::TransitionElementsKind(array, kind);
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
2011-11-08 11:59:56 +00:00
|
|
|
|
|
|
|
// Check whether the backing store should be shrunk.
|
|
|
|
if (length <= old_capacity) {
|
2012-05-23 14:24:29 +00:00
|
|
|
if (array->HasFastSmiOrObjectElements()) {
|
2014-03-25 09:29:48 +00:00
|
|
|
backing_store = JSObject::EnsureWritableFastElements(array);
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
if (2 * length <= old_capacity) {
|
|
|
|
// If more than half the elements won't be used, trim the array.
|
|
|
|
if (length == 0) {
|
|
|
|
array->initialize_elements();
|
|
|
|
} else {
|
2015-04-16 08:39:19 +00:00
|
|
|
isolate->heap()->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(
|
2014-08-05 11:16:11 +00:00
|
|
|
*backing_store, old_capacity - length);
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Otherwise, fill the unused tail with holes.
|
2012-07-30 08:34:26 +00:00
|
|
|
int old_length = FastD2IChecked(array->length()->Number());
|
2011-11-08 11:59:56 +00:00
|
|
|
for (int i = length; i < old_length; i++) {
|
2014-03-25 09:29:48 +00:00
|
|
|
Handle<BackingStore>::cast(backing_store)->set_the_hole(i);
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-19 14:56:57 +00:00
|
|
|
return length;
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the backing store should be expanded.
|
|
|
|
uint32_t min = JSObject::NewElementsCapacity(old_capacity);
|
|
|
|
uint32_t new_capacity = length > min ? length : min;
|
2014-07-28 13:12:26 +00:00
|
|
|
FastElementsAccessorSubclass::SetFastElementsCapacityAndLength(
|
|
|
|
array, new_capacity, length);
|
|
|
|
JSObject::ValidateElements(array);
|
2015-06-19 14:56:57 +00:00
|
|
|
return length;
|
2014-03-19 16:29:19 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 11:52:30 +00:00
|
|
|
static void DeleteCommon(Handle<JSObject> obj, uint32_t key,
|
|
|
|
LanguageMode language_mode) {
|
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());
|
2014-03-20 10:52:22 +00:00
|
|
|
Isolate* isolate = obj->GetIsolate();
|
2011-08-04 11:42:14 +00:00
|
|
|
Heap* heap = obj->GetHeap();
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArrayBase> elements(obj->elements());
|
2015-06-02 11:52:30 +00:00
|
|
|
if (*elements == heap->empty_fixed_array()) return;
|
|
|
|
|
2014-03-20 10:52:22 +00:00
|
|
|
Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements);
|
2014-03-11 14:39:08 +00:00
|
|
|
bool is_sloppy_arguments_elements_map =
|
|
|
|
backing_store->map() == heap->sloppy_arguments_elements_map();
|
|
|
|
if (is_sloppy_arguments_elements_map) {
|
2014-03-27 16:41:09 +00:00
|
|
|
backing_store = handle(
|
2014-04-08 14:20:29 +00:00
|
|
|
BackingStore::cast(Handle<FixedArray>::cast(backing_store)->get(1)),
|
|
|
|
isolate);
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
|
|
|
uint32_t length = static_cast<uint32_t>(
|
|
|
|
obj->IsJSArray()
|
2014-03-20 10:52:22 +00:00
|
|
|
? Smi::cast(Handle<JSArray>::cast(obj)->length())->value()
|
2011-08-04 11:42:14 +00:00
|
|
|
: backing_store->length());
|
2011-08-17 16:15:30 +00:00
|
|
|
if (key < length) {
|
2014-03-11 14:39:08 +00:00
|
|
|
if (!is_sloppy_arguments_elements_map) {
|
2012-11-02 10:24:56 +00:00
|
|
|
ElementsKind kind = KindTraits::Kind;
|
|
|
|
if (IsFastPackedElementsKind(kind)) {
|
2014-03-20 10:52:22 +00:00
|
|
|
JSObject::TransitionElementsKind(obj, GetHoleyElementsKind(kind));
|
2012-11-02 10:24:56 +00:00
|
|
|
}
|
|
|
|
if (IsFastSmiOrObjectElementsKind(KindTraits::Kind)) {
|
2014-03-20 10:52:22 +00:00
|
|
|
Handle<Object> writable = JSObject::EnsureWritableFastElements(obj);
|
|
|
|
backing_store = Handle<BackingStore>::cast(writable);
|
2012-11-02 10:24:56 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-17 16:15:30 +00:00
|
|
|
backing_store->set_the_hole(key);
|
2011-08-04 11:42:14 +00:00
|
|
|
// 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 &&
|
2014-03-20 10:52:22 +00:00
|
|
|
!heap->InNewSpace(*backing_store) &&
|
2012-05-23 14:24:29 +00:00
|
|
|
((key > 0 && backing_store->is_the_hole(key - 1)) ||
|
|
|
|
(key + 1 < length && backing_store->is_the_hole(key + 1)))) {
|
2011-08-04 11:42:14 +00:00
|
|
|
int num_used = 0;
|
|
|
|
for (int i = 0; i < backing_store->length(); ++i) {
|
2012-05-23 14:24:29 +00:00
|
|
|
if (!backing_store->is_the_hole(i)) ++num_used;
|
2011-08-04 11:42:14 +00:00
|
|
|
// Bail out early if more than 1/4 is used.
|
|
|
|
if (4 * num_used > backing_store->length()) break;
|
|
|
|
}
|
|
|
|
if (4 * num_used <= backing_store->length()) {
|
2014-03-20 10:52:22 +00:00
|
|
|
JSObject::NormalizeElements(obj);
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-02 11:52:30 +00:00
|
|
|
virtual void Delete(Handle<JSObject> obj, uint32_t key,
|
|
|
|
LanguageMode language_mode) final {
|
|
|
|
DeleteCommon(obj, key, language_mode);
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static bool HasIndexImpl(FixedArrayBase* backing_store, uint32_t index) {
|
|
|
|
return !BackingStore::cast(backing_store)->is_the_hole(index);
|
|
|
|
}
|
|
|
|
|
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);
|
2012-05-23 14:24:29 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK((!IsFastSmiElementsKind(KindTraits::Kind) ||
|
2014-04-16 06:18:37 +00:00
|
|
|
BackingStore::get(backing_store, i)->IsSmi()) ||
|
2012-05-23 14:24:29 +00:00
|
|
|
(IsFastHoleyElementsKind(KindTraits::Kind) ==
|
|
|
|
backing_store->is_the_hole(i)));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-29 08:22:24 +00:00
|
|
|
static inline ElementsKind ElementsKindForArray(FixedArrayBase* array) {
|
2013-01-02 10:09:42 +00:00
|
|
|
switch (array->map()->instance_type()) {
|
|
|
|
case FIXED_ARRAY_TYPE:
|
|
|
|
if (array->IsDictionary()) {
|
|
|
|
return DICTIONARY_ELEMENTS;
|
|
|
|
} else {
|
|
|
|
return FAST_HOLEY_ELEMENTS;
|
|
|
|
}
|
|
|
|
case FIXED_DOUBLE_ARRAY_TYPE:
|
|
|
|
return FAST_HOLEY_DOUBLE_ELEMENTS;
|
2014-01-24 16:01:15 +00:00
|
|
|
|
|
|
|
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
|
|
|
|
case EXTERNAL_##TYPE##_ARRAY_TYPE: \
|
|
|
|
return EXTERNAL_##TYPE##_ELEMENTS; \
|
|
|
|
case FIXED_##TYPE##_ARRAY_TYPE: \
|
|
|
|
return TYPE##_ELEMENTS;
|
|
|
|
|
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_CASE)
|
|
|
|
#undef TYPED_ARRAY_CASE
|
2014-01-16 17:08:45 +00:00
|
|
|
|
2013-01-02 10:09:42 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return FAST_HOLEY_ELEMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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;
|
2014-03-11 14:39:08 +00:00
|
|
|
case SLOPPY_ARGUMENTS_ELEMENTS: {
|
2013-01-02 10:09:42 +00:00
|
|
|
// TODO(verwaest): This is a temporary hack to support extending
|
2014-03-11 14:39:08 +00:00
|
|
|
// SLOPPY_ARGUMENTS_ELEMENTS in SetFastElementsCapacityAndLength.
|
2013-01-02 10:09:42 +00:00
|
|
|
// This case should be UNREACHABLE().
|
2014-09-29 08:22:24 +00:00
|
|
|
FixedArray* parameter_map = FixedArray::cast(from);
|
|
|
|
FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1));
|
2014-04-09 12:56:24 +00:00
|
|
|
ElementsKind from_kind = ElementsKindForArray(arguments);
|
2014-03-27 16:41:09 +00:00
|
|
|
CopyElementsImpl(arguments, from_start, to, from_kind,
|
|
|
|
to_start, packed_size, copy_size);
|
|
|
|
break;
|
2012-06-12 15:30:16 +00:00
|
|
|
}
|
2014-01-24 16:01:15 +00:00
|
|
|
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
|
|
|
|
case EXTERNAL_##TYPE##_ELEMENTS: \
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-25 15:33:22 +00:00
|
|
|
static void SetFastElementsCapacityAndLength(
|
|
|
|
Handle<JSObject> obj,
|
|
|
|
uint32_t capacity,
|
|
|
|
uint32_t length) {
|
2012-05-23 14:24:29 +00:00
|
|
|
JSObject::SetFastElementsCapacitySmiMode set_capacity_mode =
|
|
|
|
obj->HasFastSmiElements()
|
|
|
|
? JSObject::kAllowSmiElements
|
|
|
|
: JSObject::kDontAllowSmiElements;
|
2014-03-25 15:33:22 +00:00
|
|
|
JSObject::SetFastElementsCapacityAndLength(
|
|
|
|
obj, capacity, length, set_capacity_mode);
|
2014-03-25 09:29:48 +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
|
|
|
|
2014-03-25 15:33:22 +00:00
|
|
|
static void SetFastElementsCapacityAndLength(Handle<JSObject> obj,
|
|
|
|
uint32_t capacity,
|
|
|
|
uint32_t length) {
|
|
|
|
JSObject::SetFastDoubleElementsCapacityAndLength(obj, capacity, length);
|
2014-03-25 09:29:48 +00:00
|
|
|
}
|
|
|
|
|
2011-08-17 16:15:30 +00:00
|
|
|
protected:
|
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;
|
2014-03-11 14:39:08 +00:00
|
|
|
case 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 EXTERNAL_##TYPE##_ELEMENTS: \
|
|
|
|
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:
|
|
|
|
friend class ElementsAccessorBase<FastPackedDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_DOUBLE_ELEMENTS> >;
|
|
|
|
explicit FastPackedDoubleElementsAccessor(const char* name)
|
|
|
|
: FastDoubleElementsAccessor<
|
|
|
|
FastPackedDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_DOUBLE_ELEMENTS> >(name) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FastHoleyDoubleElementsAccessor
|
|
|
|
: public FastDoubleElementsAccessor<
|
|
|
|
FastHoleyDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_HOLEY_DOUBLE_ELEMENTS> > {
|
|
|
|
public:
|
|
|
|
friend class ElementsAccessorBase<
|
|
|
|
FastHoleyDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<FAST_HOLEY_DOUBLE_ELEMENTS> >;
|
|
|
|
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
|
|
|
|
2011-08-17 16:15:30 +00:00
|
|
|
protected:
|
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
|
|
|
|
2014-01-24 16:01:15 +00:00
|
|
|
friend class ElementsAccessorBase<AccessorClass,
|
2012-03-09 13:48:29 +00:00
|
|
|
ElementsKindTraits<Kind> >;
|
2011-08-18 09:51:08 +00:00
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static Handle<Object> GetImpl(Handle<JSObject> obj, uint32_t key,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2015-05-21 12:19:39 +00:00
|
|
|
if (key < AccessorClass::GetCapacityImpl(*obj, *backing_store)) {
|
2014-04-08 14:20:29 +00:00
|
|
|
return BackingStore::get(Handle<BackingStore>::cast(backing_store), key);
|
|
|
|
} else {
|
|
|
|
return backing_store->GetIsolate()->factory()->undefined_value();
|
|
|
|
}
|
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,
|
|
|
|
uint32_t index) {
|
|
|
|
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-06-02 11:52:30 +00:00
|
|
|
virtual void Delete(Handle<JSObject> obj, uint32_t key,
|
|
|
|
LanguageMode language_mode) final {
|
2011-08-04 11:42:14 +00:00
|
|
|
// External arrays always ignore deletes.
|
|
|
|
}
|
2012-03-05 16:14:34 +00:00
|
|
|
|
2015-06-11 20:17:25 +00:00
|
|
|
static uint32_t GetIndexForKeyImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store,
|
|
|
|
uint32_t key) {
|
|
|
|
return key < AccessorClass::GetCapacityImpl(holder, backing_store)
|
|
|
|
? key
|
|
|
|
: 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 EXTERNAL_ELEMENTS_ACCESSOR(Type, type, TYPE, ctype, size) \
|
|
|
|
typedef TypedElementsAccessor<EXTERNAL_##TYPE##_ELEMENTS> \
|
|
|
|
External##Type##ElementsAccessor;
|
2011-08-03 11:12:46 +00:00
|
|
|
|
2014-01-24 16:01:15 +00:00
|
|
|
TYPED_ARRAYS(EXTERNAL_ELEMENTS_ACCESSOR)
|
|
|
|
#undef EXTERNAL_ELEMENTS_ACCESSOR
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DictionaryElementsAccessor
|
|
|
|
: public ElementsAccessorBase<DictionaryElementsAccessor,
|
2012-03-09 13:48:29 +00:00
|
|
|
ElementsKindTraits<DICTIONARY_ELEMENTS> > {
|
2011-08-03 11:12:46 +00:00
|
|
|
public:
|
2012-03-06 12:03:14 +00:00
|
|
|
explicit DictionaryElementsAccessor(const char* name)
|
|
|
|
: ElementsAccessorBase<DictionaryElementsAccessor,
|
2012-03-09 13:48:29 +00:00
|
|
|
ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {}
|
2012-03-06 12:03:14 +00:00
|
|
|
|
2015-06-19 14:56:57 +00:00
|
|
|
static void SetLengthImpl(Handle<JSArray> array, uint32_t length,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
|
|
|
uint32_t new_length =
|
|
|
|
SetLengthWithoutNormalize(backing_store, array, length);
|
|
|
|
// SetLengthWithoutNormalize does not allow length to drop below the last
|
|
|
|
// non-deletable element.
|
|
|
|
DCHECK_GE(new_length, length);
|
|
|
|
if (new_length <= Smi::kMaxValue) {
|
|
|
|
array->set_length(Smi::FromInt(new_length));
|
|
|
|
} else {
|
|
|
|
Isolate* isolate = array->GetIsolate();
|
|
|
|
Handle<Object> length_obj =
|
|
|
|
isolate->factory()->NewNumberFromUint(new_length);
|
|
|
|
array->set_length(*length_obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-08 11:59:56 +00:00
|
|
|
// Adjusts the length of the dictionary backing store and returns the new
|
|
|
|
// length according to ES5 section 15.4.5.2 behavior.
|
2015-06-19 14:56:57 +00:00
|
|
|
static uint32_t SetLengthWithoutNormalize(Handle<FixedArrayBase> store,
|
|
|
|
Handle<JSArray> array,
|
|
|
|
uint32_t length) {
|
2014-04-09 14:26:32 +00:00
|
|
|
Handle<SeededNumberDictionary> dict =
|
|
|
|
Handle<SeededNumberDictionary>::cast(store);
|
|
|
|
Isolate* isolate = array->GetIsolate();
|
2012-09-19 11:52:33 +00:00
|
|
|
int capacity = dict->Capacity();
|
2015-06-19 14:56:57 +00:00
|
|
|
uint32_t old_length = 0;
|
|
|
|
CHECK(array->length()->ToArrayLength(&old_length));
|
|
|
|
if (length < old_length) {
|
2012-09-19 11:52:33 +00:00
|
|
|
// Find last non-deletable element in range of elements to be
|
|
|
|
// deleted and adjust range accordingly.
|
|
|
|
for (int i = 0; i < capacity; i++) {
|
2014-04-09 14:26:32 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2012-09-19 11:52:33 +00:00
|
|
|
Object* key = dict->KeyAt(i);
|
|
|
|
if (key->IsNumber()) {
|
|
|
|
uint32_t number = static_cast<uint32_t>(key->Number());
|
2015-06-19 14:56:57 +00:00
|
|
|
if (length <= number && number < old_length) {
|
2012-09-19 11:52:33 +00:00
|
|
|
PropertyDetails details = dict->DetailsAt(i);
|
2015-06-19 14:56:57 +00:00
|
|
|
if (!details.IsConfigurable()) length = number + 1;
|
2012-09-19 11:52:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 14:56:57 +00:00
|
|
|
if (length == 0) {
|
2014-06-13 12:12:42 +00:00
|
|
|
// Flush the backing store.
|
2014-04-09 14:26:32 +00:00
|
|
|
JSObject::ResetElements(array);
|
2011-11-08 11:59:56 +00:00
|
|
|
} else {
|
2014-04-09 14:26:32 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2012-09-19 11:52:33 +00:00
|
|
|
// Remove elements that should be deleted.
|
|
|
|
int removed_entries = 0;
|
2014-04-25 13:21:16 +00:00
|
|
|
Handle<Object> the_hole_value = isolate->factory()->the_hole_value();
|
2012-09-19 11:52:33 +00:00
|
|
|
for (int i = 0; i < capacity; i++) {
|
|
|
|
Object* key = dict->KeyAt(i);
|
|
|
|
if (key->IsNumber()) {
|
|
|
|
uint32_t number = static_cast<uint32_t>(key->Number());
|
2015-06-19 14:56:57 +00:00
|
|
|
if (length <= number && number < old_length) {
|
2012-09-19 11:52:33 +00:00
|
|
|
dict->SetEntry(i, the_hole_value, the_hole_value);
|
|
|
|
removed_entries++;
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-19 11:52:33 +00:00
|
|
|
|
|
|
|
// Update the number of elements.
|
|
|
|
dict->ElementsRemoved(removed_entries);
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
2015-06-19 14:56:57 +00:00
|
|
|
return length;
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 11:52:30 +00:00
|
|
|
static void DeleteCommon(Handle<JSObject> obj, uint32_t key,
|
|
|
|
LanguageMode language_mode) {
|
2011-08-04 11:42:14 +00:00
|
|
|
Isolate* isolate = obj->GetIsolate();
|
2014-04-09 15:45:12 +00:00
|
|
|
Handle<FixedArray> backing_store(FixedArray::cast(obj->elements()),
|
|
|
|
isolate);
|
2011-08-04 11:42:14 +00:00
|
|
|
bool is_arguments =
|
2014-03-11 14:39:08 +00:00
|
|
|
(obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS);
|
2011-08-04 11:42:14 +00:00
|
|
|
if (is_arguments) {
|
2014-04-09 15:45:12 +00:00
|
|
|
backing_store = handle(FixedArray::cast(backing_store->get(1)), isolate);
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
2014-04-09 15:45:12 +00:00
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
Handle<SeededNumberDictionary>::cast(backing_store);
|
2011-08-17 16:15:30 +00:00
|
|
|
int entry = dictionary->FindEntry(key);
|
2012-01-16 09:44:35 +00:00
|
|
|
if (entry != SeededNumberDictionary::kNotFound) {
|
2015-06-02 11:52:30 +00:00
|
|
|
Handle<Object> result =
|
|
|
|
SeededNumberDictionary::DeleteProperty(dictionary, entry);
|
|
|
|
USE(result);
|
|
|
|
DCHECK(result->IsTrue());
|
2014-04-09 15:45:12 +00:00
|
|
|
Handle<FixedArray> new_elements =
|
|
|
|
SeededNumberDictionary::Shrink(dictionary, key);
|
|
|
|
|
2012-10-15 15:23:22 +00:00
|
|
|
if (is_arguments) {
|
2014-04-09 15:45:12 +00:00
|
|
|
FixedArray::cast(obj->elements())->set(1, *new_elements);
|
2012-10-15 15:23:22 +00:00
|
|
|
} else {
|
2014-04-09 15:45:12 +00:00
|
|
|
obj->set_elements(*new_elements);
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-20 10:52:22 +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) {
|
2013-01-02 10:09:42 +00:00
|
|
|
UNREACHABLE();
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-17 16:15:30 +00:00
|
|
|
protected:
|
|
|
|
friend class ElementsAccessorBase<DictionaryElementsAccessor,
|
2012-03-09 13:48:29 +00:00
|
|
|
ElementsKindTraits<DICTIONARY_ELEMENTS> >;
|
2011-08-17 16:15:30 +00:00
|
|
|
|
2015-06-02 11:52:30 +00:00
|
|
|
virtual void Delete(Handle<JSObject> obj, uint32_t key,
|
|
|
|
LanguageMode language_mode) final {
|
|
|
|
DeleteCommon(obj, key, language_mode);
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static Handle<Object> GetImpl(Handle<JSObject> obj, uint32_t key,
|
|
|
|
Handle<FixedArrayBase> store) {
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<SeededNumberDictionary> backing_store =
|
|
|
|
Handle<SeededNumberDictionary>::cast(store);
|
|
|
|
Isolate* isolate = backing_store->GetIsolate();
|
2011-08-18 09:51:08 +00:00
|
|
|
int entry = backing_store->FindEntry(key);
|
2012-01-16 09:44:35 +00:00
|
|
|
if (entry != SeededNumberDictionary::kNotFound) {
|
2015-06-02 10:42:16 +00:00
|
|
|
return handle(backing_store->ValueAt(entry), isolate);
|
2011-08-18 09:51:08 +00:00
|
|
|
}
|
2014-04-08 14:20:29 +00:00
|
|
|
return isolate->factory()->the_hole_value();
|
2011-08-03 11:12:46 +00:00
|
|
|
}
|
2011-08-10 10:51:01 +00:00
|
|
|
|
2015-06-19 09:25:16 +00:00
|
|
|
static void SetImpl(FixedArrayBase* store, uint32_t key, Object* value) {
|
|
|
|
SeededNumberDictionary* backing_store = SeededNumberDictionary::cast(store);
|
2015-06-11 15:07:00 +00:00
|
|
|
int entry = backing_store->FindEntry(key);
|
|
|
|
DCHECK_NE(SeededNumberDictionary::kNotFound, entry);
|
2015-06-19 09:25:16 +00:00
|
|
|
backing_store->ValueAtPut(entry, value);
|
2015-06-11 15:07:00 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static MaybeHandle<AccessorPair> GetAccessorPairImpl(
|
|
|
|
Handle<JSObject> obj, uint32_t key, Handle<FixedArrayBase> store) {
|
2014-04-07 09:20:44 +00:00
|
|
|
Handle<SeededNumberDictionary> backing_store =
|
|
|
|
Handle<SeededNumberDictionary>::cast(store);
|
2012-11-15 11:31:40 +00:00
|
|
|
int entry = backing_store->FindEntry(key);
|
|
|
|
if (entry != SeededNumberDictionary::kNotFound &&
|
2015-01-19 17:49:13 +00:00
|
|
|
backing_store->DetailsAt(entry).type() == ACCESSOR_CONSTANT &&
|
2012-11-15 11:31:40 +00:00
|
|
|
backing_store->ValueAt(entry)->IsAccessorPair()) {
|
2014-04-07 09:20:44 +00:00
|
|
|
return handle(AccessorPair::cast(backing_store->ValueAt(entry)));
|
2012-11-15 11:31:40 +00:00
|
|
|
}
|
2014-04-07 09:20:44 +00:00
|
|
|
return MaybeHandle<AccessorPair>();
|
2012-11-15 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static bool HasIndexImpl(FixedArrayBase* store, uint32_t index) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
SeededNumberDictionary* dict = SeededNumberDictionary::cast(store);
|
|
|
|
Object* key = dict->KeyAt(index);
|
|
|
|
return !key->IsTheHole();
|
|
|
|
}
|
|
|
|
|
2015-05-21 12:19:39 +00:00
|
|
|
static uint32_t GetKeyForIndexImpl(FixedArrayBase* store, uint32_t index) {
|
2014-04-09 12:56:24 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2015-05-21 12:19:39 +00:00
|
|
|
SeededNumberDictionary* dict = SeededNumberDictionary::cast(store);
|
2011-08-17 16:15:30 +00:00
|
|
|
Object* key = dict->KeyAt(index);
|
|
|
|
return Smi::cast(key)->value();
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
2015-05-21 12:19:39 +00:00
|
|
|
|
2015-06-11 20:17:25 +00:00
|
|
|
static uint32_t GetIndexForKeyImpl(JSObject* holder, FixedArrayBase* store,
|
|
|
|
uint32_t key) {
|
2015-05-21 12:19:39 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
SeededNumberDictionary* dict = SeededNumberDictionary::cast(store);
|
|
|
|
int entry = dict->FindEntry(key);
|
2015-06-11 20:17:25 +00:00
|
|
|
return entry == SeededNumberDictionary::kNotFound
|
|
|
|
? kMaxUInt32
|
|
|
|
: static_cast<uint32_t>(entry);
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store,
|
|
|
|
uint32_t index) {
|
|
|
|
return SeededNumberDictionary::cast(backing_store)->DetailsAt(index);
|
|
|
|
}
|
2011-08-03 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-11 14:39:08 +00:00
|
|
|
class SloppyArgumentsElementsAccessor : public ElementsAccessorBase<
|
|
|
|
SloppyArgumentsElementsAccessor,
|
|
|
|
ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> > {
|
2012-03-06 12:03:14 +00:00
|
|
|
public:
|
2014-03-11 14:39:08 +00:00
|
|
|
explicit SloppyArgumentsElementsAccessor(const char* name)
|
2012-03-09 13:48:29 +00:00
|
|
|
: ElementsAccessorBase<
|
2014-03-11 14:39:08 +00:00
|
|
|
SloppyArgumentsElementsAccessor,
|
|
|
|
ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> >(name) {}
|
2011-08-17 16:15:30 +00:00
|
|
|
protected:
|
2012-03-09 13:48:29 +00:00
|
|
|
friend class ElementsAccessorBase<
|
2014-03-11 14:39:08 +00:00
|
|
|
SloppyArgumentsElementsAccessor,
|
|
|
|
ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> >;
|
2011-08-17 16:15:30 +00:00
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static Handle<Object> GetImpl(Handle<JSObject> obj, uint32_t key,
|
|
|
|
Handle<FixedArrayBase> parameters) {
|
2014-04-08 14:20:29 +00:00
|
|
|
Isolate* isolate = obj->GetIsolate();
|
|
|
|
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters);
|
2015-06-02 10:42:16 +00:00
|
|
|
Handle<Object> probe(GetParameterMapArg(*parameter_map, key), isolate);
|
2011-08-17 16:15:30 +00:00
|
|
|
if (!probe->IsTheHole()) {
|
2014-04-08 14:20:29 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2011-08-03 11:12:46 +00:00
|
|
|
Context* context = Context::cast(parameter_map->get(0));
|
2015-02-19 09:04:49 +00:00
|
|
|
int context_index = Handle<Smi>::cast(probe)->value();
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!context->get(context_index)->IsTheHole());
|
2014-04-08 14:20:29 +00:00
|
|
|
return handle(context->get(context_index), isolate);
|
2011-08-03 11:12:46 +00:00
|
|
|
} else {
|
|
|
|
// Object is not mapped, defer to the arguments.
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)),
|
|
|
|
isolate);
|
2015-06-02 10:42:16 +00:00
|
|
|
Handle<Object> result =
|
|
|
|
ElementsAccessor::ForArray(arguments)->Get(obj, key, arguments);
|
2012-02-24 14:34:01 +00:00
|
|
|
// Elements of the arguments object in slow mode might be slow aliases.
|
|
|
|
if (result->IsAliasedArgumentsEntry()) {
|
2014-04-08 14:20:29 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
AliasedArgumentsEntry* entry = AliasedArgumentsEntry::cast(*result);
|
2012-02-24 14:34:01 +00:00
|
|
|
Context* context = Context::cast(parameter_map->get(0));
|
|
|
|
int context_index = entry->aliased_context_slot();
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!context->get(context_index)->IsTheHole());
|
2014-04-08 14:20:29 +00:00
|
|
|
return handle(context->get(context_index), isolate);
|
2012-02-24 14:34:01 +00:00
|
|
|
} else {
|
|
|
|
return result;
|
|
|
|
}
|
2011-08-03 11:12:46 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-04 11:42:14 +00:00
|
|
|
|
2015-06-19 09:25:16 +00:00
|
|
|
static void SetImpl(FixedArrayBase* store, uint32_t key, Object* value) {
|
|
|
|
FixedArray* parameter_map = FixedArray::cast(store);
|
|
|
|
Object* probe = GetParameterMapArg(parameter_map, key);
|
2015-06-11 15:07:00 +00:00
|
|
|
if (!probe->IsTheHole()) {
|
|
|
|
Context* context = Context::cast(parameter_map->get(0));
|
|
|
|
int context_index = Smi::cast(probe)->value();
|
|
|
|
DCHECK(!context->get(context_index)->IsTheHole());
|
2015-06-19 09:25:16 +00:00
|
|
|
context->set(context_index, 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-06-18 19:49:31 +00:00
|
|
|
ElementsAccessor::ForArray(arguments)->Set(arguments, key, value);
|
2015-06-11 15:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static MaybeHandle<AccessorPair> GetAccessorPairImpl(
|
|
|
|
Handle<JSObject> obj, uint32_t key, Handle<FixedArrayBase> parameters) {
|
2014-04-07 09:20:44 +00:00
|
|
|
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters);
|
2015-06-02 10:42:16 +00:00
|
|
|
Handle<Object> probe(GetParameterMapArg(*parameter_map, key),
|
|
|
|
obj->GetIsolate());
|
2012-11-15 11:31:40 +00:00
|
|
|
if (!probe->IsTheHole()) {
|
2014-04-07 09:20:44 +00:00
|
|
|
return MaybeHandle<AccessorPair>();
|
2012-11-15 11:31:40 +00:00
|
|
|
} else {
|
|
|
|
// If not aliased, check the arguments.
|
2014-04-07 09:20:44 +00:00
|
|
|
Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
|
2015-02-19 09:04:49 +00:00
|
|
|
return ElementsAccessor::ForArray(arguments)
|
2015-02-19 08:13:33 +00:00
|
|
|
->GetAccessorPair(obj, key, arguments);
|
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> parameter_map) {
|
|
|
|
// Sloppy arguments objects are not arrays.
|
|
|
|
UNREACHABLE();
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 11:52:30 +00:00
|
|
|
virtual void Delete(Handle<JSObject> obj, uint32_t key,
|
|
|
|
LanguageMode language_mode) final {
|
2014-03-20 10:52:22 +00:00
|
|
|
Isolate* isolate = obj->GetIsolate();
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArray> parameter_map(FixedArray::cast(obj->elements()));
|
2015-06-02 10:42:16 +00:00
|
|
|
Handle<Object> probe(GetParameterMapArg(*parameter_map, key), isolate);
|
2011-08-17 16:15:30 +00:00
|
|
|
if (!probe->IsTheHole()) {
|
2011-08-04 11:42:14 +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.
|
2011-08-17 16:15:30 +00:00
|
|
|
parameter_map->set_the_hole(key + 2);
|
2011-08-04 11:42:14 +00:00
|
|
|
} else {
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
|
2011-08-04 11:42:14 +00:00
|
|
|
if (arguments->IsDictionary()) {
|
2015-06-02 11:52:30 +00:00
|
|
|
DictionaryElementsAccessor::DeleteCommon(obj, key, language_mode);
|
2011-08-04 11:42:14 +00:00
|
|
|
} else {
|
2012-05-23 14:24:29 +00:00
|
|
|
// It's difficult to access the version of DeleteCommon that is declared
|
|
|
|
// in the templatized super class, call the concrete implementation in
|
|
|
|
// the class for the most generalized ElementsKind subclass.
|
2015-06-02 11:52:30 +00:00
|
|
|
FastHoleyObjectElementsAccessor::DeleteCommon(obj, key, language_mode);
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-10 10:51:01 +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) {
|
2013-01-02 10:09:42 +00:00
|
|
|
UNREACHABLE();
|
2012-03-09 13:48:29 +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 +
|
|
|
|
ForArray(arguments)->GetCapacity(holder, arguments);
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static bool HasIndexImpl(FixedArrayBase* parameters, uint32_t index) {
|
|
|
|
FixedArray* parameter_map = FixedArray::cast(parameters);
|
|
|
|
uint32_t length = parameter_map->length() - 2;
|
|
|
|
if (index < length) {
|
|
|
|
return !GetParameterMapArg(parameter_map, index)->IsTheHole();
|
|
|
|
}
|
|
|
|
|
|
|
|
FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1));
|
|
|
|
return ForArray(arguments)->HasIndex(arguments, index - length);
|
2011-08-17 16:15:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static uint32_t GetKeyForIndexImpl(FixedArrayBase* parameters,
|
|
|
|
uint32_t index) {
|
|
|
|
FixedArray* parameter_map = FixedArray::cast(parameters);
|
|
|
|
uint32_t length = parameter_map->length() - 2;
|
|
|
|
if (index < length) return index;
|
|
|
|
|
|
|
|
FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
|
|
|
|
return ForArray(arguments)->GetKeyForIndex(arguments, index - length);
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 20:17:25 +00:00
|
|
|
static uint32_t GetIndexForKeyImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* parameters, uint32_t key) {
|
2015-06-02 10:42:16 +00:00
|
|
|
FixedArray* parameter_map = FixedArray::cast(parameters);
|
|
|
|
Object* probe = GetParameterMapArg(parameter_map, key);
|
|
|
|
if (!probe->IsTheHole()) return key;
|
|
|
|
|
|
|
|
FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
|
2015-06-11 20:17:25 +00:00
|
|
|
uint32_t index = ElementsAccessor::ForArray(arguments)
|
|
|
|
->GetIndexForKey(holder, arguments, key);
|
|
|
|
if (index == kMaxUInt32) return index;
|
|
|
|
return (parameter_map->length() - 2) + index;
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:42:16 +00:00
|
|
|
static PropertyDetails GetDetailsImpl(FixedArrayBase* parameters,
|
|
|
|
uint32_t index) {
|
|
|
|
FixedArray* parameter_map = FixedArray::cast(parameters);
|
|
|
|
uint32_t length = parameter_map->length() - 2;
|
|
|
|
if (index < length) {
|
|
|
|
return PropertyDetails(NONE, DATA, 0, PropertyCellType::kNoCell);
|
|
|
|
}
|
|
|
|
index -= length;
|
|
|
|
FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
|
|
|
|
return ElementsAccessor::ForArray(arguments)->GetDetails(arguments, index);
|
|
|
|
}
|
2015-05-21 12:19:39 +00:00
|
|
|
|
2011-08-17 16:15:30 +00:00
|
|
|
private:
|
2015-06-02 10:42:16 +00:00
|
|
|
static Object* GetParameterMapArg(FixedArray* parameter_map, uint32_t key) {
|
|
|
|
uint32_t length = parameter_map->length() - 2;
|
|
|
|
return key < length
|
|
|
|
? parameter_map->get(key + 2)
|
|
|
|
: Object::cast(parameter_map->GetHeap()->the_hole_value());
|
2014-03-20 10:52:22 +00:00
|
|
|
}
|
2011-08-03 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-05-21 12:19:39 +00:00
|
|
|
ElementsAccessor* ElementsAccessor::ForArray(FixedArrayBase* array) {
|
|
|
|
return elements_accessors_[ElementsKindForArray(array)];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-19 09:04:49 +00:00
|
|
|
ElementsAccessor* ElementsAccessor::ForArray(Handle<FixedArrayBase> array) {
|
2015-05-21 12:19:39 +00:00
|
|
|
return ForArray(*array);
|
2011-08-17 16:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-03 11:12:46 +00:00
|
|
|
void ElementsAccessor::InitializeOncePerProcess() {
|
|
|
|
static ElementsAccessor* accessor_array[] = {
|
2012-03-27 10:51:13 +00:00
|
|
|
#define ACCESSOR_ARRAY(Class, Kind, Store) new Class(#Kind),
|
2011-11-18 08:59:33 +00:00
|
|
|
ELEMENTS_LIST(ACCESSOR_ARRAY)
|
|
|
|
#undef ACCESSOR_ARRAY
|
2011-08-03 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
2011-09-22 11:30:04 +00:00
|
|
|
STATIC_ASSERT((sizeof(accessor_array) / sizeof(*accessor_array)) ==
|
|
|
|
kElementsKindCount);
|
|
|
|
|
2011-08-03 11:12:46 +00:00
|
|
|
elements_accessors_ = accessor_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-27 10:51:13 +00:00
|
|
|
void ElementsAccessor::TearDown() {
|
2014-08-26 13:07:18 +00:00
|
|
|
if (elements_accessors_ == NULL) return;
|
2012-03-27 10:51:13 +00:00
|
|
|
#define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind];
|
|
|
|
ELEMENTS_LIST(ACCESSOR_DELETE)
|
|
|
|
#undef ACCESSOR_DELETE
|
|
|
|
elements_accessors_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
// Normalize if the length does not fit in a smi. Fast mode arrays only
|
|
|
|
// support smi length.
|
|
|
|
if (JSArray::SetLengthWouldNormalize(array->GetHeap(), length)) {
|
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
JSObject::NormalizeElements(array);
|
|
|
|
DCHECK(!dictionary.is_null());
|
|
|
|
DictionaryElementsAccessor::SetLengthImpl(array, length, dictionary);
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
uint32_t max = Smi::kMaxValue;
|
|
|
|
DCHECK_LE(length, max);
|
|
|
|
#endif
|
|
|
|
uint32_t new_length = ElementsAccessorSubclass::SetLengthWithoutNormalize(
|
|
|
|
backing_store, array, length);
|
|
|
|
DCHECK_EQ(length, new_length);
|
|
|
|
array->set_length(Smi::FromInt(new_length));
|
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);
|
2013-03-01 16:06:34 +00:00
|
|
|
for (int index = 0; index < number_of_elements; index++) {
|
|
|
|
smi_elms->set(index, (*args)[index], SKIP_WRITE_BARRIER);
|
|
|
|
}
|
|
|
|
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);
|
2013-03-01 16:06:34 +00:00
|
|
|
for (int index = 0; index < number_of_elements; index++) {
|
|
|
|
object_elms->set(index, (*args)[index], mode);
|
|
|
|
}
|
|
|
|
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);
|
2013-03-01 16:06:34 +00:00
|
|
|
for (int index = 0; index < number_of_elements; index++) {
|
|
|
|
double_elms->set(index, (*args)[index]->Number());
|
|
|
|
}
|
|
|
|
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-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|