Reviewers: Yang,

Message:
PTAL

Description:
Internalize names before using them in slow-mode objects.

Please review this at https://chromiumcodereview.appspot.com/24566005/

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

Affected files (+15, -1 lines):
  M src/bootstrapper.cc
  M src/objects-inl.h
  M src/objects.cc


Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 0756aefb0b4653d0e3b14cd8f10af34f41b2d6fa..332131a7cab880df8d057137c0f5001419221f63 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -1043,7 +1043,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
   }

   {  // -- J S O N
-    Handle<String> name = factory->NewStringFromAscii(CStrVector("JSON"));
+    Handle<String> name = factory->InternalizeUtf8String("JSON");
     Handle<JSFunction> cons = factory->NewFunction(name,
factory->the_hole_value());
     JSFunction::SetInstancePrototype(cons,
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 8c20c7a1663a1af4096a23f818fe37d1eb0a5fac..48bd78e75485c984ccb56f42b4c450ff49587fa6 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -5921,6 +5921,7 @@ uint32_t NameDictionaryShape::HashForObject(Name* key, Object* other) {


 MaybeObject* NameDictionaryShape::AsObject(Heap* heap, Name* key) {
+  ASSERT(key->IsUniqueName());
   return key;
 }

Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 32127eb8b9f19afd9e3cf46c04303b900ca86772..1399e33ffab4acb74f42abd63ad646747b9b61cc 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -672,12 +672,19 @@ void JSObject::SetNormalizedProperty(Handle<JSObject> object,
                                      PropertyDetails details) {
   ASSERT(!object->HasFastProperties());
Handle<NameDictionary> property_dictionary(object->property_dictionary());
+
+  if (!name->IsUniqueName()) {
+    name = object->GetIsolate()->factory()->InternalizedStringFromString(
+        Handle<String>::cast(name));
+  }
+
   int entry = property_dictionary->FindEntry(*name);
   if (entry == NameDictionary::kNotFound) {
     Handle<Object> store_value = value;
     if (object->IsGlobalObject()) {
store_value = object->GetIsolate()->factory()->NewPropertyCell(value);
     }
+
     property_dictionary =
         NameDictionaryAdd(property_dictionary, name, store_value, details);
     object->set_properties(*property_dictionary);
@@ -2044,6 +2051,12 @@ Handle<Object> JSObject::AddProperty(Handle<JSObject> object,
                                      TransitionFlag transition_flag) {
   ASSERT(!object->IsJSGlobalProxy());
   Isolate* isolate = object->GetIsolate();
+
+  if (!name->IsUniqueName()) {
+    name = isolate->factory()->InternalizedStringFromString(
+        Handle<String>::cast(name));
+  }
+
   if (extensibility_check == PERFORM_EXTENSIBILITY_CHECK &&
       !object->map()->is_extensible()) {
     if (strict_mode == kNonStrictMode) {


--
--
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/groups/opt_out.

Reply via email to