Reviewers: Toon Verwaest,
Description:
Clean up hash creation code to use Handle<Smi> where possible
Also remove apparently-bogus TODO and reorder arguments in
Object::GetOrCreateHash to put Isolate first (as seems to
be the custom).
[email protected]
Please review this at https://codereview.chromium.org/268063005/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+23, -29 lines):
M src/api.cc
M src/objects.h
M src/objects.cc
M src/objects-inl.h
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
1fc270c7255ceddbdae4557714de08a7562a15c1..839b73eba7f0e71e019689c0f72f6e5cb2817b63
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<i::JSObject> self = Utils::OpenHandle(this);
- return i::Handle<i::Smi>::cast(
- i::JSReceiver::GetOrCreateIdentityHash(self))->value();
+ return i::JSReceiver::GetOrCreateIdentityHash(self)->value();
}
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index
029e80d9bb96e075f39c14c7d9d93566fc5d4321..980437afe644e7c1f21a9d5bf9892bc3d7fbf310
100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -6320,7 +6320,7 @@ bool JSGlobalProxy::IsDetachedFrom(GlobalObject*
global) {
}
-Handle<Object> JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver>
object) {
+Handle<Smi> JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver> object)
{
return object->IsJSProxy()
? JSProxy::GetOrCreateIdentityHash(Handle<JSProxy>::cast(object))
: JSObject::GetOrCreateIdentityHash(Handle<JSObject>::cast(object));
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
87853f3805a9f3a8fc2463f35ce8b2effa9fc16e..68d0326374820ed7d1eb56d65f5fab19845bbd3c
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -945,11 +945,9 @@ Object* Object::GetHash() {
}
-Handle<Object> Object::GetOrCreateHash(Handle<Object> object,
- Isolate* isolate) {
+Handle<Smi> Object::GetOrCreateHash(Isolate* isolate, Handle<Object>
object) {
Handle<Object> hash(object->GetHash(), isolate);
- if (hash->IsSmi())
- return hash;
+ if (hash->IsSmi()) return Handle<Smi>::cast(hash);
ASSERT(object->IsJSReceiver());
return
JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver>::cast(object));
@@ -5096,13 +5094,13 @@ void JSObject::SetIdentityHash(Handle<JSObject>
object, Handle<Smi> hash) {
template<typename ProxyType>
-static Handle<Object> GetOrCreateIdentityHashHelper(Handle<ProxyType>
proxy) {
+static Handle<Smi> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) {
Isolate* isolate = proxy->GetIsolate();
- Handle<Object> hash(proxy->hash(), isolate);
- if (hash->IsSmi()) return hash;
+ Handle<Object> maybe_hash(proxy->hash(), isolate);
+ if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash);
- hash = handle(GenerateIdentityHash(isolate), isolate);
+ Handle<Smi> hash(GenerateIdentityHash(isolate), isolate);
proxy->set_hash(*hash);
return hash;
}
@@ -5122,17 +5120,17 @@ Object* JSObject::GetIdentityHash() {
}
-Handle<Object> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) {
+Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) {
if (object->IsJSGlobalProxy()) {
return
GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object));
}
Isolate* isolate = object->GetIsolate();
- Handle<Object> hash(object->GetIdentityHash(), isolate);
- if (hash->IsSmi()) return hash;
+ Handle<Object> maybe_hash(object->GetIdentityHash(), isolate);
+ if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash);
- hash = handle(GenerateIdentityHash(isolate), isolate);
+ Handle<Smi> hash(GenerateIdentityHash(isolate), isolate);
SetHiddenProperty(object, isolate->factory()->identity_hash_string(),
hash);
return hash;
}
@@ -5143,7 +5141,7 @@ Object* JSProxy::GetIdentityHash() {
}
-Handle<Object> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) {
+Handle<Smi> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) {
return GetOrCreateIdentityHashHelper(proxy);
}
@@ -16109,7 +16107,7 @@ Handle<ObjectHashTable>
ObjectHashTable::Put(Handle<ObjectHashTable> table,
Isolate* isolate = table->GetIsolate();
// Make sure the key object has an identity hash code.
- Handle<Object> hash = Object::GetOrCreateHash(key, isolate);
+ Handle<Smi> hash = Object::GetOrCreateHash(isolate, key);
int entry = table->FindEntry(key);
@@ -16128,7 +16126,7 @@ Handle<ObjectHashTable>
ObjectHashTable::Put(Handle<ObjectHashTable> table,
// Check whether the hash table should be extended.
table = EnsureCapacity(table, 1, key);
-
table->AddEntry(table->FindInsertionEntry(Handle<Smi>::cast(hash)->value()),
+ table->AddEntry(table->FindInsertionEntry(hash->value()),
*key,
*value);
return table;
@@ -16421,8 +16419,8 @@ Handle<OrderedHashSet>
OrderedHashSet::Add(Handle<OrderedHashSet> table,
table = EnsureGrowable(table);
- Handle<Object> hash = GetOrCreateHash(key, table->GetIsolate());
- int index = table->AddEntry(Smi::cast(*hash)->value());
+ Handle<Smi> hash = GetOrCreateHash(table->GetIsolate(), key);
+ int index = table->AddEntry(hash->value());
table->set(index, *key);
return table;
}
@@ -16463,8 +16461,8 @@ Handle<OrderedHashMap>
OrderedHashMap::Put(Handle<OrderedHashMap> table,
table = EnsureGrowable(table);
- Handle<Object> hash = GetOrCreateHash(key, table->GetIsolate());
- int index = table->AddEntry(Smi::cast(*hash)->value());
+ Handle<Smi> hash = GetOrCreateHash(table->GetIsolate(), key);
+ int index = table->AddEntry(hash->value());
table->set(index, *key);
table->set(index + kValueOffset, *value);
return table;
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
0fd3daedb35f8563a2f5ab39445b4c7cd4175c51..f9ea1e479d76b521e97b613283adf104aaefe5e8
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -1502,10 +1502,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<Object> GetOrCreateHash(Handle<Object> object,
- Isolate* isolate);
+ static Handle<Smi> GetOrCreateHash(Isolate* isolate, Handle<Object>
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
@@ -1971,7 +1968,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<Object> GetOrCreateIdentityHash(
+ inline static Handle<Smi> GetOrCreateIdentityHash(
Handle<JSReceiver> object);
// Lookup a property. If found, the result is valid and has
@@ -2883,7 +2880,7 @@ class JSObject: public JSReceiver {
MUST_USE_RESULT Object* GetIdentityHash();
- static Handle<Object> GetOrCreateIdentityHash(Handle<JSObject> object);
+ static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object);
DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
};
@@ -9873,7 +9870,7 @@ class JSProxy: public JSReceiver {
MUST_USE_RESULT Object* GetIdentityHash();
- static Handle<Object> GetOrCreateIdentityHash(Handle<JSProxy> proxy);
+ static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy);
DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy);
};
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.