From a773cd7271fe6f559475b363d192aa80f74b1a51 Mon Sep 17 00:00:00 2001 From: "verwaest@chromium.org" Date: Fri, 9 May 2014 16:39:33 +0000 Subject: [PATCH] Replace NewFunctionWithPrototype(name, prototype) by NewFunction(name) BUG= R=ishell@chromium.org Review URL: https://codereview.chromium.org/268063008 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21235 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/bootstrapper.cc | 15 +++++++-------- src/factory.cc | 22 +++++++++------------- src/factory.h | 9 +++------ src/runtime.cc | 9 ++------- test/cctest/test-alloc.cc | 4 ++-- test/cctest/test-heap.cc | 19 ++++--------------- test/cctest/test-mark-compact.cc | 6 +----- test/cctest/test-weakmaps.cc | 8 ++++---- test/cctest/test-weaksets.cc | 8 ++++---- 9 files changed, 36 insertions(+), 64 deletions(-) diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 994a50f..f3a9330 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -461,8 +461,7 @@ Handle Genesis::CreateEmptyFunction(Isolate* isolate) { Handle object_name = factory->Object_string(); { // --- O b j e c t --- - Handle object_fun = factory->NewFunctionWithPrototype( - object_name, factory->null_value()); + Handle object_fun = factory->NewFunction(object_name); Handle object_function_map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); object_fun->set_initial_map(*object_function_map); @@ -488,7 +487,8 @@ Handle Genesis::CreateEmptyFunction(Isolate* isolate) { Handle empty_string = factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty")); Handle code(isolate->builtins()->builtin(Builtins::kEmptyFunction)); - Handle empty_function = factory->NewFunction(empty_string, code); + Handle empty_function = factory->NewFunction( + empty_string, MaybeHandle(), code); // --- E m p t y --- Handle source = factory->NewStringFromStaticAscii("() {}"); @@ -569,7 +569,8 @@ Handle Genesis::GetThrowTypeErrorFunction() { STATIC_ASCII_VECTOR("ThrowTypeError")); Handle code(isolate()->builtins()->builtin( Builtins::kStrictModePoisonPill)); - throw_type_error_function = factory()->NewFunction(name, code); + throw_type_error_function = factory()->NewFunction( + name, MaybeHandle(), code); throw_type_error_function->set_map(native_context()->sloppy_function_map()); throw_type_error_function->shared()->DontAdaptArguments(); @@ -1026,8 +1027,7 @@ void Genesis::InitializeGlobal(Handle inner_global, { // -- J S O N Handle name = factory->InternalizeUtf8String("JSON"); - Handle cons = factory->NewFunctionWithPrototype( - name, factory->the_hole_value()); + Handle cons = factory->NewFunction(name); JSFunction::SetInstancePrototype(cons, Handle(native_context()->initial_object_prototype(), isolate)); cons->SetInstanceClassName(*name); @@ -1669,8 +1669,7 @@ bool Genesis::InstallNatives() { set_builtins(*builtins); // Create a bridge function that has context in the native context. - Handle bridge = factory()->NewFunctionWithPrototype( - factory()->empty_string(), factory()->undefined_value()); + Handle bridge = factory()->NewFunction(factory()->empty_string()); ASSERT(bridge->context() == *isolate()->native_context()); // Allocate the builtins context. diff --git a/src/factory.cc b/src/factory.cc index a8035d8..0c79e6c 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1203,11 +1203,14 @@ Handle Factory::NewFunction(Handle map, Handle Factory::NewFunction(Handle name, - Handle code, - MaybeHandle maybe_prototype) { + MaybeHandle maybe_prototype, + MaybeHandle maybe_code) { Handle info = NewSharedFunctionInfo(name); ASSERT(info->strict_mode() == SLOPPY); - info->set_code(*code); + Handle code; + if (maybe_code.ToHandle(&code)) { + info->set_code(*code); + } Handle context(isolate()->context()->native_context()); Handle map = maybe_prototype.is_null() ? isolate()->sloppy_function_without_prototype_map() @@ -1221,15 +1224,8 @@ Handle Factory::NewFunction(Handle name, } -Handle Factory::NewFunctionWithPrototype(Handle name, - Handle prototype) { - Handle info = NewSharedFunctionInfo(name); - ASSERT(info->strict_mode() == SLOPPY); - Handle context(isolate()->context()->native_context()); - Handle map = isolate()->sloppy_function_map(); - Handle result = NewFunction(map, info, context); - result->set_prototype_or_initial_map(*prototype); - return result; +Handle Factory::NewFunction(Handle name) { + return NewFunction(name, the_hole_value(), MaybeHandle()); } @@ -1240,7 +1236,7 @@ Handle Factory::NewFunction(MaybeHandle maybe_prototype, Handle code, bool force_initial_map) { // Allocate the function - Handle function = NewFunction(name, code, maybe_prototype); + Handle function = NewFunction(name, maybe_prototype, code); if (force_initial_map || type != JS_OBJECT_TYPE || diff --git a/src/factory.h b/src/factory.h index 4ec24b2..87eb61a 100644 --- a/src/factory.h +++ b/src/factory.h @@ -452,12 +452,9 @@ class Factory V8_FINAL { void BecomeJSFunction(Handle object); Handle NewFunction(Handle name, - Handle code, - MaybeHandle maybe_prototype = - MaybeHandle()); - - Handle NewFunctionWithPrototype(Handle name, - Handle prototype); + MaybeHandle maybe_prototype, + MaybeHandle maybe_code); + Handle NewFunction(Handle name); Handle NewFunctionFromSharedFunctionInfo( Handle function_info, diff --git a/src/runtime.cc b/src/runtime.cc index 130afad..e22df0e 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -2806,13 +2806,8 @@ static Handle InstallBuiltin(Isolate* isolate, Builtins::Name builtin_name) { Handle key = isolate->factory()->InternalizeUtf8String(name); Handle code(isolate->builtins()->builtin(builtin_name)); - Handle optimized = - isolate->factory()->NewFunction(MaybeHandle(), - key, - JS_OBJECT_TYPE, - JSObject::kHeaderSize, - code, - false); + Handle optimized = isolate->factory()->NewFunction( + key, MaybeHandle(), code); optimized->shared()->DontAdaptArguments(); JSReceiver::SetProperty(holder, key, optimized, NONE, STRICT).Assert(); return optimized; diff --git a/test/cctest/test-alloc.cc b/test/cctest/test-alloc.cc index 7a213ae..8c5508b 100644 --- a/test/cctest/test-alloc.cc +++ b/test/cctest/test-alloc.cc @@ -137,8 +137,8 @@ TEST(StressJS) { v8::HandleScope scope(CcTest::isolate()); v8::Handle env = v8::Context::New(CcTest::isolate()); env->Enter(); - Handle function = factory->NewFunctionWithPrototype( - factory->function_string(), factory->null_value()); + Handle function = factory->NewFunction( + factory->function_string()); // Force the creation of an initial map and set the code to // something empty. factory->NewJSObject(function); diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index ee9343a..81a53ad 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -261,11 +261,7 @@ TEST(GarbageCollection) { { HandleScope inner_scope(isolate); // Allocate a function and keep it in global object's property. - Handle function = factory->NewFunctionWithPrototype( - name, factory->undefined_value()); - Handle initial_map = - factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); - function->set_initial_map(*initial_map); + Handle function = factory->NewFunction(name); JSReceiver::SetProperty(global, name, function, NONE, SLOPPY).Check(); // Allocate an object. Unrooted after leaving the scope. Handle obj = factory->NewJSObject(function); @@ -624,11 +620,7 @@ TEST(FunctionAllocation) { v8::HandleScope sc(CcTest::isolate()); Handle name = factory->InternalizeUtf8String("theFunction"); - Handle function = factory->NewFunctionWithPrototype( - name, factory->undefined_value()); - Handle initial_map = - factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); - function->set_initial_map(*initial_map); + Handle function = factory->NewFunction(name); Handle twenty_three(Smi::FromInt(23), isolate); Handle twenty_four(Smi::FromInt(24), isolate); @@ -723,14 +715,11 @@ TEST(JSObjectMaps) { v8::HandleScope sc(CcTest::isolate()); Handle name = factory->InternalizeUtf8String("theFunction"); - Handle function = factory->NewFunctionWithPrototype( - name, factory->undefined_value()); - Handle initial_map = - factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); - function->set_initial_map(*initial_map); + Handle function = factory->NewFunction(name); Handle prop_name = factory->InternalizeUtf8String("theSlot"); Handle obj = factory->NewJSObject(function); + Handle initial_map(function->initial_map()); // Set a propery Handle twenty_three(Smi::FromInt(23), isolate); diff --git a/test/cctest/test-mark-compact.cc b/test/cctest/test-mark-compact.cc index c7f5bc6..08b1c71 100644 --- a/test/cctest/test-mark-compact.cc +++ b/test/cctest/test-mark-compact.cc @@ -156,11 +156,7 @@ TEST(MarkCompactCollector) { { HandleScope scope(isolate); // allocate a garbage Handle func_name = factory->InternalizeUtf8String("theFunction"); - Handle function = factory->NewFunctionWithPrototype( - func_name, factory->undefined_value()); - Handle initial_map = factory->NewMap( - JS_OBJECT_TYPE, JSObject::kHeaderSize); - function->set_initial_map(*initial_map); + Handle function = factory->NewFunction(func_name); JSReceiver::SetProperty(global, func_name, function, NONE, SLOPPY).Check(); factory->NewJSObject(function); diff --git a/test/cctest/test-weakmaps.cc b/test/cctest/test-weakmaps.cc index 14a5e02..369dae5 100644 --- a/test/cctest/test-weakmaps.cc +++ b/test/cctest/test-weakmaps.cc @@ -185,8 +185,8 @@ TEST(Regress2060a) { Factory* factory = isolate->factory(); Heap* heap = isolate->heap(); HandleScope scope(isolate); - Handle function = factory->NewFunctionWithPrototype( - factory->function_string(), factory->null_value()); + Handle function = factory->NewFunction( + factory->function_string()); Handle key = factory->NewJSObject(function); Handle weakmap = AllocateJSWeakMap(isolate); @@ -225,8 +225,8 @@ TEST(Regress2060b) { Factory* factory = isolate->factory(); Heap* heap = isolate->heap(); HandleScope scope(isolate); - Handle function = factory->NewFunctionWithPrototype( - factory->function_string(), factory->null_value()); + Handle function = factory->NewFunction( + factory->function_string()); // Start second old-space page so that keys land on evacuation candidate. Page* first_page = heap->old_pointer_space()->anchor()->next_page(); diff --git a/test/cctest/test-weaksets.cc b/test/cctest/test-weaksets.cc index a3a9478..a83e16b 100644 --- a/test/cctest/test-weaksets.cc +++ b/test/cctest/test-weaksets.cc @@ -185,8 +185,8 @@ TEST(WeakSet_Regress2060a) { Factory* factory = isolate->factory(); Heap* heap = isolate->heap(); HandleScope scope(isolate); - Handle function = factory->NewFunctionWithPrototype( - factory->function_string(), factory->null_value()); + Handle function = factory->NewFunction( + factory->function_string()); Handle key = factory->NewJSObject(function); Handle weakset = AllocateJSWeakSet(isolate); @@ -225,8 +225,8 @@ TEST(WeakSet_Regress2060b) { Factory* factory = isolate->factory(); Heap* heap = isolate->heap(); HandleScope scope(isolate); - Handle function = factory->NewFunctionWithPrototype( - factory->function_string(), factory->null_value()); + Handle function = factory->NewFunction( + factory->function_string()); // Start second old-space page so that keys land on evacuation candidate. Page* first_page = heap->old_pointer_space()->anchor()->next_page(); -- 2.7.4