diff --git a/src/factory.cc b/src/factory.cc index 400132e14b..cccc3e7629 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -576,10 +576,32 @@ Handle Factory::NewMap(InstanceType type, Handle Factory::NewFunctionPrototype(Handle function) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateFunctionPrototype(*function), - JSObject); + // Make sure to use globals from the function's context, since the function + // can be from a different context. + Handle native_context(function->context()->native_context()); + Handle new_map; + if (function->shared()->is_generator()) { + // Generator prototypes can share maps since they don't have "constructor" + // properties. + new_map = handle(native_context->generator_object_prototype_map()); + } else { + // Each function prototype gets a fresh map to avoid unwanted sharing of + // maps between prototypes of different constructors. + Handle object_function(native_context->object_function()); + ASSERT(object_function->has_initial_map()); + new_map = Map::Copy(handle(object_function->initial_map())); + } + + Handle prototype = NewJSObjectFromMap(new_map); + + if (!function->shared()->is_generator()) { + JSObject::SetLocalPropertyIgnoreAttributes(prototype, + constructor_string(), + function, + DONT_ENUM); + } + + return prototype; } diff --git a/src/heap.cc b/src/heap.cc index ecd959da67..30932093be 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -4388,39 +4388,6 @@ void Heap::InitializeFunction(JSFunction* function, } -MaybeObject* Heap::AllocateFunctionPrototype(JSFunction* function) { - // Make sure to use globals from the function's context, since the function - // can be from a different context. - Context* native_context = function->context()->native_context(); - Map* new_map; - if (function->shared()->is_generator()) { - // Generator prototypes can share maps since they don't have "constructor" - // properties. - new_map = native_context->generator_object_prototype_map(); - } else { - // Each function prototype gets a fresh map to avoid unwanted sharing of - // maps between prototypes of different constructors. - JSFunction* object_function = native_context->object_function(); - ASSERT(object_function->has_initial_map()); - MaybeObject* maybe_map = object_function->initial_map()->Copy(); - if (!maybe_map->To(&new_map)) return maybe_map; - } - - Object* prototype; - MaybeObject* maybe_prototype = AllocateJSObjectFromMap(new_map); - if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; - - if (!function->shared()->is_generator()) { - MaybeObject* maybe_failure = - JSObject::cast(prototype)->SetLocalPropertyIgnoreAttributesTrampoline( - constructor_string(), function, DONT_ENUM); - if (maybe_failure->IsFailure()) return maybe_failure; - } - - return prototype; -} - - MaybeObject* Heap::AllocateFunction(Map* function_map, SharedFunctionInfo* shared, Object* prototype, diff --git a/src/heap.h b/src/heap.h index fc0a2152fd..ea70f076c2 100644 --- a/src/heap.h +++ b/src/heap.h @@ -672,12 +672,6 @@ class Heap { MUST_USE_RESULT MaybeObject* CopyJSObject(JSObject* source, AllocationSite* site = NULL); - // Allocates the function prototype. - // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation - // failed. - // Please note this does not perform a garbage collection. - MUST_USE_RESULT MaybeObject* AllocateFunctionPrototype(JSFunction* function); - // Allocates a JS ArrayBuffer object. // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation // failed.