Chromium Code Reviews| Index: src/factory.cc |
| diff --git a/src/factory.cc b/src/factory.cc |
| index 879b9b74ef1e1e85f63880c4038275752b6f42d5..988c171cd8c19523e9797e373ab16c5b184d1d23 100644 |
| --- a/src/factory.cc |
| +++ b/src/factory.cc |
| @@ -975,35 +975,21 @@ Handle<ConstantPoolArray> Factory::CopyConstantPoolArray( |
| } |
| -static Handle<Map> MapForNewFunction(Isolate *isolate, |
| - Handle<SharedFunctionInfo> function_info) { |
| - Context *context = isolate->context()->native_context(); |
| - int map_index = Context::FunctionMapIndex(function_info->strict_mode(), |
| - function_info->is_generator()); |
| - return Handle<Map>(Map::cast(context->get(map_index))); |
| -} |
| - |
| - |
| Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
| - Handle<SharedFunctionInfo> function_info, |
| + Handle<SharedFunctionInfo> info, |
| Handle<Context> context, |
| PretenureFlag pretenure) { |
| - Handle<JSFunction> result = NewFunctionHelper( |
| - MapForNewFunction(isolate(), function_info), |
| - function_info, |
| - the_hole_value(), |
| - pretenure); |
| + Handle<JSFunction> result = NewFunction( |
| + info, context, the_hole_value(), pretenure); |
| - if (function_info->ic_age() != isolate()->heap()->global_ic_age()) { |
| - function_info->ResetForNewContext(isolate()->heap()->global_ic_age()); |
| + if (info->ic_age() != isolate()->heap()->global_ic_age()) { |
| + info->ResetForNewContext(isolate()->heap()->global_ic_age()); |
| } |
| - result->set_context(*context); |
| - |
| - int index = function_info->SearchOptimizedCodeMap(context->native_context(), |
| - BailoutId::None()); |
| - if (!function_info->bound() && index < 0) { |
| - int number_of_literals = function_info->num_literals(); |
| + int index = info->SearchOptimizedCodeMap(context->native_context(), |
| + BailoutId::None()); |
| + if (!info->bound() && index < 0) { |
| + int number_of_literals = info->num_literals(); |
| Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure); |
| if (number_of_literals > 0) { |
| // Store the native context in the literals array prefix. This |
| @@ -1017,10 +1003,9 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
| if (index > 0) { |
| // Caching of optimized code enabled and optimized code found. |
| - FixedArray* literals = |
| - function_info->GetLiteralsFromOptimizedCodeMap(index); |
| + FixedArray* literals = info->GetLiteralsFromOptimizedCodeMap(index); |
| if (literals != NULL) result->set_literals(literals); |
| - Code* code = function_info->GetCodeFromOptimizedCodeMap(index); |
| + Code* code = info->GetCodeFromOptimizedCodeMap(index); |
| ASSERT(!code->marked_for_deoptimization()); |
| result->ReplaceCode(code); |
| return result; |
| @@ -1029,9 +1014,9 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
| if (isolate()->use_crankshaft() && |
| FLAG_always_opt && |
| result->is_compiled() && |
| - !function_info->is_toplevel() && |
| - function_info->allows_lazy_compilation() && |
| - !function_info->optimization_disabled() && |
| + !info->is_toplevel() && |
| + info->allows_lazy_compilation() && |
| + !info->optimization_disabled() && |
| !isolate()->DebuggerHasBreakPoints()) { |
| result->MarkForOptimization(); |
| } |
| @@ -1752,8 +1737,9 @@ void Factory::ReinitializeJSReceiver(Handle<JSReceiver> object, |
| if (type == JS_FUNCTION_TYPE) { |
| map->set_function_with_prototype(true); |
| Handle<JSFunction> js_function = Handle<JSFunction>::cast(object); |
| - InitializeFunction(js_function, shared.ToHandleChecked(), the_hole_value()); |
| - js_function->set_context(isolate()->context()->native_context()); |
| + Handle<Context> context(isolate()->context()->native_context()); |
| + InitializeFunction(js_function, shared.ToHandleChecked(), |
| + context, the_hole_value()); |
|
Igor Sheludko
2014/04/17 11:10:08
What about passing here an null prototype just to
Toon Verwaest
2014/04/17 11:50:18
Done.
|
| } |
| // Put in filler if the new object is smaller than the old. |
| @@ -1983,52 +1969,68 @@ Handle<UnseededNumberDictionary> Factory::DictionaryAtNumberPut( |
| void Factory::InitializeFunction(Handle<JSFunction> function, |
| - Handle<SharedFunctionInfo> shared, |
| - Handle<Object> prototype) { |
| - ASSERT(!prototype->IsMap()); |
| + Handle<SharedFunctionInfo> info, |
| + Handle<Context> context, |
| + MaybeHandle<Object> maybe_prototype) { |
| function->initialize_properties(); |
| function->initialize_elements(); |
| - function->set_shared(*shared); |
| - function->set_code(shared->code()); |
| + function->set_shared(*info); |
| + function->set_code(info->code()); |
| + function->set_context(*context); |
| + Handle<Object> prototype; |
| + if (maybe_prototype.ToHandle(&prototype)) { |
| + ASSERT(!prototype->IsMap()); |
| + } else { |
| + prototype = the_hole_value(); |
| + } |
| function->set_prototype_or_initial_map(*prototype); |
| - function->set_context(*undefined_value()); |
| function->set_literals_or_bindings(*empty_fixed_array()); |
| function->set_next_function_link(*undefined_value()); |
| } |
| -Handle<JSFunction> Factory::NewFunctionHelper(Handle<Map> function_map, |
| - Handle<SharedFunctionInfo> shared, |
| - Handle<Object> prototype, |
| - PretenureFlag pretenure) { |
| - AllocationSpace space = |
| - (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; |
| - Handle<JSFunction> fun = New<JSFunction>(function_map, space); |
| - InitializeFunction(fun, shared, prototype); |
| - return fun; |
| +static Handle<Map> MapForNewFunction(Isolate* isolate, |
| + Handle<SharedFunctionInfo> function_info, |
| + MaybeHandle<Object> maybe_prototype) { |
| + if (maybe_prototype.is_null()) { |
| + return function_info->strict_mode() == SLOPPY |
| + ? isolate->sloppy_function_without_prototype_map() |
| + : isolate->strict_function_without_prototype_map(); |
| + } |
| + |
| + Context* context = isolate->context()->native_context(); |
| + int map_index = Context::FunctionMapIndex(function_info->strict_mode(), |
| + function_info->is_generator()); |
| + return Handle<Map>(Map::cast(context->get(map_index))); |
| +} |
| + |
| + |
| +Handle<JSFunction> Factory::NewFunction(Handle<SharedFunctionInfo> info, |
| + Handle<Context> context, |
| + MaybeHandle<Object> maybe_prototype, |
| + PretenureFlag pretenure) { |
| + Handle<Map> map = MapForNewFunction(isolate(), info, maybe_prototype); |
| + AllocationSpace space = pretenure == TENURED ? OLD_POINTER_SPACE : NEW_SPACE; |
| + Handle<JSFunction> result = New<JSFunction>(map, space); |
| + InitializeFunction(result, info, context, maybe_prototype); |
| + return result; |
| } |
| Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
| Handle<Object> prototype) { |
| - Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); |
| - Handle<JSFunction> fun = NewFunctionHelper( |
| - isolate()->sloppy_function_map(), function_share, prototype); |
| - fun->set_context(isolate()->context()->native_context()); |
| - return fun; |
| + Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name); |
| + Handle<Context> context(isolate()->context()->native_context()); |
| + return NewFunction(info, context, prototype); |
| } |
| Handle<JSFunction> Factory::NewFunctionWithoutPrototype( |
| Handle<String> name, |
| StrictMode strict_mode) { |
| - Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); |
| - Handle<Map> map = strict_mode == SLOPPY |
| - ? isolate()->sloppy_function_without_prototype_map() |
| - : isolate()->strict_function_without_prototype_map(); |
| - Handle<JSFunction> fun = |
| - NewFunctionHelper(map, function_share, the_hole_value()); |
| - fun->set_context(isolate()->context()->native_context()); |
| + Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name); |
| + Handle<Context> context(isolate()->context()->native_context()); |
| + Handle<JSFunction> fun = NewFunction(info, context, MaybeHandle<Object>()); |
| return fun; |
| } |
| @@ -2111,12 +2113,8 @@ Handle<JSFunction> Factory::CreateApiFunction( |
| break; |
| } |
| - Handle<JSFunction> result = |
| - NewFunction(Factory::empty_string(), |
| - type, |
| - instance_size, |
| - code, |
| - true); |
| + Handle<JSFunction> result = NewFunction( |
| + Factory::empty_string(), type, instance_size, code, true); |
| // Set length. |
| result->shared()->set_length(obj->length()); |