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 CHECK(IsResumableFunction(function->shared()->kind())); | 20 CHECK(IsResumableFunction(function->shared()->kind())); |
21 | 21 |
22 Handle<FixedArray> operand_stack; | 22 // Underlying function needs to have bytecode available. |
23 if (function->shared()->HasBytecodeArray()) { | 23 DCHECK(function->shared()->HasBytecodeArray()); |
24 // New-style generators. | 24 DCHECK(!function->shared()->HasBaselineCode()); |
25 DCHECK(!function->shared()->HasBaselineCode()); | 25 int size = function->shared()->bytecode_array()->register_count(); |
26 int size = function->shared()->bytecode_array()->register_count(); | 26 Handle<FixedArray> operand_stack = isolate->factory()->NewFixedArray(size); |
27 operand_stack = isolate->factory()->NewFixedArray(size); | |
28 } else { | |
29 // Old-style generators. | |
30 DCHECK(function->shared()->HasBaselineCode()); | |
31 operand_stack = isolate->factory()->empty_fixed_array(); | |
32 } | |
33 | 27 |
34 Handle<JSGeneratorObject> generator = | 28 Handle<JSGeneratorObject> generator = |
35 isolate->factory()->NewJSGeneratorObject(function); | 29 isolate->factory()->NewJSGeneratorObject(function); |
36 generator->set_function(*function); | 30 generator->set_function(*function); |
37 generator->set_context(isolate->context()); | 31 generator->set_context(isolate->context()); |
38 generator->set_receiver(*receiver); | 32 generator->set_receiver(*receiver); |
39 generator->set_operand_stack(*operand_stack); | 33 generator->set_operand_stack(*operand_stack); |
40 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting); | 34 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting); |
41 return *generator; | 35 return *generator; |
42 } | 36 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 HandleScope scope(isolate); | 89 HandleScope scope(isolate); |
96 DCHECK(args.length() == 1); | 90 DCHECK(args.length() == 1); |
97 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 91 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
98 | 92 |
99 if (!generator->is_suspended()) return isolate->heap()->undefined_value(); | 93 if (!generator->is_suspended()) return isolate->heap()->undefined_value(); |
100 return Smi::FromInt(generator->source_position()); | 94 return Smi::FromInt(generator->source_position()); |
101 } | 95 } |
102 | 96 |
103 } // namespace internal | 97 } // namespace internal |
104 } // namespace v8 | 98 } // namespace v8 |
OLD | NEW |