Reviewers: Yang,

Message:
PTAL #6

Description:
Dictionary::Add() handlified.

Please review this at https://codereview.chromium.org/249723004/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+38, -54 lines):
  M src/factory.cc
  M src/objects.h
  M src/objects.cc
  M src/runtime.cc


Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index 66b7fc614f35c01584344fb21b034cf338779d66..17798ab020050625e347f96fd888036e7f9d2e11 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -1496,7 +1496,7 @@ Handle<GlobalObject> Factory::NewGlobalObject(Handle<JSFunction> constructor) {
     Handle<Name> name(descs->GetKey(i));
     Handle<Object> value(descs->GetCallbacksObject(i), isolate());
     Handle<PropertyCell> cell = NewPropertyCell(value);
-    NameDictionary::AddNameEntry(dictionary, name, cell, d);
+    NameDictionary::Add(dictionary, *name, cell, d);
   }

   // Allocate the global object and initialize it with the backing store.
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 86baab160370c9e06b21d466122d15213f35de64..5c10f54aefb793f895b45f64597109e6fb4e9dda 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -667,8 +667,8 @@ void JSObject::SetNormalizedProperty(Handle<JSObject> object, store_value = object->GetIsolate()->factory()->NewPropertyCell(value);
     }

-    property_dictionary = NameDictionary::AddNameEntry(
-        property_dictionary, name, store_value, details);
+    property_dictionary = NameDictionary::Add(
+        property_dictionary, *name, store_value, details);
     object->set_properties(*property_dictionary);
     return;
   }
@@ -1942,7 +1942,7 @@ void JSObject::AddSlowProperty(Handle<JSObject> object,
   }
   PropertyDetails details = PropertyDetails(attributes, NORMAL, 0);
   Handle<NameDictionary> result =
-      NameDictionary::AddNameEntry(dict, name, value, details);
+      NameDictionary::Add(dict, *name, value, details);
   if (*dict != *result) object->set_properties(*result);
 }

@@ -4641,7 +4641,7 @@ void JSObject::NormalizeProperties(Handle<JSObject> object,
         Handle<Object> value(descs->GetConstant(i), isolate);
         PropertyDetails d = PropertyDetails(
             details.attributes(), NORMAL, i + 1);
- dictionary = NameDictionary::AddNameEntry(dictionary, key, value, d);
+        dictionary = NameDictionary::Add(dictionary, *key, value, d);
         break;
       }
       case FIELD: {
@@ -4650,7 +4650,7 @@ void JSObject::NormalizeProperties(Handle<JSObject> object,
             object->RawFastPropertyAt(descs->GetFieldIndex(i)), isolate);
         PropertyDetails d =
             PropertyDetails(details.attributes(), NORMAL, i + 1);
- dictionary = NameDictionary::AddNameEntry(dictionary, key, value, d);
+        dictionary = NameDictionary::Add(dictionary, *key, value, d);
         break;
       }
       case CALLBACKS: {
@@ -4658,7 +4658,7 @@ void JSObject::NormalizeProperties(Handle<JSObject> object,
         Handle<Object> value(descs->GetCallbacksObject(i), isolate);
         PropertyDetails d = PropertyDetails(
             details.attributes(), CALLBACKS, i + 1);
- dictionary = NameDictionary::AddNameEntry(dictionary, key, value, d);
+        dictionary = NameDictionary::Add(dictionary, *key, value, d);
         break;
       }
       case INTERCEPTOR:
@@ -14973,9 +14973,9 @@ template int
 Dictionary<NameDictionary, NameDictionaryShape, Name*>::
     NumberOfElementsFilterAttributes(PropertyAttributes);

-template MaybeObject*
+template Handle<NameDictionary>
 Dictionary<NameDictionary, NameDictionaryShape, Name*>::Add(
-    Name*, Object*, PropertyDetails);
+    Handle<NameDictionary>, Name*, Handle<Object>, PropertyDetails);

 template MaybeObject*
 Dictionary<NameDictionary, NameDictionaryShape, Name*>::
@@ -14985,13 +14985,19 @@ template int
 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
     NumberOfElementsFilterAttributes(PropertyAttributes);

-template MaybeObject*
-Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::Add(
-    uint32_t, Object*, PropertyDetails);
+template Handle<SeededNumberDictionary>
+Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
+    Add(Handle<SeededNumberDictionary>,
+        uint32_t,
+        Handle<Object>,
+        PropertyDetails);

-template MaybeObject*
+template Handle<UnseededNumberDictionary>
Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>::
-    Add(uint32_t, Object*, PropertyDetails);
+    Add(Handle<UnseededNumberDictionary>,
+        uint32_t,
+        Handle<Object>,
+        PropertyDetails);

 template MaybeObject*
 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
@@ -15030,16 +15036,6 @@ int HashTable<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
     FindEntry(uint32_t);


