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"
|
2016-03-28 15:53:15 +00:00
|
|
|
#include "src/isolate-inl.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) \
|
2017-06-30 11:26:14 +00:00
|
|
|
V(FastPackedSmiElementsAccessor, PACKED_SMI_ELEMENTS, FixedArray) \
|
|
|
|
V(FastHoleySmiElementsAccessor, HOLEY_SMI_ELEMENTS, FixedArray) \
|
|
|
|
V(FastPackedObjectElementsAccessor, PACKED_ELEMENTS, FixedArray) \
|
|
|
|
V(FastHoleyObjectElementsAccessor, HOLEY_ELEMENTS, FixedArray) \
|
|
|
|
V(FastPackedDoubleElementsAccessor, PACKED_DOUBLE_ELEMENTS, \
|
2015-07-02 14:38:37 +00:00
|
|
|
FixedDoubleArray) \
|
2017-06-30 11:26:14 +00:00
|
|
|
V(FastHoleyDoubleElementsAccessor, HOLEY_DOUBLE_ELEMENTS, FixedDoubleArray) \
|
2015-07-02 14:38:37 +00:00
|
|
|
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);
|
2017-06-30 18:00:44 +00:00
|
|
|
DCHECK(IsSmiOrObjectElementsKind(from_kind));
|
|
|
|
DCHECK(IsSmiOrObjectElementsKind(to_kind));
|
2015-11-18 09:46:24 +00:00
|
|
|
|
|
|
|
WriteBarrierMode write_barrier_mode =
|
2017-06-30 18:00:44 +00:00
|
|
|
(IsObjectElementsKind(from_kind) && IsObjectElementsKind(to_kind))
|
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);
|
2017-06-30 18:00:44 +00:00
|
|
|
DCHECK(IsSmiOrObjectElementsKind(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;
|
|
|
|
}
|
2017-06-30 18:00:44 +00:00
|
|
|
WriteBarrierMode write_barrier_mode =
|
|
|
|
IsObjectElementsKind(to_kind) ? UPDATE_WRITE_BARRIER : SKIP_WRITE_BARRIER;
|
2016-11-23 09:43:42 +00:00
|
|
|
Isolate* isolate = from->GetIsolate();
|
2012-03-16 13:59:59 +00:00
|
|
|
for (int i = 0; i < copy_size; i++) {
|
2017-01-19 13:27:59 +00:00
|
|
|
int entry = from->FindEntry(isolate, i + from_start);
|
2012-03-16 13:59:59 +00:00
|
|
|
if (entry != SeededNumberDictionary::kNotFound) {
|
|
|
|
Object* value = from->ValueAt(entry);
|
2016-11-23 09:43:42 +00:00
|
|
|
DCHECK(!value->IsTheHole(isolate));
|
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 {
|
2016-11-23 09:43:42 +00:00
|
|
|
to->set_the_hole(isolate, i + to_start);
|
2012-03-16 13:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
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 {
|
2017-07-10 12:58:27 +00:00
|
|
|
to->set(to_start, Smi::ToInt(hole_or_smi));
|
2012-06-12 15:30:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(!smi->IsTheHole(from->GetIsolate()));
|
2017-07-10 12:58:27 +00:00
|
|
|
to->set(to_start, Smi::ToInt(smi));
|
2012-06-12 15:30:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2017-01-19 13:27:59 +00:00
|
|
|
Isolate* isolate = from->GetIsolate();
|
2012-03-16 13:59:59 +00:00
|
|
|
for (int i = 0; i < copy_size; i++) {
|
2017-01-19 13:27:59 +00:00
|
|
|
int entry = from->FindEntry(isolate, i + from_start);
|
2012-03-16 13:59:59 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-05-25 09:13:31 +00:00
|
|
|
static void SortIndices(
|
|
|
|
Handle<FixedArray> indices, uint32_t sort_size,
|
|
|
|
WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER) {
|
|
|
|
struct {
|
2017-06-21 10:48:39 +00:00
|
|
|
bool operator()(const base::AtomicElement<Object*>& elementA,
|
|
|
|
const base::AtomicElement<Object*>& elementB) {
|
|
|
|
const Object* a = elementA.value();
|
|
|
|
const Object* b = elementB.value();
|
2016-06-14 10:08:44 +00:00
|
|
|
if (a->IsSmi() || !a->IsUndefined(HeapObject::cast(a)->GetIsolate())) {
|
|
|
|
if (!b->IsSmi() && b->IsUndefined(HeapObject::cast(b)->GetIsolate())) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-25 09:13:31 +00:00
|
|
|
return a->Number() < b->Number();
|
|
|
|
}
|
2016-06-14 10:08:44 +00:00
|
|
|
return !b->IsSmi() && b->IsUndefined(HeapObject::cast(b)->GetIsolate());
|
2016-05-25 09:13:31 +00:00
|
|
|
}
|
|
|
|
} cmp;
|
2017-06-21 10:48:39 +00:00
|
|
|
// Use AtomicElement wrapper to ensure that std::sort uses atomic load and
|
|
|
|
// store operations that are safe for concurrent marking.
|
|
|
|
base::AtomicElement<Object*>* start =
|
|
|
|
reinterpret_cast<base::AtomicElement<Object*>*>(
|
|
|
|
indices->GetFirstElementAddress());
|
2016-05-25 09:13:31 +00:00
|
|
|
std::sort(start, start + sort_size, cmp);
|
|
|
|
if (write_barrier_mode != SKIP_WRITE_BARRIER) {
|
|
|
|
FIXED_ARRAY_ELEMENTS_WRITE_BARRIER(indices->GetIsolate()->heap(), *indices,
|
|
|
|
0, sort_size);
|
|
|
|
}
|
|
|
|
}
|
2013-02-07 07:56:11 +00:00
|
|
|
|
2016-08-03 03:26:58 +00:00
|
|
|
static Maybe<bool> IncludesValueSlowPath(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
bool search_for_hole = value->IsUndefined(isolate);
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
|
|
|
LookupIterator it(isolate, receiver, k);
|
|
|
|
if (!it.IsFound()) {
|
|
|
|
if (search_for_hole) return Just(true);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Handle<Object> element_k;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, element_k,
|
|
|
|
Object::GetProperty(&it), Nothing<bool>());
|
|
|
|
|
|
|
|
if (value->SameValueZero(*element_k)) return Just(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Just(false);
|
|
|
|
}
|
|
|
|
|
2016-08-22 18:36:50 +00:00
|
|
|
static Maybe<int64_t> IndexOfValueSlowPath(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from,
|
|
|
|
uint32_t length) {
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
|
|
|
LookupIterator it(isolate, receiver, k);
|
|
|
|
if (!it.IsFound()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Handle<Object> element_k;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
|
|
|
isolate, element_k, Object::GetProperty(&it), Nothing<int64_t>());
|
|
|
|
|
|
|
|
if (value->StrictEquals(*element_k)) return Just<int64_t>(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
|
|
|
|
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).
|
2016-04-06 13:38:02 +00:00
|
|
|
template <typename Subclass, 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
|
|
|
|
2017-07-06 08:26:19 +00:00
|
|
|
static void ValidateContents(JSObject* holder, int length) {}
|
2012-05-23 14:24:29 +00:00
|
|
|
|
2017-07-06 08:26:19 +00:00
|
|
|
static void ValidateImpl(JSObject* holder) {
|
|
|
|
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()) {
|
2017-07-06 08:26:19 +00:00
|
|
|
Object* length_obj = JSArray::cast(holder)->length();
|
2012-05-23 14:24:29 +00:00
|
|
|
if (length_obj->IsSmi()) {
|
2017-07-10 12:58:27 +00:00
|
|
|
length = Smi::ToInt(length_obj);
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
length = fixed_array_base->length();
|
|
|
|
}
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::ValidateContents(holder, length);
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 08:26:19 +00:00
|
|
|
void Validate(JSObject* holder) final {
|
2014-04-07 10:00:14 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::ValidateImpl(holder);
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
|
|
|
|
2017-04-11 17:28:33 +00:00
|
|
|
static bool IsPackedImpl(JSObject* holder, FixedArrayBase* backing_store,
|
|
|
|
uint32_t start, uint32_t end) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
2015-08-31 12:19:16 +00:00
|
|
|
if (IsFastPackedElementsKind(kind())) return true;
|
2016-11-15 18:30:35 +00:00
|
|
|
Isolate* isolate = backing_store->GetIsolate();
|
2015-08-31 12:19:16 +00:00
|
|
|
for (uint32_t i = start; i < end; i++) {
|
2016-11-15 18:30:35 +00:00
|
|
|
if (!Subclass::HasElementImpl(isolate, holder, i, backing_store,
|
|
|
|
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) {
|
2017-06-30 16:28:26 +00:00
|
|
|
if (!IsHoleyOrDictionaryElementsKind(kind())) return;
|
2015-09-15 09:08:28 +00:00
|
|
|
Handle<FixedArrayBase> backing_store(array->elements());
|
2017-07-10 12:58:27 +00:00
|
|
|
int length = Smi::ToInt(array->length());
|
2017-04-11 17:28:33 +00:00
|
|
|
if (!Subclass::IsPackedImpl(*array, *backing_store, 0, length)) {
|
2015-09-15 09:08:28 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-11 17:28:33 +00:00
|
|
|
bool HasElement(JSObject* holder, uint32_t index,
|
|
|
|
FixedArrayBase* backing_store, PropertyFilter filter) final {
|
2016-11-15 18:30:35 +00:00
|
|
|
return Subclass::HasElementImpl(holder->GetIsolate(), holder, index,
|
|
|
|
backing_store, filter);
|
2015-08-31 12:19:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-11 17:28:33 +00:00
|
|
|
static bool HasElementImpl(Isolate* isolate, JSObject* holder, uint32_t index,
|
|
|
|
FixedArrayBase* backing_store,
|
2016-11-24 14:47:58 +00:00
|
|
|
PropertyFilter filter = ALL_PROPERTIES) {
|
2017-04-11 17:28:33 +00:00
|
|
|
return Subclass::GetEntryForIndexImpl(isolate, holder, backing_store, index,
|
|
|
|
filter) != kMaxUInt32;
|
2012-03-06 12:22:18 +00:00
|
|
|
}
|
|
|
|
|
2016-03-15 20:28:15 +00:00
|
|
|
bool HasAccessors(JSObject* holder) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::HasAccessorsImpl(holder, holder->elements());
|
2016-03-15 20:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool HasAccessorsImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-29 18:57:26 +00:00
|
|
|
Handle<Object> Get(Handle<JSObject> holder, uint32_t entry) final {
|
2016-11-24 14:47:58 +00:00
|
|
|
return Subclass::GetInternalImpl(holder, entry);
|
2011-08-18 09:51:08 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 14:47:58 +00:00
|
|
|
static Handle<Object> GetInternalImpl(Handle<JSObject> holder,
|
|
|
|
uint32_t entry) {
|
|
|
|
return Subclass::GetImpl(holder->GetIsolate(), holder->elements(), entry);
|
2011-08-03 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 14:47:58 +00:00
|
|
|
static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store,
|
|
|
|
uint32_t entry) {
|
2016-01-29 18:57:26 +00:00
|
|
|
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 {
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::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 {
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::ReconfigureImpl(object, store, entry, value, attributes);
|
2015-06-25 11:25:59 +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 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 {
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::AddImpl(object, index, value, attributes, new_capacity);
|
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) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
uint32_t Push(Handle<JSArray> receiver, Arguments* args,
|
|
|
|
uint32_t push_size) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::PushImpl(receiver, args, push_size);
|
2015-07-31 16:10:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
static uint32_t PushImpl(Handle<JSArray> receiver, Arguments* args,
|
2015-09-02 06:41:56 +00:00
|
|
|
uint32_t push_sized) {
|
2015-07-31 16:10:37 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
uint32_t Unshift(Handle<JSArray> receiver, Arguments* args,
|
2015-11-04 13:08:27 +00:00
|
|
|
uint32_t unshift_size) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::UnshiftImpl(receiver, args, unshift_size);
|
2015-09-01 21:19:44 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
static uint32_t UnshiftImpl(Handle<JSArray> receiver, Arguments* args,
|
2015-09-01 21:19:44 +00:00
|
|
|
uint32_t unshift_size) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2017-04-01 16:46:10 +00:00
|
|
|
Handle<JSObject> Slice(Handle<JSObject> receiver, uint32_t start,
|
|
|
|
uint32_t end) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::SliceImpl(receiver, start, end);
|
2015-08-31 12:19:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-01 16:46:10 +00:00
|
|
|
Handle<JSObject> Slice(Handle<JSObject> receiver, uint32_t start,
|
|
|
|
uint32_t end, Handle<JSObject> result) final {
|
|
|
|
return Subclass::SliceWithResultImpl(receiver, start, end, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Handle<JSObject> SliceImpl(Handle<JSObject> receiver, uint32_t start,
|
|
|
|
uint32_t end) {
|
2015-08-31 12:19:16 +00:00
|
|
|
UNREACHABLE();
|
2017-04-01 16:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Handle<JSObject> SliceWithResultImpl(Handle<JSObject> receiver,
|
|
|
|
uint32_t start, uint32_t end,
|
|
|
|
Handle<JSObject> result) {
|
|
|
|
UNREACHABLE();
|
2015-08-31 12:19:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
Handle<JSArray> Splice(Handle<JSArray> receiver, uint32_t start,
|
2015-11-04 13:08:27 +00:00
|
|
|
uint32_t delete_count, Arguments* args,
|
|
|
|
uint32_t add_count) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::SpliceImpl(receiver, start, delete_count, args, add_count);
|
2015-08-27 13:05:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver,
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
Handle<Object> Pop(Handle<JSArray> receiver) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::PopImpl(receiver);
|
2015-08-31 15:18:01 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
static Handle<Object> PopImpl(Handle<JSArray> receiver) {
|
2015-08-31 15:18:01 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2015-08-27 13:05:50 +00:00
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
Handle<Object> Shift(Handle<JSArray> receiver) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::ShiftImpl(receiver);
|
2015-09-02 15:29:21 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
static Handle<Object> ShiftImpl(Handle<JSArray> receiver) {
|
2015-09-02 15:29:21 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2015-11-04 13:08:27 +00:00
|
|
|
void SetLength(Handle<JSArray> array, uint32_t length) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::SetLengthImpl(array->GetIsolate(), array, length,
|
|
|
|
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();
|
2017-06-30 18:00:44 +00:00
|
|
|
if (!IsHoleyElementsKind(kind)) {
|
2015-09-02 15:29:21 +00:00
|
|
|
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) {
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsSmiOrObjectElementsKind(kind())) {
|
2016-02-25 05:39:57 +00:00
|
|
|
JSObject::EnsureWritableFastElements(array);
|
|
|
|
if (array->elements() != *backing_store) {
|
|
|
|
backing_store = handle(array->elements(), isolate);
|
|
|
|
}
|
2015-09-02 15:29:21 +00:00
|
|
|
}
|
2017-05-15 15:56:10 +00:00
|
|
|
if (2 * length + JSObject::kMinAddedElementsCapacity <= capacity) {
|
2015-09-02 15:29:21 +00:00
|
|
|
// If more than half the elements won't be used, trim the array.
|
2017-05-15 15:56:10 +00:00
|
|
|
// Do not trim from short arrays to prevent frequent trimming on
|
|
|
|
// repeated pop operations.
|
|
|
|
// Leave some space to allow for subsequent push operations.
|
|
|
|
int elements_to_trim = length + 1 == old_length
|
|
|
|
? (capacity - length) / 2
|
|
|
|
: capacity - length;
|
|
|
|
isolate->heap()->RightTrimFixedArray(*backing_store, elements_to_trim);
|
2017-06-23 11:09:09 +00:00
|
|
|
// Fill the non-trimmed elements with holes.
|
|
|
|
BackingStore::cast(*backing_store)
|
|
|
|
->FillWithHoles(length,
|
|
|
|
std::min(old_length, capacity - elements_to_trim));
|
2015-09-02 15:29:21 +00:00
|
|
|
} else {
|
|
|
|
// Otherwise, fill the unused tail with holes.
|
2016-11-23 09:43:42 +00:00
|
|
|
BackingStore::cast(*backing_store)->FillWithHoles(length, old_length);
|
2015-09-02 15:29:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Check whether the backing store should be expanded.
|
|
|
|
capacity = Max(length, JSObject::NewElementsCapacity(capacity));
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::GrowCapacityAndConvertImpl(array, capacity);
|
2015-09-02 15:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
array->set_length(Smi::FromInt(length));
|
2017-07-06 08:26:19 +00:00
|
|
|
JSObject::ValidateElements(*array);
|
2015-09-02 15:29:21 +00:00
|
|
|
}
|
2011-11-08 11:59:56 +00:00
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
uint32_t NumberOfElements(JSObject* receiver) final {
|
|
|
|
return Subclass::NumberOfElementsImpl(receiver, receiver->elements());
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t NumberOfElementsImpl(JSObject* receiver,
|
|
|
|
FixedArrayBase* backing_store) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2016-05-25 09:13:31 +00:00
|
|
|
static uint32_t GetMaxIndex(JSObject* receiver, FixedArrayBase* elements) {
|
2016-03-07 19:25:12 +00:00
|
|
|
if (receiver->IsJSArray()) {
|
2016-03-18 12:42:53 +00:00
|
|
|
DCHECK(JSArray::cast(receiver)->length()->IsSmi());
|
2016-03-07 19:25:12 +00:00
|
|
|
return static_cast<uint32_t>(
|
2017-07-10 12:58:27 +00:00
|
|
|
Smi::ToInt(JSArray::cast(receiver)->length()));
|
2016-03-07 19:25:12 +00:00
|
|
|
}
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::GetCapacityImpl(receiver, elements);
|
2016-03-07 19:25:12 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 09:13:31 +00:00
|
|
|
static uint32_t GetMaxNumberOfEntries(JSObject* receiver,
|
|
|
|
FixedArrayBase* elements) {
|
|
|
|
return Subclass::GetMaxIndex(receiver, elements);
|
|
|
|
}
|
|
|
|
|
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;
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsDoubleElementsKind(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()) {
|
2017-07-10 12:58:27 +00:00
|
|
|
packed_size = Smi::ToInt(JSArray::cast(*object)->length());
|
2015-06-23 09:44:15 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::CopyElementsImpl(*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
|
|
|
}
|
|
|
|
|
2016-07-19 13:38:12 +00:00
|
|
|
static void TransitionElementsKindImpl(Handle<JSObject> object,
|
|
|
|
Handle<Map> to_map) {
|
|
|
|
Handle<Map> from_map = handle(object->map());
|
|
|
|
ElementsKind from_kind = from_map->elements_kind();
|
|
|
|
ElementsKind to_kind = to_map->elements_kind();
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsHoleyElementsKind(from_kind)) {
|
2016-07-19 13:38:12 +00:00
|
|
|
to_kind = GetHoleyElementsKind(to_kind);
|
|
|
|
}
|
|
|
|
if (from_kind != to_kind) {
|
|
|
|
// This method should never be called for any other case.
|
|
|
|
DCHECK(IsFastElementsKind(from_kind));
|
|
|
|
DCHECK(IsFastElementsKind(to_kind));
|
|
|
|
DCHECK_NE(TERMINAL_FAST_ELEMENTS_KIND, from_kind);
|
|
|
|
|
|
|
|
Handle<FixedArrayBase> from_elements(object->elements());
|
|
|
|
if (object->elements() == object->GetHeap()->empty_fixed_array() ||
|
2017-06-30 18:00:44 +00:00
|
|
|
IsDoubleElementsKind(from_kind) == IsDoubleElementsKind(to_kind)) {
|
2016-07-19 13:38:12 +00:00
|
|
|
// No change is needed to the elements() buffer, the transition
|
|
|
|
// only requires a map change.
|
|
|
|
JSObject::MigrateToMap(object, to_map);
|
|
|
|
} else {
|
2017-06-30 18:00:44 +00:00
|
|
|
DCHECK(
|
|
|
|
(IsSmiElementsKind(from_kind) && IsDoubleElementsKind(to_kind)) ||
|
|
|
|
(IsDoubleElementsKind(from_kind) && IsObjectElementsKind(to_kind)));
|
2016-07-19 13:38:12 +00:00
|
|
|
uint32_t capacity = static_cast<uint32_t>(object->elements()->length());
|
|
|
|
Handle<FixedArrayBase> elements = ConvertElementsWithCapacity(
|
|
|
|
object, from_elements, from_kind, capacity);
|
|
|
|
JSObject::SetMapAndElements(object, to_map, elements);
|
|
|
|
}
|
|
|
|
if (FLAG_trace_elements_transitions) {
|
|
|
|
JSObject::PrintElementsTransition(stdout, object, from_kind,
|
|
|
|
from_elements, to_kind,
|
|
|
|
handle(object->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();
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsSmiOrObjectElementsKind(from_kind)) {
|
2015-06-23 09:44:15 +00:00
|
|
|
// 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.
|
2017-06-30 18:00:44 +00:00
|
|
|
DCHECK(IsDoubleElementsKind(from_kind) != IsDoubleElementsKind(kind()) ||
|
2015-06-23 09:44:15 +00:00
|
|
|
IsDictionaryElementsKind(from_kind) ||
|
|
|
|
static_cast<uint32_t>(old_elements->length()) < capacity);
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::BasicGrowCapacityAndConvertImpl(object, old_elements, from_kind,
|
|
|
|
kind(), capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void BasicGrowCapacityAndConvertImpl(
|
|
|
|
Handle<JSObject> object, Handle<FixedArrayBase> old_elements,
|
|
|
|
ElementsKind from_kind, ElementsKind to_kind, uint32_t capacity) {
|
2015-06-23 09:44:15 +00:00
|
|
|
Handle<FixedArrayBase> elements =
|
|
|
|
ConvertElementsWithCapacity(object, old_elements, from_kind, capacity);
|
|
|
|
|
2017-06-30 16:28:26 +00:00
|
|
|
if (IsHoleyOrDictionaryElementsKind(from_kind))
|
|
|
|
to_kind = GetHoleyElementsKind(to_kind);
|
2015-06-23 09:44:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-07-19 13:38:12 +00:00
|
|
|
void TransitionElementsKind(Handle<JSObject> object, Handle<Map> map) final {
|
|
|
|
Subclass::TransitionElementsKindImpl(object, map);
|
|
|
|
}
|
|
|
|
|
2015-11-04 13:08:27 +00:00
|
|
|
void GrowCapacityAndConvert(Handle<JSObject> object,
|
|
|
|
uint32_t capacity) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::GrowCapacityAndConvertImpl(object, capacity);
|
2015-06-22 11:24:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-25 11:39:27 +00:00
|
|
|
bool GrowCapacity(Handle<JSObject> object, uint32_t index) final {
|
|
|
|
// This function is intended to be called from optimized code. We don't
|
|
|
|
// want to trigger lazy deopts there, so refuse to handle cases that would.
|
|
|
|
if (object->map()->is_prototype_map() ||
|
|
|
|
object->WouldConvertToSlowElements(index)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Handle<FixedArrayBase> old_elements(object->elements());
|
|
|
|
uint32_t new_capacity = JSObject::NewElementsCapacity(index + 1);
|
|
|
|
DCHECK(static_cast<uint32_t>(old_elements->length()) < new_capacity);
|
|
|
|
Handle<FixedArrayBase> elements =
|
|
|
|
ConvertElementsWithCapacity(object, old_elements, kind(), new_capacity);
|
|
|
|
|
|
|
|
DCHECK_EQ(object->GetElementsKind(), kind());
|
|
|
|
// Transition through the allocation site as well if present.
|
|
|
|
if (JSObject::UpdateAllocationSite<AllocationSiteUpdateMode::kCheckOnly>(
|
|
|
|
object, kind())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
object->set_elements(*elements);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-04 13:08:27 +00:00
|
|
|
void Delete(Handle<JSObject> obj, uint32_t entry) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::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) {
|
2017-07-10 12:58:27 +00:00
|
|
|
packed_size = Smi::ToInt(JSArray::cast(from_holder)->length());
|
2014-04-03 09:12:59 +00:00
|
|
|
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();
|
2016-04-06 13:38:02 +00:00
|
|
|
// NOTE: the Subclass::CopyElementsImpl() methods
|
2014-09-29 08:22:24 +00:00
|
|
|
// 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.
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::CopyElementsImpl(from, from_start, *to, from_kind, to_start,
|
|
|
|
packed_size, copy_size);
|
2012-03-09 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
2016-11-14 10:46:06 +00:00
|
|
|
void CopyElements(Handle<FixedArrayBase> source, ElementsKind source_kind,
|
|
|
|
Handle<FixedArrayBase> destination, int size) {
|
|
|
|
Subclass::CopyElementsImpl(*source, 0, *destination, source_kind, 0,
|
|
|
|
kPackedSizeNotKnown, size);
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:06:39 +00:00
|
|
|
Object* CopyElements(Handle<JSReceiver> source, Handle<JSObject> destination,
|
|
|
|
size_t length) final {
|
|
|
|
return Subclass::CopyElementsHandleImpl(source, destination, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Object* CopyElementsHandleImpl(Handle<JSReceiver> source,
|
|
|
|
Handle<JSObject> destination,
|
|
|
|
size_t length) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2016-03-16 13:02:21 +00:00
|
|
|
Handle<SeededNumberDictionary> Normalize(Handle<JSObject> object) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::NormalizeImpl(object, handle(object->elements()));
|
2016-03-16 13:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Handle<SeededNumberDictionary> NormalizeImpl(
|
|
|
|
Handle<JSObject> object, Handle<FixedArrayBase> elements) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2016-03-28 15:53:15 +00:00
|
|
|
Maybe<bool> CollectValuesOrEntries(Isolate* isolate, Handle<JSObject> object,
|
|
|
|
Handle<FixedArray> values_or_entries,
|
|
|
|
bool get_entries, int* nof_items,
|
|
|
|
PropertyFilter filter) {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::CollectValuesOrEntriesImpl(
|
2016-03-28 15:53:15 +00:00
|
|
|
isolate, object, values_or_entries, get_entries, nof_items, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Maybe<bool> CollectValuesOrEntriesImpl(
|
|
|
|
Isolate* isolate, Handle<JSObject> object,
|
|
|
|
Handle<FixedArray> values_or_entries, bool get_entries, int* nof_items,
|
|
|
|
PropertyFilter filter) {
|
|
|
|
int count = 0;
|
2016-05-30 15:52:56 +00:00
|
|
|
KeyAccumulator accumulator(isolate, KeyCollectionMode::kOwnOnly,
|
|
|
|
ALL_PROPERTIES);
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::CollectElementIndicesImpl(
|
2016-05-06 10:50:41 +00:00
|
|
|
object, handle(object->elements(), isolate), &accumulator);
|
2016-03-28 15:53:15 +00:00
|
|
|
Handle<FixedArray> keys = accumulator.GetKeys();
|
|
|
|
|
|
|
|
for (int i = 0; i < keys->length(); ++i) {
|
|
|
|
Handle<Object> key(keys->get(i), isolate);
|
|
|
|
Handle<Object> value;
|
|
|
|
uint32_t index;
|
|
|
|
if (!key->ToUint32(&index)) continue;
|
|
|
|
|
2016-04-06 13:38:02 +00:00
|
|
|
uint32_t entry = Subclass::GetEntryForIndexImpl(
|
2016-11-15 18:30:35 +00:00
|
|
|
isolate, *object, object->elements(), index, filter);
|
2016-03-28 15:53:15 +00:00
|
|
|
if (entry == kMaxUInt32) continue;
|
|
|
|
|
2016-04-06 13:38:02 +00:00
|
|
|
PropertyDetails details = Subclass::GetDetailsImpl(*object, entry);
|
2016-03-28 15:53:15 +00:00
|
|
|
|
|
|
|
if (details.kind() == kData) {
|
2016-11-24 14:47:58 +00:00
|
|
|
value = Subclass::GetImpl(isolate, object->elements(), entry);
|
2016-03-28 15:53:15 +00:00
|
|
|
} else {
|
|
|
|
LookupIterator it(isolate, object, index, LookupIterator::OWN);
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
|
|
|
isolate, value, Object::GetProperty(&it), Nothing<bool>());
|
|
|
|
}
|
|
|
|
if (get_entries) {
|
|
|
|
value = MakeEntryPair(isolate, index, value);
|
|
|
|
}
|
|
|
|
values_or_entries->set(count++, *value);
|
|
|
|
}
|
|
|
|
|
|
|
|
*nof_items = count;
|
|
|
|
return Just(true);
|
|
|
|
}
|
|
|
|
|
2016-03-07 19:25:12 +00:00
|
|
|
void CollectElementIndices(Handle<JSObject> object,
|
|
|
|
Handle<FixedArrayBase> backing_store,
|
2016-05-06 10:50:41 +00:00
|
|
|
KeyAccumulator* keys) final {
|
|
|
|
if (keys->filter() & ONLY_ALL_CAN_READ) return;
|
|
|
|
Subclass::CollectElementIndicesImpl(object, backing_store, keys);
|
2016-03-07 19:25:12 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 13:47:24 +00:00
|
|
|
static void CollectElementIndicesImpl(Handle<JSObject> object,
|
|
|
|
Handle<FixedArrayBase> backing_store,
|
2016-05-06 10:50:41 +00:00
|
|
|
KeyAccumulator* keys) {
|
2016-01-29 18:57:26 +00:00
|
|
|
DCHECK_NE(DICTIONARY_ELEMENTS, kind());
|
2016-03-15 10:52:08 +00:00
|
|
|
// Non-dictionary elements can't have all-can-read accessors.
|
2016-05-25 09:13:31 +00:00
|
|
|
uint32_t length = Subclass::GetMaxIndex(*object, *backing_store);
|
2016-05-06 10:50:41 +00:00
|
|
|
PropertyFilter filter = keys->filter();
|
2016-11-15 18:30:35 +00:00
|
|
|
Isolate* isolate = keys->isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
2016-05-06 10:50:41 +00:00
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2017-04-11 17:28:33 +00:00
|
|
|
if (Subclass::HasElementImpl(isolate, *object, i, *backing_store,
|
|
|
|
filter)) {
|
2016-05-25 09:13:31 +00:00
|
|
|
keys->AddKey(factory->NewNumberFromUint(i));
|
2016-03-07 16:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 19:25:12 +00:00
|
|
|
static Handle<FixedArray> DirectCollectElementIndicesImpl(
|
|
|
|
Isolate* isolate, Handle<JSObject> object,
|
|
|
|
Handle<FixedArrayBase> backing_store, GetKeysConversion convert,
|
2016-03-14 17:09:19 +00:00
|
|
|
PropertyFilter filter, Handle<FixedArray> list, uint32_t* nof_indices,
|
|
|
|
uint32_t insertion_index = 0) {
|
2016-05-25 09:13:31 +00:00
|
|
|
uint32_t length = Subclass::GetMaxIndex(*object, *backing_store);
|
2016-03-07 19:25:12 +00:00
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2017-04-11 17:28:33 +00:00
|
|
|
if (Subclass::HasElementImpl(isolate, *object, i, *backing_store,
|
|
|
|
filter)) {
|
2016-05-30 15:52:56 +00:00
|
|
|
if (convert == GetKeysConversion::kConvertToString) {
|
2016-03-07 19:25:12 +00:00
|
|
|
Handle<String> index_string = isolate->factory()->Uint32ToString(i);
|
|
|
|
list->set(insertion_index, *index_string);
|
|
|
|
} else {
|
|
|
|
list->set(insertion_index, Smi::FromInt(i), SKIP_WRITE_BARRIER);
|
|
|
|
}
|
|
|
|
insertion_index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*nof_indices = insertion_index;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2016-08-05 12:52:02 +00:00
|
|
|
MaybeHandle<FixedArray> PrependElementIndices(
|
|
|
|
Handle<JSObject> object, Handle<FixedArrayBase> backing_store,
|
|
|
|
Handle<FixedArray> keys, GetKeysConversion convert,
|
|
|
|
PropertyFilter filter) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::PrependElementIndicesImpl(object, backing_store, keys,
|
|
|
|
convert, filter);
|
2016-03-07 19:25:12 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 12:52:02 +00:00
|
|
|
static MaybeHandle<FixedArray> PrependElementIndicesImpl(
|
2016-03-07 19:25:12 +00:00
|
|
|
Handle<JSObject> object, Handle<FixedArrayBase> backing_store,
|
|
|
|
Handle<FixedArray> keys, GetKeysConversion convert,
|
|
|
|
PropertyFilter filter) {
|
|
|
|
Isolate* isolate = object->GetIsolate();
|
|
|
|
uint32_t nof_property_keys = keys->length();
|
|
|
|
uint32_t initial_list_length =
|
2016-07-21 09:22:48 +00:00
|
|
|
Subclass::GetMaxNumberOfEntries(*object, *backing_store);
|
2016-11-15 18:30:35 +00:00
|
|
|
|
2016-03-07 19:25:12 +00:00
|
|
|
initial_list_length += nof_property_keys;
|
2016-08-05 12:52:02 +00:00
|
|
|
if (initial_list_length > FixedArray::kMaxLength ||
|
|
|
|
initial_list_length < nof_property_keys) {
|
|
|
|
return isolate->Throw<FixedArray>(isolate->factory()->NewRangeError(
|
|
|
|
MessageTemplate::kInvalidArrayLength));
|
|
|
|
}
|
2016-03-07 19:25:12 +00:00
|
|
|
|
|
|
|
// Collect the element indices into a new list.
|
2016-11-15 18:30:35 +00:00
|
|
|
MaybeHandle<FixedArray> raw_array =
|
|
|
|
isolate->factory()->TryNewFixedArray(initial_list_length);
|
|
|
|
Handle<FixedArray> combined_keys;
|
|
|
|
|
|
|
|
// If we have a holey backing store try to precisely estimate the backing
|
|
|
|
// store size as a last emergency measure if we cannot allocate the big
|
|
|
|
// array.
|
|
|
|
if (!raw_array.ToHandle(&combined_keys)) {
|
2017-06-30 16:28:26 +00:00
|
|
|
if (IsHoleyOrDictionaryElementsKind(kind())) {
|
2016-11-15 18:30:35 +00:00
|
|
|
// If we overestimate the result list size we might end up in the
|
|
|
|
// large-object space which doesn't free memory on shrinking the list.
|
|
|
|
// Hence we try to estimate the final size for holey backing stores more
|
|
|
|
// precisely here.
|
|
|
|
initial_list_length =
|
|
|
|
Subclass::NumberOfElementsImpl(*object, *backing_store);
|
|
|
|
initial_list_length += nof_property_keys;
|
|
|
|
}
|
|
|
|
combined_keys = isolate->factory()->NewFixedArray(initial_list_length);
|
|
|
|
}
|
|
|
|
|
2016-03-07 19:25:12 +00:00
|
|
|
uint32_t nof_indices = 0;
|
2017-04-06 08:51:47 +00:00
|
|
|
bool needs_sorting = IsDictionaryElementsKind(kind()) ||
|
|
|
|
IsSloppyArgumentsElementsKind(kind());
|
2016-04-06 13:38:02 +00:00
|
|
|
combined_keys = Subclass::DirectCollectElementIndicesImpl(
|
2016-07-21 09:22:48 +00:00
|
|
|
isolate, object, backing_store,
|
|
|
|
needs_sorting ? GetKeysConversion::kKeepNumbers : convert, filter,
|
|
|
|
combined_keys, &nof_indices);
|
2016-03-07 19:25:12 +00:00
|
|
|
|
2016-07-21 09:22:48 +00:00
|
|
|
if (needs_sorting) {
|
2016-07-23 12:13:32 +00:00
|
|
|
SortIndices(combined_keys, nof_indices);
|
2016-03-07 19:25:12 +00:00
|
|
|
// Indices from dictionary elements should only be converted after
|
|
|
|
// sorting.
|
2016-05-30 15:52:56 +00:00
|
|
|
if (convert == GetKeysConversion::kConvertToString) {
|
2016-03-07 19:25:12 +00:00
|
|
|
for (uint32_t i = 0; i < nof_indices; i++) {
|
|
|
|
Handle<Object> index_string = isolate->factory()->Uint32ToString(
|
2016-07-23 12:13:32 +00:00
|
|
|
combined_keys->get(i)->Number());
|
2016-03-07 19:25:12 +00:00
|
|
|
combined_keys->set(i, *index_string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy over the passed-in property keys.
|
2017-06-30 11:26:14 +00:00
|
|
|
CopyObjectToObjectElements(*keys, PACKED_ELEMENTS, 0, *combined_keys,
|
|
|
|
PACKED_ELEMENTS, nof_indices, nof_property_keys);
|
2016-03-07 19:25:12 +00:00
|
|
|
|
2016-07-21 09:22:48 +00:00
|
|
|
// For holey elements and arguments we might have to shrink the collected
|
|
|
|
// keys since the estimates might be off.
|
2017-06-30 16:28:26 +00:00
|
|
|
if (IsHoleyOrDictionaryElementsKind(kind()) ||
|
|
|
|
IsSloppyArgumentsElementsKind(kind())) {
|
2016-03-07 19:25:12 +00:00
|
|
|
// Shrink combined_keys to the final size.
|
|
|
|
int final_size = nof_indices + nof_property_keys;
|
|
|
|
DCHECK_LE(final_size, combined_keys->length());
|
|
|
|
combined_keys->Shrink(final_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return combined_keys;
|
|
|
|
}
|
2015-10-19 13:47:24 +00:00
|
|
|
|
2015-11-04 13:08:27 +00:00
|
|
|
void AddElementsToKeyAccumulator(Handle<JSObject> receiver,
|
|
|
|
KeyAccumulator* accumulator,
|
|
|
|
AddKeyConversion convert) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::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 {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::GetCapacityImpl(holder, backing_store);
|
2011-08-03 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 13:32:54 +00:00
|
|
|
static Object* FillImpl(Isolate* isolate, Handle<JSObject> receiver,
|
|
|
|
Handle<Object> obj_value, uint32_t start,
|
|
|
|
uint32_t end) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
Object* Fill(Isolate* isolate, Handle<JSObject> receiver,
|
|
|
|
Handle<Object> obj_value, uint32_t start, uint32_t end) {
|
|
|
|
return Subclass::FillImpl(isolate, receiver, obj_value, start, end);
|
|
|
|
}
|
|
|
|
|
2016-08-03 03:26:58 +00:00
|
|
|
static Maybe<bool> IncludesValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
return IncludesValueSlowPath(isolate, receiver, value, start_from, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<bool> IncludesValue(Isolate* isolate, Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value, uint32_t start_from,
|
|
|
|
uint32_t length) final {
|
|
|
|
return Subclass::IncludesValueImpl(isolate, receiver, value, start_from,
|
|
|
|
length);
|
|
|
|
}
|
|
|
|
|
2016-08-22 18:36:50 +00:00
|
|
|
static Maybe<int64_t> IndexOfValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
return IndexOfValueSlowPath(isolate, receiver, value, start_from, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<int64_t> IndexOfValue(Isolate* isolate, Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value, uint32_t start_from,
|
|
|
|
uint32_t length) final {
|
|
|
|
return Subclass::IndexOfValueImpl(isolate, receiver, value, start_from,
|
|
|
|
length);
|
|
|
|
}
|
|
|
|
|
2017-03-16 16:28:00 +00:00
|
|
|
static Maybe<int64_t> LastIndexOfValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<int64_t> LastIndexOfValue(Isolate* isolate, Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from) final {
|
|
|
|
return Subclass::LastIndexOfValueImpl(isolate, receiver, value, start_from);
|
|
|
|
}
|
|
|
|
|
2017-03-25 16:04:35 +00:00
|
|
|
static void ReverseImpl(JSObject* receiver) { UNREACHABLE(); }
|
|
|
|
|
|
|
|
void Reverse(JSObject* receiver) final { Subclass::ReverseImpl(receiver); }
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
static uint32_t GetEntryForIndexImpl(Isolate* isolate, JSObject* holder,
|
2015-07-07 11:52:51 +00:00
|
|
|
FixedArrayBase* backing_store,
|
2015-12-02 16:30:06 +00:00
|
|
|
uint32_t index, PropertyFilter filter) {
|
2016-08-31 17:45:59 +00:00
|
|
|
uint32_t length = Subclass::GetMaxIndex(holder, backing_store);
|
2017-06-30 16:28:26 +00:00
|
|
|
if (IsHoleyOrDictionaryElementsKind(kind())) {
|
2016-08-31 17:45:59 +00:00
|
|
|
return index < length &&
|
2016-11-15 18:30:35 +00:00
|
|
|
!BackingStore::cast(backing_store)
|
|
|
|
->is_the_hole(isolate, index)
|
2015-07-10 14:13:27 +00:00
|
|
|
? index
|
|
|
|
: kMaxUInt32;
|
|
|
|
} else {
|
|
|
|
return index < length ? index : kMaxUInt32;
|
|
|
|
}
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
uint32_t GetEntryForIndex(Isolate* isolate, JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store,
|
2015-11-04 13:08:27 +00:00
|
|
|
uint32_t index) final {
|
2016-11-15 18:30:35 +00:00
|
|
|
return Subclass::GetEntryForIndexImpl(isolate, holder, backing_store, index,
|
2016-04-06 13:38:02 +00:00
|
|
|
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) {
|
2017-06-22 09:52:28 +00:00
|
|
|
return PropertyDetails(kData, NONE, PropertyCellType::kNoCell);
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 18:57:26 +00:00
|
|
|
static PropertyDetails GetDetailsImpl(JSObject* holder, uint32_t entry) {
|
2017-06-22 09:52:28 +00:00
|
|
|
return PropertyDetails(kData, NONE, PropertyCellType::kNoCell);
|
2016-01-29 18:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertyDetails GetDetails(JSObject* holder, uint32_t entry) final {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::GetDetailsImpl(holder, entry);
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 14:47:58 +00:00
|
|
|
Handle<FixedArray> CreateListFromArray(Isolate* isolate,
|
|
|
|
Handle<JSArray> array) final {
|
|
|
|
return Subclass::CreateListFromArrayImpl(isolate, array);
|
|
|
|
};
|
|
|
|
|
|
|
|
static Handle<FixedArray> CreateListFromArrayImpl(Isolate* isolate,
|
|
|
|
Handle<JSArray> array) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
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) {}
|
|
|
|
|
2016-05-25 09:13:31 +00:00
|
|
|
static uint32_t GetMaxIndex(JSObject* receiver, FixedArrayBase* elements) {
|
|
|
|
// We cannot properly estimate this for dictionaries.
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t GetMaxNumberOfEntries(JSObject* receiver,
|
|
|
|
FixedArrayBase* backing_store) {
|
2016-11-15 18:30:35 +00:00
|
|
|
return NumberOfElementsImpl(receiver, backing_store);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t NumberOfElementsImpl(JSObject* receiver,
|
|
|
|
FixedArrayBase* backing_store) {
|
2016-05-25 09:13:31 +00:00
|
|
|
SeededNumberDictionary* dict = SeededNumberDictionary::cast(backing_store);
|
|
|
|
return dict->NumberOfElements();
|
2016-03-18 12:42:53 +00:00
|
|
|
}
|
|
|
|
|
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));
|
2017-06-23 08:41:29 +00:00
|
|
|
{
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
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.
|
|
|
|
for (int entry = 0; entry < capacity; entry++) {
|
|
|
|
Object* index = dict->KeyAt(entry);
|
|
|
|
if (dict->IsKey(isolate, index)) {
|
|
|
|
uint32_t number = static_cast<uint32_t>(index->Number());
|
|
|
|
if (length <= number && number < old_length) {
|
|
|
|
PropertyDetails details = dict->DetailsAt(entry);
|
|
|
|
if (!details.IsConfigurable()) length = number + 1;
|
|
|
|
}
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-23 08:41:29 +00:00
|
|
|
if (length == 0) {
|
|
|
|
// Flush the backing store.
|
|
|
|
array->initialize_elements();
|
|
|
|
} else {
|
|
|
|
// Remove elements that should be deleted.
|
|
|
|
int removed_entries = 0;
|
|
|
|
for (int entry = 0; entry < capacity; entry++) {
|
|
|
|
Object* index = dict->KeyAt(entry);
|
|
|
|
if (dict->IsKey(isolate, index)) {
|
|
|
|
uint32_t number = static_cast<uint32_t>(index->Number());
|
|
|
|
if (length <= number && number < old_length) {
|
|
|
|
dict->ClearEntry(entry);
|
|
|
|
removed_entries++;
|
|
|
|
}
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-23 08:41:29 +00:00
|
|
|
// Update the number of elements.
|
|
|
|
dict->ElementsRemoved(removed_entries);
|
|
|
|
}
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2015-07-06 08:53:41 +00:00
|
|
|
Handle<SeededNumberDictionary> dict(
|
|
|
|
SeededNumberDictionary::cast(obj->elements()));
|
2017-06-22 07:59:05 +00:00
|
|
|
dict = SeededNumberDictionary::DeleteEntry(dict, entry);
|
|
|
|
obj->set_elements(*dict);
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
|
2016-03-15 20:28:15 +00:00
|
|
|
static bool HasAccessorsImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store) {
|
2016-04-01 14:38:53 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2016-03-15 20:28:15 +00:00
|
|
|
SeededNumberDictionary* dict = SeededNumberDictionary::cast(backing_store);
|
|
|
|
if (!dict->requires_slow_elements()) return false;
|
|
|
|
int capacity = dict->Capacity();
|
2016-06-07 12:21:50 +00:00
|
|
|
Isolate* isolate = dict->GetIsolate();
|
2016-03-15 20:28:15 +00:00
|
|
|
for (int i = 0; i < capacity; i++) {
|
|
|
|
Object* key = dict->KeyAt(i);
|
2016-06-07 12:21:50 +00:00
|
|
|
if (!dict->IsKey(isolate, key)) continue;
|
2016-03-15 20:28:15 +00:00
|
|
|
PropertyDetails details = dict->DetailsAt(i);
|
2017-01-12 16:37:12 +00:00
|
|
|
if (details.kind() == kAccessor) return true;
|
2016-03-15 20:28:15 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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-11-24 14:47:58 +00:00
|
|
|
static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store,
|
|
|
|
uint32_t entry) {
|
|
|
|
return handle(GetRaw(backing_store, entry), isolate);
|
2016-01-29 18:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-06-22 09:52:28 +00:00
|
|
|
details = PropertyDetails(kData, attributes, PropertyCellType::kNoCell,
|
|
|
|
details.dictionary_index());
|
|
|
|
|
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) {
|
2017-06-22 09:52:28 +00:00
|
|
|
PropertyDetails details(kData, attributes, PropertyCellType::kNoCell);
|
2015-07-02 16:44:17 +00:00
|
|
|
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 =
|
2017-06-21 08:27:38 +00:00
|
|
|
SeededNumberDictionary::Add(dictionary, index, value, details);
|
|
|
|
new_dictionary->UpdateMaxNumberKey(index, object);
|
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);
|
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
static bool HasEntryImpl(Isolate* isolate, 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);
|
2016-11-15 18:30:35 +00:00
|
|
|
return !index->IsTheHole(isolate);
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
static uint32_t GetEntryForIndexImpl(Isolate* isolate, JSObject* holder,
|
|
|
|
FixedArrayBase* store, 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);
|
2016-11-15 18:30:35 +00:00
|
|
|
int entry = dictionary->FindEntry(isolate, index);
|
2015-10-19 13:47:24 +00:00
|
|
|
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
|
|
|
|
2016-04-01 14:38:53 +00:00
|
|
|
static uint32_t FilterKey(Handle<SeededNumberDictionary> dictionary,
|
|
|
|
int entry, Object* raw_key, PropertyFilter filter) {
|
2016-03-07 19:25:12 +00:00
|
|
|
DCHECK(raw_key->IsNumber());
|
|
|
|
DCHECK_LE(raw_key->Number(), kMaxUInt32);
|
|
|
|
PropertyDetails details = dictionary->DetailsAt(entry);
|
|
|
|
PropertyAttributes attr = details.attributes();
|
|
|
|
if ((attr & filter) != 0) return kMaxUInt32;
|
2016-03-15 10:52:08 +00:00
|
|
|
return static_cast<uint32_t>(raw_key->Number());
|
2016-03-07 19:25:12 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 12:21:50 +00:00
|
|
|
static uint32_t GetKeyForEntryImpl(Isolate* isolate,
|
|
|
|
Handle<SeededNumberDictionary> dictionary,
|
2016-04-01 14:38:53 +00:00
|
|
|
int entry, PropertyFilter filter) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
Object* raw_key = dictionary->KeyAt(entry);
|
2016-06-07 12:21:50 +00:00
|
|
|
if (!dictionary->IsKey(isolate, raw_key)) return kMaxUInt32;
|
2016-04-01 14:38:53 +00:00
|
|
|
return FilterKey(dictionary, entry, raw_key, filter);
|
|
|
|
}
|
|
|
|
|
2015-10-19 13:47:24 +00:00
|
|
|
static void CollectElementIndicesImpl(Handle<JSObject> object,
|
|
|
|
Handle<FixedArrayBase> backing_store,
|
2016-05-06 10:50:41 +00:00
|
|
|
KeyAccumulator* keys) {
|
|
|
|
if (keys->filter() & SKIP_STRINGS) return;
|
2016-06-07 12:21:50 +00:00
|
|
|
Isolate* isolate = keys->isolate();
|
2015-10-19 13:47:24 +00:00
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
Handle<SeededNumberDictionary>::cast(backing_store);
|
|
|
|
int capacity = dictionary->Capacity();
|
2016-06-07 12:21:50 +00:00
|
|
|
Handle<FixedArray> elements = isolate->factory()->NewFixedArray(
|
|
|
|
GetMaxNumberOfEntries(*object, *backing_store));
|
2016-05-25 09:13:31 +00:00
|
|
|
int insertion_index = 0;
|
2016-05-06 10:50:41 +00:00
|
|
|
PropertyFilter filter = keys->filter();
|
2015-10-19 13:47:24 +00:00
|
|
|
for (int i = 0; i < capacity; i++) {
|
2016-06-28 13:32:18 +00:00
|
|
|
Object* raw_key = dictionary->KeyAt(i);
|
|
|
|
if (!dictionary->IsKey(isolate, raw_key)) continue;
|
|
|
|
uint32_t key = FilterKey(dictionary, i, raw_key, filter);
|
|
|
|
if (key == kMaxUInt32) {
|
2016-07-21 11:05:16 +00:00
|
|
|
keys->AddShadowingKey(raw_key);
|
2016-06-28 13:32:18 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
elements->set(insertion_index, raw_key);
|
2016-05-25 09:13:31 +00:00
|
|
|
insertion_index++;
|
|
|
|
}
|
|
|
|
SortIndices(elements, insertion_index);
|
|
|
|
for (int i = 0; i < insertion_index; i++) {
|
|
|
|
keys->AddKey(elements->get(i));
|
2015-10-19 13:47:24 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-29 18:57:26 +00:00
|
|
|
|
2016-03-07 19:25:12 +00:00
|
|
|
static Handle<FixedArray> DirectCollectElementIndicesImpl(
|
|
|
|
Isolate* isolate, Handle<JSObject> object,
|
|
|
|
Handle<FixedArrayBase> backing_store, GetKeysConversion convert,
|
2016-03-14 17:09:19 +00:00
|
|
|
PropertyFilter filter, Handle<FixedArray> list, uint32_t* nof_indices,
|
|
|
|
uint32_t insertion_index = 0) {
|
2016-03-15 10:52:08 +00:00
|
|
|
if (filter & SKIP_STRINGS) return list;
|
|
|
|
if (filter & ONLY_ALL_CAN_READ) return list;
|
2016-04-01 14:38:53 +00:00
|
|
|
|
2016-03-07 19:25:12 +00:00
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
Handle<SeededNumberDictionary>::cast(backing_store);
|
|
|
|
uint32_t capacity = dictionary->Capacity();
|
|
|
|
for (uint32_t i = 0; i < capacity; i++) {
|
2016-06-07 12:21:50 +00:00
|
|
|
uint32_t key = GetKeyForEntryImpl(isolate, dictionary, i, filter);
|
2016-03-07 19:25:12 +00:00
|
|
|
if (key == kMaxUInt32) continue;
|
|
|
|
Handle<Object> index = isolate->factory()->NewNumberFromUint(key);
|
|
|
|
list->set(insertion_index, *index);
|
|
|
|
insertion_index++;
|
|
|
|
}
|
|
|
|
*nof_indices = insertion_index;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2016-01-29 18:57:26 +00:00
|
|
|
static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver,
|
|
|
|
KeyAccumulator* accumulator,
|
|
|
|
AddKeyConversion convert) {
|
2016-04-01 14:38:53 +00:00
|
|
|
Isolate* isolate = accumulator->isolate();
|
2016-11-15 18:30:35 +00:00
|
|
|
Handle<SeededNumberDictionary> dictionary(
|
|
|
|
SeededNumberDictionary::cast(receiver->elements()), isolate);
|
2016-01-29 18:57:26 +00:00
|
|
|
int capacity = dictionary->Capacity();
|
|
|
|
for (int i = 0; i < capacity; i++) {
|
|
|
|
Object* k = dictionary->KeyAt(i);
|
2017-06-27 11:57:13 +00:00
|
|
|
if (!dictionary->IsKey(isolate, k)) continue;
|
2016-01-29 18:57:26 +00:00
|
|
|
Object* value = dictionary->ValueAt(i);
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(!value->IsTheHole(isolate));
|
2016-01-29 18:57:26 +00:00
|
|
|
DCHECK(!value->IsAccessorPair());
|
|
|
|
DCHECK(!value->IsAccessorInfo());
|
|
|
|
accumulator->AddKey(value, convert);
|
|
|
|
}
|
|
|
|
}
|
2016-08-03 03:26:58 +00:00
|
|
|
|
|
|
|
static bool IncludesValueFastPath(Isolate* isolate, Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value, uint32_t start_from,
|
|
|
|
uint32_t length, Maybe<bool>* result) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
SeededNumberDictionary* dictionary =
|
|
|
|
SeededNumberDictionary::cast(receiver->elements());
|
|
|
|
int capacity = dictionary->Capacity();
|
|
|
|
Object* the_hole = isolate->heap()->the_hole_value();
|
|
|
|
Object* undefined = isolate->heap()->undefined_value();
|
|
|
|
|
|
|
|
// Scan for accessor properties. If accessors are present, then elements
|
|
|
|
// must be accessed in order via the slow path.
|
|
|
|
bool found = false;
|
|
|
|
for (int i = 0; i < capacity; ++i) {
|
|
|
|
Object* k = dictionary->KeyAt(i);
|
|
|
|
if (k == the_hole) continue;
|
|
|
|
if (k == undefined) continue;
|
|
|
|
|
|
|
|
uint32_t index;
|
|
|
|
if (!k->ToArrayIndex(&index) || index < start_from || index >= length) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-12 16:37:12 +00:00
|
|
|
if (dictionary->DetailsAt(i).kind() == kAccessor) {
|
2016-08-03 03:26:58 +00:00
|
|
|
// Restart from beginning in slow path, otherwise we may observably
|
|
|
|
// access getters out of order
|
|
|
|
return false;
|
|
|
|
} else if (!found) {
|
|
|
|
Object* element_k = dictionary->ValueAt(i);
|
|
|
|
if (value->SameValueZero(element_k)) found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = Just(found);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Maybe<bool> IncludesValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver));
|
|
|
|
bool search_for_hole = value->IsUndefined(isolate);
|
|
|
|
|
|
|
|
if (!search_for_hole) {
|
|
|
|
Maybe<bool> result = Nothing<bool>();
|
|
|
|
if (DictionaryElementsAccessor::IncludesValueFastPath(
|
|
|
|
isolate, receiver, value, start_from, length, &result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<SeededNumberDictionary> dictionary(
|
|
|
|
SeededNumberDictionary::cast(receiver->elements()), isolate);
|
|
|
|
// Iterate through entire range, as accessing elements out of order is
|
|
|
|
// observable
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
2017-01-19 13:27:59 +00:00
|
|
|
int entry = dictionary->FindEntry(isolate, k);
|
2016-08-03 03:26:58 +00:00
|
|
|
if (entry == SeededNumberDictionary::kNotFound) {
|
|
|
|
if (search_for_hole) return Just(true);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-08-04 19:05:40 +00:00
|
|
|
PropertyDetails details = GetDetailsImpl(*dictionary, entry);
|
2016-08-03 03:26:58 +00:00
|
|
|
switch (details.kind()) {
|
|
|
|
case kData: {
|
|
|
|
Object* element_k = dictionary->ValueAt(entry);
|
|
|
|
if (value->SameValueZero(element_k)) return Just(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kAccessor: {
|
|
|
|
LookupIterator it(isolate, receiver, k,
|
|
|
|
LookupIterator::OWN_SKIP_INTERCEPTOR);
|
|
|
|
DCHECK(it.IsFound());
|
|
|
|
DCHECK_EQ(it.state(), LookupIterator::ACCESSOR);
|
|
|
|
Handle<Object> element_k;
|
|
|
|
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
|
|
|
isolate, element_k, JSObject::GetPropertyWithAccessor(&it),
|
|
|
|
Nothing<bool>());
|
|
|
|
|
|
|
|
if (value->SameValueZero(*element_k)) return Just(true);
|
|
|
|
|
2016-08-04 19:05:40 +00:00
|
|
|
// Bailout to slow path if elements on prototype changed
|
2016-08-03 03:26:58 +00:00
|
|
|
if (!JSObject::PrototypeHasNoElements(isolate, *receiver)) {
|
|
|
|
return IncludesValueSlowPath(isolate, receiver, value, k + 1,
|
|
|
|
length);
|
|
|
|
}
|
2016-08-04 19:05:40 +00:00
|
|
|
|
|
|
|
// Continue if elements unchanged
|
|
|
|
if (*dictionary == receiver->elements()) continue;
|
|
|
|
|
|
|
|
// Otherwise, bailout or update elements
|
2017-06-23 08:41:29 +00:00
|
|
|
|
|
|
|
// If switched to initial elements, return true if searching for
|
|
|
|
// undefined, and false otherwise.
|
|
|
|
if (receiver->map()->GetInitialElements() == receiver->elements()) {
|
|
|
|
return Just(search_for_hole);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If switched to fast elements, continue with the correct accessor.
|
2016-08-04 19:05:40 +00:00
|
|
|
if (receiver->GetElementsKind() != DICTIONARY_ELEMENTS) {
|
2017-06-23 08:41:29 +00:00
|
|
|
ElementsAccessor* accessor = receiver->GetElementsAccessor();
|
|
|
|
return accessor->IncludesValue(isolate, receiver, value, k + 1,
|
|
|
|
length);
|
2016-08-04 19:05:40 +00:00
|
|
|
}
|
|
|
|
dictionary = handle(
|
|
|
|
SeededNumberDictionary::cast(receiver->elements()), isolate);
|
2016-08-03 03:26:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Just(false);
|
|
|
|
}
|
2016-08-22 18:36:50 +00:00
|
|
|
|
|
|
|
static Maybe<int64_t> IndexOfValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver));
|
|
|
|
|
|
|
|
Handle<SeededNumberDictionary> dictionary(
|
|
|
|
SeededNumberDictionary::cast(receiver->elements()), isolate);
|
|
|
|
// Iterate through entire range, as accessing elements out of order is
|
|
|
|
// observable.
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
2017-01-19 13:27:59 +00:00
|
|
|
int entry = dictionary->FindEntry(isolate, k);
|
2016-08-22 18:36:50 +00:00
|
|
|
if (entry == SeededNumberDictionary::kNotFound) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyDetails details = GetDetailsImpl(*dictionary, entry);
|
|
|
|
switch (details.kind()) {
|
|
|
|
case kData: {
|
|
|
|
Object* element_k = dictionary->ValueAt(entry);
|
|
|
|
if (value->StrictEquals(element_k)) {
|
|
|
|
return Just<int64_t>(k);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kAccessor: {
|
|
|
|
LookupIterator it(isolate, receiver, k,
|
|
|
|
LookupIterator::OWN_SKIP_INTERCEPTOR);
|
|
|
|
DCHECK(it.IsFound());
|
|
|
|
DCHECK_EQ(it.state(), LookupIterator::ACCESSOR);
|
|
|
|
Handle<Object> element_k;
|
|
|
|
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
|
|
|
isolate, element_k, JSObject::GetPropertyWithAccessor(&it),
|
|
|
|
Nothing<int64_t>());
|
|
|
|
|
|
|
|
if (value->StrictEquals(*element_k)) return Just<int64_t>(k);
|
|
|
|
|
|
|
|
// Bailout to slow path if elements on prototype changed.
|
|
|
|
if (!JSObject::PrototypeHasNoElements(isolate, *receiver)) {
|
|
|
|
return IndexOfValueSlowPath(isolate, receiver, value, k + 1,
|
|
|
|
length);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue if elements unchanged.
|
|
|
|
if (*dictionary == receiver->elements()) continue;
|
|
|
|
|
|
|
|
// Otherwise, bailout or update elements.
|
|
|
|
if (receiver->GetElementsKind() != DICTIONARY_ELEMENTS) {
|
|
|
|
// Otherwise, switch to slow path.
|
|
|
|
return IndexOfValueSlowPath(isolate, receiver, value, k + 1,
|
|
|
|
length);
|
|
|
|
}
|
|
|
|
dictionary = handle(
|
|
|
|
SeededNumberDictionary::cast(receiver->elements()), isolate);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
2017-07-06 08:26:19 +00:00
|
|
|
|
|
|
|
static void ValidateContents(JSObject* holder, int length) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
#if DEBUG
|
|
|
|
DCHECK_EQ(holder->map()->elements_kind(), DICTIONARY_ELEMENTS);
|
|
|
|
if (!FLAG_enable_slow_asserts) return;
|
|
|
|
Isolate* isolate = holder->GetIsolate();
|
|
|
|
SeededNumberDictionary* dictionary =
|
|
|
|
SeededNumberDictionary::cast(holder->elements());
|
|
|
|
// Validate the requires_slow_elements and max_number_key values.
|
|
|
|
int capacity = dictionary->Capacity();
|
|
|
|
bool requires_slow_elements = false;
|
|
|
|
int max_key = 0;
|
|
|
|
for (int i = 0; i < capacity; ++i) {
|
|
|
|
Object* k;
|
|
|
|
if (!dictionary->ToKey(isolate, i, &k)) continue;
|
|
|
|
DCHECK_LE(0.0, k->Number());
|
|
|
|
if (k->Number() > SeededNumberDictionary::kRequiresSlowElementsLimit) {
|
|
|
|
requires_slow_elements = true;
|
|
|
|
} else {
|
2017-07-10 12:58:27 +00:00
|
|
|
max_key = Max(max_key, Smi::ToInt(k));
|
2017-07-06 08:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (requires_slow_elements) {
|
|
|
|
DCHECK(dictionary->requires_slow_elements());
|
|
|
|
} else if (!dictionary->requires_slow_elements()) {
|
|
|
|
DCHECK_LE(max_key, dictionary->max_number_key());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
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.
|
2016-04-06 13:38:02 +00:00
|
|
|
template <typename Subclass, typename KindTraits>
|
|
|
|
class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> {
|
2012-03-06 12:03:14 +00:00
|
|
|
public:
|
|
|
|
explicit FastElementsAccessor(const char* name)
|
2016-04-06 13:38:02 +00:00
|
|
|
: ElementsAccessorBase<Subclass, 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
|
|
|
|
2016-03-16 13:02:21 +00:00
|
|
|
static Handle<SeededNumberDictionary> NormalizeImpl(
|
|
|
|
Handle<JSObject> object, Handle<FixedArrayBase> store) {
|
|
|
|
Isolate* isolate = store->GetIsolate();
|
2016-04-06 13:38:02 +00:00
|
|
|
ElementsKind kind = Subclass::kind();
|
2016-03-16 13:02:21 +00:00
|
|
|
|
|
|
|
// Ensure that notifications fire if the array or object prototypes are
|
|
|
|
// normalizing.
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsSmiOrObjectElementsKind(kind)) {
|
2016-03-16 13:02:21 +00:00
|
|
|
isolate->UpdateArrayProtectorOnNormalizeElements(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
int capacity = object->GetFastElementsUsage();
|
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
SeededNumberDictionary::New(isolate, capacity);
|
|
|
|
|
|
|
|
PropertyDetails details = PropertyDetails::Empty();
|
|
|
|
int j = 0;
|
2017-06-21 08:27:38 +00:00
|
|
|
int max_number_key = -1;
|
2016-03-16 13:02:21 +00:00
|
|
|
for (int i = 0; j < capacity; i++) {
|
2017-06-30 16:28:26 +00:00
|
|
|
if (IsHoleyOrDictionaryElementsKind(kind)) {
|
2016-11-15 18:30:35 +00:00
|
|
|
if (BackingStore::cast(*store)->is_the_hole(isolate, i)) continue;
|
2016-03-16 13:02:21 +00:00
|
|
|
}
|
2017-06-21 08:27:38 +00:00
|
|
|
max_number_key = i;
|
2016-11-24 14:47:58 +00:00
|
|
|
Handle<Object> value = Subclass::GetImpl(isolate, *store, i);
|
2017-06-21 08:27:38 +00:00
|
|
|
dictionary = SeededNumberDictionary::Add(dictionary, i, value, details);
|
2016-03-16 13:02:21 +00:00
|
|
|
j++;
|
|
|
|
}
|
2017-06-21 08:27:38 +00:00
|
|
|
|
|
|
|
if (max_number_key > 0) {
|
|
|
|
dictionary->UpdateMaxNumberKey(static_cast<uint32_t>(max_number_key),
|
|
|
|
object);
|
|
|
|
}
|
2016-03-16 13:02:21 +00:00
|
|
|
return dictionary;
|
|
|
|
}
|
|
|
|
|
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());
|
2016-11-15 18:30:35 +00:00
|
|
|
Isolate* isolate = obj->GetIsolate();
|
2015-07-07 16:02:30 +00:00
|
|
|
for (; entry > 0; entry--) {
|
2016-11-15 18:30:35 +00:00
|
|
|
if (!backing_store->is_the_hole(isolate, entry - 1)) break;
|
2015-07-07 16:02:30 +00:00
|
|
|
}
|
|
|
|
if (entry == 0) {
|
2016-11-15 18:30:35 +00:00
|
|
|
FixedArray* empty = isolate->heap()->empty_fixed_array();
|
2016-04-08 08:02:26 +00:00
|
|
|
// Dynamically ask for the elements kind here since we manually redirect
|
|
|
|
// the operations for argument backing stores.
|
|
|
|
if (obj->GetElementsKind() == FAST_SLOPPY_ARGUMENTS_ELEMENTS) {
|
2017-04-06 08:51:47 +00:00
|
|
|
SloppyArgumentsElements::cast(obj->elements())->set_arguments(empty);
|
2015-07-07 16:02:30 +00:00
|
|
|
} else {
|
|
|
|
obj->set_elements(empty);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-18 11:11:30 +00:00
|
|
|
isolate->heap()->RightTrimFixedArray(*backing_store, length - entry);
|
2015-07-07 16:02:30 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2017-06-30 18:00:44 +00:00
|
|
|
DCHECK(obj->HasSmiOrObjectElements() || obj->HasDoubleElements() ||
|
2016-01-29 18:57:26 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
Isolate* isolate = obj->GetIsolate();
|
2016-11-23 09:43:42 +00:00
|
|
|
backing_store->set_the_hole(isolate, 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.
|
|
|
|
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
|
|
|
}
|
2017-05-15 17:47:56 +00:00
|
|
|
|
|
|
|
// To avoid doing the check on every delete, use a counter-based heuristic.
|
|
|
|
const int kLengthFraction = 16;
|
|
|
|
// The above constant must be large enough to ensure that we check for
|
|
|
|
// normalization frequently enough. At a minimum, it should be large
|
|
|
|
// enough to reliably hit the "window" of remaining elements count where
|
|
|
|
// normalization would be beneficial.
|
|
|
|
STATIC_ASSERT(kLengthFraction >=
|
|
|
|
SeededNumberDictionary::kEntrySize *
|
|
|
|
SeededNumberDictionary::kPreferFastElementsSizeFactor);
|
|
|
|
size_t current_counter = isolate->elements_deletion_counter();
|
|
|
|
if (current_counter < length / kLengthFraction) {
|
|
|
|
isolate->set_elements_deletion_counter(current_counter + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Reset the counter whenever the full check is performed.
|
|
|
|
isolate->set_elements_deletion_counter(0);
|
|
|
|
|
|
|
|
if (!obj->IsJSArray()) {
|
|
|
|
uint32_t i;
|
|
|
|
for (i = entry + 1; i < length; i++) {
|
|
|
|
if (!backing_store->is_the_hole(isolate, i)) break;
|
2015-07-07 16:02:30 +00:00
|
|
|
}
|
2017-05-15 17:47:56 +00:00
|
|
|
if (i == length) {
|
|
|
|
DeleteAtEnd(obj, backing_store, entry);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int num_used = 0;
|
|
|
|
for (int i = 0; i < backing_store->length(); ++i) {
|
|
|
|
if (!backing_store->is_the_hole(isolate, i)) {
|
|
|
|
++num_used;
|
|
|
|
// Bail out if a number dictionary wouldn't be able to save much space.
|
|
|
|
if (SeededNumberDictionary::kPreferFastElementsSizeFactor *
|
|
|
|
SeededNumberDictionary::ComputeCapacity(num_used) *
|
|
|
|
SeededNumberDictionary::kEntrySize >
|
|
|
|
static_cast<uint32_t>(backing_store->length())) {
|
|
|
|
return;
|
2015-11-25 11:46:36 +00:00
|
|
|
}
|
2011-08-04 11:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-15 17:47:56 +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();
|
2016-04-06 13:38:02 +00:00
|
|
|
ElementsKind to_kind = Subclass::kind();
|
2015-06-25 14:17:10 +00:00
|
|
|
if (IsDictionaryElementsKind(from_kind) ||
|
2017-06-30 18:00:44 +00:00
|
|
|
IsDoubleElementsKind(from_kind) != IsDoubleElementsKind(to_kind) ||
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::GetCapacityImpl(*object, object->elements()) !=
|
|
|
|
new_capacity) {
|
|
|
|
Subclass::GrowCapacityAndConvertImpl(object, new_capacity);
|
2015-06-25 14:17:10 +00:00
|
|
|
} 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);
|
|
|
|
}
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsSmiOrObjectElementsKind(from_kind)) {
|
|
|
|
DCHECK(IsSmiOrObjectElementsKind(to_kind));
|
2015-06-25 14:17:10 +00:00
|
|
|
JSObject::EnsureWritableFastElements(object);
|
|
|
|
}
|
|
|
|
}
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::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));
|
|
|
|
}
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsSmiOrObjectElementsKind(KindTraits::Kind)) {
|
2015-07-06 08:53:41 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
static bool HasEntryImpl(Isolate* isolate, FixedArrayBase* backing_store,
|
|
|
|
uint32_t entry) {
|
|
|
|
return !BackingStore::cast(backing_store)->is_the_hole(isolate, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t NumberOfElementsImpl(JSObject* receiver,
|
|
|
|
FixedArrayBase* backing_store) {
|
|
|
|
uint32_t max_index = Subclass::GetMaxIndex(receiver, backing_store);
|
|
|
|
if (IsFastPackedElementsKind(Subclass::kind())) return max_index;
|
|
|
|
Isolate* isolate = receiver->GetIsolate();
|
|
|
|
uint32_t count = 0;
|
|
|
|
for (uint32_t i = 0; i < max_index; i++) {
|
|
|
|
if (Subclass::HasEntryImpl(isolate, backing_store, i)) count++;
|
|
|
|
}
|
|
|
|
return count;
|
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) {
|
2016-11-15 18:30:35 +00:00
|
|
|
Isolate* isolate = accumulator->isolate();
|
|
|
|
Handle<FixedArrayBase> elements(receiver->elements(), isolate);
|
2016-05-25 09:13:31 +00:00
|
|
|
uint32_t length = Subclass::GetMaxNumberOfEntries(*receiver, *elements);
|
2016-01-29 18:57:26 +00:00
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
|
|
|
if (IsFastPackedElementsKind(KindTraits::Kind) ||
|
2016-11-15 18:30:35 +00:00
|
|
|
HasEntryImpl(isolate, *elements, i)) {
|
2016-11-24 14:47:58 +00:00
|
|
|
accumulator->AddKey(Subclass::GetImpl(isolate, *elements, i), convert);
|
2016-01-29 18:57:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-06 08:26:19 +00:00
|
|
|
static void ValidateContents(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();
|
2016-04-07 15:27:35 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2017-07-06 08:26:19 +00:00
|
|
|
FixedArrayBase* elements = holder->elements();
|
2012-05-23 14:24:29 +00:00
|
|
|
Map* map = elements->map();
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsSmiOrObjectElementsKind(KindTraits::Kind)) {
|
2016-04-07 15:27:35 +00:00
|
|
|
DCHECK_NE(map, heap->fixed_double_array_map());
|
2017-06-30 18:00:44 +00:00
|
|
|
} else if (IsDoubleElementsKind(KindTraits::Kind)) {
|
2016-04-07 15:27:35 +00:00
|
|
|
DCHECK_NE(map, heap->fixed_cow_array_map());
|
|
|
|
if (map == heap->fixed_array_map()) DCHECK_EQ(0, length);
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2015-03-13 10:47:31 +00:00
|
|
|
if (length == 0) return; // nothing to do!
|
2016-04-07 15:27:35 +00:00
|
|
|
#if ENABLE_SLOW_DCHECKS
|
2014-04-16 06:18:37 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2017-07-06 08:26:19 +00:00
|
|
|
BackingStore* backing_store = BackingStore::cast(elements);
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsSmiElementsKind(KindTraits::Kind)) {
|
2017-07-06 08:26:19 +00:00
|
|
|
HandleScope scope(isolate);
|
2015-06-23 13:35:07 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2017-07-06 08:26:19 +00:00
|
|
|
DCHECK(BackingStore::get(backing_store, i, isolate)->IsSmi() ||
|
2017-06-30 18:00:44 +00:00
|
|
|
(IsHoleyElementsKind(KindTraits::Kind) &&
|
2016-11-15 18:30:35 +00:00
|
|
|
backing_store->is_the_hole(isolate, i)));
|
2015-06-23 13:35:07 +00:00
|
|
|
}
|
2017-06-30 11:26:14 +00:00
|
|
|
} else if (KindTraits::Kind == PACKED_ELEMENTS ||
|
|
|
|
KindTraits::Kind == PACKED_DOUBLE_ELEMENTS) {
|
2016-04-07 15:27:35 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2016-11-15 18:30:35 +00:00
|
|
|
DCHECK(!backing_store->is_the_hole(isolate, i));
|
2016-04-07 15:27:35 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-06-30 18:00:44 +00:00
|
|
|
DCHECK(IsHoleyElementsKind(KindTraits::Kind));
|
2012-05-23 14:24:29 +00:00
|
|
|
}
|
2016-04-07 15:27:35 +00:00
|
|
|
#endif
|
2012-05-23 14:24:29 +00:00
|
|
|
#endif
|
|
|
|
}
|
2015-07-31 16:10:37 +00:00
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
static Handle<Object> PopImpl(Handle<JSArray> receiver) {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::RemoveElement(receiver, AT_END);
|
2015-09-02 15:29:21 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
static Handle<Object> ShiftImpl(Handle<JSArray> receiver) {
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::RemoveElement(receiver, 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,
|
2015-09-02 06:41:56 +00:00
|
|
|
Arguments* args, uint32_t push_size) {
|
2016-03-07 16:25:00 +00:00
|
|
|
Handle<FixedArrayBase> backing_store(receiver->elements());
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::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,
|
|
|
|
Arguments* args, uint32_t unshift_size) {
|
2016-03-07 16:25:00 +00:00
|
|
|
Handle<FixedArrayBase> backing_store(receiver->elements());
|
2016-04-06 13:38:02 +00:00
|
|
|
return Subclass::AddArguments(receiver, backing_store, args, unshift_size,
|
|
|
|
AT_START);
|
2015-09-01 21:19:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-01 16:46:10 +00:00
|
|
|
static Handle<JSObject> SliceImpl(Handle<JSObject> receiver, uint32_t start,
|
|
|
|
uint32_t end) {
|
2015-08-31 12:19:16 +00:00
|
|
|
Isolate* isolate = receiver->GetIsolate();
|
2016-03-07 16:25:00 +00:00
|
|
|
Handle<FixedArrayBase> backing_store(receiver->elements(), isolate);
|
|
|
|
int result_len = end < start ? 0u : end - start;
|
2015-08-31 12:19:16 +00:00
|
|
|
Handle<JSArray> result_array = isolate->factory()->NewJSArray(
|
|
|
|
KindTraits::Kind, result_len, result_len);
|
|
|
|
DisallowHeapAllocation no_gc;
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::CopyElementsImpl(*backing_store, start, result_array->elements(),
|
|
|
|
KindTraits::Kind, 0, kPackedSizeNotKnown,
|
|
|
|
result_len);
|
|
|
|
Subclass::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,
|
|
|
|
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();
|
2017-07-10 12:58:27 +00:00
|
|
|
uint32_t length = Smi::ToInt(receiver->length());
|
2015-09-18 11:15:34 +00:00
|
|
|
uint32_t new_length = length - delete_count + add_count;
|
2015-08-27 13:05:50 +00:00
|
|
|
|
2016-03-07 16:25:00 +00:00
|
|
|
ElementsKind kind = KindTraits::Kind;
|
|
|
|
if (new_length <= static_cast<uint32_t>(receiver->elements()->length()) &&
|
2017-06-30 18:00:44 +00:00
|
|
|
IsSmiOrObjectElementsKind(kind)) {
|
2016-03-07 16:25:00 +00:00
|
|
|
HandleScope scope(isolate);
|
|
|
|
JSObject::EnsureWritableFastElements(receiver);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<FixedArrayBase> backing_store(receiver->elements(), isolate);
|
|
|
|
|
2015-08-27 13:05:50 +00:00
|
|
|
if (new_length == 0) {
|
|
|
|
receiver->set_elements(heap->empty_fixed_array());
|
2016-10-07 13:05:07 +00:00
|
|
|
receiver->set_length(Smi::kZero);
|
2015-08-27 13:05:50 +00:00
|
|
|
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;
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::CopyElementsImpl(*backing_store, start,
|
|
|
|
deleted_elements->elements(), KindTraits::Kind,
|
|
|
|
0, kPackedSizeNotKnown, delete_count);
|
2015-08-27 13:05:50 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::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) {
|
2016-04-06 13:38:02 +00:00
|
|
|
backing_store =
|
|
|
|
Subclass::SpliceGrowStep(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.
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::CopyArguments(args, backing_store, add_count, 3, start);
|
2015-08-27 13:05:50 +00:00
|
|
|
|
|
|
|
receiver->set_length(Smi::FromInt(new_length));
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::TryTransitionResultArrayToPacked(deleted_elements);
|
2015-08-27 13:05:50 +00:00
|
|
|
return deleted_elements;
|
|
|
|
}
|
|
|
|
|
2016-03-28 15:53:15 +00:00
|
|
|
static Maybe<bool> CollectValuesOrEntriesImpl(
|
|
|
|
Isolate* isolate, Handle<JSObject> object,
|
|
|
|
Handle<FixedArray> values_or_entries, bool get_entries, int* nof_items,
|
|
|
|
PropertyFilter filter) {
|
2016-11-15 18:30:35 +00:00
|
|
|
Handle<BackingStore> elements(BackingStore::cast(object->elements()),
|
|
|
|
isolate);
|
2016-03-28 15:53:15 +00:00
|
|
|
int count = 0;
|
2016-11-15 18:30:35 +00:00
|
|
|
uint32_t length = elements->length();
|
2016-03-28 15:53:15 +00:00
|
|
|
for (uint32_t index = 0; index < length; ++index) {
|
2016-11-15 18:30:35 +00:00
|
|
|
if (!HasEntryImpl(isolate, *elements, index)) continue;
|
2016-11-24 14:47:58 +00:00
|
|
|
Handle<Object> value = Subclass::GetImpl(isolate, *elements, index);
|
2016-03-28 15:53:15 +00:00
|
|
|
if (get_entries) {
|
|
|
|
value = MakeEntryPair(isolate, index, value);
|
|
|
|
}
|
|
|
|
values_or_entries->set(count++, *value);
|
|
|
|
}
|
|
|
|
*nof_items = count;
|
|
|
|
return Just(true);
|
|
|
|
}
|
|
|
|
|
2016-03-29 14:53:49 +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();
|
|
|
|
Handle<BackingStore> dst_elms = Handle<BackingStore>::cast(backing_store);
|
2017-05-15 15:56:10 +00:00
|
|
|
if (len > JSArray::kMaxCopyElements && dst_index == 0 &&
|
|
|
|
heap->CanMoveObjectStart(*dst_elms)) {
|
2016-03-29 14:53:49 +00:00
|
|
|
// Update all the copies of this backing_store handle.
|
|
|
|
*dst_elms.location() =
|
|
|
|
BackingStore::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) {
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsDoubleElementsKind(KindTraits::Kind)) {
|
2016-03-29 14:53:49 +00:00
|
|
|
MemMove(dst_elms->data_start() + dst_index,
|
|
|
|
dst_elms->data_start() + src_index, len * kDoubleSize);
|
|
|
|
} else {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
heap->MoveElements(FixedArray::cast(*dst_elms), dst_index, src_index,
|
|
|
|
len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hole_start != hole_end) {
|
|
|
|
dst_elms->FillWithHoles(hole_start, hole_end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-03 03:26:58 +00:00
|
|
|
static Maybe<bool> IncludesValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> search_value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver));
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
FixedArrayBase* elements_base = receiver->elements();
|
|
|
|
Object* the_hole = isolate->heap()->the_hole_value();
|
|
|
|
Object* undefined = isolate->heap()->undefined_value();
|
|
|
|
Object* value = *search_value;
|
|
|
|
|
|
|
|
// Elements beyond the capacity of the backing store treated as undefined.
|
|
|
|
if (value == undefined &&
|
|
|
|
static_cast<uint32_t>(elements_base->length()) < length) {
|
|
|
|
return Just(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start_from >= length) return Just(false);
|
|
|
|
|
|
|
|
length = std::min(static_cast<uint32_t>(elements_base->length()), length);
|
|
|
|
|
|
|
|
if (!value->IsNumber()) {
|
|
|
|
if (value == undefined) {
|
2017-06-30 11:26:14 +00:00
|
|
|
// Only PACKED_ELEMENTS, HOLEY_ELEMENTS, HOLEY_SMI_ELEMENTS, and
|
|
|
|
// HOLEY_DOUBLE_ELEMENTS can have `undefined` as a value.
|
2017-06-30 18:00:44 +00:00
|
|
|
if (!IsObjectElementsKind(Subclass::kind()) &&
|
|
|
|
!IsHoleyElementsKind(Subclass::kind())) {
|
2016-08-03 03:26:58 +00:00
|
|
|
return Just(false);
|
|
|
|
}
|
|
|
|
|
2017-06-30 11:26:14 +00:00
|
|
|
// Search for `undefined` or The Hole in PACKED_ELEMENTS,
|
|
|
|
// HOLEY_ELEMENTS or HOLEY_SMI_ELEMENTS
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsSmiOrObjectElementsKind(Subclass::kind())) {
|
2016-08-03 03:26:58 +00:00
|
|
|
auto elements = FixedArray::cast(receiver->elements());
|
|
|
|
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
|
|
|
Object* element_k = elements->get(k);
|
|
|
|
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsHoleyElementsKind(Subclass::kind()) &&
|
2016-08-03 03:26:58 +00:00
|
|
|
element_k == the_hole) {
|
|
|
|
return Just(true);
|
|
|
|
}
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsObjectElementsKind(Subclass::kind()) &&
|
2016-08-03 03:26:58 +00:00
|
|
|
element_k == undefined) {
|
|
|
|
return Just(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Just(false);
|
|
|
|
} else {
|
2017-06-30 11:26:14 +00:00
|
|
|
// Seach for The Hole in HOLEY_DOUBLE_ELEMENTS
|
|
|
|
DCHECK_EQ(Subclass::kind(), HOLEY_DOUBLE_ELEMENTS);
|
2016-08-03 03:26:58 +00:00
|
|
|
auto elements = FixedDoubleArray::cast(receiver->elements());
|
|
|
|
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsHoleyElementsKind(Subclass::kind()) &&
|
2016-08-03 03:26:58 +00:00
|
|
|
elements->is_the_hole(k)) {
|
|
|
|
return Just(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Just(false);
|
|
|
|
}
|
2017-06-30 18:00:44 +00:00
|
|
|
} else if (!IsObjectElementsKind(Subclass::kind())) {
|
2016-08-03 03:26:58 +00:00
|
|
|
// Search for non-number, non-Undefined value, with either
|
2017-06-30 11:26:14 +00:00
|
|
|
// PACKED_SMI_ELEMENTS, PACKED_DOUBLE_ELEMENTS, HOLEY_SMI_ELEMENTS or
|
|
|
|
// HOLEY_DOUBLE_ELEMENTS. Guaranteed to return false, since these
|
2016-08-03 03:26:58 +00:00
|
|
|
// elements kinds can only contain Number values or undefined.
|
|
|
|
return Just(false);
|
|
|
|
} else {
|
|
|
|
// Search for non-number, non-Undefined value with either
|
2017-06-30 11:26:14 +00:00
|
|
|
// PACKED_ELEMENTS or HOLEY_ELEMENTS.
|
2017-06-30 18:00:44 +00:00
|
|
|
DCHECK(IsObjectElementsKind(Subclass::kind()));
|
2016-08-03 03:26:58 +00:00
|
|
|
auto elements = FixedArray::cast(receiver->elements());
|
|
|
|
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
|
|
|
Object* element_k = elements->get(k);
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsHoleyElementsKind(Subclass::kind()) && element_k == the_hole) {
|
2016-08-03 03:26:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value->SameValueZero(element_k)) return Just(true);
|
|
|
|
}
|
|
|
|
return Just(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!value->IsNaN()) {
|
|
|
|
double search_value = value->Number();
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsDoubleElementsKind(Subclass::kind())) {
|
2017-06-30 11:26:14 +00:00
|
|
|
// Search for non-NaN Number in PACKED_DOUBLE_ELEMENTS or
|
|
|
|
// HOLEY_DOUBLE_ELEMENTS --- Skip TheHole, and trust UCOMISD or
|
2016-08-03 03:26:58 +00:00
|
|
|
// similar operation for result.
|
|
|
|
auto elements = FixedDoubleArray::cast(receiver->elements());
|
|
|
|
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsHoleyElementsKind(Subclass::kind()) &&
|
2016-08-03 03:26:58 +00:00
|
|
|
elements->is_the_hole(k)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (elements->get_scalar(k) == search_value) return Just(true);
|
|
|
|
}
|
|
|
|
return Just(false);
|
|
|
|
} else {
|
2017-06-30 11:26:14 +00:00
|
|
|
// Search for non-NaN Number in PACKED_ELEMENTS, HOLEY_ELEMENTS,
|
|
|
|
// PACKED_SMI_ELEMENTS or HOLEY_SMI_ELEMENTS --- Skip non-Numbers,
|
2016-08-03 03:26:58 +00:00
|
|
|
// and trust UCOMISD or similar operation for result
|
|
|
|
auto elements = FixedArray::cast(receiver->elements());
|
|
|
|
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
|
|
|
Object* element_k = elements->get(k);
|
|
|
|
if (element_k->IsNumber() && element_k->Number() == search_value) {
|
|
|
|
return Just(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Just(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Search for NaN --- NaN cannot be represented with Smi elements, so
|
2017-06-30 11:26:14 +00:00
|
|
|
// abort if ElementsKind is PACKED_SMI_ELEMENTS or HOLEY_SMI_ELEMENTS
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsSmiElementsKind(Subclass::kind())) return Just(false);
|
2016-08-03 03:26:58 +00:00
|
|
|
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsDoubleElementsKind(Subclass::kind())) {
|
2017-06-30 11:26:14 +00:00
|
|
|
// Search for NaN in PACKED_DOUBLE_ELEMENTS or
|
|
|
|
// HOLEY_DOUBLE_ELEMENTS --- Skip The Hole and trust
|
2016-08-03 03:26:58 +00:00
|
|
|
// std::isnan(elementK) for result
|
|
|
|
auto elements = FixedDoubleArray::cast(receiver->elements());
|
|
|
|
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsHoleyElementsKind(Subclass::kind()) &&
|
2016-08-03 03:26:58 +00:00
|
|
|
elements->is_the_hole(k)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (std::isnan(elements->get_scalar(k))) return Just(true);
|
|
|
|
}
|
|
|
|
return Just(false);
|
|
|
|
} else {
|
2017-06-30 11:26:14 +00:00
|
|
|
// Search for NaN in PACKED_ELEMENTS, HOLEY_ELEMENTS,
|
|
|
|
// PACKED_SMI_ELEMENTS or HOLEY_SMI_ELEMENTS. Return true if
|
2016-08-03 03:26:58 +00:00
|
|
|
// elementK->IsHeapNumber() && std::isnan(elementK->Number())
|
2017-06-30 18:00:44 +00:00
|
|
|
DCHECK(IsSmiOrObjectElementsKind(Subclass::kind()));
|
2016-08-03 03:26:58 +00:00
|
|
|
auto elements = FixedArray::cast(receiver->elements());
|
|
|
|
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
|
|
|
if (elements->get(k)->IsNaN()) return Just(true);
|
|
|
|
}
|
|
|
|
return Just(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 14:47:58 +00:00
|
|
|
static Handle<FixedArray> CreateListFromArrayImpl(Isolate* isolate,
|
|
|
|
Handle<JSArray> array) {
|
|
|
|
uint32_t length = 0;
|
|
|
|
array->length()->ToArrayLength(&length);
|
|
|
|
Handle<FixedArray> result = isolate->factory()->NewFixedArray(length);
|
|
|
|
Handle<FixedArrayBase> elements(array->elements(), isolate);
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2017-04-11 17:28:33 +00:00
|
|
|
if (!Subclass::HasElementImpl(isolate, *array, i, *elements)) continue;
|
2016-11-24 14:47:58 +00:00
|
|
|
Handle<Object> value;
|
|
|
|
value = Subclass::GetImpl(isolate, *elements, i);
|
|
|
|
if (value->IsName()) {
|
|
|
|
value = isolate->factory()->InternalizeName(Handle<Name>::cast(value));
|
|
|
|
}
|
|
|
|
result->set(i, *value);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-08-27 13:05:50 +00:00
|
|
|
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;
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::MoveElements(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())) {
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::MoveElements(isolate, receiver, backing_store,
|
|
|
|
start + add_count, start + delete_count,
|
|
|
|
(length - delete_count - start), 0, 0);
|
2015-12-23 11:48:40 +00:00
|
|
|
// 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.
|
2016-04-06 13:38:02 +00:00
|
|
|
Handle<FixedArrayBase> new_elms = Subclass::ConvertElementsWithCapacity(
|
|
|
|
receiver, backing_store, KindTraits::Kind, capacity, start);
|
2015-09-18 11:15:34 +00:00
|
|
|
// Copy the trailing elements after start + delete_count
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::CopyElementsImpl(*backing_store, start + delete_count, *new_elms,
|
|
|
|
KindTraits::Kind, start + add_count,
|
|
|
|
kPackedSizeNotKnown,
|
|
|
|
ElementsAccessor::kCopyToEndAndInitializeToHole);
|
2015-09-18 11:15:34 +00:00
|
|
|
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,
|
|
|
|
Where remove_position) {
|
2015-12-23 11:48:40 +00:00
|
|
|
Isolate* isolate = receiver->GetIsolate();
|
2016-03-07 16:25:00 +00:00
|
|
|
ElementsKind kind = KindTraits::Kind;
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsSmiOrObjectElementsKind(kind)) {
|
2016-03-07 16:25:00 +00:00
|
|
|
HandleScope scope(isolate);
|
|
|
|
JSObject::EnsureWritableFastElements(receiver);
|
|
|
|
}
|
|
|
|
Handle<FixedArrayBase> backing_store(receiver->elements(), isolate);
|
2017-07-10 12:58:27 +00:00
|
|
|
uint32_t length = static_cast<uint32_t>(Smi::ToInt(receiver->length()));
|
2015-09-18 11:15:34 +00:00
|
|
|
DCHECK(length > 0);
|
|
|
|
int new_length = length - 1;
|
|
|
|
int remove_index = remove_position == AT_START ? 0 : new_length;
|
2016-11-24 14:47:58 +00:00
|
|
|
Handle<Object> result =
|
|
|
|
Subclass::GetImpl(isolate, *backing_store, remove_index);
|
2015-09-18 11:15:34 +00:00
|
|
|
if (remove_position == AT_START) {
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::MoveElements(isolate, receiver, backing_store, 0, 1, new_length,
|
|
|
|
0, 0);
|
2015-09-18 11:15:34 +00:00
|
|
|
}
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::SetLengthImpl(isolate, receiver, new_length, backing_store);
|
2015-08-27 13:05:50 +00:00
|
|
|
|
2017-06-30 16:28:26 +00:00
|
|
|
if (IsHoleyOrDictionaryElementsKind(kind) && result->IsTheHole(isolate)) {
|
2016-03-07 16:25:00 +00:00
|
|
|
return isolate->factory()->undefined_value();
|
2015-09-18 11:15:34 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t AddArguments(Handle<JSArray> receiver,
|
|
|
|
Handle<FixedArrayBase> backing_store,
|
|
|
|
Arguments* args, uint32_t add_size,
|
2016-04-07 15:27:35 +00:00
|
|
|
Where add_position) {
|
2017-07-10 12:58:27 +00:00
|
|
|
uint32_t length = Smi::ToInt(receiver->length());
|
2016-03-07 16:25:00 +00:00
|
|
|
DCHECK(0 < add_size);
|
2015-09-18 11:15:34 +00:00
|
|
|
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.
|
2016-04-07 15:27:35 +00:00
|
|
|
int copy_dst_index = add_position == AT_START ? add_size : 0;
|
2015-09-18 11:15:34 +00:00
|
|
|
// Copy over all objects to a new backing_store.
|
2016-04-06 13:38:02 +00:00
|
|
|
backing_store = Subclass::ConvertElementsWithCapacity(
|
2015-09-18 11:15:34 +00:00
|
|
|
receiver, backing_store, KindTraits::Kind, capacity, 0,
|
|
|
|
copy_dst_index, ElementsAccessor::kCopyToEndAndInitializeToHole);
|
|
|
|
receiver->set_elements(*backing_store);
|
2016-04-07 15:27:35 +00:00
|
|
|
} else if (add_position == AT_START) {
|
2015-09-18 11:15:34 +00:00
|
|
|
// 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();
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::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
|
|
|
|
2016-04-07 15:27:35 +00:00
|
|
|
int insertion_index = add_position == AT_START ? 0 : length;
|
2015-09-18 11:15:34 +00:00
|
|
|
// Copy the arguments to the start.
|
2016-04-06 13:38:02 +00:00
|
|
|
Subclass::CopyArguments(args, backing_store, add_size, 1, insertion_index);
|
2015-09-18 11:15:34 +00:00
|
|
|
// 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++) {
|
2016-04-07 15:27:35 +00:00
|
|
|
Object* argument = (*args)[src_index + i];
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(!argument->IsTheHole(raw_backing_store->GetIsolate()));
|
2016-04-07 15:27:35 +00:00
|
|
|
Subclass::SetImpl(raw_backing_store, dst_index + i, argument, mode);
|
2015-08-27 13:05:50 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-23 14:24:29 +00:00
|
|
|
};
|
|
|
|
|
2016-04-06 13:38:02 +00:00
|
|
|
template <typename Subclass, typename KindTraits>
|
2012-05-23 14:24:29 +00:00
|
|
|
class FastSmiOrObjectElementsAccessor
|
2016-04-06 13:38:02 +00:00
|
|
|
: public FastElementsAccessor<Subclass, KindTraits> {
|
2012-05-23 14:24:29 +00:00
|
|
|
public:
|
|
|
|
explicit FastSmiOrObjectElementsAccessor(const char* name)
|
2016-04-06 13:38:02 +00:00
|
|
|
: FastElementsAccessor<Subclass, 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) {
|
2016-04-06 13:38:02 +00:00
|
|
|
uint32_t index = Subclass::GetIndexForEntryImpl(backing_store, entry);
|
2015-07-10 15:51:57 +00:00
|
|
|
return backing_store->get(index);
|
|
|
|
}
|
|
|
|
|
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) {
|
2017-06-30 11:26:14 +00:00
|
|
|
case PACKED_SMI_ELEMENTS:
|
|
|
|
case HOLEY_SMI_ELEMENTS:
|
|
|
|
case PACKED_ELEMENTS:
|
|
|
|
case HOLEY_ELEMENTS:
|
2014-09-29 08:22:24 +00:00
|
|
|
CopyObjectToObjectElements(from, from_kind, from_start, to, to_kind,
|
2014-07-25 13:00:06 +00:00
|
|
|
to_start, copy_size);
|
2014-03-27 16:41:09 +00:00
|
|
|
break;
|
2017-06-30 11:26:14 +00:00
|
|
|
case PACKED_DOUBLE_ELEMENTS:
|
|
|
|
case HOLEY_DOUBLE_ELEMENTS: {
|
2014-09-29 08:22:24 +00:00
|
|
|
AllowHeapAllocation allow_allocation;
|
2017-06-30 18:00:44 +00:00
|
|
|
DCHECK(IsObjectElementsKind(to_kind));
|
2015-09-25 12:26:22 +00:00
|
|
|
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:
|
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-04-06 13:38:02 +00:00
|
|
|
case FAST_STRING_WRAPPER_ELEMENTS:
|
|
|
|
case SLOW_STRING_WRAPPER_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
|
|
|
}
|
|
|
|
}
|
2016-08-22 18:36:50 +00:00
|
|
|
|
|
|
|
static Maybe<int64_t> IndexOfValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> search_value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver));
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
FixedArrayBase* elements_base = receiver->elements();
|
|
|
|
Object* value = *search_value;
|
|
|
|
|
|
|
|
if (start_from >= length) return Just<int64_t>(-1);
|
|
|
|
|
|
|
|
length = std::min(static_cast<uint32_t>(elements_base->length()), length);
|
|
|
|
|
|
|
|
// Only FAST_{,HOLEY_}ELEMENTS can store non-numbers.
|
2017-06-30 18:00:44 +00:00
|
|
|
if (!value->IsNumber() && !IsObjectElementsKind(Subclass::kind())) {
|
2016-08-22 18:36:50 +00:00
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
|
|
|
// NaN can never be found by strict equality.
|
|
|
|
if (value->IsNaN()) return Just<int64_t>(-1);
|
|
|
|
|
|
|
|
FixedArray* elements = FixedArray::cast(receiver->elements());
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
|
|
|
if (value->StrictEquals(elements->get(k))) return Just<int64_t>(k);
|
|
|
|
}
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
2012-05-23 14:24:29 +00:00
|
|
|
};
|
2011-11-08 11:59:56 +00:00
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
class FastPackedSmiElementsAccessor
|
|
|
|
: public FastSmiOrObjectElementsAccessor<
|
2017-06-30 11:26:14 +00:00
|
|
|
FastPackedSmiElementsAccessor,
|
|
|
|
ElementsKindTraits<PACKED_SMI_ELEMENTS>> {
|
2012-05-23 14:24:29 +00:00
|
|
|
public:
|
|
|
|
explicit FastPackedSmiElementsAccessor(const char* name)
|
|
|
|
: FastSmiOrObjectElementsAccessor<
|
2017-06-30 11:26:14 +00:00
|
|
|
FastPackedSmiElementsAccessor,
|
|
|
|
ElementsKindTraits<PACKED_SMI_ELEMENTS>>(name) {}
|
2012-05-23 14:24:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FastHoleySmiElementsAccessor
|
|
|
|
: public FastSmiOrObjectElementsAccessor<
|
2017-06-30 11:26:14 +00:00
|
|
|
FastHoleySmiElementsAccessor,
|
|
|
|
ElementsKindTraits<HOLEY_SMI_ELEMENTS>> {
|
2012-05-23 14:24:29 +00:00
|
|
|
public:
|
|
|
|
explicit FastHoleySmiElementsAccessor(const char* name)
|
2017-06-30 11:26:14 +00:00
|
|
|
: FastSmiOrObjectElementsAccessor<FastHoleySmiElementsAccessor,
|
|
|
|
ElementsKindTraits<HOLEY_SMI_ELEMENTS>>(
|
|
|
|
name) {}
|
2011-08-03 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
class FastPackedObjectElementsAccessor
|
|
|
|
: public FastSmiOrObjectElementsAccessor<
|
2017-06-30 11:26:14 +00:00
|
|
|
FastPackedObjectElementsAccessor,
|
|
|
|
ElementsKindTraits<PACKED_ELEMENTS>> {
|
2012-05-23 14:24:29 +00:00
|
|
|
public:
|
|
|
|
explicit FastPackedObjectElementsAccessor(const char* name)
|
2017-06-30 11:26:14 +00:00
|
|
|
: FastSmiOrObjectElementsAccessor<FastPackedObjectElementsAccessor,
|
|
|
|
ElementsKindTraits<PACKED_ELEMENTS>>(
|
|
|
|
name) {}
|
2012-05-23 14:24:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FastHoleyObjectElementsAccessor
|
|
|
|
: public FastSmiOrObjectElementsAccessor<
|
2017-06-30 11:26:14 +00:00
|
|
|
FastHoleyObjectElementsAccessor, ElementsKindTraits<HOLEY_ELEMENTS>> {
|
2012-05-23 14:24:29 +00:00
|
|
|
public:
|
|
|
|
explicit FastHoleyObjectElementsAccessor(const char* name)
|
2017-06-30 11:26:14 +00:00
|
|
|
: FastSmiOrObjectElementsAccessor<FastHoleyObjectElementsAccessor,
|
|
|
|
ElementsKindTraits<HOLEY_ELEMENTS>>(
|
|
|
|
name) {}
|
2012-05-23 14:24:29 +00:00
|
|
|
};
|
|
|
|
|
2016-04-06 13:38:02 +00:00
|
|
|
template <typename Subclass, typename KindTraits>
|
2011-08-03 11:12:46 +00:00
|
|
|
class FastDoubleElementsAccessor
|
2016-04-06 13:38:02 +00:00
|
|
|
: public FastElementsAccessor<Subclass, KindTraits> {
|
2012-03-06 12:03:14 +00:00
|
|
|
public:
|
|
|
|
explicit FastDoubleElementsAccessor(const char* name)
|
2016-04-06 13:38:02 +00:00
|
|
|
: FastElementsAccessor<Subclass, KindTraits>(name) {}
|
2012-03-06 12:03:14 +00:00
|
|
|
|
2016-11-24 14:47:58 +00:00
|
|
|
static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store,
|
|
|
|
uint32_t entry) {
|
2016-01-29 18:57:26 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
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) {
|
2017-06-30 11:26:14 +00:00
|
|
|
case PACKED_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;
|
2017-06-30 11:26:14 +00:00
|
|
|
case 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;
|
2017-06-30 11:26:14 +00:00
|
|
|
case PACKED_DOUBLE_ELEMENTS:
|
|
|
|
case 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;
|
2017-06-30 11:26:14 +00:00
|
|
|
case PACKED_ELEMENTS:
|
|
|
|
case 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
|
|
|
}
|
|
|
|
}
|
2016-08-22 18:36:50 +00:00
|
|
|
|
|
|
|
static Maybe<int64_t> IndexOfValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> search_value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver));
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
FixedArrayBase* elements_base = receiver->elements();
|
|
|
|
Object* value = *search_value;
|
|
|
|
|
|
|
|
length = std::min(static_cast<uint32_t>(elements_base->length()), length);
|
|
|
|
|
2017-03-16 06:53:09 +00:00
|
|
|
if (start_from >= length) return Just<int64_t>(-1);
|
|
|
|
|
2016-08-22 18:36:50 +00:00
|
|
|
if (!value->IsNumber()) {
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
|
|
|
if (value->IsNaN()) {
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
|
|
|
double numeric_search_value = value->Number();
|
|
|
|
FixedDoubleArray* elements = FixedDoubleArray::cast(receiver->elements());
|
|
|
|
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
|
|
|
if (elements->is_the_hole(k)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (elements->get_scalar(k) == numeric_search_value) {
|
|
|
|
return Just<int64_t>(k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
2012-05-23 14:24:29 +00:00
|
|
|
};
|
2012-03-09 13:48:29 +00:00
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
class FastPackedDoubleElementsAccessor
|
|
|
|
: public FastDoubleElementsAccessor<
|
2017-06-30 11:26:14 +00:00
|
|
|
FastPackedDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<PACKED_DOUBLE_ELEMENTS>> {
|
2012-05-23 14:24:29 +00:00
|
|
|
public:
|
|
|
|
explicit FastPackedDoubleElementsAccessor(const char* name)
|
2017-06-30 11:26:14 +00:00
|
|
|
: FastDoubleElementsAccessor<FastPackedDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<PACKED_DOUBLE_ELEMENTS>>(
|
|
|
|
name) {}
|
2012-05-23 14:24:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FastHoleyDoubleElementsAccessor
|
|
|
|
: public FastDoubleElementsAccessor<
|
2017-06-30 11:26:14 +00:00
|
|
|
FastHoleyDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<HOLEY_DOUBLE_ELEMENTS>> {
|
2012-05-23 14:24:29 +00:00
|
|
|
public:
|
|
|
|
explicit FastHoleyDoubleElementsAccessor(const char* name)
|
2017-06-30 11:26:14 +00:00
|
|
|
: FastDoubleElementsAccessor<FastHoleyDoubleElementsAccessor,
|
|
|
|
ElementsKindTraits<HOLEY_DOUBLE_ELEMENTS>>(
|
|
|
|
name) {}
|
2011-08-03 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Super class for all external element arrays.
|
2016-08-03 03:26:58 +00:00
|
|
|
template <ElementsKind Kind, typename ctype>
|
2014-01-16 17:08:45 +00:00
|
|
|
class TypedElementsAccessor
|
2016-08-03 03:26:58 +00:00
|
|
|
: public ElementsAccessorBase<TypedElementsAccessor<Kind, ctype>,
|
|
|
|
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;
|
2016-08-03 03:26:58 +00:00
|
|
|
typedef TypedElementsAccessor<Kind, ctype> 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-11-24 14:47:58 +00:00
|
|
|
static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store,
|
|
|
|
uint32_t entry) {
|
2016-01-29 18:57:26 +00:00
|
|
|
return BackingStore::get(BackingStore::cast(backing_store), entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PropertyDetails GetDetailsImpl(JSObject* holder, uint32_t entry) {
|
2017-06-22 09:52:28 +00:00
|
|
|
return PropertyDetails(kData, DONT_DELETE, 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) {
|
2017-06-22 09:52:28 +00:00
|
|
|
return PropertyDetails(kData, DONT_DELETE, PropertyCellType::kNoCell);
|
2012-11-15 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-04-11 17:28:33 +00:00
|
|
|
static bool HasElementImpl(Isolate* isolate, JSObject* holder, uint32_t index,
|
|
|
|
FixedArrayBase* backing_store,
|
2016-01-29 18:57:26 +00:00
|
|
|
PropertyFilter filter) {
|
2017-04-11 17:28:33 +00:00
|
|
|
return index < AccessorClass::GetCapacityImpl(holder, backing_store);
|
2016-01-29 18:57:26 +00:00
|
|
|
}
|
|
|
|
|
2016-03-15 20:28:15 +00:00
|
|
|
static bool HasAccessorsImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
static uint32_t GetEntryForIndexImpl(Isolate* isolate, JSObject* holder,
|
2015-07-07 11:52:51 +00:00
|
|
|
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
|
|
|
|
2017-02-16 10:13:56 +00:00
|
|
|
static bool WasNeutered(JSObject* holder) {
|
|
|
|
JSArrayBufferView* view = JSArrayBufferView::cast(holder);
|
|
|
|
return view->WasNeutered();
|
|
|
|
}
|
|
|
|
|
2015-05-21 12:19:39 +00:00
|
|
|
static uint32_t GetCapacityImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store) {
|
2017-02-16 10:13:56 +00:00
|
|
|
if (WasNeutered(holder)) return 0;
|
2015-04-27 09:28:16 +00:00
|
|
|
return backing_store->length();
|
|
|
|
}
|
2016-01-29 18:57:26 +00:00
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
static uint32_t NumberOfElementsImpl(JSObject* receiver,
|
|
|
|
FixedArrayBase* backing_store) {
|
|
|
|
return AccessorClass::GetCapacityImpl(receiver, backing_store);
|
|
|
|
}
|
|
|
|
|
2016-01-29 18:57:26 +00:00
|
|
|
static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver,
|
|
|
|
KeyAccumulator* accumulator,
|
|
|
|
AddKeyConversion convert) {
|
2016-11-24 14:47:58 +00:00
|
|
|
Isolate* isolate = receiver->GetIsolate();
|
2016-03-07 16:25:00 +00:00
|
|
|
Handle<FixedArrayBase> elements(receiver->elements());
|
2016-01-29 18:57:26 +00:00
|
|
|
uint32_t length = AccessorClass::GetCapacityImpl(*receiver, *elements);
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2016-11-24 14:47:58 +00:00
|
|
|
Handle<Object> value = AccessorClass::GetImpl(isolate, *elements, i);
|
2016-01-29 18:57:26 +00:00
|
|
|
accumulator->AddKey(value, convert);
|
|
|
|
}
|
|
|
|
}
|
2016-03-28 15:53:15 +00:00
|
|
|
|
|
|
|
static Maybe<bool> CollectValuesOrEntriesImpl(
|
|
|
|
Isolate* isolate, Handle<JSObject> object,
|
|
|
|
Handle<FixedArray> values_or_entries, bool get_entries, int* nof_items,
|
|
|
|
PropertyFilter filter) {
|
|
|
|
int count = 0;
|
|
|
|
if ((filter & ONLY_CONFIGURABLE) == 0) {
|
|
|
|
Handle<FixedArrayBase> elements(object->elements());
|
|
|
|
uint32_t length = AccessorClass::GetCapacityImpl(*object, *elements);
|
|
|
|
for (uint32_t index = 0; index < length; ++index) {
|
2016-11-24 14:47:58 +00:00
|
|
|
Handle<Object> value =
|
|
|
|
AccessorClass::GetImpl(isolate, *elements, index);
|
2016-03-28 15:53:15 +00:00
|
|
|
if (get_entries) {
|
|
|
|
value = MakeEntryPair(isolate, index, value);
|
|
|
|
}
|
|
|
|
values_or_entries->set(count++, *value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*nof_items = count;
|
|
|
|
return Just(true);
|
|
|
|
}
|
2011-08-03 11:12:46 +00:00
|
|
|
|
2017-03-20 13:32:54 +00:00
|
|
|
static Object* FillImpl(Isolate* isolate, Handle<JSObject> receiver,
|
|
|
|
Handle<Object> obj_value, uint32_t start,
|
|
|
|
uint32_t end) {
|
|
|
|
Handle<JSTypedArray> array = Handle<JSTypedArray>::cast(receiver);
|
|
|
|
DCHECK(!array->WasNeutered());
|
2017-04-03 09:34:29 +00:00
|
|
|
DCHECK(obj_value->IsNumber());
|
2017-03-20 13:32:54 +00:00
|
|
|
|
2017-03-24 22:43:35 +00:00
|
|
|
ctype value;
|
2017-03-20 13:32:54 +00:00
|
|
|
if (obj_value->IsSmi()) {
|
2017-07-10 12:58:27 +00:00
|
|
|
value = BackingStore::from(Smi::ToInt(*obj_value));
|
2017-03-20 13:32:54 +00:00
|
|
|
} else {
|
2017-04-03 09:34:29 +00:00
|
|
|
DCHECK(obj_value->IsHeapNumber());
|
2017-04-19 12:06:39 +00:00
|
|
|
value = BackingStore::from(HeapNumber::cast(*obj_value)->value());
|
2017-03-20 13:32:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure indexes are within array bounds
|
|
|
|
DCHECK_LE(0, start);
|
|
|
|
DCHECK_LE(start, end);
|
|
|
|
DCHECK_LE(end, array->length_value());
|
|
|
|
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
BackingStore* elements = BackingStore::cast(receiver->elements());
|
|
|
|
ctype* data = static_cast<ctype*>(elements->DataPtr());
|
|
|
|
std::fill(data + start, data + end, value);
|
|
|
|
return *array;
|
|
|
|
}
|
|
|
|
|
2016-08-03 03:26:58 +00:00
|
|
|
static Maybe<bool> IncludesValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
2016-08-01 22:19:25 +00:00
|
|
|
|
2017-02-16 10:13:56 +00:00
|
|
|
// TODO(caitp): return Just(false) here when implementing strict throwing on
|
|
|
|
// neutered views.
|
|
|
|
if (WasNeutered(*receiver)) {
|
|
|
|
return Just(value->IsUndefined(isolate) && length > start_from);
|
|
|
|
}
|
|
|
|
|
2016-08-03 03:26:58 +00:00
|
|
|
BackingStore* elements = BackingStore::cast(receiver->elements());
|
|
|
|
if (value->IsUndefined(isolate) &&
|
|
|
|
length > static_cast<uint32_t>(elements->length())) {
|
|
|
|
return Just(true);
|
|
|
|
}
|
|
|
|
if (!value->IsNumber()) return Just(false);
|
|
|
|
|
|
|
|
double search_value = value->Number();
|
|
|
|
|
|
|
|
if (!std::isfinite(search_value)) {
|
|
|
|
// Integral types cannot represent +Inf or NaN
|
|
|
|
if (AccessorClass::kind() < FLOAT32_ELEMENTS ||
|
|
|
|
AccessorClass::kind() > FLOAT64_ELEMENTS) {
|
|
|
|
return Just(false);
|
|
|
|
}
|
|
|
|
} else if (search_value < std::numeric_limits<ctype>::lowest() ||
|
|
|
|
search_value > std::numeric_limits<ctype>::max()) {
|
|
|
|
// Return false if value can't be represented in this space
|
|
|
|
return Just(false);
|
|
|
|
}
|
|
|
|
|
2016-08-04 15:53:10 +00:00
|
|
|
// Prototype has no elements, and not searching for the hole --- limit
|
|
|
|
// search to backing store length.
|
|
|
|
if (static_cast<uint32_t>(elements->length()) < length) {
|
|
|
|
length = elements->length();
|
|
|
|
}
|
|
|
|
|
2016-08-03 03:26:58 +00:00
|
|
|
if (!std::isnan(search_value)) {
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
|
|
|
double element_k = elements->get_scalar(k);
|
|
|
|
if (element_k == search_value) return Just(true);
|
|
|
|
}
|
|
|
|
return Just(false);
|
|
|
|
} else {
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
|
|
|
double element_k = elements->get_scalar(k);
|
|
|
|
if (std::isnan(element_k)) return Just(true);
|
|
|
|
}
|
|
|
|
return Just(false);
|
|
|
|
}
|
|
|
|
}
|
2016-08-22 18:36:50 +00:00
|
|
|
|
|
|
|
static Maybe<int64_t> IndexOfValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
|
2017-02-16 10:13:56 +00:00
|
|
|
if (WasNeutered(*receiver)) return Just<int64_t>(-1);
|
|
|
|
|
2016-08-22 18:36:50 +00:00
|
|
|
BackingStore* elements = BackingStore::cast(receiver->elements());
|
|
|
|
if (!value->IsNumber()) return Just<int64_t>(-1);
|
|
|
|
|
|
|
|
double search_value = value->Number();
|
|
|
|
|
|
|
|
if (!std::isfinite(search_value)) {
|
|
|
|
// Integral types cannot represent +Inf or NaN.
|
|
|
|
if (AccessorClass::kind() < FLOAT32_ELEMENTS ||
|
|
|
|
AccessorClass::kind() > FLOAT64_ELEMENTS) {
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
|
|
|
} else if (search_value < std::numeric_limits<ctype>::lowest() ||
|
|
|
|
search_value > std::numeric_limits<ctype>::max()) {
|
|
|
|
// Return false if value can't be represented in this ElementsKind.
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prototype has no elements, and not searching for the hole --- limit
|
|
|
|
// search to backing store length.
|
|
|
|
if (static_cast<uint32_t>(elements->length()) < length) {
|
|
|
|
length = elements->length();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (std::isnan(search_value)) {
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctype typed_search_value = static_cast<ctype>(search_value);
|
|
|
|
if (static_cast<double>(typed_search_value) != search_value) {
|
|
|
|
return Just<int64_t>(-1); // Loss of precision.
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
|
|
|
ctype element_k = elements->get_scalar(k);
|
|
|
|
if (element_k == typed_search_value) return Just<int64_t>(k);
|
|
|
|
}
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
2017-03-16 16:28:00 +00:00
|
|
|
|
|
|
|
static Maybe<int64_t> LastIndexOfValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
DCHECK(!WasNeutered(*receiver));
|
|
|
|
|
|
|
|
if (!value->IsNumber()) return Just<int64_t>(-1);
|
|
|
|
BackingStore* elements = BackingStore::cast(receiver->elements());
|
|
|
|
|
|
|
|
double search_value = value->Number();
|
|
|
|
|
|
|
|
if (!std::isfinite(search_value)) {
|
|
|
|
if (std::is_integral<ctype>::value) {
|
|
|
|
// Integral types cannot represent +Inf or NaN.
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
} else if (std::isnan(search_value)) {
|
|
|
|
// Strict Equality Comparison of NaN is always false.
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
|
|
|
} else if (search_value < std::numeric_limits<ctype>::lowest() ||
|
|
|
|
search_value > std::numeric_limits<ctype>::max()) {
|
|
|
|
// Return -1 if value can't be represented in this ElementsKind.
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctype typed_search_value = static_cast<ctype>(search_value);
|
|
|
|
if (static_cast<double>(typed_search_value) != search_value) {
|
|
|
|
return Just<int64_t>(-1); // Loss of precision.
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK_LT(start_from, elements->length());
|
|
|
|
|
|
|
|
uint32_t k = start_from;
|
|
|
|
do {
|
|
|
|
ctype element_k = elements->get_scalar(k);
|
|
|
|
if (element_k == typed_search_value) return Just<int64_t>(k);
|
|
|
|
} while (k-- != 0);
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
2017-03-25 16:04:35 +00:00
|
|
|
|
|
|
|
static void ReverseImpl(JSObject* receiver) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
DCHECK(!WasNeutered(receiver));
|
|
|
|
|
|
|
|
BackingStore* elements = BackingStore::cast(receiver->elements());
|
|
|
|
|
|
|
|
uint32_t len = elements->length();
|
|
|
|
if (len == 0) return;
|
|
|
|
|
|
|
|
ctype* data = static_cast<ctype*>(elements->DataPtr());
|
|
|
|
std::reverse(data, data + len);
|
|
|
|
}
|
2017-04-01 16:46:10 +00:00
|
|
|
|
|
|
|
static Handle<JSObject> SliceWithResultImpl(Handle<JSObject> receiver,
|
|
|
|
uint32_t start, uint32_t end,
|
|
|
|
Handle<JSObject> result) {
|
|
|
|
Isolate* isolate = receiver->GetIsolate();
|
|
|
|
DCHECK(!WasNeutered(*receiver));
|
|
|
|
DCHECK(result->IsJSTypedArray());
|
|
|
|
DCHECK(!WasNeutered(*result));
|
|
|
|
DCHECK_LE(start, end);
|
|
|
|
|
|
|
|
Handle<JSTypedArray> array = Handle<JSTypedArray>::cast(receiver);
|
|
|
|
Handle<JSTypedArray> result_array = Handle<JSTypedArray>::cast(result);
|
|
|
|
DCHECK_LE(end, array->length_value());
|
|
|
|
|
|
|
|
// Fast path for the same type result array
|
|
|
|
if (result_array->type() == array->type()) {
|
|
|
|
int64_t element_size = array->element_size();
|
|
|
|
int64_t count = end - start;
|
|
|
|
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
BackingStore* src_elements = BackingStore::cast(receiver->elements());
|
|
|
|
BackingStore* result_elements =
|
|
|
|
BackingStore::cast(result_array->elements());
|
|
|
|
|
|
|
|
DCHECK_LE(count, result_elements->length());
|
2017-04-10 12:31:20 +00:00
|
|
|
uint8_t* src =
|
|
|
|
static_cast<uint8_t*>(src_elements->DataPtr()) + start * element_size;
|
2017-04-01 16:46:10 +00:00
|
|
|
uint8_t* result = static_cast<uint8_t*>(result_elements->DataPtr());
|
2017-04-10 12:31:20 +00:00
|
|
|
if (array->buffer() != result_array->buffer()) {
|
|
|
|
std::memcpy(result, src, count * element_size);
|
|
|
|
} else {
|
|
|
|
// The spec defines the copy-step iteratively, which means that we
|
|
|
|
// cannot use memcpy if the buffer is shared.
|
|
|
|
uint8_t* end = src + count * element_size;
|
|
|
|
while (src < end) {
|
|
|
|
*result++ = *src++;
|
|
|
|
}
|
|
|
|
}
|
2017-04-01 16:46:10 +00:00
|
|
|
return result_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the types of the two typed arrays are different, properly convert
|
|
|
|
// elements
|
|
|
|
Handle<BackingStore> from(BackingStore::cast(array->elements()), isolate);
|
|
|
|
ElementsAccessor* result_accessor = result_array->GetElementsAccessor();
|
|
|
|
for (uint32_t i = start; i < end; i++) {
|
|
|
|
Handle<Object> elem = AccessorClass::GetImpl(isolate, *from, i);
|
2017-05-29 13:27:07 +00:00
|
|
|
result_accessor->Set(result_array, i - start, *elem);
|
2017-04-01 16:46:10 +00:00
|
|
|
}
|
|
|
|
return result_array;
|
|
|
|
}
|
2017-04-19 12:06:39 +00:00
|
|
|
|
|
|
|
static bool HasSimpleRepresentation(InstanceType type) {
|
|
|
|
return !(type == FIXED_FLOAT32_ARRAY_TYPE ||
|
|
|
|
type == FIXED_FLOAT64_ARRAY_TYPE ||
|
|
|
|
type == FIXED_UINT8_CLAMPED_ARRAY_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename SourceTraits>
|
|
|
|
static void CopyBetweenBackingStores(FixedTypedArrayBase* source,
|
|
|
|
BackingStore* dest, size_t length) {
|
|
|
|
FixedTypedArray<SourceTraits>* source_fta =
|
|
|
|
FixedTypedArray<SourceTraits>::cast(source);
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
|
|
|
typename SourceTraits::ElementType elem = source_fta->get_scalar(i);
|
|
|
|
dest->set(i, dest->from(elem));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CopyElementsHandleFromTypedArray(Handle<JSTypedArray> source,
|
|
|
|
Handle<JSTypedArray> destination,
|
|
|
|
size_t length) {
|
|
|
|
// The source is a typed array, so we know we don't need to do ToNumber
|
|
|
|
// side-effects, as the source elements will always be a number or
|
|
|
|
// undefined.
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
|
|
|
|
Handle<FixedTypedArrayBase> source_elements(
|
|
|
|
FixedTypedArrayBase::cast(source->elements()));
|
|
|
|
Handle<BackingStore> destination_elements(
|
|
|
|
BackingStore::cast(destination->elements()));
|
|
|
|
|
2017-04-26 15:45:30 +00:00
|
|
|
DCHECK_GE(destination->length(), source->length());
|
2017-04-19 12:06:39 +00:00
|
|
|
DCHECK(source->length()->IsSmi());
|
|
|
|
DCHECK_EQ(Smi::FromInt(static_cast<int>(length)), source->length());
|
|
|
|
|
|
|
|
InstanceType source_type = source_elements->map()->instance_type();
|
|
|
|
InstanceType destination_type =
|
|
|
|
destination_elements->map()->instance_type();
|
|
|
|
|
|
|
|
bool same_type = source_type == destination_type;
|
2017-05-02 13:38:36 +00:00
|
|
|
bool same_size = source->element_size() == destination->element_size();
|
2017-04-19 12:06:39 +00:00
|
|
|
bool both_are_simple = HasSimpleRepresentation(source_type) &&
|
|
|
|
HasSimpleRepresentation(destination_type);
|
|
|
|
|
2017-05-02 13:38:36 +00:00
|
|
|
// We assume the source and destination don't overlap, even though they
|
|
|
|
// can share the same buffer. This is always true for newly allocated
|
|
|
|
// TypedArrays.
|
|
|
|
uint8_t* source_data = static_cast<uint8_t*>(source_elements->DataPtr());
|
|
|
|
uint8_t* dest_data = static_cast<uint8_t*>(destination_elements->DataPtr());
|
2017-05-05 09:27:58 +00:00
|
|
|
size_t source_byte_length = NumberToSize(source->byte_length());
|
|
|
|
size_t dest_byte_length = NumberToSize(destination->byte_length());
|
2017-05-02 13:38:36 +00:00
|
|
|
CHECK(dest_data + dest_byte_length <= source_data ||
|
|
|
|
source_data + source_byte_length <= dest_data);
|
|
|
|
|
2017-04-19 12:06:39 +00:00
|
|
|
// We can simply copy the backing store if the types are the same, or if
|
|
|
|
// we are converting e.g. Uint8 <-> Int8, as the binary representation
|
|
|
|
// will be the same. This is not the case for floats or clamped Uint8,
|
|
|
|
// which have special conversion operations.
|
|
|
|
if (same_type || (same_size && both_are_simple)) {
|
2017-05-02 13:38:36 +00:00
|
|
|
size_t element_size = source->element_size();
|
|
|
|
std::memcpy(dest_data, source_data, length * element_size);
|
2017-04-19 12:06:39 +00:00
|
|
|
} else {
|
|
|
|
// We use scalar accessors below to avoid boxing/unboxing, so there are
|
|
|
|
// no allocations.
|
|
|
|
switch (source->GetElementsKind()) {
|
|
|
|
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
|
|
|
|
case TYPE##_ELEMENTS: \
|
|
|
|
CopyBetweenBackingStores<Type##ArrayTraits>( \
|
|
|
|
*source_elements, *destination_elements, length); \
|
|
|
|
break;
|
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_CASE)
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#undef TYPED_ARRAY_CASE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-26 14:38:19 +00:00
|
|
|
static bool HoleyPrototypeLookupRequired(Isolate* isolate,
|
|
|
|
Handle<JSArray> source) {
|
|
|
|
Object* source_proto = source->map()->prototype();
|
|
|
|
// Null prototypes are OK - we don't need to do prototype chain lookups on
|
|
|
|
// them.
|
|
|
|
if (source_proto->IsNull(isolate)) return false;
|
|
|
|
if (source_proto->IsJSProxy()) return true;
|
|
|
|
DCHECK(source_proto->IsJSObject());
|
|
|
|
if (!isolate->is_initial_array_prototype(JSObject::cast(source_proto))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return !isolate->IsFastArrayConstructorPrototypeChainIntact();
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:06:39 +00:00
|
|
|
static bool TryCopyElementsHandleFastNumber(Handle<JSArray> source,
|
|
|
|
Handle<JSTypedArray> destination,
|
|
|
|
size_t length) {
|
2017-04-26 14:38:19 +00:00
|
|
|
Isolate* isolate = source->GetIsolate();
|
2017-04-19 12:06:39 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2017-04-26 14:38:19 +00:00
|
|
|
DisallowJavascriptExecution no_js(isolate);
|
|
|
|
|
2017-04-19 12:06:39 +00:00
|
|
|
ElementsKind kind = source->GetElementsKind();
|
|
|
|
BackingStore* dest = BackingStore::cast(destination->elements());
|
|
|
|
|
2017-04-26 14:38:19 +00:00
|
|
|
// When we find the hole, we normally have to look up the element on the
|
|
|
|
// prototype chain, which is not handled here and we return false instead.
|
|
|
|
// When the array has the original array prototype, and that prototype has
|
|
|
|
// not been changed in a way that would affect lookups, we can just convert
|
|
|
|
// the hole into undefined.
|
|
|
|
if (HoleyPrototypeLookupRequired(isolate, source)) return false;
|
|
|
|
|
|
|
|
Object* undefined = isolate->heap()->undefined_value();
|
|
|
|
|
|
|
|
// Fastpath for packed Smi kind.
|
2017-06-30 11:26:14 +00:00
|
|
|
if (kind == PACKED_SMI_ELEMENTS) {
|
2017-04-19 12:06:39 +00:00
|
|
|
FixedArray* source_store = FixedArray::cast(source->elements());
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
|
|
|
Object* elem = source_store->get(i);
|
|
|
|
DCHECK(elem->IsSmi());
|
2017-07-10 12:58:27 +00:00
|
|
|
int int_value = Smi::ToInt(elem);
|
2017-04-19 12:06:39 +00:00
|
|
|
dest->set(i, dest->from(int_value));
|
|
|
|
}
|
|
|
|
return true;
|
2017-06-30 11:26:14 +00:00
|
|
|
} else if (kind == HOLEY_SMI_ELEMENTS) {
|
2017-04-26 14:38:19 +00:00
|
|
|
FixedArray* source_store = FixedArray::cast(source->elements());
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
|
|
|
if (source_store->is_the_hole(isolate, i)) {
|
|
|
|
dest->SetValue(i, undefined);
|
|
|
|
} else {
|
|
|
|
Object* elem = source_store->get(i);
|
|
|
|
DCHECK(elem->IsSmi());
|
2017-07-10 12:58:27 +00:00
|
|
|
int int_value = Smi::ToInt(elem);
|
2017-04-26 14:38:19 +00:00
|
|
|
dest->set(i, dest->from(int_value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2017-06-30 11:26:14 +00:00
|
|
|
} else if (kind == PACKED_DOUBLE_ELEMENTS) {
|
2017-04-19 12:06:39 +00:00
|
|
|
// Fastpath for packed double kind. We avoid boxing and then immediately
|
|
|
|
// unboxing the double here by using get_scalar.
|
|
|
|
FixedDoubleArray* source_store =
|
|
|
|
FixedDoubleArray::cast(source->elements());
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
|
|
|
// Use the from_double conversion for this specific TypedArray type,
|
|
|
|
// rather than relying on C++ to convert elem.
|
|
|
|
double elem = source_store->get_scalar(i);
|
|
|
|
dest->set(i, dest->from(elem));
|
|
|
|
}
|
|
|
|
return true;
|
2017-06-30 11:26:14 +00:00
|
|
|
} else if (kind == HOLEY_DOUBLE_ELEMENTS) {
|
2017-04-26 14:38:19 +00:00
|
|
|
FixedDoubleArray* source_store =
|
|
|
|
FixedDoubleArray::cast(source->elements());
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
|
|
|
if (source_store->is_the_hole(i)) {
|
|
|
|
dest->SetValue(i, undefined);
|
|
|
|
} else {
|
|
|
|
double elem = source_store->get_scalar(i);
|
|
|
|
dest->set(i, dest->from(elem));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2017-04-19 12:06:39 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Object* CopyElementsHandleSlow(Handle<JSReceiver> source,
|
|
|
|
Handle<JSTypedArray> destination,
|
|
|
|
size_t length) {
|
|
|
|
Isolate* isolate = source->GetIsolate();
|
|
|
|
Handle<BackingStore> destination_elements(
|
|
|
|
BackingStore::cast(destination->elements()));
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
|
|
|
LookupIterator it(isolate, source, i, source);
|
|
|
|
Handle<Object> elem;
|
|
|
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, elem,
|
|
|
|
Object::GetProperty(&it));
|
|
|
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, elem, Object::ToNumber(elem));
|
|
|
|
// We don't need to check for buffer neutering here, because the
|
|
|
|
// source cannot be a TypedArray.
|
|
|
|
// The spec says we store the length, then get each element, so we don't
|
|
|
|
// need to check changes to length.
|
|
|
|
destination_elements->SetValue(i, *elem);
|
|
|
|
}
|
|
|
|
return Smi::kZero;
|
|
|
|
}
|
|
|
|
|
2017-04-26 15:45:30 +00:00
|
|
|
// This doesn't guarantee that the destination array will be completely
|
|
|
|
// filled. The caller must do this by passing a source with equal length, if
|
|
|
|
// that is required.
|
2017-04-19 12:06:39 +00:00
|
|
|
static Object* CopyElementsHandleImpl(Handle<JSReceiver> source,
|
|
|
|
Handle<JSObject> destination,
|
|
|
|
size_t length) {
|
|
|
|
Handle<JSTypedArray> destination_ta =
|
|
|
|
Handle<JSTypedArray>::cast(destination);
|
|
|
|
|
|
|
|
// All conversions from TypedArrays can be done without allocation.
|
|
|
|
if (source->IsJSTypedArray()) {
|
|
|
|
Handle<JSTypedArray> source_ta = Handle<JSTypedArray>::cast(source);
|
|
|
|
CopyElementsHandleFromTypedArray(source_ta, destination_ta, length);
|
|
|
|
return Smi::kZero;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fast cases for packed numbers kinds where we don't need to allocate.
|
|
|
|
if (source->IsJSArray()) {
|
|
|
|
Handle<JSArray> source_array = Handle<JSArray>::cast(source);
|
|
|
|
if (TryCopyElementsHandleFastNumber(source_array, destination_ta,
|
|
|
|
length)) {
|
|
|
|
return Smi::kZero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Final generic case that handles prototype chain lookups, getters, proxies
|
|
|
|
// and observable side effects via valueOf, etc.
|
|
|
|
return CopyElementsHandleSlow(source, destination_ta, length);
|
|
|
|
}
|
2016-08-03 03:26:58 +00:00
|
|
|
};
|
2011-08-03 11:12:46 +00:00
|
|
|
|
2016-08-03 03:26:58 +00:00
|
|
|
#define FIXED_ELEMENTS_ACCESSOR(Type, type, TYPE, ctype, size) \
|
|
|
|
typedef TypedElementsAccessor<TYPE##_ELEMENTS, ctype> \
|
2014-01-24 16:01:15 +00:00
|
|
|
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
|
|
|
|
2016-04-06 13:38:02 +00:00
|
|
|
template <typename Subclass, typename ArgumentsAccessor, typename KindTraits>
|
2015-07-02 16:44:17 +00:00
|
|
|
class SloppyArgumentsElementsAccessor
|
2016-04-06 13:38:02 +00:00
|
|
|
: public ElementsAccessorBase<Subclass, KindTraits> {
|
2015-07-02 16:44:17 +00:00
|
|
|
public:
|
|
|
|
explicit SloppyArgumentsElementsAccessor(const char* name)
|
2016-04-06 13:38:02 +00:00
|
|
|
: ElementsAccessorBase<Subclass, KindTraits>(name) {
|
2015-07-10 14:13:27 +00:00
|
|
|
USE(KindTraits::Kind);
|
|
|
|
}
|
2015-07-02 14:38:37 +00:00
|
|
|
|
2017-04-06 08:51:47 +00:00
|
|
|
static void ConvertArgumentsStoreResult(
|
|
|
|
Isolate* isolate, Handle<SloppyArgumentsElements> elements,
|
|
|
|
Handle<Object> result) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2016-11-24 14:47:58 +00:00
|
|
|
static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* parameters,
|
|
|
|
uint32_t entry) {
|
2017-04-06 08:51:47 +00:00
|
|
|
Handle<SloppyArgumentsElements> elements(
|
|
|
|
SloppyArgumentsElements::cast(parameters), isolate);
|
|
|
|
uint32_t length = elements->parameter_map_length();
|
2015-07-10 14:13:27 +00:00
|
|
|
if (entry < length) {
|
2017-04-06 08:51:47 +00:00
|
|
|
// Read context mapped entry.
|
2015-07-02 16:44:17 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2017-04-06 08:51:47 +00:00
|
|
|
Object* probe = elements->get_mapped_entry(entry);
|
|
|
|
DCHECK(!probe->IsTheHole(isolate));
|
|
|
|
Context* context = elements->context();
|
2017-07-10 12:58:27 +00:00
|
|
|
int context_entry = Smi::ToInt(probe);
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(!context->get(context_entry)->IsTheHole(isolate));
|
2015-07-07 11:52:51 +00:00
|
|
|
return handle(context->get(context_entry), isolate);
|
2015-07-02 16:44:17 +00:00
|
|
|
} else {
|
2017-04-06 08:51:47 +00:00
|
|
|
// Entry is not context mapped, defer to the arguments.
|
2016-01-29 18:57:26 +00:00
|
|
|
Handle<Object> result = ArgumentsAccessor::GetImpl(
|
2017-04-06 08:51:47 +00:00
|
|
|
isolate, elements->arguments(), entry - length);
|
|
|
|
return Subclass::ConvertArgumentsStoreResult(isolate, elements, result);
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-03 11:12:46 +00:00
|
|
|
|
2016-07-19 13:38:12 +00:00
|
|
|
static void TransitionElementsKindImpl(Handle<JSObject> object,
|
|
|
|
Handle<Map> map) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
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) {
|
2017-04-06 08:51:47 +00:00
|
|
|
SloppyArgumentsElements* elements = SloppyArgumentsElements::cast(store);
|
|
|
|
uint32_t length = elements->parameter_map_length();
|
2015-07-10 12:56:36 +00:00
|
|
|
if (entry < length) {
|
2017-04-06 08:51:47 +00:00
|
|
|
// Store context mapped entry.
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
Object* probe = elements->get_mapped_entry(entry);
|
|
|
|
DCHECK(!probe->IsTheHole(store->GetIsolate()));
|
|
|
|
Context* context = elements->context();
|
2017-07-10 12:58:27 +00:00
|
|
|
int context_entry = Smi::ToInt(probe);
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(!context->get(context_entry)->IsTheHole(store->GetIsolate()));
|
2015-07-07 11:52:51 +00:00
|
|
|
context->set(context_entry, value);
|
2015-06-18 12:51:49 +00:00
|
|
|
} else {
|
2017-04-06 08:51:47 +00:00
|
|
|
// Entry is not context mapped defer to arguments.
|
|
|
|
FixedArray* arguments = elements->arguments();
|
2015-07-10 15:51:57 +00:00
|
|
|
Object* current = ArgumentsAccessor::GetRaw(arguments, entry - length);
|
|
|
|
if (current->IsAliasedArgumentsEntry()) {
|
|
|
|
AliasedArgumentsEntry* alias = AliasedArgumentsEntry::cast(current);
|
2017-04-06 08:51:47 +00:00
|
|
|
Context* context = elements->context();
|
2015-07-10 15:51:57 +00:00
|
|
|
int context_entry = alias->aliased_context_slot();
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(!context->get(context_entry)->IsTheHole(store->GetIsolate()));
|
2015-07-10 15:51:57 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-04-06 08:51:47 +00:00
|
|
|
static uint32_t GetCapacityImpl(JSObject* holder, FixedArrayBase* store) {
|
|
|
|
SloppyArgumentsElements* elements = SloppyArgumentsElements::cast(store);
|
|
|
|
FixedArray* arguments = elements->arguments();
|
|
|
|
return elements->parameter_map_length() +
|
2015-07-02 14:38:37 +00:00
|
|
|
ArgumentsAccessor::GetCapacityImpl(holder, arguments);
|
2011-08-10 10:51:01 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 09:22:48 +00:00
|
|
|
static uint32_t GetMaxNumberOfEntries(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store) {
|
2017-04-06 08:51:47 +00:00
|
|
|
SloppyArgumentsElements* elements =
|
|
|
|
SloppyArgumentsElements::cast(backing_store);
|
|
|
|
FixedArrayBase* arguments = elements->arguments();
|
|
|
|
return elements->parameter_map_length() +
|
2016-07-21 09:22:48 +00:00
|
|
|
ArgumentsAccessor::GetMaxNumberOfEntries(holder, arguments);
|
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
static uint32_t NumberOfElementsImpl(JSObject* receiver,
|
|
|
|
FixedArrayBase* backing_store) {
|
2017-04-06 08:51:47 +00:00
|
|
|
Isolate* isolate = receiver->GetIsolate();
|
|
|
|
SloppyArgumentsElements* elements =
|
|
|
|
SloppyArgumentsElements::cast(backing_store);
|
|
|
|
FixedArrayBase* arguments = elements->arguments();
|
2016-11-15 18:30:35 +00:00
|
|
|
uint32_t nof_elements = 0;
|
2017-04-06 08:51:47 +00:00
|
|
|
uint32_t length = elements->parameter_map_length();
|
2016-11-15 18:30:35 +00:00
|
|
|
for (uint32_t entry = 0; entry < length; entry++) {
|
2017-04-06 08:51:47 +00:00
|
|
|
if (HasParameterMapArg(isolate, elements, entry)) nof_elements++;
|
2016-11-15 18:30:35 +00:00
|
|
|
}
|
|
|
|
return nof_elements +
|
|
|
|
ArgumentsAccessor::NumberOfElementsImpl(receiver, arguments);
|
|
|
|
}
|
|
|
|
|
2016-01-29 18:57:26 +00:00
|
|
|
static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver,
|
|
|
|
KeyAccumulator* accumulator,
|
|
|
|
AddKeyConversion convert) {
|
2016-11-15 18:30:35 +00:00
|
|
|
Isolate* isolate = accumulator->isolate();
|
|
|
|
Handle<FixedArrayBase> elements(receiver->elements(), isolate);
|
|
|
|
uint32_t length = GetCapacityImpl(*receiver, *elements);
|
2016-01-29 18:57:26 +00:00
|
|
|
for (uint32_t entry = 0; entry < length; entry++) {
|
2016-11-15 18:30:35 +00:00
|
|
|
if (!HasEntryImpl(isolate, *elements, entry)) continue;
|
2016-11-24 14:47:58 +00:00
|
|
|
Handle<Object> value = GetImpl(isolate, *elements, entry);
|
2016-01-29 18:57:26 +00:00
|
|
|
accumulator->AddKey(value, convert);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
static bool HasEntryImpl(Isolate* isolate, FixedArrayBase* parameters,
|
|
|
|
uint32_t entry) {
|
2017-04-06 08:51:47 +00:00
|
|
|
SloppyArgumentsElements* elements =
|
|
|
|
SloppyArgumentsElements::cast(parameters);
|
|
|
|
uint32_t length = elements->parameter_map_length();
|
2015-07-07 11:52:51 +00:00
|
|
|
if (entry < length) {
|
2017-04-06 08:51:47 +00:00
|
|
|
return HasParameterMapArg(isolate, elements, entry);
|
2015-06-02 10:42:16 +00:00
|
|
|
}
|
2017-04-06 08:51:47 +00:00
|
|
|
FixedArrayBase* arguments = elements->arguments();
|
2016-11-15 18:30:35 +00:00
|
|
|
return ArgumentsAccessor::HasEntryImpl(isolate, arguments, entry - length);
|
2011-08-17 16:15:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-15 20:28:15 +00:00
|
|
|
static bool HasAccessorsImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store) {
|
2017-04-06 08:51:47 +00:00
|
|
|
SloppyArgumentsElements* elements =
|
|
|
|
SloppyArgumentsElements::cast(backing_store);
|
|
|
|
FixedArray* arguments = elements->arguments();
|
2016-03-15 20:28:15 +00:00
|
|
|
return ArgumentsAccessor::HasAccessorsImpl(holder, arguments);
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:52:51 +00:00
|
|
|
static uint32_t GetIndexForEntryImpl(FixedArrayBase* parameters,
|
|
|
|
uint32_t entry) {
|
2017-04-06 08:51:47 +00:00
|
|
|
SloppyArgumentsElements* elements =
|
|
|
|
SloppyArgumentsElements::cast(parameters);
|
|
|
|
uint32_t length = elements->parameter_map_length();
|
2015-07-07 11:52:51 +00:00
|
|
|
if (entry < length) return entry;
|
2017-04-06 08:51:47 +00:00
|
|
|
FixedArray* arguments = elements->arguments();
|
2015-07-07 11:52:51 +00:00
|
|
|
return ArgumentsAccessor::GetIndexForEntryImpl(arguments, entry - length);
|
2015-05-21 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
static uint32_t GetEntryForIndexImpl(Isolate* isolate, JSObject* holder,
|
2015-07-07 11:52:51 +00:00
|
|
|
FixedArrayBase* parameters,
|
2015-12-02 16:30:06 +00:00
|
|
|
uint32_t index, PropertyFilter filter) {
|
2017-04-06 08:51:47 +00:00
|
|
|
SloppyArgumentsElements* elements =
|
|
|
|
SloppyArgumentsElements::cast(parameters);
|
|
|
|
if (HasParameterMapArg(isolate, elements, index)) return index;
|
|
|
|
FixedArray* arguments = elements->arguments();
|
2016-11-15 18:30:35 +00:00
|
|
|
uint32_t entry = ArgumentsAccessor::GetEntryForIndexImpl(
|
|
|
|
isolate, holder, arguments, index, filter);
|
2016-04-08 08:02:26 +00:00
|
|
|
if (entry == kMaxUInt32) return kMaxUInt32;
|
2017-04-27 12:58:19 +00:00
|
|
|
// Arguments entries could overlap with the dictionary entries, hence offset
|
|
|
|
// them by the number of context mapped entries.
|
2017-04-06 08:51:47 +00:00
|
|
|
return elements->parameter_map_length() + 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) {
|
2017-04-06 08:51:47 +00:00
|
|
|
SloppyArgumentsElements* elements =
|
|
|
|
SloppyArgumentsElements::cast(holder->elements());
|
|
|
|
uint32_t length = elements->parameter_map_length();
|
2015-07-07 11:52:51 +00:00
|
|
|
if (entry < length) {
|
2017-06-22 09:52:28 +00:00
|
|
|
return PropertyDetails(kData, NONE, PropertyCellType::kNoCell);
|
2015-06-02 10:42:16 +00:00
|
|
|
}
|
2017-04-06 08:51:47 +00:00
|
|
|
FixedArray* arguments = elements->arguments();
|
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
|
|
|
|
2017-04-06 08:51:47 +00:00
|
|
|
static bool HasParameterMapArg(Isolate* isolate,
|
|
|
|
SloppyArgumentsElements* elements,
|
|
|
|
uint32_t index) {
|
|
|
|
uint32_t length = elements->parameter_map_length();
|
2016-09-12 17:31:25 +00:00
|
|
|
if (index >= length) return false;
|
2017-04-06 08:51:47 +00:00
|
|
|
return !elements->get_mapped_entry(index)->IsTheHole(isolate);
|
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) {
|
2017-04-27 12:58:19 +00:00
|
|
|
Handle<SloppyArgumentsElements> elements(
|
|
|
|
SloppyArgumentsElements::cast(obj->elements()));
|
2017-04-06 08:51:47 +00:00
|
|
|
uint32_t length = elements->parameter_map_length();
|
2017-04-27 12:58:19 +00:00
|
|
|
uint32_t delete_or_entry = entry;
|
|
|
|
if (entry < length) {
|
|
|
|
delete_or_entry = kMaxUInt32;
|
|
|
|
}
|
|
|
|
Subclass::SloppyDeleteImpl(obj, elements, delete_or_entry);
|
|
|
|
// SloppyDeleteImpl allocates a new dictionary elements store. For making
|
|
|
|
// heap verification happy we postpone clearing out the mapped entry.
|
2015-07-07 11:52:51 +00:00
|
|
|
if (entry < length) {
|
2017-04-06 08:51:47 +00:00
|
|
|
elements->set_mapped_entry(entry, obj->GetHeap()->the_hole_value());
|
2015-07-06 08:53:41 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-14 17:09:19 +00:00
|
|
|
|
2017-04-27 12:58:19 +00:00
|
|
|
static void SloppyDeleteImpl(Handle<JSObject> obj,
|
|
|
|
Handle<SloppyArgumentsElements> elements,
|
|
|
|
uint32_t entry) {
|
|
|
|
// Implemented in subclasses.
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2016-03-14 17:09:19 +00:00
|
|
|
static void CollectElementIndicesImpl(Handle<JSObject> object,
|
|
|
|
Handle<FixedArrayBase> backing_store,
|
2016-05-06 10:50:41 +00:00
|
|
|
KeyAccumulator* keys) {
|
2016-05-25 09:13:31 +00:00
|
|
|
Isolate* isolate = keys->isolate();
|
|
|
|
uint32_t nof_indices = 0;
|
|
|
|
Handle<FixedArray> indices = isolate->factory()->NewFixedArray(
|
|
|
|
GetCapacityImpl(*object, *backing_store));
|
|
|
|
DirectCollectElementIndicesImpl(isolate, object, backing_store,
|
2016-05-30 15:52:56 +00:00
|
|
|
GetKeysConversion::kKeepNumbers,
|
|
|
|
ENUMERABLE_STRINGS, indices, &nof_indices);
|
2016-05-25 09:13:31 +00:00
|
|
|
SortIndices(indices, nof_indices);
|
|
|
|
for (uint32_t i = 0; i < nof_indices; i++) {
|
|
|
|
keys->AddKey(indices->get(i));
|
2016-03-14 17:09:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Handle<FixedArray> DirectCollectElementIndicesImpl(
|
|
|
|
Isolate* isolate, Handle<JSObject> object,
|
|
|
|
Handle<FixedArrayBase> backing_store, GetKeysConversion convert,
|
|
|
|
PropertyFilter filter, Handle<FixedArray> list, uint32_t* nof_indices,
|
|
|
|
uint32_t insertion_index = 0) {
|
2017-04-06 08:51:47 +00:00
|
|
|
Handle<SloppyArgumentsElements> elements =
|
|
|
|
Handle<SloppyArgumentsElements>::cast(backing_store);
|
|
|
|
uint32_t length = elements->parameter_map_length();
|
2016-03-14 17:09:19 +00:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2017-04-06 08:51:47 +00:00
|
|
|
if (elements->get_mapped_entry(i)->IsTheHole(isolate)) continue;
|
2016-05-30 15:52:56 +00:00
|
|
|
if (convert == GetKeysConversion::kConvertToString) {
|
2016-03-14 17:09:19 +00:00
|
|
|
Handle<String> index_string = isolate->factory()->Uint32ToString(i);
|
|
|
|
list->set(insertion_index, *index_string);
|
|
|
|
} else {
|
|
|
|
list->set(insertion_index, Smi::FromInt(i), SKIP_WRITE_BARRIER);
|
|
|
|
}
|
|
|
|
insertion_index++;
|
|
|
|
}
|
|
|
|
|
2017-04-06 08:51:47 +00:00
|
|
|
Handle<FixedArray> store(elements->arguments(), isolate);
|
2016-03-14 17:09:19 +00:00
|
|
|
return ArgumentsAccessor::DirectCollectElementIndicesImpl(
|
|
|
|
isolate, object, store, convert, filter, list, nof_indices,
|
|
|
|
insertion_index);
|
|
|
|
}
|
2016-08-03 03:26:58 +00:00
|
|
|
|
|
|
|
static Maybe<bool> IncludesValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> object,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
DCHECK(JSObject::PrototypeHasNoElements(isolate, *object));
|
|
|
|
Handle<Map> original_map = handle(object->map(), isolate);
|
2017-04-06 08:51:47 +00:00
|
|
|
Handle<SloppyArgumentsElements> elements(
|
|
|
|
SloppyArgumentsElements::cast(object->elements()), isolate);
|
2016-08-03 03:26:58 +00:00
|
|
|
bool search_for_hole = value->IsUndefined(isolate);
|
|
|
|
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
2017-04-06 08:51:47 +00:00
|
|
|
uint32_t entry =
|
|
|
|
GetEntryForIndexImpl(isolate, *object, *elements, k, ALL_PROPERTIES);
|
2016-08-03 03:26:58 +00:00
|
|
|
if (entry == kMaxUInt32) {
|
|
|
|
if (search_for_hole) return Just(true);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-04-06 08:51:47 +00:00
|
|
|
Handle<Object> element_k = Subclass::GetImpl(isolate, *elements, entry);
|
2016-08-03 03:26:58 +00:00
|
|
|
|
|
|
|
if (element_k->IsAccessorPair()) {
|
|
|
|
LookupIterator it(isolate, object, k, LookupIterator::OWN);
|
|
|
|
DCHECK(it.IsFound());
|
|
|
|
DCHECK_EQ(it.state(), LookupIterator::ACCESSOR);
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, element_k,
|
|
|
|
Object::GetPropertyWithAccessor(&it),
|
|
|
|
Nothing<bool>());
|
|
|
|
|
|
|
|
if (value->SameValueZero(*element_k)) return Just(true);
|
|
|
|
|
|
|
|
if (object->map() != *original_map) {
|
|
|
|
// Some mutation occurred in accessor. Abort "fast" path
|
|
|
|
return IncludesValueSlowPath(isolate, object, value, k + 1, length);
|
|
|
|
}
|
|
|
|
} else if (value->SameValueZero(*element_k)) {
|
|
|
|
return Just(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Just(false);
|
|
|
|
}
|
2016-08-22 18:36:50 +00:00
|
|
|
|
|
|
|
static Maybe<int64_t> IndexOfValueImpl(Isolate* isolate,
|
|
|
|
Handle<JSObject> object,
|
|
|
|
Handle<Object> value,
|
|
|
|
uint32_t start_from, uint32_t length) {
|
|
|
|
DCHECK(JSObject::PrototypeHasNoElements(isolate, *object));
|
|
|
|
Handle<Map> original_map = handle(object->map(), isolate);
|
2017-04-06 08:51:47 +00:00
|
|
|
Handle<SloppyArgumentsElements> elements(
|
|
|
|
SloppyArgumentsElements::cast(object->elements()), isolate);
|
2016-08-22 18:36:50 +00:00
|
|
|
|
|
|
|
for (uint32_t k = start_from; k < length; ++k) {
|
2017-04-06 08:51:47 +00:00
|
|
|
uint32_t entry =
|
|
|
|
GetEntryForIndexImpl(isolate, *object, *elements, k, ALL_PROPERTIES);
|
2016-08-22 18:36:50 +00:00
|
|
|
if (entry == kMaxUInt32) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-04-06 08:51:47 +00:00
|
|
|
Handle<Object> element_k = Subclass::GetImpl(isolate, *elements, entry);
|
2016-08-22 18:36:50 +00:00
|
|
|
|
|
|
|
if (element_k->IsAccessorPair()) {
|
|
|
|
LookupIterator it(isolate, object, k, LookupIterator::OWN);
|
|
|
|
DCHECK(it.IsFound());
|
|
|
|
DCHECK_EQ(it.state(), LookupIterator::ACCESSOR);
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, element_k,
|
|
|
|
Object::GetPropertyWithAccessor(&it),
|
|
|
|
Nothing<int64_t>());
|
|
|
|
|
|
|
|
if (value->StrictEquals(*element_k)) {
|
|
|
|
return Just<int64_t>(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object->map() != *original_map) {
|
|
|
|
// Some mutation occurred in accessor. Abort "fast" path.
|
|
|
|
return IndexOfValueSlowPath(isolate, object, value, k + 1, length);
|
|
|
|
}
|
|
|
|
} else if (value->StrictEquals(*element_k)) {
|
|
|
|
return Just<int64_t>(k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Just<int64_t>(-1);
|
|
|
|
}
|
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) {}
|
|
|
|
|
2017-04-06 08:51:47 +00:00
|
|
|
static Handle<Object> ConvertArgumentsStoreResult(
|
|
|
|
Isolate* isolate, Handle<SloppyArgumentsElements> elements,
|
|
|
|
Handle<Object> result) {
|
|
|
|
// Elements of the arguments object in slow mode might be slow aliases.
|
|
|
|
if (result->IsAliasedArgumentsEntry()) {
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
AliasedArgumentsEntry* alias = AliasedArgumentsEntry::cast(*result);
|
|
|
|
Context* context = elements->context();
|
|
|
|
int context_entry = alias->aliased_context_slot();
|
|
|
|
DCHECK(!context->get(context_entry)->IsTheHole(isolate));
|
|
|
|
return handle(context->get(context_entry), isolate);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2017-04-27 12:58:19 +00:00
|
|
|
static void SloppyDeleteImpl(Handle<JSObject> obj,
|
|
|
|
Handle<SloppyArgumentsElements> elements,
|
|
|
|
uint32_t entry) {
|
|
|
|
// No need to delete a context mapped entry from the arguments elements.
|
|
|
|
if (entry == kMaxUInt32) return;
|
2017-04-06 08:51:47 +00:00
|
|
|
Isolate* isolate = obj->GetIsolate();
|
2015-07-06 08:53:41 +00:00
|
|
|
Handle<SeededNumberDictionary> dict(
|
2017-04-06 08:51:47 +00:00
|
|
|
SeededNumberDictionary::cast(elements->arguments()), isolate);
|
2017-04-27 12:58:19 +00:00
|
|
|
int length = elements->parameter_map_length();
|
2017-06-22 07:59:05 +00:00
|
|
|
dict = SeededNumberDictionary::DeleteEntry(dict, entry - length);
|
|
|
|
elements->set_arguments(*dict);
|
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 16:44:17 +00:00
|
|
|
Handle<Object> value, PropertyAttributes attributes,
|
|
|
|
uint32_t new_capacity) {
|
2017-04-06 08:51:47 +00:00
|
|
|
Isolate* isolate = object->GetIsolate();
|
|
|
|
Handle<SloppyArgumentsElements> elements(
|
|
|
|
SloppyArgumentsElements::cast(object->elements()), isolate);
|
|
|
|
Handle<FixedArrayBase> old_arguments(
|
|
|
|
FixedArrayBase::cast(elements->arguments()), isolate);
|
2015-07-02 16:44:17 +00:00
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
2017-04-06 08:51:47 +00:00
|
|
|
old_arguments->IsSeededNumberDictionary()
|
|
|
|
? Handle<SeededNumberDictionary>::cast(old_arguments)
|
2015-07-02 16:44:17 +00:00
|
|
|
: JSObject::NormalizeElements(object);
|
2017-06-22 09:52:28 +00:00
|
|
|
PropertyDetails details(kData, attributes, PropertyCellType::kNoCell);
|
2015-07-02 16:44:17 +00:00
|
|
|
Handle<SeededNumberDictionary> new_dictionary =
|
2017-06-21 08:27:38 +00:00
|
|
|
SeededNumberDictionary::Add(dictionary, index, value, details);
|
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) {
|
2017-04-06 08:51:47 +00:00
|
|
|
elements->set_arguments(*new_dictionary);
|
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) {
|
2016-06-06 12:58:10 +00:00
|
|
|
Isolate* isolate = store->GetIsolate();
|
2017-04-06 08:51:47 +00:00
|
|
|
Handle<SloppyArgumentsElements> elements =
|
|
|
|
Handle<SloppyArgumentsElements>::cast(store);
|
|
|
|
uint32_t length = elements->parameter_map_length();
|
2015-07-07 11:52:51 +00:00
|
|
|
if (entry < length) {
|
2017-04-06 08:51:47 +00:00
|
|
|
Object* probe = elements->get_mapped_entry(entry);
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(!probe->IsTheHole(isolate));
|
2017-04-06 08:51:47 +00:00
|
|
|
Context* context = elements->context();
|
2017-07-10 12:58:27 +00:00
|
|
|
int context_entry = Smi::ToInt(probe);
|
2016-06-06 12:58:10 +00:00
|
|
|
DCHECK(!context->get(context_entry)->IsTheHole(isolate));
|
2015-07-07 11:52:51 +00:00
|
|
|
context->set(context_entry, *value);
|
2015-07-02 16:44:17 +00:00
|
|
|
|
|
|
|
// Redefining attributes of an aliased element destroys fast aliasing.
|
2017-04-06 08:51:47 +00:00
|
|
|
elements->set_mapped_entry(entry, isolate->heap()->the_hole_value());
|
2015-07-02 16:44:17 +00:00
|
|
|
// For elements that are still writable we re-establish slow aliasing.
|
|
|
|
if ((attributes & READ_ONLY) == 0) {
|
2015-07-07 11:52:51 +00:00
|
|
|
value = isolate->factory()->NewAliasedArgumentsEntry(context_entry);
|
2015-07-02 16:44:17 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 09:52:28 +00:00
|
|
|
PropertyDetails details(kData, attributes, PropertyCellType::kNoCell);
|
2015-07-02 16:44:17 +00:00
|
|
|
Handle<SeededNumberDictionary> arguments(
|
2017-04-06 08:51:47 +00:00
|
|
|
SeededNumberDictionary::cast(elements->arguments()), isolate);
|
2017-06-21 08:27:38 +00:00
|
|
|
arguments = SeededNumberDictionary::Add(arguments, entry, value, details);
|
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);
|
2017-04-06 08:51:47 +00:00
|
|
|
elements->set_arguments(*arguments);
|
2015-07-02 16:44:17 +00:00
|
|
|
} else {
|
2017-04-06 08:51:47 +00:00
|
|
|
Handle<FixedArrayBase> arguments(elements->arguments(), isolate);
|
2015-07-02 16:44:17 +00:00
|
|
|
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) {}
|
|
|
|
|
2017-04-06 08:51:47 +00:00
|
|
|
static Handle<Object> ConvertArgumentsStoreResult(
|
|
|
|
Isolate* isolate, Handle<SloppyArgumentsElements> paramtere_map,
|
|
|
|
Handle<Object> result) {
|
|
|
|
DCHECK(!result->IsAliasedArgumentsEntry());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-04-06 13:29:44 +00:00
|
|
|
static Handle<FixedArray> GetArguments(Isolate* isolate,
|
2017-04-06 08:51:47 +00:00
|
|
|
FixedArrayBase* store) {
|
|
|
|
SloppyArgumentsElements* elements = SloppyArgumentsElements::cast(store);
|
|
|
|
return Handle<FixedArray>(elements->arguments(), isolate);
|
2016-04-06 13:29:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-01 16:46:10 +00:00
|
|
|
static Handle<JSObject> SliceImpl(Handle<JSObject> receiver, uint32_t start,
|
|
|
|
uint32_t end) {
|
2016-04-06 13:29:44 +00:00
|
|
|
Isolate* isolate = receiver->GetIsolate();
|
|
|
|
uint32_t result_len = end < start ? 0u : end - start;
|
2017-06-30 11:26:14 +00:00
|
|
|
Handle<JSArray> result_array =
|
|
|
|
isolate->factory()->NewJSArray(HOLEY_ELEMENTS, result_len, result_len);
|
2016-04-06 13:29:44 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
FixedArray* elements = FixedArray::cast(result_array->elements());
|
|
|
|
FixedArray* parameters = FixedArray::cast(receiver->elements());
|
|
|
|
uint32_t insertion_index = 0;
|
|
|
|
for (uint32_t i = start; i < end; i++) {
|
2016-11-15 18:30:35 +00:00
|
|
|
uint32_t entry = GetEntryForIndexImpl(isolate, *receiver, parameters, i,
|
|
|
|
ALL_PROPERTIES);
|
|
|
|
if (entry != kMaxUInt32 && HasEntryImpl(isolate, parameters, entry)) {
|
2016-11-24 14:47:58 +00:00
|
|
|
elements->set(insertion_index, *GetImpl(isolate, parameters, entry));
|
2016-04-06 13:29:44 +00:00
|
|
|
} else {
|
2016-11-23 09:43:42 +00:00
|
|
|
elements->set_the_hole(isolate, insertion_index);
|
2016-04-06 13:29:44 +00:00
|
|
|
}
|
|
|
|
insertion_index++;
|
|
|
|
}
|
|
|
|
return result_array;
|
|
|
|
}
|
|
|
|
|
2016-03-16 13:02:21 +00:00
|
|
|
static Handle<SeededNumberDictionary> NormalizeImpl(
|
|
|
|
Handle<JSObject> object, Handle<FixedArrayBase> elements) {
|
2016-04-06 13:29:44 +00:00
|
|
|
Handle<FixedArray> arguments =
|
|
|
|
GetArguments(elements->GetIsolate(), *elements);
|
2016-03-16 13:02:21 +00:00
|
|
|
return FastHoleyObjectElementsAccessor::NormalizeImpl(object, arguments);
|
|
|
|
}
|
|
|
|
|
2017-04-27 12:58:19 +00:00
|
|
|
static Handle<SeededNumberDictionary> NormalizeArgumentsElements(
|
|
|
|
Handle<JSObject> object, Handle<SloppyArgumentsElements> elements,
|
|
|
|
uint32_t* entry) {
|
|
|
|
Handle<SeededNumberDictionary> dictionary =
|
|
|
|
JSObject::NormalizeElements(object);
|
|
|
|
elements->set_arguments(*dictionary);
|
|
|
|
// kMaxUInt32 indicates that a context mapped element got deleted. In this
|
|
|
|
// case we only normalize the elements (aka. migrate to SLOW_SLOPPY).
|
|
|
|
if (*entry == kMaxUInt32) return dictionary;
|
|
|
|
uint32_t length = elements->parameter_map_length();
|
|
|
|
if (*entry >= length) {
|
|
|
|
*entry = dictionary->FindEntry(*entry - length) + length;
|
|
|
|
}
|
|
|
|
return dictionary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SloppyDeleteImpl(Handle<JSObject> obj,
|
|
|
|
Handle<SloppyArgumentsElements> elements,
|
|
|
|
uint32_t entry) {
|
|
|
|
// Always normalize element on deleting an entry.
|
|
|
|
NormalizeArgumentsElements(obj, elements, &entry);
|
|
|
|
SlowSloppyArgumentsElementsAccessor::SloppyDeleteImpl(obj, elements, entry);
|
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);
|
2017-04-06 08:51:47 +00:00
|
|
|
Isolate* isolate = object->GetIsolate();
|
|
|
|
Handle<SloppyArgumentsElements> elements(
|
|
|
|
SloppyArgumentsElements::cast(object->elements()), isolate);
|
|
|
|
Handle<FixedArray> old_arguments(elements->arguments(), isolate);
|
|
|
|
if (old_arguments->IsSeededNumberDictionary() ||
|
|
|
|
static_cast<uint32_t>(old_arguments->length()) < new_capacity) {
|
2015-07-02 14:38:37 +00:00
|
|
|
GrowCapacityAndConvertImpl(object, new_capacity);
|
|
|
|
}
|
2017-04-06 08:51:47 +00:00
|
|
|
FixedArray* arguments = elements->arguments();
|
2015-07-10 12:56:36 +00:00
|
|
|
// 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) {
|
2017-04-27 12:58:19 +00:00
|
|
|
DCHECK_EQ(object->elements(), *store);
|
|
|
|
Handle<SloppyArgumentsElements> elements(
|
|
|
|
SloppyArgumentsElements::cast(*store));
|
|
|
|
NormalizeArgumentsElements(object, elements, &entry);
|
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) {
|
2017-06-30 11:26:14 +00:00
|
|
|
CopyDictionaryToObjectElements(from, from_start, to, HOLEY_ELEMENTS,
|
2015-07-02 14:38:37 +00:00
|
|
|
to_start, copy_size);
|
|
|
|
} else {
|
|
|
|
DCHECK_EQ(FAST_SLOPPY_ARGUMENTS_ELEMENTS, from_kind);
|
2017-06-30 11:26:14 +00:00
|
|
|
CopyObjectToObjectElements(from, HOLEY_ELEMENTS, from_start, to,
|
|
|
|
HOLEY_ELEMENTS, to_start, copy_size);
|
2015-07-02 14:38:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GrowCapacityAndConvertImpl(Handle<JSObject> object,
|
|
|
|
uint32_t capacity) {
|
2017-04-06 08:51:47 +00:00
|
|
|
Isolate* isolate = object->GetIsolate();
|
|
|
|
Handle<SloppyArgumentsElements> elements(
|
|
|
|
SloppyArgumentsElements::cast(object->elements()), isolate);
|
|
|
|
Handle<FixedArray> old_arguments(FixedArray::cast(elements->arguments()),
|
|
|
|
isolate);
|
2015-07-02 14:38:37 +00:00
|
|
|
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 ||
|
2017-04-06 08:51:47 +00:00
|
|
|
static_cast<uint32_t>(old_arguments->length()) < capacity);
|
|
|
|
Handle<FixedArrayBase> arguments =
|
|
|
|
ConvertElementsWithCapacity(object, old_arguments, from_kind, capacity);
|
2015-07-02 14:38:37 +00:00
|
|
|
Handle<Map> new_map = JSObject::GetElementsTransitionMap(
|
|
|
|
object, FAST_SLOPPY_ARGUMENTS_ELEMENTS);
|
|
|
|
JSObject::MigrateToMap(object, new_map);
|
2017-04-06 08:51:47 +00:00
|
|
|
elements->set_arguments(FixedArray::cast(*arguments));
|
2017-07-06 08:26:19 +00:00
|
|
|
JSObject::ValidateElements(*object);
|
2015-07-02 14:38:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-06 13:38:02 +00:00
|
|
|
template <typename Subclass, typename BackingStoreAccessor, typename KindTraits>
|
2016-01-29 18:57:26 +00:00
|
|
|
class StringWrapperElementsAccessor
|
2016-04-06 13:38:02 +00:00
|
|
|
: public ElementsAccessorBase<Subclass, KindTraits> {
|
2016-01-29 18:57:26 +00:00
|
|
|
public:
|
|
|
|
explicit StringWrapperElementsAccessor(const char* name)
|
2016-04-06 13:38:02 +00:00
|
|
|
: ElementsAccessorBase<Subclass, KindTraits>(name) {
|
2016-01-29 18:57:26 +00:00
|
|
|
USE(KindTraits::Kind);
|
|
|
|
}
|
|
|
|
|
2016-11-24 14:47:58 +00:00
|
|
|
static Handle<Object> GetInternalImpl(Handle<JSObject> holder,
|
|
|
|
uint32_t entry) {
|
|
|
|
return GetImpl(holder, entry);
|
|
|
|
}
|
|
|
|
|
2016-01-29 18:57:26 +00:00
|
|
|
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));
|
|
|
|
}
|
2016-11-24 14:47:58 +00:00
|
|
|
return BackingStoreAccessor::GetImpl(isolate, holder->elements(),
|
|
|
|
entry - length);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* elements,
|
|
|
|
uint32_t entry) {
|
|
|
|
UNREACHABLE();
|
2016-01-29 18:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-06-22 09:52:28 +00:00
|
|
|
return PropertyDetails(kData, attributes, PropertyCellType::kNoCell);
|
2016-01-29 18:57:26 +00:00
|
|
|
}
|
|
|
|
return BackingStoreAccessor::GetDetailsImpl(holder, entry - length);
|
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
static uint32_t GetEntryForIndexImpl(Isolate* isolate, JSObject* holder,
|
2016-01-29 18:57:26 +00:00
|
|
|
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(
|
2016-11-15 18:30:35 +00:00
|
|
|
isolate, holder, backing_store, index, filter);
|
2016-01-29 18:57:26 +00:00
|
|
|
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-04-06 13:38:02 +00:00
|
|
|
GrowCapacityAndConvertImpl(object, new_capacity);
|
2016-01-29 18:57:26 +00:00
|
|
|
}
|
|
|
|
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,
|
2016-05-06 10:50:41 +00:00
|
|
|
KeyAccumulator* keys) {
|
2016-03-15 10:52:08 +00:00
|
|
|
uint32_t length = GetString(*object)->length();
|
2016-05-25 09:13:31 +00:00
|
|
|
Factory* factory = keys->isolate()->factory();
|
2016-03-15 10:52:08 +00:00
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2016-05-25 09:13:31 +00:00
|
|
|
keys->AddKey(factory->NewNumberFromUint(i));
|
2016-01-29 18:57:26 +00:00
|
|
|
}
|
2016-05-06 10:50:41 +00:00
|
|
|
BackingStoreAccessor::CollectElementIndicesImpl(object, backing_store,
|
|
|
|
keys);
|
2016-01-29 18:57:26 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 13:38:02 +00:00
|
|
|
static void GrowCapacityAndConvertImpl(Handle<JSObject> object,
|
|
|
|
uint32_t capacity) {
|
|
|
|
Handle<FixedArrayBase> old_elements(object->elements());
|
|
|
|
ElementsKind from_kind = object->GetElementsKind();
|
|
|
|
// This method should only be called if there's a reason to update the
|
|
|
|
// elements.
|
|
|
|
DCHECK(from_kind == SLOW_STRING_WRAPPER_ELEMENTS ||
|
|
|
|
static_cast<uint32_t>(old_elements->length()) < capacity);
|
|
|
|
Subclass::BasicGrowCapacityAndConvertImpl(object, old_elements, from_kind,
|
|
|
|
FAST_STRING_WRAPPER_ELEMENTS,
|
|
|
|
capacity);
|
|
|
|
}
|
|
|
|
|
2016-01-29 18:57:26 +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) {
|
2016-04-06 13:38:02 +00:00
|
|
|
DCHECK(!to->IsDictionary());
|
|
|
|
if (from_kind == SLOW_STRING_WRAPPER_ELEMENTS) {
|
2017-06-30 11:26:14 +00:00
|
|
|
CopyDictionaryToObjectElements(from, from_start, to, HOLEY_ELEMENTS,
|
2016-04-06 13:38:02 +00:00
|
|
|
to_start, copy_size);
|
|
|
|
} else {
|
|
|
|
DCHECK_EQ(FAST_STRING_WRAPPER_ELEMENTS, from_kind);
|
2017-06-30 11:26:14 +00:00
|
|
|
CopyObjectToObjectElements(from, HOLEY_ELEMENTS, from_start, to,
|
|
|
|
HOLEY_ELEMENTS, to_start, copy_size);
|
2016-04-06 13:38:02 +00:00
|
|
|
}
|
2016-01-29 18:57:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 18:30:35 +00:00
|
|
|
static uint32_t NumberOfElementsImpl(JSObject* object,
|
|
|
|
FixedArrayBase* backing_store) {
|
|
|
|
uint32_t length = GetString(object)->length();
|
|
|
|
return length +
|
|
|
|
BackingStoreAccessor::NumberOfElementsImpl(object, backing_store);
|
|
|
|
}
|
|
|
|
|
2016-01-29 18:57:26 +00:00
|
|
|
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) {}
|
2016-03-16 13:02:21 +00:00
|
|
|
|
|
|
|
static Handle<SeededNumberDictionary> NormalizeImpl(
|
|
|
|
Handle<JSObject> object, Handle<FixedArrayBase> elements) {
|
|
|
|
return FastHoleyObjectElementsAccessor::NormalizeImpl(object, elements);
|
|
|
|
}
|
2016-01-29 18:57:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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) {}
|
2016-03-15 20:28:15 +00:00
|
|
|
|
|
|
|
static bool HasAccessorsImpl(JSObject* holder,
|
|
|
|
FixedArrayBase* backing_store) {
|
|
|
|
return DictionaryElementsAccessor::HasAccessorsImpl(holder, backing_store);
|
|
|
|
}
|
2016-01-29 18:57:26 +00:00
|
|
|
};
|
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;
|
|
|
|
|
2016-12-16 13:24:07 +00:00
|
|
|
} else if (args->length() == 1 && args->at(0)->IsNumber()) {
|
2015-06-19 11:21:26 +00:00
|
|
|
uint32_t length;
|
2016-12-16 13:24:07 +00:00
|
|
|
if (!args->at(0)->ToArrayLength(&length)) {
|
2015-06-19 11:21:26 +00:00
|
|
|
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);
|
|
|
|
|
2017-06-30 18:00:44 +00:00
|
|
|
if (!IsHoleyElementsKind(elements_kind)) {
|
2015-06-19 11:21:26 +00:00
|
|
|
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;
|
2017-06-30 18:00:44 +00:00
|
|
|
if (IsDoubleElementsKind(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
|
2016-04-07 15:27:35 +00:00
|
|
|
switch (elements_kind) {
|
2017-06-30 11:26:14 +00:00
|
|
|
case HOLEY_SMI_ELEMENTS:
|
|
|
|
case PACKED_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;
|
|
|
|
}
|
2017-06-30 11:26:14 +00:00
|
|
|
case HOLEY_ELEMENTS:
|
|
|
|
case PACKED_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;
|
|
|
|
}
|
2017-06-30 11:26:14 +00:00
|
|
|
case HOLEY_DOUBLE_ELEMENTS:
|
|
|
|
case PACKED_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,
|
2016-05-12 08:50:18 +00:00
|
|
|
uint32_t concat_size,
|
|
|
|
uint32_t result_len) {
|
2016-03-23 16:30:25 +00:00
|
|
|
ElementsKind result_elements_kind = GetInitialFastElementsKind();
|
2016-05-12 08:50:18 +00:00
|
|
|
bool has_raw_doubles = false;
|
2015-09-07 13:44:44 +00:00
|
|
|
{
|
|
|
|
DisallowHeapAllocation no_gc;
|
2016-03-23 16:30:25 +00:00
|
|
|
bool is_holey = false;
|
2015-09-07 13:44:44 +00:00
|
|
|
for (uint32_t i = 0; i < concat_size; i++) {
|
2016-05-12 08:50:18 +00:00
|
|
|
Object* arg = (*args)[i];
|
|
|
|
ElementsKind arg_kind = JSArray::cast(arg)->GetElementsKind();
|
2017-06-30 18:00:44 +00:00
|
|
|
has_raw_doubles = has_raw_doubles || IsDoubleElementsKind(arg_kind);
|
|
|
|
is_holey = is_holey || IsHoleyElementsKind(arg_kind);
|
2016-03-23 16:30:25 +00:00
|
|
|
result_elements_kind =
|
|
|
|
GetMoreGeneralElementsKind(result_elements_kind, arg_kind);
|
2015-09-07 13:44:44 +00:00
|
|
|
}
|
|
|
|
if (is_holey) {
|
2016-03-23 16:30:25 +00:00
|
|
|
result_elements_kind = GetHoleyElementsKind(result_elements_kind);
|
2015-09-07 13:44:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2016-03-23 16:30:25 +00:00
|
|
|
bool requires_double_boxing =
|
2017-06-30 18:00:44 +00:00
|
|
|
has_raw_doubles && !IsDoubleElementsKind(result_elements_kind);
|
2016-03-23 16:30:25 +00:00
|
|
|
ArrayStorageAllocationMode mode = requires_double_boxing
|
|
|
|
? INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE
|
|
|
|
: DONT_INITIALIZE_ARRAY_ELEMENTS;
|
2015-09-07 13:44:44 +00:00
|
|
|
Handle<JSArray> result_array = isolate->factory()->NewJSArray(
|
2016-03-23 16:30:25 +00:00
|
|
|
result_elements_kind, result_len, result_len, mode);
|
2015-09-07 13:44:44 +00:00
|
|
|
if (result_len == 0) return result_array;
|
2016-03-23 16:30:25 +00:00
|
|
|
|
|
|
|
uint32_t insertion_index = 0;
|
2015-09-07 13:44:44 +00:00
|
|
|
Handle<FixedArrayBase> storage(result_array->elements(), isolate);
|
2016-03-23 16:30:25 +00:00
|
|
|
ElementsAccessor* accessor = ElementsAccessor::ForKind(result_elements_kind);
|
2015-09-07 13:44:44 +00:00
|
|
|
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]);
|
2016-03-23 16:30:25 +00:00
|
|
|
uint32_t len = 0;
|
|
|
|
array->length()->ToArrayLength(&len);
|
|
|
|
if (len == 0) continue;
|
|
|
|
ElementsKind from_kind = array->GetElementsKind();
|
|
|
|
accessor->CopyElements(array, 0, from_kind, storage, insertion_index, len);
|
|
|
|
insertion_index += len;
|
2015-09-07 13:44:44 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 16:30:25 +00:00
|
|
|
DCHECK_EQ(insertion_index, result_len);
|
2015-09-07 13:44:44 +00:00
|
|
|
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
|