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 assertEquals([undefined, undefined, undefined], | 203 assertThrows(function() { |
arv (Not doing code reviews)
2015/02/23 22:02:24
More extensive tests below
| |
204 fold(append, [], | 204 assertEquals([undefined, undefined, undefined], |
205 results([10, "foo", /qux/, { value: 37, done: true }]))); | 205 fold(append, [], |
206 results([10, "foo", /qux/, { value: 37, done: true }]))); | |
207 }, TypeError); | |
206 // Getters (shudder). | 208 // Getters (shudder). |
207 assertEquals([1, 2], | 209 assertEquals([1, 2], |
208 fold(append, [], | 210 fold(append, [], |
209 results([one_time_getter({ value: 1 }, 'done', false), | 211 results([one_time_getter({ value: 1 }, 'done', false), |
210 one_time_getter({ done: false }, 'value', 2), | 212 one_time_getter({ done: false }, 'value', 2), |
211 { value: 37, done: true }, | 213 { value: 37, done: true }, |
212 never_getter(never_getter({}, 'done'), 'value')]))); | 214 never_getter(never_getter({}, 'done'), 'value')]))); |
213 | 215 |
214 // Unlike the case with for-in, null and undefined cause an error. | 216 // Unlike the case with for-in, null and undefined cause an error. |
215 assertThrows('fold(sum, 0, unreachable(null))', TypeError); | 217 assertThrows('fold(sum, 0, unreachable(null))', TypeError); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 if (name == 'next' && n-- < 0) throw "unreachable"; | 329 if (name == 'next' && n-- < 0) throw "unreachable"; |
328 return iterator[name]; | 330 return iterator[name]; |
329 }, | 331 }, |
330 // Needed for integers_until(10)'s this.n++. | 332 // Needed for integers_until(10)'s this.n++. |
331 set: function(receiver, name, val) { | 333 set: function(receiver, name, val) { |
332 return iterator[name] = val; | 334 return iterator[name] = val; |
333 } | 335 } |
334 })); | 336 })); |
335 } | 337 } |
336 assertEquals(45, fold(sum, 0, poison_proxy_after(integers_until(10), 10))); | 338 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 |