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" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 RUNTIME_FUNCTION(Runtime_CreateJSGeneratorObject) { | 15 RUNTIME_FUNCTION(Runtime_CreateJSGeneratorObject) { |
16 HandleScope scope(isolate); | 16 HandleScope scope(isolate); |
17 DCHECK(args.length() == 2); | 17 DCHECK(args.length() == 2); |
18 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 18 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
19 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); | 19 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); |
20 RUNTIME_ASSERT(function->shared()->is_generator()); | 20 RUNTIME_ASSERT(function->shared()->is_generator() || |
| 21 function->shared()->is_async()); |
21 | 22 |
22 Handle<JSGeneratorObject> generator = | 23 Handle<JSGeneratorObject> generator = |
23 isolate->factory()->NewJSGeneratorObject(function); | 24 isolate->factory()->NewJSGeneratorObject(function); |
24 generator->set_function(*function); | 25 generator->set_function(*function); |
25 generator->set_context(isolate->context()); | 26 generator->set_context(isolate->context()); |
26 generator->set_receiver(*receiver); | 27 generator->set_receiver(*receiver); |
27 generator->set_operand_stack(isolate->heap()->empty_fixed_array()); | 28 generator->set_operand_stack(isolate->heap()->empty_fixed_array()); |
28 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting); | 29 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting); |
29 return *generator; | 30 return *generator; |
30 } | 31 } |
31 | 32 |
32 | 33 |
33 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { | 34 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { |
34 HandleScope handle_scope(isolate); | 35 HandleScope handle_scope(isolate); |
35 DCHECK(args.length() == 1); | 36 DCHECK(args.length() == 1); |
36 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); | 37 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); |
37 | 38 |
38 JavaScriptFrameIterator stack_iterator(isolate); | 39 JavaScriptFrameIterator stack_iterator(isolate); |
39 JavaScriptFrame* frame = stack_iterator.frame(); | 40 JavaScriptFrame* frame = stack_iterator.frame(); |
40 RUNTIME_ASSERT(frame->function()->shared()->is_generator()); | 41 RUNTIME_ASSERT(frame->function()->shared()->is_generator() || |
| 42 frame->function()->shared()->is_async()); |
41 DCHECK_EQ(frame->function(), generator_object->function()); | 43 DCHECK_EQ(frame->function(), generator_object->function()); |
42 DCHECK(frame->function()->shared()->is_compiled()); | 44 DCHECK(frame->function()->shared()->is_compiled()); |
43 DCHECK(!frame->function()->IsOptimized()); | 45 DCHECK(!frame->function()->IsOptimized()); |
44 | 46 |
45 // The caller should have saved the context and continuation already. | 47 // The caller should have saved the context and continuation already. |
46 DCHECK_EQ(generator_object->context(), Context::cast(frame->context())); | 48 DCHECK_EQ(generator_object->context(), Context::cast(frame->context())); |
47 DCHECK_LT(0, generator_object->continuation()); | 49 DCHECK_LT(0, generator_object->continuation()); |
48 | 50 |
49 // 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 |
50 // 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. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 int offset = generator->continuation(); | 131 int offset = generator->continuation(); |
130 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size()); | 132 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size()); |
131 return Smi::FromInt(code->SourcePosition(offset)); | 133 return Smi::FromInt(code->SourcePosition(offset)); |
132 } | 134 } |
133 | 135 |
134 return isolate->heap()->undefined_value(); | 136 return isolate->heap()->undefined_value(); |
135 } | 137 } |
136 | 138 |
137 } // namespace internal | 139 } // namespace internal |
138 } // namespace v8 | 140 } // namespace v8 |
OLD | NEW |