Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 6089558f78177ffb080cd41e98ec255c0a3a6f1c..d25569708180f31070aefb987799154667a0f1c8 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -5068,9 +5068,7 @@ Handle<SeededNumberDictionary> JSObject::NormalizeElements( |
} |
-Smi* JSReceiver::GenerateIdentityHash() { |
- Isolate* isolate = GetIsolate(); |
- |
+static Smi* GenerateIdentityHash(Isolate* isolate) { |
int hash_value; |
int attempts = 0; |
do { |
@@ -5086,14 +5084,31 @@ Smi* JSReceiver::GenerateIdentityHash() { |
void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) { |
+ ASSERT(!object->IsJSGlobalProxy()); |
Isolate* isolate = object->GetIsolate(); |
SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash); |
} |
+template<typename ProxyType> |
+static Handle<Object> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) { |
+ Isolate* isolate = proxy->GetIsolate(); |
+ |
+ Handle<Object> hash(proxy->hash(), isolate); |
+ if (hash->IsSmi()) return hash; |
+ |
+ hash = handle(GenerateIdentityHash(isolate), isolate); |
+ proxy->set_hash(*hash); |
+ return hash; |
+} |
+ |
+ |
Object* JSObject::GetIdentityHash() { |
DisallowHeapAllocation no_gc; |
Isolate* isolate = GetIsolate(); |
+ if (IsJSGlobalProxy()) { |
+ return JSGlobalProxy::cast(this)->hash(); |
+ } |
Object* stored_value = |
GetHiddenProperty(isolate->factory()->identity_hash_string()); |
return stored_value->IsSmi() |
@@ -5103,21 +5118,17 @@ Object* JSObject::GetIdentityHash() { |
Handle<Object> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { |
- Handle<Object> hash(object->GetIdentityHash(), object->GetIsolate()); |
- if (hash->IsSmi()) |
- return hash; |
+ if (object->IsJSGlobalProxy()) { |
+ return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object)); |
+ } |
Isolate* isolate = object->GetIsolate(); |
- hash = handle(object->GenerateIdentityHash(), isolate); |
- Handle<Object> result = SetHiddenProperty(object, |
- isolate->factory()->identity_hash_string(), hash); |
- |
- if (result->IsUndefined()) { |
- // Trying to get hash of detached proxy. |
- return handle(Smi::FromInt(0), isolate); |
- } |
+ Handle<Object> hash(object->GetIdentityHash(), isolate); |
+ if (hash->IsSmi()) return hash; |
+ hash = handle(GenerateIdentityHash(isolate), isolate); |
+ SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash); |
return hash; |
} |
@@ -5128,15 +5139,7 @@ Object* JSProxy::GetIdentityHash() { |
Handle<Object> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) { |
- Isolate* isolate = proxy->GetIsolate(); |
- |
- Handle<Object> hash(proxy->GetIdentityHash(), isolate); |
- if (hash->IsSmi()) |
- return hash; |
- |
- hash = handle(proxy->GenerateIdentityHash(), isolate); |
- proxy->set_hash(*hash); |
- return hash; |
+ return GetOrCreateIdentityHashHelper(proxy); |
} |
@@ -5144,6 +5147,8 @@ Object* JSObject::GetHiddenProperty(Handle<Name> key) { |
DisallowHeapAllocation no_gc; |
ASSERT(key->IsUniqueName()); |
if (IsJSGlobalProxy()) { |
+ // JSGlobalProxies store their hash internally. |
+ ASSERT(*key != GetHeap()->identity_hash_string()); |
// For a proxy, use the prototype as target object. |
Object* proxy_parent = GetPrototype(); |
// If the proxy is detached, return undefined. |
@@ -5178,6 +5183,8 @@ Handle<Object> JSObject::SetHiddenProperty(Handle<JSObject> object, |
ASSERT(key->IsUniqueName()); |
if (object->IsJSGlobalProxy()) { |
+ // JSGlobalProxies store their hash internally. |
+ ASSERT(*key != *isolate->factory()->identity_hash_string()); |
// For a proxy, use the prototype as target object. |
Handle<Object> proxy_parent(object->GetPrototype(), isolate); |
// If the proxy is detached, return undefined. |