OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 CALL_HEAP_FUNCTION( | 571 CALL_HEAP_FUNCTION( |
572 isolate(), | 572 isolate(), |
573 isolate()->heap()->AllocateFunction(*function_map, | 573 isolate()->heap()->AllocateFunction(*function_map, |
574 *function_info, | 574 *function_info, |
575 isolate()->heap()->the_hole_value(), | 575 isolate()->heap()->the_hole_value(), |
576 pretenure), | 576 pretenure), |
577 JSFunction); | 577 JSFunction); |
578 } | 578 } |
579 | 579 |
580 | 580 |
581 static Handle<Map> MapForNewFunction(Isolate *isolate, | |
582 Handle<SharedFunctionInfo> function_info) { | |
583 if (function_info->is_generator()) { | |
584 if (function_info->is_classic_mode()) { | |
585 return isolate->generator_function_map(); | |
586 } else { | |
587 return isolate->strict_mode_generator_function_map(); | |
588 } | |
589 } else { | |
590 if (function_info->is_classic_mode()) { | |
591 return isolate->function_map(); | |
592 } else { | |
593 return isolate->strict_mode_function_map(); | |
594 } | |
595 } | |
596 } | |
597 | |
598 | |
581 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( | 599 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
582 Handle<SharedFunctionInfo> function_info, | 600 Handle<SharedFunctionInfo> function_info, |
583 Handle<Context> context, | 601 Handle<Context> context, |
584 PretenureFlag pretenure) { | 602 PretenureFlag pretenure) { |
585 Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo( | 603 Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo( |
586 function_info, | 604 function_info, |
587 function_info->is_classic_mode() | 605 MapForNewFunction(isolate(), function_info), |
588 ? isolate()->function_map() | |
589 : isolate()->strict_mode_function_map(), | |
590 pretenure); | 606 pretenure); |
591 | 607 |
592 if (function_info->ic_age() != isolate()->heap()->global_ic_age()) { | 608 if (function_info->ic_age() != isolate()->heap()->global_ic_age()) { |
593 function_info->ResetForNewContext(isolate()->heap()->global_ic_age()); | 609 function_info->ResetForNewContext(isolate()->heap()->global_ic_age()); |
594 } | 610 } |
595 | 611 |
596 result->set_context(*context); | 612 result->set_context(*context); |
597 | 613 |
614 if (function_info->is_generator()) { | |
615 // Generator functions have specialized prototypes and instance types, so | |
616 // they need their prototypes to be created eagerly. | |
rossberg
2013/04/09 16:44:14
I don't understand. Why can't you make the case di
| |
617 // TODO(wingo): Use JS_GENERATOR_TYPE. | |
618 Handle<Map> instance_map = NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | |
619 Handle<JSObject> iterator_prototype = NewFunctionPrototype(result); | |
620 instance_map->set_prototype(*iterator_prototype); | |
621 result->set_initial_map(*instance_map); | |
622 } | |
623 | |
598 int index = function_info->SearchOptimizedCodeMap(context->native_context()); | 624 int index = function_info->SearchOptimizedCodeMap(context->native_context()); |
599 if (!function_info->bound() && index < 0) { | 625 if (!function_info->bound() && index < 0) { |
600 int number_of_literals = function_info->num_literals(); | 626 int number_of_literals = function_info->num_literals(); |
601 Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure); | 627 Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure); |
602 if (number_of_literals > 0) { | 628 if (number_of_literals > 0) { |
603 // Store the native context in the literals array prefix. This | 629 // Store the native context in the literals array prefix. This |
604 // context will be used when creating object, regexp and array | 630 // context will be used when creating object, regexp and array |
605 // literals in this function. | 631 // literals in this function. |
606 literals->set(JSFunction::kLiteralNativeContextIndex, | 632 literals->set(JSFunction::kLiteralNativeContextIndex, |
607 context->native_context()); | 633 context->native_context()); |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1479 return Handle<Object>::null(); | 1505 return Handle<Object>::null(); |
1480 } | 1506 } |
1481 | 1507 |
1482 | 1508 |
1483 Handle<Object> Factory::ToBoolean(bool value) { | 1509 Handle<Object> Factory::ToBoolean(bool value) { |
1484 return value ? true_value() : false_value(); | 1510 return value ? true_value() : false_value(); |
1485 } | 1511 } |
1486 | 1512 |
1487 | 1513 |
1488 } } // namespace v8::internal | 1514 } } // namespace v8::internal |
OLD | NEW |