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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 results([{ done: false }, | 193 results([{ done: false }, |
194 { value: 1, done: false }, | 194 { value: 1, done: false }, |
195 // A missing "done" is the same as undefined, which | 195 // A missing "done" is the same as undefined, which |
196 // is false. | 196 // is false. |
197 { value: 2 }, | 197 { value: 2 }, |
198 // Not done. | 198 // Not done. |
199 { value: 3, done: 0 }, | 199 { value: 3, done: 0 }, |
200 // Done. | 200 // Done. |
201 { value: 4, done: 42 }]))); | 201 { value: 4, done: 42 }]))); |
202 // Results that are not objects. | 202 // Results that are not objects. |
203 assertThrows(function() { | 203 assertEquals([undefined, undefined, undefined], |
204 assertEquals([undefined, undefined, undefined], | 204 fold(append, [], |
205 fold(append, [], | 205 results([10, "foo", /qux/, { value: 37, done: true }]))); |
206 results([10, "foo", /qux/, { value: 37, done: true }]))); | |
207 }, TypeError); | |
208 // Getters (shudder). | 206 // Getters (shudder). |
209 assertEquals([1, 2], | 207 assertEquals([1, 2], |
210 fold(append, [], | 208 fold(append, [], |
211 results([one_time_getter({ value: 1 }, 'done', false), | 209 results([one_time_getter({ value: 1 }, 'done', false), |
212 one_time_getter({ done: false }, 'value', 2), | 210 one_time_getter({ done: false }, 'value', 2), |
213 { value: 37, done: true }, | 211 { value: 37, done: true }, |
214 never_getter(never_getter({}, 'done'), 'value')]))); | 212 never_getter(never_getter({}, 'done'), 'value')]))); |
215 | 213 |
216 // Unlike the case with for-in, null and undefined cause an error. | 214 // Unlike the case with for-in, null and undefined cause an error. |
217 assertThrows('fold(sum, 0, unreachable(null))', TypeError); | 215 assertThrows('fold(sum, 0, unreachable(null))', TypeError); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 if (name == 'next' && n-- < 0) throw "unreachable"; | 327 if (name == 'next' && n-- < 0) throw "unreachable"; |
330 return iterator[name]; | 328 return iterator[name]; |
331 }, | 329 }, |
332 // Needed for integers_until(10)'s this.n++. | 330 // Needed for integers_until(10)'s this.n++. |
333 set: function(receiver, name, val) { | 331 set: function(receiver, name, val) { |
334 return iterator[name] = val; | 332 return iterator[name] = val; |
335 } | 333 } |
336 })); | 334 })); |
337 } | 335 } |
338 assertEquals(45, fold(sum, 0, poison_proxy_after(integers_until(10), 10))); | 336 assertEquals(45, fold(sum, 0, poison_proxy_after(integers_until(10), 10))); |
339 | |
340 | |
341 function test_iterator_result_object_non_object(value, descr) { | |
342 var arr = []; | |
343 var ex; | |
344 var message = 'Iterator result ' + (descr || value) + ' is not an object'; | |
345 try { | |
346 fold(append, arr, | |
347 results([{value: 1}, {}, value, {value: 2}, {done: true}])); | |
348 } catch (e) { | |
349 ex = e; | |
350 } | |
351 assertInstanceof(ex, TypeError); | |
352 assertEquals(message, ex.message); | |
353 assertArrayEquals([1, undefined], arr); | |
354 } | |
355 test_iterator_result_object_non_object(null); | |
356 test_iterator_result_object_non_object(undefined); | |
357 test_iterator_result_object_non_object(42); | |
358 test_iterator_result_object_non_object('abc'); | |
359 test_iterator_result_object_non_object(false); | |
360 test_iterator_result_object_non_object(Symbol('x'), 'Symbol(x)'); | |
OLD | NEW |