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) { |