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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 // Test generator iteration. | 30 // Test generator iteration. |
31 | 31 |
32 var GeneratorFunction = (function*(){yield 1;}).__proto__.constructor; | 32 var GeneratorFunction = (function*(){yield 1;}).__proto__.constructor; |
33 | 33 |
34 function TestGenerator(g, expected_values_for_next, | 34 function TestGenerator(g, expected_values_for_next, |
35 send_val, expected_values_for_send) { | 35 send_val, expected_values_for_send) { |
36 function testNext(thunk) { | 36 function testNext(thunk) { |
37 var iter = thunk(); | 37 var iter = thunk(); |
38 for (var i = 0; i < expected_values_for_next.length; i++) { | 38 for (var i = 0; i < expected_values_for_next.length; i++) { |
39 assertEquals(expected_values_for_next[i], iter.next()); | 39 assertEquals({ value: expected_values_for_next[i], |
| 40 done: i == expected_values_for_next.length - 1 }, |
| 41 iter.next()); |
40 } | 42 } |
41 assertThrows(function() { iter.next(); }, Error); | 43 assertThrows(function() { iter.next(); }, Error); |
42 } | 44 } |
43 function testSend(thunk) { | 45 function testSend(thunk) { |
44 var iter = thunk(); | 46 var iter = thunk(); |
45 for (var i = 0; i < expected_values_for_send.length; i++) { | 47 for (var i = 0; i < expected_values_for_send.length; i++) { |
46 assertEquals(expected_values_for_send[i], iter.send(send_val)); | 48 assertEquals({ value: expected_values_for_send[i], |
| 49 done: i == expected_values_for_send.length - 1 }, |
| 50 iter.send(send_val)); |
47 } | 51 } |
48 assertThrows(function() { iter.send(send_val); }, Error); | 52 assertThrows(function() { iter.send(send_val); }, Error); |
49 } | 53 } |
50 function testThrow(thunk) { | 54 function testThrow(thunk) { |
51 for (var i = 0; i < expected_values_for_next.length; i++) { | 55 for (var i = 0; i < expected_values_for_next.length; i++) { |
52 var iter = thunk(); | 56 var iter = thunk(); |
53 for (var j = 0; j < i; j++) { | 57 for (var j = 0; j < i; j++) { |
54 assertEquals(expected_values_for_next[j], iter.next()); | 58 assertEquals({ value: expected_values_for_next[j], |
| 59 done: j == expected_values_for_next.length - 1 }, |
| 60 iter.next()); |
55 } | 61 } |
56 function Sentinel() {} | 62 function Sentinel() {} |
57 assertThrows(function () { iter.throw(new Sentinel); }, Sentinel); | 63 assertThrows(function () { iter.throw(new Sentinel); }, Sentinel); |
58 assertThrows(function () { iter.next(); }, Error); | 64 assertThrows(function () { iter.next(); }, Error); |
59 } | 65 } |
60 } | 66 } |
61 | 67 |
62 testNext(g); | 68 testNext(g); |
63 testSend(g); | 69 testSend(g); |
64 testThrow(g); | 70 testThrow(g); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 function TestThrowRecursion() { | 290 function TestThrowRecursion() { |
285 function* g() { yield iter.throw(1); } | 291 function* g() { yield iter.throw(1); } |
286 var iter = g(); | 292 var iter = g(); |
287 return iter.next(); | 293 return iter.next(); |
288 } | 294 } |
289 assertThrows(TestNextRecursion, Error); | 295 assertThrows(TestNextRecursion, Error); |
290 assertThrows(TestSendRecursion, Error); | 296 assertThrows(TestSendRecursion, Error); |
291 assertThrows(TestThrowRecursion, Error); | 297 assertThrows(TestThrowRecursion, Error); |
292 } | 298 } |
293 TestRecursion(); | 299 TestRecursion(); |
OLD | NEW |