blob: cd0ca957a8cf1719c4980ca45c8234804bec6767 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001// 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
3// found in the LICENSE file.
4
5// Flags: --harmony-function-sent
6
7
8{
9 function* g() { return function.sent }
10 assertEquals({value: 42, done: true}, g().next(42));
11}
12
13
14{
15 function* g() {
16 try {
17 yield function.sent;
18 } finally {
19 yield function.sent;
20 return function.sent;
21 }
22 }
23
24 {
25 let x = g();
26 assertEquals({value: 1, done: false}, x.next(1));
27 assertEquals({value: 2, done: false}, x.next(2));
28 assertEquals({value: 3, done: true}, x.next(3));
29 }
30
31 {
32 let x = g();
33 assertEquals({value: 1, done: false}, x.next(1));
34 assertEquals({value: 2, done: false}, x.throw(2));
35 assertEquals({value: 3, done: true}, x.next(3));
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 }
44}
45
46
47{
48 function* inner() {
49 try {
50 yield function.sent;
51 } finally {
Ben Murdochc5610432016-08-08 18:44:38 +010052 return 23;
Ben Murdoch097c5b22016-05-18 11:27:45 +010053 }
54 }
55
56 function* g() {
57 yield function.sent;
58 yield* inner();
59 return function.sent;
60 }
61
62 {
63 let x = g();
64 assertEquals({value: 1, done: false}, x.next(1));
65 assertEquals({value: undefined, done: false}, x.next(2));
66 assertEquals({value: 3, done: true}, x.next(3));
67 }
68
69 {
70 let x = g();
71 assertEquals({value: 1, done: false}, x.next(1));
72 assertEquals({value: undefined, done: false}, x.next(2));
73 assertEquals({value: 42, done: true}, x.throw(42));
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));
Ben Murdochc5610432016-08-08 18:44:38 +010080 assertEquals({value: 23, done: true}, x.return(42));
Ben Murdoch097c5b22016-05-18 11:27:45 +010081 }
82}
83
84
85assertThrows("function f() { return function.sent }", SyntaxError);
86assertThrows("() => { return function.sent }", SyntaxError);
87assertThrows("() => { function.sent }", SyntaxError);
88assertThrows("() => function.sent", SyntaxError);
89assertThrows("({*f() { function.sent }})", SyntaxError);
90assertDoesNotThrow("({*f() { return function.sent }})");