-Handle<NameDictionary> NameDictionary::AddNameEntry(Handle<NameDictionary> dict,
-                                                    Handle<Name> name,
-                                                    Handle<Object> value,
- PropertyDetails details) {
-  CALL_HEAP_FUNCTION(dict->GetIsolate(),
-                     dict->Add(*name, *value, details),
-                     NameDictionary);
-}
-
-
 Handle<Object> JSObject::PrepareSlowElementsForSort(
     Handle<JSObject> object, uint32_t limit) {
   ASSERT(object->HasDictionaryElements());
@@ -15480,8 +15476,8 @@ Handle<PropertyCell> JSGlobalObject::EnsurePropertyCell(
         isolate->factory()->the_hole_value());
     PropertyDetails details(NONE, NORMAL, 0);
     details = details.AsDeleted();
-    Handle<NameDictionary> dictionary = NameDictionary::AddNameEntry(
-        handle(global->property_dictionary()), name, cell, details);
+    Handle<NameDictionary> dictionary = NameDictionary::Add(
+        handle(global->property_dictionary()), *name, cell, details);
     global->set_properties(*dictionary);
     return cell;
   } else {
@@ -15960,20 +15956,17 @@ Handle<Derived> Dictionary<Derived, Shape, Key>::AtPut(


 template<typename Derived, typename Shape, typename Key>
-MaybeObject* Dictionary<Derived, Shape, Key>::Add(
+Handle<Derived> Dictionary<Derived, Shape, Key>::Add(
+    Handle<Derived> dictionary,
     Key key,
-    Object* value,
+    Handle<Object> value,
     PropertyDetails details) {
   // Valdate key is absent.
-  SLOW_ASSERT((this->FindEntry(key) == Dictionary::kNotFound));
+  SLOW_ASSERT((dictionary->FindEntry(key) == Dictionary::kNotFound));
   // Check whether the dictionary should be extended.
-  Object* obj;
-  { MaybeObject* maybe_obj = EnsureCapacity(1, key);
-    if (!maybe_obj->ToObject(&obj)) return maybe_obj;
-  }
+  dictionary = EnsureCapacity(dictionary, 1, key);

-  return Dictionary::cast(obj)->AddEntry(
-      key, value, details, Dictionary::Hash(key));
+  return AddEntry(dictionary, key, value, details, dictionary->Hash(key));
 }


@@ -16049,9 +16042,7 @@ Handle<SeededNumberDictionary> SeededNumberDictionary::AddNumberEntry(
     PropertyDetails details) {
   dictionary->UpdateMaxNumberKey(key);
   SLOW_ASSERT(dictionary->FindEntry(key) == kNotFound);
-  CALL_HEAP_FUNCTION(dictionary->GetIsolate(),
-                     dictionary->Add(key, *value, details),
-                     SeededNumberDictionary);
+  return Add(dictionary, key, value, details);
 }


@@ -16060,10 +16051,7 @@ Handle<UnseededNumberDictionary> UnseededNumberDictionary::AddNumberEntry(
     uint32_t key,
     Handle<Object> value) {
   SLOW_ASSERT(dictionary->FindEntry(key) == kNotFound);
-  CALL_HEAP_FUNCTION(dictionary->GetIsolate(),
-                     dictionary->Add(
-                         key, *value, PropertyDetails(NONE, NORMAL, 0)),
-                     UnseededNumberDictionary);
+  return Add(dictionary, key, value, PropertyDetails(NONE, NORMAL, 0));
 }


Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 37eb1393ff2b13f4ca3dc19bed21669b79fead40..ac8f7493bcb7afdfd91d46acc27105cd54d58bd9 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -4064,7 +4064,7 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
       PretenureFlag pretenure = NOT_TENURED);

   // Creates a new dictionary.
-  static Handle<Derived> New(
+  MUST_USE_RESULT static Handle<Derived> New(
       Isolate* isolate,
       int at_least_space_for,
       PretenureFlag pretenure = NOT_TENURED);
@@ -4089,9 +4089,11 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
                        Object* value,
                        PropertyDetails details);

-  MUST_USE_RESULT MaybeObject* Add(Key key,
-                                   Object* value,
-                                   PropertyDetails details);
+  MUST_USE_RESULT static Handle<Derived> Add(
+      Handle<Derived> dictionary,
+      Key key,
+      Handle<Object> value,
+      PropertyDetails details);

  protected:
   // Generic at put operation.
@@ -4150,12 +4152,6 @@ class NameDictionary: public Dictionary<NameDictionary,
   // Find entry for key, otherwise return kNotFound. Optimized version of
   // HashTable::FindEntry.
   int FindEntry(Name* key);
-
-  // TODO(mstarzinger): Temporary wrapper until handlified.
-  static Handle<NameDictionary> AddNameEntry(Handle<NameDictionary> dict,
-                                             Handle<Name> name,
-                                             Handle<Object> value,
-                                             PropertyDetails details);
 };


Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 3e84da98cb4115cc499e650aed5e00d9658f0cf2..a86bfa3701c129d013fd6587b1daaf2dacf32c4d 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -15098,9 +15098,9 @@ void Runtime::InitializeIntrinsicFunctionNames(Isolate* isolate,
   for (int i = 0; i < kNumFunctions; ++i) {
     const char* name = kIntrinsicFunctions[i].name;
     if (name == NULL) continue;
-    Handle<NameDictionary> new_dict = NameDictionary::AddNameEntry(
+    Handle<NameDictionary> new_dict = NameDictionary::Add(
         dict,
-        isolate->factory()->InternalizeUtf8String(name),
+        *isolate->factory()->InternalizeUtf8String(name),
         Handle<Smi>(Smi::FromInt(i), isolate),
         PropertyDetails(NONE, NORMAL, Representation::None()));
     // The dictionary does not need to grow.


--
--
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.

Reply via email to