Index: src/x64/full-codegen-x64.cc |
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc |
index e9fe2a8cd2fdb2f87f07dc62a1c2d952dd3a4bf6..4068af3683bd3cb8b625df330e1acf7a752c5d3a 100644 |
--- a/src/x64/full-codegen-x64.cc |
+++ b/src/x64/full-codegen-x64.cc |
@@ -1974,8 +1974,12 @@ void FullCodeGenerator::VisitYield(Yield* expr) { |
VisitForStackValue(expr->expression()); |
switch (expr->yield_kind()) { |
- case Yield::INITIAL: |
- case Yield::SUSPEND: { |
+ case Yield::SUSPEND: |
+ // Pop value from top-of-stack slot; box result into result register. |
+ EmitCreateIteratorResult(false); |
+ __ push(result_register()); |
+ // Fall through. |
+ case Yield::INITIAL: { |
VisitForStackValue(expr->generator_object()); |
__ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
__ movq(context_register(), |
@@ -1984,12 +1988,8 @@ void FullCodeGenerator::VisitYield(Yield* expr) { |
Label resume; |
__ CompareRoot(result_register(), Heap::kTheHoleValueRootIndex); |
__ j(not_equal, &resume); |
- if (expr->yield_kind() == Yield::SUSPEND) { |
- EmitReturnIteratorResult(false); |
- } else { |
- __ pop(result_register()); |
- EmitReturnSequence(); |
- } |
+ __ pop(result_register()); |
+ EmitReturnSequence(); |
__ bind(&resume); |
context()->Plug(result_register()); |
@@ -2001,7 +2001,10 @@ void FullCodeGenerator::VisitYield(Yield* expr) { |
__ Move(FieldOperand(result_register(), |
JSGeneratorObject::kContinuationOffset), |
Smi::FromInt(JSGeneratorObject::kGeneratorClosed)); |
- EmitReturnIteratorResult(true); |
+ // Pop value from top-of-stack slot, box result into result register. |
+ EmitCreateIteratorResult(true); |
+ EmitUnwindBeforeReturn(); |
+ EmitReturnSequence(); |
break; |
} |
@@ -2031,17 +2034,18 @@ void FullCodeGenerator::VisitYield(Yield* expr) { |
// try { received = yield result.value } |
__ bind(&l_try); |
- __ pop(rax); // result.value |
+ EmitCreateIteratorResult(false); // pop and box to rax |
__ PushTryHandler(StackHandler::CATCH, expr->index()); |
const int handler_size = StackHandlerConstants::kSize; |
- __ push(rax); // result.value |
+ __ push(rax); // result |
__ push(Operand(rsp, (0 + 1) * kPointerSize + handler_size)); // g |
__ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
__ movq(context_register(), |
Operand(rbp, StandardFrameConstants::kContextOffset)); |
__ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
__ j(not_equal, &l_resume); |
- EmitReturnIteratorResult(false); |
+ __ pop(rax); // result |
+ EmitReturnSequence(); |
__ bind(&l_resume); // received in rax |
__ PopTryHandler(); |
@@ -2195,13 +2199,20 @@ void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
} |
-void FullCodeGenerator::EmitReturnIteratorResult(bool done) { |
+void FullCodeGenerator::EmitCreateIteratorResult(bool done) { |
Label gc_required; |
Label allocated; |
Handle<Map> map(isolate()->native_context()->generator_result_map()); |
__ Allocate(map->instance_size(), rax, rcx, rdx, &gc_required, TAG_OBJECT); |
+ __ jmp(&allocated); |
+ |
+ __ bind(&gc_required); |
+ __ Push(Smi::FromInt(map->instance_size())); |
+ __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
+ __ movq(context_register(), |
+ Operand(rbp, StandardFrameConstants::kContextOffset)); |
__ bind(&allocated); |
__ Move(rbx, map); |
@@ -2222,26 +2233,6 @@ void FullCodeGenerator::EmitReturnIteratorResult(bool done) { |
// root set. |
__ RecordWriteField(rax, JSGeneratorObject::kResultValuePropertyOffset, |
rcx, rdx, kDontSaveFPRegs); |
- |
- if (done) { |
- // Exit all nested statements. |
- NestedStatement* current = nesting_stack_; |
- int stack_depth = 0; |
- int context_length = 0; |
- while (current != NULL) { |
- current = current->Exit(&stack_depth, &context_length); |
- } |
- __ Drop(stack_depth); |
- } |
- |
- EmitReturnSequence(); |
- |
- __ bind(&gc_required); |
- __ Push(Smi::FromInt(map->instance_size())); |
- __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
- __ movq(context_register(), |
- Operand(rbp, StandardFrameConstants::kContextOffset)); |
- __ jmp(&allocated); |
} |