diff --git a/src/factory.cc b/src/factory.cc index 028dcabeb5..4ec47e5278 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1318,6 +1318,17 @@ Handle Factory::NewJSModule(Handle context, } +// TODO(mstarzinger): Temporary wrapper until handlified. +static Handle NameDictionaryAdd(Handle dict, + Handle name, + Handle value, + PropertyDetails details) { + CALL_HEAP_FUNCTION(dict->GetIsolate(), + dict->Add(*name, *value, details), + NameDictionary); +} + + static Handle NewGlobalObjectFromMap(Isolate* isolate, Handle map) { CALL_HEAP_FUNCTION(isolate, @@ -1360,7 +1371,7 @@ Handle Factory::NewGlobalObject(Handle constructor) { Handle name(descs->GetKey(i)); Handle value(descs->GetCallbacksObject(i), isolate()); Handle cell = NewPropertyCell(value); - NameDictionary::Add(dictionary, name, cell, d); + NameDictionaryAdd(dictionary, name, cell, d); } // Allocate the global object and initialize it with the backing store. diff --git a/src/heap.cc b/src/heap.cc index f51d226d4d..00e513ba88 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -2996,6 +2996,10 @@ bool Heap::CreateInitialObjects() { NameDictionary::Allocate(this, Runtime::kNumFunctions); if (!maybe_obj->ToObject(&obj)) return false; } + { MaybeObject* maybe_obj = Runtime::InitializeIntrinsicFunctionNames(this, + obj); + if (!maybe_obj->ToObject(&obj)) return false; + } set_intrinsic_function_names(NameDictionary::cast(obj)); { MaybeObject* maybe_obj = AllocateInitialNumberStringCache(); @@ -6176,11 +6180,6 @@ bool Heap::CreateHeapObjects() { array_buffers_list_ = undefined_value(); allocation_sites_list_ = undefined_value(); weak_object_to_code_table_ = undefined_value(); - - HandleScope scope(isolate()); - Runtime::InitializeIntrinsicFunctionNames( - isolate(), handle(intrinsic_function_names(), isolate())); - return true; } diff --git a/src/objects.cc b/src/objects.cc index 04641175db..3e5e0bd594 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -633,6 +633,17 @@ void JSObject::SetNormalizedProperty(Handle object, } +// TODO(mstarzinger): Temporary wrapper until handlified. +static Handle NameDictionaryAdd(Handle dict, + Handle name, + Handle value, + PropertyDetails details) { + CALL_HEAP_FUNCTION(dict->GetIsolate(), + dict->Add(*name, *value, details), + NameDictionary); +} + + void JSObject::SetNormalizedProperty(Handle object, Handle name, Handle value, @@ -653,7 +664,7 @@ void JSObject::SetNormalizedProperty(Handle object, } property_dictionary = - NameDictionary::Add(property_dictionary, name, store_value, details); + NameDictionaryAdd(property_dictionary, name, store_value, details); object->set_properties(*property_dictionary); return; } @@ -1933,8 +1944,7 @@ void JSObject::AddSlowProperty(Handle object, value = cell; } PropertyDetails details = PropertyDetails(attributes, NORMAL, 0); - Handle result = - NameDictionary::Add(dict, name, value, details); + Handle result = NameDictionaryAdd(dict, name, value, details); if (*dict != *result) object->set_properties(*result); } @@ -4493,7 +4503,7 @@ void JSObject::NormalizeProperties(Handle object, Handle value(descs->GetConstant(i), isolate); PropertyDetails d = PropertyDetails( details.attributes(), NORMAL, i + 1); - dictionary = NameDictionary::Add(dictionary, key, value, d); + dictionary = NameDictionaryAdd(dictionary, key, value, d); break; } case FIELD: { @@ -4502,7 +4512,7 @@ void JSObject::NormalizeProperties(Handle object, object->RawFastPropertyAt(descs->GetFieldIndex(i)), isolate); PropertyDetails d = PropertyDetails(details.attributes(), NORMAL, i + 1); - dictionary = NameDictionary::Add(dictionary, key, value, d); + dictionary = NameDictionaryAdd(dictionary, key, value, d); break; } case CALLBACKS: { @@ -4510,7 +4520,7 @@ void JSObject::NormalizeProperties(Handle object, Handle value(descs->GetCallbacksObject(i), isolate); PropertyDetails d = PropertyDetails( details.attributes(), CALLBACKS, i + 1); - dictionary = NameDictionary::Add(dictionary, key, value, d); + dictionary = NameDictionaryAdd(dictionary, key, value, d); break; } case INTERCEPTOR: @@ -14298,17 +14308,6 @@ template int HashTable::FindEntry(uint32_t); -Handle NameDictionary::Add(Handle dict, - Handle name, - Handle value, - PropertyDetails details) { - CALL_HEAP_FUNCTION(dict->GetIsolate(), - Handle::cast(dict)->Add( - *name, *value, details), - NameDictionary); -} - - Handle JSObject::PrepareSlowElementsForSort( Handle object, uint32_t limit) { CALL_HEAP_FUNCTION(object->GetIsolate(), @@ -14840,7 +14839,7 @@ Handle JSGlobalObject::EnsurePropertyCell( isolate->factory()->the_hole_value()); PropertyDetails details(NONE, NORMAL, 0); details = details.AsDeleted(); - Handle dictionary = NameDictionary::Add( + Handle dictionary = NameDictionaryAdd( handle(global->property_dictionary()), name, cell, details); global->set_properties(*dictionary); return cell; diff --git a/src/objects.h b/src/objects.h index 325f26db0d..047f8450f5 100644 --- a/src/objects.h +++ b/src/objects.h @@ -4093,12 +4093,6 @@ class NameDictionary: public Dictionary { // Find entry for key, otherwise return kNotFound. Optimized version of // HashTable::FindEntry. int FindEntry(Name* key); - - // TODO(mstarzinger): Temporary wrapper until handlified. - static Handle Add(Handle dict, - Handle name, - Handle value, - PropertyDetails details); }; diff --git a/src/runtime.cc b/src/runtime.cc index c72aaa289a..7ce8b79c30 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -15089,21 +15089,31 @@ static const Runtime::Function kIntrinsicFunctions[] = { #undef F -void Runtime::InitializeIntrinsicFunctionNames(Isolate* isolate, - Handle dict) { - ASSERT(dict->NumberOfElements() == 0); - HandleScope scope(isolate); +MaybeObject* Runtime::InitializeIntrinsicFunctionNames(Heap* heap, + Object* dictionary) { + ASSERT(dictionary != NULL); + ASSERT(NameDictionary::cast(dictionary)->NumberOfElements() == 0); for (int i = 0; i < kNumFunctions; ++i) { const char* name = kIntrinsicFunctions[i].name; if (name == NULL) continue; - Handle new_dict = NameDictionary::Add( - dict, - isolate->factory()->InternalizeUtf8String(name), - Handle(Smi::FromInt(i), isolate), - PropertyDetails(NONE, NORMAL, Representation::None())); - // The dictionary does not need to grow. - CHECK(new_dict.is_identical_to(dict)); + Object* name_string; + { MaybeObject* maybe_name_string = + heap->InternalizeUtf8String(name); + if (!maybe_name_string->ToObject(&name_string)) return maybe_name_string; + } + NameDictionary* name_dictionary = NameDictionary::cast(dictionary); + { MaybeObject* maybe_dictionary = name_dictionary->Add( + String::cast(name_string), + Smi::FromInt(i), + PropertyDetails(NONE, NORMAL, Representation::None())); + if (!maybe_dictionary->ToObject(&dictionary)) { + // Non-recoverable failure. Calling code must restart heap + // initialization. + return maybe_dictionary; + } + } } + return dictionary; } diff --git a/src/runtime.h b/src/runtime.h index c1c563ab5f..3a5c4546a7 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -798,8 +798,11 @@ class Runtime : public AllStatic { // Add internalized strings for all the intrinsic function names to a // StringDictionary. - static void InitializeIntrinsicFunctionNames(Isolate* isolate, - Handle dict); + // Returns failure if an allocation fails. In this case, it must be + // retried with a new, empty StringDictionary, not with the same one. + // Alternatively, heap initialization can be completely restarted. + MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames( + Heap* heap, Object* dictionary); // Get the intrinsic function with the given name, which must be internalized. static const Function* FunctionForName(Handle name);