OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/frames-inl.h" | 9 #include "src/frames-inl.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 return isolate->heap()->undefined_value(); | 82 return isolate->heap()->undefined_value(); |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 // Note that this function is the slow path for resuming generators. It is only | 86 // Note that this function is the slow path for resuming generators. It is only |
87 // called if the suspended activation had operands on the stack, stack handlers | 87 // called if the suspended activation had operands on the stack, stack handlers |
88 // needing rewinding, or if the resume should throw an exception. The fast path | 88 // needing rewinding, or if the resume should throw an exception. The fast path |
89 // is handled directly in FullCodeGenerator::EmitGeneratorResume(), which is | 89 // is handled directly in FullCodeGenerator::EmitGeneratorResume(), which is |
90 // inlined into GeneratorNext and GeneratorThrow. EmitGeneratorResumeResume is | 90 // inlined into GeneratorNext, GeneratorReturn, and GeneratorThrow. |
91 // called in any case, as it needs to reconstruct the stack frame and make space | 91 // EmitGeneratorResume is called in any case, as it needs to reconstruct the |
92 // for arguments and operands. | 92 // stack frame and make space for arguments and operands. |
93 RUNTIME_FUNCTION(Runtime_ResumeJSGeneratorObject) { | 93 RUNTIME_FUNCTION(Runtime_ResumeJSGeneratorObject) { |
94 SealHandleScope shs(isolate); | 94 SealHandleScope shs(isolate); |
95 DCHECK(args.length() == 3); | 95 DCHECK(args.length() == 3); |
96 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0); | 96 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0); |
97 CONVERT_ARG_CHECKED(Object, value, 1); | 97 CONVERT_ARG_CHECKED(Object, value, 1); |
98 CONVERT_SMI_ARG_CHECKED(resume_mode_int, 2); | 98 CONVERT_SMI_ARG_CHECKED(resume_mode_int, 2); |
99 JavaScriptFrameIterator stack_iterator(isolate); | 99 JavaScriptFrameIterator stack_iterator(isolate); |
100 JavaScriptFrame* frame = stack_iterator.frame(); | 100 JavaScriptFrame* frame = stack_iterator.frame(); |
101 | 101 |
102 DCHECK_EQ(frame->function(), generator_object->function()); | 102 DCHECK_EQ(frame->function(), generator_object->function()); |
(...skipping 15 matching lines...) Expand all Loading... |
118 FixedArray* operand_stack = generator_object->operand_stack(); | 118 FixedArray* operand_stack = generator_object->operand_stack(); |
119 int operands_count = operand_stack->length(); | 119 int operands_count = operand_stack->length(); |
120 if (operands_count != 0) { | 120 if (operands_count != 0) { |
121 frame->RestoreOperandStack(operand_stack); | 121 frame->RestoreOperandStack(operand_stack); |
122 generator_object->set_operand_stack(isolate->heap()->empty_fixed_array()); | 122 generator_object->set_operand_stack(isolate->heap()->empty_fixed_array()); |
123 } | 123 } |
124 | 124 |
125 JSGeneratorObject::ResumeMode resume_mode = | 125 JSGeneratorObject::ResumeMode resume_mode = |
126 static_cast<JSGeneratorObject::ResumeMode>(resume_mode_int); | 126 static_cast<JSGeneratorObject::ResumeMode>(resume_mode_int); |
127 switch (resume_mode) { | 127 switch (resume_mode) { |
| 128 // Note: this looks like NEXT and RETURN are the same but RETURN receives |
| 129 // special treatment in the generator code (to which we return here). |
128 case JSGeneratorObject::NEXT: | 130 case JSGeneratorObject::NEXT: |
| 131 case JSGeneratorObject::RETURN: |
129 return value; | 132 return value; |
130 case JSGeneratorObject::THROW: | 133 case JSGeneratorObject::THROW: |
131 return isolate->Throw(value); | 134 return isolate->Throw(value); |
132 } | 135 } |
133 | 136 |
134 UNREACHABLE(); | 137 UNREACHABLE(); |
135 return isolate->ThrowIllegalOperation(); | 138 return isolate->ThrowIllegalOperation(); |
136 } | 139 } |
137 | 140 |
138 | 141 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 return isolate->heap()->undefined_value(); | 208 return isolate->heap()->undefined_value(); |
206 } | 209 } |
207 | 210 |
208 | 211 |
209 RUNTIME_FUNCTION(Runtime_GeneratorNext) { | 212 RUNTIME_FUNCTION(Runtime_GeneratorNext) { |
210 UNREACHABLE(); // Optimization disabled in SetUpGenerators(). | 213 UNREACHABLE(); // Optimization disabled in SetUpGenerators(). |
211 return NULL; | 214 return NULL; |
212 } | 215 } |
213 | 216 |
214 | 217 |
| 218 RUNTIME_FUNCTION(Runtime_GeneratorReturn) { |
| 219 UNREACHABLE(); // Optimization disabled in SetUpGenerators(). |
| 220 return NULL; |
| 221 } |
| 222 |
| 223 |
215 RUNTIME_FUNCTION(Runtime_GeneratorThrow) { | 224 RUNTIME_FUNCTION(Runtime_GeneratorThrow) { |
216 UNREACHABLE(); // Optimization disabled in SetUpGenerators(). | 225 UNREACHABLE(); // Optimization disabled in SetUpGenerators(). |
217 return NULL; | 226 return NULL; |
218 } | 227 } |
219 } // namespace internal | 228 } // namespace internal |
220 } // namespace v8 | 229 } // namespace v8 |
OLD | NEW |