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"
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
2011-08-03 11:12:46 +00:00
|
|
|
ElementsAccessor** ElementsAccessor::elements_accessors_;
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (element->IsSmi() && element == key) return true;
|
|
|
|
if (element->IsString() &&
|
|
|
|
key->IsString() && String::cast(element)->Equals(String::cast(key))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-09 13:16:19 +00:00
|
|
|
MUST_USE_RESULT
|
|
|
|
static MaybeHandle<Object> ThrowArrayLengthRangeError(Isolate* isolate) {
|
|
|
|
return isolate->Throw<Object>(
|
|
|
|
isolate->factory()->NewRangeError("invalid_array_length",
|
|
|
|
HandleVector<Object>(NULL, 0)));
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-27 16:41:09 +00:00
|
|
|
static void CopyObjectToObjectElements(Handle<FixedArrayBase> from_base,
|
2012-11-15 12:19:14 +00:00
|
|
|
ElementsKind from_kind,
|
|
|
|
uint32_t from_start,
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArrayBase> to_base,
|
2012-11-15 12:19:14 +00:00
|
|
|
ElementsKind to_kind,
|
|
|
|
uint32_t to_start,
|
|
|
|
int raw_copy_size) {
|
2013-09-10 14:30:36 +00:00
|
|
|
ASSERT(to_base->map() !=
|
|
|
|
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) {
|
|
|
|
ASSERT(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
|
|
|
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-03-27 16:41:09 +00:00
|
|
|
MemsetPointer(Handle<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
|
|
|
}
|
2012-11-29 15:58:16 +00:00
|
|
|
ASSERT((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2012-03-09 13:48:29 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArray> from = Handle<FixedArray>::cast(from_base);
|
|
|
|
Handle<FixedArray> to = Handle<FixedArray>::cast(to_base);
|
2012-05-23 14:24:29 +00:00
|
|
|
ASSERT(IsFastSmiOrObjectElementsKind(from_kind));
|
|
|
|
ASSERT(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-03-27 16:41:09 +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-03-27 16:41:09 +00:00
|
|
|
heap->incremental_marking()->RecordWrites(*to);
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-27 16:41:09 +00:00
|
|
|
static void CopyDictionaryToObjectElements(Handle<FixedArrayBase> from_base,
|
2012-03-09 13:48:29 +00:00
|
|
|
uint32_t from_start,
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArrayBase> to_base,
|
2012-03-09 13:48:29 +00:00
|
|
|
ElementsKind to_kind,
|
|
|
|
uint32_t to_start,
|
2012-03-25 15:16:06 +00:00
|
|
|
int raw_copy_size) {
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<SeededNumberDictionary> from =
|
|
|
|
Handle<SeededNumberDictionary>::cast(from_base);
|
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;
|
|
|
|
Heap* heap = from->GetHeap();
|
|
|
|
if (raw_copy_size < 0) {
|
|
|
|
ASSERT(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
|
|
|
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-03-27 16:41:09 +00:00
|
|
|
MemsetPointer(Handle<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-03-27 16:41:09 +00:00
|
|
|
ASSERT(*to_base != *from_base);
|
2012-05-23 14:24:29 +00:00
|
|
|
ASSERT(IsFastSmiOrObjectElementsKind(to_kind));
|
2012-03-16 13:59:59 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArray> to = Handle<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);
|
|
|
|
ASSERT(!value->IsTheHole());
|
|
|
|
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-03-27 16:41:09 +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-03-27 16:41:09 +00:00
|
|
|
heap->incremental_marking()->RecordWrites(*to);
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-27 16:41:09 +00:00
|
|
|
static void CopyDoubleToObjectElements(Handle<FixedArrayBase> from_base,
|
|
|
|
uint32_t from_start,
|
|
|
|
Handle<FixedArrayBase> to_base,
|
|
|
|
ElementsKind to_kind,
|
|
|
|
uint32_t to_start,
|
|
|
|
int raw_copy_size) {
|
2012-05-23 14:24:29 +00:00
|
|
|
ASSERT(IsFastSmiOrObjectElementsKind(to_kind));
|
2012-03-16 13:59:59 +00:00
|
|
|
int copy_size = raw_copy_size;
|
|
|
|
if (raw_copy_size < 0) {
|
|
|
|
ASSERT(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
|
|
|
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-03-27 16:41:09 +00:00
|
|
|
MemsetPointer(Handle<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
|
|
|
}
|
2012-11-29 15:58:16 +00:00
|
|
|
ASSERT((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2014-03-27 16:41:09 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-04-03 09:12:59 +00:00
|
|
|
Isolate* isolate = from_base->GetIsolate();
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedDoubleArray> from = Handle<FixedDoubleArray>::cast(from_base);
|
|
|
|
Handle<FixedArray> to = Handle<FixedArray>::cast(to_base);
|
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 {
|
2012-05-23 14:24:29 +00:00
|
|
|
ASSERT(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-03-27 16:41:09 +00:00
|
|
|
static void CopyDoubleToDoubleElements(Handle<FixedArrayBase> from_base,
|
2012-03-09 13:48:29 +00:00
|
|
|
uint32_t from_start,
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArrayBase> to_base,
|
2012-03-09 13:48:29 +00:00
|
|
|
uint32_t to_start,
|
2012-03-16 13:59:59 +00:00
|
|
|
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) {
|
|
|
|
ASSERT(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
|
|
|
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-03-27 16:41:09 +00:00
|
|
|
Handle<FixedDoubleArray>::cast(to_base)->set_the_hole(i);
|
2012-03-16 13:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
2012-11-29 15:58:16 +00:00
|
|
|
ASSERT((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2012-03-09 13:48:29 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedDoubleArray> from = Handle<FixedDoubleArray>::cast(from_base);
|
|
|
|
Handle<FixedDoubleArray> to = Handle<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-03-27 16:41:09 +00:00
|
|
|
static void CopySmiToDoubleElements(Handle<FixedArrayBase> from_base,
|
2012-06-12 15:30:16 +00:00
|
|
|
uint32_t from_start,
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArrayBase> to_base,
|
2012-06-12 15:30:16 +00:00
|
|
|
uint32_t to_start,
|
|
|
|
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) {
|
|
|
|
ASSERT(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
|
|
|
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-03-27 16:41:09 +00:00
|
|
|
Handle<FixedDoubleArray>::cast(to_base)->set_the_hole(i);
|
2012-06-12 15:30:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-29 15:58:16 +00:00
|
|
|
ASSERT((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2012-06-12 15:30:16 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArray> from = Handle<FixedArray>::cast(from_base);
|
|
|
|
Handle<FixedDoubleArray> to = Handle<FixedDoubleArray>::cast(to_base);
|
|
|
|
Handle<Object> the_hole = from->GetIsolate()->factory()->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-03-27 16:41:09 +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-03-27 16:41:09 +00:00
|
|
|
static void CopyPackedSmiToDoubleElements(Handle<FixedArrayBase> from_base,
|
2012-06-12 15:30:16 +00:00
|
|
|
uint32_t from_start,
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArrayBase> to_base,
|
2012-06-12 15:30:16 +00:00
|
|
|
uint32_t to_start,
|
|
|
|
int packed_size,
|
|
|
|
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) {
|
|
|
|
ASSERT(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
|
|
|
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-03-27 16:41:09 +00:00
|
|
|
Handle<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);
|
|
|
|
}
|
2012-11-29 15:58:16 +00:00
|
|
|
ASSERT(static_cast<int>(to_end) <= to_base->length());
|
2012-06-12 15:30:16 +00:00
|
|
|
ASSERT(packed_size >= 0 && packed_size <= copy_size);
|
2012-11-29 15:58:16 +00:00
|
|
|
ASSERT((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2012-06-12 15:30:16 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArray> from = Handle<FixedArray>::cast(from_base);
|
|
|
|
Handle<FixedDoubleArray> to = Handle<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);
|
|
|
|
ASSERT(!smi->IsTheHole());
|
|
|
|
to->set(to_start, Smi::cast(smi)->value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-27 16:41:09 +00:00
|
|
|
static void CopyObjectToDoubleElements(Handle<FixedArrayBase> from_base,
|
2012-03-16 13:59:59 +00:00
|
|
|
uint32_t from_start,
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<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;
|
2012-03-16 13:59:59 +00:00
|
|
|
int copy_size = raw_copy_size;
|
|
|
|
if (raw_copy_size < 0) {
|
|
|
|
ASSERT(raw_copy_size == ElementsAccessor::kCopyToEnd ||
|
|
|
|
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-03-27 16:41:09 +00:00
|
|
|
Handle<FixedDoubleArray>::cast(to_base)->set_the_hole(i);
|
2012-03-16 13:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-29 15:58:16 +00:00
|
|
|
ASSERT((copy_size + static_cast<int>(to_start)) <= to_base->length() &&
|
|
|
|
(copy_size + static_cast<int>(from_start)) <= from_base->length());
|
2012-03-16 13:59:59 +00:00
|
|
|
if (copy_size == 0) return;
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArray> from = Handle<FixedArray>::cast(from_base);
|
|
|
|
Handle<FixedDoubleArray> to = Handle<FixedDoubleArray>::cast(to_base);
|
|
|
|
Handle<Object> the_hole = from->GetIsolate()->factory()->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-03-27 16:41:09 +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-03-27 16:41:09 +00:00
|
|
|
static void CopyDictionaryToDoubleElements(Handle<FixedArrayBase> from_base,
|
2012-03-16 13:59:59 +00:00
|
|
|
uint32_t from_start,
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<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
|
|
|
Handle<SeededNumberDictionary> from =
|
|
|
|
Handle<SeededNumberDictionary>::cast(from_base);
|
|
|
|
DisallowHeapAllocation no_allocation;
|
2012-03-16 13:59:59 +00:00
|
|
|
int copy_size = raw_copy_size;
|
|
|
|
if (copy_size < 0) {
|
|
|
|
ASSERT(copy_size == ElementsAccessor::kCopyToEnd ||
|
|
|
|
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-03-27 16:41:09 +00:00
|
|
|
Handle<FixedDoubleArray>::cast(to_base)->set_the_hole(i);
|
2012-03-16 13:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (copy_size == 0) return;
|
2014-03-27 16:41:09 +00:00
|
|
|
Handle<FixedDoubleArray> to = Handle<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;
|
|
|
|
|
2014-03-24 09:06:04 +00:00
|
|
|
virtual ElementsKind kind() const V8_FINAL V8_OVERRIDE {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-04-07 10:00:14 +00:00
|
|
|
virtual void Validate(Handle<JSObject> holder) V8_FINAL V8_OVERRIDE {
|
|
|
|
DisallowHeapAllocation no_gc;
|
2014-04-16 06:18:37 +00:00
|
|
|
ElementsAccessorSubclass::ValidateImpl(holder);
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
|
2014-04-08 14:20:29 +00:00
|
|
|
static bool HasElementImpl(Handle<Object> receiver,
|
|
|
|
Handle<JSObject> holder,
|
2012-03-06 12:22:18 +00:00
|
|
|
uint32_t key,
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2012-11-12 11:08:34 +00:00
|
|
|
return ElementsAccessorSubclass::GetAttributesImpl(
|
2014-04-09 12:56:24 +00:00
|
|
|
receiver, holder, key, backing_store) != ABSENT;
|
2012-03-06 12:22:18 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 13:05:37 +00:00
|
|
|
virtual bool HasElement(
|
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
uint32_t key,
|
|
|
|
Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE {
|
2012-03-06 12:22:18 +00:00
|
|
|
return ElementsAccessorSubclass::HasElementImpl(
|
2014-04-08 14:20:29 +00:00
|
|
|
receiver, holder, key, backing_store);
|
2012-03-06 12:22:18 +00:00
|
|
|
}
|
|
|
|
|
2014-04-10 09:20:11 +00:00
|
|
|
MUST_USE_RESULT virtual MaybeHandle<Object> Get(
|
2014-03-20 13:16:19 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
uint32_t key,
|
2014-03-24 09:06:04 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE {
|
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
|
|
|
}
|
|
|
|
|
2012-02-17 12:59:58 +00:00
|
|
|
return ElementsAccessorSubclass::GetImpl(
|
2012-11-29 15:58:16 +00:00
|
|
|
receiver, holder, key, backing_store);
|
2011-08-18 09:51:08 +00:00
|
|
|
}
|
|
|
|
|
2014-04-10 09:20:11 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<Object> GetImpl(
|
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
|
|
|
uint32_t key,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2014-04-09 12:56:24 +00:00
|
|
|
if (key < ElementsAccessorSubclass::GetCapacityImpl(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
|
|
|
}
|
|
|
|
|
2014-04-04 13:20:24 +00:00
|
|
|
MUST_USE_RESULT virtual PropertyAttributes GetAttributes(
|
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
uint32_t key,
|
|
|
|
Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE {
|
2012-11-08 12:58:08 +00:00
|
|
|
return ElementsAccessorSubclass::GetAttributesImpl(
|
2012-11-28 08:41:45 +00:00
|
|
|
receiver, holder, key, backing_store);
|
2012-11-08 12:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MUST_USE_RESULT static PropertyAttributes GetAttributesImpl(
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
2012-11-08 12:58:08 +00:00
|
|
|
uint32_t key,
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2012-11-08 12:58:08 +00:00
|
|
|
if (key >= ElementsAccessorSubclass::GetCapacityImpl(backing_store)) {
|
|
|
|
return ABSENT;
|
|
|
|
}
|
2014-04-09 12:56:24 +00:00
|
|
|
return
|
|
|
|
Handle<BackingStore>::cast(backing_store)->is_the_hole(key)
|
|
|
|
? ABSENT : NONE;
|
2012-11-08 12:58:08 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 13:20:24 +00:00
|
|
|
MUST_USE_RESULT virtual PropertyType GetType(
|
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
uint32_t key,
|
|
|
|
Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE {
|
2012-11-15 11:31:40 +00:00
|
|
|
return ElementsAccessorSubclass::GetTypeImpl(
|
2012-11-29 15:58:16 +00:00
|
|
|
receiver, holder, key, backing_store);
|
2012-11-15 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MUST_USE_RESULT static PropertyType GetTypeImpl(
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
|
|
|
uint32_t key,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2012-11-15 11:31:40 +00:00
|
|
|
if (key >= ElementsAccessorSubclass::GetCapacityImpl(backing_store)) {
|
|
|
|
return NONEXISTENT;
|
|
|
|
}
|
2014-04-09 12:56:24 +00:00
|
|
|
return
|
|
|
|
Handle<BackingStore>::cast(backing_store)->is_the_hole(key)
|
|
|
|
? NONEXISTENT : FIELD;
|
2012-11-15 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 09:20:44 +00:00
|
|
|
MUST_USE_RESULT virtual MaybeHandle<AccessorPair> GetAccessorPair(
|
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> holder,
|
2012-11-15 11:31:40 +00:00
|
|
|
uint32_t key,
|
2014-04-07 09:20:44 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE {
|
2012-11-15 11:31:40 +00:00
|
|
|
return ElementsAccessorSubclass::GetAccessorPairImpl(
|
2012-11-29 15:58:16 +00:00
|
|
|
receiver, holder, key, backing_store);
|
2012-11-15 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 09:20:44 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl(
|
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
|
|
|
uint32_t key,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
|
|
|
return MaybeHandle<AccessorPair>();
|
2012-11-15 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 13:16:19 +00:00
|
|
|
MUST_USE_RESULT virtual MaybeHandle<Object> SetLength(
|
2014-03-19 14:09:50 +00:00
|
|
|
Handle<JSArray> array,
|
2014-03-24 09:06:04 +00:00
|
|
|
Handle<Object> length) V8_FINAL V8_OVERRIDE {
|
2012-02-17 12:59:58 +00:00
|
|
|
return ElementsAccessorSubclass::SetLengthImpl(
|
2014-03-27 16:41:09 +00:00
|
|
|
array, length, handle(array->elements()));
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 13:16:19 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
|
2014-03-19 16:29:19 +00:00
|
|
|
Handle<JSObject> obj,
|
|
|
|
Handle<Object> length,
|
|
|
|
Handle<FixedArrayBase> backing_store);
|
2011-11-08 11:59:56 +00:00
|
|
|
|
2014-03-25 09:51:13 +00:00
|
|
|
virtual void SetCapacityAndLength(
|
|
|
|
Handle<JSArray> array,
|
2012-05-23 14:24:29 +00:00
|
|
|
int capacity,
|
2014-03-24 09:06:04 +00:00
|
|
|
int length) V8_FINAL V8_OVERRIDE {
|
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
|
|
|
}
|
|
|
|
|
2014-04-09 15:45:12 +00:00
|
|
|
MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
|
2014-03-20 10:52:22 +00:00
|
|
|
Handle<JSObject> obj,
|
|
|
|
uint32_t key,
|
2014-03-24 09:06:04 +00:00
|
|
|
JSReceiver::DeleteMode mode) V8_OVERRIDE = 0;
|
2011-08-04 11:42:14 +00:00
|
|
|
|
2014-03-27 16:41:09 +00:00
|
|
|
static void CopyElementsImpl(Handle<FixedArrayBase> from,
|
|
|
|
uint32_t from_start,
|
|
|
|
Handle<FixedArrayBase> to,
|
|
|
|
ElementsKind from_kind,
|
|
|
|
uint32_t to_start,
|
|
|
|
int packed_size,
|
|
|
|
int copy_size) {
|
2012-03-09 13:48:29 +00:00
|
|
|
UNREACHABLE();
|
2014-03-21 11:22:16 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 13:01:08 +00:00
|
|
|
virtual void CopyElements(
|
2014-04-03 09:12:59 +00:00
|
|
|
Handle<FixedArrayBase> from,
|
2014-03-20 13:01:08 +00:00
|
|
|
uint32_t from_start,
|
|
|
|
ElementsKind from_kind,
|
|
|
|
Handle<FixedArrayBase> to,
|
|
|
|
uint32_t to_start,
|
2014-04-03 09:12:59 +00:00
|
|
|
int copy_size) V8_FINAL V8_OVERRIDE {
|
|
|
|
ASSERT(!from.is_null());
|
|
|
|
ElementsAccessorSubclass::CopyElementsImpl(
|
|
|
|
from, from_start, to, from_kind, to_start, kPackedSizeNotKnown,
|
|
|
|
copy_size);
|
|
|
|
}
|
2012-06-12 15:30:16 +00:00
|
|
|
|
2014-04-03 09:12:59 +00:00
|
|
|
virtual void CopyElements(
|
|
|
|
JSObject* from_holder,
|
|
|
|
uint32_t from_start,
|
|
|
|
ElementsKind from_kind,
|
|
|
|
Handle<FixedArrayBase> to,
|
|
|
|
uint32_t to_start,
|
|
|
|
int copy_size) V8_FINAL V8_OVERRIDE {
|
|
|
|
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-04-03 09:12:59 +00:00
|
|
|
Handle<FixedArrayBase> from(from_holder->elements());
|
2014-03-27 16:41:09 +00:00
|
|
|
ElementsAccessorSubclass::CopyElementsImpl(
|
2013-01-02 10:09:42 +00:00
|
|
|
from, from_start, to, from_kind, to_start, packed_size, copy_size);
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
2014-04-10 09:20:11 +00:00
|
|
|
virtual MaybeHandle<FixedArray> AddElementsToFixedArray(
|
2014-04-04 13:05:37 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<FixedArray> to,
|
|
|
|
Handle<FixedArrayBase> from) V8_FINAL V8_OVERRIDE {
|
2011-08-12 14:52:03 +00:00
|
|
|
int len0 = to->length();
|
2013-10-25 11:10:28 +00:00
|
|
|
#ifdef ENABLE_SLOW_ASSERTS
|
2011-08-10 10:51:01 +00:00
|
|
|
if (FLAG_enable_slow_asserts) {
|
|
|
|
for (int i = 0; i < len0; i++) {
|
2011-08-12 14:52:03 +00:00
|
|
|
ASSERT(!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.
|
2014-04-09 12:56:24 +00:00
|
|
|
uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(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++) {
|
2014-04-09 12:56:24 +00:00
|
|
|
uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(from, y);
|
2012-03-05 16:14:34 +00:00
|
|
|
if (ElementsAccessorSubclass::HasElementImpl(
|
2012-11-29 15:58:16 +00:00
|
|
|
receiver, holder, key, from)) {
|
2014-04-10 09:20:11 +00:00
|
|
|
Handle<Object> value;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION(
|
|
|
|
isolate, value,
|
|
|
|
ElementsAccessorSubclass::GetImpl(receiver, holder, key, from),
|
|
|
|
FixedArray);
|
2014-04-08 14:20:29 +00:00
|
|
|
|
2011-08-17 16:15:30 +00:00
|
|
|
ASSERT(!value->IsTheHole());
|
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);
|
2011-08-10 10:51:01 +00:00
|
|
|
ASSERT(e->IsString() || e->IsNumber());
|
|
|
|
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++) {
|
2012-03-05 16:14:34 +00:00
|
|
|
uint32_t key =
|
2014-04-09 12:56:24 +00:00
|
|
|
ElementsAccessorSubclass::GetKeyForIndexImpl(from, y);
|
2012-03-05 16:14:34 +00:00
|
|
|
if (ElementsAccessorSubclass::HasElementImpl(
|
2012-11-29 15:58:16 +00:00
|
|
|
receiver, holder, key, from)) {
|
2014-04-10 09:20:11 +00:00
|
|
|
Handle<Object> value;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION(
|
|
|
|
isolate, value,
|
|
|
|
ElementsAccessorSubclass::GetImpl(receiver, holder, key, from),
|
|
|
|
FixedArray);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT(extra == index);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-08-17 16:15:30 +00:00
|
|
|
protected:
|
2014-04-09 12:56:24 +00:00
|
|
|
static uint32_t GetCapacityImpl(Handle<FixedArrayBase> backing_store) {
|
2011-08-12 14:52:03 +00:00
|
|
|
return backing_store->length();
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 12:56:24 +00:00
|
|
|
virtual uint32_t GetCapacity(Handle<FixedArrayBase> backing_store)
|
2014-03-24 09:06:04 +00:00
|
|
|
V8_FINAL V8_OVERRIDE {
|
2012-11-28 08:41:45 +00:00
|
|
|
return ElementsAccessorSubclass::GetCapacityImpl(backing_store);
|
2011-08-03 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 12:56:24 +00:00
|
|
|
static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> backing_store,
|
2012-02-17 12:59:58 +00:00
|
|
|
uint32_t index) {
|
2011-08-17 16:15:30 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2014-04-04 13:05:37 +00:00
|
|
|
virtual uint32_t GetKeyForIndex(Handle<FixedArrayBase> backing_store,
|
2014-03-24 09:06:04 +00:00
|
|
|
uint32_t index) V8_FINAL V8_OVERRIDE {
|
2014-04-09 12:56:24 +00:00
|
|
|
return ElementsAccessorSubclass::GetKeyForIndexImpl(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,
|
2012-03-09 13:48:29 +00:00
|
|
|
typename KindTraits,
|
2011-11-08 11:59:56 +00:00
|
|
|
int ElementSize>
|
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
|
|
|
|
|
|
|
// Adjusts the length of the fast backing store or returns the new length or
|
|
|
|
// undefined in case conversion to a slow backing store should be performed.
|
2014-03-25 09:29:48 +00:00
|
|
|
static Handle<Object> SetLengthWithoutNormalize(
|
|
|
|
Handle<FixedArrayBase> backing_store,
|
|
|
|
Handle<JSArray> array,
|
|
|
|
Handle<Object> length_object,
|
|
|
|
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 {
|
2014-03-31 14:29:01 +00:00
|
|
|
int filler_size = (old_capacity - length) * ElementSize;
|
2011-11-08 11:59:56 +00:00
|
|
|
Address filler_start = backing_store->address() +
|
|
|
|
BackingStore::OffsetOfElementAt(length);
|
|
|
|
array->GetHeap()->CreateFillerObjectAt(filler_start, filler_size);
|
2014-03-31 14:29:01 +00:00
|
|
|
|
|
|
|
// We are storing the new length using release store after creating a
|
|
|
|
// filler for the left-over space to avoid races with the sweeper
|
|
|
|
// thread.
|
|
|
|
backing_store->synchronized_set_length(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
|
|
|
}
|
|
|
|
}
|
|
|
|
return length_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the backing store should be expanded.
|
|
|
|
uint32_t min = JSObject::NewElementsCapacity(old_capacity);
|
|
|
|
uint32_t new_capacity = length > min ? length : min;
|
|
|
|
if (!array->ShouldConvertToSlowElements(new_capacity)) {
|
2014-03-25 09:29:48 +00:00
|
|
|
FastElementsAccessorSubclass::
|
2011-11-08 11:59:56 +00:00
|
|
|
SetFastElementsCapacityAndLength(array, new_capacity, length);
|
2014-04-07 10:00:14 +00:00
|
|
|
JSObject::ValidateElements(array);
|
2011-11-08 11:59:56 +00:00
|
|
|
return length_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Request conversion to slow elements.
|
2014-03-25 09:29:48 +00:00
|
|
|
return isolate->factory()->undefined_value();
|
2014-03-19 16:29:19 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 10:52:22 +00:00
|
|
|
static Handle<Object> DeleteCommon(Handle<JSObject> obj,
|
|
|
|
uint32_t key,
|
|
|
|
JSReceiver::DeleteMode mode) {
|
2012-05-23 14:24:29 +00:00
|
|
|
ASSERT(obj->HasFastSmiOrObjectElements() ||
|
|
|
|
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());
|
2014-03-20 10:52:22 +00:00
|
|
|
if (*elements == heap->empty_fixed_array()) {
|
|
|
|
return isolate->factory()->true_value();
|
2012-11-02 10:24:56 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-20 10:52:22 +00:00
|
|
|
return isolate->factory()->true_value();
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 15:45:12 +00:00
|
|
|
virtual MaybeHandle<Object> Delete(
|
2014-03-24 09:06:04 +00:00
|
|
|
Handle<JSObject> obj,
|
|
|
|
uint32_t key,
|
|
|
|
JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
|
2012-05-23 14:24:29 +00:00
|
|
|
return DeleteCommon(obj, key, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool HasElementImpl(
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> holder,
|
2012-05-23 14:24:29 +00:00
|
|
|
uint32_t key,
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2012-05-23 14:24:29 +00:00
|
|
|
if (key >= static_cast<uint32_t>(backing_store->length())) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-08 14:20:29 +00:00
|
|
|
return !Handle<BackingStore>::cast(backing_store)->is_the_hole(key);
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 06:18:37 +00:00
|
|
|
static void ValidateContents(Handle<JSObject> holder, int length) {
|
2012-05-23 14:24:29 +00:00
|
|
|
#if DEBUG
|
2014-04-16 06:18:37 +00:00
|
|
|
Isolate* isolate = holder->GetIsolate();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<FixedArrayBase> elements(holder->elements(), isolate);
|
2012-05-23 14:24:29 +00:00
|
|
|
Map* map = elements->map();
|
|
|
|
ASSERT((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())));
|
|
|
|
DisallowHeapAllocation no_gc;
|
2012-05-23 14:24:29 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2014-04-16 06:18:37 +00:00
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements);
|
2012-05-23 14:24:29 +00:00
|
|
|
ASSERT((!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-04-09 12:56:24 +00:00
|
|
|
static inline ElementsKind ElementsKindForArray(Handle<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
|
|
|
|
: public FastElementsAccessor<FastElementsAccessorSubclass,
|
|
|
|
KindTraits,
|
|
|
|
kPointerSize> {
|
|
|
|
public:
|
|
|
|
explicit FastSmiOrObjectElementsAccessor(const char* name)
|
|
|
|
: FastElementsAccessor<FastElementsAccessorSubclass,
|
|
|
|
KindTraits,
|
|
|
|
kPointerSize>(name) {}
|
|
|
|
|
2014-03-27 16:41:09 +00:00
|
|
|
static void CopyElementsImpl(Handle<FixedArrayBase> from,
|
|
|
|
uint32_t from_start,
|
|
|
|
Handle<FixedArrayBase> to,
|
|
|
|
ElementsKind from_kind,
|
|
|
|
uint32_t to_start,
|
|
|
|
int packed_size,
|
|
|
|
int copy_size) {
|
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:
|
|
|
|
CopyObjectToObjectElements(
|
|
|
|
from, from_kind, from_start, to, to_kind, 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:
|
|
|
|
case FAST_HOLEY_DOUBLE_ELEMENTS:
|
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;
|
2013-01-02 10:09:42 +00:00
|
|
|
case DICTIONARY_ELEMENTS:
|
|
|
|
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-03-27 16:41:09 +00:00
|
|
|
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(from);
|
|
|
|
Handle<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
|
2012-05-23 14:24:29 +00:00
|
|
|
: public FastElementsAccessor<FastElementsAccessorSubclass,
|
|
|
|
KindTraits,
|
2011-11-08 11:59:56 +00:00
|
|
|
kDoubleSize> {
|
2012-03-06 12:03:14 +00:00
|
|
|
public:
|
|
|
|
explicit FastDoubleElementsAccessor(const char* name)
|
2012-05-23 14:24:29 +00:00
|
|
|
: FastElementsAccessor<FastElementsAccessorSubclass,
|
|
|
|
KindTraits,
|
2012-03-06 12:03:14 +00:00
|
|
|
kDoubleSize>(name) {}
|
|
|
|
|
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-03-27 16:41:09 +00:00
|
|
|
static void CopyElementsImpl(Handle<FixedArrayBase> from,
|
|
|
|
uint32_t from_start,
|
|
|
|
Handle<FixedArrayBase> to,
|
|
|
|
ElementsKind from_kind,
|
|
|
|
uint32_t to_start,
|
|
|
|
int packed_size,
|
|
|
|
int copy_size) {
|
2013-01-02 10:09:42 +00:00
|
|
|
switch (from_kind) {
|
2012-05-23 14:24:29 +00:00
|
|
|
case FAST_SMI_ELEMENTS:
|
2013-01-02 10:09:42 +00:00
|
|
|
CopyPackedSmiToDoubleElements(
|
|
|
|
from, from_start, to, to_start, packed_size, copy_size);
|
|
|
|
break;
|
2012-05-23 14:24:29 +00:00
|
|
|
case FAST_HOLEY_SMI_ELEMENTS:
|
2013-01-02 10:09:42 +00:00
|
|
|
CopySmiToDoubleElements(from, from_start, to, to_start, copy_size);
|
|
|
|
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:
|
2012-11-29 15:58:16 +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:
|
|
|
|
CopyObjectToDoubleElements(from, from_start, to, to_start, copy_size);
|
|
|
|
break;
|
|
|
|
case DICTIONARY_ELEMENTS:
|
|
|
|
CopyDictionaryToDoubleElements(
|
|
|
|
from, from_start, to, to_start, copy_size);
|
|
|
|
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
|
|
|
|
2014-04-10 09:20:11 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<Object> GetImpl(
|
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
|
|
|
uint32_t key,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2014-04-09 12:56:24 +00:00
|
|
|
if (key < AccessorClass::GetCapacityImpl(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
|
|
|
|
2012-11-08 12:58:08 +00:00
|
|
|
MUST_USE_RESULT static PropertyAttributes GetAttributesImpl(
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
2012-11-08 12:58:08 +00:00
|
|
|
uint32_t key,
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2012-11-08 12:58:08 +00:00
|
|
|
return
|
2014-01-24 16:01:15 +00:00
|
|
|
key < AccessorClass::GetCapacityImpl(backing_store)
|
2012-11-15 11:31:40 +00:00
|
|
|
? NONE : ABSENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
MUST_USE_RESULT static PropertyType GetTypeImpl(
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
2012-11-15 11:31:40 +00:00
|
|
|
uint32_t key,
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2012-11-15 11:31:40 +00:00
|
|
|
return
|
2014-01-24 16:01:15 +00:00
|
|
|
key < AccessorClass::GetCapacityImpl(backing_store)
|
2012-11-15 11:31:40 +00:00
|
|
|
? FIELD : NONEXISTENT;
|
2012-11-08 12:58:08 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 13:16:19 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
|
2014-03-19 16:29:19 +00:00
|
|
|
Handle<JSObject> obj,
|
|
|
|
Handle<Object> length,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2011-11-08 11:59:56 +00:00
|
|
|
// External arrays do not support changing their length.
|
|
|
|
UNREACHABLE();
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2014-04-09 15:45:12 +00:00
|
|
|
MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
|
2014-03-24 09:06:04 +00:00
|
|
|
Handle<JSObject> obj,
|
|
|
|
uint32_t key,
|
|
|
|
JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
|
2011-08-04 11:42:14 +00:00
|
|
|
// External arrays always ignore deletes.
|
2014-03-20 10:52:22 +00:00
|
|
|
return obj->GetIsolate()->factory()->true_value();
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
2012-03-05 16:14:34 +00:00
|
|
|
|
2014-04-08 14:20:29 +00:00
|
|
|
static bool HasElementImpl(Handle<Object> receiver,
|
|
|
|
Handle<JSObject> holder,
|
2012-03-06 12:22:18 +00:00
|
|
|
uint32_t key,
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) {
|
2012-03-05 16:14:34 +00:00
|
|
|
uint32_t capacity =
|
2014-04-09 12:56:24 +00:00
|
|
|
AccessorClass::GetCapacityImpl(backing_store);
|
2012-03-05 16:14:34 +00:00
|
|
|
return key < capacity;
|
|
|
|
}
|
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
|
|
|
|
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.
|
2014-04-09 14:26:32 +00:00
|
|
|
static Handle<Object> SetLengthWithoutNormalize(
|
|
|
|
Handle<FixedArrayBase> store,
|
|
|
|
Handle<JSArray> array,
|
|
|
|
Handle<Object> length_object,
|
2012-05-09 14:34:27 +00:00
|
|
|
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();
|
|
|
|
uint32_t new_length = length;
|
|
|
|
uint32_t old_length = static_cast<uint32_t>(array->length()->Number());
|
|
|
|
if (new_length < old_length) {
|
|
|
|
// 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());
|
|
|
|
if (new_length <= number && number < old_length) {
|
|
|
|
PropertyDetails details = dict->DetailsAt(i);
|
|
|
|
if (details.IsDontDelete()) new_length = number + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (new_length != length) {
|
2014-04-09 14:26:32 +00:00
|
|
|
length_object = isolate->factory()->NewNumberFromUint(new_length);
|
2012-09-19 11:52:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_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());
|
|
|
|
if (new_length <= number && number < old_length) {
|
|
|
|
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
|
|
|
}
|
|
|
|
return length_object;
|
|
|
|
}
|
|
|
|
|
2014-04-09 15:45:12 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<Object> DeleteCommon(
|
|
|
|
Handle<JSObject> obj,
|
2012-05-09 14:34:27 +00:00
|
|
|
uint32_t key,
|
|
|
|
JSReceiver::DeleteMode 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) {
|
2014-04-09 15:45:12 +00:00
|
|
|
Handle<Object> result =
|
|
|
|
SeededNumberDictionary::DeleteProperty(dictionary, entry, mode);
|
|
|
|
if (*result == *isolate->factory()->false_value()) {
|
2012-10-15 15:23:22 +00:00
|
|
|
if (mode == JSObject::STRICT_DELETION) {
|
|
|
|
// Deleting a non-configurable property in strict mode.
|
|
|
|
Handle<Object> name = isolate->factory()->NewNumberFromUint(key);
|
2014-04-09 15:45:12 +00:00
|
|
|
Handle<Object> args[2] = { name, obj };
|
2012-10-15 15:23:22 +00:00
|
|
|
Handle<Object> error =
|
|
|
|
isolate->factory()->NewTypeError("strict_delete_property",
|
|
|
|
HandleVector(args, 2));
|
2014-04-09 15:45:12 +00:00
|
|
|
return isolate->Throw<Object>(error);
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
2014-04-09 15:45:12 +00:00
|
|
|
return isolate->factory()->false_value();
|
2012-10-15 15:23:22 +00:00
|
|
|
}
|
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-04-09 15:45:12 +00:00
|
|
|
return isolate->factory()->true_value();
|
2014-03-20 10:52:22 +00:00
|
|
|
}
|
|
|
|
|
2014-03-27 16:41:09 +00:00
|
|
|
static void CopyElementsImpl(Handle<FixedArrayBase> from,
|
|
|
|
uint32_t from_start,
|
|
|
|
Handle<FixedArrayBase> to,
|
|
|
|
ElementsKind from_kind,
|
|
|
|
uint32_t to_start,
|
|
|
|
int packed_size,
|
|
|
|
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
|
|
|
|
2014-04-09 15:45:12 +00:00
|
|
|
MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
|
2014-03-24 09:06:04 +00:00
|
|
|
Handle<JSObject> obj,
|
|
|
|
uint32_t key,
|
|
|
|
JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
|
2011-08-17 16:15:30 +00:00
|
|
|
return DeleteCommon(obj, key, mode);
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
|
|
|
|
2014-04-10 09:20:11 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<Object> GetImpl(
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
2012-05-09 14:34:27 +00:00
|
|
|
uint32_t key,
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<FixedArrayBase> store) {
|
|
|
|
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) {
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<Object> element(backing_store->ValueAt(entry), isolate);
|
2011-08-18 09:51:08 +00:00
|
|
|
PropertyDetails details = backing_store->DetailsAt(entry);
|
|
|
|
if (details.type() == CALLBACKS) {
|
2014-04-08 14:20:29 +00:00
|
|
|
return JSObject::GetElementWithCallback(
|
|
|
|
obj, receiver, element, key, obj);
|
2011-08-18 09:51:08 +00:00
|
|
|
} else {
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2012-11-08 12:58:08 +00:00
|
|
|
MUST_USE_RESULT static PropertyAttributes GetAttributesImpl(
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
2012-11-08 12:58:08 +00:00
|
|
|
uint32_t key,
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) {
|
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
Handle<SeededNumberDictionary>::cast(backing_store);
|
2012-11-28 08:41:45 +00:00
|
|
|
int entry = dictionary->FindEntry(key);
|
2012-11-08 12:58:08 +00:00
|
|
|
if (entry != SeededNumberDictionary::kNotFound) {
|
2012-11-28 08:41:45 +00:00
|
|
|
return dictionary->DetailsAt(entry).attributes();
|
2012-11-08 12:58:08 +00:00
|
|
|
}
|
|
|
|
return ABSENT;
|
|
|
|
}
|
|
|
|
|
2012-11-15 11:31:40 +00:00
|
|
|
MUST_USE_RESULT static PropertyType GetTypeImpl(
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
2012-11-15 11:31:40 +00:00
|
|
|
uint32_t key,
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<FixedArrayBase> store) {
|
|
|
|
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) {
|
|
|
|
return backing_store->DetailsAt(entry).type();
|
|
|
|
}
|
|
|
|
return NONEXISTENT;
|
|
|
|
}
|
|
|
|
|
2014-04-07 09:20:44 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl(
|
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
2012-11-15 11:31:40 +00:00
|
|
|
uint32_t key,
|
2014-04-07 09:20:44 +00:00
|
|
|
Handle<FixedArrayBase> store) {
|
|
|
|
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 &&
|
|
|
|
backing_store->DetailsAt(entry).type() == CALLBACKS &&
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-04-08 14:20:29 +00:00
|
|
|
static bool HasElementImpl(Handle<Object> receiver,
|
|
|
|
Handle<JSObject> holder,
|
2012-03-06 12:22:18 +00:00
|
|
|
uint32_t key,
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<FixedArrayBase> store) {
|
|
|
|
Handle<SeededNumberDictionary> backing_store =
|
|
|
|
Handle<SeededNumberDictionary>::cast(store);
|
|
|
|
return backing_store->FindEntry(key) != SeededNumberDictionary::kNotFound;
|
2012-03-05 16:14:34 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 12:56:24 +00:00
|
|
|
static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> store,
|
2012-02-17 12:59:58 +00:00
|
|
|
uint32_t index) {
|
2014-04-09 12:56:24 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
Handle<SeededNumberDictionary> dict =
|
|
|
|
Handle<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
|
|
|
}
|
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
|
|
|
|
2014-04-10 09:20:11 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<Object> GetImpl(
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
|
|
|
uint32_t key,
|
|
|
|
Handle<FixedArrayBase> parameters) {
|
|
|
|
Isolate* isolate = obj->GetIsolate();
|
|
|
|
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters);
|
|
|
|
Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
|
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));
|
2014-04-08 14:20:29 +00:00
|
|
|
int context_index = Handle<Smi>::cast(probe)->value();
|
2011-08-03 11:12:46 +00:00
|
|
|
ASSERT(!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);
|
2014-04-10 09:20:11 +00:00
|
|
|
Handle<Object> result;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION(
|
|
|
|
isolate, result,
|
|
|
|
ElementsAccessor::ForArray(arguments)->Get(
|
|
|
|
receiver, obj, key, arguments),
|
|
|
|
Object);
|
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();
|
|
|
|
ASSERT(!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
|
|
|
|
2012-11-08 12:58:08 +00:00
|
|
|
MUST_USE_RESULT static PropertyAttributes GetAttributesImpl(
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
2012-11-08 12:58:08 +00:00
|
|
|
uint32_t key,
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<FixedArrayBase> backing_store) {
|
|
|
|
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(backing_store);
|
|
|
|
Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
|
2012-11-08 12:58:08 +00:00
|
|
|
if (!probe->IsTheHole()) {
|
|
|
|
return NONE;
|
|
|
|
} else {
|
|
|
|
// If not aliased, check the arguments.
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
|
2012-11-08 12:58:08 +00:00
|
|
|
return ElementsAccessor::ForArray(arguments)->GetAttributes(
|
|
|
|
receiver, obj, key, arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-15 11:31:40 +00:00
|
|
|
MUST_USE_RESULT static PropertyType GetTypeImpl(
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
2012-11-15 11:31:40 +00:00
|
|
|
uint32_t key,
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<FixedArrayBase> parameters) {
|
|
|
|
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters);
|
|
|
|
Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
|
2012-11-15 11:31:40 +00:00
|
|
|
if (!probe->IsTheHole()) {
|
|
|
|
return FIELD;
|
|
|
|
} else {
|
|
|
|
// If not aliased, check the arguments.
|
2014-04-09 12:56:24 +00:00
|
|
|
Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
|
2012-11-15 11:31:40 +00:00
|
|
|
return ElementsAccessor::ForArray(arguments)->GetType(
|
|
|
|
receiver, obj, key, arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-07 09:20:44 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl(
|
|
|
|
Handle<Object> receiver,
|
|
|
|
Handle<JSObject> obj,
|
2012-11-15 11:31:40 +00:00
|
|
|
uint32_t key,
|
2014-04-07 09:20:44 +00:00
|
|
|
Handle<FixedArrayBase> parameters) {
|
|
|
|
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters);
|
|
|
|
Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
|
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)));
|
2012-11-15 11:31:40 +00:00
|
|
|
return ElementsAccessor::ForArray(arguments)->GetAccessorPair(
|
|
|
|
receiver, obj, key, arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-09 13:16:19 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
|
2014-03-19 16:29:19 +00:00
|
|
|
Handle<JSObject> obj,
|
|
|
|
Handle<Object> length,
|
|
|
|
Handle<FixedArrayBase> parameter_map) {
|
2011-11-08 11:59:56 +00:00
|
|
|
// TODO(mstarzinger): This was never implemented but will be used once we
|
|
|
|
// correctly implement [[DefineOwnProperty]] on arrays.
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2014-04-09 15:45:12 +00:00
|
|
|
MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
|
2014-03-24 09:06:04 +00:00
|
|
|
Handle<JSObject> obj,
|
|
|
|
uint32_t key,
|
|
|
|
JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
|
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()));
|
2014-03-20 10:52:22 +00:00
|
|
|
Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
|
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()) {
|
2011-08-17 16:15:30 +00:00
|
|
|
return DictionaryElementsAccessor::DeleteCommon(obj, key, 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.
|
|
|
|
return FastHoleyObjectElementsAccessor::DeleteCommon(obj, key, mode);
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-20 10:52:22 +00:00
|
|
|
return isolate->factory()->true_value();
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
2011-08-10 10:51:01 +00:00
|
|
|
|
2014-03-27 16:41:09 +00:00
|
|
|
static void CopyElementsImpl(Handle<FixedArrayBase> from,
|
|
|
|
uint32_t from_start,
|
|
|
|
Handle<FixedArrayBase> to,
|
|
|
|
ElementsKind from_kind,
|
|
|
|
uint32_t to_start,
|
|
|
|
int packed_size,
|
|
|
|
int copy_size) {
|
2013-01-02 10:09:42 +00:00
|
|
|
UNREACHABLE();
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 12:56:24 +00:00
|
|
|
static uint32_t GetCapacityImpl(Handle<FixedArrayBase> backing_store) {
|
|
|
|
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(backing_store);
|
|
|
|
Handle<FixedArrayBase> arguments(
|
|
|
|
FixedArrayBase::cast(parameter_map->get(1)));
|
2011-08-17 16:15:30 +00:00
|
|
|
return Max(static_cast<uint32_t>(parameter_map->length() - 2),
|
|
|
|
ForArray(arguments)->GetCapacity(arguments));
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 12:56:24 +00:00
|
|
|
static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> dict,
|
2012-02-17 12:59:58 +00:00
|
|
|
uint32_t index) {
|
2011-08-17 16:15:30 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2014-04-08 14:20:29 +00:00
|
|
|
static bool HasElementImpl(Handle<Object> receiver,
|
|
|
|
Handle<JSObject> holder,
|
2012-03-06 12:22:18 +00:00
|
|
|
uint32_t key,
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<FixedArrayBase> parameters) {
|
|
|
|
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters);
|
|
|
|
Handle<Object> probe = GetParameterMapArg(holder, parameter_map, key);
|
2011-08-17 16:15:30 +00:00
|
|
|
if (!probe->IsTheHole()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2014-04-10 09:20:11 +00:00
|
|
|
Isolate* isolate = holder->GetIsolate();
|
2014-04-08 14:20:29 +00:00
|
|
|
Handle<FixedArrayBase> arguments(FixedArrayBase::cast(
|
2014-04-10 09:20:11 +00:00
|
|
|
Handle<FixedArray>::cast(parameter_map)->get(1)), isolate);
|
2011-08-17 16:15:30 +00:00
|
|
|
ElementsAccessor* accessor = ElementsAccessor::ForArray(arguments);
|
2014-04-10 09:20:11 +00:00
|
|
|
Handle<Object> value;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
|
|
|
isolate, value,
|
|
|
|
accessor->Get(receiver, holder, key, arguments),
|
|
|
|
false);
|
|
|
|
return !value->IsTheHole();
|
2011-08-17 16:15:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-03-20 10:52:22 +00:00
|
|
|
static Handle<Object> GetParameterMapArg(Handle<JSObject> holder,
|
|
|
|
Handle<FixedArray> parameter_map,
|
|
|
|
uint32_t key) {
|
|
|
|
Isolate* isolate = holder->GetIsolate();
|
|
|
|
uint32_t length = holder->IsJSArray()
|
|
|
|
? Smi::cast(Handle<JSArray>::cast(holder)->length())->value()
|
|
|
|
: parameter_map->length();
|
|
|
|
return key < (length - 2)
|
|
|
|
? handle(parameter_map->get(key + 2), isolate)
|
|
|
|
: Handle<Object>::cast(isolate->factory()->the_hole_value());
|
|
|
|
}
|
2011-08-03 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-04-09 12:56:24 +00:00
|
|
|
ElementsAccessor* ElementsAccessor::ForArray(Handle<FixedArrayBase> array) {
|
2013-01-02 10:09:42 +00:00
|
|
|
return elements_accessors_[ElementsKindForArray(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() {
|
|
|
|
#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>
|
2014-04-09 13:16:19 +00:00
|
|
|
MUST_USE_RESULT
|
|
|
|
MaybeHandle<Object> ElementsAccessorBase<ElementsAccessorSubclass,
|
|
|
|
ElementsKindTraits>::
|
2014-03-19 16:29:19 +00:00
|
|
|
SetLengthImpl(Handle<JSObject> obj,
|
|
|
|
Handle<Object> length,
|
|
|
|
Handle<FixedArrayBase> backing_store) {
|
|
|
|
Isolate* isolate = obj->GetIsolate();
|
|
|
|
Handle<JSArray> array = Handle<JSArray>::cast(obj);
|
2011-11-08 11:59:56 +00:00
|
|
|
|
|
|
|
// Fast case: The new length fits into a Smi.
|
2014-04-29 13:18:27 +00:00
|
|
|
Handle<Object> smi_length;
|
2014-03-19 16:29:19 +00:00
|
|
|
|
2014-04-29 13:18:27 +00:00
|
|
|
if (Object::ToSmi(isolate, length).ToHandle(&smi_length) &&
|
|
|
|
smi_length->IsSmi()) {
|
2014-03-19 16:29:19 +00:00
|
|
|
const int value = Handle<Smi>::cast(smi_length)->value();
|
2011-11-08 11:59:56 +00:00
|
|
|
if (value >= 0) {
|
2014-03-19 16:29:19 +00:00
|
|
|
Handle<Object> new_length = ElementsAccessorSubclass::
|
2011-11-08 11:59:56 +00:00
|
|
|
SetLengthWithoutNormalize(backing_store, array, smi_length, value);
|
2014-04-09 13:16:19 +00:00
|
|
|
ASSERT(!new_length.is_null());
|
2014-03-19 16:29:19 +00:00
|
|
|
|
2014-03-11 10:30:10 +00:00
|
|
|
// even though the proposed length was a smi, new_length could
|
|
|
|
// still be a heap number because SetLengthWithoutNormalize doesn't
|
|
|
|
// allow the array length property to drop below the index of
|
|
|
|
// non-deletable elements.
|
|
|
|
ASSERT(new_length->IsSmi() || new_length->IsHeapNumber() ||
|
|
|
|
new_length->IsUndefined());
|
2011-11-08 11:59:56 +00:00
|
|
|
if (new_length->IsSmi()) {
|
2014-03-19 16:29:19 +00:00
|
|
|
array->set_length(*Handle<Smi>::cast(new_length));
|
2011-11-08 11:59:56 +00:00
|
|
|
return array;
|
2014-03-11 10:30:10 +00:00
|
|
|
} else if (new_length->IsHeapNumber()) {
|
2014-03-19 16:29:19 +00:00
|
|
|
array->set_length(*new_length);
|
2014-03-11 10:30:10 +00:00
|
|
|
return array;
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-03-19 16:29:19 +00:00
|
|
|
return ThrowArrayLengthRangeError(isolate);
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slow case: The new length does not fit into a Smi or conversion
|
|
|
|
// to slow elements is needed for other reasons.
|
|
|
|
if (length->IsNumber()) {
|
|
|
|
uint32_t value;
|
|
|
|
if (length->ToArrayIndex(&value)) {
|
2014-03-19 16:29:19 +00:00
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
JSObject::NormalizeElements(array);
|
2014-04-09 13:16:19 +00:00
|
|
|
ASSERT(!dictionary.is_null());
|
2014-03-19 16:29:19 +00:00
|
|
|
|
|
|
|
Handle<Object> new_length = DictionaryElementsAccessor::
|
2011-11-08 11:59:56 +00:00
|
|
|
SetLengthWithoutNormalize(dictionary, array, length, value);
|
2014-04-09 13:16:19 +00:00
|
|
|
ASSERT(!new_length.is_null());
|
2014-03-19 16:29:19 +00:00
|
|
|
|
2011-11-08 11:59:56 +00:00
|
|
|
ASSERT(new_length->IsNumber());
|
2014-03-19 16:29:19 +00:00
|
|
|
array->set_length(*new_length);
|
2011-11-08 11:59:56 +00:00
|
|
|
return array;
|
|
|
|
} else {
|
2014-03-19 16:29:19 +00:00
|
|
|
return ThrowArrayLengthRangeError(isolate);
|
2011-11-08 11:59:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall-back case: The new length is not a number so make the array
|
|
|
|
// size one and set only element to length.
|
2014-03-21 08:30:42 +00:00
|
|
|
Handle<FixedArray> new_backing_store = isolate->factory()->NewFixedArray(1);
|
2014-03-19 16:29:19 +00:00
|
|
|
new_backing_store->set(0, *length);
|
2014-03-21 08:30:42 +00:00
|
|
|
JSArray::SetContent(array, new_backing_store);
|
2011-11-08 11:59:56 +00:00
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-09 13:16:19 +00:00
|
|
|
MaybeHandle<Object> ArrayConstructInitializeElements(Handle<JSArray> array,
|
|
|
|
Arguments* args) {
|
2013-03-01 16:06:34 +00:00
|
|
|
// Optimize the case where there is one argument and the argument is a
|
|
|
|
// small smi.
|
|
|
|
if (args->length() == 1) {
|
2014-03-18 11:38:27 +00:00
|
|
|
Handle<Object> obj = args->at<Object>(0);
|
2013-03-01 16:06:34 +00:00
|
|
|
if (obj->IsSmi()) {
|
2014-03-18 11:38:27 +00:00
|
|
|
int len = Handle<Smi>::cast(obj)->value();
|
2013-03-01 16:06:34 +00:00
|
|
|
if (len > 0 && len < JSObject::kInitialMaxFastElementArray) {
|
|
|
|
ElementsKind elements_kind = array->GetElementsKind();
|
2014-03-18 11:38:27 +00:00
|
|
|
JSArray::Initialize(array, len, len);
|
2013-03-01 16:06:34 +00:00
|
|
|
|
|
|
|
if (!IsFastHoleyElementsKind(elements_kind)) {
|
|
|
|
elements_kind = GetHoleyElementsKind(elements_kind);
|
2014-03-18 11:38:27 +00:00
|
|
|
JSObject::TransitionElementsKind(array, elements_kind);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
return array;
|
|
|
|
} else if (len == 0) {
|
2014-03-18 11:38:27 +00:00
|
|
|
JSArray::Initialize(array, JSArray::kPreallocatedArrayElements);
|
|
|
|
return array;
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Take the argument as the length.
|
2014-03-18 11:38:27 +00:00
|
|
|
JSArray::Initialize(array, 0);
|
2013-03-01 16:06:34 +00:00
|
|
|
|
2014-03-18 11:38:27 +00:00
|
|
|
return JSArray::SetElementsLength(array, obj);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Optimize the case where there are no parameters passed.
|
|
|
|
if (args->length() == 0) {
|
2014-03-18 11:38:27 +00:00
|
|
|
JSArray::Initialize(array, JSArray::kPreallocatedArrayElements);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-03 11:12:46 +00:00
|
|
|
} } // namespace v8::internal
|