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

Unified Diff: src/builtins.cc

Issue 1865833002: [generators] Decouple generator resume from fullcodegen. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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/builtins.h ('k') | src/code-factory.h » ('j') | src/deoptimizer.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index d19f71a332bad9e9fc5b50dae22f230fc90a96bb..53085c3e0037a30bb1df6f991b493697be4fe7a7 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -2313,8 +2313,112 @@ void Builtins::Generate_MathTrunc(compiler::CodeStubAssembler* assembler) {
}
// -----------------------------------------------------------------------------
-// ES6 section 26.1 The Reflect Object
+// ES6 section 25.3 Generator Objects
+
+namespace {
+
+void Generate_GeneratorPrototypeResume(
+ compiler::CodeStubAssembler* assembler,
+ JSGeneratorObject::ResumeMode resume_mode, char const* const method_name) {
+ typedef compiler::CodeStubAssembler::Label Label;
+ typedef compiler::Node Node;
+
+ Node* receiver = assembler->Parameter(0);
+ Node* value = assembler->Parameter(1);
+ Node* context = assembler->Parameter(4);
+ Node* zero = assembler->SmiConstant(Smi::FromInt(0));
+
+ // Check if the {receiver} is actually a JSGeneratorObject.
+ Label if_receiverisincompatible(assembler, Label::kDeferred);
+ assembler->GotoIf(assembler->WordIsSmi(receiver), &if_receiverisincompatible);
+ Node* receiver_instance_type = assembler->LoadInstanceType(receiver);
+ assembler->GotoUnless(assembler->Word32Equal(
+ receiver_instance_type,
+ assembler->Int32Constant(JS_GENERATOR_OBJECT_TYPE)),
+ &if_receiverisincompatible);
+
+ // Check if the {receiver} is running or already closed.
+ Node* receiver_continuation = assembler->LoadObjectField(
+ receiver, JSGeneratorObject::kContinuationOffset);
+ Label if_receiverisclosed(assembler, Label::kDeferred),
+ if_receiverisrunning(assembler, Label::kDeferred);
+ assembler->GotoIf(assembler->SmiEqual(receiver_continuation, zero),
+ &if_receiverisclosed);
+ assembler->GotoIf(assembler->SmiLessThan(receiver_continuation, zero),
+ &if_receiverisrunning);
+
+ // Resume the {receiver} using our trampoline.
+ Node* result = assembler->CallStub(
+ CodeFactory::ResumeGenerator(assembler->isolate()), context, value,
+ receiver, assembler->SmiConstant(Smi::FromInt(resume_mode)));
+ assembler->Return(result);
+
+ assembler->Bind(&if_receiverisincompatible);
+ {
+ // The {receiver} is not a valid JSGeneratorObject.
+ Node* result = assembler->CallRuntime(
+ Runtime::kThrowIncompatibleMethodReceiver, context,
+ assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked(
+ method_name, TENURED)),
+ receiver);
+ assembler->Return(result); // Never reached.
+ }
+
+ assembler->Bind(&if_receiverisclosed);
+ {
+ // The {receiver} is closed already.
+ Node* result = nullptr;
+ switch (resume_mode) {
+ case JSGeneratorObject::kNext:
+ result = assembler->CallRuntime(Runtime::kCreateIterResultObject,
+ context, assembler->UndefinedConstant(),
+ assembler->BooleanConstant(true));
+ break;
+ case JSGeneratorObject::kReturn:
+ result =
+ assembler->CallRuntime(Runtime::kCreateIterResultObject, context,
+ value, assembler->BooleanConstant(true));
+ break;
+ case JSGeneratorObject::kThrow:
+ result = assembler->CallRuntime(Runtime::kThrow, context, value);
+ break;
+ }
+ assembler->Return(result);
+ }
+
+ assembler->Bind(&if_receiverisrunning);
+ {
+ Node* result =
+ assembler->CallRuntime(Runtime::kThrowGeneratorRunning, context);
+ assembler->Return(result); // Never reached.
+ }
+}
+
+} // namespace
+// ES6 section 25.3.1.2 Generator.prototype.next ( value )
+void Builtins::Generate_GeneratorPrototypeNext(
+ compiler::CodeStubAssembler* assembler) {
+ Generate_GeneratorPrototypeResume(assembler, JSGeneratorObject::kNext,
+ "[Generator].prototype.next");
+}
+
+// ES6 section 25.3.1.3 Generator.prototype.return ( value )
+void Builtins::Generate_GeneratorPrototypeReturn(
+ compiler::CodeStubAssembler* assembler) {
+ Generate_GeneratorPrototypeResume(assembler, JSGeneratorObject::kReturn,
+ "[Generator].prototype.return");
+}
+
+// ES6 section 25.3.1.4 Generator.prototype.throw ( exception )
+void Builtins::Generate_GeneratorPrototypeThrow(
+ compiler::CodeStubAssembler* assembler) {
+ Generate_GeneratorPrototypeResume(assembler, JSGeneratorObject::kThrow,
+ "[Generator].prototype.throw");
+}
+
+// -----------------------------------------------------------------------------
+// ES6 section 26.1 The Reflect Object
// ES6 section 26.1.3 Reflect.defineProperty
BUILTIN(ReflectDefineProperty) {
« no previous file with comments | « src/builtins.h ('k') | src/code-factory.h » ('j') | src/deoptimizer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698