OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2104 break; | 2104 break; |
2105 } | 2105 } |
2106 } | 2106 } |
2107 } | 2107 } |
2108 | 2108 |
2109 | 2109 |
2110 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, | 2110 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
2111 Expression *value, | 2111 Expression *value, |
2112 JSGeneratorObject::ResumeMode resume_mode) { | 2112 JSGeneratorObject::ResumeMode resume_mode) { |
2113 // The value stays in r0, and is ultimately read by the resumed generator, as | 2113 // The value stays in r0, and is ultimately read by the resumed generator, as |
2114 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. r1 | 2114 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or used |
2115 // will hold the generator object until the activation has been resumed. | 2115 // to throw the value when the resumed generator is already closed. r1 will |
| 2116 // hold the generator object until the activation has been resumed. |
2116 VisitForStackValue(generator); | 2117 VisitForStackValue(generator); |
2117 VisitForAccumulatorValue(value); | 2118 VisitForAccumulatorValue(value); |
2118 __ pop(r1); | 2119 __ pop(r1); |
2119 | 2120 |
2120 // Check generator state. | 2121 // Check generator state. |
2121 Label wrong_state, done; | 2122 Label wrong_state, closed_state, done; |
2122 __ ldr(r3, FieldMemOperand(r1, JSGeneratorObject::kContinuationOffset)); | 2123 __ ldr(r3, FieldMemOperand(r1, JSGeneratorObject::kContinuationOffset)); |
2123 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting <= 0); | 2124 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0); |
2124 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed <= 0); | 2125 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0); |
2125 __ cmp(r3, Operand(Smi::FromInt(0))); | 2126 __ cmp(r3, Operand(Smi::FromInt(0))); |
2126 __ b(le, &wrong_state); | 2127 __ b(eq, &closed_state); |
| 2128 __ b(lt, &wrong_state); |
2127 | 2129 |
2128 // Load suspended function and context. | 2130 // Load suspended function and context. |
2129 __ ldr(cp, FieldMemOperand(r1, JSGeneratorObject::kContextOffset)); | 2131 __ ldr(cp, FieldMemOperand(r1, JSGeneratorObject::kContextOffset)); |
2130 __ ldr(r4, FieldMemOperand(r1, JSGeneratorObject::kFunctionOffset)); | 2132 __ ldr(r4, FieldMemOperand(r1, JSGeneratorObject::kFunctionOffset)); |
2131 | 2133 |
2132 // Load receiver and store as the first argument. | 2134 // Load receiver and store as the first argument. |
2133 __ ldr(r2, FieldMemOperand(r1, JSGeneratorObject::kReceiverOffset)); | 2135 __ ldr(r2, FieldMemOperand(r1, JSGeneratorObject::kReceiverOffset)); |
2134 __ push(r2); | 2136 __ push(r2); |
2135 | 2137 |
2136 // Push holes for the rest of the arguments to the generator function. | 2138 // Push holes for the rest of the arguments to the generator function. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2191 __ push(r2); | 2193 __ push(r2); |
2192 __ b(&push_operand_holes); | 2194 __ b(&push_operand_holes); |
2193 __ bind(&call_resume); | 2195 __ bind(&call_resume); |
2194 ASSERT(!result_register().is(r1)); | 2196 ASSERT(!result_register().is(r1)); |
2195 __ Push(r1, result_register()); | 2197 __ Push(r1, result_register()); |
2196 __ Push(Smi::FromInt(resume_mode)); | 2198 __ Push(Smi::FromInt(resume_mode)); |
2197 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); | 2199 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
2198 // Not reached: the runtime call returns elsewhere. | 2200 // Not reached: the runtime call returns elsewhere. |
2199 __ stop("not-reached"); | 2201 __ stop("not-reached"); |
2200 | 2202 |
| 2203 // Reach here when generator is closed. |
| 2204 __ bind(&closed_state); |
| 2205 if (resume_mode == JSGeneratorObject::NEXT) { |
| 2206 // Return completed iterator result when generator is closed. |
| 2207 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 2208 __ push(r2); |
| 2209 // Pop value from top-of-stack slot; box result into result register. |
| 2210 EmitCreateIteratorResult(true); |
| 2211 } else { |
| 2212 // Throw the provided value. |
| 2213 __ push(r0); |
| 2214 __ CallRuntime(Runtime::kThrow, 1); |
| 2215 } |
| 2216 __ jmp(&done); |
| 2217 |
2201 // Throw error if we attempt to operate on a running generator. | 2218 // Throw error if we attempt to operate on a running generator. |
2202 __ bind(&wrong_state); | 2219 __ bind(&wrong_state); |
2203 __ push(r1); | 2220 __ push(r1); |
2204 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); | 2221 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); |
2205 | 2222 |
2206 __ bind(&done); | 2223 __ bind(&done); |
2207 context()->Plug(result_register()); | 2224 context()->Plug(result_register()); |
2208 } | 2225 } |
2209 | 2226 |
2210 | 2227 |
(...skipping 2682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4893 ASSERT(Memory::uint32_at(interrupt_address_pointer) == | 4910 ASSERT(Memory::uint32_at(interrupt_address_pointer) == |
4894 reinterpret_cast<uint32_t>( | 4911 reinterpret_cast<uint32_t>( |
4895 isolate->builtins()->OsrAfterStackCheck()->entry())); | 4912 isolate->builtins()->OsrAfterStackCheck()->entry())); |
4896 return OSR_AFTER_STACK_CHECK; | 4913 return OSR_AFTER_STACK_CHECK; |
4897 } | 4914 } |
4898 | 4915 |
4899 | 4916 |
4900 } } // namespace v8::internal | 4917 } } // namespace v8::internal |
4901 | 4918 |
4902 #endif // V8_TARGET_ARCH_ARM | 4919 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |