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

Side by Side Diff: src/mips/full-codegen-mips.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: Revised Created 6 years, 10 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 | « src/messages.js ('k') | src/runtime.h » ('j') | no next file with comments »
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 2017 matching lines...) Expand 10 before | Expand all | Expand 10 after
2028 __ Addu(a1, fp, Operand(StandardFrameConstants::kExpressionsOffset)); 2028 __ Addu(a1, fp, Operand(StandardFrameConstants::kExpressionsOffset));
2029 __ Branch(&post_runtime, eq, sp, Operand(a1)); 2029 __ Branch(&post_runtime, eq, sp, Operand(a1));
2030 __ push(v0); // generator object 2030 __ push(v0); // generator object
2031 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); 2031 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
2032 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); 2032 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2033 __ bind(&post_runtime); 2033 __ bind(&post_runtime);
2034 __ pop(result_register()); 2034 __ pop(result_register());
2035 EmitReturnSequence(); 2035 EmitReturnSequence();
2036 2036
2037 __ bind(&resume); 2037 __ bind(&resume);
2038 Label init_value_check_done;
2039 if (expr->yield_kind() == Yield::INITIAL) {
2040 // When value is provided and it is not undefined, throw error.
2041 __ LoadRoot(a1, Heap::kUndefinedValueRootIndex);
2042 __ Branch(&init_value_check_done, eq, result_register(), Operand(a1));
2043 // This error should be raised from the Generator.prototype.next side.
2044 // So in this case, we return the hole value as a marker. The caller
2045 // checks the result value and if it is the hole value, the caller
2046 // throws error.
2047 __ Push(isolate()->factory()->the_hole_value());
2048 __ jmp(&suspend);
2049 }
2050 __ bind(&init_value_check_done);
2038 context()->Plug(result_register()); 2051 context()->Plug(result_register());
2039 break; 2052 break;
2040 } 2053 }
2041 2054
2042 case Yield::FINAL: { 2055 case Yield::FINAL: {
2043 VisitForAccumulatorValue(expr->generator_object()); 2056 VisitForAccumulatorValue(expr->generator_object());
2044 __ li(a1, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); 2057 __ li(a1, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorClosed)));
2045 __ sw(a1, FieldMemOperand(result_register(), 2058 __ sw(a1, FieldMemOperand(result_register(),
2046 JSGeneratorObject::kContinuationOffset)); 2059 JSGeneratorObject::kContinuationOffset));
2047 // Pop value from top-of-stack slot, box result into result register. 2060 // Pop value from top-of-stack slot, box result into result register.
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 __ push(a0); 2263 __ push(a0);
2251 __ CallRuntime(Runtime::kThrow, 1); 2264 __ CallRuntime(Runtime::kThrow, 1);
2252 } 2265 }
2253 __ jmp(&done); 2266 __ jmp(&done);
2254 2267
2255 // Throw error if we attempt to operate on a running generator. 2268 // Throw error if we attempt to operate on a running generator.
2256 __ bind(&wrong_state); 2269 __ bind(&wrong_state);
2257 __ push(a1); 2270 __ push(a1);
2258 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); 2271 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1);
2259 2272
2273 // Throw error if we attempt to pass a value to an unborn generator.
2274 Label wrong_start;
2275 __ bind(&wrong_start);
2276 __ CallRuntime(Runtime::kThrowGeneratorStartError, 0);
2277
2260 __ bind(&done); 2278 __ bind(&done);
2279 // When a value is passed to an unborn generator, the result becomes the hole
2280 // value. And we need to throw GeneratorStartError in the caller side.
2281 // (Generator.prototype.next)
2282 __ LoadRoot(a2, Heap::kTheHoleValueRootIndex);
2283 __ Branch(&wrong_start, eq, result_register(), Operand(a2));
2261 context()->Plug(result_register()); 2284 context()->Plug(result_register());
2262 } 2285 }
2263 2286
2264 2287
2265 void FullCodeGenerator::EmitCreateIteratorResult(bool done) { 2288 void FullCodeGenerator::EmitCreateIteratorResult(bool done) {
2266 Label gc_required; 2289 Label gc_required;
2267 Label allocated; 2290 Label allocated;
2268 2291
2269 Handle<Map> map(isolate()->native_context()->generator_result_map()); 2292 Handle<Map> map(isolate()->native_context()->generator_result_map());
2270 2293
(...skipping 2703 matching lines...) Expand 10 before | Expand all | Expand 10 after
4974 Assembler::target_address_at(pc_immediate_load_address)) == 4997 Assembler::target_address_at(pc_immediate_load_address)) ==
4975 reinterpret_cast<uint32_t>( 4998 reinterpret_cast<uint32_t>(
4976 isolate->builtins()->OsrAfterStackCheck()->entry())); 4999 isolate->builtins()->OsrAfterStackCheck()->entry()));
4977 return OSR_AFTER_STACK_CHECK; 5000 return OSR_AFTER_STACK_CHECK;
4978 } 5001 }
4979 5002
4980 5003
4981 } } // namespace v8::internal 5004 } } // namespace v8::internal
4982 5005
4983 #endif // V8_TARGET_ARCH_MIPS 5006 #endif // V8_TARGET_ARCH_MIPS
OLDNEW
« no previous file with comments | « src/messages.js ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698