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