Index: src/bootstrapper.cc |
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc |
index f57a1f6fd8fb69cbb3ac633382283fa7e6556486..0ec2e0c114493a4ad28dd03142fd42bee70af6cc 100644 |
--- a/src/bootstrapper.cc |
+++ b/src/bootstrapper.cc |
@@ -1321,6 +1321,59 @@ void Genesis::InitializeExperimentalGlobal() { |
Builtins::kIllegal, true); |
} |
} |
+ |
+ if (FLAG_harmony_generators) { |
+ // Fetch Function, Function.prototype, Object.prototype, and some maps from |
+ // the environment. |
+ Handle<String> function_string = factory()->function_class_string(); |
+ Handle<JSFunction> function = Handle<JSFunction>::cast( |
+ GetProperty(isolate(), isolate()->global_object(), function_string)); |
+ Handle<JSObject> function_prototype(JSObject::cast( |
+ function->instance_prototype())); |
+ Handle<JSObject> object_prototype(isolate()->initial_object_prototype()); |
+ Handle<Map> function_map(native_context()->function_map()); |
+ Handle<Map> strict_mode_function_map( |
+ native_context()->strict_mode_function_map()); |
+ Handle<Map> object_map(native_context()->object_function()->initial_map()); |
+ |
+ // Create generator meta-objects and install them on the builtins object. |
+ Handle<JSObject> builtins(native_context()->builtins()); |
+ Handle<JSObject> generator_object_prototype = |
+ factory()->NewJSObject(isolate()->object_function(), TENURED); |
+ Handle<JSFunction> generator_function_prototype = |
+ InstallFunction(builtins, "GeneratorFunctionPrototype", |
+ JS_FUNCTION_TYPE, JSFunction::kHeaderSize, |
+ generator_object_prototype, Builtins::kIllegal, |
+ false); |
+ SetPrototype(Handle<JSObject>::cast(generator_function_prototype), |
+ function_prototype); |
+ Handle<JSFunction> generator_function = |
+ InstallFunction(builtins, "GeneratorFunction", JS_FUNCTION_TYPE, |
+ JSFunction::kSize, generator_function_prototype, |
+ Builtins::kIllegal, false); |
+ SetPrototype(Handle<JSObject>::cast(generator_function), |
+ function); |
+ |
+ // Create maps for generator functions and their prototypes. Store those |
+ // maps in the native context. |
+ Handle<Map> generator_function_map = factory()->CopyMap(function_map); |
+ generator_function_map->set_prototype(*generator_function_prototype); |
+ native_context()->set_generator_function_map(*generator_function_map); |
+ |
+ Handle<Map> strict_mode_generator_function_map = factory()->CopyMap( |
+ strict_mode_function_map); |
+ strict_mode_generator_function_map->set_prototype( |
+ *generator_function_prototype); |
+ native_context()->set_strict_mode_generator_function_map( |
+ *strict_mode_generator_function_map); |
+ |
+ Handle<Map> generator_object_prototype_map = factory()->CopyMap( |
+ object_map, 0); |
+ generator_object_prototype_map->set_prototype( |
+ *generator_object_prototype); |
+ native_context()->set_generator_object_prototype_map( |
+ *generator_object_prototype_map); |
+ } |
} |
@@ -1933,6 +1986,11 @@ bool Genesis::InstallExperimentalNatives() { |
"native typedarray.js") == 0) { |
if (!CompileExperimentalBuiltin(isolate(), i)) return false; |
} |
+ if (FLAG_harmony_generators && |
+ strcmp(ExperimentalNatives::GetScriptName(i).start(), |
+ "native generator.js") == 0) { |
+ if (!CompileExperimentalBuiltin(isolate(), i)) return false; |
+ } |
} |
InstallExperimentalNativeFunctions(); |