Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 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 |
| 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 Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 52 | return 23; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 53 | } |
| 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 Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 80 | assertEquals({value: 23, done: true}, x.return(42)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
| 84 | |
| 85 | assertThrows("function f() { return function.sent }", SyntaxError); |
| 86 | assertThrows("() => { return function.sent }", SyntaxError); |
| 87 | assertThrows("() => { function.sent }", SyntaxError); |
| 88 | assertThrows("() => function.sent", SyntaxError); |
| 89 | assertThrows("({*f() { function.sent }})", SyntaxError); |
| 90 | assertDoesNotThrow("({*f() { return function.sent }})"); |