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

Unified Diff: src/x64/full-codegen-x64.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: Revised Created 6 years, 10 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
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/harmony/generators-iteration.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/x64/full-codegen-x64.cc
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc
index 6f8989a934cd45396b7d39215a7777a60efb5bbf..49ee16c1437a3f227aa41943d70ff93a7896e1fd 100644
--- a/src/x64/full-codegen-x64.cc
+++ b/src/x64/full-codegen-x64.cc
@@ -1998,6 +1998,19 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
EmitReturnSequence();
__ bind(&resume);
+ Label init_value_check_done;
+ if (expr->yield_kind() == Yield::INITIAL) {
+ // When value is provided and it is not undefined, throw error.
+ __ CompareRoot(result_register(), Heap::kUndefinedValueRootIndex);
+ __ j(equal, &init_value_check_done);
+ // This error should be raised from the Generator.prototype.next side.
+ // So in this case, we return the hole value as a marker. The caller
+ // checks the result value and if it is the hole value, the caller
+ // throws error.
+ __ PushRoot(Heap::kTheHoleValueRootIndex);
+ __ jmp(&suspend);
+ }
+ __ bind(&init_value_check_done);
context()->Plug(result_register());
break;
}
@@ -2216,7 +2229,17 @@ void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
__ push(rbx);
__ CallRuntime(Runtime::kThrowGeneratorStateError, 1);
+ // Throw error if we attempt to pass a value to an unborn generator.
+ Label wrong_start;
+ __ bind(&wrong_start);
+ __ CallRuntime(Runtime::kThrowGeneratorStartError, 0);
+
__ bind(&done);
+ // When a value is passed to an unborn generator, the result becomes the hole
+ // value. And we need to throw GeneratorStartError in the caller side.
+ // (Generator.prototype.next)
+ __ CompareRoot(result_register(), Heap::kTheHoleValueRootIndex);
+ __ j(equal, &wrong_start);
context()->Plug(result_register());
}
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/harmony/generators-iteration.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698