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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 Handle<Code> code(generator->function()->code(), isolate); | 209 Handle<Code> code(generator->function()->code(), isolate); |
207 int offset = generator->continuation(); | 210 int offset = generator->continuation(); |
208 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size()); | 211 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size()); |
209 return Smi::FromInt(code->SourcePosition(offset)); | 212 return Smi::FromInt(code->SourcePosition(offset)); |
210 } | 213 } |
211 | 214 |
212 return isolate->heap()->undefined_value(); | 215 return isolate->heap()->undefined_value(); |
213 } | 216 } |
214 | 217 |
215 | 218 |
| 219 // Optimization for the following three functions is disabled in |
| 220 // js/generator.js and compiler/ast-graph-builder.cc. |
| 221 |
| 222 |
216 RUNTIME_FUNCTION(Runtime_GeneratorNext) { | 223 RUNTIME_FUNCTION(Runtime_GeneratorNext) { |
217 UNREACHABLE(); // Optimization disabled in SetUpGenerators(). | 224 UNREACHABLE(); |
218 return NULL; | 225 return nullptr; |
| 226 } |
| 227 |
| 228 |
| 229 RUNTIME_FUNCTION(Runtime_GeneratorReturn) { |
| 230 UNREACHABLE(); |
| 231 return nullptr; |
219 } | 232 } |
220 | 233 |
221 | 234 |
222 RUNTIME_FUNCTION(Runtime_GeneratorThrow) { | 235 RUNTIME_FUNCTION(Runtime_GeneratorThrow) { |
223 UNREACHABLE(); // Optimization disabled in SetUpGenerators(). | 236 UNREACHABLE(); |
224 return NULL; | 237 return nullptr; |
225 } | 238 } |
226 } // namespace internal | 239 } // namespace internal |
227 } // namespace v8 | 240 } // namespace v8 |
OLD | NEW |