OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 7779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7790 } else { | 7790 } else { |
7791 if (copying) { | 7791 if (copying) { |
7792 Representation representation = details.representation(); | 7792 Representation representation = details.representation(); |
7793 value = Object::NewStorageFor(isolate, value, representation); | 7793 value = Object::NewStorageFor(isolate, value, representation); |
7794 copy->FastPropertyAtPut(index, *value); | 7794 copy->FastPropertyAtPut(index, *value); |
7795 } | 7795 } |
7796 } | 7796 } |
7797 } | 7797 } |
7798 } | 7798 } |
7799 } else { | 7799 } else { |
7800 Handle<FixedArray> names = | 7800 // Only deep copy fields from the object literal expression. |
7801 isolate->factory()->NewFixedArray(copy->NumberOfOwnProperties()); | 7801 // In particular, don't try to copy the length attribute of |
7802 copy->GetOwnPropertyNames(*names, 0); | 7802 // an array. |
| 7803 PropertyFilter filter = static_cast<PropertyFilter>( |
| 7804 ONLY_WRITABLE | ONLY_ENUMERABLE | ONLY_CONFIGURABLE); |
| 7805 KeyAccumulator accumulator(isolate, filter); |
| 7806 accumulator.NextPrototype(); |
| 7807 copy->CollectOwnPropertyNames(&accumulator, filter); |
| 7808 Handle<FixedArray> names = accumulator.GetKeys(); |
7803 for (int i = 0; i < names->length(); i++) { | 7809 for (int i = 0; i < names->length(); i++) { |
7804 DCHECK(names->get(i)->IsName()); | 7810 DCHECK(names->get(i)->IsName()); |
7805 Handle<Name> name(Name::cast(names->get(i))); | 7811 Handle<Name> name(Name::cast(names->get(i))); |
7806 Maybe<PropertyAttributes> maybe = | |
7807 JSReceiver::GetOwnPropertyAttributes(copy, name); | |
7808 DCHECK(maybe.IsJust()); | |
7809 PropertyAttributes attributes = maybe.FromJust(); | |
7810 // Only deep copy fields from the object literal expression. | |
7811 // In particular, don't try to copy the length attribute of | |
7812 // an array. | |
7813 if (attributes != NONE) continue; | |
7814 Handle<Object> value = | 7812 Handle<Object> value = |
7815 Object::GetProperty(copy, name).ToHandleChecked(); | 7813 Object::GetProperty(copy, name).ToHandleChecked(); |
7816 if (value->IsJSObject()) { | 7814 if (value->IsJSObject()) { |
7817 Handle<JSObject> result; | 7815 Handle<JSObject> result; |
7818 ASSIGN_RETURN_ON_EXCEPTION( | 7816 ASSIGN_RETURN_ON_EXCEPTION( |
7819 isolate, result, | 7817 isolate, result, |
7820 VisitElementOrProperty(copy, Handle<JSObject>::cast(value)), | 7818 VisitElementOrProperty(copy, Handle<JSObject>::cast(value)), |
7821 JSObject); | 7819 JSObject); |
7822 if (copying) { | 7820 if (copying) { |
7823 // Creating object copy for literals. No strict mode needed. | 7821 // Creating object copy for literals. No strict mode needed. |
(...skipping 8010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15834 Maybe<bool> JSObject::HasRealNamedCallbackProperty(Handle<JSObject> object, | 15832 Maybe<bool> JSObject::HasRealNamedCallbackProperty(Handle<JSObject> object, |
15835 Handle<Name> name) { | 15833 Handle<Name> name) { |
15836 LookupIterator it = LookupIterator::PropertyOrElement( | 15834 LookupIterator it = LookupIterator::PropertyOrElement( |
15837 name->GetIsolate(), object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); | 15835 name->GetIsolate(), object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); |
15838 Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it); | 15836 Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it); |
15839 return maybe_result.IsJust() ? Just(it.state() == LookupIterator::ACCESSOR) | 15837 return maybe_result.IsJust() ? Just(it.state() == LookupIterator::ACCESSOR) |
15840 : Nothing<bool>(); | 15838 : Nothing<bool>(); |
15841 } | 15839 } |
15842 | 15840 |
15843 | 15841 |
15844 // Private symbols are always filtered out. | |
15845 int JSObject::NumberOfOwnProperties(PropertyFilter filter) { | |
15846 if (HasFastProperties()) { | |
15847 Map* map = this->map(); | |
15848 if (filter == ENUMERABLE_STRINGS) { | |
15849 // The cached enum length was computed with filter == ENUMERABLE_STRING, | |
15850 // so that's the only filter for which it's valid to retrieve it. | |
15851 int result = map->EnumLength(); | |
15852 if (result != kInvalidEnumCacheSentinel) return result; | |
15853 } | |
15854 return map->NumberOfDescribedProperties(OWN_DESCRIPTORS, filter); | |
15855 } else if (IsJSGlobalObject()) { | |
15856 return global_dictionary()->NumberOfElementsFilterAttributes(filter); | |
15857 } else { | |
15858 return property_dictionary()->NumberOfElementsFilterAttributes(filter); | |
15859 } | |
15860 } | |
15861 | |
15862 | |
15863 void FixedArray::SwapPairs(FixedArray* numbers, int i, int j) { | 15842 void FixedArray::SwapPairs(FixedArray* numbers, int i, int j) { |
15864 Object* temp = get(i); | 15843 Object* temp = get(i); |
15865 set(i, get(j)); | 15844 set(i, get(j)); |
15866 set(j, temp); | 15845 set(j, temp); |
15867 if (this != numbers) { | 15846 if (this != numbers) { |
15868 temp = numbers->get(i); | 15847 temp = numbers->get(i); |
15869 numbers->set(i, Smi::cast(numbers->get(j))); | 15848 numbers->set(i, Smi::cast(numbers->get(j))); |
15870 numbers->set(j, Smi::cast(temp)); | 15849 numbers->set(j, Smi::cast(temp)); |
15871 } | 15850 } |
15872 } | 15851 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15966 SwapPairs(numbers, i, p); | 15945 SwapPairs(numbers, i, p); |
15967 } | 15946 } |
15968 } | 15947 } |
15969 } else { | 15948 } else { |
15970 HeapSortPairs(this, numbers, len); | 15949 HeapSortPairs(this, numbers, len); |
15971 return; | 15950 return; |
15972 } | 15951 } |
15973 } | 15952 } |
15974 | 15953 |
15975 | 15954 |
15976 // Fill in the names of own properties into the supplied storage. The main | |
15977 // purpose of this function is to provide reflection information for the object | |
15978 // mirrors. | |
15979 int JSObject::GetOwnPropertyNames(FixedArray* storage, int index, | |
15980 PropertyFilter filter) { | |
15981 DCHECK(storage->length() >= (NumberOfOwnProperties(filter) - index)); | |
15982 if (HasFastProperties()) { | |
15983 int start_index = index; | |
15984 int real_size = map()->NumberOfOwnDescriptors(); | |
15985 DescriptorArray* descs = map()->instance_descriptors(); | |
15986 for (int i = 0; i < real_size; i++) { | |
15987 if ((descs->GetDetails(i).attributes() & filter) == 0 && | |
15988 !descs->GetKey(i)->FilterKey(filter)) { | |
15989 storage->set(index++, descs->GetKey(i)); | |
15990 } | |
15991 } | |
15992 return index - start_index; | |
15993 } else if (IsJSGlobalObject()) { | |
15994 return global_dictionary()->CopyKeysTo(storage, index, filter, | |
15995 GlobalDictionary::UNSORTED); | |
15996 } else { | |
15997 return property_dictionary()->CopyKeysTo(storage, index, filter, | |
15998 NameDictionary::UNSORTED); | |
15999 } | |
16000 } | |
16001 | |
16002 | |
16003 void JSObject::CollectOwnPropertyNames(KeyAccumulator* keys, | 15955 void JSObject::CollectOwnPropertyNames(KeyAccumulator* keys, |
16004 PropertyFilter filter) { | 15956 PropertyFilter filter) { |
16005 if (HasFastProperties()) { | 15957 if (HasFastProperties()) { |
16006 int real_size = map()->NumberOfOwnDescriptors(); | 15958 int real_size = map()->NumberOfOwnDescriptors(); |
16007 Handle<DescriptorArray> descs(map()->instance_descriptors()); | 15959 Handle<DescriptorArray> descs(map()->instance_descriptors()); |
16008 for (int i = 0; i < real_size; i++) { | 15960 for (int i = 0; i < real_size; i++) { |
16009 PropertyDetails details = descs->GetDetails(i); | 15961 PropertyDetails details = descs->GetDetails(i); |
16010 if ((details.attributes() & filter) != 0) continue; | 15962 if ((details.attributes() & filter) != 0) continue; |
16011 if (filter & ONLY_ALL_CAN_READ) { | 15963 if (filter & ONLY_ALL_CAN_READ) { |
16012 if (details.kind() != kAccessor) continue; | 15964 if (details.kind() != kAccessor) continue; |
(...skipping 3222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19235 if (cell->value() != *new_value) { | 19187 if (cell->value() != *new_value) { |
19236 cell->set_value(*new_value); | 19188 cell->set_value(*new_value); |
19237 Isolate* isolate = cell->GetIsolate(); | 19189 Isolate* isolate = cell->GetIsolate(); |
19238 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19190 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19239 isolate, DependentCode::kPropertyCellChangedGroup); | 19191 isolate, DependentCode::kPropertyCellChangedGroup); |
19240 } | 19192 } |
19241 } | 19193 } |
19242 | 19194 |
19243 } // namespace internal | 19195 } // namespace internal |
19244 } // namespace v8 | 19196 } // namespace v8 |
OLD | NEW |