Commit 65eef383 authored by jkummerow's avatar jkummerow Committed by Commit bot

[cleanup] Drop JSObject::GetOwnPropertyNames().

Can be replaced by KeyAccumulator + CollectOwnPropertyNames().

Review URL: https://codereview.chromium.org/1515473003

Cr-Commit-Position: refs/heads/master@{#32719}
parent a2d5641b
......@@ -7797,20 +7797,18 @@ MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk(
}
}
} else {
Handle<FixedArray> names =
isolate->factory()->NewFixedArray(copy->NumberOfOwnProperties());
copy->GetOwnPropertyNames(*names, 0);
// Only deep copy fields from the object literal expression.
// In particular, don't try to copy the length attribute of
// an array.
PropertyFilter filter = static_cast<PropertyFilter>(
ONLY_WRITABLE | ONLY_ENUMERABLE | ONLY_CONFIGURABLE);
KeyAccumulator accumulator(isolate, filter);
accumulator.NextPrototype();
copy->CollectOwnPropertyNames(&accumulator, filter);
Handle<FixedArray> names = accumulator.GetKeys();
for (int i = 0; i < names->length(); i++) {
DCHECK(names->get(i)->IsName());
Handle<Name> name(Name::cast(names->get(i)));
Maybe<PropertyAttributes> maybe =
JSReceiver::GetOwnPropertyAttributes(copy, name);
DCHECK(maybe.IsJust());
PropertyAttributes attributes = maybe.FromJust();
// Only deep copy fields from the object literal expression.
// In particular, don't try to copy the length attribute of
// an array.
if (attributes != NONE) continue;
Handle<Object> value =
Object::GetProperty(copy, name).ToHandleChecked();
if (value->IsJSObject()) {
......@@ -15841,25 +15839,6 @@ Maybe<bool> JSObject::HasRealNamedCallbackProperty(Handle<JSObject> object,
}
// Private symbols are always filtered out.
int JSObject::NumberOfOwnProperties(PropertyFilter filter) {
if (HasFastProperties()) {
Map* map = this->map();
if (filter == ENUMERABLE_STRINGS) {
// The cached enum length was computed with filter == ENUMERABLE_STRING,
// so that's the only filter for which it's valid to retrieve it.
int result = map->EnumLength();
if (result != kInvalidEnumCacheSentinel) return result;
}
return map->NumberOfDescribedProperties(OWN_DESCRIPTORS, filter);
} else if (IsJSGlobalObject()) {
return global_dictionary()->NumberOfElementsFilterAttributes(filter);
} else {
return property_dictionary()->NumberOfElementsFilterAttributes(filter);
}
}
void FixedArray::SwapPairs(FixedArray* numbers, int i, int j) {
Object* temp = get(i);
set(i, get(j));
......@@ -15973,33 +15952,6 @@ void FixedArray::SortPairs(FixedArray* numbers, uint32_t len) {
}
// Fill in the names of own properties into the supplied storage. The main
// purpose of this function is to provide reflection information for the object
// mirrors.
int JSObject::GetOwnPropertyNames(FixedArray* storage, int index,
PropertyFilter filter) {
DCHECK(storage->length() >= (NumberOfOwnProperties(filter) - index));
if (HasFastProperties()) {
int start_index = index;
int real_size = map()->NumberOfOwnDescriptors();
DescriptorArray* descs = map()->instance_descriptors();
for (int i = 0; i < real_size; i++) {
if ((descs->GetDetails(i).attributes() & filter) == 0 &&
!descs->GetKey(i)->FilterKey(filter)) {
storage->set(index++, descs->GetKey(i));
}
}
return index - start_index;
} else if (IsJSGlobalObject()) {
return global_dictionary()->CopyKeysTo(storage, index, filter,
GlobalDictionary::UNSORTED);
} else {
return property_dictionary()->CopyKeysTo(storage, index, filter,
NameDictionary::UNSORTED);
}
}
void JSObject::CollectOwnPropertyNames(KeyAccumulator* keys,
PropertyFilter filter) {
if (HasFastProperties()) {
......
......@@ -2258,13 +2258,6 @@ class JSObject: public JSReceiver {
inline void SetInternalField(int index, Object* value);
inline void SetInternalField(int index, Smi* value);
// Returns the number of properties on this object filtering out properties
// with the specified attributes (ignoring interceptors).
int NumberOfOwnProperties(PropertyFilter filter = ALL_PROPERTIES);
// Fill in details for properties into storage starting at the specified
// index. Returns the number of properties added.
int GetOwnPropertyNames(FixedArray* storage, int index,
PropertyFilter filter = ALL_PROPERTIES);
void CollectOwnPropertyNames(KeyAccumulator* keys,
PropertyFilter filter = ALL_PROPERTIES);
......@@ -3353,9 +3346,11 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
// Returns the number of elements in the dictionary filtering out properties
// with the specified attributes.
// TODO(jkummerow): Deprecated, only used by Object.observe.
int NumberOfElementsFilterAttributes(PropertyFilter filter);
// Returns the number of enumerable elements in the dictionary.
// TODO(jkummerow): Deprecated, only used by Object.observe.
int NumberOfEnumElements() {
return NumberOfElementsFilterAttributes(ENUMERABLE_STRINGS);
}
......@@ -3368,6 +3363,7 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
// Fill in details for properties into storage.
// Returns the number of properties added.
// TODO(jkummerow): Deprecated, only used by Object.observe.
int CopyKeysTo(FixedArray* storage, int index, PropertyFilter filter,
SortMode sort_mode);
// Collect the keys into the given KeyAccumulator, in ascending chronological
......
......@@ -38,7 +38,9 @@ enum PropertyAttributes {
enum PropertyFilter {
ALL_PROPERTIES = 0,
ONLY_WRITABLE = 1,
ONLY_ENUMERABLE = 2,
ONLY_CONFIGURABLE = 4,
SKIP_STRINGS = 8,
SKIP_SYMBOLS = 16,
ONLY_ALL_CAN_READ = 32,
......@@ -46,7 +48,9 @@ enum PropertyFilter {
};
// Enable fast comparisons of PropertyAttributes against PropertyFilters.
STATIC_ASSERT(ALL_PROPERTIES == static_cast<PropertyFilter>(NONE));
STATIC_ASSERT(ONLY_WRITABLE == static_cast<PropertyFilter>(READ_ONLY));
STATIC_ASSERT(ONLY_ENUMERABLE == static_cast<PropertyFilter>(DONT_ENUM));
STATIC_ASSERT(ONLY_CONFIGURABLE == static_cast<PropertyFilter>(DONT_DELETE));
STATIC_ASSERT(((SKIP_STRINGS | SKIP_SYMBOLS | ONLY_ALL_CAN_READ) &
ALL_ATTRIBUTES_MASK) == 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