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/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 #include "src/frames-inl.h" | 10 #include "src/frames-inl.h" |
11 #include "src/objects-inl.h" | 11 #include "src/objects-inl.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 RUNTIME_FUNCTION(Runtime_CreateJSGeneratorObject) { | 16 RUNTIME_FUNCTION(Runtime_CreateJSGeneratorObject) { |
17 HandleScope scope(isolate); | 17 HandleScope scope(isolate); |
18 DCHECK(args.length() == 2); | 18 DCHECK(args.length() == 2); |
19 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 19 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
20 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); | 20 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); |
21 CHECK(function->shared()->is_resumable()); | 21 CHECK(IsResumableFunction(function->shared()->kind())); |
22 | 22 |
23 Handle<FixedArray> operand_stack; | 23 Handle<FixedArray> operand_stack; |
24 if (function->shared()->HasBytecodeArray()) { | 24 if (function->shared()->HasBytecodeArray()) { |
25 // New-style generators. | 25 // New-style generators. |
26 DCHECK(!function->shared()->HasBaselineCode()); | 26 DCHECK(!function->shared()->HasBaselineCode()); |
27 int size = function->shared()->bytecode_array()->register_count(); | 27 int size = function->shared()->bytecode_array()->register_count(); |
28 operand_stack = isolate->factory()->NewFixedArray(size); | 28 operand_stack = isolate->factory()->NewFixedArray(size); |
29 } else { | 29 } else { |
30 // Old-style generators. | 30 // Old-style generators. |
31 DCHECK(function->shared()->HasBaselineCode()); | 31 DCHECK(function->shared()->HasBaselineCode()); |
(...skipping 10 matching lines...) Expand all Loading... |
42 return *generator; | 42 return *generator; |
43 } | 43 } |
44 | 44 |
45 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { | 45 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { |
46 HandleScope handle_scope(isolate); | 46 HandleScope handle_scope(isolate); |
47 DCHECK(args.length() == 1); | 47 DCHECK(args.length() == 1); |
48 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); | 48 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); |
49 | 49 |
50 JavaScriptFrameIterator stack_iterator(isolate); | 50 JavaScriptFrameIterator stack_iterator(isolate); |
51 JavaScriptFrame* frame = stack_iterator.frame(); | 51 JavaScriptFrame* frame = stack_iterator.frame(); |
52 CHECK(frame->function()->shared()->is_resumable()); | 52 CHECK(IsResumableFunction(frame->function()->shared()->kind())); |
53 DCHECK_EQ(frame->function(), generator_object->function()); | 53 DCHECK_EQ(frame->function(), generator_object->function()); |
54 DCHECK(frame->function()->shared()->is_compiled()); | 54 DCHECK(frame->function()->shared()->is_compiled()); |
55 DCHECK(!frame->function()->IsOptimized()); | 55 DCHECK(!frame->function()->IsOptimized()); |
56 | 56 |
57 isolate->debug()->RecordAsyncFunction(generator_object); | 57 isolate->debug()->RecordAsyncFunction(generator_object); |
58 | 58 |
59 // The caller should have saved the context and continuation already. | 59 // The caller should have saved the context and continuation already. |
60 DCHECK_EQ(generator_object->context(), Context::cast(frame->context())); | 60 DCHECK_EQ(generator_object->context(), Context::cast(frame->context())); |
61 DCHECK_LT(0, generator_object->continuation()); | 61 DCHECK_LT(0, generator_object->continuation()); |
62 | 62 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 HandleScope scope(isolate); | 136 HandleScope scope(isolate); |
137 DCHECK(args.length() == 1); | 137 DCHECK(args.length() == 1); |
138 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 138 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
139 | 139 |
140 if (!generator->is_suspended()) return isolate->heap()->undefined_value(); | 140 if (!generator->is_suspended()) return isolate->heap()->undefined_value(); |
141 return Smi::FromInt(generator->source_position()); | 141 return Smi::FromInt(generator->source_position()); |
142 } | 142 } |
143 | 143 |
144 } // namespace internal | 144 } // namespace internal |
145 } // namespace v8 | 145 } // namespace v8 |
OLD | NEW |