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

Set code on the SharedFunctionInfo before creating the function.

BUG=
R=ishell@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20873 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent af051411
......@@ -355,14 +355,14 @@ 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 = prototype.is_null() ?
factory->NewFunctionWithoutPrototype(internalized_name, call_code) :
factory->NewFunctionWithPrototype(internalized_name,
type,
instance_size,
prototype,
call_code,
install_initial_map);
Handle<JSFunction> function = prototype.is_null()
? factory->NewFunction(internalized_name, call_code)
: factory->NewFunctionWithPrototype(internalized_name,
type,
instance_size,
prototype,
call_code,
install_initial_map);
PropertyAttributes attributes;
if (target->IsJSBuiltinsObject()) {
attributes =
......@@ -458,8 +458,8 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
Handle<String> object_name = factory->Object_string();
{ // --- O b j e c t ---
Handle<JSFunction> object_fun =
factory->NewFunction(object_name, factory->null_value());
Handle<JSFunction> object_fun = factory->NewFunctionWithPrototype(
object_name, factory->null_value());
Handle<Map> object_function_map =
factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
object_fun->set_initial_map(*object_function_map);
......@@ -485,8 +485,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->NewFunctionWithoutPrototype(empty_string, code);
Handle<JSFunction> empty_function = factory->NewFunction(empty_string, code);
// --- E m p t y ---
Handle<String> source = factory->NewStringFromStaticAscii("() {}");
......@@ -564,8 +563,7 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() {
STATIC_ASCII_VECTOR("ThrowTypeError"));
Handle<Code> code(isolate()->builtins()->builtin(
Builtins::kStrictModePoisonPill));
throw_type_error_function =
factory()->NewFunctionWithoutPrototype(name, 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();
......@@ -1016,8 +1014,8 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
{ // -- J S O N
Handle<String> name = factory->InternalizeUtf8String("JSON");
Handle<JSFunction> cons = factory->NewFunction(name,
factory->the_hole_value());
Handle<JSFunction> cons = factory->NewFunctionWithPrototype(
name, factory->the_hole_value());
JSFunction::SetInstancePrototype(cons,
Handle<Object>(native_context()->initial_object_prototype(), isolate));
cons->SetInstanceClassName(*name);
......@@ -1063,11 +1061,9 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
// class_name equals 'Arguments'.
Handle<String> arguments_string = factory->InternalizeOneByteString(
STATIC_ASCII_VECTOR("Arguments"));
Handle<Code> code = Handle<Code>(
isolate->builtins()->builtin(Builtins::kIllegal));
Handle<JSObject> prototype =
Handle<JSObject>(
JSObject::cast(native_context()->object_function()->prototype()));
Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal));
Handle<JSObject> prototype(
JSObject::cast(native_context()->object_function()->prototype()));
Handle<JSFunction> function =
factory->NewFunctionWithPrototype(arguments_string,
......@@ -1662,9 +1658,8 @@ bool Genesis::InstallNatives() {
set_builtins(*builtins);
// Create a bridge function that has context in the native context.
Handle<JSFunction> bridge =
factory()->NewFunction(factory()->empty_string(),
factory()->undefined_value());
Handle<JSFunction> bridge = factory()->NewFunctionWithPrototype(
factory()->empty_string(), factory()->undefined_value());
ASSERT(bridge->context() == *isolate()->native_context());
// Allocate the builtins context.
......
......@@ -1273,12 +1273,7 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name,
Handle<Code> code,
bool force_initial_map) {
// Allocate the function
Handle<JSFunction> function = NewFunction(name, the_hole_value());
// Set up the code pointer in both the shared function info and in
// the function itself.
function->shared()->set_code(*code);
function->set_code(*code);
Handle<JSFunction> function = NewFunction(name, code, the_hole_value());
if (force_initial_map ||
type != JS_OBJECT_TYPE ||
......@@ -1304,12 +1299,7 @@ Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name,
Handle<Code> code,
bool force_initial_map) {
// Allocate the function.
Handle<JSFunction> function = NewFunction(name, prototype);
// Set up the code pointer in both the shared function info and in
// the function itself.
function->shared()->set_code(*code);
function->set_code(*code);
Handle<JSFunction> function = NewFunction(name, code, prototype);
if (force_initial_map ||
type != JS_OBJECT_TYPE ||
......@@ -2041,19 +2031,20 @@ Handle<JSFunction> Factory::NewFunction(Handle<SharedFunctionInfo> info,
Handle<JSFunction> Factory::NewFunction(Handle<String> name,
Handle<Object> prototype) {
Handle<Code> code,
MaybeHandle<Object> maybe_prototype) {
Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name);
info->set_code(*code);
Handle<Context> context(isolate()->context()->native_context());
return NewFunction(info, context, prototype);
return NewFunction(info, context, maybe_prototype);
}
Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name,
Handle<Code> code) {
Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name,
Handle<Object> prototype) {
Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name);
info->set_code(*code);
Handle<Context> context(isolate()->context()->native_context());
return NewFunction(info, context, MaybeHandle<Object>());
return NewFunction(info, context, prototype);
}
......
......@@ -442,7 +442,12 @@ class Factory V8_FINAL {
void BecomeJSFunction(Handle<JSReceiver> object);
Handle<JSFunction> NewFunction(Handle<String> name,
Handle<Object> prototype);
Handle<Code> code,
MaybeHandle<Object> maybe_prototype =
MaybeHandle<Object>());
Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
Handle<Object> prototype);
Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Handle<SharedFunctionInfo> function_info,
......@@ -462,9 +467,6 @@ class Factory V8_FINAL {
Handle<Code> code,
bool force_initial_map);
Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
Handle<Code> code);
// Create a serialized scope info.
Handle<ScopeInfo> NewScopeInfo(int length);
......
......@@ -122,8 +122,8 @@ TEST(StressJS) {
v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate());
env->Enter();
Handle<JSFunction> function =
factory->NewFunction(factory->function_string(), factory->null_value());
Handle<JSFunction> function = factory->NewFunctionWithPrototype(
factory->function_string(), factory->null_value());
// Force the creation of an initial map and set the code to
// something empty.
factory->NewJSObject(function);
......
......@@ -267,8 +267,8 @@ TEST(GarbageCollection) {
{
HandleScope inner_scope(isolate);
// Allocate a function and keep it in global object's property.
Handle<JSFunction> function =
factory->NewFunction(name, factory->undefined_value());
Handle<JSFunction> function = factory->NewFunctionWithPrototype(
name, factory->undefined_value());
Handle<Map> initial_map =
factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
function->set_initial_map(*initial_map);
......@@ -626,8 +626,8 @@ TEST(FunctionAllocation) {
v8::HandleScope sc(CcTest::isolate());
Handle<String> name = factory->InternalizeUtf8String("theFunction");
Handle<JSFunction> function =
factory->NewFunction(name, factory->undefined_value());
Handle<JSFunction> function = factory->NewFunctionWithPrototype(
name, factory->undefined_value());
Handle<Map> initial_map =
factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
function->set_initial_map(*initial_map);
......@@ -725,8 +725,8 @@ TEST(JSObjectMaps) {
v8::HandleScope sc(CcTest::isolate());
Handle<String> name = factory->InternalizeUtf8String("theFunction");
Handle<JSFunction> function =
factory->NewFunction(name, factory->undefined_value());
Handle<JSFunction> function = factory->NewFunctionWithPrototype(
name, factory->undefined_value());
Handle<Map> initial_map =
factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
function->set_initial_map(*initial_map);
......
......@@ -159,7 +159,7 @@ TEST(MarkCompactCollector) {
{ HandleScope scope(isolate);
// allocate a garbage
Handle<String> func_name = factory->InternalizeUtf8String("theFunction");
Handle<JSFunction> function = factory->NewFunction(
Handle<JSFunction> function = factory->NewFunctionWithPrototype(
func_name, factory->undefined_value());
Handle<Map> initial_map = factory->NewMap(
JS_OBJECT_TYPE, JSObject::kHeaderSize);
......
......@@ -187,8 +187,8 @@ TEST(Regress2060a) {
Factory* factory = isolate->factory();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
Handle<JSFunction> function =
factory->NewFunction(factory->function_string(), factory->null_value());
Handle<JSFunction> function = factory->NewFunctionWithPrototype(
factory->function_string(), factory->null_value());
Handle<JSObject> key = factory->NewJSObject(function);
Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
......@@ -227,8 +227,8 @@ TEST(Regress2060b) {
Factory* factory = isolate->factory();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
Handle<JSFunction> function =
factory->NewFunction(factory->function_string(), factory->null_value());
Handle<JSFunction> function = factory->NewFunctionWithPrototype(
factory->function_string(), factory->null_value());
// Start second old-space page so that keys land on evacuation candidate.
Page* first_page = heap->old_pointer_space()->anchor()->next_page();
......
......@@ -187,8 +187,8 @@ TEST(WeakSet_Regress2060a) {
Factory* factory = isolate->factory();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
Handle<JSFunction> function =
factory->NewFunction(factory->function_string(), factory->null_value());
Handle<JSFunction> function = factory->NewFunctionWithPrototype(
factory->function_string(), factory->null_value());
Handle<JSObject> key = factory->NewJSObject(function);
Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate);
......@@ -227,8 +227,8 @@ TEST(WeakSet_Regress2060b) {
Factory* factory = isolate->factory();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
Handle<JSFunction> function =
factory->NewFunction(factory->function_string(), factory->null_value());
Handle<JSFunction> function = factory->NewFunctionWithPrototype(
factory->function_string(), factory->null_value());
// Start second old-space page so that keys land on evacuation candidate.
Page* first_page = heap->old_pointer_space()->anchor()->next_page();
......
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