Commit a615efaa authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[elements] Dehandlify ElementsAccessor::HasElement as it cannot allocate

Change-Id: I8a20bff1f029df74732899db0b8a9ddc1f4f26d6
Reviewed-on: https://chromium-review.googlesource.com/474827Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44596}
parent 1fceaf9f
......@@ -727,9 +727,12 @@ void CollectElementIndices(Handle<JSObject> object, uint32_t range,
}
case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: {
DisallowHeapAllocation no_gc;
FixedArrayBase* elements = object->elements();
JSObject* raw_object = *object;
ElementsAccessor* accessor = object->GetElementsAccessor();
for (uint32_t i = 0; i < range; i++) {
if (accessor->HasElement(object, i)) {
if (accessor->HasElement(raw_object, i, elements)) {
indices->Add(i);
}
}
......@@ -749,7 +752,7 @@ void CollectElementIndices(Handle<JSObject> object, uint32_t range,
}
ElementsAccessor* accessor = object->GetElementsAccessor();
for (; i < range; i++) {
if (accessor->HasElement(object, i)) {
if (accessor->HasElement(*object, i)) {
indices->Add(i);
}
}
......
......@@ -564,9 +564,9 @@ class ElementsAccessorBase : public ElementsAccessor {
Subclass::ValidateImpl(holder);
}
static bool IsPackedImpl(Handle<JSObject> holder,
Handle<FixedArrayBase> backing_store, uint32_t start,
uint32_t end) {
static bool IsPackedImpl(JSObject* holder, FixedArrayBase* backing_store,
uint32_t start, uint32_t end) {
DisallowHeapAllocation no_gc;
if (IsFastPackedElementsKind(kind())) return true;
Isolate* isolate = backing_store->GetIsolate();
for (uint32_t i = start; i < end; i++) {
......@@ -580,9 +580,9 @@ class ElementsAccessorBase : public ElementsAccessor {
static void TryTransitionResultArrayToPacked(Handle<JSArray> array) {
if (!IsHoleyElementsKind(kind())) return;
int length = Smi::cast(array->length())->value();
Handle<FixedArrayBase> backing_store(array->elements());
if (!Subclass::IsPackedImpl(array, backing_store, 0, length)) {
int length = Smi::cast(array->length())->value();
if (!Subclass::IsPackedImpl(*array, *backing_store, 0, length)) {
return;
}
ElementsKind packed_kind = GetPackedElementsKind(kind());
......@@ -595,19 +595,17 @@ class ElementsAccessorBase : public ElementsAccessor {
}
}
bool HasElement(Handle<JSObject> holder, uint32_t index,
Handle<FixedArrayBase> backing_store,
PropertyFilter filter) final {
bool HasElement(JSObject* holder, uint32_t index,
FixedArrayBase* backing_store, PropertyFilter filter) final {
return Subclass::HasElementImpl(holder->GetIsolate(), holder, index,
backing_store, filter);
}
static bool HasElementImpl(Isolate* isolate, Handle<JSObject> holder,
uint32_t index,
Handle<FixedArrayBase> backing_store,
static bool HasElementImpl(Isolate* isolate, JSObject* holder, uint32_t index,
FixedArrayBase* backing_store,
PropertyFilter filter = ALL_PROPERTIES) {
return Subclass::GetEntryForIndexImpl(isolate, *holder, *backing_store,
index, filter) != kMaxUInt32;
return Subclass::GetEntryForIndexImpl(isolate, holder, backing_store, index,
filter) != kMaxUInt32;
}
bool HasAccessors(JSObject* holder) final {
......@@ -1079,7 +1077,8 @@ class ElementsAccessorBase : public ElementsAccessor {
Isolate* isolate = keys->isolate();
Factory* factory = isolate->factory();
for (uint32_t i = 0; i < length; i++) {
if (Subclass::HasElementImpl(isolate, object, i, backing_store, filter)) {
if (Subclass::HasElementImpl(isolate, *object, i, *backing_store,
filter)) {
keys->AddKey(factory->NewNumberFromUint(i));
}
}
......@@ -1092,7 +1091,8 @@ class ElementsAccessorBase : public ElementsAccessor {
uint32_t insertion_index = 0) {
uint32_t length = Subclass::GetMaxIndex(*object, *backing_store);
for (uint32_t i = 0; i < length; i++) {
if (Subclass::HasElementImpl(isolate, object, i, backing_store, filter)) {
if (Subclass::HasElementImpl(isolate, *object, i, *backing_store,
filter)) {
if (convert == GetKeysConversion::kConvertToString) {
Handle<String> index_string = isolate->factory()->Uint32ToString(i);
list->set(insertion_index, *index_string);
......@@ -2319,7 +2319,7 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> {
Handle<FixedArray> result = isolate->factory()->NewFixedArray(length);
Handle<FixedArrayBase> elements(array->elements(), isolate);
for (uint32_t i = 0; i < length; i++) {
if (!Subclass::HasElementImpl(isolate, array, i, elements)) continue;
if (!Subclass::HasElementImpl(isolate, *array, i, *elements)) continue;
Handle<Object> value;
value = Subclass::GetImpl(isolate, *elements, i);
if (value->IsName()) {
......@@ -2772,11 +2772,10 @@ class TypedElementsAccessor
return PropertyDetails(kData, DONT_DELETE, 0, PropertyCellType::kNoCell);
}
static bool HasElementImpl(Isolate* isolate, Handle<JSObject> holder,
uint32_t index,
Handle<FixedArrayBase> backing_store,
static bool HasElementImpl(Isolate* isolate, JSObject* holder, uint32_t index,
FixedArrayBase* backing_store,
PropertyFilter filter) {
return index < AccessorClass::GetCapacityImpl(*holder, *backing_store);
return index < AccessorClass::GetCapacityImpl(holder, backing_store);
}
static bool HasAccessorsImpl(JSObject* holder,
......
......@@ -43,13 +43,13 @@ class ElementsAccessor {
// index is ignored. Note that only Dictionary elements have custom
// PropertyAttributes associated, hence the |filter| argument is ignored for
// all but DICTIONARY_ELEMENTS and SLOW_SLOPPY_ARGUMENTS_ELEMENTS.
virtual bool HasElement(Handle<JSObject> holder, uint32_t index,
Handle<FixedArrayBase> backing_store,
virtual bool HasElement(JSObject* holder, uint32_t index,
FixedArrayBase* backing_store,
PropertyFilter filter = ALL_PROPERTIES) = 0;
inline bool HasElement(Handle<JSObject> holder, uint32_t index,
inline bool HasElement(JSObject* holder, uint32_t index,
PropertyFilter filter = ALL_PROPERTIES) {
return HasElement(holder, index, handle(holder->elements()), filter);
return HasElement(holder, index, holder->elements(), filter);
}
virtual Handle<Object> Get(Handle<JSObject> holder, uint32_t entry) = 0;
......
......@@ -142,14 +142,14 @@ RUNTIME_FUNCTION(Runtime_MoveArrayContents) {
// How many elements does this object/array have?
RUNTIME_FUNCTION(Runtime_EstimateNumberOfElements) {
DisallowHeapAllocation no_gc;
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
Handle<FixedArrayBase> elements(array->elements(), isolate);
CONVERT_ARG_CHECKED(JSArray, array, 0);
FixedArrayBase* elements = array->elements();
SealHandleScope shs(isolate);
if (elements->IsDictionary()) {
int result =
Handle<SeededNumberDictionary>::cast(elements)->NumberOfElements();
int result = SeededNumberDictionary::cast(elements)->NumberOfElements();
return Smi::FromInt(result);
} else {
DCHECK(array->length()->IsSmi());
......@@ -661,7 +661,7 @@ RUNTIME_FUNCTION(Runtime_SpreadIterableFixed) {
Handle<FixedArray> result = isolate->factory()->NewFixedArray(spread_length);
ElementsAccessor* accessor = spread_array->GetElementsAccessor();
for (uint32_t i = 0; i < spread_length; i++) {
DCHECK(accessor->HasElement(spread_array, i));
DCHECK(accessor->HasElement(*spread_array, i));
Handle<Object> element = accessor->Get(spread_array, i);
result->set(i, *element);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment