Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 8817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8828 Isolate* isolate = object->GetIsolate(); | 8828 Isolate* isolate = object->GetIsolate(); |
| 8829 KeyAccumulator accumulator(isolate, type, filter); | 8829 KeyAccumulator accumulator(isolate, type, filter); |
| 8830 MAYBE_RETURN( | 8830 MAYBE_RETURN( |
| 8831 GetKeys_Internal(isolate, object, object, type, filter, &accumulator), | 8831 GetKeys_Internal(isolate, object, object, type, filter, &accumulator), |
| 8832 MaybeHandle<FixedArray>()); | 8832 MaybeHandle<FixedArray>()); |
| 8833 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion); | 8833 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion); |
| 8834 DCHECK(ContainsOnlyValidKeys(keys)); | 8834 DCHECK(ContainsOnlyValidKeys(keys)); |
| 8835 return keys; | 8835 return keys; |
| 8836 } | 8836 } |
| 8837 | 8837 |
| 8838 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries( | |
| 8839 Isolate* isolate, Handle<JSObject> object, bool get_entries, | |
| 8840 Handle<FixedArray>* result) { | |
| 8841 Handle<Map> map(JSReceiver::cast(*object)->map(), isolate); | |
| 8842 | |
| 8843 if (!map->IsJSObjectMap()) return Just(false); | |
| 8844 if (!map->OnlyHasSimpleProperties()) return Just(false); | |
| 8845 | |
| 8846 if (object->elements() != isolate->heap()->empty_fixed_array()) { | |
| 8847 return Just(false); | |
| 8848 } | |
| 8849 | |
| 8850 Handle<DescriptorArray> descriptors(map->instance_descriptors(), isolate); | |
| 8851 int length = map->NumberOfOwnDescriptors(); | |
|
Camillo Bruni
2016/03/04 09:40:25
nit: rename to nof_own_descriptors
| |
| 8852 Handle<FixedArray> values_or_entries = | |
| 8853 isolate->factory()->NewFixedArray(length); | |
| 8854 int elements = 0; | |
| 8855 | |
| 8856 bool stable = true; | |
| 8857 | |
| 8858 for (int i = 0; i < length; i++) { | |
| 8859 Handle<Name> next_key(descriptors->GetKey(i), isolate); | |
| 8860 Handle<Object> prop_value; | |
|
Camillo Bruni
2016/03/04 09:40:25
Have you tried to be dirty an use a pointer here i
caitp (gmail)
2016/03/04 14:03:03
Doesn't the "if (get_entries)" block on line 8892
| |
| 8861 | |
| 8862 // Directly decode from the descriptor array if |from| did not change shape. | |
| 8863 if (stable) { | |
| 8864 PropertyDetails details = descriptors->GetDetails(i); | |
| 8865 if (!details.IsEnumerable()) continue; | |
| 8866 if (details.kind() == kData) { | |
| 8867 if (details.location() == kDescriptor) { | |
| 8868 prop_value = handle(descriptors->GetValue(i), isolate); | |
| 8869 } else { | |
| 8870 Representation representation = details.representation(); | |
| 8871 FieldIndex index = FieldIndex::ForDescriptor(*map, i); | |
| 8872 prop_value = JSObject::FastPropertyAt(object, representation, index); | |
| 8873 } | |
| 8874 } else { | |
| 8875 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, prop_value, | |
| 8876 Object::GetProperty(object, next_key), | |
| 8877 Nothing<bool>()); | |
| 8878 stable = object->map() == *map; | |
| 8879 } | |
| 8880 } else { | |
| 8881 // If the map did change, do a slower lookup. We are still guaranteed that | |
| 8882 // the object has a simple shape, and that the key is a name. | |
| 8883 LookupIterator it(object, next_key, LookupIterator::OWN_SKIP_INTERCEPTOR); | |
| 8884 if (!it.IsFound()) continue; | |
| 8885 DCHECK(it.state() == LookupIterator::DATA || | |
| 8886 it.state() == LookupIterator::ACCESSOR); | |
| 8887 if (!it.IsEnumerable()) continue; | |
| 8888 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
| 8889 isolate, prop_value, Object::GetProperty(&it), Nothing<bool>()); | |
| 8890 } | |
| 8891 | |
| 8892 if (get_entries) { | |
| 8893 Handle<FixedArray> entry_storage = | |
| 8894 isolate->factory()->NewUninitializedFixedArray(2); | |
| 8895 entry_storage->set(0, *next_key); | |
| 8896 entry_storage->set(1, *prop_value); | |
| 8897 prop_value = isolate->factory()->NewJSArrayWithElements(entry_storage, | |
| 8898 FAST_ELEMENTS, 2); | |
| 8899 } | |
| 8900 | |
| 8901 values_or_entries->set(elements, *prop_value); | |
| 8902 elements++; | |
| 8903 } | |
| 8904 | |
| 8905 *result = values_or_entries; | |
| 8906 return Just(true); | |
| 8907 } | |
| 8908 | |
| 8838 MaybeHandle<FixedArray> GetOwnValuesOrEntries(Isolate* isolate, | 8909 MaybeHandle<FixedArray> GetOwnValuesOrEntries(Isolate* isolate, |
| 8839 Handle<JSReceiver> object, | 8910 Handle<JSReceiver> object, |
| 8840 PropertyFilter filter, | 8911 PropertyFilter filter, |
| 8841 bool get_entries) { | 8912 bool get_entries) { |
| 8913 Handle<FixedArray> values_or_entries; | |
| 8914 if (filter == ENUMERABLE_STRINGS && object->IsJSObject()) { | |
| 8915 Maybe<bool> fast_values_or_entries = | |
| 8916 FastGetOwnValuesOrEntries(isolate, Handle<JSObject>::cast(object), | |
| 8917 get_entries, &values_or_entries); | |
| 8918 if (fast_values_or_entries.IsNothing()) return MaybeHandle<FixedArray>(); | |
| 8919 if (fast_values_or_entries.FromJust()) return values_or_entries; | |
| 8920 } | |
| 8921 | |
| 8842 PropertyFilter key_filter = | 8922 PropertyFilter key_filter = |
| 8843 static_cast<PropertyFilter>(filter & ~ONLY_ENUMERABLE); | 8923 static_cast<PropertyFilter>(filter & ~ONLY_ENUMERABLE); |
| 8844 KeyAccumulator accumulator(isolate, OWN_ONLY, key_filter); | 8924 KeyAccumulator accumulator(isolate, OWN_ONLY, key_filter); |
| 8845 MAYBE_RETURN(GetKeys_Internal(isolate, object, object, OWN_ONLY, key_filter, | 8925 MAYBE_RETURN(GetKeys_Internal(isolate, object, object, OWN_ONLY, key_filter, |
| 8846 &accumulator), | 8926 &accumulator), |
| 8847 MaybeHandle<FixedArray>()); | 8927 MaybeHandle<FixedArray>()); |
| 8848 Handle<FixedArray> keys = accumulator.GetKeys(CONVERT_TO_STRING); | 8928 Handle<FixedArray> keys = accumulator.GetKeys(CONVERT_TO_STRING); |
| 8849 DCHECK(ContainsOnlyValidKeys(keys)); | 8929 DCHECK(ContainsOnlyValidKeys(keys)); |
| 8850 | 8930 |
| 8851 Handle<FixedArray> values_or_entries = | 8931 values_or_entries = isolate->factory()->NewFixedArray(keys->length()); |
| 8852 isolate->factory()->NewFixedArray(keys->length()); | |
| 8853 int length = 0; | 8932 int length = 0; |
| 8854 | 8933 |
| 8855 for (int i = 0; i < keys->length(); ++i) { | 8934 for (int i = 0; i < keys->length(); ++i) { |
| 8856 Handle<Name> key = Handle<Name>::cast(handle(keys->get(i), isolate)); | 8935 Handle<Name> key = Handle<Name>::cast(handle(keys->get(i), isolate)); |
| 8857 | 8936 |
| 8858 if (filter & ONLY_ENUMERABLE) { | 8937 if (filter & ONLY_ENUMERABLE) { |
| 8859 PropertyDescriptor descriptor; | 8938 PropertyDescriptor descriptor; |
| 8860 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor( | 8939 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor( |
| 8861 isolate, object, key, &descriptor); | 8940 isolate, object, key, &descriptor); |
| 8862 MAYBE_RETURN(did_get_descriptor, MaybeHandle<FixedArray>()); | 8941 MAYBE_RETURN(did_get_descriptor, MaybeHandle<FixedArray>()); |
| (...skipping 10961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 19824 if (cell->value() != *new_value) { | 19903 if (cell->value() != *new_value) { |
| 19825 cell->set_value(*new_value); | 19904 cell->set_value(*new_value); |
| 19826 Isolate* isolate = cell->GetIsolate(); | 19905 Isolate* isolate = cell->GetIsolate(); |
| 19827 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19906 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 19828 isolate, DependentCode::kPropertyCellChangedGroup); | 19907 isolate, DependentCode::kPropertyCellChangedGroup); |
| 19829 } | 19908 } |
| 19830 } | 19909 } |
| 19831 | 19910 |
| 19832 } // namespace internal | 19911 } // namespace internal |
| 19833 } // namespace v8 | 19912 } // namespace v8 |
| OLD | NEW |