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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 Handle<JSGeneratorObject> generator = | 33 Handle<JSGeneratorObject> generator = |
34 isolate->factory()->NewJSGeneratorObject(function); | 34 isolate->factory()->NewJSGeneratorObject(function); |
35 generator->set_function(*function); | 35 generator->set_function(*function); |
36 generator->set_context(isolate->context()); | 36 generator->set_context(isolate->context()); |
37 generator->set_receiver(*receiver); | 37 generator->set_receiver(*receiver); |
38 generator->set_operand_stack(*operand_stack); | 38 generator->set_operand_stack(*operand_stack); |
39 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting); | 39 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting); |
40 return *generator; | 40 return *generator; |
41 } | 41 } |
42 | 42 |
43 | |
44 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { | 43 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { |
45 HandleScope handle_scope(isolate); | 44 HandleScope handle_scope(isolate); |
46 DCHECK(args.length() == 1); | 45 DCHECK(args.length() == 1); |
47 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); | 46 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); |
48 | 47 |
49 JavaScriptFrameIterator stack_iterator(isolate); | 48 JavaScriptFrameIterator stack_iterator(isolate); |
50 JavaScriptFrame* frame = stack_iterator.frame(); | 49 JavaScriptFrame* frame = stack_iterator.frame(); |
51 CHECK(frame->function()->shared()->is_resumable()); | 50 CHECK(frame->function()->shared()->is_resumable()); |
52 DCHECK_EQ(frame->function(), generator_object->function()); | 51 DCHECK_EQ(frame->function(), generator_object->function()); |
53 DCHECK(frame->function()->shared()->is_compiled()); | 52 DCHECK(frame->function()->shared()->is_compiled()); |
(...skipping 30 matching lines...) Expand all Loading... |
84 RUNTIME_FUNCTION(Runtime_GeneratorClose) { | 83 RUNTIME_FUNCTION(Runtime_GeneratorClose) { |
85 HandleScope scope(isolate); | 84 HandleScope scope(isolate); |
86 DCHECK(args.length() == 1); | 85 DCHECK(args.length() == 1); |
87 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 86 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
88 | 87 |
89 generator->set_continuation(JSGeneratorObject::kGeneratorClosed); | 88 generator->set_continuation(JSGeneratorObject::kGeneratorClosed); |
90 | 89 |
91 return isolate->heap()->undefined_value(); | 90 return isolate->heap()->undefined_value(); |
92 } | 91 } |
93 | 92 |
94 | |
95 // Returns function of generator activation. | |
96 RUNTIME_FUNCTION(Runtime_GeneratorGetFunction) { | 93 RUNTIME_FUNCTION(Runtime_GeneratorGetFunction) { |
97 HandleScope scope(isolate); | 94 HandleScope scope(isolate); |
98 DCHECK(args.length() == 1); | 95 DCHECK(args.length() == 1); |
99 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 96 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
100 | 97 |
101 return generator->function(); | 98 return generator->function(); |
102 } | 99 } |
103 | 100 |
104 | |
105 // Returns receiver of generator activation. | |
106 RUNTIME_FUNCTION(Runtime_GeneratorGetReceiver) { | 101 RUNTIME_FUNCTION(Runtime_GeneratorGetReceiver) { |
107 HandleScope scope(isolate); | 102 HandleScope scope(isolate); |
108 DCHECK(args.length() == 1); | 103 DCHECK(args.length() == 1); |
109 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 104 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
110 | 105 |
111 return generator->receiver(); | 106 return generator->receiver(); |
112 } | 107 } |
113 | 108 |
114 | 109 RUNTIME_FUNCTION(Runtime_GeneratorGetInputOrDebugPos) { |
115 // Returns input of generator activation. | |
116 RUNTIME_FUNCTION(Runtime_GeneratorGetInput) { | |
117 HandleScope scope(isolate); | 110 HandleScope scope(isolate); |
118 DCHECK(args.length() == 1); | 111 DCHECK(args.length() == 1); |
119 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 112 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
120 | 113 |
121 return generator->input(); | 114 return generator->input_or_debug_pos(); |
122 } | 115 } |
123 | 116 |
124 // Returns resume mode of generator activation. | |
125 RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode) { | 117 RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode) { |
126 HandleScope scope(isolate); | 118 HandleScope scope(isolate); |
127 DCHECK(args.length() == 1); | 119 DCHECK(args.length() == 1); |
128 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 120 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
129 | 121 |
130 return Smi::FromInt(generator->resume_mode()); | 122 return Smi::FromInt(generator->resume_mode()); |
131 } | 123 } |
132 | 124 |
133 | |
134 RUNTIME_FUNCTION(Runtime_GeneratorGetContinuation) { | 125 RUNTIME_FUNCTION(Runtime_GeneratorGetContinuation) { |
135 HandleScope scope(isolate); | 126 HandleScope scope(isolate); |
136 DCHECK(args.length() == 1); | 127 DCHECK(args.length() == 1); |
137 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 128 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
138 | 129 |
139 return Smi::FromInt(generator->continuation()); | 130 return Smi::FromInt(generator->continuation()); |
140 } | 131 } |
141 | 132 |
142 | |
143 RUNTIME_FUNCTION(Runtime_GeneratorGetSourcePosition) { | 133 RUNTIME_FUNCTION(Runtime_GeneratorGetSourcePosition) { |
144 HandleScope scope(isolate); | 134 HandleScope scope(isolate); |
145 DCHECK(args.length() == 1); | 135 DCHECK(args.length() == 1); |
146 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 136 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
147 | 137 |
148 if (!generator->is_suspended()) return isolate->heap()->undefined_value(); | 138 if (!generator->is_suspended()) return isolate->heap()->undefined_value(); |
149 | 139 return Smi::FromInt(generator->source_position()); |
150 if (generator->function()->shared()->HasBytecodeArray()) UNIMPLEMENTED(); | |
151 | |
152 Handle<Code> code(generator->function()->code(), isolate); | |
153 int offset = generator->continuation(); | |
154 CHECK(0 <= offset && offset < code->instruction_size()); | |
155 return Smi::FromInt(code->SourcePosition(offset)); | |
156 } | 140 } |
157 | 141 |
158 } // namespace internal | 142 } // namespace internal |
159 } // namespace v8 | 143 } // namespace v8 |
OLD | NEW |