Revert of [keys] Simplify KeyAccumulator (patchset #15 id:280001 of https://codereview.chromium.org/1995263002/ )

Reason for revert:
https://build.chromium.org/p/client.v8/builders/V8%20Mac%20GC%20Stress/builds/6248

Original issue's description:
> [keys] Simplify KeyAccumulator
>
> - Use KeyAccumulator::GetKeys directly instead of JSReceiver::GetKeys
> - Revert KeyAccumulator to single OrderedHashSet implementation.
> - Convert the OrderedHashSet in-place to a FixedArray
> - IndexedInterceptor indices are no longer combined and sorted with the object indices
>
> BUG=
>
> Committed: https://crrev.com/d3324df017046bcde247a5aef6d1b59bfae5908f
> Cr-Commit-Position: refs/heads/master@{#36485}

TBR=jkummerow@chromium.org,verwaest@chromium.org,cbruni@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review-Url: https://codereview.chromium.org/2010593002
Cr-Commit-Position: refs/heads/master@{#36486}
This commit is contained in:
machenbach 2016-05-24 10:35:53 -07:00 committed by Commit bot
parent d3324df017
commit 893524b53d
15 changed files with 427 additions and 288 deletions

View File

@ -3872,9 +3872,9 @@ MaybeLocal<Array> v8::Object::GetPropertyNames(Local<Context> context) {
PREPARE_FOR_EXECUTION(context, Object, GetPropertyNames, Array);
auto self = Utils::OpenHandle(this);
i::Handle<i::FixedArray> value;
has_pending_exception = !i::KeyAccumulator::GetKeys(self, i::INCLUDE_PROTOS,
i::ENUMERABLE_STRINGS)
.ToHandle(&value);
has_pending_exception =
!i::JSReceiver::GetKeys(self, i::INCLUDE_PROTOS, i::ENUMERABLE_STRINGS)
.ToHandle(&value);
RETURN_ON_FAILED_EXECUTION(Array);
DCHECK(self->map()->EnumLength() == i::kInvalidEnumCacheSentinel ||
self->map()->EnumLength() == 0 ||
@ -3905,8 +3905,8 @@ MaybeLocal<Array> v8::Object::GetOwnPropertyNames(Local<Context> context,
auto self = Utils::OpenHandle(this);
i::Handle<i::FixedArray> value;
has_pending_exception =
!i::KeyAccumulator::GetKeys(self, i::OWN_ONLY,
static_cast<i::PropertyFilter>(filter))
!i::JSReceiver::GetKeys(self, i::OWN_ONLY,
static_cast<i::PropertyFilter>(filter))
.ToHandle(&value);
RETURN_ON_FAILED_EXECUTION(Array);
DCHECK(self->map()->EnumLength() == i::kInvalidEnumCacheSentinel ||

View File

@ -1628,7 +1628,7 @@ BUILTIN(ObjectAssign) {
Handle<FixedArray> keys;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, keys,
KeyAccumulator::GetKeys(from, OWN_ONLY, ALL_PROPERTIES, KEEP_NUMBERS));
JSReceiver::GetKeys(from, OWN_ONLY, ALL_PROPERTIES, KEEP_NUMBERS));
// 4c. Repeat for each element nextKey of keys in List order,
for (int j = 0; j < keys->length(); ++j) {
Handle<Object> next_key(keys->get(j), isolate);
@ -1901,7 +1901,7 @@ Object* GetOwnPropertyKeys(Isolate* isolate,
Handle<FixedArray> keys;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, keys,
KeyAccumulator::GetKeys(receiver, OWN_ONLY, filter, CONVERT_TO_STRING));
JSReceiver::GetKeys(receiver, OWN_ONLY, filter, CONVERT_TO_STRING));
return *isolate->factory()->NewJSArrayWithElements(keys);
}
@ -1997,8 +1997,8 @@ BUILTIN(ObjectKeys) {
} else {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, keys,
KeyAccumulator::GetKeys(receiver, OWN_ONLY, ENUMERABLE_STRINGS,
CONVERT_TO_STRING));
JSReceiver::GetKeys(receiver, OWN_ONLY, ENUMERABLE_STRINGS,
CONVERT_TO_STRING));
}
return *isolate->factory()->NewJSArrayWithElements(keys, FAST_ELEMENTS);
}
@ -2040,8 +2040,8 @@ BUILTIN(ObjectGetOwnPropertyDescriptors) {
Handle<FixedArray> keys;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, keys, KeyAccumulator::GetKeys(receiver, OWN_ONLY, ALL_PROPERTIES,
CONVERT_TO_STRING));
isolate, keys, JSReceiver::GetKeys(receiver, OWN_ONLY, ALL_PROPERTIES,
CONVERT_TO_STRING));
Handle<JSObject> descriptors =
isolate->factory()->NewJSObject(isolate->object_function());
@ -2708,8 +2708,8 @@ BUILTIN(ReflectOwnKeys) {
Handle<FixedArray> keys;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, keys,
KeyAccumulator::GetKeys(Handle<JSReceiver>::cast(target), OWN_ONLY,
ALL_PROPERTIES, CONVERT_TO_STRING));
JSReceiver::GetKeys(Handle<JSReceiver>::cast(target), OWN_ONLY,
ALL_PROPERTIES, CONVERT_TO_STRING));
return *isolate->factory()->NewJSArrayWithElements(keys);
}

View File

