Handlify Heap::AllocateFunctionPrototype method.
R=rossberg@chromium.org BUG=v8:2877 Review URL: https://codereview.chromium.org/37463002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17487 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
a4b4cfdc58
commit
ae8824e5de
@ -576,10 +576,32 @@ Handle<Map> Factory::NewMap(InstanceType type,
|
||||
|
||||
|
||||
Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> 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<Context> native_context(function->context()->native_context());
|
||||
Handle<Map> 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<JSFunction> object_function(native_context->object_function());
|
||||
ASSERT(object_function->has_initial_map());
|
||||
new_map = Map::Copy(handle(object_function->initial_map()));
|
||||
}
|
||||
|
||||
Handle<JSObject> prototype = NewJSObjectFromMap(new_map);
|
||||
|
||||
if (!function->shared()->is_generator()) {
|
||||
JSObject::SetLocalPropertyIgnoreAttributes(prototype,
|
||||
constructor_string(),
|
||||
function,
|
||||
DONT_ENUM);
|
||||
}
|
||||
|
||||
return prototype;
|
||||
}
|
||||
|
||||
|
||||
|
33
src/heap.cc
33
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,
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user