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