OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
8 | 8 |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 2146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2157 Expression *value, | 2157 Expression *value, |
2158 JSGeneratorObject::ResumeMode resume_mode) { | 2158 JSGeneratorObject::ResumeMode resume_mode) { |
2159 // The value stays in eax, and is ultimately read by the resumed generator, as | 2159 // The value stays in eax, and is ultimately read by the resumed generator, as |
2160 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it | 2160 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it |
2161 // is read to throw the value when the resumed generator is already closed. | 2161 // is read to throw the value when the resumed generator is already closed. |
2162 // ebx will hold the generator object until the activation has been resumed. | 2162 // ebx will hold the generator object until the activation has been resumed. |
2163 VisitForStackValue(generator); | 2163 VisitForStackValue(generator); |
2164 VisitForAccumulatorValue(value); | 2164 VisitForAccumulatorValue(value); |
2165 __ pop(ebx); | 2165 __ pop(ebx); |
2166 | 2166 |
2167 // Check generator state. | |
2168 Label wrong_state, closed_state, done; | |
2169 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0); | |
2170 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0); | |
2171 __ cmp(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), | |
2172 Immediate(Smi::FromInt(0))); | |
2173 __ j(equal, &closed_state); | |
2174 __ j(less, &wrong_state); | |
2175 | |
2176 // Load suspended function and context. | 2167 // Load suspended function and context. |
2177 __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); | 2168 __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); |
2178 __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); | 2169 __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); |
2179 | 2170 |
2180 // Push receiver. | 2171 // Push receiver. |
2181 __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); | 2172 __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); |
2182 | 2173 |
2183 // Push holes for arguments to generator function. | 2174 // Push holes for arguments to generator function. |
2184 __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); | 2175 __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
2185 __ mov(edx, | 2176 __ mov(edx, |
2186 FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); | 2177 FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
2187 __ mov(ecx, isolate()->factory()->the_hole_value()); | 2178 __ mov(ecx, isolate()->factory()->the_hole_value()); |
2188 Label push_argument_holes, push_frame; | 2179 Label push_argument_holes, push_frame; |
2189 __ bind(&push_argument_holes); | 2180 __ bind(&push_argument_holes); |
2190 __ sub(edx, Immediate(Smi::FromInt(1))); | 2181 __ sub(edx, Immediate(Smi::FromInt(1))); |
2191 __ j(carry, &push_frame); | 2182 __ j(carry, &push_frame); |
2192 __ push(ecx); | 2183 __ push(ecx); |
2193 __ jmp(&push_argument_holes); | 2184 __ jmp(&push_argument_holes); |
2194 | 2185 |
2195 // Enter a new JavaScript frame, and initialize its slots as they were when | 2186 // Enter a new JavaScript frame, and initialize its slots as they were when |
2196 // the generator was suspended. | 2187 // the generator was suspended. |
2197 Label resume_frame; | 2188 Label resume_frame, done; |
2198 __ bind(&push_frame); | 2189 __ bind(&push_frame); |
2199 __ call(&resume_frame); | 2190 __ call(&resume_frame); |
2200 __ jmp(&done); | 2191 __ jmp(&done); |
2201 __ bind(&resume_frame); | 2192 __ bind(&resume_frame); |
2202 __ push(ebp); // Caller's frame pointer. | 2193 __ push(ebp); // Caller's frame pointer. |
2203 __ mov(ebp, esp); | 2194 __ mov(ebp, esp); |
2204 __ push(esi); // Callee's context. | 2195 __ push(esi); // Callee's context. |
2205 __ push(edi); // Callee's JS Function. | 2196 __ push(edi); // Callee's JS Function. |
2206 | 2197 |
2207 // Load the operand stack size. | 2198 // Load the operand stack size. |
(...skipping 26 matching lines...) Expand all Loading... |
2234 __ push(ecx); | 2225 __ push(ecx); |
2235 __ jmp(&push_operand_holes); | 2226 __ jmp(&push_operand_holes); |
2236 __ bind(&call_resume); | 2227 __ bind(&call_resume); |
2237 __ push(ebx); | 2228 __ push(ebx); |
2238 __ push(result_register()); | 2229 __ push(result_register()); |
2239 __ Push(Smi::FromInt(resume_mode)); | 2230 __ Push(Smi::FromInt(resume_mode)); |
2240 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); | 2231 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
2241 // Not reached: the runtime call returns elsewhere. | 2232 // Not reached: the runtime call returns elsewhere. |
2242 __ Abort(kGeneratorFailedToResume); | 2233 __ Abort(kGeneratorFailedToResume); |
2243 | 2234 |
2244 // Reach here when generator is closed. | |
2245 __ bind(&closed_state); | |
2246 if (resume_mode == JSGeneratorObject::NEXT) { | |
2247 // Return completed iterator result when generator is closed. | |
2248 __ push(Immediate(isolate()->factory()->undefined_value())); | |
2249 // Pop value from top-of-stack slot; box result into result register. | |
2250 EmitCreateIteratorResult(true); | |
2251 } else { | |
2252 // Throw the provided value. | |
2253 __ push(eax); | |
2254 __ CallRuntime(Runtime::kThrow, 1); | |
2255 } | |
2256 __ jmp(&done); | |
2257 | |
2258 // Throw error if we attempt to operate on a running generator. | |
2259 __ bind(&wrong_state); | |
2260 __ push(ebx); | |
2261 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); | |
2262 | |
2263 __ bind(&done); | 2235 __ bind(&done); |
2264 context()->Plug(result_register()); | 2236 context()->Plug(result_register()); |
2265 } | 2237 } |
2266 | 2238 |
2267 | 2239 |
2268 void FullCodeGenerator::EmitCreateIteratorResult(bool done) { | 2240 void FullCodeGenerator::EmitCreateIteratorResult(bool done) { |
2269 Label gc_required; | 2241 Label gc_required; |
2270 Label allocated; | 2242 Label allocated; |
2271 | 2243 |
2272 const int instance_size = 5 * kPointerSize; | 2244 const int instance_size = 5 * kPointerSize; |
(...skipping 2970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5243 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5215 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
5244 Assembler::target_address_at(call_target_address, | 5216 Assembler::target_address_at(call_target_address, |
5245 unoptimized_code)); | 5217 unoptimized_code)); |
5246 return OSR_AFTER_STACK_CHECK; | 5218 return OSR_AFTER_STACK_CHECK; |
5247 } | 5219 } |
5248 | 5220 |
5249 | 5221 |
5250 } } // namespace v8::internal | 5222 } } // namespace v8::internal |
5251 | 5223 |
5252 #endif // V8_TARGET_ARCH_IA32 | 5224 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |