| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 "foo", | 204 "foo", |
| 205 ["fee", "fi", "fo", "fum", undefined]); | 205 ["fee", "fi", "fo", "fum", undefined]); |
| 206 | 206 |
| 207 // GC. | 207 // GC. |
| 208 TestGenerator(function* g16() { yield "baz"; gc(); yield "qux"; }, | 208 TestGenerator(function* g16() { yield "baz"; gc(); yield "qux"; }, |
| 209 ["baz", "qux", undefined], | 209 ["baz", "qux", undefined], |
| 210 "foo", | 210 "foo", |
| 211 ["baz", "qux", undefined]); | 211 ["baz", "qux", undefined]); |
| 212 | 212 |
| 213 // Receivers. | 213 // Receivers. |
| 214 function TestReceivers() { | 214 TestGenerator( |
| 215 TestGenerator( | 215 function g17() { |
| 216 function g17() { | 216 function* g() { yield this.x; yield this.y; } |
| 217 function* g() { yield this.x; yield this.y; } | 217 var o = { start: g, x: 1, y: 2 }; |
| 218 var o = { start: g, x: 1, y: 2 }; | 218 return o.start(); |
| 219 return o.start(); | 219 }, |
| 220 }, | 220 [1, 2, undefined], |
| 221 [1, 2, undefined], | 221 "foo", |
| 222 "foo", | 222 [1, 2, undefined]); |
| 223 [1, 2, undefined]); | |
| 224 | 223 |
| 225 TestGenerator( | 224 TestGenerator( |
| 226 function g18() { | 225 function g18() { |
| 227 function* g() { yield this.x; yield this.y; } | 226 function* g() { yield this.x; yield this.y; } |
| 228 var iter = new g; | 227 var iter = new g; |
| 229 iter.x = 1; | 228 iter.x = 1; |
| 230 iter.y = 2; | 229 iter.y = 2; |
| 231 return iter; | 230 return iter; |
| 232 }, | 231 }, |
| 233 [1, 2, undefined], | 232 [1, 2, undefined], |
| 234 "foo", | 233 "foo", |
| 235 [1, 2, undefined]); | 234 [1, 2, undefined]); |
| 236 } | |
| 237 // TODO(wingo): Enable this test. Currently accessing "this" doesn't work as | |
| 238 // prior to generators, nothing needed to heap-allocate the receiver. | |
| 239 // TestReceivers(); | |
| 240 | 235 |
| 241 function TestRecursion() { | 236 function TestRecursion() { |
| 242 function TestNextRecursion() { | 237 function TestNextRecursion() { |
| 243 function* g() { yield iter.next(); } | 238 function* g() { yield iter.next(); } |
| 244 var iter = g(); | 239 var iter = g(); |
| 245 return iter.next(); | 240 return iter.next(); |
| 246 } | 241 } |
| 247 function TestSendRecursion() { | 242 function TestSendRecursion() { |
| 248 function* g() { yield iter.send(42); } | 243 function* g() { yield iter.send(42); } |
| 249 var iter = g(); | 244 var iter = g(); |
| 250 return iter.next(); | 245 return iter.next(); |
| 251 } | 246 } |
| 252 function TestThrowRecursion() { | 247 function TestThrowRecursion() { |
| 253 function* g() { yield iter.throw(1); } | 248 function* g() { yield iter.throw(1); } |
| 254 var iter = g(); | 249 var iter = g(); |
| 255 return iter.next(); | 250 return iter.next(); |
| 256 } | 251 } |
| 257 assertThrows(TestNextRecursion, Error); | 252 assertThrows(TestNextRecursion, Error); |
| 258 assertThrows(TestSendRecursion, Error); | 253 assertThrows(TestSendRecursion, Error); |
| 259 assertThrows(TestThrowRecursion, Error); | 254 assertThrows(TestThrowRecursion, Error); |
| 260 } | 255 } |
| 261 TestRecursion(); | 256 TestRecursion(); |
| OLD | NEW |