This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +25
-5
lines changed
2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -170,18 +170,18 @@ function orderByFilter($parse) {
170
170
if ( t1 === t2 && t1 === "object" ) {
171
171
// If types are both numbers, emulate abstract ToPrimitive() operation
172
172
// in order to get primitive values suitable for comparison
173
- t1 = typeof ( v1 = v1 . valueOf ( ) ) ;
174
- t2 = typeof ( v2 = v2 . valueOf ( ) ) ;
173
+ t1 = typeof ( v1 . valueOf ? v1 = v1 . valueOf ( ) : v1 ) ;
174
+ t2 = typeof ( v2 . valueOf ? v2 = v2 . valueOf ( ) : v2 ) ;
175
175
if ( t1 === t2 && t1 === "object" ) {
176
176
// Object.prototype.valueOf will return the original object, by
177
177
// default. If we do not receive a primitive value, use ToString()
178
178
// instead.
179
- t1 = typeof ( v1 = v1 . toString ( ) ) ;
180
- t2 = typeof ( v2 = v2 . toString ( ) ) ;
179
+ t1 = typeof ( v1 . toString ? v1 = v1 . toString ( ) : v1 ) ;
180
+ t2 = typeof ( v2 . toString ? v2 = v2 . toString ( ) : v2 ) ;
181
181
182
182
// If the end result of toString() for each item is the same, do not
183
183
// perform relational comparison, and do not re-order objects.
184
- if ( t1 === t2 && v1 === v2 ) return 0 ;
184
+ if ( t1 === t2 && v1 === v2 || t1 === "object" ) return 0 ;
185
185
}
186
186
}
187
187
if ( t1 === t2 ) {
Original file line number Diff line number Diff line change @@ -115,6 +115,16 @@ describe('Filter: orderBy', function() {
115
115
] ;
116
116
expect ( orderBy ( array ) ) . toEqualData ( array ) ;
117
117
} ) ;
118
+
119
+
120
+ it ( 'should not reverse array of objects with null prototype and no predicate' , function ( ) {
121
+ var array = [ 2 , 1 , 4 , 3 ] . map ( function ( id ) {
122
+ var obj = Object . create ( null ) ;
123
+ obj . id = id ;
124
+ return obj ;
125
+ } ) ;
126
+ expect ( orderBy ( array ) ) . toEqualData ( array ) ;
127
+ } ) ;
118
128
} ) ;
119
129
120
130
@@ -232,5 +242,15 @@ describe('Filter: orderBy', function() {
232
242
] ;
233
243
expect ( orderBy ( array ) ) . toEqualData ( array ) ;
234
244
} ) ;
245
+
246
+
247
+ it ( 'should not reverse array of objects with null prototype and no predicate' , function ( ) {
248
+ var array = [ 2 , 1 , 4 , 3 ] . map ( function ( id ) {
249
+ var obj = Object . create ( null ) ;
250
+ obj . id = id ;
251
+ return obj ;
252
+ } ) ;
253
+ expect ( orderBy ( array ) ) . toEqualData ( array ) ;
254
+ } ) ;
235
255
} ) ;
236
256
} ) ;
You can’t perform that action at this time.
0 commit comments