Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1696)

Unified Diff: src/mips/full-codegen-mips.cc

Issue 139653003: Throw a TypeError when calling "next" method of a newly created generator with a value (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/mips/full-codegen-mips.cc
diff --git a/src/mips/full-codegen-mips.cc b/src/mips/full-codegen-mips.cc
index 1303fba5385530dc80fbea18f3ce96653cc1565b..2c4b29aaae24ae5877ba7f02fb97763983e5db6f 100644
--- a/src/mips/full-codegen-mips.cc
+++ b/src/mips/full-codegen-mips.cc
@@ -2017,6 +2017,10 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
ASSERT(continuation.pos() > 0 && Smi::IsValid(continuation.pos()));
__ li(a1, Operand(Smi::FromInt(continuation.pos())));
__ sw(a1, FieldMemOperand(v0, JSGeneratorObject::kContinuationOffset));
+ if (expr->yield_kind() == Yield::INITIAL) {
+ __ sw(a1,
+ FieldMemOperand(v0, JSGeneratorObject::kSuspendedStartOffset));
+ }
__ sw(cp, FieldMemOperand(v0, JSGeneratorObject::kContextOffset));
__ mov(a1, cp);
__ RecordWriteField(v0, JSGeneratorObject::kContextOffset, a1, a2,
@@ -2146,12 +2150,16 @@ void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
__ pop(a1);
// Check generator state.
- Label wrong_state, closed_state, done;
+ Label wrong_state, closed_state, suspended_start_state, resume_state, done;
__ lw(a3, FieldMemOperand(a1, JSGeneratorObject::kContinuationOffset));
STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0);
STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0);
__ Branch(&closed_state, eq, a3, Operand(zero_reg));
__ Branch(&wrong_state, lt, a3, Operand(zero_reg));
+ __ lw(a2, FieldMemOperand(a1, JSGeneratorObject::kSuspendedStartOffset));
+ __ Branch(&suspended_start_state, eq, a3, Operand(a2));
+
+ __ bind(&resume_state);
// Load suspended function and context.
__ lw(cp, FieldMemOperand(a1, JSGeneratorObject::kContextOffset));
@@ -2224,6 +2232,30 @@ void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
// Not reached: the runtime call returns elsewhere.
__ stop("not-reached");
+ // Throw the provided value.
+ Label throw_provided_value;
+ __ bind(&throw_provided_value);
+ if (resume_mode != JSGeneratorObject::NEXT) {
+ __ push(a0);
+ __ CallRuntime(Runtime::kThrow, 1);
+ __ Branch(&done);
+ }
+
+ // Reach here when calling initial resume to a generator.
+ __ bind(&suspended_start_state);
+ if (resume_mode == JSGeneratorObject::NEXT) {
+ // When value is provided and it is not undefined, throw error.
+ __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
+ __ Branch(&resume_state, eq, a0, Operand(a2));
+ __ CallRuntime(Runtime::kThrowGeneratorStartError, 0);
+ __ Branch(&done);
+ } else {
+ // Make generator's state to "closed".
+ __ li(a2, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorClosed)));
+ __ sw(a2, FieldMemOperand(a1, JSGeneratorObject::kContinuationOffset));
+ __ Branch(&throw_provided_value);
+ }
+
// Reach here when generator is closed.
__ bind(&closed_state);
if (resume_mode == JSGeneratorObject::NEXT) {
@@ -2232,12 +2264,10 @@ void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
__ push(a2);
// Pop value from top-of-stack slot; box result into result register.
EmitCreateIteratorResult(true);
+ __ Branch(&done);
} else {
- // Throw the provided value.
- __ push(a0);
- __ CallRuntime(Runtime::kThrow, 1);
+ __ Branch(&throw_provided_value);
}
- __ jmp(&done);
// Throw error if we attempt to operate on a running generator.
__ bind(&wrong_state);
« src/ia32/full-codegen-ia32.cc ('K') | « src/messages.js ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698