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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 } | 472 } |
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 |
| 483 |
| 484 // Test special prototypes |
| 485 (function testSortSpecialPrototypes() { |
| 486 function test(proto, length, expected) { |
| 487 var result = { |
| 488 length: length, |
| 489 __proto__: proto, |
| 490 }; |
| 491 Array.prototype.sort.call(result); |
| 492 assertEquals(expected.length, result.length, "result.length"); |
| 493 for (var i = 0; i<expected.length; i++) { |
| 494 assertEquals(expected[i], result[i], "result["+i+"]"); |
| 495 } |
| 496 } |
| 497 |
| 498 (function fast() { |
| 499 // Fast elements, non-empty |
| 500 test(arguments, 0, []); |
| 501 test(arguments, 1, [2]); |
| 502 test(arguments, 2, [1, 2]); |
| 503 test(arguments, 4, [1, 2, 3, 4]); |
| 504 delete arguments[0] |
| 505 // sort copies down the properties to the receiver, hence result[1] |
| 506 // is read on the arguments through the hole on the receiver. |
| 507 test(arguments, 2, [1, 1]); |
| 508 arguments[0] = undefined; |
| 509 test(arguments, 2, [1, undefined]); |
| 510 })(2, 1, 4, 3); |
| 511 |
| 512 (function fastSloppy(a) { |
| 513 // Fast sloppy |
| 514 test(arguments, 0, []); |
| 515 test(arguments, 1, [2]); |
| 516 test(arguments, 2, [1, 2]); |
| 517 delete arguments[0] |
| 518 test(arguments, 2, [1, 1]); |
| 519 arguments[0] = undefined; |
| 520 test(arguments, 2, [1, undefined]); |
| 521 })(2, 1); |
| 522 |
| 523 (function fastEmpty() { |
| 524 test(arguments, 0, []); |
| 525 test(arguments, 1, [undefined]); |
| 526 test(arguments, 2, [undefined, undefined]); |
| 527 })(); |
| 528 |
| 529 (function stringWrapper() { |
| 530 // cannot redefine string wrapper properties |
| 531 assertThrows(() => test(new String('cba'), 3, []), TypeError); |
| 532 })(); |
| 533 |
| 534 (function typedArrys() { |
| 535 test(new Int32Array(0), 0, []); |
| 536 test(new Int32Array(1), 1, [0]); |
| 537 var array = new Int32Array(3); |
| 538 array[0] = 2; |
| 539 array[1] = 1; |
| 540 array[2] = 3; |
| 541 test(array, 1, [2]); |
| 542 test(array, 2, [1, 2]); |
| 543 test(array, 3, [1, 2, 3]); |
| 544 })() |
| 545 |
| 546 })(); |
OLD | NEW |