Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Unified Diff: src/objects.cc

Issue 1673673002: reland [es7] refactor and fix Object.values() / Object.entries() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 7097ea36d2615c11308c99699f8a4ccb5afb824d..65f38495332a71087d249ffee571629341193f82 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -8944,6 +8944,64 @@ MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
return keys;
}
+MaybeHandle<FixedArray> GetOwnValuesOrEntries(Isolate* isolate,
+ Handle<JSReceiver> object,
+ PropertyFilter filter,
+ bool get_entries) {
+ PropertyFilter key_filter =
+ static_cast<PropertyFilter>(filter & ~ONLY_ENUMERABLE);
+ KeyAccumulator accumulator(isolate, OWN_ONLY, key_filter);
+ MAYBE_RETURN(GetKeys_Internal(isolate, object, object, OWN_ONLY, key_filter,
+ &accumulator),
+ MaybeHandle<FixedArray>());
+ Handle<FixedArray> keys = accumulator.GetKeys(CONVERT_TO_STRING);
+ DCHECK(ContainsOnlyValidKeys(keys));
+
+ Handle<FixedArray> values_or_entries =
+ isolate->factory()->NewFixedArray(keys->length());
+ int length = 0;
+
+ for (int i = 0; i < keys->length(); ++i) {
+ Handle<Name> key = Handle<Name>::cast(handle(keys->get(i), isolate));
+
+ if (filter & ONLY_ENUMERABLE) {
+ PropertyDescriptor descriptor;
+ Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor(
+ isolate, object, key, &descriptor);
+ MAYBE_RETURN(did_get_descriptor, MaybeHandle<FixedArray>());
+ if (!did_get_descriptor.FromJust() || !descriptor.enumerable()) continue;
+ }
+
+ Handle<Object> value;
+ ASSIGN_RETURN_ON_EXCEPTION_VALUE(
+ isolate, value, JSReceiver::GetPropertyOrElement(object, key, STRICT),
+ MaybeHandle<FixedArray>());
+
+ if (get_entries) {
+ Handle<FixedArray> entry_storage =
+ isolate->factory()->NewUninitializedFixedArray(2);
+ entry_storage->set(0, *key);
+ entry_storage->set(1, *value);
+ value = isolate->factory()->NewJSArrayWithElements(entry_storage,
+ FAST_ELEMENTS, 2);
+ }
+
+ values_or_entries->set(length, *value);
+ length++;
+ }
+ if (length < values_or_entries->length()) values_or_entries->Shrink(length);
+ return values_or_entries;
+}
+
+MaybeHandle<FixedArray> JSReceiver::GetOwnValues(Handle<JSReceiver> object,
+ PropertyFilter filter) {
+ return GetOwnValuesOrEntries(object->GetIsolate(), object, filter, false);
+}
+
+MaybeHandle<FixedArray> JSReceiver::GetOwnEntries(Handle<JSReceiver> object,
+ PropertyFilter filter) {
+ return GetOwnValuesOrEntries(object->GetIsolate(), object, filter, true);
+}
bool Map::DictionaryElementsInPrototypeChainOnly() {
if (IsDictionaryElementsKind(elements_kind())) {
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698