Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Unified Diff: src/factory.cc

Issue 13192004: arrange to create prototypes for generators (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Generators JS runtime to separate file, to avoid overhead when no --harmony-generators Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index fece9a09c91779c6f360d842a7c2b3b9a7a51791..a2e91e64a5acfd3dc90469963aa195411bdc2ee8 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -578,15 +578,31 @@ Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo(
}
+static Handle<Map> MapForNewFunction(Isolate *isolate,
+ Handle<SharedFunctionInfo> function_info) {
+ if (function_info->is_generator()) {
+ if (function_info->is_classic_mode()) {
+ return isolate->generator_function_map();
+ } else {
+ return isolate->strict_mode_generator_function_map();
+ }
+ } else {
+ if (function_info->is_classic_mode()) {
+ return isolate->function_map();
+ } else {
+ return isolate->strict_mode_function_map();
+ }
+ }
+}
+
+
Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
Handle<SharedFunctionInfo> function_info,
Handle<Context> context,
PretenureFlag pretenure) {
Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo(
function_info,
- function_info->is_classic_mode()
- ? isolate()->function_map()
- : isolate()->strict_mode_function_map(),
+ MapForNewFunction(isolate(), function_info),
pretenure);
if (function_info->ic_age() != isolate()->heap()->global_ic_age()) {
@@ -595,6 +611,16 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
result->set_context(*context);
+ if (function_info->is_generator()) {
+ // Generator functions have specialized prototypes and instance types, so
+ // 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
+ // TODO(wingo): Use JS_GENERATOR_TYPE.
+ Handle<Map> instance_map = NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
+ Handle<JSObject> iterator_prototype = NewFunctionPrototype(result);
+ instance_map->set_prototype(*iterator_prototype);
+ result->set_initial_map(*instance_map);
+ }
+
int index = function_info->SearchOptimizedCodeMap(context->native_context());
if (!function_info->bound() && index < 0) {
int number_of_literals = function_info->num_literals();

Powered by Google App Engine
This is Rietveld 408576698