From c357a87a79ce94d83443686bfd41c9c0a58936b5 Mon Sep 17 00:00:00 2001 From: "zhengxing.li" Date: Thu, 4 Feb 2016 23:41:04 -0800 Subject: [PATCH] X87: [generators] Implement Generator.prototype.return. port dbd86408134e67551c1e66c3a7484abb628b95f7 (r33744) original commit message: Note: This is currently only used by yield*, we still need to support it in other places (such as for-of loops). It can be used manually of course. (This CL does not touch the full-codegen implementation of yield* because that code is already dead. The yield* desugaring already supports return and doesn't need to be touched.) BUG= Review URL: https://codereview.chromium.org/1671783002 Cr-Commit-Position: refs/heads/master@{#33760} --- src/full-codegen/x87/full-codegen-x87.cc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/full-codegen/x87/full-codegen-x87.cc b/src/full-codegen/x87/full-codegen-x87.cc index 99dac75e6d..a8c7c722b1 100644 --- a/src/full-codegen/x87/full-codegen-x87.cc +++ b/src/full-codegen/x87/full-codegen-x87.cc @@ -1839,8 +1839,17 @@ void FullCodeGenerator::VisitYield(Yield* expr) { __ jmp(&suspend); __ bind(&continuation); + // When we arrive here, the stack top is the resume mode and + // result_register() holds the input value (the argument given to the + // respective resume operation). __ RecordGeneratorContinuation(); - __ jmp(&resume); + __ pop(ebx); + __ cmp(ebx, Immediate(Smi::FromInt(JSGeneratorObject::RETURN))); + __ j(not_equal, &resume); + __ push(result_register()); + EmitCreateIteratorResult(true); + EmitUnwindBeforeReturn(); + EmitReturnSequence(); __ bind(&suspend); VisitForAccumulatorValue(expr->generator_object()); @@ -2001,8 +2010,8 @@ void FullCodeGenerator::EmitGeneratorResume(Expression *generator, // Store input value into generator object. __ mov(FieldOperand(ebx, JSGeneratorObject::kInputOffset), result_register()); - __ mov(edx, result_register()); - __ RecordWriteField(ebx, JSGeneratorObject::kInputOffset, edx, ecx, + __ mov(ecx, result_register()); + __ RecordWriteField(ebx, JSGeneratorObject::kInputOffset, ecx, edx, kDontSaveFPRegs); // Load suspended function and context. @@ -2053,6 +2062,7 @@ void FullCodeGenerator::EmitGeneratorResume(Expression *generator, __ add(edx, ecx); __ mov(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting))); + __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation. __ jmp(edx); __ bind(&slow_resume); } @@ -2066,6 +2076,7 @@ void FullCodeGenerator::EmitGeneratorResume(Expression *generator, __ push(ecx); __ jmp(&push_operand_holes); __ bind(&call_resume); + __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation. __ push(ebx); __ push(result_register()); __ Push(Smi::FromInt(resume_mode));