@ -768,7 +768,7 @@ void ScopeIterator::CopyContextExtensionToScopeObject(
if (context->extension_object() == nullptr) return;
Handle<JSObject> extension(context->extension_object());
Handle<FixedArray> keys =
KeyAccumulator::GetKeys(extension, type, ENUMERABLE_STRINGS)
JSReceiver::GetKeys(extension, type, ENUMERABLE_STRINGS)
.ToHandleChecked();
for (int i = 0; i < keys->length(); i++) {

View File

@ -445,26 +445,6 @@ static void TraceTopFrame(Isolate* isolate) {
JavaScriptFrame::PrintTop(isolate, stdout, false, true);
}
static void SortIndices(
Handle<FixedArray> indices, uint32_t sort_size,
WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER) {
struct {
bool operator()(Object* a, Object* b) {
if (!a->IsUndefined()) {
if (b->IsUndefined()) return true;
return a->Number() < b->Number();
}
return b->IsUndefined();
}
} cmp;
Object** start =
reinterpret_cast<Object**>(indices->GetFirstElementAddress());
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);
}
}
// Base class for element handler implementations. Contains the
// the common logic for objects with different ElementsKinds.
@ -729,7 +709,8 @@ class ElementsAccessorBase : public ElementsAccessor {
JSObject::ValidateElements(array);
}
static uint32_t GetMaxIndex(JSObject* receiver, FixedArrayBase* elements) {
static uint32_t GetIterationLength(JSObject* receiver,
FixedArrayBase* elements) {
if (receiver->IsJSArray()) {
DCHECK(JSArray::cast(receiver)->length()->IsSmi());
return static_cast<uint32_t>(
@ -738,11 +719,6 @@ class ElementsAccessorBase : public ElementsAccessor {
return Subclass::GetCapacityImpl(receiver, elements);
}
static uint32_t GetMaxNumberOfEntries(JSObject* receiver,
FixedArrayBase* elements) {
return Subclass::GetMaxIndex(receiver, elements);
}
static Handle<FixedArrayBase> ConvertElementsWithCapacity(
Handle<JSObject> object, Handle<FixedArrayBase> old_elements,
ElementsKind from_kind, uint32_t capacity) {
@ -887,6 +863,7 @@ class ElementsAccessorBase : public ElementsAccessor {
PropertyFilter filter) {
int count = 0;
KeyAccumulator accumulator(isolate, OWN_ONLY, ALL_PROPERTIES);
accumulator.NextPrototype();
Subclass::CollectElementIndicesImpl(
object, handle(object->elements(), isolate), &accumulator);
Handle<FixedArray> keys = accumulator.GetKeys();
@ -932,12 +909,11 @@ class ElementsAccessorBase : public ElementsAccessor {
KeyAccumulator* keys) {
DCHECK_NE(DICTIONARY_ELEMENTS, kind());
// Non-dictionary elements can't have all-can-read accessors.
uint32_t length = Subclass::GetMaxIndex(*object, *backing_store);
uint32_t length = GetIterationLength(*object, *backing_store);
PropertyFilter filter = keys->filter();
Factory* factory = keys->isolate()->factory();
for (uint32_t i = 0; i < length; i++) {
if (Subclass::HasElementImpl(object, i, backing_store, filter)) {
keys->AddKey(factory->NewNumberFromUint(i));
keys->AddKey(i);
}
}
}
@ -947,7 +923,7 @@ class ElementsAccessorBase : public ElementsAccessor {
Handle<FixedArrayBase> backing_store, GetKeysConversion convert,
PropertyFilter filter, Handle<FixedArray> list, uint32_t* nof_indices,
uint32_t insertion_index = 0) {
uint32_t length = Subclass::GetMaxIndex(*object, *backing_store);
uint32_t length = Subclass::GetIterationLength(*object, *backing_store);
for (uint32_t i = 0; i < length; i++) {
if (Subclass::HasElementImpl(object, i, backing_store, filter)) {
if (convert == CONVERT_TO_STRING) {
@ -992,7 +968,18 @@ class ElementsAccessorBase : public ElementsAccessor {
// Sort the indices list if necessary.
if (IsDictionaryElementsKind(kind()) || IsSloppyArgumentsElements(kind())) {
SortIndices(combined_keys, nof_indices, SKIP_WRITE_BARRIER);
struct {
bool operator()(Object* a, Object* b) {
if (!a->IsUndefined()) {
if (b->IsUndefined()) return true;
return a->Number() < b->Number();
}
return !b->IsUndefined();
}
} cmp;
Object** start =
reinterpret_cast<Object**>(combined_keys->GetFirstElementAddress());
std::sort(start, start + nof_indices, cmp);
uint32_t array_length = 0;
// Indices from dictionary elements should only be converted after
// sorting.
@ -1057,7 +1044,7 @@ class ElementsAccessorBase : public ElementsAccessor {
? index
: kMaxUInt32;
} else {
uint32_t length = Subclass::GetMaxIndex(holder, backing_store);
uint32_t length = GetIterationLength(holder, backing_store);
return index < length ? index : kMaxUInt32;
}
}
@ -1094,15 +1081,17 @@ class DictionaryElementsAccessor
: ElementsAccessorBase<DictionaryElementsAccessor,
ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {}
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) {
SeededNumberDictionary* dict = SeededNumberDictionary::cast(backing_store);
return dict->NumberOfElements();
static uint32_t GetIterationLength(JSObject* receiver,
FixedArrayBase* elements) {
uint32_t length;
if (receiver->IsJSArray()) {
// Special-case GetIterationLength for dictionary elements since the
// length of the array might be a HeapNumber.
JSArray::cast(receiver)->length()->ToArrayLength(&length);
} else {
length = GetCapacityImpl(receiver, elements);
}
return length;
}
static void SetLengthImpl(Isolate* isolate, Handle<JSArray> array,
@ -1324,27 +1313,21 @@ class DictionaryElementsAccessor
Handle<FixedArrayBase> backing_store,
KeyAccumulator* keys) {
if (keys->filter() & SKIP_STRINGS) return;
Factory* factory = keys->isolate()->factory();
Handle<Object> undefined = factory->undefined_value();
Handle<Object> the_hole = factory->the_hole_value();
Isolate* isolate = keys->isolate();
Handle<Object> undefined = isolate->factory()->undefined_value();
Handle<Object> the_hole = isolate->factory()->the_hole_value();
Handle<SeededNumberDictionary> dictionary =
Handle<SeededNumberDictionary>::cast(backing_store);
int capacity = dictionary->Capacity();
Handle<FixedArray> elements =
factory->NewFixedArray(GetMaxNumberOfEntries(*object, *backing_store));
int insertion_index = 0;
PropertyFilter filter = keys->filter();
for (int i = 0; i < capacity; i++) {
uint32_t key =
GetKeyForEntryImpl(dictionary, i, filter, *undefined, *the_hole);
if (key == kMaxUInt32) continue;
elements->set(insertion_index, *factory->NewNumberFromUint(key));
insertion_index++;
}
SortIndices(elements, insertion_index);
for (int i = 0; i < insertion_index; i++) {
keys->AddKey(elements->get(i));
keys->AddKey(key);
}
keys->SortCurrentElementsList();
}
static Handle<FixedArray> DirectCollectElementIndicesImpl(
@ -1569,8 +1552,8 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> {
KeyAccumulator* accumulator,
AddKeyConversion convert) {
Handle<FixedArrayBase> elements(receiver->elements(),
accumulator->isolate());
uint32_t length = Subclass::GetMaxNumberOfEntries(*receiver, *elements);
receiver->GetIsolate());
uint32_t length = Subclass::GetIterationLength(*receiver, *elements);
for (uint32_t i = 0; i < length; i++) {
if (IsFastPackedElementsKind(KindTraits::Kind) ||
HasEntryImpl(*elements, i)) {
@ -2403,16 +2386,18 @@ class SloppyArgumentsElementsAccessor
static void CollectElementIndicesImpl(Handle<JSObject> object,
Handle<FixedArrayBase> backing_store,
KeyAccumulator* keys) {
Isolate* isolate = keys->isolate();
uint32_t nof_indices = 0;
Handle<FixedArray> indices = isolate->factory()->NewFixedArray(
GetCapacityImpl(*object, *backing_store));
DirectCollectElementIndicesImpl(isolate, object, backing_store,
KEEP_NUMBERS, ENUMERABLE_STRINGS, indices,
&nof_indices);
SortIndices(indices, nof_indices);
for (uint32_t i = 0; i < nof_indices; i++) {
keys->AddKey(indices->get(i));
FixedArray* parameter_map = FixedArray::cast(*backing_store);
uint32_t length = parameter_map->length() - 2;
for (uint32_t i = 0; i < length; ++i) {
if (!parameter_map->get(i + 2)->IsTheHole()) {
keys->AddKey(i);
}
}
Handle<FixedArrayBase> store(FixedArrayBase::cast(parameter_map->get(1)));
ArgumentsAccessor::CollectElementIndicesImpl(object, store, keys);
if (Subclass::kind() == FAST_SLOPPY_ARGUMENTS_ELEMENTS) {
keys->SortCurrentElementsList();
}
}
@ -2760,9 +2745,8 @@ class StringWrapperElementsAccessor
Handle<FixedArrayBase> backing_store,
KeyAccumulator* keys) {
uint32_t length = GetString(*object)->length();
Factory* factory = keys->isolate()->factory();
for (uint32_t i = 0; i < length; i++) {
keys->AddKey(factory->NewNumberFromUint(i));
keys->AddKey(i);
}
BackingStoreAccessor::CollectElementIndicesImpl(object, backing_store,
keys);

View File

@ -544,9 +544,9 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSReceiverSlow(
if (contents.is_null()) {
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, contents,
KeyAccumulator::GetKeys(object, OWN_ONLY, ENUMERABLE_STRINGS),
EXCEPTION);
JSReceiver::GetKeys(object, OWN_ONLY, ENUMERABLE_STRINGS), EXCEPTION);
}
builder_.AppendCharacter('{');
Indent();
bool comma = false;

View File

@ -17,6 +17,9 @@ namespace v8 {
namespace internal {
KeyAccumulator::~KeyAccumulator() {
for (size_t i = 0; i < elements_.size(); i++) {
delete elements_[i];
}
}
namespace {
@ -34,12 +37,11 @@ static bool ContainsOnlyValidKeys(Handle<FixedArray> array) {
MaybeHandle<FixedArray> KeyAccumulator::GetKeys(
Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter,
GetKeysConversion keys_conversion, bool filter_proxy_keys, bool is_for_in) {
GetKeysConversion keys_conversion, bool filter_proxy_keys) {
USE(ContainsOnlyValidKeys);
Isolate* isolate = object->GetIsolate();
KeyAccumulator accumulator(isolate, type, filter);
accumulator.set_filter_proxy_keys(filter_proxy_keys);
accumulator.set_is_for_in(is_for_in);
MAYBE_RETURN(accumulator.CollectKeys(object, object),
MaybeHandle<FixedArray>());
Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion);
@ -48,41 +50,181 @@ MaybeHandle<FixedArray> KeyAccumulator::GetKeys(
}
Handle<FixedArray> KeyAccumulator::GetKeys(GetKeysConversion convert) {
if (keys_.is_null()) {
if (length_ == 0) {
return isolate_->factory()->empty_fixed_array();
}
if (type_ == OWN_ONLY &&
keys_->map() == isolate_->heap()->fixed_array_map()) {
return Handle<FixedArray>::cast(keys_);
// Make sure we have all the lengths collected.
NextPrototype();
if (type_ == OWN_ONLY && !ownProxyKeys_.is_null()) {
return ownProxyKeys_;
}
return OrderedHashSet::ConvertToKeysArray(keys(), convert);
// Assemble the result array by first adding the element keys and then the
// property keys. We use the total number of String + Symbol keys per level in
// |level_lengths_| and the available element keys in the corresponding bucket
// in |elements_| to deduce the number of keys to take from the
// |string_properties_| and |symbol_properties_| set.
Handle<FixedArray> result = isolate_->factory()->NewFixedArray(length_);
int insertion_index = 0;
int string_properties_index = 0;
int symbol_properties_index = 0;
// String and Symbol lengths always come in pairs:
size_t max_level = level_lengths_.size() / 2;
for (size_t level = 0; level < max_level; level++) {
int num_string_properties = level_lengths_[level * 2];
int num_symbol_properties = level_lengths_[level * 2 + 1];
int num_elements = 0;
if (num_string_properties < 0) {
// If the |num_string_properties| is negative, the current level contains
// properties from a proxy, hence we skip the integer keys in |elements_|
// since proxies define the complete ordering.
num_string_properties = -num_string_properties;
} else if (level < elements_.size()) {
// Add the element indices for this prototype level.
std::vector<uint32_t>* elements = elements_[level];
num_elements = static_cast<int>(elements->size());
for (int i = 0; i < num_elements; i++) {
Handle<Object> key;
if (convert == KEEP_NUMBERS) {
key = isolate_->factory()->NewNumberFromUint(elements->at(i));
} else {
key = isolate_->factory()->Uint32ToString(elements->at(i));
}
result->set(insertion_index, *key);
insertion_index++;
}
}
// Add the string property keys for this prototype level.
for (int i = 0; i < num_string_properties; i++) {
Object* key = string_properties_->KeyAt(string_properties_index);
result->set(insertion_index, key);
insertion_index++;
string_properties_index++;
}
// Add the symbol property keys for this prototype level.
for (int i = 0; i < num_symbol_properties; i++) {
Object* key = symbol_properties_->KeyAt(symbol_properties_index);
result->set(insertion_index, key);
insertion_index++;
symbol_properties_index++;
}
if (FLAG_trace_for_in_enumerate) {
PrintF("| strings=%d symbols=%d elements=%i ", num_string_properties,
num_symbol_properties, num_elements);
}
}
if (FLAG_trace_for_in_enumerate) {
PrintF("|| prototypes=%zu ||\n", max_level);
}
DCHECK_EQ(insertion_index, length_);
return result;
}
void KeyAccumulator::AddKey(Object* key, AddKeyConversion convert) {
AddKey(handle(key, isolate_), convert);
namespace {
bool AccumulatorHasKey(std::vector<uint32_t>* sub_elements, uint32_t key) {
return std::binary_search(sub_elements->begin(), sub_elements->end(), key);
}
void KeyAccumulator::AddKey(Handle<Object> key, AddKeyConversion convert) {
} // namespace
bool KeyAccumulator::AddKey(Object* key, AddKeyConversion convert) {
return AddKey(handle(key, isolate_), convert);
}
bool KeyAccumulator::AddKey(Handle<Object> key, AddKeyConversion convert) {
if (key->IsSymbol()) {
if (filter_ & SKIP_SYMBOLS) return;
if (Handle<Symbol>::cast(key)->is_private()) return;
} else if (filter_ & SKIP_STRINGS) {
return;
if (filter_ & SKIP_SYMBOLS) return false;
if (Handle<Symbol>::cast(key)->is_private()) return false;
return AddSymbolKey(key);
}
if (keys_.is_null()) {
keys_ = OrderedHashSet::Allocate(isolate_, 16);
if (filter_ & SKIP_STRINGS) return false;
// Make sure we do not add keys to a proxy-level (see AddKeysFromJSProxy).
DCHECK_LE(0, level_string_length_);
// In some cases (e.g. proxies) we might get in String-converted ints which
// should be added to the elements list instead of the properties. For
// proxies we have to convert as well but also respect the original order.
// Therefore we add a converted key to both sides
if (convert == CONVERT_TO_ARRAY_INDEX || convert == PROXY_MAGIC) {
uint32_t index = 0;
int prev_length = length_;
int prev_proto = level_string_length_;
if ((key->IsString() && Handle<String>::cast(key)->AsArrayIndex(&index)) ||
key->ToArrayIndex(&index)) {
bool key_was_added = AddIntegerKey(index);
if (convert == CONVERT_TO_ARRAY_INDEX) return key_was_added;
if (convert == PROXY_MAGIC) {
// If we had an array index (number) and it wasn't added, the key
// already existed before, hence we cannot add it to the properties
// keys as it would lead to duplicate entries.
if (!key_was_added) {
return false;
}
length_ = prev_length;
level_string_length_ = prev_proto;
}
}
}
uint32_t index;
if (convert == CONVERT_TO_ARRAY_INDEX && key->IsString() &&
Handle<String>::cast(key)->AsArrayIndex(&index)) {
key = isolate_->factory()->NewNumberFromUint(index);
return AddStringKey(key, convert);
}
bool KeyAccumulator::AddKey(uint32_t key) { return AddIntegerKey(key); }
bool KeyAccumulator::AddIntegerKey(uint32_t key) {
// Make sure we do not add keys to a proxy-level (see AddKeysFromJSProxy).
// We mark proxy-levels with a negative length
DCHECK_LE(0, level_string_length_);
// Binary search over all but the last level. The last one might not be
// sorted yet.
for (size_t i = 1; i < elements_.size(); i++) {
if (AccumulatorHasKey(elements_[i - 1], key)) return false;
}
elements_.back()->push_back(key);
length_++;
return true;
}
bool KeyAccumulator::AddStringKey(Handle<Object> key,
AddKeyConversion convert) {
if (string_properties_.is_null()) {
string_properties_ = OrderedHashSet::Allocate(isolate_, 16);
}
// TODO(cbruni): remove this conversion once we throw the correct TypeError
// for non-string/symbol elements returned by proxies
if (convert == PROXY_MAGIC && key->IsNumber()) {
key = isolate_->factory()->NumberToString(key);
}
int prev_size = string_properties_->NumberOfElements();
string_properties_ = OrderedHashSet::Add(string_properties_, key);
if (prev_size < string_properties_->NumberOfElements()) {
length_++;
level_string_length_++;
return true;
} else {
return false;
}
}
bool KeyAccumulator::AddSymbolKey(Handle<Object> key) {
if (symbol_properties_.is_null()) {
symbol_properties_ = OrderedHashSet::Allocate(isolate_, 16);
}
int prev_size = symbol_properties_->NumberOfElements();
symbol_properties_ = OrderedHashSet::Add(symbol_properties_, key);
if (prev_size < symbol_properties_->NumberOfElements()) {
length_++;
level_symbol_length_++;
return true;
} else {
return false;
}
keys_ = OrderedHashSet::Add(keys(), key);
}
void KeyAccumulator::AddKeys(Handle<FixedArray> array,
AddKeyConversion convert) {
int add_length = array->length();
if (add_length == 0) return;
for (int i = 0; i < add_length; i++) {
Handle<Object> current(array->get(i), isolate_);
AddKey(current, convert);
@ -129,20 +271,65 @@ MaybeHandle<FixedArray> FilterProxyKeys(Isolate* isolate, Handle<JSProxy> owner,
Maybe<bool> KeyAccumulator::AddKeysFromJSProxy(Handle<JSProxy> proxy,
Handle<FixedArray> keys) {
if (filter_proxy_keys_) {
DCHECK(!is_for_in_);
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, keys, FilterProxyKeys(isolate_, proxy, keys, filter_),
Nothing<bool>());
}
if (type_ == OWN_ONLY && !is_for_in_) {
// If we collect only the keys from a JSProxy do not sort or deduplicate it.
keys_ = keys;
return Just(true);
// Proxies define a complete list of keys with no distinction of
// elements and properties, which breaks the normal assumption for the
// KeyAccumulator.
if (type_ == OWN_ONLY) {
ownProxyKeys_ = keys;
level_string_length_ = keys->length();
length_ = level_string_length_;
} else {
AddKeys(keys, PROXY_MAGIC);
}
AddKeys(keys, is_for_in_ ? CONVERT_TO_ARRAY_INDEX : DO_NOT_CONVERT);
// Invert the current length to indicate a present proxy, so we can ignore
// element keys for this level. Otherwise we would not fully respect the order
// given by the proxy.
level_string_length_ = -level_string_length_;
return Just(true);
}
void KeyAccumulator::AddElementKeysFromInterceptor(
Handle<JSObject> array_like) {
AddKeys(array_like, CONVERT_TO_ARRAY_INDEX);
// The interceptor might introduce duplicates for the current level, since
// these keys get added after the objects's normal element keys.
SortCurrentElementsListRemoveDuplicates();
}
void KeyAccumulator::SortCurrentElementsListRemoveDuplicates() {
// Sort and remove duplicates from the current elements level and adjust.
// the lengths accordingly.
auto last_level = elements_.back();
size_t nof_removed_keys = last_level->size();
std::sort(last_level->begin(), last_level->end());
last_level->erase(std::unique(last_level->begin(), last_level->end()),
last_level->end());
// Adjust total length by the number of removed duplicates.
nof_removed_keys -= last_level->size();
length_ -= static_cast<int>(nof_removed_keys);
}
void KeyAccumulator::SortCurrentElementsList() {
if (elements_.empty()) return;
auto element_keys = elements_.back();
std::sort(element_keys->begin(), element_keys->end());
}
void KeyAccumulator::NextPrototype() {
// Store the protoLength on the first call of this method.
if (!elements_.empty()) {
level_lengths_.push_back(level_string_length_);
level_lengths_.push_back(level_symbol_length_);
}
elements_.push_back(new std::vector<uint32_t>());
level_string_length_ = 0;
level_symbol_length_ = 0;
}
Maybe<bool> KeyAccumulator::CollectKeys(Handle<JSReceiver> receiver,
Handle<JSReceiver> object) {
// Proxies have no hidden prototype and we should not trigger the
@ -408,19 +595,17 @@ MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysFast(
MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysSlow(
GetKeysConversion convert) {
return KeyAccumulator::GetKeys(receiver_, type_, filter_, KEEP_NUMBERS,
filter_proxy_keys_, is_for_in_);
return JSReceiver::GetKeys(receiver_, type_, filter_, KEEP_NUMBERS,
filter_proxy_keys_);
}
namespace {
enum IndexedOrNamed { kIndexed, kNamed };
// Returns |true| on success, |nothing| on exception.
template <class Callback, IndexedOrNamed type>
Maybe<bool> GetKeysFromInterceptor(Handle<JSReceiver> receiver,
Handle<JSObject> object,
KeyAccumulator* accumulator) {
static Maybe<bool> GetKeysFromInterceptor(Handle<JSReceiver> receiver,
Handle<JSObject> object,
KeyAccumulator* accumulator) {
Isolate* isolate = accumulator->isolate();
if (type == kIndexed) {
if (!object->HasIndexedInterceptor()) return Just(true);
@ -447,90 +632,54 @@ Maybe<bool> GetKeysFromInterceptor(Handle<JSReceiver> receiver,
}
RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>());
if (result.is_null()) return Just(true);
accumulator->AddKeys(
result, type == kIndexed ? CONVERT_TO_ARRAY_INDEX : DO_NOT_CONVERT);
DCHECK(result->IsJSArray() || result->HasSloppyArgumentsElements());
// The accumulator takes care of string/symbol filtering.
if (type == kIndexed) {
accumulator->AddElementKeysFromInterceptor(result);
} else {
accumulator->AddKeys(result, DO_NOT_CONVERT);
}
return Just(true);
}
} // namespace
Maybe<bool> KeyAccumulator::CollectOwnElementIndices(
Handle<JSReceiver> receiver, Handle<JSObject> object) {
if (filter_ & SKIP_STRINGS || skip_indices_) return Just(true);
void KeyAccumulator::CollectOwnElementIndices(Handle<JSObject> object) {
if (filter_ & SKIP_STRINGS) return;
ElementsAccessor* accessor = object->GetElementsAccessor();
accessor->CollectElementIndices(object, this);
return GetKeysFromInterceptor<v8::IndexedPropertyEnumeratorCallback,
kIndexed>(receiver, object, this);
}
namespace {
template <bool skip_symbols>
int CollectOwnPropertyNamesInternal(Handle<JSObject> object,
KeyAccumulator* keys,
Handle<DescriptorArray> descs,
int start_index, int limit) {
int first_skipped = -1;
for (int i = start_index; i < limit; i++) {
PropertyDetails details = descs->GetDetails(i);
if ((details.attributes() & keys->filter()) != 0) continue;
if (keys->filter() & ONLY_ALL_CAN_READ) {
if (details.kind() != kAccessor) continue;
Object* accessors = descs->GetValue(i);
if (!accessors->IsAccessorInfo()) continue;
if (!AccessorInfo::cast(accessors)->all_can_read()) continue;
}
Name* key = descs->GetKey(i);
if (skip_symbols == key->IsSymbol()) {
if (first_skipped == -1) first_skipped = i;
continue;
}
if (key->FilterKey(keys->filter())) continue;
keys->AddKey(key, DO_NOT_CONVERT);
}
return first_skipped;
}
} // namespace
Maybe<bool> KeyAccumulator::CollectOwnPropertyNames(Handle<JSReceiver> receiver,
Handle<JSObject> object) {
if (filter_ == ENUMERABLE_STRINGS) {
Handle<FixedArray> enum_keys =
KeyAccumulator::GetEnumPropertyKeys(isolate_, object);
AddKeys(enum_keys, DO_NOT_CONVERT);
} else {
if (object->HasFastProperties()) {
int limit = object->map()->NumberOfOwnDescriptors();
Handle<DescriptorArray> descs(object->map()->instance_descriptors(),
isolate_);
// First collect the strings,
int first_symbol =
CollectOwnPropertyNamesInternal<true>(object, this, descs, 0, limit);
// then the symbols.
if (first_symbol != -1) {
CollectOwnPropertyNamesInternal<false>(object, this, descs,
first_symbol, limit);
void KeyAccumulator::CollectOwnPropertyNames(Handle<JSObject> object) {
if (object->HasFastProperties()) {
int real_size = object->map()->NumberOfOwnDescriptors();
Handle<DescriptorArray> descs(object->map()->instance_descriptors(),
isolate_);
for (int i = 0; i < real_size; i++) {
PropertyDetails details = descs->GetDetails(i);
if ((details.attributes() & filter_) != 0) continue;
if (filter_ & ONLY_ALL_CAN_READ) {
if (details.kind() != kAccessor) continue;
Object* accessors = descs->GetValue(i);
if (!accessors->IsAccessorInfo()) continue;
if (!AccessorInfo::cast(accessors)->all_can_read()) continue;
}
} else if (object->IsJSGlobalObject()) {
GlobalDictionary::CollectKeysTo(
handle(object->global_dictionary(), isolate_), this, filter_);
} else {
NameDictionary::CollectKeysTo(
handle(object->property_dictionary(), isolate_), this, filter_);
Name* key = descs->GetKey(i);
if (key->FilterKey(filter_)) continue;
AddKey(key, DO_NOT_CONVERT);
}
} else if (object->IsJSGlobalObject()) {
GlobalDictionary::CollectKeysTo(
handle(object->global_dictionary(), isolate_), this, filter_);
} else {
NameDictionary::CollectKeysTo(
handle(object->property_dictionary(), isolate_), this, filter_);
}
// Add the property keys from the interceptor.
return GetKeysFromInterceptor<v8::GenericNamedPropertyEnumeratorCallback,
kNamed>(receiver, object, this);
}
// Returns |true| on success, |false| if prototype walking should be stopped,
// |nothing| if an exception was thrown.
Maybe<bool> KeyAccumulator::CollectOwnKeys(Handle<JSReceiver> receiver,
Handle<JSObject> object) {
NextPrototype();
// Check access rights if required.
if (object->IsAccessCheckNeeded() &&
!isolate_->MayAccess(handle(isolate_->context()), object)) {
@ -543,8 +692,27 @@ Maybe<bool> KeyAccumulator::CollectOwnKeys(Handle<JSReceiver> receiver,
DCHECK_EQ(OWN_ONLY, type_);
filter_ = static_cast<PropertyFilter>(filter_ | ONLY_ALL_CAN_READ);
}
MAYBE_RETURN(CollectOwnElementIndices(receiver, object), Nothing<bool>());
MAYBE_RETURN(CollectOwnPropertyNames(receiver, object), Nothing<bool>());
CollectOwnElementIndices(object);
// Add the element keys from the interceptor.
Maybe<bool> success =
GetKeysFromInterceptor<v8::IndexedPropertyEnumeratorCallback, kIndexed>(
receiver, object, this);
MAYBE_RETURN(success, Nothing<bool>());
if (filter_ == ENUMERABLE_STRINGS) {
Handle<FixedArray> enum_keys =
KeyAccumulator::GetEnumPropertyKeys(isolate_, object);
AddKeys(enum_keys, DO_NOT_CONVERT);
} else {
CollectOwnPropertyNames(object);
}
// Add the property keys from the interceptor.
success = GetKeysFromInterceptor<v8::GenericNamedPropertyEnumeratorCallback,
kNamed>(receiver, object, this);
MAYBE_RETURN(success, Nothing<bool>());
return Just(true);
}
@ -654,6 +822,7 @@ Maybe<bool> KeyAccumulator::CollectOwnJSProxyKeys(Handle<JSReceiver> receiver,
// (No-op, just keep it in |target_keys|.)
}
}
NextPrototype(); // Prepare for accumulating keys.
// 15. If extensibleTarget is true and targetNonconfigurableKeys is empty,
// then:
if (extensible_target && nonconfigurable_keys_length == 0) {
@ -727,6 +896,7 @@ Maybe<bool> KeyAccumulator::CollectOwnJSProxyTargetKeys(
Handle<FixedArray> keys;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, keys, JSReceiver::OwnPropertyKeys(target), Nothing<bool>());
NextPrototype(); // Prepare for accumulating keys.
bool prev_filter_proxy_keys_ = filter_proxy_keys_;
filter_proxy_keys_ = false;
Maybe<bool> result = AddKeysFromJSProxy(proxy, keys);

View File

@ -11,7 +11,7 @@
namespace v8 {
namespace internal {
enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX };
enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX, PROXY_MAGIC };
// This is a helper class for JSReceiver::GetKeys which collects and sorts keys.
// GetKeys needs to sort keys per prototype level, first showing the integer
@ -36,33 +36,36 @@ class KeyAccumulator final BASE_EMBEDDED {
: isolate_(isolate), type_(type), filter_(filter) {}
~KeyAccumulator();
static MaybeHandle<FixedArray> GetKeys(
Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter,
GetKeysConversion keys_conversion = KEEP_NUMBERS,
bool filter_proxy_keys = true, bool is_for_in = false);
static MaybeHandle<FixedArray> GetKeys(Handle<JSReceiver> object,
KeyCollectionType type,
PropertyFilter filter,
GetKeysConversion keys_conversion,
bool filter_proxy_keys);
Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS);
Maybe<bool> CollectKeys(Handle<JSReceiver> receiver,
Handle<JSReceiver> object);
Maybe<bool> CollectOwnElementIndices(Handle<JSReceiver> receiver,
Handle<JSObject> object);
Maybe<bool> CollectOwnPropertyNames(Handle<JSReceiver> receiver,
Handle<JSObject> object);
void CollectOwnElementIndices(Handle<JSObject> object);
void CollectOwnPropertyNames(Handle<JSObject> object);
static Handle<FixedArray> GetEnumPropertyKeys(Isolate* isolate,
Handle<JSObject> object);
void AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT);
void AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT);
bool AddKey(uint32_t key);
bool AddKey(Object* key, AddKeyConversion convert);
bool AddKey(Handle<Object> key, AddKeyConversion convert);
void AddKeys(Handle<FixedArray> array, AddKeyConversion convert);
void AddKeys(Handle<JSObject> array_like, AddKeyConversion convert);
void AddKeys(Handle<JSObject> array, AddKeyConversion convert);
void AddElementKeysFromInterceptor(Handle<JSObject> array);
// Jump to the next level, pushing the current |levelLength_| to
// |levelLengths_| and adding a new list to |elements_|.
void NextPrototype();
// Sort the integer indices in the last list in |elements_|
void SortCurrentElementsList();
int length() { return length_; }
Isolate* isolate() { return isolate_; }
PropertyFilter filter() { return filter_; }
void set_filter_proxy_keys(bool filter) { filter_proxy_keys_ = filter; }
void set_is_for_in(bool value) { is_for_in_ = value; }
void set_skip_indices(bool value) { skip_indices_ = value; }
private:
Maybe<bool> CollectOwnKeys(Handle<JSReceiver> receiver,
@ -75,17 +78,35 @@ class KeyAccumulator final BASE_EMBEDDED {
Maybe<bool> AddKeysFromJSProxy(Handle<JSProxy> proxy,
Handle<FixedArray> keys);
Handle<OrderedHashSet> keys() { return Handle<OrderedHashSet>::cast(keys_); }
bool AddIntegerKey(uint32_t key);
bool AddStringKey(Handle<Object> key, AddKeyConversion convert);
bool AddSymbolKey(Handle<Object> array);
void SortCurrentElementsListRemoveDuplicates();
Isolate* isolate_;
// keys_ is either an Handle<OrderedHashSet> or in the case of own JSProxy
// keys a Handle<FixedArray>.
Handle<FixedArray> keys_;
KeyCollectionType type_;
PropertyFilter filter_;
bool filter_proxy_keys_ = true;
bool is_for_in_ = false;
bool skip_indices_ = false;
// |elements_| contains the sorted element keys (indices) per level.
std::vector<std::vector<uint32_t>*> elements_;
// |protoLengths_| contains the total number of keys (elements + properties)
// per level. Negative values mark counts for a level with keys from a proxy.
std::vector<int> level_lengths_;
// |string_properties_| contains the unique String property keys for all
// levels in insertion order per level.
Handle<OrderedHashSet> string_properties_;
// |symbol_properties_| contains the unique Symbol property keys for all
// levels in insertion order per level.
Handle<OrderedHashSet> symbol_properties_;
Handle<FixedArray> ownProxyKeys_;
// |length_| keeps track of the total number of all element and property keys.
int length_ = 0;
// |levelLength_| keeps track of the number of String keys in the current
// level.
int level_string_length_ = 0;
// |levelSymbolLength_| keeps track of the number of Symbol keys in the
// current level.
int level_symbol_length_ = 0;
DISALLOW_COPY_AND_ASSIGN(KeyAccumulator);
};
@ -104,7 +125,6 @@ class FastKeyAccumulator {
bool is_receiver_simple_enum() { return is_receiver_simple_enum_; }
bool has_empty_prototype() { return has_empty_prototype_; }
void set_filter_proxy_keys(bool filter) { filter_proxy_keys_ = filter; }
void set_is_for_in(bool value) { is_for_in_ = value; }
MaybeHandle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS);
@ -118,7 +138,6 @@ class FastKeyAccumulator {
KeyCollectionType type_;
PropertyFilter filter_;
bool filter_proxy_keys_ = true;
bool is_for_in_ = false;
bool is_receiver_simple_enum_ = false;
bool has_empty_prototype_ = false;

View File

@ -21,9 +21,8 @@
#include "src/handles-inl.h"
#include "src/heap/heap-inl.h"
#include "src/heap/heap.h"
#include "src/isolate-inl.h"
#include "src/isolate.h"
#include "src/keys.h"
#include "src/isolate-inl.h"
#include "src/layout-descriptor-inl.h"
#include "src/lookup.h"
#include "src/objects.h"
@ -1111,12 +1110,6 @@ MaybeHandle<Object> JSReceiver::GetProperty(Isolate* isolate,
return GetProperty(receiver, str);
}
// static
MUST_USE_RESULT MaybeHandle<FixedArray> JSReceiver::OwnPropertyKeys(
Handle<JSReceiver> object) {
return KeyAccumulator::GetKeys(object, OWN_ONLY, ALL_PROPERTIES,
CONVERT_TO_STRING);
}
#define FIELD_ADDR(p, offset) \
(reinterpret_cast<byte*>(p) + offset - kHeapObjectTag)
@ -6647,18 +6640,16 @@ ElementsKind JSObject::GetElementsKind() {
// pointer may point to a one pointer filler map.
if (ElementsAreSafeToExamine()) {
Map* map = fixed_array->map();
if (IsFastSmiOrObjectElementsKind(kind)) {
DCHECK(map == GetHeap()->fixed_array_map() ||
map == GetHeap()->fixed_cow_array_map());
} else if (IsFastDoubleElementsKind(kind)) {
DCHECK(fixed_array->IsFixedDoubleArray() ||
fixed_array == GetHeap()->empty_fixed_array());
} else if (kind == DICTIONARY_ELEMENTS) {
DCHECK(fixed_array->IsFixedArray());
DCHECK(fixed_array->IsDictionary());
} else {
DCHECK(kind > DICTIONARY_ELEMENTS);
}
DCHECK((IsFastSmiOrObjectElementsKind(kind) &&
(map == GetHeap()->fixed_array_map() ||
map == GetHeap()->fixed_cow_array_map())) ||
(IsFastDoubleElementsKind(kind) &&
(fixed_array->IsFixedDoubleArray() ||
fixed_array == GetHeap()->empty_fixed_array())) ||
(kind == DICTIONARY_ELEMENTS &&
fixed_array->IsFixedArray() &&
fixed_array->IsDictionary()) ||
(kind > DICTIONARY_ELEMENTS));
DCHECK(!IsSloppyArgumentsElements(kind) ||
(elements()->IsFixedArray() && elements()->length() >= 2));
}

View File

@ -6179,7 +6179,7 @@ MaybeHandle<Object> JSReceiver::DefineProperties(Isolate* isolate,
// 5. ReturnIfAbrupt(keys).
Handle<FixedArray> keys;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, keys, KeyAccumulator::GetKeys(props, OWN_ONLY, ALL_PROPERTIES),
isolate, keys, JSReceiver::GetKeys(props, OWN_ONLY, ALL_PROPERTIES),
Object);
// 6. Let descriptors be an empty List.
int capacity = keys->length();
@ -7858,7 +7858,8 @@ MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk(
PropertyFilter filter = static_cast<PropertyFilter>(
ONLY_WRITABLE | ONLY_ENUMERABLE | ONLY_CONFIGURABLE);
KeyAccumulator accumulator(isolate, OWN_ONLY, filter);
accumulator.CollectOwnPropertyNames(copy, copy);
accumulator.NextPrototype();
accumulator.CollectOwnPropertyNames(copy);
Handle<FixedArray> names = accumulator.GetKeys();
for (int i = 0; i < names->length(); i++) {
DCHECK(names->get(i)->IsName());
@ -8163,6 +8164,15 @@ bool Map::OnlyHasSimpleProperties() {
!has_hidden_prototype() && !is_dictionary_map();
}
MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
KeyCollectionType type,
PropertyFilter filter,
GetKeysConversion keys_conversion,
bool filter_proxy_keys) {
return KeyAccumulator::GetKeys(object, type, filter, keys_conversion,
filter_proxy_keys);
}
MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries(
Isolate* isolate, Handle<JSReceiver> receiver, bool get_entries,
Handle<FixedArray>* result) {
@ -17179,23 +17189,9 @@ void Dictionary<Derived, Shape, Key>::CollectKeysTo(
std::sort(start, start + array_size, cmp);
}
bool has_seen_symbol = false;
for (int i = 0; i < array_size; i++) {
int index = Smi::cast(array->get(i))->value();
Object* key = dictionary->KeyAt(index);
if (key->IsSymbol()) {
has_seen_symbol = true;
continue;
}
keys->AddKey(key, DO_NOT_CONVERT);
}
if (has_seen_symbol) {
for (int i = 0; i < array_size; i++) {
int index = Smi::cast(array->get(i))->value();
Object* key = dictionary->KeyAt(index);
if (!key->IsSymbol()) continue;
keys->AddKey(key, DO_NOT_CONVERT);
}
keys->AddKey(dictionary->KeyAt(index), DO_NOT_CONVERT);
}
}
@ -17495,26 +17491,6 @@ Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table,
return table;
}
Handle<FixedArray> OrderedHashSet::ConvertToKeysArray(
Handle<OrderedHashSet> table, GetKeysConversion convert) {
Isolate* isolate = table->GetIsolate();
int length = table->NumberOfElements();
int nof_buckets = table->NumberOfBuckets();
// Convert the dictionary to a linear list.
Handle<FixedArray> result = Handle<FixedArray>::cast(table);
// From this point on table is no longer a valid OrderedHashSet.
result->set_map_no_write_barrier(isolate->heap()->fixed_array_map());
for (int i = 0; i < length; i++) {
int index = kHashTableStartIndex + nof_buckets + (i * kEntrySize);
Object* key = table->get(index);
if (convert == CONVERT_TO_STRING && key->IsNumber()) {
key = *isolate->factory()->NumberToString(handle(key, isolate));
}
result->set(i, key);
}
result->Shrink(length);
return result;
}
template<class Derived, class Iterator, int entrysize>
Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Rehash(

View File

@ -1975,8 +1975,17 @@ class JSReceiver: public HeapObject {
Handle<JSReceiver> object);
// ES6 [[OwnPropertyKeys]] (modulo return type)
MUST_USE_RESULT static inline MaybeHandle<FixedArray> OwnPropertyKeys(
Handle<JSReceiver> object);
MUST_USE_RESULT static MaybeHandle<FixedArray> OwnPropertyKeys(
Handle<JSReceiver> object) {
return GetKeys(object, OWN_ONLY, ALL_PROPERTIES, CONVERT_TO_STRING);
}
// Computes the enumerable keys for a JSObject. Used for implementing
// "for (n in object) { }".
MUST_USE_RESULT static MaybeHandle<FixedArray> GetKeys(
Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter,
GetKeysConversion keys_conversion = KEEP_NUMBERS,
bool filter_proxy_keys_ = true);
MUST_USE_RESULT static MaybeHandle<FixedArray> GetOwnValues(
Handle<JSReceiver> object, PropertyFilter filter);
@ -3971,8 +3980,6 @@ class OrderedHashSet: public OrderedHashTable<
static Handle<OrderedHashSet> Add(Handle<OrderedHashSet> table,
Handle<Object> value);
static Handle<FixedArray> ConvertToKeysArray(Handle<OrderedHashSet> table,
GetKeysConversion convert);
};

View File

@ -211,8 +211,9 @@ RUNTIME_FUNCTION(Runtime_GetArrayKeys) {
// collecting keys in that case.
return *isolate->factory()->NewNumberFromUint(length);
}
accumulator.NextPrototype();
Handle<JSObject> current = PrototypeIterator::GetCurrent<JSObject>(iter);
accumulator.CollectOwnElementIndices(array, current);
accumulator.CollectOwnElementIndices(current);
}
// Erase any keys >= length.
Handle<FixedArray> keys = accumulator.GetKeys(KEEP_NUMBERS);

View File

@ -25,7 +25,6 @@ MaybeHandle<HeapObject> Enumerate(Handle<JSReceiver> receiver) {
FastKeyAccumulator accumulator(isolate, receiver, INCLUDE_PROTOS,
ENUMERABLE_STRINGS);
accumulator.set_filter_proxy_keys(false);
accumulator.set_is_for_in(true);
// Test if we have an enum cache for {receiver}.
if (!accumulator.is_receiver_simple_enum()) {
Handle<FixedArray> keys;

View File

@ -563,7 +563,7 @@ RUNTIME_FUNCTION(Runtime_GetOwnPropertyKeys) {
Handle<FixedArray> keys;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, keys,
KeyAccumulator::GetKeys(object, OWN_ONLY, filter, CONVERT_TO_STRING));
JSReceiver::GetKeys(object, OWN_ONLY, filter, CONVERT_TO_STRING));
return *isolate->factory()->NewJSArrayWithElements(keys);
}

View File

@ -2270,34 +2270,33 @@ THREADED_TEST(Enumerators) {
// This order is not mandated by the spec, so this test is just
// documenting our behavior.
CHECK_EQ(17u, result->Length());
// Indexed properties.
CHECK(v8_str("5")
// Indexed properties + indexed interceptor properties in numerical order.
CHECK(v8_str("0")
->Equals(context.local(),
result->Get(context.local(), v8::Integer::New(isolate, 0))
.ToLocalChecked())
.FromJust());
CHECK(v8_str("10")
CHECK(v8_str("1")
->Equals(context.local(),
result->Get(context.local(), v8::Integer::New(isolate, 1))
.ToLocalChecked())
.FromJust());
CHECK(v8_str("140000")
CHECK(v8_str("5")
->Equals(context.local(),
result->Get(context.local(), v8::Integer::New(isolate, 2))
.ToLocalChecked())
.FromJust());
CHECK(v8_str("4294967294")
CHECK(v8_str("10")
->Equals(context.local(),
result->Get(context.local(), v8::Integer::New(isolate, 3))
.ToLocalChecked())
.FromJust());
// Indexed Interceptor properties
CHECK(v8_str("0")
CHECK(v8_str("140000")
->Equals(context.local(),
result->Get(context.local(), v8::Integer::New(isolate, 4))
.ToLocalChecked())
.FromJust());
CHECK(v8_str("1")
CHECK(v8_str("4294967294")
->Equals(context.local(),
result->Get(context.local(), v8::Integer::New(isolate, 5))
.ToLocalChecked())

View File

@ -541,13 +541,6 @@ function prepare(target) {
[s2]: 0, "-1": 0, "88": 0, "aaa": 0 };
assertEquals(["0", "42", "88", "bla", "-1", "aaa", s1, s2],
Reflect.ownKeys(obj));
// Force dict-mode elements.
delete obj[0];
assertEquals(["42", "88", "bla", "-1", "aaa", s1, s2],
Reflect.ownKeys(obj));
// Force dict-mode properties.
delete obj["bla"];
assertEquals(["42", "88", "-1", "aaa", s1, s2], Reflect.ownKeys(obj));
})();