Commit e4c3be5a authored by cbruni's avatar cbruni Committed by Commit bot

[keys] KeyAccumulator cleanups

Move most of JSReceiver::GetKeys to the KeyAccumulator

BUG=

Review-Url: https://codereview.chromium.org/1989263002
Cr-Commit-Position: refs/heads/master@{#36321}
parent 233ca4ce
......@@ -22,6 +22,33 @@ KeyAccumulator::~KeyAccumulator() {
}
}
namespace {
static bool ContainsOnlyValidKeys(Handle<FixedArray> array) {
int len = array->length();
for (int i = 0; i < len; i++) {
Object* e = array->get(i);
if (!(e->IsName() || e->IsNumber())) return false;
}
return true;
}
} // namespace
MaybeHandle<FixedArray> KeyAccumulator::GetKeys(
Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter,
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);
MAYBE_RETURN(accumulator.CollectKeys(object, object),
MaybeHandle<FixedArray>());
Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion);
DCHECK(ContainsOnlyValidKeys(keys));
return keys;
}
Handle<FixedArray> KeyAccumulator::GetKeys(GetKeysConversion convert) {
if (length_ == 0) {
return isolate_->factory()->empty_fixed_array();
......@@ -568,7 +595,7 @@ MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysFast(
MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysSlow(
GetKeysConversion convert) {
return JSReceiver::GetKeys(receiver_, type_, ENUMERABLE_STRINGS, KEEP_NUMBERS,
return JSReceiver::GetKeys(receiver_, type_, filter_, KEEP_NUMBERS,
filter_proxy_keys_);
}
......
......@@ -36,6 +36,11 @@ 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,
bool filter_proxy_keys);
Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS);
Maybe<bool> CollectKeys(Handle<JSReceiver> receiver,
Handle<JSReceiver> object);
......@@ -115,8 +120,6 @@ class FastKeyAccumulator {
KeyCollectionType type, PropertyFilter filter)
: isolate_(isolate), receiver_(receiver), type_(type), filter_(filter) {
Prepare();
// TODO(cbruni): pass filter_ directly to the KeyAccumulator.
USE(filter_);
}
bool is_receiver_simple_enum() { return is_receiver_simple_enum_; }
......@@ -134,9 +137,9 @@ class FastKeyAccumulator {
Handle<JSReceiver> receiver_;
KeyCollectionType type_;
PropertyFilter filter_;
bool filter_proxy_keys_ = true;
bool is_receiver_simple_enum_ = false;
bool has_empty_prototype_ = false;
bool filter_proxy_keys_ = true;
DISALLOW_COPY_AND_ASSIGN(FastKeyAccumulator);
};
......
......@@ -8152,16 +8152,6 @@ int Map::NextFreePropertyIndex() {
}
static bool ContainsOnlyValidKeys(Handle<FixedArray> array) {
int len = array->length();
for (int i = 0; i < len; i++) {
Object* e = array->get(i);
if (!(e->IsName() || e->IsNumber())) return false;
}
return true;
}
bool Map::OnlyHasSimpleProperties() {
// Wrapped string elements aren't explicitly stored in the elements backing
// store, but are loaded indirectly from the underlying string.
......@@ -8175,15 +8165,8 @@ MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
PropertyFilter filter,
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);
MAYBE_RETURN(accumulator.CollectKeys(object, object),
MaybeHandle<FixedArray>());
Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion);
DCHECK(ContainsOnlyValidKeys(keys));
return keys;
return KeyAccumulator::GetKeys(object, type, filter, keys_conversion,
filter_proxy_keys);
}
MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries(
......@@ -8280,7 +8263,6 @@ MaybeHandle<FixedArray> GetOwnValuesOrEntries(Isolate* isolate,
MAYBE_RETURN(accumulator.CollectKeys(object, object),
MaybeHandle<FixedArray>());
Handle<FixedArray> keys = accumulator.GetKeys(CONVERT_TO_STRING);
DCHECK(ContainsOnlyValidKeys(keys));
values_or_entries = isolate->factory()->NewFixedArray(keys->length());
int length = 0;
......
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