From: verwaest@chromium.org Date: Fri, 9 May 2014 17:39:54 +0000 (+0000) Subject: Rename NewFunction without prototype to NewFunctionWithoutPrototype X-Git-Tag: upstream/4.7.83~9185 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e1c86f820794b329c56181711ca7cbbf5fa45de9;p=platform%2Fupstream%2Fv8.git Rename NewFunction without prototype to NewFunctionWithoutPrototype BUG= R=ishell@chromium.org Review URL: https://codereview.chromium.org/270573003 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21241 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index f464bdb..c35120d 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -358,9 +358,9 @@ static Handle InstallFunction(Handle target, Handle call_code = Handle(isolate->builtins()->builtin(call)); Handle prototype; Handle function = maybe_prototype.ToHandle(&prototype) - ? factory->NewFunction(prototype, internalized_name, type, - instance_size, call_code) - : factory->NewFunction(internalized_name, call_code); + ? factory->NewFunction(internalized_name, call_code, prototype, + type, instance_size) + : factory->NewFunctionWithoutPrototype(internalized_name, call_code); PropertyAttributes attributes; if (target->IsJSBuiltinsObject()) { attributes = @@ -488,7 +488,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->NewFunctionWithoutPrototype( + empty_string, code); // --- E m p t y --- Handle source = factory->NewStringFromStaticAscii("() {}"); @@ -569,7 +570,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()->NewFunctionWithoutPrototype( + name, code); throw_type_error_function->set_map(native_context()->sloppy_function_map()); throw_type_error_function->shared()->DontAdaptArguments(); @@ -708,7 +710,7 @@ Handle Genesis::CreateNewGlobals( Handle code = Handle(isolate()->builtins()->builtin( Builtins::kIllegal)); js_global_function = factory()->NewFunction( - name, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize, code); + name, code, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize); // Change the constructor property of the prototype of the // hidden global function to refer to the Object function. Handle prototype = @@ -741,7 +743,7 @@ Handle Genesis::CreateNewGlobals( Handle code = Handle(isolate()->builtins()->builtin( Builtins::kIllegal)); global_proxy_function = factory()->NewFunction( - name, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize, code); + name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); } else { Handle data = v8::Utils::OpenHandle(*global_template); @@ -1084,7 +1086,8 @@ void Genesis::InitializeGlobal(Handle inner_global, STATIC_ASCII_VECTOR("Arguments")); Handle code(isolate->builtins()->builtin(Builtins::kIllegal)); - Handle function = factory->NewFunction(arguments_string, code); + Handle function = factory->NewFunctionWithoutPrototype( + arguments_string, code); ASSERT(!function->has_initial_map()); function->shared()->set_instance_class_name(*arguments_string); function->shared()->set_expected_nof_properties(2); @@ -1224,8 +1227,8 @@ void Genesis::InitializeGlobal(Handle inner_global, Handle code = Handle( isolate->builtins()->builtin(Builtins::kIllegal)); Handle context_extension_fun = factory->NewFunction( - factory->empty_string(), JS_CONTEXT_EXTENSION_OBJECT_TYPE, - JSObject::kHeaderSize, code); + factory->empty_string(), code, JS_CONTEXT_EXTENSION_OBJECT_TYPE, + JSObject::kHeaderSize); Handle name = factory->InternalizeOneByteString( STATIC_ASCII_VECTOR("context_extension")); @@ -1240,7 +1243,7 @@ void Genesis::InitializeGlobal(Handle inner_global, Handle(isolate->builtins()->builtin( Builtins::kHandleApiCallAsFunction)); Handle delegate = factory->NewFunction( - factory->empty_string(), JS_OBJECT_TYPE, JSObject::kHeaderSize, code); + factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); native_context()->set_call_as_function_delegate(*delegate); delegate->shared()->DontAdaptArguments(); } @@ -1251,7 +1254,7 @@ void Genesis::InitializeGlobal(Handle inner_global, Handle(isolate->builtins()->builtin( Builtins::kHandleApiCallAsConstructor)); Handle delegate = factory->NewFunction( - factory->empty_string(), JS_OBJECT_TYPE, JSObject::kHeaderSize, code); + factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); native_context()->set_call_as_constructor_delegate(*delegate); delegate->shared()->DontAdaptArguments(); } @@ -1611,8 +1614,8 @@ bool Genesis::InstallNatives() { Handle code = Handle( isolate()->builtins()->builtin(Builtins::kIllegal)); Handle builtins_fun = factory()->NewFunction( - factory()->empty_string(), JS_BUILTINS_OBJECT_TYPE, - JSBuiltinsObject::kSize, code); + factory()->empty_string(), code, JS_BUILTINS_OBJECT_TYPE, + JSBuiltinsObject::kSize); Handle name = factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("builtins")); diff --git a/src/factory.cc b/src/factory.cc index 8ecbdbf..cfcb2f1 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1202,38 +1202,47 @@ Handle Factory::NewFunction(Handle map, } -Handle Factory::NewFunction(Handle name, - MaybeHandle maybe_code, - MaybeHandle maybe_prototype) { - Handle info = NewSharedFunctionInfo(name); - ASSERT(info->strict_mode() == SLOPPY); - Handle code; - if (maybe_code.ToHandle(&code)) { - info->set_code(*code); - } +Handle Factory::NewFunction(Handle map, + Handle name, + MaybeHandle code) { Handle context(isolate()->context()->native_context()); - Handle map = maybe_prototype.is_null() - ? isolate()->sloppy_function_without_prototype_map() - : isolate()->sloppy_function_map(); - Handle result = NewFunction(map, info, context); - Handle prototype; - if (maybe_prototype.ToHandle(&prototype)) { - result->set_prototype_or_initial_map(*prototype); - } - return result; + Handle info = NewSharedFunctionInfo(name, code); + ASSERT((info->strict_mode() == SLOPPY) && + (map.is_identical_to(isolate()->sloppy_function_map()) || + map.is_identical_to( + isolate()->sloppy_function_without_prototype_map()))); + return NewFunction(map, info, context); } Handle Factory::NewFunction(Handle name) { - return NewFunction(name, MaybeHandle(), the_hole_value()); + return NewFunction( + isolate()->sloppy_function_map(), name, MaybeHandle()); } -Handle Factory::NewFunction(Handle prototype, - Handle name, +Handle Factory::NewFunctionWithoutPrototype(Handle name, + Handle code) { + return NewFunction( + isolate()->sloppy_function_without_prototype_map(), name, code); +} + + +Handle Factory::NewFunction(Handle name, + Handle code, + Handle prototype) { + Handle result = NewFunction( + isolate()->sloppy_function_map(), name, code); + result->set_prototype_or_initial_map(*prototype); + return result; +} + + +Handle Factory::NewFunction(Handle name, + Handle code, + Handle prototype, InstanceType type, - int instance_size, - Handle code) { + int instance_size) { // Allocate the function Handle function = NewFunction(name, code, prototype); @@ -1251,10 +1260,10 @@ Handle Factory::NewFunction(Handle prototype, Handle Factory::NewFunction(Handle name, + Handle code, InstanceType type, - int instance_size, - Handle code) { - return NewFunction(the_hole_value(), name, type, instance_size, code); + int instance_size) { + return NewFunction(name, code, the_hole_value(), type, instance_size); } @@ -1753,7 +1762,7 @@ void Factory::ReinitializeJSReceiver(Handle object, OneByteStringKey key(STATIC_ASCII_VECTOR(""), heap->HashSeed()); Handle name = InternalizeStringWithKey(&key); - shared = NewSharedFunctionInfo(name); + shared = NewSharedFunctionInfo(name, MaybeHandle()); } // In order to keep heap in consistent state there must be no allocations @@ -1848,8 +1857,7 @@ Handle Factory::NewSharedFunctionInfo( Handle code, Handle scope_info, Handle feedback_vector) { - Handle shared = NewSharedFunctionInfo(name); - shared->set_code(*code); + Handle shared = NewSharedFunctionInfo(name, code); shared->set_scope_info(*scope_info); shared->set_feedback_vector(*feedback_vector); int literals_array_size = number_of_literals; @@ -1890,15 +1898,20 @@ Handle Factory::NewJSMessageObject( } -Handle Factory::NewSharedFunctionInfo(Handle name) { +Handle Factory::NewSharedFunctionInfo( + Handle name, + MaybeHandle maybe_code) { Handle map = shared_function_info_map(); Handle share = New(map, OLD_POINTER_SPACE); // Set pointer fields. share->set_name(*name); - Code* illegal = isolate()->builtins()->builtin(Builtins::kIllegal); - share->set_code(illegal); + Handle code; + if (!maybe_code.ToHandle(&code)) { + code = handle(isolate()->builtins()->builtin(Builtins::kIllegal)); + } + share->set_code(*code); share->set_optimized_code_map(Smi::FromInt(0)); share->set_scope_info(ScopeInfo::Empty(isolate())); Code* construct_stub = @@ -2054,7 +2067,7 @@ Handle Factory::CreateApiFunction( Handle result; if (obj->remove_prototype()) { - result = NewFunction(empty_string(), code); + result = NewFunctionWithoutPrototype(empty_string(), code); } else { int internal_field_count = 0; if (!obj->instance_template()->IsUndefined()) { @@ -2088,7 +2101,7 @@ Handle Factory::CreateApiFunction( break; } - result = NewFunction(prototype, empty_string(), type, instance_size, code); + result = NewFunction(empty_string(), code, prototype, type, instance_size); } result->shared()->set_length(obj->length()); diff --git a/src/factory.h b/src/factory.h index 02d0044..45d5401 100644 --- a/src/factory.h +++ b/src/factory.h @@ -452,25 +452,26 @@ class Factory V8_FINAL { void BecomeJSFunction(Handle object); Handle NewFunction(Handle name, - MaybeHandle maybe_code, - MaybeHandle maybe_prototype = - MaybeHandle()); + Handle code, + Handle prototype); Handle NewFunction(Handle name); + Handle NewFunctionWithoutPrototype(Handle name, + Handle code); Handle NewFunctionFromSharedFunctionInfo( Handle function_info, Handle context, PretenureFlag pretenure = TENURED); - Handle NewFunction(Handle maybe_prototype, - Handle name, + Handle NewFunction(Handle name, + Handle code, + Handle prototype, InstanceType type, - int instance_size, - Handle code); + int instance_size); Handle NewFunction(Handle name, + Handle code, InstanceType type, - int instance_size, - Handle code); + int instance_size); // Create a serialized scope info. Handle NewScopeInfo(int length); @@ -597,7 +598,8 @@ class Factory V8_FINAL { Handle code, Handle scope_info, Handle feedback_vector); - Handle NewSharedFunctionInfo(Handle name); + Handle NewSharedFunctionInfo(Handle name, + MaybeHandle code); // Allocate a new type feedback vector Handle NewTypeFeedbackVector(int slot_count); @@ -659,20 +661,6 @@ class Factory V8_FINAL { // Creates a code object that is not yet fully initialized yet. inline Handle NewCodeRaw(int object_size, bool immovable); - // Initializes a function with a shared part and prototype. - // Note: this code was factored out of NewFunction such that other parts of - // the VM could use it. Specifically, a function that creates instances of - // type JS_FUNCTION_TYPE benefit from the use of this function. - inline void InitializeFunction(Handle function, - Handle info, - Handle context); - - // Creates a function initialized with a shared part. - inline Handle NewFunction(Handle map, - Handle info, - Handle context, - PretenureFlag pretenure = TENURED); - // Create a new map cache. Handle NewMapCache(int at_least_space_for); @@ -687,6 +675,24 @@ class Factory V8_FINAL { // Update the cache with a new number-string pair. void SetNumberStringCache(Handle number, Handle string); + + // Initializes a function with a shared part and prototype. + // Note: this code was factored out of NewFunction such that other parts of + // the VM could use it. Specifically, a function that creates instances of + // type JS_FUNCTION_TYPE benefit from the use of this function. + inline void InitializeFunction(Handle function, + Handle info, + Handle context); + + // Creates a function initialized with a shared part. + Handle NewFunction(Handle map, + Handle info, + Handle context, + PretenureFlag pretenure = TENURED); + + Handle NewFunction(Handle map, + Handle name, + MaybeHandle maybe_code); }; } } // namespace v8::internal diff --git a/src/runtime.cc b/src/runtime.cc index ed6ce93..4982606 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -2806,7 +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(key, code); + Handle optimized = + isolate->factory()->NewFunctionWithoutPrototype(key, code); optimized->shared()->DontAdaptArguments(); JSReceiver::SetProperty(holder, key, optimized, NONE, STRICT).Assert(); return optimized;