Index: src/interpreter/bytecode-generator.cc |
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc |
index f2a5d74029bc8f33726b604f218f48c0da6530be..58f1a98a70bde78dfff489c1d11375f344ac5bba 100644 |
--- a/src/interpreter/bytecode-generator.cc |
+++ b/src/interpreter/bytecode-generator.cc |
@@ -981,13 +981,16 @@ void BytecodeGenerator::BuildGeneratorPrologue() { |
// This is a resume call. Restore the current context and the registers, |
// then perform state dispatch. |
- Register generator_context = register_allocator()->NewRegister(); |
- builder() |
- ->CallRuntime(Runtime::kInlineGeneratorGetContext, generator_object_) |
- .PushContext(generator_context) |
- .RestoreGeneratorState(generator_object_) |
- .StoreAccumulatorInRegister(generator_state_) |
- .SwitchOnSmiNoFeedback(generator_jump_table_); |
+ { |
+ RegisterAllocationScope register_scope(this); |
+ Register generator_context = register_allocator()->NewRegister(); |
+ builder() |
+ ->CallRuntime(Runtime::kInlineGeneratorGetContext, generator_object_) |
+ .PushContext(generator_context) |
+ .RestoreGeneratorState(generator_object_) |
+ .StoreAccumulatorInRegister(generator_state_) |
+ .SwitchOnSmiNoFeedback(generator_jump_table_); |
+ } |
// We fall through when the generator state is not in the jump table. |
// TODO(leszeks): Only generate this for debug builds. |
BuildAbort(BailoutReason::kInvalidJumpTableIndex); |
@@ -2183,6 +2186,13 @@ void BytecodeGenerator::BuildReturn() { |
if (info()->literal()->feedback_vector_spec()->HasTypeProfileSlot()) { |
builder()->CollectTypeProfile(info()->literal()->return_position()); |
} |
+ if (IsGeneratorFunction(info()->literal()->kind())) { |
+ Register result = register_allocator()->NewRegister(); |
rmcilroy
2017/06/05 10:02:58
nit - add a comment that we need to close the gene
Jarin
2017/06/05 16:03:25
Done.
|
+ builder() |
+ ->StoreAccumulatorInRegister(result) |
+ .CallRuntime(Runtime::kInlineGeneratorClose, generator_object_) |
+ .LoadAccumulatorWithRegister(result); |
+ } |
builder()->Return(); |
} |
@@ -2546,6 +2556,14 @@ void BytecodeGenerator::BuildGeneratorSuspend(Suspend* expr, Register generator, |
.LoadFalse() |
.StoreAccumulatorInRegister(args[2]) |
.CallRuntime(Runtime::kInlineAsyncGeneratorResolve, args); |
+ } else if (expr->IsNonInitialGeneratorYield()) { |
rmcilroy
2017/06/05 10:02:58
nit - let's put this above expr->IsNonInitialAsync
Jarin
2017/06/05 16:03:24
Done.
|
+ // GeneratorYield: Wrap the value into IteratorResult. |
+ RegisterList args = register_allocator()->NewRegisterList(2); |
+ builder() |
+ ->MoveRegister(value, args[0]) |
+ .LoadFalse() |
+ .StoreAccumulatorInRegister(args[1]) |
+ .CallRuntime(Runtime::kInlineCreateIterResultObject, args); |
} else { |
builder()->LoadAccumulatorWithRegister(value); |
} |
@@ -2599,17 +2617,11 @@ void BytecodeGenerator::BuildGeneratorResume( |
.JumpIfTrue(ToBooleanMode::kAlreadyBoolean, &resume_with_throw); |
// Fall through for resuming with return. |
+ builder()->LoadAccumulatorWithRegister(input); |
if (expr->is_async_generator()) { |
// Async generator methods will produce the iter result object. |
- builder()->LoadAccumulatorWithRegister(input); |
execution_control()->AsyncReturnAccumulator(); |
} else { |
- RegisterList args = register_allocator()->NewRegisterList(2); |
- builder() |
- ->MoveRegister(input, args[0]) |
- .LoadTrue() |
- .StoreAccumulatorInRegister(args[1]) |
- .CallRuntime(Runtime::kInlineCreateIterResultObject, args); |
execution_control()->ReturnAccumulator(); |
} |