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 18 matching lines...) Expand all Loading... |
29 generator->set_receiver(frame->receiver()); | 29 generator->set_receiver(frame->receiver()); |
30 generator->set_continuation(0); | 30 generator->set_continuation(0); |
31 generator->set_operand_stack(isolate->heap()->empty_fixed_array()); | 31 generator->set_operand_stack(isolate->heap()->empty_fixed_array()); |
32 | 32 |
33 return *generator; | 33 return *generator; |
34 } | 34 } |
35 | 35 |
36 | 36 |
37 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { | 37 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { |
38 HandleScope handle_scope(isolate); | 38 HandleScope handle_scope(isolate); |
39 DCHECK(args.length() == 1 || args.length() == 2); | 39 DCHECK(args.length() == 1); |
40 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); | 40 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); |
41 | 41 |
42 JavaScriptFrameIterator stack_iterator(isolate); | 42 JavaScriptFrameIterator stack_iterator(isolate); |
43 JavaScriptFrame* frame = stack_iterator.frame(); | 43 JavaScriptFrame* frame = stack_iterator.frame(); |
44 RUNTIME_ASSERT(frame->function()->shared()->is_generator()); | 44 RUNTIME_ASSERT(frame->function()->shared()->is_generator()); |
45 DCHECK_EQ(frame->function(), generator_object->function()); | 45 DCHECK_EQ(frame->function(), generator_object->function()); |
46 | 46 |
47 // The caller should have saved the context and continuation already. | 47 // The caller should have saved the context and continuation already. |
48 DCHECK_EQ(generator_object->context(), Context::cast(frame->context())); | 48 DCHECK_EQ(generator_object->context(), Context::cast(frame->context())); |
49 DCHECK_LT(0, generator_object->continuation()); | 49 DCHECK_LT(0, generator_object->continuation()); |
50 | 50 |
51 // We expect there to be at least two values on the operand stack: the return | 51 // We expect there to be at least two values on the operand stack: the return |
52 // value of the yield expression, and the arguments to this runtime call. | 52 // value of the yield expression, and the arguments to this runtime call. |
53 // Neither of those should be saved. | 53 // Neither of those should be saved. |
54 int operands_count = frame->ComputeOperandsCount(); | 54 int operands_count = frame->ComputeOperandsCount(); |
55 DCHECK_GE(operands_count, 1 + args.length()); | 55 DCHECK_GE(operands_count, 1 + args.length()); |
56 operands_count -= 1 + args.length(); | 56 operands_count -= 1 + args.length(); |
57 | 57 |
58 // Second argument indicates that we need to patch the handler table because | |
59 // a delegating yield introduced a try-catch statement at expression level, | |
60 // hence the operand count was off when we statically computed it. | |
61 // TODO(mstarzinger): This special case disappears with do-expressions. | |
62 if (args.length() == 2) { | |
63 CONVERT_SMI_ARG_CHECKED(handler_index, 1); | |
64 Handle<Code> code(frame->unchecked_code()); | |
65 Handle<HandlerTable> table(HandlerTable::cast(code->handler_table())); | |
66 int handler_depth = operands_count - TryBlockConstant::kElementCount; | |
67 table->SetRangeDepth(handler_index, handler_depth); | |
68 } | |
69 | |
70 if (operands_count == 0) { | 58 if (operands_count == 0) { |
71 // Although it's semantically harmless to call this function with an | 59 // Although it's semantically harmless to call this function with an |
72 // operands_count of zero, it is also unnecessary. | 60 // operands_count of zero, it is also unnecessary. |
73 DCHECK_EQ(generator_object->operand_stack(), | 61 DCHECK_EQ(generator_object->operand_stack(), |
74 isolate->heap()->empty_fixed_array()); | 62 isolate->heap()->empty_fixed_array()); |
75 } else { | 63 } else { |
76 Handle<FixedArray> operand_stack = | 64 Handle<FixedArray> operand_stack = |
77 isolate->factory()->NewFixedArray(operands_count); | 65 isolate->factory()->NewFixedArray(operands_count); |
78 frame->SaveOperandStack(*operand_stack); | 66 frame->SaveOperandStack(*operand_stack); |
79 generator_object->set_operand_stack(*operand_stack); | 67 generator_object->set_operand_stack(*operand_stack); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 return nullptr; | 219 return nullptr; |
232 } | 220 } |
233 | 221 |
234 | 222 |
235 RUNTIME_FUNCTION(Runtime_GeneratorThrow) { | 223 RUNTIME_FUNCTION(Runtime_GeneratorThrow) { |
236 UNREACHABLE(); | 224 UNREACHABLE(); |
237 return nullptr; | 225 return nullptr; |
238 } | 226 } |
239 } // namespace internal | 227 } // namespace internal |
240 } // namespace v8 | 228 } // namespace v8 |
OLD | NEW |