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" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } else { | 61 } else { |
62 Handle<FixedArray> operand_stack = | 62 Handle<FixedArray> operand_stack = |
63 isolate->factory()->NewFixedArray(operands_count); | 63 isolate->factory()->NewFixedArray(operands_count); |
64 frame->SaveOperandStack(*operand_stack); | 64 frame->SaveOperandStack(*operand_stack); |
65 generator_object->set_operand_stack(*operand_stack); | 65 generator_object->set_operand_stack(*operand_stack); |
66 } | 66 } |
67 | 67 |
68 return isolate->heap()->undefined_value(); | 68 return isolate->heap()->undefined_value(); |
69 } | 69 } |
70 | 70 |
| 71 |
71 RUNTIME_FUNCTION(Runtime_GeneratorClose) { | 72 RUNTIME_FUNCTION(Runtime_GeneratorClose) { |
72 HandleScope scope(isolate); | 73 HandleScope scope(isolate); |
73 DCHECK(args.length() == 1); | 74 DCHECK(args.length() == 1); |
74 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 75 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
75 | 76 |
76 generator->set_continuation(JSGeneratorObject::kGeneratorClosed); | 77 generator->set_continuation(JSGeneratorObject::kGeneratorClosed); |
77 | 78 |
78 return isolate->heap()->undefined_value(); | 79 return isolate->heap()->undefined_value(); |
79 } | 80 } |
80 | 81 |
(...skipping 21 matching lines...) Expand all Loading... |
102 // Returns input of generator activation. | 103 // Returns input of generator activation. |
103 RUNTIME_FUNCTION(Runtime_GeneratorGetInput) { | 104 RUNTIME_FUNCTION(Runtime_GeneratorGetInput) { |
104 HandleScope scope(isolate); | 105 HandleScope scope(isolate); |
105 DCHECK(args.length() == 1); | 106 DCHECK(args.length() == 1); |
106 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 107 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
107 | 108 |
108 return generator->input(); | 109 return generator->input(); |
109 } | 110 } |
110 | 111 |
111 | 112 |
| 113 // Returns resume mode of generator activation. |
| 114 RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode) { |
| 115 HandleScope scope(isolate); |
| 116 DCHECK(args.length() == 1); |
| 117 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
| 118 |
| 119 return Smi::FromInt(generator->resume_mode()); |
| 120 } |
| 121 |
| 122 |
112 // Returns generator continuation as a PC offset, or the magic -1 or 0 values. | 123 // Returns generator continuation as a PC offset, or the magic -1 or 0 values. |
113 RUNTIME_FUNCTION(Runtime_GeneratorGetContinuation) { | 124 RUNTIME_FUNCTION(Runtime_GeneratorGetContinuation) { |
114 HandleScope scope(isolate); | 125 HandleScope scope(isolate); |
115 DCHECK(args.length() == 1); | 126 DCHECK(args.length() == 1); |
116 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 127 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
117 | 128 |
118 return Smi::FromInt(generator->continuation()); | 129 return Smi::FromInt(generator->continuation()); |
119 } | 130 } |
120 | 131 |
121 | 132 |
122 RUNTIME_FUNCTION(Runtime_GeneratorGetSourcePosition) { | 133 RUNTIME_FUNCTION(Runtime_GeneratorGetSourcePosition) { |
123 HandleScope scope(isolate); | 134 HandleScope scope(isolate); |
124 DCHECK(args.length() == 1); | 135 DCHECK(args.length() == 1); |
125 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); | 136 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
126 | 137 |
127 if (generator->is_suspended()) { | 138 if (generator->is_suspended()) { |
128 Handle<Code> code(generator->function()->code(), isolate); | 139 Handle<Code> code(generator->function()->code(), isolate); |
129 int offset = generator->continuation(); | 140 int offset = generator->continuation(); |
130 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size()); | 141 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size()); |
131 return Smi::FromInt(code->SourcePosition(offset)); | 142 return Smi::FromInt(code->SourcePosition(offset)); |
132 } | 143 } |
133 | 144 |
134 return isolate->heap()->undefined_value(); | 145 return isolate->heap()->undefined_value(); |
135 } | 146 } |
136 | 147 |
| 148 |
| 149 RUNTIME_FUNCTION(Runtime_SuspendIgnitionGenerator) { |
| 150 HandleScope scope(isolate); |
| 151 DCHECK(args.length() == 2); |
| 152 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
| 153 CONVERT_ARG_HANDLE_CHECKED(Smi, state, 1); |
| 154 |
| 155 JavaScriptFrameIterator it(isolate); |
| 156 JavaScriptFrame* frame = it.frame(); |
| 157 Handle<JSFunction> function(frame->function()); |
| 158 CHECK(function->shared()->is_generator()); |
| 159 CHECK_EQ(frame->type(), StackFrame::INTERPRETED); |
| 160 |
| 161 // Save register file. |
| 162 int size = function->shared()->bytecode_array()->register_count(); |
| 163 Handle<FixedArray> register_file = isolate->factory()->NewFixedArray(size); |
| 164 for (int i = 0; i < size; ++i) { |
| 165 Object* value = |
| 166 static_cast<InterpretedFrame*>(frame)->ReadInterpreterRegister(i); |
| 167 register_file->set(i, value); |
| 168 } |
| 169 |
| 170 generator->set_operand_stack(*register_file); |
| 171 generator->set_context(Context::cast(frame->context())); |
| 172 generator->set_continuation(state->value()); |
| 173 |
| 174 return isolate->heap()->undefined_value(); |
| 175 } |
| 176 |
| 177 |
| 178 RUNTIME_FUNCTION(Runtime_ResumeIgnitionGenerator) { |
| 179 HandleScope scope(isolate); |
| 180 DCHECK(args.length() == 1); |
| 181 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0); |
| 182 |
| 183 JavaScriptFrameIterator it(isolate); |
| 184 JavaScriptFrame* frame = it.frame(); |
| 185 Handle<JSFunction> function(frame->function()); |
| 186 CHECK(function->shared()->is_generator()); |
| 187 CHECK_EQ(frame->type(), StackFrame::INTERPRETED); |
| 188 |
| 189 // Restore register file. |
| 190 int size = function->shared()->bytecode_array()->register_count(); |
| 191 DCHECK_EQ(size, generator->operand_stack()->length()); |
| 192 for (int i = 0; i < size; ++i) { |
| 193 Object* value = generator->operand_stack()->get(i); |
| 194 static_cast<InterpretedFrame*>(frame)->WriteInterpreterRegister(i, value); |
| 195 } |
| 196 generator->set_operand_stack(isolate->heap()->empty_fixed_array()); |
| 197 |
| 198 int state = generator->continuation(); |
| 199 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting); |
| 200 return Smi::FromInt(state); |
| 201 } |
| 202 |
137 } // namespace internal | 203 } // namespace internal |
138 } // namespace v8 | 204 } // namespace v8 |
OLD | NEW |