Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: src/mips/full-codegen-mips.cc

Issue 136003003: Closed generator returns a completed object instead of throwing a error (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Rev 2 Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 break; 2126 break;
2127 } 2127 }
2128 } 2128 }
2129 } 2129 }
2130 2130
2131 2131
2132 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, 2132 void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
2133 Expression *value, 2133 Expression *value,
2134 JSGeneratorObject::ResumeMode resume_mode) { 2134 JSGeneratorObject::ResumeMode resume_mode) {
2135 // The value stays in a0, and is ultimately read by the resumed generator, as 2135 // The value stays in a0, and is ultimately read by the resumed generator, as
2136 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. a1 2136 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it
2137 // will hold the generator object until the activation has been resumed. 2137 // is read to throw the value when the resumed generator is already closed.
2138 // a1 will hold the generator object until the activation has been resumed.
2138 VisitForStackValue(generator); 2139 VisitForStackValue(generator);
2139 VisitForAccumulatorValue(value); 2140 VisitForAccumulatorValue(value);
2140 __ pop(a1); 2141 __ pop(a1);
2141 2142
2142 // Check generator state. 2143 // Check generator state.
2143 Label wrong_state, done; 2144 Label wrong_state, closed_state, done;
2144 __ lw(a3, FieldMemOperand(a1, JSGeneratorObject::kContinuationOffset)); 2145 __ lw(a3, FieldMemOperand(a1, JSGeneratorObject::kContinuationOffset));
2145 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting <= 0); 2146 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0);
2146 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed <= 0); 2147 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0);
2147 __ Branch(&wrong_state, le, a3, Operand(zero_reg)); 2148 __ Branch(&closed_state, eq, a3, Operand(zero_reg));
2149 __ Branch(&wrong_state, lt, a3, Operand(zero_reg));
2148 2150
2149 // Load suspended function and context. 2151 // Load suspended function and context.
2150 __ lw(cp, FieldMemOperand(a1, JSGeneratorObject::kContextOffset)); 2152 __ lw(cp, FieldMemOperand(a1, JSGeneratorObject::kContextOffset));
2151 __ lw(t0, FieldMemOperand(a1, JSGeneratorObject::kFunctionOffset)); 2153 __ lw(t0, FieldMemOperand(a1, JSGeneratorObject::kFunctionOffset));
2152 2154
2153 // Load receiver and store as the first argument. 2155 // Load receiver and store as the first argument.
2154 __ lw(a2, FieldMemOperand(a1, JSGeneratorObject::kReceiverOffset)); 2156 __ lw(a2, FieldMemOperand(a1, JSGeneratorObject::kReceiverOffset));
2155 __ push(a2); 2157 __ push(a2);
2156 2158
2157 // Push holes for the rest of the arguments to the generator function. 2159 // Push holes for the rest of the arguments to the generator function.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2210 __ push(a2); 2212 __ push(a2);
2211 __ Branch(&push_operand_holes); 2213 __ Branch(&push_operand_holes);
2212 __ bind(&call_resume); 2214 __ bind(&call_resume);
2213 ASSERT(!result_register().is(a1)); 2215 ASSERT(!result_register().is(a1));
2214 __ Push(a1, result_register()); 2216 __ Push(a1, result_register());
2215 __ Push(Smi::FromInt(resume_mode)); 2217 __ Push(Smi::FromInt(resume_mode));
2216 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); 2218 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3);
2217 // Not reached: the runtime call returns elsewhere. 2219 // Not reached: the runtime call returns elsewhere.
2218 __ stop("not-reached"); 2220 __ stop("not-reached");
2219 2221
2222 // Reach here when generator is closed.
2223 __ bind(&closed_state);
2224 if (resume_mode == JSGeneratorObject::NEXT) {
2225 // Return completed iterator result when generator is closed.
2226 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2227 __ push(a2);
2228 // Pop value from top-of-stack slot; box result into result register.
2229 EmitCreateIteratorResult(true);
2230 } else {
2231 // Throw the provided value.
2232 __ push(a0);
2233 __ CallRuntime(Runtime::kThrow, 1);
2234 }
2235 __ jmp(&done);
2236
2220 // Throw error if we attempt to operate on a running generator. 2237 // Throw error if we attempt to operate on a running generator.
2221 __ bind(&wrong_state); 2238 __ bind(&wrong_state);
2222 __ push(a1); 2239 __ push(a1);
2223 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); 2240 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1);
2224 2241
2225 __ bind(&done); 2242 __ bind(&done);
2226 context()->Plug(result_register()); 2243 context()->Plug(result_register());
2227 } 2244 }
2228 2245
2229 2246
(...skipping 2720 matching lines...) Expand 10 before | Expand all | Expand 10 after
4950 Assembler::target_address_at(pc_immediate_load_address)) == 4967 Assembler::target_address_at(pc_immediate_load_address)) ==
4951 reinterpret_cast<uint32_t>( 4968 reinterpret_cast<uint32_t>(
4952 isolate->builtins()->OsrAfterStackCheck()->entry())); 4969 isolate->builtins()->OsrAfterStackCheck()->entry()));
4953 return OSR_AFTER_STACK_CHECK; 4970 return OSR_AFTER_STACK_CHECK;
4954 } 4971 }
4955 4972
4956 4973
4957 } } // namespace v8::internal 4974 } } // namespace v8::internal
4958 4975
4959 #endif // V8_TARGET_ARCH_MIPS 4976 #endif // V8_TARGET_ARCH_MIPS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698