Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(638)

Side by Side Diff: test/mjsunit/array-sort.js

Issue 2664173002: Throw when a holey property is set in Array.sort (Closed)
Patch Set: Patch PrepareSlowElementsForSort directly Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/objects.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
adamk 2017/02/07 00:23:46 You can use assertThrows(() => arr.sort(), TypeEr
Choongwoo Han 2017/02/07 09:45:49 Done.
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]);
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
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 })();
OLDNEW
« src/objects.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698