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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 assertEquals(false, | 300 assertEquals(false, |
301 try_control(integers_until(10), | 301 try_control(integers_until(10), |
302 function() { return "break" })); | 302 function() { return "break" })); |
303 assertEquals(false, | 303 assertEquals(false, |
304 try_control(integers_until(10), | 304 try_control(integers_until(10), |
305 function() { return "continue" })); | 305 function() { return "continue" })); |
306 assertEquals(5, | 306 assertEquals(5, |
307 try_control(integers_until(10), | 307 try_control(integers_until(10), |
308 function(x) { return (x == 5) ? x : "continue" })); | 308 function(x) { return (x == 5) ? x : "continue" })); |
309 | 309 |
| 310 // TODO(neis,cbruni): Enable once the corresponding traps work again. |
310 // Proxy results, with getters. | 311 // Proxy results, with getters. |
311 function transparent_proxy(x) { | 312 // function transparent_proxy(x) { |
312 return Proxy.create({ | 313 // return new Proxy({}, { |
313 get: function(receiver, name) { return x[name]; } | 314 // get: function(receiver, name) { return x[name]; } |
314 }); | 315 // }); |
315 } | 316 // } |
316 assertEquals([1, 2], | 317 // assertEquals([1, 2], |
317 fold(append, [], | 318 // fold(append, [], |
318 results([one_time_getter({ value: 1 }, 'done', false), | 319 // results([one_time_getter({ value: 1 }, 'done', false), |
319 one_time_getter({ done: false }, 'value', 2), | 320 // one_time_getter({ done: false }, 'value', 2), |
320 { value: 37, done: true }, | 321 // { value: 37, done: true }, |
321 never_getter(never_getter({}, 'done'), 'value')] | 322 // never_getter(never_getter({}, 'done'), 'value')] |
322 .map(transparent_proxy)))); | 323 // .map(transparent_proxy)))); |
323 | 324 |
324 // Proxy iterators. | 325 // Proxy iterators. |
325 function poison_proxy_after(iterable, n) { | 326 // function poison_proxy_after(iterable, n) { |
326 var iterator = iterable[Symbol.iterator](); | 327 // var iterator = iterable[Symbol.iterator](); |
327 return wrap_iterator(Proxy.create({ | 328 // return wrap_iterator(new Proxy({}, { |
328 get: function(receiver, name) { | 329 // get: function(receiver, name) { |
329 if (name == 'next' && n-- < 0) throw "unreachable"; | 330 // if (name == 'next' && n-- < 0) throw "unreachable"; |
330 return iterator[name]; | 331 // return iterator[name]; |
331 }, | 332 // }, |
332 // Needed for integers_until(10)'s this.n++. | 333 // // Needed for integers_until(10)'s this.n++. |
333 set: function(receiver, name, val) { | 334 // set: function(receiver, name, val) { |
334 return iterator[name] = val; | 335 // return iterator[name] = val; |
335 } | 336 // } |
336 })); | 337 // })); |
337 } | 338 // } |
338 assertEquals(45, fold(sum, 0, poison_proxy_after(integers_until(10), 10))); | 339 // assertEquals(45, fold(sum, 0, poison_proxy_after(integers_until(10), 10))); |
339 | 340 |
340 | 341 |
341 function test_iterator_result_object_non_object(value, descr) { | 342 function test_iterator_result_object_non_object(value, descr) { |
342 var arr = []; | 343 var arr = []; |
343 var ex; | 344 var ex; |
344 var message = 'Iterator result ' + (descr || value) + ' is not an object'; | 345 var message = 'Iterator result ' + (descr || value) + ' is not an object'; |
345 try { | 346 try { |
346 fold(append, arr, | 347 fold(append, arr, |
347 results([{value: 1}, {}, value, {value: 2}, {done: true}])); | 348 results([{value: 1}, {}, value, {value: 2}, {done: true}])); |
348 } catch (e) { | 349 } catch (e) { |
349 ex = e; | 350 ex = e; |
350 } | 351 } |
351 assertInstanceof(ex, TypeError); | 352 assertInstanceof(ex, TypeError); |
352 assertEquals(message, ex.message); | 353 assertEquals(message, ex.message); |
353 assertArrayEquals([1, undefined], arr); | 354 assertArrayEquals([1, undefined], arr); |
354 } | 355 } |
355 test_iterator_result_object_non_object(null); | 356 test_iterator_result_object_non_object(null); |
356 test_iterator_result_object_non_object(undefined); | 357 test_iterator_result_object_non_object(undefined); |
357 test_iterator_result_object_non_object(42); | 358 test_iterator_result_object_non_object(42); |
358 test_iterator_result_object_non_object('abc'); | 359 test_iterator_result_object_non_object('abc'); |
359 test_iterator_result_object_non_object(false); | 360 test_iterator_result_object_non_object(false); |
360 test_iterator_result_object_non_object(Symbol('x'), 'Symbol(x)'); | 361 test_iterator_result_object_non_object(Symbol('x'), 'Symbol(x)'); |
OLD | NEW |