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

Side by Side Diff: test/mjsunit/es6/generators-states.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 | « test/mjsunit/es6/generators-iteration.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Test generator states.
6
7 function Foo() {}
8 function Bar() {}
9
10 function assertIteratorResult(value, done, result) {
11 assertEquals({ value: value, done: done}, result);
12 }
13
14 function assertIteratorIsClosed(iter) {
15 assertIteratorResult(undefined, true, iter.next());
16 // Next and throw on a closed iterator.
17 assertDoesNotThrow(function() { iter.next(); });
18 assertThrows(function() { iter.throw(new Bar); }, Bar);
19 }
20
21 var iter;
22 function* nextGenerator() { yield iter.next(); }
23 function* throwGenerator() { yield iter.throw(new Bar); }
24
25 // Throw on a suspendedStart iterator.
26 iter = nextGenerator();
27 assertThrows(function() { iter.throw(new Foo) }, Foo)
28 assertThrows(function() { iter.throw(new Foo) }, Foo)
29 assertIteratorIsClosed(iter);
30
31 // The same.
32 iter = throwGenerator();
33 assertThrows(function() { iter.throw(new Foo) }, Foo)
34 assertThrows(function() { iter.throw(new Foo) }, Foo)
35 assertIteratorIsClosed(iter);
36
37 // Next on an executing iterator raises a TypeError.
38 iter = nextGenerator();
39 assertThrows(function() { iter.next() }, TypeError)
40 assertIteratorIsClosed(iter);
41
42 // Throw on an executing iterator raises a TypeError.
43 iter = throwGenerator();
44 assertThrows(function() { iter.next() }, TypeError)
45 assertIteratorIsClosed(iter);
46
47 // Next on an executing iterator doesn't change the state of the
48 // generator.
49 iter = (function* () {
50 try {
51 iter.next();
52 yield 1;
53 } catch (e) {
54 try {
55 // This next() should raise the same exception, because the first
56 // next() left the iter in the executing state.
57 iter.next();
58 yield 2;
59 } catch (e) {
60 yield 3;
61 }
62 }
63 yield 4;
64 })();
65 assertIteratorResult(3, false, iter.next());
66 assertIteratorResult(4, false, iter.next());
67 assertIteratorIsClosed(iter);
OLDNEW
« no previous file with comments | « test/mjsunit/es6/generators-iteration.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698