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

Side by Side Diff: src/array.js

Issue 92123: Fix Issue 326. Handle sorting of non-array objects correctly. (Closed)
Patch Set: Simplified fixed-array collation loop. Added more tests for dictionary. Created 11 years, 7 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
« no previous file with comments | « no previous file | src/objects.h » ('j') | src/objects.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 a[i] = a[high_start]; 702 a[i] = a[high_start];
703 a[high_start] = element; 703 a[high_start] = element;
704 } else { // order == 0 704 } else { // order == 0
705 i++; 705 i++;
706 } 706 }
707 } 707 }
708 QuickSort(a, from, low_end); 708 QuickSort(a, from, low_end);
709 QuickSort(a, high_start, to); 709 QuickSort(a, high_start, to);
710 } 710 }
711 711
712 var old_length = ToUint32(this.length); 712 var length = ToUint32(this.length);
713 if (old_length < 2) return this; 713 if (!(length >= 2)) return this;
714 714
715 %RemoveArrayHoles(this); 715 var num_non_undefined = %RemoveArrayHoles(this, length);
716 716
717 var length = ToUint32(this.length); 717 QuickSort(this, 0, num_non_undefined);
718
719 // Move undefined elements to the end of the array.
720 for (var i = 0; i < length; ) {
721 if (IS_UNDEFINED(this[i])) {
722 length--;
723 this[i] = this[length];
724 this[length] = void 0;
725 } else {
726 i++;
727 }
728 }
729
730 QuickSort(this, 0, length);
731
732 // We only changed the length of the this object (in
733 // RemoveArrayHoles) if it was an array. We are not allowed to set
734 // the length of the this object if it is not an array because this
735 // might introduce a new length property.
736 if (IS_ARRAY(this)) {
737 this.length = old_length;
738 }
739 718
740 return this; 719 return this;
741 } 720 }
742 721
743 722
744 // The following functions cannot be made efficient on sparse arrays while 723 // The following functions cannot be made efficient on sparse arrays while
745 // preserving the semantics, since the calls to the receiver function can add 724 // preserving the semantics, since the calls to the receiver function can add
746 // or delete elements from the array. 725 // or delete elements from the array.
747 function ArrayFilter(f, receiver) { 726 function ArrayFilter(f, receiver) {
748 if (!IS_FUNCTION(f)) { 727 if (!IS_FUNCTION(f)) {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 ArrayIndexOf: 1, 968 ArrayIndexOf: 1,
990 ArrayLastIndexOf: 1, 969 ArrayLastIndexOf: 1,
991 ArrayPush: 1, 970 ArrayPush: 1,
992 ArrayReduce: 1, 971 ArrayReduce: 1,
993 ArrayReduceRight: 1 972 ArrayReduceRight: 1
994 }); 973 });
995 } 974 }
996 975
997 976
998 SetupArray(); 977 SetupArray();
OLDNEW
« no previous file with comments | « no previous file | src/objects.h » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698