| 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 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 return constructor_function->initial_map(); | 1394 return constructor_function->initial_map(); |
| 1395 } | 1395 } |
| 1396 return isolate->heap()->null_value()->map(); | 1396 return isolate->heap()->null_value()->map(); |
| 1397 } | 1397 } |
| 1398 | 1398 |
| 1399 | 1399 |
| 1400 Object* Object::GetHash() { | 1400 Object* Object::GetHash() { |
| 1401 Object* hash = GetSimpleHash(); | 1401 Object* hash = GetSimpleHash(); |
| 1402 if (hash->IsSmi()) return hash; | 1402 if (hash->IsSmi()) return hash; |
| 1403 | 1403 |
| 1404 DisallowHeapAllocation no_gc; |
| 1404 DCHECK(IsJSReceiver()); | 1405 DCHECK(IsJSReceiver()); |
| 1405 return JSReceiver::cast(this)->GetIdentityHash(); | 1406 JSReceiver* receiver = JSReceiver::cast(this); |
| 1407 Isolate* isolate = receiver->GetIsolate(); |
| 1408 return *JSReceiver::GetIdentityHash(isolate, handle(receiver, isolate)); |
| 1406 } | 1409 } |
| 1407 | 1410 |
| 1408 | 1411 |
| 1409 Object* Object::GetSimpleHash() { | 1412 Object* Object::GetSimpleHash() { |
| 1410 // The object is either a Smi, a HeapNumber, a name, an odd-ball, | 1413 // The object is either a Smi, a HeapNumber, a name, an odd-ball, |
| 1411 // a SIMD value type, a real JS object, or a Harmony proxy. | 1414 // a SIMD value type, a real JS object, or a Harmony proxy. |
| 1412 if (IsSmi()) { | 1415 if (IsSmi()) { |
| 1413 uint32_t hash = ComputeIntegerHash(Smi::cast(this)->value(), kZeroHashSeed); | 1416 uint32_t hash = ComputeIntegerHash(Smi::cast(this)->value(), kZeroHashSeed); |
| 1414 return Smi::FromInt(hash & Smi::kMaxValue); | 1417 return Smi::FromInt(hash & Smi::kMaxValue); |
| 1415 } | 1418 } |
| (...skipping 4432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5848 } while (hash_value == 0 && attempts < 30); | 5851 } while (hash_value == 0 && attempts < 30); |
| 5849 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 | 5852 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 |
| 5850 | 5853 |
| 5851 return Smi::FromInt(hash_value); | 5854 return Smi::FromInt(hash_value); |
| 5852 } | 5855 } |
| 5853 | 5856 |
| 5854 | 5857 |
| 5855 void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) { | 5858 void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) { |
| 5856 DCHECK(!object->IsJSGlobalProxy()); | 5859 DCHECK(!object->IsJSGlobalProxy()); |
| 5857 Isolate* isolate = object->GetIsolate(); | 5860 Isolate* isolate = object->GetIsolate(); |
| 5858 Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol()); | 5861 Handle<Name> hash_code_symbol = isolate->factory()->hash_code_symbol(); |
| 5859 JSObject::AddProperty(object, hash_code_symbol, hash, NONE); | 5862 JSObject::AddProperty(object, hash_code_symbol, hash, NONE); |
| 5860 } | 5863 } |
| 5861 | 5864 |
| 5862 | 5865 |
| 5863 template<typename ProxyType> | 5866 template<typename ProxyType> |
| 5864 static Handle<Smi> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) { | 5867 static Handle<Smi> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) { |
| 5865 Isolate* isolate = proxy->GetIsolate(); | 5868 Isolate* isolate = proxy->GetIsolate(); |
| 5866 | 5869 |
| 5867 Handle<Object> maybe_hash(proxy->hash(), isolate); | 5870 Handle<Object> maybe_hash(proxy->hash(), isolate); |
| 5868 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); | 5871 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); |
| 5869 | 5872 |
| 5870 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); | 5873 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); |
| 5871 proxy->set_hash(*hash); | 5874 proxy->set_hash(*hash); |
| 5872 return hash; | 5875 return hash; |
| 5873 } | 5876 } |
| 5874 | 5877 |
| 5875 | 5878 // static |
| 5876 Object* JSObject::GetIdentityHash() { | 5879 Handle<Object> JSObject::GetIdentityHash(Isolate* isolate, |
| 5877 DisallowHeapAllocation no_gc; | 5880 Handle<JSObject> object) { |
| 5878 Isolate* isolate = GetIsolate(); | 5881 if (object->IsJSGlobalProxy()) { |
| 5879 if (IsJSGlobalProxy()) { | 5882 return handle(JSGlobalProxy::cast(*object)->hash(), isolate); |
| 5880 return JSGlobalProxy::cast(this)->hash(); | |
| 5881 } | 5883 } |
| 5882 Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol()); | 5884 Handle<Name> hash_code_symbol = isolate->factory()->hash_code_symbol(); |
| 5883 Handle<Object> stored_value = | 5885 return JSReceiver::GetDataProperty(object, hash_code_symbol); |
| 5884 Object::GetPropertyOrElement(Handle<Object>(this, isolate), | |
| 5885 hash_code_symbol).ToHandleChecked(); | |
| 5886 return stored_value->IsSmi() ? *stored_value | |
| 5887 : isolate->heap()->undefined_value(); | |
| 5888 } | 5886 } |
| 5889 | 5887 |
| 5890 | 5888 // static |
| 5891 Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { | 5889 Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { |
| 5892 if (object->IsJSGlobalProxy()) { | 5890 if (object->IsJSGlobalProxy()) { |
| 5893 return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object)); | 5891 return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object)); |
| 5894 } | 5892 } |
| 5895 Isolate* isolate = object->GetIsolate(); | 5893 Isolate* isolate = object->GetIsolate(); |
| 5896 | 5894 |
| 5897 Handle<Object> maybe_hash(object->GetIdentityHash(), isolate); | 5895 Handle<Object> maybe_hash = JSObject::GetIdentityHash(isolate, object); |
| 5898 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); | 5896 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); |
| 5899 | 5897 |
| 5900 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); | 5898 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); |
| 5901 Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol()); | 5899 SetIdentityHash(object, hash); |
| 5902 JSObject::AddProperty(object, hash_code_symbol, hash, NONE); | |
| 5903 return hash; | 5900 return hash; |
| 5904 } | 5901 } |
| 5905 | 5902 |
| 5906 | 5903 // static |
| 5907 Object* JSProxy::GetIdentityHash() { | 5904 Handle<Object> JSProxy::GetIdentityHash(Isolate* isolate, |
| 5908 return this->hash(); | 5905 Handle<JSProxy> proxy) { |
| 5906 return handle(proxy->hash(), isolate); |
| 5909 } | 5907 } |
| 5910 | 5908 |
| 5911 | 5909 |
| 5912 Handle<Smi> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) { | 5910 Handle<Smi> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) { |
| 5913 return GetOrCreateIdentityHashHelper(proxy); | 5911 return GetOrCreateIdentityHashHelper(proxy); |
| 5914 } | 5912 } |
| 5915 | 5913 |
| 5916 | 5914 |
| 5917 Object* JSObject::GetHiddenProperty(Handle<Name> key) { | 5915 Object* JSObject::GetHiddenProperty(Handle<Name> key) { |
| 5918 DisallowHeapAllocation no_gc; | 5916 DisallowHeapAllocation no_gc; |
| (...skipping 13848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19767 if (cell->value() != *new_value) { | 19765 if (cell->value() != *new_value) { |
| 19768 cell->set_value(*new_value); | 19766 cell->set_value(*new_value); |
| 19769 Isolate* isolate = cell->GetIsolate(); | 19767 Isolate* isolate = cell->GetIsolate(); |
| 19770 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19768 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 19771 isolate, DependentCode::kPropertyCellChangedGroup); | 19769 isolate, DependentCode::kPropertyCellChangedGroup); |
| 19772 } | 19770 } |
| 19773 } | 19771 } |
| 19774 | 19772 |
| 19775 } // namespace internal | 19773 } // namespace internal |
| 19776 } // namespace v8 | 19774 } // namespace v8 |
| OLD | NEW |