From: adamk@chromium.org Date: Fri, 9 May 2014 18:31:08 +0000 (+0000) Subject: Clean up hash creation code to use Handle where possible X-Git-Tag: upstream/4.7.83~9180 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=97dd64091b44984048826962aa1d1f7d6aa5491c;p=platform%2Fupstream%2Fv8.git Clean up hash creation code to use Handle where possible Also remove apparently-bogus TODO and reorder arguments in Object::GetOrCreateHash to put Isolate first (as seems to be the custom). R=verwaest@chromium.org Review URL: https://codereview.chromium.org/268063005 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21246 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/api.cc b/src/api.cc index db52d43..931549a 100644 --- a/src/api.cc +++ b/src/api.cc @@ -3584,8 +3584,7 @@ int v8::Object::GetIdentityHash() { ENTER_V8(isolate); i::HandleScope scope(isolate); i::Handle self = Utils::OpenHandle(this); - return i::Handle::cast( - i::JSReceiver::GetOrCreateIdentityHash(self))->value(); + return i::JSReceiver::GetOrCreateIdentityHash(self)->value(); } diff --git a/src/objects-inl.h b/src/objects-inl.h index 00cd62e..b19f5f3 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -6319,7 +6319,7 @@ bool JSGlobalProxy::IsDetachedFrom(GlobalObject* global) { } -Handle JSReceiver::GetOrCreateIdentityHash(Handle object) { +Handle JSReceiver::GetOrCreateIdentityHash(Handle object) { return object->IsJSProxy() ? JSProxy::GetOrCreateIdentityHash(Handle::cast(object)) : JSObject::GetOrCreateIdentityHash(Handle::cast(object)); diff --git a/src/objects.cc b/src/objects.cc index cdd90d9..f9a52e5 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -945,11 +945,9 @@ Object* Object::GetHash() { } -Handle Object::GetOrCreateHash(Handle object, - Isolate* isolate) { +Handle Object::GetOrCreateHash(Isolate* isolate, Handle object) { Handle hash(object->GetHash(), isolate); - if (hash->IsSmi()) - return hash; + if (hash->IsSmi()) return Handle::cast(hash); ASSERT(object->IsJSReceiver()); return JSReceiver::GetOrCreateIdentityHash(Handle::cast(object)); @@ -5098,13 +5096,13 @@ void JSObject::SetIdentityHash(Handle object, Handle hash) { template -static Handle GetOrCreateIdentityHashHelper(Handle proxy) { +static Handle GetOrCreateIdentityHashHelper(Handle proxy) { Isolate* isolate = proxy->GetIsolate(); - Handle hash(proxy->hash(), isolate); - if (hash->IsSmi()) return hash; + Handle maybe_hash(proxy->hash(), isolate); + if (maybe_hash->IsSmi()) return Handle::cast(maybe_hash); - hash = handle(GenerateIdentityHash(isolate), isolate); + Handle hash(GenerateIdentityHash(isolate), isolate); proxy->set_hash(*hash); return hash; } @@ -5124,17 +5122,17 @@ Object* JSObject::GetIdentityHash() { } -Handle JSObject::GetOrCreateIdentityHash(Handle object) { +Handle JSObject::GetOrCreateIdentityHash(Handle object) { if (object->IsJSGlobalProxy()) { return GetOrCreateIdentityHashHelper(Handle::cast(object)); } Isolate* isolate = object->GetIsolate(); - Handle hash(object->GetIdentityHash(), isolate); - if (hash->IsSmi()) return hash; + Handle maybe_hash(object->GetIdentityHash(), isolate); + if (maybe_hash->IsSmi()) return Handle::cast(maybe_hash); - hash = handle(GenerateIdentityHash(isolate), isolate); + Handle hash(GenerateIdentityHash(isolate), isolate); SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash); return hash; } @@ -5145,7 +5143,7 @@ Object* JSProxy::GetIdentityHash() { } -Handle JSProxy::GetOrCreateIdentityHash(Handle proxy) { +Handle JSProxy::GetOrCreateIdentityHash(Handle proxy) { return GetOrCreateIdentityHashHelper(proxy); } @@ -16114,7 +16112,7 @@ Handle ObjectHashTable::Put(Handle table, Isolate* isolate = table->GetIsolate(); // Make sure the key object has an identity hash code. - Handle hash = Object::GetOrCreateHash(key, isolate); + Handle hash = Object::GetOrCreateHash(isolate, key); int entry = table->FindEntry(key); @@ -16133,7 +16131,7 @@ Handle ObjectHashTable::Put(Handle table, // Check whether the hash table should be extended. table = EnsureCapacity(table, 1, key); - table->AddEntry(table->FindInsertionEntry(Handle::cast(hash)->value()), + table->AddEntry(table->FindInsertionEntry(hash->value()), *key, *value); return table; @@ -16426,8 +16424,8 @@ Handle OrderedHashSet::Add(Handle table, table = EnsureGrowable(table); - Handle hash = GetOrCreateHash(key, table->GetIsolate()); - int index = table->AddEntry(Smi::cast(*hash)->value()); + Handle hash = GetOrCreateHash(table->GetIsolate(), key); + int index = table->AddEntry(hash->value()); table->set(index, *key); return table; } @@ -16468,8 +16466,8 @@ Handle OrderedHashMap::Put(Handle table, table = EnsureGrowable(table); - Handle hash = GetOrCreateHash(key, table->GetIsolate()); - int index = table->AddEntry(Smi::cast(*hash)->value()); + Handle hash = GetOrCreateHash(table->GetIsolate(), key); + int index = table->AddEntry(hash->value()); table->set(index, *key); table->set(index + kValueOffset, *value); return table; diff --git a/src/objects.h b/src/objects.h index 20f40b8..fa39900 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1503,10 +1503,7 @@ class Object { // Returns the permanent hash code associated with this object depending on // the actual object type. May create and store a hash code if needed and none // exists. - // TODO(rafaelw): Remove isolate parameter when objects.cc is fully - // handlified. - static Handle GetOrCreateHash(Handle object, - Isolate* isolate); + static Handle GetOrCreateHash(Isolate* isolate, Handle object); // Checks whether this object has the same value as the given one. This // function is implemented according to ES5, section 9.12 and can be used @@ -1972,7 +1969,7 @@ class JSReceiver: public HeapObject { // Retrieves a permanent object identity hash code. May create and store a // hash code if needed and none exists. - inline static Handle GetOrCreateIdentityHash( + inline static Handle GetOrCreateIdentityHash( Handle object); // Lookup a property. If found, the result is valid and has @@ -2884,7 +2881,7 @@ class JSObject: public JSReceiver { MUST_USE_RESULT Object* GetIdentityHash(); - static Handle GetOrCreateIdentityHash(Handle object); + static Handle GetOrCreateIdentityHash(Handle object); DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); }; @@ -9874,7 +9871,7 @@ class JSProxy: public JSReceiver { MUST_USE_RESULT Object* GetIdentityHash(); - static Handle GetOrCreateIdentityHash(Handle proxy); + static Handle GetOrCreateIdentityHash(Handle proxy); DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); };