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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 fold(append, [], | 206 fold(append, [], |
207 results([10, "foo", /qux/, { value: 37, done: true }]))); | 207 results([10, "foo", /qux/, { value: 37, done: true }]))); |
208 // Getters (shudder). | 208 // Getters (shudder). |
209 assertEquals([1, 2], | 209 assertEquals([1, 2], |
210 fold(append, [], | 210 fold(append, [], |
211 results([one_time_getter({ value: 1 }, 'done', false), | 211 results([one_time_getter({ value: 1 }, 'done', false), |
212 one_time_getter({ done: false }, 'value', 2), | 212 one_time_getter({ done: false }, 'value', 2), |
213 { value: 37, done: true }, | 213 { value: 37, done: true }, |
214 never_getter(never_getter({}, 'done'), 'value')]))); | 214 never_getter(never_getter({}, 'done'), 'value')]))); |
215 | 215 |
216 // Null and undefined do not cause an error. | 216 // Unlike the case with for-in, null and undefined cause an error. |
217 assertEquals(0, fold(sum, 0, unreachable(null))); | 217 assertThrows('fold(sum, 0, unreachable(null))', TypeError); |
218 assertEquals(0, fold(sum, 0, unreachable(undefined))); | 218 assertThrows('fold(sum, 0, unreachable(undefined))', TypeError); |
219 | 219 |
220 // Other non-iterators do cause an error. | 220 // Other non-iterators do cause an error. |
221 assertThrows('fold(sum, 0, unreachable({}))', TypeError); | 221 assertThrows('fold(sum, 0, unreachable({}))', TypeError); |
222 assertThrows('fold(sum, 0, unreachable(false))', TypeError); | 222 assertThrows('fold(sum, 0, unreachable(false))', TypeError); |
223 assertThrows('fold(sum, 0, unreachable(37))', TypeError); | 223 assertThrows('fold(sum, 0, unreachable(37))', TypeError); |
224 | 224 |
225 // "next" is looked up each time. | 225 // "next" is looked up each time. |
226 assertThrows('fold(sum, 0, remove_next_after(integers_until(10), 5))', | 226 assertThrows('fold(sum, 0, remove_next_after(integers_until(10), 5))', |
227 TypeError); | 227 TypeError); |
228 // It is not called at any other time. | 228 // It is not called at any other time. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 if (name == 'next' && n-- < 0) throw "unreachable"; | 329 if (name == 'next' && n-- < 0) throw "unreachable"; |
330 return iterator[name]; | 330 return iterator[name]; |
331 }, | 331 }, |
332 // Needed for integers_until(10)'s this.n++. | 332 // Needed for integers_until(10)'s this.n++. |
333 set: function(receiver, name, val) { | 333 set: function(receiver, name, val) { |
334 return iterator[name] = val; | 334 return iterator[name] = val; |
335 } | 335 } |
336 })); | 336 })); |
337 } | 337 } |
338 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))); |
OLD | NEW |