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 |
| 6 { // yield in try-catch |
| 7 |
| 8 let g = function*() { |
| 9 try {yield 1} catch (error) {assertEquals("caught", error)} |
| 10 }; |
| 11 |
| 12 assertThrowsEquals(() => g().throw("not caught"), "not caught"); |
| 13 |
| 14 { |
| 15 let x = g(); |
| 16 assertEquals({value: 1, done: false}, x.next()); |
| 17 assertEquals({value: undefined, done: true}, x.throw("caught")); |
| 18 } |
| 19 |
| 20 { |
| 21 let x = g(); |
| 22 assertEquals({value: 1, done: false}, x.next()); |
| 23 assertEquals({value: undefined, done: true}, x.next()); |
| 24 assertThrowsEquals(() => x.throw("not caught"), "not caught"); |
| 25 } |
| 26 } |
| 27 |
| 28 |
| 29 { // return that doesn't close |
| 30 let g = function*() { try {return 42} finally {yield 43} }; |
| 31 |
| 32 { |
| 33 let x = g(); |
| 34 assertEquals({value: 43, done: false}, x.next()); |
| 35 assertEquals({value: 42, done: true}, x.next()); |
| 36 } |
| 37 } |
| 38 |
| 39 |
| 40 { // return that doesn't close |
| 41 let x; |
| 42 let g = function*() { try {return 42} finally {x.throw(666)} }; |
| 43 |
| 44 { |
| 45 x = g(); |
| 46 assertThrows(() => x.next(), TypeError); // still executing |
| 47 } |
| 48 } |
| 49 |
| 50 |
| 51 { // yield in try-finally, finally clause performs return |
| 52 |
| 53 let g = function*() { try {yield 42} finally {return 13} }; |
| 54 |
| 55 { // "return" closes at suspendedStart |
| 56 let x = g(); |
| 57 assertEquals({value: 666, done: true}, x.return(666)); |
| 58 assertEquals({value: undefined, done: true}, x.next(42)); |
| 59 assertThrowsEquals(() => x.throw(43), 43); |
| 60 assertEquals({value: 42, done: true}, x.return(42)); |
| 61 } |
| 62 |
| 63 { // "throw" closes at suspendedStart |
| 64 let x = g(); |
| 65 assertThrowsEquals(() => x.throw(666), 666); |
| 66 assertEquals({value: undefined, done: true}, x.next(42)); |
| 67 assertEquals({value: 43, done: true}, x.return(43)); |
| 68 assertThrowsEquals(() => x.throw(44), 44); |
| 69 } |
| 70 |
| 71 { // "next" closes at suspendedYield |
| 72 let x = g(); |
| 73 assertEquals({value: 42, done: false}, x.next()); |
| 74 assertEquals({value: 13, done: true}, x.next(666)); |
| 75 assertEquals({value: undefined, done: true}, x.next(666)); |
| 76 assertThrowsEquals(() => x.throw(666), 666); |
| 77 } |
| 78 |
| 79 { // "return" closes at suspendedYield |
| 80 let x = g(); |
| 81 assertEquals({value: 42, done: false}, x.next()); |
| 82 assertEquals({value: 13, done: true}, x.return(666)); |
| 83 assertEquals({value: undefined, done: true}, x.next(666)); |
| 84 assertEquals({value: 666, done: true}, x.return(666)); |
| 85 } |
| 86 |
| 87 { // "throw" closes at suspendedYield |
| 88 let x = g(); |
| 89 assertEquals({value: 42, done: false}, x.next()); |
| 90 assertEquals({value: 13, done: true}, x.throw(666)); |
| 91 assertThrowsEquals(() => x.throw(666), 666); |
| 92 assertEquals({value: undefined, done: true}, x.next(666)); |
| 93 } |
| 94 } |
| 95 |
| 96 |
| 97 { // yield in try-finally, finally clause doesn't perform return |
| 98 |
| 99 let g = function*() { try {yield 42} finally {13} }; |
| 100 |
| 101 { // "return" closes at suspendedStart |
| 102 let x = g(); |
| 103 assertEquals({value: 666, done: true}, x.return(666)); |
| 104 assertEquals({value: undefined, done: true}, x.next(42)); |
| 105 assertThrowsEquals(() => x.throw(43), 43); |
| 106 assertEquals({value: 42, done: true}, x.return(42)); |
| 107 } |
| 108 |
| 109 { // "throw" closes at suspendedStart |
| 110 let x = g(); |
| 111 assertThrowsEquals(() => x.throw(666), 666); |
| 112 assertEquals({value: undefined, done: true}, x.next(42)); |
| 113 assertEquals({value: 43, done: true}, x.return(43)); |
| 114 assertThrowsEquals(() => x.throw(44), 44); |
| 115 } |
| 116 |
| 117 { // "next" closes at suspendedYield |
| 118 let x = g(); |
| 119 assertEquals({value: 42, done: false}, x.next()); |
| 120 assertEquals({value: undefined, done: true}, x.next(666)); |
| 121 assertEquals({value: undefined, done: true}, x.next(666)); |
| 122 assertThrowsEquals(() => x.throw(666), 666); |
| 123 assertEquals({value: 42, done: true}, x.return(42)); |
| 124 } |
| 125 |
| 126 { // "return" closes at suspendedYield |
| 127 let x = g(); |
| 128 assertEquals({value: 42, done: false}, x.next()); |
| 129 assertEquals({value: 666, done: true}, x.return(666)); |
| 130 assertEquals({value: undefined, done: true}, x.next(666)); |
| 131 assertThrowsEquals(() => x.throw(44), 44); |
| 132 assertEquals({value: 42, done: true}, x.return(42)); |
| 133 } |
| 134 |
| 135 { // "throw" closes at suspendedYield |
| 136 let x = g(); |
| 137 assertEquals({value: 42, done: false}, x.next()); |
| 138 assertThrowsEquals(() => x.throw(666), 666); |
| 139 assertEquals({value: undefined, done: true}, x.next(666)); |
| 140 assertThrowsEquals(() => x.throw(666), 666); |
| 141 assertEquals({value: 42, done: true}, x.return(42)); |
| 142 } |
| 143 } |
| 144 |
| 145 |
| 146 { // yield in try-finally, finally clause yields and performs return |
| 147 |
| 148 let g = function*() { try {yield 42} finally {yield 43; return 13} }; |
| 149 |
| 150 { |
| 151 let x = g(); |
| 152 assertEquals({value: 42, done: false}, x.next()); |
| 153 assertEquals({value: 43, done: false}, x.return(666)); |
| 154 assertEquals({value: 13, done: true}, x.next()); |
| 155 assertEquals({value: 666, done: true}, x.return(666)); |
| 156 } |
| 157 |
| 158 { |
| 159 let x = g(); |
| 160 assertEquals({value: 666, done: true}, x.return(666)); |
| 161 assertEquals({value: undefined, done: true}, x.next()); |
| 162 assertEquals({value: 666, done: true}, x.return(666)); |
| 163 } |
| 164 } |
| 165 |
| 166 |
| 167 { // yield in try-finally, finally clause yields and doesn't perform return |
| 168 |
| 169 let g = function*() { try {yield 42} finally {yield 43; 13} }; |
| 170 |
| 171 { |
| 172 let x = g(); |
| 173 assertEquals({value: 42, done: false}, x.next()); |
| 174 assertEquals({value: 43, done: false}, x.return(666)); |
| 175 assertEquals({value: 666, done: true}, x.next()); |
| 176 assertEquals({value: 5, done: true}, x.return(5)); |
| 177 } |
| 178 |
| 179 { |
| 180 let x = g(); |
| 181 assertEquals({value: 666, done: true}, x.return(666)); |
| 182 assertEquals({value: undefined, done: true}, x.next()); |
| 183 assertEquals({value: 666, done: true}, x.return(666)); |
| 184 } |
| 185 } |
| 186 |
| 187 |
| 188 { // yield*, finally clause performs return |
| 189 |
| 190 let h = function*() { try {yield 42} finally {yield 43; return 13} }; |
| 191 let g = function*() { yield 1; yield yield* h(); }; |
| 192 |
| 193 { |
| 194 let x = g(); |
| 195 assertEquals({value: 1, done: false}, x.next()); |
| 196 assertEquals({value: 42, done: false}, x.next()); |
| 197 assertEquals({value: 43, done: false}, x.next(666)); |
| 198 assertEquals({value: 13, done: false}, x.next()); |
| 199 assertEquals({value: undefined, done: true}, x.next()); |
| 200 } |
| 201 |
| 202 { |
| 203 let x = g(); |
| 204 assertEquals({value: 1, done: false}, x.next()); |
| 205 assertEquals({value: 42, done: false}, x.next()); |
| 206 assertEquals({value: 43, done: false}, x.return(666)); |
| 207 assertEquals({value: 13, done: false}, x.next()); |
| 208 assertEquals({value: undefined, done: true}, x.next()); |
| 209 } |
| 210 |
| 211 { |
| 212 let x = g(); |
| 213 assertEquals({value: 1, done: false}, x.next()); |
| 214 assertEquals({value: 42, done: false}, x.next()); |
| 215 assertEquals({value: 43, done: false}, x.throw(666)); |
| 216 assertEquals({value: 13, done: false}, x.next()); |
| 217 assertEquals({value: undefined, done: true}, x.next()); |
| 218 } |
| 219 } |
| 220 |
| 221 |
| 222 { // yield*, finally clause does not perform return |
| 223 |
| 224 let h = function*() { try {yield 42} finally {yield 43; 13} }; |
| 225 let g = function*() { yield 1; yield yield* h(); }; |
| 226 |
| 227 { |
| 228 let x = g(); |
| 229 assertEquals({value: 1, done: false}, x.next()); |
| 230 assertEquals({value: 42, done: false}, x.next()); |
| 231 assertEquals({value: 43, done: false}, x.next(666)); |
| 232 assertEquals({value: undefined, done: false}, x.next()); |
| 233 assertEquals({value: undefined, done: true}, x.next()); |
| 234 } |
| 235 |
| 236 { |
| 237 let x = g(); |
| 238 assertEquals({value: 1, done: false}, x.next()); |
| 239 assertEquals({value: 42, done: false}, x.next()); |
| 240 assertEquals({value: 43, done: false}, x.return(666)); |
| 241 assertEquals({value: 666, done: false}, x.next()); |
| 242 assertEquals({value: undefined, done: true}, x.next()); |
| 243 } |
| 244 |
| 245 { |
| 246 let x = g(); |
| 247 assertEquals({value: 1, done: false}, x.next()); |
| 248 assertEquals({value: 42, done: false}, x.next()); |
| 249 assertEquals({value: 43, done: false}, x.throw(666)); |
| 250 assertThrowsEquals(() => x.next(), 666); |
| 251 } |
| 252 } |
OLD | NEW |