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 8758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8769 Isolate* isolate = object->GetIsolate(); | 8769 Isolate* isolate = object->GetIsolate(); |
| 8770 KeyAccumulator accumulator(isolate, type, filter); | 8770 KeyAccumulator accumulator(isolate, type, filter); |
| 8771 MAYBE_RETURN( | 8771 MAYBE_RETURN( |
| 8772 GetKeys_Internal(isolate, object, object, type, filter, &accumulator), | 8772 GetKeys_Internal(isolate, object, object, type, filter, &accumulator), |
| 8773 MaybeHandle<FixedArray>()); | 8773 MaybeHandle<FixedArray>()); |
| 8774 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion); | 8774 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion); |
| 8775 DCHECK(ContainsOnlyValidKeys(keys)); | 8775 DCHECK(ContainsOnlyValidKeys(keys)); |
| 8776 return keys; | 8776 return keys; |
| 8777 } | 8777 } |
| 8778 | 8778 |
| 8779 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries( | |
| 8780 Isolate* isolate, Handle<JSObject> object, bool get_entries, | |
| 8781 Handle<FixedArray>* result) { | |
| 8782 Handle<Map> map(JSReceiver::cast(*object)->map(), isolate); | |
| 8783 | |
| 8784 if (!map->IsJSObjectMap()) return Just(false); | |
| 8785 if (!map->OnlyHasSimpleProperties()) return Just(false); | |
| 8786 | |
| 8787 if (object->elements() != isolate->heap()->empty_fixed_array()) { | |
| 8788 return Just(false); | |
| 8789 } | |
| 8790 | |
| 8791 Handle<DescriptorArray> descriptors(map->instance_descriptors(), isolate); | |
| 8792 int length = map->NumberOfOwnDescriptors(); | |
| 8793 int elements_length = object->NumberOfOwnElements(ENUMERABLE_STRINGS); | |
| 8794 Handle<FixedArray> values_or_entries = | |
| 8795 isolate->factory()->NewFixedArray(length + elements_length); | |
| 8796 int count = 0; | |
| 8797 | |
| 8798 bool stable = true; | |
| 8799 | |
| 8800 for (int index = 0; index < length; index++) { | |
| 8801 Handle<Name> next_key(descriptors->GetKey(index), isolate); | |
| 8802 if (!next_key->IsString()) continue; | |
| 8803 Handle<Object> prop_value; | |
| 8804 | |
| 8805 // Directly decode from the descriptor array if |from| did not change shape. | |
| 8806 if (stable) { | |
| 8807 PropertyDetails details = descriptors->GetDetails(index); | |
| 8808 if (!details.IsEnumerable()) continue; | |
| 8809 if (details.kind() == kData) { | |
| 8810 if (details.location() == kDescriptor) { | |
| 8811 prop_value = handle(descriptors->GetValue(index), isolate); | |
| 8812 } else { | |
| 8813 Representation representation = details.representation(); | |
| 8814 FieldIndex field_index = FieldIndex::ForDescriptor(*map, index); | |
| 8815 prop_value = | |
| 8816 JSObject::FastPropertyAt(object, representation, field_index); | |
| 8817 } | |
| 8818 } else { | |
| 8819 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, prop_value, | |
| 8820 Object::GetProperty(object, next_key), | |
| 8821 Nothing<bool>()); | |
| 8822 stable = object->map() == *map; | |
| 8823 } | |
| 8824 } else { | |
| 8825 // If the map did change, do a slower lookup. We are still guaranteed that | |
| 8826 // the object has a simple shape, and that the key is a name. | |
| 8827 LookupIterator it(object, next_key, LookupIterator::OWN_SKIP_INTERCEPTOR); | |
| 8828 if (!it.IsFound()) continue; | |
| 8829 DCHECK(it.state() == LookupIterator::DATA || | |
| 8830 it.state() == LookupIterator::ACCESSOR); | |
| 8831 if (!it.IsEnumerable()) continue; | |
| 8832 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
| 8833 isolate, prop_value, Object::GetProperty(&it), Nothing<bool>()); | |
| 8834 } | |
| 8835 | |
| 8836 if (get_entries) { | |
| 8837 Handle<FixedArray> entry_storage = | |
| 8838 isolate->factory()->NewUninitializedFixedArray(2); | |
| 8839 entry_storage->set(0, *next_key); | |
| 8840 entry_storage->set(1, *prop_value); | |
| 8841 prop_value = isolate->factory()->NewJSArrayWithElements(entry_storage, | |
| 8842 FAST_ELEMENTS, 2); | |
| 8843 } | |
| 8844 | |
| 8845 values_or_entries->set(count, *prop_value); | |
| 8846 count++; | |
| 8847 } | |
| 8848 | |
| 8849 if (count < values_or_entries->length()) values_or_entries->Shrink(count); | |
| 8850 *result = values_or_entries; | |
| 8851 return Just(true); | |
| 8852 } | |
| 8853 | |
| 8779 MaybeHandle<FixedArray> GetOwnValuesOrEntries(Isolate* isolate, | 8854 MaybeHandle<FixedArray> GetOwnValuesOrEntries(Isolate* isolate, |
| 8780 Handle<JSReceiver> object, | 8855 Handle<JSReceiver> object, |
| 8781 PropertyFilter filter, | 8856 PropertyFilter filter, |
| 8782 bool get_entries) { | 8857 bool get_entries) { |
| 8858 Handle<FixedArray> values_or_entries; | |
| 8859 if (filter == ENUMERABLE_STRINGS && object->IsJSObject()) { | |
|
Toon Verwaest
2016/03/07 22:39:34
You don't need object->IsJSObject since that's alr
| |
| 8860 Maybe<bool> fast_values_or_entries = | |
| 8861 FastGetOwnValuesOrEntries(isolate, Handle<JSObject>::cast(object), | |
| 8862 get_entries, &values_or_entries); | |
| 8863 if (fast_values_or_entries.IsNothing()) return MaybeHandle<FixedArray>(); | |
| 8864 if (fast_values_or_entries.FromJust()) return values_or_entries; | |
| 8865 } | |
| 8866 | |
| 8783 PropertyFilter key_filter = | 8867 PropertyFilter key_filter = |
| 8784 static_cast<PropertyFilter>(filter & ~ONLY_ENUMERABLE); | 8868 static_cast<PropertyFilter>(filter & ~ONLY_ENUMERABLE); |
| 8785 KeyAccumulator accumulator(isolate, OWN_ONLY, key_filter); | 8869 KeyAccumulator accumulator(isolate, OWN_ONLY, key_filter); |
| 8786 MAYBE_RETURN(GetKeys_Internal(isolate, object, object, OWN_ONLY, key_filter, | 8870 MAYBE_RETURN(GetKeys_Internal(isolate, object, object, OWN_ONLY, key_filter, |
| 8787 &accumulator), | 8871 &accumulator), |
| 8788 MaybeHandle<FixedArray>()); | 8872 MaybeHandle<FixedArray>()); |
| 8789 Handle<FixedArray> keys = accumulator.GetKeys(CONVERT_TO_STRING); | 8873 Handle<FixedArray> keys = accumulator.GetKeys(CONVERT_TO_STRING); |
| 8790 DCHECK(ContainsOnlyValidKeys(keys)); | 8874 DCHECK(ContainsOnlyValidKeys(keys)); |
| 8791 | 8875 |
| 8792 Handle<FixedArray> values_or_entries = | 8876 values_or_entries = isolate->factory()->NewFixedArray(keys->length()); |
| 8793 isolate->factory()->NewFixedArray(keys->length()); | |
| 8794 int length = 0; | 8877 int length = 0; |
| 8795 | 8878 |
| 8796 for (int i = 0; i < keys->length(); ++i) { | 8879 for (int i = 0; i < keys->length(); ++i) { |
| 8797 Handle<Name> key = Handle<Name>::cast(handle(keys->get(i), isolate)); | 8880 Handle<Name> key = Handle<Name>::cast(handle(keys->get(i), isolate)); |
| 8798 | 8881 |
| 8799 if (filter & ONLY_ENUMERABLE) { | 8882 if (filter & ONLY_ENUMERABLE) { |
| 8800 PropertyDescriptor descriptor; | 8883 PropertyDescriptor descriptor; |
| 8801 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor( | 8884 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor( |
| 8802 isolate, object, key, &descriptor); | 8885 isolate, object, key, &descriptor); |
| 8803 MAYBE_RETURN(did_get_descriptor, MaybeHandle<FixedArray>()); | 8886 MAYBE_RETURN(did_get_descriptor, MaybeHandle<FixedArray>()); |
| (...skipping 10952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 19756 if (cell->value() != *new_value) { | 19839 if (cell->value() != *new_value) { |
| 19757 cell->set_value(*new_value); | 19840 cell->set_value(*new_value); |
| 19758 Isolate* isolate = cell->GetIsolate(); | 19841 Isolate* isolate = cell->GetIsolate(); |
| 19759 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19842 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 19760 isolate, DependentCode::kPropertyCellChangedGroup); | 19843 isolate, DependentCode::kPropertyCellChangedGroup); |
| 19761 } | 19844 } |
| 19762 } | 19845 } |
| 19763 | 19846 |
| 19764 } // namespace internal | 19847 } // namespace internal |
| 19765 } // namespace v8 | 19848 } // namespace v8 |
| OLD | NEW |