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

Side by Side Diff: test/mjsunit/harmony/function-sent.js

Issue 1639343005: [generators] Implement Generator.prototype.return. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@yield-star
Patch Set: Another rebase Created 4 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 | « test/mjsunit/es6/generators-runtime.js ('k') | test/mjsunit/harmony/generators.js » ('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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 // Flags: --harmony-function-sent 5 // Flags: --harmony-function-sent
6 6
7 7
8 { 8 {
9 function* g() { return function.sent } 9 function* g() { return function.sent }
10 assertEquals({value: 42, done: true}, g().next(42)); 10 assertEquals({value: 42, done: true}, g().next(42));
11 } 11 }
12 12
13 13
14 { 14 {
15 function* g() { 15 function* g() {
16 try { 16 try {
17 yield function.sent; 17 yield function.sent;
18 } finally { 18 } finally {
19 yield function.sent; 19 yield function.sent;
20 return function.sent; 20 return function.sent;
21 } 21 }
22 } 22 }
23 23
24 { 24 {
25 x = g(); 25 let x = g();
26 assertEquals({value: 1, done: false}, x.next(1)); 26 assertEquals({value: 1, done: false}, x.next(1));
27 assertEquals({value: 2, done: false}, x.next(2)); 27 assertEquals({value: 2, done: false}, x.next(2));
28 assertEquals({value: 3, done: true}, x.next(3)); 28 assertEquals({value: 3, done: true}, x.next(3));
29 } 29 }
30 30
31 { 31 {
32 x = g(); 32 let x = g();
33 assertEquals({value: 1, done: false}, x.next(1)); 33 assertEquals({value: 1, done: false}, x.next(1));
34 assertEquals({value: 2, done: false}, x.throw(2)); 34 assertEquals({value: 2, done: false}, x.throw(2));
35 assertEquals({value: 3, done: true}, x.next(3)); 35 assertEquals({value: 3, done: true}, x.next(3));
36 } 36 }
37
38 {
39 let x = g();
40 assertEquals({value: 1, done: false}, x.next(1));
41 assertEquals({value: 2, done: false}, x.return(2));
42 assertEquals({value: 3, done: true}, x.next(3));
43 }
37 } 44 }
38 45
39 46
40 { 47 {
41 function* inner() { 48 function* inner() {
42 try { 49 try {
43 yield function.sent; 50 yield function.sent;
44 } finally { 51 } finally {
45 return 666; 52 return 666;
46 } 53 }
47 } 54 }
48 55
49 function* g() { 56 function* g() {
50 yield function.sent; 57 yield function.sent;
51 yield* inner(); 58 yield* inner();
52 return function.sent; 59 return function.sent;
53 } 60 }
54 61
55 { 62 {
56 x = g(); 63 let x = g();
57 assertEquals({value: 1, done: false}, x.next(1)); 64 assertEquals({value: 1, done: false}, x.next(1));
58 assertEquals({value: undefined, done: false}, x.next(2)); 65 assertEquals({value: undefined, done: false}, x.next(2));
59 assertEquals({value: 3, done: true}, x.next(3)); 66 assertEquals({value: 3, done: true}, x.next(3));
60 } 67 }
61 68
62 { 69 {
63 x = g(); 70 let x = g();
64 assertEquals({value: 1, done: false}, x.next(1)); 71 assertEquals({value: 1, done: false}, x.next(1));
65 assertEquals({value: undefined, done: false}, x.next(2)); 72 assertEquals({value: undefined, done: false}, x.next(2));
66 assertEquals({value: 42, done: true}, x.throw(42)); 73 assertEquals({value: 42, done: true}, x.throw(42));
67 } 74 }
75
76 {
77 let x = g();
78 assertEquals({value: 1, done: false}, x.next(1));
79 assertEquals({value: undefined, done: false}, x.next(2));
80 assertEquals({value: 42, done: true}, x.return(42));
81 }
68 } 82 }
69 83
70 84
71 assertThrows("function f() { return function.sent }", SyntaxError); 85 assertThrows("function f() { return function.sent }", SyntaxError);
72 assertThrows("() => { return function.sent }", SyntaxError); 86 assertThrows("() => { return function.sent }", SyntaxError);
73 assertThrows("() => { function.sent }", SyntaxError); 87 assertThrows("() => { function.sent }", SyntaxError);
74 assertThrows("() => function.sent", SyntaxError); 88 assertThrows("() => function.sent", SyntaxError);
75 assertThrows("({*f() { function.sent }})", SyntaxError); 89 assertThrows("({*f() { function.sent }})", SyntaxError);
76 assertDoesNotThrow("({*f() { return function.sent }})"); 90 assertDoesNotThrow("({*f() { return function.sent }})");
OLDNEW
« no previous file with comments | « test/mjsunit/es6/generators-runtime.js ('k') | test/mjsunit/harmony/generators.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698