From 756a99bdbaca89980444d8a4fefb222b057e9b4a Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Fri, 30 Aug 2013 13:42:16 +0000 Subject: [PATCH] Handlify JSObject::SetIdentityHash method. R=verwaest@chromium.org Review URL: https://codereview.chromium.org/23495011 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16454 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/factory.cc | 7 ------- src/factory.h | 2 -- src/objects.cc | 18 ++++++++---------- src/objects.h | 17 +++++++++-------- test/cctest/test-dictionary.cc | 6 +++--- test/cctest/test-heap.cc | 4 +--- 6 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/factory.cc b/src/factory.cc index 6faa84e..bd6ed2b 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1190,13 +1190,6 @@ void Factory::BecomeJSFunction(Handle object) { } -void Factory::SetIdentityHash(Handle object, Smi* hash) { - CALL_HEAP_FUNCTION_VOID( - isolate(), - object->SetIdentityHash(hash, ALLOW_CREATION)); -} - - Handle Factory::NewSharedFunctionInfo( Handle name, int number_of_literals, diff --git a/src/factory.h b/src/factory.h index 390329c..46b562c 100644 --- a/src/factory.h +++ b/src/factory.h @@ -346,8 +346,6 @@ class Factory { void BecomeJSObject(Handle object); void BecomeJSFunction(Handle object); - void SetIdentityHash(Handle object, Smi* hash); - Handle NewFunction(Handle name, Handle prototype); diff --git a/src/objects.cc b/src/objects.cc index ed2eafd..22d597c 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -3672,8 +3672,7 @@ void JSProxy::Fix(Handle proxy) { // Inherit identity, if it was present. if (hash->IsSmi()) { - isolate->factory()->SetIdentityHash( - Handle::cast(proxy), Smi::cast(*hash)); + JSObject::SetIdentityHash(Handle::cast(proxy), Smi::cast(*hash)); } } @@ -4716,17 +4715,16 @@ Smi* JSReceiver::GenerateIdentityHash() { } -MaybeObject* JSObject::SetIdentityHash(Smi* hash, CreationFlag flag) { - MaybeObject* maybe = SetHiddenProperty(GetHeap()->identity_hash_string(), - hash); - if (maybe->IsFailure()) return maybe; - return this; +void JSObject::SetIdentityHash(Handle object, Smi* hash) { + CALL_HEAP_FUNCTION_VOID(object->GetIsolate(), + object->SetHiddenProperty( + object->GetHeap()->identity_hash_string(), hash)); } -int JSObject::GetIdentityHash(Handle obj) { - CALL_AND_RETRY_OR_DIE(obj->GetIsolate(), - obj->GetIdentityHash(ALLOW_CREATION), +int JSObject::GetIdentityHash(Handle object) { + CALL_AND_RETRY_OR_DIE(object->GetIsolate(), + object->GetIdentityHash(ALLOW_CREATION), return Smi::cast(__object__)->value(), return 0); } diff --git a/src/objects.h b/src/objects.h index 9fa133d..056dad2 100644 --- a/src/objects.h +++ b/src/objects.h @@ -2299,9 +2299,8 @@ class JSObject: public JSReceiver { // Returns true if the object has a property with the hidden string as name. bool HasHiddenProperties(); - static int GetIdentityHash(Handle obj); - MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); - MUST_USE_RESULT MaybeObject* SetIdentityHash(Smi* hash, CreationFlag flag); + static int GetIdentityHash(Handle object); + static void SetIdentityHash(Handle object, Smi* hash); inline void ValidateElements(); @@ -2848,6 +2847,8 @@ class JSObject: public JSReceiver { MUST_USE_RESULT MaybeObject* SetHiddenPropertiesHashTable( Object* value); + MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); + DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); }; @@ -9106,11 +9107,7 @@ class JSProxy: public JSReceiver { JSReceiver* receiver, uint32_t index); - MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); - static Handle GetIdentityHash(Handle proxy, - CreationFlag flag); - - // Turn this into an (empty) JSObject. + // Turn the proxy into an (empty) JSObject. static void Fix(Handle proxy); // Initializes the body after the handler slot. @@ -9159,6 +9156,10 @@ class JSProxy: public JSReceiver { uint32_t index, DeleteMode mode); + MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); + static Handle GetIdentityHash(Handle proxy, + CreationFlag flag); + DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); }; diff --git a/test/cctest/test-dictionary.cc b/test/cctest/test-dictionary.cc index 2bdf235..21c20bd 100644 --- a/test/cctest/test-dictionary.cc +++ b/test/cctest/test-dictionary.cc @@ -72,7 +72,7 @@ TEST(ObjectHashTable) { // Keys should map back to their respective values and also should get // an identity hash code generated. for (int i = 0; i < 100; i++) { - Handle key = factory->NewJSArray(7); + Handle key = factory->NewJSArray(7); Handle value = factory->NewJSArray(11); table = PutIntoObjectHashTable(table, key, value); CHECK_EQ(table->NumberOfElements(), i + 1); @@ -84,7 +84,7 @@ TEST(ObjectHashTable) { // Keys never added to the map which already have an identity hash // code should not be found. for (int i = 0; i < 100; i++) { - Handle key = factory->NewJSArray(7); + Handle key = factory->NewJSArray(7); CHECK(key->GetIdentityHash(ALLOW_CREATION)->ToObjectChecked()->IsSmi()); CHECK_EQ(table->FindEntry(*key), ObjectHashTable::kNotFound); CHECK_EQ(table->Lookup(*key), HEAP->the_hole_value()); @@ -94,7 +94,7 @@ TEST(ObjectHashTable) { // Keys that don't have an identity hash should not be found and also // should not get an identity hash code generated. for (int i = 0; i < 100; i++) { - Handle key = factory->NewJSArray(7); + Handle key = factory->NewJSArray(7); CHECK_EQ(table->Lookup(*key), HEAP->the_hole_value()); CHECK_EQ(key->GetIdentityHash(OMIT_CREATION), HEAP->undefined_value()); } diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index 87598e2..fc6a1ec 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -2691,9 +2691,7 @@ TEST(Regress2211) { // In the first iteration, set hidden value first and identity hash second. // In the second iteration, reverse the order. if (i == 0) obj->SetHiddenValue(v8_str("key string"), value); - MaybeObject* maybe_obj = internal_obj->SetIdentityHash(hash, - ALLOW_CREATION); - CHECK(!maybe_obj->IsFailure()); + JSObject::SetIdentityHash(internal_obj, hash); if (i == 1) obj->SetHiddenValue(v8_str("key string"), value); // Check values. -- 2.7.4