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() == 1); |
18 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 18 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
19 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); | |
20 RUNTIME_ASSERT(function->shared()->is_generator()); | 19 RUNTIME_ASSERT(function->shared()->is_generator()); |
21 | 20 |
22 Handle<FixedArray> operand_stack; | 21 Handle<FixedArray> operand_stack; |
23 if (FLAG_ignition && FLAG_ignition_generators) { | 22 if (FLAG_ignition && FLAG_ignition_generators) { |
24 int size = function->shared()->bytecode_array()->register_count(); | 23 int size = function->shared()->bytecode_array()->register_count(); |
25 operand_stack = isolate->factory()->NewFixedArray(size); | 24 operand_stack = isolate->factory()->NewFixedArray(size); |
26 } else { | 25 } else { |
27 DCHECK(!function->shared()->HasBytecodeArray()); | 26 DCHECK(!function->shared()->HasBytecodeArray()); |
28 operand_stack = handle(isolate->heap()->empty_fixed_array()); | 27 operand_stack = handle(isolate->heap()->empty_fixed_array()); |
29 } | 28 } |
30 | 29 |
31 Handle<JSGeneratorObject> generator = | 30 Handle<JSGeneratorObject> generator = |
32 isolate->factory()->NewJSGeneratorObject(function); | 31 isolate->factory()->NewJSGeneratorObject(function); |
33 generator->set_function(*function); | 32 generator->set_function(*function); |
34 generator->set_context(isolate->context()); | 33 generator->set_context(isolate->context()); |
35 generator->set_receiver(*receiver); | |
36 generator->set_operand_stack(*operand_stack); | 34 generator->set_operand_stack(*operand_stack); |
37 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting); | 35 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting); |
38 return *generator; | 36 return *generator; |
39 } | 37 } |
40 | 38 |
41 | 39 |
42 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { | 40 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { |
43 HandleScope handle_scope(isolate); | 41 HandleScope handle_scope(isolate); |
44 DCHECK(args.length() == 1); | 42 DCHECK(args.length() == 1); |
45 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); | 43 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // Returns function of generator activation. | 90 // Returns function of generator activation. |
93 RUNTIME_FUNCTION(Runtime_GeneratorGetFunction) { | 91 RUNTIME_FUNCTION(Runtime_GeneratorGetFunction) { |
94 HandleScope scope(isolate); | 92 HandleScope scope(isolate); |
95 DCHECK(args.length() == 1); | 93 DCHECK(args.length() == 1); |
96 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 94 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
97 | 95 |
98 return generator->function(); | 96 return generator->function(); |
99 } | 97 } |
100 | 98 |
101 | 99 |
102 // Returns receiver of generator activation. | |
103 RUNTIME_FUNCTION(Runtime_GeneratorGetReceiver) { | |
104 HandleScope scope(isolate); | |
105 DCHECK(args.length() == 1); | |
106 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | |
107 | |
108 return generator->receiver(); | |
109 } | |
110 | |
111 | |
112 // Returns input of generator activation. | 100 // Returns input of generator activation. |
113 RUNTIME_FUNCTION(Runtime_GeneratorGetInput) { | 101 RUNTIME_FUNCTION(Runtime_GeneratorGetInput) { |
114 HandleScope scope(isolate); | 102 HandleScope scope(isolate); |
115 DCHECK(args.length() == 1); | 103 DCHECK(args.length() == 1); |
116 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 104 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
117 | 105 |
118 return generator->input(); | 106 return generator->input(); |
119 } | 107 } |
120 | 108 |
121 | 109 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 int offset = generator->continuation(); | 185 int offset = generator->continuation(); |
198 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size()); | 186 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size()); |
199 return Smi::FromInt(code->SourcePosition(offset)); | 187 return Smi::FromInt(code->SourcePosition(offset)); |
200 } | 188 } |
201 | 189 |
202 return isolate->heap()->undefined_value(); | 190 return isolate->heap()->undefined_value(); |
203 } | 191 } |
204 | 192 |
205 } // namespace internal | 193 } // namespace internal |
206 } // namespace v8 | 194 } // namespace v8 |
OLD | NEW |