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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 8926 matching lines...) Expand 10 before | Expand all | Expand 10 after
8937 Isolate* isolate = object->GetIsolate(); 8937 Isolate* isolate = object->GetIsolate();
8938 KeyAccumulator accumulator(isolate, type, filter); 8938 KeyAccumulator accumulator(isolate, type, filter);
8939 MAYBE_RETURN( 8939 MAYBE_RETURN(
8940 GetKeys_Internal(isolate, object, object, type, filter, &accumulator), 8940 GetKeys_Internal(isolate, object, object, type, filter, &accumulator),
8941 MaybeHandle<FixedArray>()); 8941 MaybeHandle<FixedArray>());
8942 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion); 8942 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion);
8943 DCHECK(ContainsOnlyValidKeys(keys)); 8943 DCHECK(ContainsOnlyValidKeys(keys));
8944 return keys; 8944 return keys;
8945 } 8945 }
8946 8946
8947 MaybeHandle<FixedArray> GetOwnValuesOrEntries(Isolate* isolate,
8948 Handle<JSReceiver> object,
8949 PropertyFilter filter,
8950 bool get_entries) {
8951 PropertyFilter key_filter =
8952 static_cast<PropertyFilter>(filter & ~ONLY_ENUMERABLE);
8953 KeyAccumulator accumulator(isolate, OWN_ONLY, key_filter);
8954 MAYBE_RETURN(GetKeys_Internal(isolate, object, object, OWN_ONLY, key_filter,
8955 &accumulator),
8956 MaybeHandle<FixedArray>());
8957 Handle<FixedArray> keys = accumulator.GetKeys(CONVERT_TO_STRING);
8958 DCHECK(ContainsOnlyValidKeys(keys));
8959
8960 Handle<FixedArray> values_or_entries =
8961 isolate->factory()->NewFixedArray(keys->length());
8962 int length = 0;
8963
8964 for (int i = 0; i < keys->length(); ++i) {
8965 Handle<Name> key = Handle<Name>::cast(handle(keys->get(i), isolate));
8966
8967 if (filter & ONLY_ENUMERABLE) {
8968 PropertyDescriptor descriptor;
8969 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor(
8970 isolate, object, key, &descriptor);
8971 MAYBE_RETURN(did_get_descriptor, MaybeHandle<FixedArray>());
8972 if (!did_get_descriptor.FromJust() || !descriptor.enumerable()) continue;
8973 }
8974
8975 Handle<Object> value;
8976 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
8977 isolate, value, JSReceiver::GetPropertyOrElement(object, key, STRICT),
8978 MaybeHandle<FixedArray>());
8979
8980 if (get_entries) {
8981 Handle<FixedArray> entry_storage =
8982 isolate->factory()->NewUninitializedFixedArray(2);
8983 entry_storage->set(0, *key);
8984 entry_storage->set(1, *value);
8985 value = isolate->factory()->NewJSArrayWithElements(entry_storage,
8986 FAST_ELEMENTS, 2);
8987 }
8988
8989 values_or_entries->set(length, *value);
8990 length++;
8991 }
8992 if (length < values_or_entries->length()) values_or_entries->Shrink(length);
8993 return values_or_entries;
8994 }
8995
8996 MaybeHandle<FixedArray> JSReceiver::GetOwnValues(Handle<JSReceiver> object,
8997 PropertyFilter filter) {
8998 return GetOwnValuesOrEntries(object->GetIsolate(), object, filter, false);
8999 }
9000
9001 MaybeHandle<FixedArray> JSReceiver::GetOwnEntries(Handle<JSReceiver> object,
9002 PropertyFilter filter) {
9003 return GetOwnValuesOrEntries(object->GetIsolate(), object, filter, true);
9004 }
8947 9005
8948 bool Map::DictionaryElementsInPrototypeChainOnly() { 9006 bool Map::DictionaryElementsInPrototypeChainOnly() {
8949 if (IsDictionaryElementsKind(elements_kind())) { 9007 if (IsDictionaryElementsKind(elements_kind())) {
8950 return false; 9008 return false;
8951 } 9009 }
8952 9010
8953 for (PrototypeIterator iter(this); !iter.IsAtEnd(); iter.Advance()) { 9011 for (PrototypeIterator iter(this); !iter.IsAtEnd(); iter.Advance()) {
8954 // Be conservative, don't walk into proxies. 9012 // Be conservative, don't walk into proxies.
8955 if (iter.GetCurrent()->IsJSProxy()) return true; 9013 if (iter.GetCurrent()->IsJSProxy()) return true;
8956 // String wrappers have non-configurable, non-writable elements. 9014 // String wrappers have non-configurable, non-writable elements.
(...skipping 10860 matching lines...) Expand 10 before | Expand all | Expand 10 after
19817 if (cell->value() != *new_value) { 19875 if (cell->value() != *new_value) {
19818 cell->set_value(*new_value); 19876 cell->set_value(*new_value);
19819 Isolate* isolate = cell->GetIsolate(); 19877 Isolate* isolate = cell->GetIsolate();
19820 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19878 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19821 isolate, DependentCode::kPropertyCellChangedGroup); 19879 isolate, DependentCode::kPropertyCellChangedGroup);
19822 } 19880 }
19823 } 19881 }
19824 19882
19825 } // namespace internal 19883 } // namespace internal
19826 } // namespace v8 19884 } // namespace v8
OLDNEW
« 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