OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 | 473 |
474 { | 474 { |
475 function f() { return arguments }; | 475 function f() { return arguments }; |
476 var a = f(2,1,3); | 476 var a = f(2,1,3); |
477 a.__proto__ = new Proxy({}, {}); | 477 a.__proto__ = new Proxy({}, {}); |
478 assertEquals([1,2,3], [...(Array.prototype.sort.apply(a))]); | 478 assertEquals([1,2,3], [...(Array.prototype.sort.apply(a))]); |
479 } | 479 } |
480 } | 480 } |
481 TestSortOnProxy(); | 481 TestSortOnProxy(); |
482 | 482 |
483 function TestSortOnNonExtensible() { | |
484 { | |
485 var arr = [1,,2]; | |
486 Object.preventExtensions(arr); | |
487 var exception = false; | |
488 try { | |
489 arr.sort(); | |
490 } catch (e) { | |
491 exception = true; | |
492 assertTrue(e instanceof TypeError); | |
493 } | |
494 assertTrue(exception); | |
495 assertEquals(arr, [1,,2]); | |
496 } | |
497 { | |
498 var arr = [1,undefined,2]; | |
499 Object.preventExtensions(arr); | |
500 arr.sort(); | |
501 assertEquals(3, arr.length); | |
502 assertEquals(arr, [1,2,undefined]); | |
adamk
2017/02/01 16:39:13
Shouldn't this fail now?
Choongwoo Han
2017/02/01 18:21:07
Yes. In this case, this arr does not have any hole
| |
503 } | |
504 } | |
505 TestSortOnNonExtensible(); | |
506 | |
483 | 507 |
484 // Test special prototypes | 508 // Test special prototypes |
485 (function testSortSpecialPrototypes() { | 509 (function testSortSpecialPrototypes() { |
486 function test(proto, length, expected) { | 510 function test(proto, length, expected) { |
487 var result = { | 511 var result = { |
488 length: length, | 512 length: length, |
489 __proto__: proto, | 513 __proto__: proto, |
490 }; | 514 }; |
491 Array.prototype.sort.call(result); | 515 Array.prototype.sort.call(result); |
492 assertEquals(expected.length, result.length, "result.length"); | 516 assertEquals(expected.length, result.length, "result.length"); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 var array = new Int32Array(3); | 561 var array = new Int32Array(3); |
538 array[0] = 2; | 562 array[0] = 2; |
539 array[1] = 1; | 563 array[1] = 1; |
540 array[2] = 3; | 564 array[2] = 3; |
541 test(array, 1, [2]); | 565 test(array, 1, [2]); |
542 test(array, 2, [1, 2]); | 566 test(array, 2, [1, 2]); |
543 test(array, 3, [1, 2, 3]); | 567 test(array, 3, [1, 2, 3]); |
544 })() | 568 })() |
545 | 569 |
546 })(); | 570 })(); |
OLD | NEW |