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

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

Issue 139653003: Throw a TypeError when calling "next" method of a newly created generator with a value (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: 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
« no previous file with comments | « no previous file | src/ia32/full-codegen-ia32.cc » ('j') | src/ia32/full-codegen-ia32.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1982 matching lines...) Expand 10 before | Expand all | Expand 10 after
1993 __ jmp(&suspend); 1993 __ jmp(&suspend);
1994 1994
1995 __ bind(&continuation); 1995 __ bind(&continuation);
1996 __ jmp(&resume); 1996 __ jmp(&resume);
1997 1997
1998 __ bind(&suspend); 1998 __ bind(&suspend);
1999 VisitForAccumulatorValue(expr->generator_object()); 1999 VisitForAccumulatorValue(expr->generator_object());
2000 ASSERT(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); 2000 ASSERT(continuation.pos() > 0 && Smi::IsValid(continuation.pos()));
2001 __ mov(r1, Operand(Smi::FromInt(continuation.pos()))); 2001 __ mov(r1, Operand(Smi::FromInt(continuation.pos())));
2002 __ str(r1, FieldMemOperand(r0, JSGeneratorObject::kContinuationOffset)); 2002 __ str(r1, FieldMemOperand(r0, JSGeneratorObject::kContinuationOffset));
2003 if (expr->yield_kind() == Yield::INITIAL) {
2004 __ str(r1,
2005 FieldMemOperand(r0, JSGeneratorObject::kSuspendedStartOffset));
2006 }
2003 __ str(cp, FieldMemOperand(r0, JSGeneratorObject::kContextOffset)); 2007 __ str(cp, FieldMemOperand(r0, JSGeneratorObject::kContextOffset));
2004 __ mov(r1, cp); 2008 __ mov(r1, cp);
2005 __ RecordWriteField(r0, JSGeneratorObject::kContextOffset, r1, r2, 2009 __ RecordWriteField(r0, JSGeneratorObject::kContextOffset, r1, r2,
2006 kLRHasBeenSaved, kDontSaveFPRegs); 2010 kLRHasBeenSaved, kDontSaveFPRegs);
2007 __ add(r1, fp, Operand(StandardFrameConstants::kExpressionsOffset)); 2011 __ add(r1, fp, Operand(StandardFrameConstants::kExpressionsOffset));
2008 __ cmp(sp, r1); 2012 __ cmp(sp, r1);
2009 __ b(eq, &post_runtime); 2013 __ b(eq, &post_runtime);
2010 __ push(r0); // generator object 2014 __ push(r0); // generator object
2011 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); 2015 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
2012 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); 2016 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 JSGeneratorObject::ResumeMode resume_mode) { 2123 JSGeneratorObject::ResumeMode resume_mode) {
2120 // The value stays in r0, and is ultimately read by the resumed generator, as 2124 // The value stays in r0, and is ultimately read by the resumed generator, as
2121 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it 2125 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it
2122 // is read to throw the value when the resumed generator is already closed. 2126 // is read to throw the value when the resumed generator is already closed.
2123 // r1 will hold the generator object until the activation has been resumed. 2127 // r1 will hold the generator object until the activation has been resumed.
2124 VisitForStackValue(generator); 2128 VisitForStackValue(generator);
2125 VisitForAccumulatorValue(value); 2129 VisitForAccumulatorValue(value);
2126 __ pop(r1); 2130 __ pop(r1);
2127 2131
2128 // Check generator state. 2132 // Check generator state.
2129 Label wrong_state, closed_state, done; 2133 Label wrong_state, closed_state, suspended_start_state, resume_state, done;
2130 __ ldr(r3, FieldMemOperand(r1, JSGeneratorObject::kContinuationOffset)); 2134 __ ldr(r3, FieldMemOperand(r1, JSGeneratorObject::kContinuationOffset));
2131 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0); 2135 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0);
2132 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0); 2136 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0);
2133 __ cmp(r3, Operand(Smi::FromInt(0))); 2137 __ cmp(r3, Operand(Smi::FromInt(0)));
2134 __ b(eq, &closed_state); 2138 __ b(eq, &closed_state);
2135 __ b(lt, &wrong_state); 2139 __ b(lt, &wrong_state);
2140 __ ldr(r2, FieldMemOperand(r1, JSGeneratorObject::kSuspendedStartOffset));
2141 __ cmp(r3, r2);
2142 __ b(eq, &suspended_start_state);
2143
2144 __ bind(&resume_state);
2136 2145
2137 // Load suspended function and context. 2146 // Load suspended function and context.
2138 __ ldr(cp, FieldMemOperand(r1, JSGeneratorObject::kContextOffset)); 2147 __ ldr(cp, FieldMemOperand(r1, JSGeneratorObject::kContextOffset));
2139 __ ldr(r4, FieldMemOperand(r1, JSGeneratorObject::kFunctionOffset)); 2148 __ ldr(r4, FieldMemOperand(r1, JSGeneratorObject::kFunctionOffset));
2140 2149
2141 // Load receiver and store as the first argument. 2150 // Load receiver and store as the first argument.
2142 __ ldr(r2, FieldMemOperand(r1, JSGeneratorObject::kReceiverOffset)); 2151 __ ldr(r2, FieldMemOperand(r1, JSGeneratorObject::kReceiverOffset));
2143 __ push(r2); 2152 __ push(r2);
2144 2153
2145 // Push holes for the rest of the arguments to the generator function. 2154 // Push holes for the rest of the arguments to the generator function.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 __ push(r2); 2209 __ push(r2);
2201 __ b(&push_operand_holes); 2210 __ b(&push_operand_holes);
2202 __ bind(&call_resume); 2211 __ bind(&call_resume);
2203 ASSERT(!result_register().is(r1)); 2212 ASSERT(!result_register().is(r1));
2204 __ Push(r1, result_register()); 2213 __ Push(r1, result_register());
2205 __ Push(Smi::FromInt(resume_mode)); 2214 __ Push(Smi::FromInt(resume_mode));
2206 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); 2215 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3);
2207 // Not reached: the runtime call returns elsewhere. 2216 // Not reached: the runtime call returns elsewhere.
2208 __ stop("not-reached"); 2217 __ stop("not-reached");
2209 2218
2219 // Throw the provided value.
2220 Label throw_provided_value;
2221 __ bind(&throw_provided_value);
2222 if (resume_mode != JSGeneratorObject::NEXT) {
2223 __ push(r0);
2224 __ CallRuntime(Runtime::kThrow, 1);
2225 __ jmp(&done);
2226 }
2227
2228 // Reach here when calling initial resume to a generator.
2229 __ bind(&suspended_start_state);
2230 if (resume_mode == JSGeneratorObject::NEXT) {
2231 // When value is provided and it is not undefined, throw error.
2232 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
2233 __ b(eq, &resume_state);
2234 __ CallRuntime(Runtime::kThrowGeneratorStartError, 1);
2235 __ jmp(&done);
2236 } else {
2237 // Make generator's state to "closed".
2238 __ mov(r2, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorClosed)));
2239 __ str(r2, FieldMemOperand(r1, JSGeneratorObject::kContinuationOffset));
2240 __ jmp(&throw_provided_value);
2241 }
2242
2210 // Reach here when generator is closed. 2243 // Reach here when generator is closed.
2211 __ bind(&closed_state); 2244 __ bind(&closed_state);
2212 if (resume_mode == JSGeneratorObject::NEXT) { 2245 if (resume_mode == JSGeneratorObject::NEXT) {
2213 // Return completed iterator result when generator is closed. 2246 // Return completed iterator result when generator is closed.
2214 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); 2247 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
2215 __ push(r2); 2248 __ push(r2);
2216 // Pop value from top-of-stack slot; box result into result register. 2249 // Pop value from top-of-stack slot; box result into result register.
2217 EmitCreateIteratorResult(true); 2250 EmitCreateIteratorResult(true);
2251 __ jmp(&done);
2218 } else { 2252 } else {
2219 // Throw the provided value. 2253 __ jmp(&throw_provided_value);
2220 __ push(r0);
2221 __ CallRuntime(Runtime::kThrow, 1);
2222 } 2254 }
2223 __ jmp(&done);
2224 2255
2225 // Throw error if we attempt to operate on a running generator. 2256 // Throw error if we attempt to operate on a running generator.
2226 __ bind(&wrong_state); 2257 __ bind(&wrong_state);
2227 __ push(r1); 2258 __ push(r1);
2228 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); 2259 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1);
2229 2260
2230 __ bind(&done); 2261 __ bind(&done);
2231 context()->Plug(result_register()); 2262 context()->Plug(result_register());
2232 } 2263 }
2233 2264
(...skipping 2675 matching lines...) Expand 10 before | Expand all | Expand 10 after
4909 ASSERT(Memory::uint32_at(interrupt_address_pointer) == 4940 ASSERT(Memory::uint32_at(interrupt_address_pointer) ==
4910 reinterpret_cast<uint32_t>( 4941 reinterpret_cast<uint32_t>(
4911 isolate->builtins()->OsrAfterStackCheck()->entry())); 4942 isolate->builtins()->OsrAfterStackCheck()->entry()));
4912 return OSR_AFTER_STACK_CHECK; 4943 return OSR_AFTER_STACK_CHECK;
4913 } 4944 }
4914 4945
4915 4946
4916 } } // namespace v8::internal 4947 } } // namespace v8::internal
4917 4948
4918 #endif // V8_TARGET_ARCH_ARM 4949 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « no previous file | src/ia32/full-codegen-ia32.cc » ('j') | src/ia32/full-codegen-ia32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698