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 2056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2067 break; | 2067 break; |
2068 } | 2068 } |
2069 } | 2069 } |
2070 } | 2070 } |
2071 | 2071 |
2072 | 2072 |
2073 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, | 2073 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
2074 Expression *value, | 2074 Expression *value, |
2075 JSGeneratorObject::ResumeMode resume_mode) { | 2075 JSGeneratorObject::ResumeMode resume_mode) { |
2076 // The value stays in eax, and is ultimately read by the resumed generator, as | 2076 // The value stays in eax, and is ultimately read by the resumed generator, as |
2077 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. ebx | 2077 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or used |
2078 // will hold the generator object until the activation has been resumed. | 2078 // to throw the value when the resumed generator is already closed. ebx will |
wingo
2014/01/13 13:44:49
It's probably best to use a full sentence in the c
yusukesuzuki
2014/01/13 14:27:51
Thanks for your review. Done. Is it OK?
| |
2079 // hold the generator object until the activation has been resumed. | |
2079 VisitForStackValue(generator); | 2080 VisitForStackValue(generator); |
2080 VisitForAccumulatorValue(value); | 2081 VisitForAccumulatorValue(value); |
2081 __ pop(ebx); | 2082 __ pop(ebx); |
2082 | 2083 |
2083 // Check generator state. | 2084 // Check generator state. |
2084 Label wrong_state, done; | 2085 Label wrong_state, closed_state, done; |
2085 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting <= 0); | 2086 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0); |
2086 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed <= 0); | 2087 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0); |
2087 __ cmp(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), | 2088 __ cmp(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
2088 Immediate(Smi::FromInt(0))); | 2089 Immediate(Smi::FromInt(0))); |
2089 __ j(less_equal, &wrong_state); | 2090 __ j(equal, &closed_state); |
2091 __ j(less, &wrong_state); | |
2090 | 2092 |
2091 // Load suspended function and context. | 2093 // Load suspended function and context. |
2092 __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); | 2094 __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); |
2093 __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); | 2095 __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); |
2094 | 2096 |
2095 // Push receiver. | 2097 // Push receiver. |
2096 __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); | 2098 __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); |
2097 | 2099 |
2098 // Push holes for arguments to generator function. | 2100 // Push holes for arguments to generator function. |
2099 __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); | 2101 __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2149 __ push(ecx); | 2151 __ push(ecx); |
2150 __ jmp(&push_operand_holes); | 2152 __ jmp(&push_operand_holes); |
2151 __ bind(&call_resume); | 2153 __ bind(&call_resume); |
2152 __ push(ebx); | 2154 __ push(ebx); |
2153 __ push(result_register()); | 2155 __ push(result_register()); |
2154 __ Push(Smi::FromInt(resume_mode)); | 2156 __ Push(Smi::FromInt(resume_mode)); |
2155 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); | 2157 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
2156 // Not reached: the runtime call returns elsewhere. | 2158 // Not reached: the runtime call returns elsewhere. |
2157 __ Abort(kGeneratorFailedToResume); | 2159 __ Abort(kGeneratorFailedToResume); |
2158 | 2160 |
2161 // Reach here when generator is closed. | |
2162 __ bind(&closed_state); | |
2163 if (resume_mode == JSGeneratorObject::NEXT) { | |
2164 // Return completed iterator result when generator is closed. | |
2165 __ push(Immediate(isolate()->factory()->undefined_value())); | |
2166 // Pop value from top-of-stack slot; box result into result register. | |
2167 EmitCreateIteratorResult(true); | |
2168 } else { | |
2169 // Throw the provided value. | |
2170 __ push(eax); | |
2171 __ CallRuntime(Runtime::kThrow, 1); | |
2172 } | |
2173 __ jmp(&done); | |
2174 | |
2159 // Throw error if we attempt to operate on a running generator. | 2175 // Throw error if we attempt to operate on a running generator. |
2160 __ bind(&wrong_state); | 2176 __ bind(&wrong_state); |
2161 __ push(ebx); | 2177 __ push(ebx); |
2162 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); | 2178 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); |
2163 | 2179 |
2164 __ bind(&done); | 2180 __ bind(&done); |
2165 context()->Plug(result_register()); | 2181 context()->Plug(result_register()); |
2166 } | 2182 } |
2167 | 2183 |
2168 | 2184 |
(...skipping 2720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4889 | 4905 |
4890 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4906 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
4891 Assembler::target_address_at(call_target_address)); | 4907 Assembler::target_address_at(call_target_address)); |
4892 return OSR_AFTER_STACK_CHECK; | 4908 return OSR_AFTER_STACK_CHECK; |
4893 } | 4909 } |
4894 | 4910 |
4895 | 4911 |
4896 } } // namespace v8::internal | 4912 } } // namespace v8::internal |
4897 | 4913 |
4898 #endif // V8_TARGET_ARCH_IA32 | 4914 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |