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

Side by Side Diff: src/generator.js

Issue 717123002: Leaving a generator via an exception causes it to close (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove state checking from full-codegen and associated runtime functions Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/ia32/full-codegen-ia32.cc » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declarations have been made 7 // This file relies on the fact that the following declarations have been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Function = global.Function; 9 // var $Function = global.Function;
10 10
11 // ---------------------------------------------------------------------------- 11 // ----------------------------------------------------------------------------
12 12
13 13
14 // Generator functions and objects are specified by ES6, sections 15.19.3 and 14 // Generator functions and objects are specified by ES6, sections 15.19.3 and
15 // 15.19.4. 15 // 15.19.4.
16 16
17 function GeneratorObjectNext(value) { 17 function GeneratorObjectNext(value) {
18 if (!IS_GENERATOR(this)) { 18 if (!IS_GENERATOR(this)) {
19 throw MakeTypeError('incompatible_method_receiver', 19 throw MakeTypeError('incompatible_method_receiver',
20 ['[Generator].prototype.next', this]); 20 ['[Generator].prototype.next', this]);
21 } 21 }
22 22
23 if (DEBUG_IS_ACTIVE) %DebugPrepareStepInIfStepping(this); 23 var continuation = %GeneratorGetContinuation(this);
24 return %_GeneratorNext(this, value); 24 if (continuation > 0) {
25 // Generator is suspended.
26 if (DEBUG_IS_ACTIVE) %DebugPrepareStepInIfStepping(this);
27 try {
28 return %_GeneratorNext(this, value);
29 } catch (e) {
30 %GeneratorClose(this);
31 throw e;
32 }
33 } else if (continuation == 0) {
34 // Generator is already closed.
35 return { value: void 0, done: true };
36 } else {
37 // Generator is running.
38 throw MakeTypeError('generator_running', []);
39 }
25 } 40 }
26 41
27 function GeneratorObjectThrow(exn) { 42 function GeneratorObjectThrow(exn) {
28 if (!IS_GENERATOR(this)) { 43 if (!IS_GENERATOR(this)) {
29 throw MakeTypeError('incompatible_method_receiver', 44 throw MakeTypeError('incompatible_method_receiver',
30 ['[Generator].prototype.throw', this]); 45 ['[Generator].prototype.throw', this]);
31 } 46 }
32 47
33 return %_GeneratorThrow(this, exn); 48 var continuation = %GeneratorGetContinuation(this);
49 if (continuation > 0) {
50 // Generator is suspended.
51 try {
52 return %_GeneratorThrow(this, exn);
53 } catch (e) {
54 %GeneratorClose(this);
55 throw e;
56 }
57 } else if (continuation == 0) {
58 // Generator is already closed.
59 throw exn;
60 } else {
61 // Generator is running.
62 throw MakeTypeError('generator_running', []);
63 }
34 } 64 }
35 65
36 function GeneratorObjectIterator() { 66 function GeneratorObjectIterator() {
37 return this; 67 return this;
38 } 68 }
39 69
40 function GeneratorFunctionPrototypeConstructor(x) { 70 function GeneratorFunctionPrototypeConstructor(x) {
41 if (%_IsConstructCall()) { 71 if (%_IsConstructCall()) {
42 throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']); 72 throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']);
43 } 73 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY); 108 symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY);
79 %InternalSetPrototype(GeneratorFunctionPrototype, $Function.prototype); 109 %InternalSetPrototype(GeneratorFunctionPrototype, $Function.prototype);
80 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor); 110 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor);
81 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", 111 %AddNamedProperty(GeneratorFunctionPrototype, "constructor",
82 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); 112 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY);
83 %InternalSetPrototype(GeneratorFunction, $Function); 113 %InternalSetPrototype(GeneratorFunction, $Function);
84 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); 114 %SetCode(GeneratorFunction, GeneratorFunctionConstructor);
85 } 115 }
86 116
87 SetUpGenerators(); 117 SetUpGenerators();
OLDNEW
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698