 Chromium Code Reviews
 Chromium Code Reviews Issue 13542002:
  Calling a generator function returns a generator object  (Closed) 
  Base URL: git://github.com/v8/v8.git@master
    
  
    Issue 13542002:
  Calling a generator function returns a generator object  (Closed) 
  Base URL: git://github.com/v8/v8.git@master| Index: src/runtime.cc | 
| diff --git a/src/runtime.cc b/src/runtime.cc | 
| index 7288f38171eb75f6c4e15106817249b4b0b950fe..b5ae6fa06b4902c1f4fba3769d47c999002792d3 100644 | 
| --- a/src/runtime.cc | 
| +++ b/src/runtime.cc | 
| @@ -2292,6 +2292,42 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SetExpectedNumberOfProperties) { | 
| } | 
| +RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSGeneratorObject) { | 
| + NoHandleAllocation ha(isolate); | 
| + ASSERT(args.length() == 0); | 
| + JavaScriptFrameIterator it(isolate); | 
| + JavaScriptFrame* frame = it.frame(); | 
| + JSFunction* function = JSFunction::cast(frame->function()); | 
| + ASSERT(function->shared()->is_generator()); | 
| + | 
| + JSGeneratorObject* generator; | 
| + if (frame->IsConstructor()) { | 
| + generator = JSGeneratorObject::cast(frame->receiver()); | 
| 
Michael Starzinger
2013/04/12 16:53:31
We shouldn't use the implicit receiver as the resu
 
Michael Starzinger
2013/04/14 21:32:50
You are right, I totally missed the fact that the
 | 
| + } else { | 
| + Map *map; | 
| + if (function->has_initial_map()) { | 
| 
Michael Starzinger
2013/04/12 16:53:31
I think we can get by without tweaking the initial
 | 
| + map = function->initial_map(); | 
| + } else { | 
| + // Allocate the initial map if absent. | 
| + MaybeObject* maybe_map = isolate->heap()->AllocateInitialMap(function); | 
| + if (!maybe_map->To(&map)) return maybe_map; | 
| + function->set_initial_map(map); | 
| + } | 
| + ASSERT(map->instance_type() == JS_GENERATOR_OBJECT_TYPE); | 
| + // Allocate the generator. | 
| + MaybeObject* maybe_generator = isolate->heap()->Allocate(map, NEW_SPACE); | 
| 
Michael Starzinger
2013/04/14 21:32:50
Please move the JSGenerator allocation back into h
 
wingo
2013/04/15 09:24:57
Done.
 | 
| + if (!maybe_generator->To(&generator)) return maybe_generator; | 
| + generator->initialize_properties(); | 
| + generator->initialize_elements(); | 
| + } | 
| + generator->set_function(function); | 
| + generator->set_context(Smi::FromInt(0)); | 
| + generator->set_continuation(0); | 
| + generator->set_operand_stack(Smi::FromInt(0)); | 
| + return generator; | 
| +} | 
| + | 
| + | 
| MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate, | 
| Object* char_code) { | 
| uint32_t code; |