Commit b1364489 authored by verwaest@chromium.org's avatar verwaest@chromium.org

Replace NewFunction(MaybeHandle<> prototype by Handle<> prototype

BUG=
R=ishell@chromium.org

Review URL: https://codereview.chromium.org/264973020

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21237 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent eb3c1bd6
......@@ -357,8 +357,11 @@ static Handle<JSFunction> InstallFunction(Handle<JSObject> target,
Factory* factory = isolate->factory();
Handle<String> internalized_name = factory->InternalizeUtf8String(name);
Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call));
Handle<JSFunction> function = factory->NewFunction(
maybe_prototype, internalized_name, type, instance_size, call_code);
Handle<JSObject> prototype;
Handle<JSFunction> function = maybe_prototype.ToHandle(&prototype)
? factory->NewFunction(prototype, internalized_name, type,
instance_size, call_code)
: factory->NewFunction(internalized_name, call_code);
PropertyAttributes attributes;
if (target->IsJSBuiltinsObject()) {
attributes =
......@@ -486,8 +489,7 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
Handle<String> empty_string =
factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty"));
Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction));
Handle<JSFunction> empty_function = factory->NewFunction(
empty_string, MaybeHandle<Object>(), code);
Handle<JSFunction> empty_function = factory->NewFunction(empty_string, code);
// --- E m p t y ---
Handle<String> source = factory->NewStringFromStaticAscii("() {}");
......@@ -568,8 +570,7 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() {
STATIC_ASCII_VECTOR("ThrowTypeError"));
Handle<Code> code(isolate()->builtins()->builtin(
Builtins::kStrictModePoisonPill));
throw_type_error_function = factory()->NewFunction(
name, MaybeHandle<Object>(), code);
throw_type_error_function = factory()->NewFunction(name, code);
throw_type_error_function->set_map(native_context()->sloppy_function_map());
throw_type_error_function->shared()->DontAdaptArguments();
......@@ -1086,9 +1087,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
STATIC_ASCII_VECTOR("Arguments"));
Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal));
Handle<JSFunction> function = factory->NewFunction(
MaybeHandle<Object>(), arguments_string, JS_OBJECT_TYPE,
JSObject::kHeaderSize, code);
Handle<JSFunction> function = factory->NewFunction(arguments_string, code);
ASSERT(!function->has_initial_map());
function->shared()->set_instance_class_name(*arguments_string);
function->shared()->set_expected_nof_properties(2);
......
......@@ -1203,8 +1203,8 @@ Handle<JSFunction> Factory::NewFunction(Handle<Map> map,
Handle<JSFunction> Factory::NewFunction(Handle<String> name,
MaybeHandle<Object> maybe_prototype,
MaybeHandle<Code> maybe_code) {
MaybeHandle<Code> maybe_code,
MaybeHandle<Object> maybe_prototype) {
Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name);
ASSERT(info->strict_mode() == SLOPPY);
Handle<Code> code;
......@@ -1225,34 +1225,26 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name,
Handle<JSFunction> Factory::NewFunction(Handle<String> name) {
return NewFunction(name, the_hole_value(), MaybeHandle<Code>());
return NewFunction(name, MaybeHandle<Code>(), the_hole_value());
}
Handle<JSFunction> Factory::NewFunction(MaybeHandle<Object> maybe_prototype,
Handle<JSFunction> Factory::NewFunction(Handle<Object> prototype,
Handle<String> name,
InstanceType type,
int instance_size,
Handle<Code> code) {
// Allocate the function
Handle<JSFunction> function = NewFunction(name, maybe_prototype, code);
if (!maybe_prototype.is_null() ||
type != JS_OBJECT_TYPE ||
instance_size != JSObject::kHeaderSize) {
Handle<Object> prototype = maybe_prototype.ToHandleChecked();
Handle<Map> initial_map = NewMap(
type, instance_size, GetInitialFastElementsKind());
if (prototype->IsTheHole() && !function->shared()->is_generator()) {
prototype = NewFunctionPrototype(function);
}
initial_map->set_prototype(*prototype);
function->set_initial_map(*initial_map);
initial_map->set_constructor(*function);
} else {
ASSERT(!function->has_initial_map());
ASSERT(!function->has_prototype());
Handle<JSFunction> function = NewFunction(name, code, prototype);
Handle<Map> initial_map = NewMap(
type, instance_size, GetInitialFastElementsKind());
if (prototype->IsTheHole() && !function->shared()->is_generator()) {
prototype = NewFunctionPrototype(function);
}
initial_map->set_prototype(*prototype);
function->set_initial_map(*initial_map);
initial_map->set_constructor(*function);
return function;
}
......@@ -2060,43 +2052,44 @@ Handle<JSFunction> Factory::CreateApiFunction(
Handle<Code> code = isolate()->builtins()->HandleApiCall();
Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi();
int internal_field_count = 0;
if (!obj->instance_template()->IsUndefined()) {
Handle<ObjectTemplateInfo> instance_template =
Handle<ObjectTemplateInfo>(
ObjectTemplateInfo::cast(obj->instance_template()));
internal_field_count =
Smi::cast(instance_template->internal_field_count())->value();
}
// TODO(svenpanne) Kill ApiInstanceType and refactor things by generalizing
// JSObject::GetHeaderSize.
int instance_size = kPointerSize * internal_field_count;
InstanceType type;
switch (instance_type) {
case JavaScriptObject:
type = JS_OBJECT_TYPE;
instance_size += JSObject::kHeaderSize;
break;
case InnerGlobalObject:
type = JS_GLOBAL_OBJECT_TYPE;
instance_size += JSGlobalObject::kSize;
break;
case OuterGlobalObject:
type = JS_GLOBAL_PROXY_TYPE;
instance_size += JSGlobalProxy::kSize;
break;
default:
UNREACHABLE();
type = JS_OBJECT_TYPE; // Keep the compiler happy.
break;
}
Handle<JSFunction> result;
if (obj->remove_prototype()) {
result = NewFunction(empty_string(), code);
} else {
int internal_field_count = 0;
if (!obj->instance_template()->IsUndefined()) {
Handle<ObjectTemplateInfo> instance_template =
Handle<ObjectTemplateInfo>(
ObjectTemplateInfo::cast(obj->instance_template()));
internal_field_count =
Smi::cast(instance_template->internal_field_count())->value();
}
MaybeHandle<Object> maybe_prototype = prototype;
if (obj->remove_prototype()) maybe_prototype = MaybeHandle<Object>();
// TODO(svenpanne) Kill ApiInstanceType and refactor things by generalizing
// JSObject::GetHeaderSize.
int instance_size = kPointerSize * internal_field_count;
InstanceType type;
switch (instance_type) {
case JavaScriptObject:
type = JS_OBJECT_TYPE;
instance_size += JSObject::kHeaderSize;
break;
case InnerGlobalObject:
type = JS_GLOBAL_OBJECT_TYPE;
instance_size += JSGlobalObject::kSize;
break;
case OuterGlobalObject:
type = JS_GLOBAL_PROXY_TYPE;
instance_size += JSGlobalProxy::kSize;
break;
default:
UNREACHABLE();
type = JS_OBJECT_TYPE; // Keep the compiler happy.
break;
}
Handle<JSFunction> result = NewFunction(
maybe_prototype, Factory::empty_string(), type, instance_size, code);
result = NewFunction(prototype, empty_string(), type, instance_size, code);
}
result->shared()->set_length(obj->length());
Handle<Object> class_name(obj->class_name(), isolate());
......
......@@ -452,8 +452,9 @@ class Factory V8_FINAL {
void BecomeJSFunction(Handle<JSReceiver> object);
Handle<JSFunction> NewFunction(Handle<String> name,
MaybeHandle<Object> maybe_prototype,
MaybeHandle<Code> maybe_code);
MaybeHandle<Code> maybe_code,
MaybeHandle<Object> maybe_prototype =
MaybeHandle<Object>());
Handle<JSFunction> NewFunction(Handle<String> name);
Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
......@@ -461,7 +462,7 @@ class Factory V8_FINAL {
Handle<Context> context,
PretenureFlag pretenure = TENURED);
Handle<JSFunction> NewFunction(MaybeHandle<Object> maybe_prototype,
Handle<JSFunction> NewFunction(Handle<Object> maybe_prototype,
Handle<String> name,
InstanceType type,
int instance_size,
......
......@@ -2806,8 +2806,7 @@ static Handle<JSFunction> InstallBuiltin(Isolate* isolate,
Builtins::Name builtin_name) {
Handle<String> key = isolate->factory()->InternalizeUtf8String(name);
Handle<Code> code(isolate->builtins()->builtin(builtin_name));
Handle<JSFunction> optimized = isolate->factory()->NewFunction(
key, MaybeHandle<Object>(), code);
Handle<JSFunction> optimized = isolate->factory()->NewFunction(key, code);
optimized->shared()->DontAdaptArguments();
JSReceiver::SetProperty(holder, key, optimized, NONE, STRICT).Assert();
return optimized;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment