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

Unified Diff: src/builtins/builtins-generator-gen.cc

Issue 2936813002: Move closing of generators upon final return to the generator-resume builtin. (Closed)
Patch Set: Fix comments Created 3 years, 6 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 | « no previous file | src/interpreter/bytecode-generator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-generator-gen.cc
diff --git a/src/builtins/builtins-generator-gen.cc b/src/builtins/builtins-generator-gen.cc
index 4fdb4addad91878d21ff5fba7d8648ebebbda8ab..aab01afd283b5c4110ca78b68eb02ca46dbf6636 100644
--- a/src/builtins/builtins-generator-gen.cc
+++ b/src/builtins/builtins-generator-gen.cc
@@ -56,18 +56,27 @@ void GeneratorBuiltinsAssembler::GeneratorPrototypeResume(
// Make sure we close the generator if there was an exception.
GotoIfException(result, &if_exception, &var_exception);
- // If the generator is not suspended (i.e., it's state is 'closed'),
- // wrap the return value in IteratorResult.
+ // If the generator is not suspended (i.e., it's state is 'executing'),
neis 2017/06/13 10:58:17 s/it's/its/
Jarin 2017/06/13 11:05:56 Done.
+ // close it and wrap the return value in IteratorResult.
Node* result_continuation =
LoadObjectField(receiver, JSGeneratorObject::kContinuationOffset);
- GotoIf(SmiEqual(result_continuation, closed), &if_final_return);
+
+ // The generator function should not close the generator by itself, let's
+ // check it is indeed not closed yet.
+ CSA_ASSERT(this, SmiNotEqual(result_continuation, closed));
+
+ Node* executing = SmiConstant(JSGeneratorObject::kGeneratorExecuting);
+ GotoIf(SmiEqual(result_continuation, executing), &if_final_return);
+
Return(result);
neis 2017/06/13 10:58:17 Please add a comment saying that on suspend the ge
Jarin 2017/06/13 11:05:56 Done.
Callable create_iter_result_object =
Builtins::CallableFor(isolate(), Builtins::kCreateIterResultObject);
-
BIND(&if_final_return);
{
+ // Close the generator.
+ StoreObjectFieldNoWriteBarrier(
+ receiver, JSGeneratorObject::kContinuationOffset, closed);
// Return the wrapped result.
Return(
CallStub(create_iter_result_object, context, result, TrueConstant()));
« no previous file with comments | « no previous file | src/interpreter/bytecode-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698