OLD | NEW |
(Empty) | |
| 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 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 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 |
| 40 { |
| 41 function* inner() { |
| 42 try { |
| 43 yield function.sent; |
| 44 } finally { |
| 45 return 666; |
| 46 } |
| 47 } |
| 48 |
| 49 function* g() { |
| 50 yield function.sent; |
| 51 yield* inner(); |
| 52 return function.sent; |
| 53 } |
| 54 |
| 55 { |
| 56 x = g(); |
| 57 assertEquals({value: 1, done: false}, x.next(1)); |
| 58 assertEquals({value: undefined, done: false}, x.next(2)); |
| 59 assertEquals({value: 3, done: true}, x.next(3)); |
| 60 } |
| 61 |
| 62 { |
| 63 x = g(); |
| 64 assertEquals({value: 1, done: false}, x.next(1)); |
| 65 assertEquals({value: undefined, done: false}, x.next(2)); |
| 66 assertEquals({value: 42, done: true}, x.throw(42)); |
| 67 } |
| 68 } |
| 69 |
| 70 |
| 71 assertThrows("function f() { return function.sent }", SyntaxError); |
| 72 assertThrows("() => { return function.sent }", SyntaxError); |
| 73 assertThrows("() => { function.sent }", SyntaxError); |
| 74 assertThrows("() => function.sent", SyntaxError); |
| 75 assertThrows("({*f() { function.sent }})", SyntaxError); |
| 76 assertDoesNotThrow("({*f() { return function.sent }})"); |
OLD | NEW |