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, ...@@ -357,8 +357,11 @@ static Handle<JSFunction> InstallFunction(Handle<JSObject> target,
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Handle<String> internalized_name = factory->InternalizeUtf8String(name); Handle<String> internalized_name = factory->InternalizeUtf8String(name);
Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call)); Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call));
Handle<JSFunction> function = factory->NewFunction( Handle<JSObject> prototype;
maybe_prototype, internalized_name, type, instance_size, call_code); 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; PropertyAttributes attributes;
if (target->IsJSBuiltinsObject()) { if (target->IsJSBuiltinsObject()) {
attributes = attributes =
...@@ -486,8 +489,7 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { ...@@ -486,8 +489,7 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
Handle<String> empty_string = Handle<String> empty_string =
factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty")); factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty"));
Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction)); Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction));
Handle<JSFunction> empty_function = factory->NewFunction( Handle<JSFunction> empty_function = factory->NewFunction(empty_string, code);
empty_string, MaybeHandle<Object>(), code);
// --- E m p t y --- // --- E m p t y ---
Handle<String> source = factory->NewStringFromStaticAscii("() {}"); Handle<String> source = factory->NewStringFromStaticAscii("() {}");
...@@ -568,8 +570,7 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() { ...@@ -568,8 +570,7 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() {
STATIC_ASCII_VECTOR("ThrowTypeError")); STATIC_ASCII_VECTOR("ThrowTypeError"));
Handle<Code> code(isolate()->builtins()->builtin( Handle<Code> code(isolate()->builtins()->builtin(
Builtins::kStrictModePoisonPill)); Builtins::kStrictModePoisonPill));
throw_type_error_function = factory()->NewFunction( throw_type_error_function = factory()->NewFunction(name, code);
name, MaybeHandle<Object>(), code);
throw_type_error_function->set_map(native_context()->sloppy_function_map()); throw_type_error_function->set_map(native_context()->sloppy_function_map());
throw_type_error_function->shared()->DontAdaptArguments(); throw_type_error_function->shared()->DontAdaptArguments();
...@@ -1086,9 +1087,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, ...@@ -1086,9 +1087,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
STATIC_ASCII_VECTOR("Arguments")); STATIC_ASCII_VECTOR("Arguments"));
Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal)); Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal));
Handle<JSFunction> function = factory->NewFunction( Handle<JSFunction> function = factory->NewFunction(arguments_string, code);
MaybeHandle<Object>(), arguments_string, JS_OBJECT_TYPE,
JSObject::kHeaderSize, code);
ASSERT(!function->has_initial_map()); ASSERT(!function->has_initial_map());
function->shared()->set_instance_class_name(*arguments_string); function->shared()->set_instance_class_name(*arguments_string);
function->shared()->set_expected_nof_properties(2); function->shared()->set_expected_nof_properties(2);
......
...@@ -1203,8 +1203,8 @@ Handle<JSFunction> Factory::NewFunction(Handle<Map> map, ...@@ -1203,8 +1203,8 @@ Handle<JSFunction> Factory::NewFunction(Handle<Map> map,
Handle<JSFunction> Factory::NewFunction(Handle<String> name, 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); Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name);
ASSERT(info->strict_mode() == SLOPPY); ASSERT(info->strict_mode() == SLOPPY);
Handle<Code> code; Handle<Code> code;
...@@ -1225,34 +1225,26 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name, ...@@ -1225,34 +1225,26 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name,
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, Handle<String> name,
InstanceType type, InstanceType type,
int instance_size, int instance_size,
Handle<Code> code) { Handle<Code> code) {
// Allocate the function // Allocate the function
Handle<JSFunction> function = NewFunction(name, maybe_prototype, code); Handle<JSFunction> function = NewFunction(name, code, prototype);
if (!maybe_prototype.is_null() || Handle<Map> initial_map = NewMap(
type != JS_OBJECT_TYPE || type, instance_size, GetInitialFastElementsKind());
instance_size != JSObject::kHeaderSize) { if (prototype->IsTheHole() && !function->shared()->is_generator()) {
Handle<Object> prototype = maybe_prototype.ToHandleChecked(); prototype = NewFunctionPrototype(function);
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());
} }
initial_map->set_prototype(*prototype);
function->set_initial_map(*initial_map);
initial_map->set_constructor(*function);
return function; return function;
} }
...@@ -2060,43 +2052,44 @@ Handle<JSFunction> Factory::CreateApiFunction( ...@@ -2060,43 +2052,44 @@ Handle<JSFunction> Factory::CreateApiFunction(
Handle<Code> code = isolate()->builtins()->HandleApiCall(); Handle<Code> code = isolate()->builtins()->HandleApiCall();
Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi(); Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi();
int internal_field_count = 0; Handle<JSFunction> result;
if (!obj->instance_template()->IsUndefined()) { if (obj->remove_prototype()) {
Handle<ObjectTemplateInfo> instance_template = result = NewFunction(empty_string(), code);
Handle<ObjectTemplateInfo>( } else {
ObjectTemplateInfo::cast(obj->instance_template())); int internal_field_count = 0;
internal_field_count = if (!obj->instance_template()->IsUndefined()) {
Smi::cast(instance_template->internal_field_count())->value(); Handle<ObjectTemplateInfo> instance_template =
} Handle<ObjectTemplateInfo>(
ObjectTemplateInfo::cast(obj->instance_template()));
// TODO(svenpanne) Kill ApiInstanceType and refactor things by generalizing internal_field_count =
// JSObject::GetHeaderSize. Smi::cast(instance_template->internal_field_count())->value();
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;
}
MaybeHandle<Object> maybe_prototype = prototype; // TODO(svenpanne) Kill ApiInstanceType and refactor things by generalizing
if (obj->remove_prototype()) maybe_prototype = MaybeHandle<Object>(); // 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( result = NewFunction(prototype, empty_string(), type, instance_size, code);
maybe_prototype, Factory::empty_string(), type, instance_size, code); }
result->shared()->set_length(obj->length()); result->shared()->set_length(obj->length());
Handle<Object> class_name(obj->class_name(), isolate()); Handle<Object> class_name(obj->class_name(), isolate());
......
...@@ -452,8 +452,9 @@ class Factory V8_FINAL { ...@@ -452,8 +452,9 @@ class Factory V8_FINAL {
void BecomeJSFunction(Handle<JSReceiver> object); void BecomeJSFunction(Handle<JSReceiver> object);
Handle<JSFunction> NewFunction(Handle<String> name, 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> NewFunction(Handle<String> name);
Handle<JSFunction> NewFunctionFromSharedFunctionInfo( Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
...@@ -461,7 +462,7 @@ class Factory V8_FINAL { ...@@ -461,7 +462,7 @@ class Factory V8_FINAL {
Handle<Context> context, Handle<Context> context,
PretenureFlag pretenure = TENURED); PretenureFlag pretenure = TENURED);
Handle<JSFunction> NewFunction(MaybeHandle<Object> maybe_prototype, Handle<JSFunction> NewFunction(Handle<Object> maybe_prototype,
Handle<String> name, Handle<String> name,
InstanceType type, InstanceType type,
int instance_size, int instance_size,
......
...@@ -2806,8 +2806,7 @@ static Handle<JSFunction> InstallBuiltin(Isolate* isolate, ...@@ -2806,8 +2806,7 @@ static Handle<JSFunction> InstallBuiltin(Isolate* isolate,
Builtins::Name builtin_name) { Builtins::Name builtin_name) {
Handle<String> key = isolate->factory()->InternalizeUtf8String(name); Handle<String> key = isolate->factory()->InternalizeUtf8String(name);
Handle<Code> code(isolate->builtins()->builtin(builtin_name)); Handle<Code> code(isolate->builtins()->builtin(builtin_name));
Handle<JSFunction> optimized = isolate->factory()->NewFunction( Handle<JSFunction> optimized = isolate->factory()->NewFunction(key, code);
key, MaybeHandle<Object>(), code);
optimized->shared()->DontAdaptArguments(); optimized->shared()->DontAdaptArguments();
JSReceiver::SetProperty(holder, key, optimized, NONE, STRICT).Assert(); JSReceiver::SetProperty(holder, key, optimized, NONE, STRICT).Assert();
return optimized; 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