Commit 50436ad4 authored by verwaest@chromium.org's avatar verwaest@chromium.org

Merge NewFunction and NewFunctionWithPrototype

BUG=
R=ishell@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21233 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ed64101b
...@@ -350,22 +350,16 @@ static Handle<JSFunction> InstallFunction(Handle<JSObject> target, ...@@ -350,22 +350,16 @@ static Handle<JSFunction> InstallFunction(Handle<JSObject> target,
const char* name, const char* name,
InstanceType type, InstanceType type,
int instance_size, int instance_size,
Handle<JSObject> prototype, MaybeHandle<JSObject> maybe_prototype,
Builtins::Name call, Builtins::Name call,
bool install_initial_map,
bool set_instance_class_name) { bool set_instance_class_name) {
Isolate* isolate = target->GetIsolate(); Isolate* isolate = target->GetIsolate();
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 = prototype.is_null() Handle<JSFunction> function = factory->NewFunction(
? factory->NewFunction(internalized_name, call_code) maybe_prototype, internalized_name, type, instance_size, call_code,
: factory->NewFunctionWithPrototype(internalized_name, !maybe_prototype.is_null());
type,
instance_size,
prototype,
call_code,
install_initial_map);
PropertyAttributes attributes; PropertyAttributes attributes;
if (target->IsJSBuiltinsObject()) { if (target->IsJSBuiltinsObject()) {
attributes = attributes =
...@@ -845,13 +839,13 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, ...@@ -845,13 +839,13 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
// Install global Function object // Install global Function object
InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize,
empty_function, Builtins::kIllegal, true, true); empty_function, Builtins::kIllegal, true);
{ // --- A r r a y --- { // --- A r r a y ---
Handle<JSFunction> array_function = Handle<JSFunction> array_function =
InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize,
isolate->initial_object_prototype(), isolate->initial_object_prototype(),
Builtins::kArrayCode, true, true); Builtins::kArrayCode, true);
array_function->shared()->DontAdaptArguments(); array_function->shared()->DontAdaptArguments();
array_function->shared()->set_function_data(Smi::FromInt(kArrayCode)); array_function->shared()->set_function_data(Smi::FromInt(kArrayCode));
...@@ -895,7 +889,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, ...@@ -895,7 +889,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
Handle<JSFunction> number_fun = Handle<JSFunction> number_fun =
InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize,
isolate->initial_object_prototype(), isolate->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
native_context()->set_number_function(*number_fun); native_context()->set_number_function(*number_fun);
} }
...@@ -903,7 +897,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, ...@@ -903,7 +897,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
Handle<JSFunction> boolean_fun = Handle<JSFunction> boolean_fun =
InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize,
isolate->initial_object_prototype(), isolate->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
native_context()->set_boolean_function(*boolean_fun); native_context()->set_boolean_function(*boolean_fun);
} }
...@@ -911,7 +905,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, ...@@ -911,7 +905,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
Handle<JSFunction> string_fun = Handle<JSFunction> string_fun =
InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize, InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize,
isolate->initial_object_prototype(), isolate->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
string_fun->shared()->set_construct_stub( string_fun->shared()->set_construct_stub(
isolate->builtins()->builtin(Builtins::kStringConstructCode)); isolate->builtins()->builtin(Builtins::kStringConstructCode));
native_context()->set_string_function(*string_fun); native_context()->set_string_function(*string_fun);
...@@ -936,7 +930,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, ...@@ -936,7 +930,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
Handle<JSFunction> date_fun = Handle<JSFunction> date_fun =
InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize, InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize,
isolate->initial_object_prototype(), isolate->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
native_context()->set_date_function(*date_fun); native_context()->set_date_function(*date_fun);
} }
...@@ -947,7 +941,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, ...@@ -947,7 +941,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
Handle<JSFunction> regexp_fun = Handle<JSFunction> regexp_fun =
InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize,
isolate->initial_object_prototype(), isolate->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
native_context()->set_regexp_function(*regexp_fun); native_context()->set_regexp_function(*regexp_fun);
ASSERT(regexp_fun->has_initial_map()); ASSERT(regexp_fun->has_initial_map());
...@@ -1050,7 +1044,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, ...@@ -1050,7 +1044,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
global, "ArrayBuffer", JS_ARRAY_BUFFER_TYPE, global, "ArrayBuffer", JS_ARRAY_BUFFER_TYPE,
JSArrayBuffer::kSizeWithInternalFields, JSArrayBuffer::kSizeWithInternalFields,
isolate->initial_object_prototype(), isolate->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
native_context()->set_array_buffer_fun(*array_buffer_fun); native_context()->set_array_buffer_fun(*array_buffer_fun);
} }
...@@ -1074,21 +1068,18 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, ...@@ -1074,21 +1068,18 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
global, "DataView", JS_DATA_VIEW_TYPE, global, "DataView", JS_DATA_VIEW_TYPE,
JSDataView::kSizeWithInternalFields, JSDataView::kSizeWithInternalFields,
isolate->initial_object_prototype(), isolate->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
native_context()->set_data_view_fun(*data_view_fun); native_context()->set_data_view_fun(*data_view_fun);
} }
{ // -- W e a k M a p // -- W e a k M a p
InstallFunction(global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize, InstallFunction(global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize,
isolate->initial_object_prototype(), isolate->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
} // -- W e a k S e t
{ // -- W e a k S e t
InstallFunction(global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize, InstallFunction(global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize,
isolate->initial_object_prototype(), isolate->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
}
{ // --- arguments_boilerplate_ { // --- arguments_boilerplate_
// Make sure we can recognize argument objects at runtime. // Make sure we can recognize argument objects at runtime.
...@@ -1097,19 +1088,15 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, ...@@ -1097,19 +1088,15 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
Handle<String> arguments_string = factory->InternalizeOneByteString( Handle<String> arguments_string = factory->InternalizeOneByteString(
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<JSObject> prototype(
JSObject::cast(native_context()->object_function()->prototype()));
Handle<JSFunction> function = Handle<JSFunction> function = factory->NewFunction(
factory->NewFunctionWithPrototype(arguments_string, MaybeHandle<Object>(), arguments_string, JS_OBJECT_TYPE,
JS_OBJECT_TYPE, JSObject::kHeaderSize, code, false);
JSObject::kHeaderSize,
prototype,
code,
false);
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);
function->set_prototype_or_initial_map(
native_context()->object_function()->prototype());
Handle<JSObject> result = factory->NewJSObject(function); Handle<JSObject> result = factory->NewJSObject(function);
native_context()->set_sloppy_arguments_boilerplate(*result); native_context()->set_sloppy_arguments_boilerplate(*result);
...@@ -1295,7 +1282,7 @@ void Genesis::InstallTypedArray( ...@@ -1295,7 +1282,7 @@ void Genesis::InstallTypedArray(
Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); Handle<JSObject> global = Handle<JSObject>(native_context()->global_object());
Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE, Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE,
JSTypedArray::kSize, isolate()->initial_object_prototype(), JSTypedArray::kSize, isolate()->initial_object_prototype(),
Builtins::kIllegal, false, true); Builtins::kIllegal, true);
Handle<Map> initial_map = isolate()->factory()->NewMap( Handle<Map> initial_map = isolate()->factory()->NewMap(
JS_TYPED_ARRAY_TYPE, JS_TYPED_ARRAY_TYPE,
...@@ -1321,21 +1308,19 @@ void Genesis::InitializeExperimentalGlobal() { ...@@ -1321,21 +1308,19 @@ void Genesis::InitializeExperimentalGlobal() {
Handle<JSFunction> symbol_fun = Handle<JSFunction> symbol_fun =
InstallFunction(global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, InstallFunction(global, "Symbol", JS_VALUE_TYPE, JSValue::kSize,
isolate()->initial_object_prototype(), isolate()->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
native_context()->set_symbol_function(*symbol_fun); native_context()->set_symbol_function(*symbol_fun);
} }
if (FLAG_harmony_collections) { if (FLAG_harmony_collections) {
{ // -- M a p // -- M a p
InstallFunction(global, "Map", JS_MAP_TYPE, JSMap::kSize, InstallFunction(global, "Map", JS_MAP_TYPE, JSMap::kSize,
isolate()->initial_object_prototype(), isolate()->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
} // -- S e t
{ // -- S e t
InstallFunction(global, "Set", JS_SET_TYPE, JSSet::kSize, InstallFunction(global, "Set", JS_SET_TYPE, JSSet::kSize,
isolate()->initial_object_prototype(), isolate()->initial_object_prototype(),
Builtins::kIllegal, true, true); Builtins::kIllegal, true);
}
{ // -- S e t I t e r a t o r { // -- S e t I t e r a t o r
Handle<Map> map = isolate()->factory()->NewMap( Handle<Map> map = isolate()->factory()->NewMap(
JS_SET_ITERATOR_TYPE, JSSetIterator::kSize); JS_SET_ITERATOR_TYPE, JSSetIterator::kSize);
...@@ -1356,12 +1341,10 @@ void Genesis::InitializeExperimentalGlobal() { ...@@ -1356,12 +1341,10 @@ void Genesis::InitializeExperimentalGlobal() {
Handle<JSFunction> generator_function_prototype = Handle<JSFunction> generator_function_prototype =
InstallFunction(builtins, "GeneratorFunctionPrototype", InstallFunction(builtins, "GeneratorFunctionPrototype",
JS_FUNCTION_TYPE, JSFunction::kHeaderSize, JS_FUNCTION_TYPE, JSFunction::kHeaderSize,
generator_object_prototype, Builtins::kIllegal, generator_object_prototype, Builtins::kIllegal, false);
false, false);
InstallFunction(builtins, "GeneratorFunction", InstallFunction(builtins, "GeneratorFunction",
JS_FUNCTION_TYPE, JSFunction::kSize, JS_FUNCTION_TYPE, JSFunction::kSize,
generator_function_prototype, Builtins::kIllegal, generator_function_prototype, Builtins::kIllegal, false);
false, false);
// Create maps for generator functions and their prototypes. Store those // Create maps for generator functions and their prototypes. Store those
// maps in the native context. // maps in the native context.
...@@ -1600,14 +1583,10 @@ Handle<JSFunction> Genesis::InstallInternalArray( ...@@ -1600,14 +1583,10 @@ Handle<JSFunction> Genesis::InstallInternalArray(
// doesn't inherit from Object.prototype. // doesn't inherit from Object.prototype.
// To be used only for internal work by builtins. Instances // To be used only for internal work by builtins. Instances
// must not be leaked to user code. // must not be leaked to user code.
Handle<JSFunction> array_function = Handle<JSFunction> array_function = InstallFunction(
InstallFunction(builtins, builtins, name, JS_ARRAY_TYPE, JSArray::kSize,
name, isolate()->initial_object_prototype(), Builtins::kInternalArrayCode,
JS_ARRAY_TYPE, true);
JSArray::kSize,
isolate()->initial_object_prototype(),
Builtins::kInternalArrayCode,
true, true);
Handle<JSObject> prototype = Handle<JSObject> prototype =
factory()->NewJSObject(isolate()->object_function(), TENURED); factory()->NewJSObject(isolate()->object_function(), TENURED);
Accessors::FunctionSetPrototype(array_function, prototype); Accessors::FunctionSetPrototype(array_function, prototype);
...@@ -1703,10 +1682,9 @@ bool Genesis::InstallNatives() { ...@@ -1703,10 +1682,9 @@ bool Genesis::InstallNatives() {
{ // -- S c r i p t { // -- S c r i p t
// Builtin functions for Script. // Builtin functions for Script.
Handle<JSFunction> script_fun = Handle<JSFunction> script_fun = InstallFunction(
InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, builtins, "Script", JS_VALUE_TYPE, JSValue::kSize,
isolate()->initial_object_prototype(), isolate()->initial_object_prototype(), Builtins::kIllegal, false);
Builtins::kIllegal, false, false);
Handle<JSObject> prototype = Handle<JSObject> prototype =
factory()->NewJSObject(isolate()->object_function(), TENURED); factory()->NewJSObject(isolate()->object_function(), TENURED);
Accessors::FunctionSetPrototype(script_fun, prototype); Accessors::FunctionSetPrototype(script_fun, prototype);
...@@ -1829,11 +1807,9 @@ bool Genesis::InstallNatives() { ...@@ -1829,11 +1807,9 @@ bool Genesis::InstallNatives() {
// Builtin function for OpaqueReference -- a JSValue-based object, // Builtin function for OpaqueReference -- a JSValue-based object,
// that keeps its field isolated from JavaScript code. It may store // that keeps its field isolated from JavaScript code. It may store
// objects, that JavaScript code may not access. // objects, that JavaScript code may not access.
Handle<JSFunction> opaque_reference_fun = Handle<JSFunction> opaque_reference_fun = InstallFunction(
InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE, builtins, "OpaqueReference", JS_VALUE_TYPE, JSValue::kSize,
JSValue::kSize, isolate()->initial_object_prototype(), Builtins::kIllegal, false);
isolate()->initial_object_prototype(),
Builtins::kIllegal, false, false);
Handle<JSObject> prototype = Handle<JSObject> prototype =
factory()->NewJSObject(isolate()->object_function(), TENURED); factory()->NewJSObject(isolate()->object_function(), TENURED);
Accessors::FunctionSetPrototype(opaque_reference_fun, prototype); Accessors::FunctionSetPrototype(opaque_reference_fun, prototype);
...@@ -1892,14 +1868,12 @@ bool Genesis::InstallNatives() { ...@@ -1892,14 +1868,12 @@ bool Genesis::InstallNatives() {
// Install the call and the apply functions. // Install the call and the apply functions.
Handle<JSFunction> call = Handle<JSFunction> call =
InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize,
Handle<JSObject>::null(), MaybeHandle<JSObject>(),
Builtins::kFunctionCall, Builtins::kFunctionCall, false);
false, false);
Handle<JSFunction> apply = Handle<JSFunction> apply =
InstallFunction(proto, "apply", JS_OBJECT_TYPE, JSObject::kHeaderSize, InstallFunction(proto, "apply", JS_OBJECT_TYPE, JSObject::kHeaderSize,
Handle<JSObject>::null(), MaybeHandle<JSObject>(),
Builtins::kFunctionApply, Builtins::kFunctionApply, false);
false, false);
// Make sure that Function.prototype.call appears to be compiled. // Make sure that Function.prototype.call appears to be compiled.
// The code will never be called, but inline caching for call will // The code will never be called, but inline caching for call will
......
...@@ -1246,14 +1246,9 @@ Handle<JSFunction> Factory::NewFunction(MaybeHandle<Object> maybe_prototype, ...@@ -1246,14 +1246,9 @@ Handle<JSFunction> Factory::NewFunction(MaybeHandle<Object> maybe_prototype,
type != JS_OBJECT_TYPE || type != JS_OBJECT_TYPE ||
instance_size != JSObject::kHeaderSize) { instance_size != JSObject::kHeaderSize) {
Handle<Object> prototype = maybe_prototype.ToHandleChecked(); Handle<Object> prototype = maybe_prototype.ToHandleChecked();
Handle<Map> initial_map = NewMap(type, instance_size); Handle<Map> initial_map = NewMap(
if (prototype->IsJSObject()) { type, instance_size, GetInitialFastElementsKind());
JSObject::SetLocalPropertyIgnoreAttributes( if (prototype->IsTheHole() && !function->shared()->is_generator()) {
Handle<JSObject>::cast(prototype),
constructor_string(),
function,
DONT_ENUM).Assert();
} else if (!function->shared()->is_generator()) {
prototype = NewFunctionPrototype(function); prototype = NewFunctionPrototype(function);
} }
initial_map->set_prototype(*prototype); initial_map->set_prototype(*prototype);
...@@ -1278,30 +1273,6 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name, ...@@ -1278,30 +1273,6 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name,
} }
Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name,
InstanceType type,
int instance_size,
Handle<JSObject> prototype,
Handle<Code> code,
bool force_initial_map) {
// Allocate the function.
Handle<JSFunction> function = NewFunction(name, code, prototype);
if (force_initial_map ||
type != JS_OBJECT_TYPE ||
instance_size != JSObject::kHeaderSize) {
Handle<Map> initial_map = NewMap(type,
instance_size,
GetInitialFastElementsKind());
function->set_initial_map(*initial_map);
initial_map->set_constructor(*function);
}
JSFunction::SetPrototype(function, prototype);
return function;
}
Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
// Make sure to use globals from the function's context, since the function // Make sure to use globals from the function's context, since the function
// can be from a different context. // can be from a different context.
...@@ -2151,6 +2122,13 @@ Handle<JSFunction> Factory::CreateApiFunction( ...@@ -2151,6 +2122,13 @@ Handle<JSFunction> Factory::CreateApiFunction(
ASSERT(!result->has_prototype()); ASSERT(!result->has_prototype());
return result; return result;
} }
JSObject::SetLocalPropertyIgnoreAttributes(
handle(JSObject::cast(result->prototype())),
constructor_string(),
result,
DONT_ENUM).Assert();
// Down from here is only valid for API functions that can be used as a // Down from here is only valid for API functions that can be used as a
// constructor (don't set the "remove prototype" flag). // constructor (don't set the "remove prototype" flag).
......
...@@ -476,13 +476,6 @@ class Factory V8_FINAL { ...@@ -476,13 +476,6 @@ class Factory V8_FINAL {
Handle<Code> code, Handle<Code> code,
bool force_initial_map); bool force_initial_map);
Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
InstanceType type,
int instance_size,
Handle<JSObject> prototype,
Handle<Code> code,
bool force_initial_map);
// Create a serialized scope info. // Create a serialized scope info.
Handle<ScopeInfo> NewScopeInfo(int length); Handle<ScopeInfo> NewScopeInfo(int length);
......
...@@ -542,7 +542,7 @@ void JSGlobalProxy::JSGlobalProxyVerify() { ...@@ -542,7 +542,7 @@ void JSGlobalProxy::JSGlobalProxyVerify() {
VerifyObjectField(JSGlobalProxy::kNativeContextOffset); VerifyObjectField(JSGlobalProxy::kNativeContextOffset);
// Make sure that this object has no properties, elements. // Make sure that this object has no properties, elements.
CHECK_EQ(0, properties()->length()); CHECK_EQ(0, properties()->length());
CHECK(HasFastObjectElements()); CHECK(HasFastSmiElements());
CHECK_EQ(0, FixedArray::cast(elements())->length()); CHECK_EQ(0, FixedArray::cast(elements())->length());
} }
......
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