| 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 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 NewTypeError(MessageTemplate::kProxyGetNonConfigurableAccessor, name, | 829 NewTypeError(MessageTemplate::kProxyGetNonConfigurableAccessor, name, |
| 830 trap_result), | 830 trap_result), |
| 831 Object); | 831 Object); |
| 832 } | 832 } |
| 833 } | 833 } |
| 834 // 11. Return trap_result | 834 // 11. Return trap_result |
| 835 return trap_result; | 835 return trap_result; |
| 836 } | 836 } |
| 837 | 837 |
| 838 | 838 |
| 839 Handle<Object> JSReceiver::GetDataProperty(Handle<JSReceiver> object, | |
| 840 Handle<Name> name) { | |
| 841 LookupIterator it(object, name, | |
| 842 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); | |
| 843 return GetDataProperty(&it); | |
| 844 } | |
| 845 | |
| 846 | |
| 847 Handle<Object> JSReceiver::GetDataProperty(LookupIterator* it) { | 839 Handle<Object> JSReceiver::GetDataProperty(LookupIterator* it) { |
| 848 for (; it->IsFound(); it->Next()) { | 840 for (; it->IsFound(); it->Next()) { |
| 849 switch (it->state()) { | 841 switch (it->state()) { |
| 850 case LookupIterator::INTERCEPTOR: | 842 case LookupIterator::INTERCEPTOR: |
| 851 case LookupIterator::NOT_FOUND: | 843 case LookupIterator::NOT_FOUND: |
| 852 case LookupIterator::TRANSITION: | 844 case LookupIterator::TRANSITION: |
| 853 UNREACHABLE(); | 845 UNREACHABLE(); |
| 854 case LookupIterator::ACCESS_CHECK: | 846 case LookupIterator::ACCESS_CHECK: |
| 855 // Support calling this method without an active context, but refuse | 847 // Support calling this method without an active context, but refuse |
| 856 // access to access-checked objects in that case. | 848 // access to access-checked objects in that case. |
| (...skipping 4992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5849 // within a smi. | 5841 // within a smi. |
| 5850 hash_value = isolate->random_number_generator()->NextInt() & Smi::kMaxValue; | 5842 hash_value = isolate->random_number_generator()->NextInt() & Smi::kMaxValue; |
| 5851 attempts++; | 5843 attempts++; |
| 5852 } while (hash_value == 0 && attempts < 30); | 5844 } while (hash_value == 0 && attempts < 30); |
| 5853 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 | 5845 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 |
| 5854 | 5846 |
| 5855 return Smi::FromInt(hash_value); | 5847 return Smi::FromInt(hash_value); |
| 5856 } | 5848 } |
| 5857 | 5849 |
| 5858 | 5850 |
| 5859 void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) { | |
| 5860 DCHECK(!object->IsJSGlobalProxy()); | |
| 5861 Isolate* isolate = object->GetIsolate(); | |
| 5862 Handle<Name> hash_code_symbol = isolate->factory()->hash_code_symbol(); | |
| 5863 JSObject::AddProperty(object, hash_code_symbol, hash, NONE); | |
| 5864 } | |
| 5865 | |
| 5866 | |
| 5867 template<typename ProxyType> | 5851 template<typename ProxyType> |
| 5868 static Handle<Smi> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) { | 5852 static Handle<Smi> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) { |
| 5869 Isolate* isolate = proxy->GetIsolate(); | 5853 Isolate* isolate = proxy->GetIsolate(); |
| 5870 | 5854 |
| 5871 Handle<Object> maybe_hash(proxy->hash(), isolate); | 5855 Handle<Object> maybe_hash(proxy->hash(), isolate); |
| 5872 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); | 5856 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); |
| 5873 | 5857 |
| 5874 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); | 5858 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); |
| 5875 proxy->set_hash(*hash); | 5859 proxy->set_hash(*hash); |
| 5876 return hash; | 5860 return hash; |
| 5877 } | 5861 } |
| 5878 | 5862 |
| 5879 // static | 5863 // static |
| 5880 Handle<Object> JSObject::GetIdentityHash(Isolate* isolate, | 5864 Handle<Object> JSObject::GetIdentityHash(Isolate* isolate, |
| 5881 Handle<JSObject> object) { | 5865 Handle<JSObject> object) { |
| 5882 if (object->IsJSGlobalProxy()) { | 5866 if (object->IsJSGlobalProxy()) { |
| 5883 return handle(JSGlobalProxy::cast(*object)->hash(), isolate); | 5867 return handle(JSGlobalProxy::cast(*object)->hash(), isolate); |
| 5884 } | 5868 } |
| 5885 Handle<Name> hash_code_symbol = isolate->factory()->hash_code_symbol(); | 5869 Handle<Name> hash_code_symbol = isolate->factory()->hash_code_symbol(); |
| 5886 return JSReceiver::GetDataProperty(object, hash_code_symbol); | 5870 return JSReceiver::GetDataProperty(object, hash_code_symbol); |
| 5887 } | 5871 } |
| 5888 | 5872 |
| 5889 // static | 5873 // static |
| 5890 Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { | 5874 Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { |
| 5891 if (object->IsJSGlobalProxy()) { | 5875 if (object->IsJSGlobalProxy()) { |
| 5892 return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object)); | 5876 return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object)); |
| 5893 } | 5877 } |
| 5894 Isolate* isolate = object->GetIsolate(); | 5878 Isolate* isolate = object->GetIsolate(); |
| 5895 | 5879 |
| 5896 Handle<Object> maybe_hash = JSObject::GetIdentityHash(isolate, object); | 5880 Handle<Name> hash_code_symbol = isolate->factory()->hash_code_symbol(); |
| 5897 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); | 5881 LookupIterator it(object, hash_code_symbol, LookupIterator::OWN); |
| 5882 if (it.IsFound()) { |
| 5883 DCHECK_EQ(LookupIterator::DATA, it.state()); |
| 5884 Handle<Object> maybe_hash = it.GetDataValue(); |
| 5885 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); |
| 5886 } |
| 5898 | 5887 |
| 5899 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); | 5888 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); |
| 5900 SetIdentityHash(object, hash); | 5889 CHECK(AddDataProperty(&it, hash, NONE, THROW_ON_ERROR, |
| 5890 CERTAINLY_NOT_STORE_FROM_KEYED) |
| 5891 .IsJust()); |
| 5901 return hash; | 5892 return hash; |
| 5902 } | 5893 } |
| 5903 | 5894 |
| 5904 // static | 5895 // static |
| 5905 Handle<Object> JSProxy::GetIdentityHash(Isolate* isolate, | 5896 Handle<Object> JSProxy::GetIdentityHash(Isolate* isolate, |
| 5906 Handle<JSProxy> proxy) { | 5897 Handle<JSProxy> proxy) { |
| 5907 return handle(proxy->hash(), isolate); | 5898 return handle(proxy->hash(), isolate); |
| 5908 } | 5899 } |
| 5909 | 5900 |
| 5910 | 5901 |
| (...skipping 13855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19766 if (cell->value() != *new_value) { | 19757 if (cell->value() != *new_value) { |
| 19767 cell->set_value(*new_value); | 19758 cell->set_value(*new_value); |
| 19768 Isolate* isolate = cell->GetIsolate(); | 19759 Isolate* isolate = cell->GetIsolate(); |
| 19769 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19760 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 19770 isolate, DependentCode::kPropertyCellChangedGroup); | 19761 isolate, DependentCode::kPropertyCellChangedGroup); |
| 19771 } | 19762 } |
| 19772 } | 19763 } |
| 19773 | 19764 |
| 19774 } // namespace internal | 19765 } // namespace internal |
| 19775 } // namespace v8 | 19766 } // namespace v8 |
| OLD | NEW |