1
1
'use strict' ;
2
+ /* eslint-disable es/no-typed-arrays -- required for testing */
2
3
var ArrayBufferViewCore = require ( '../internals/array-buffer-view-core' ) ;
4
+ var global = require ( '../internals/global' ) ;
3
5
var fails = require ( '../internals/fails' ) ;
4
- var $sort = require ( '../internals/array-sort' ) ;
6
+ var aFunction = require ( '../internals/a-function' ) ;
7
+ var arraySort = require ( '../internals/array-sort' ) ;
5
8
var FF = require ( '../internals/engine-ff-version' ) ;
6
9
var IE_OR_EDGE = require ( '../internals/engine-is-ie-or-edge' ) ;
7
10
var V8 = require ( '../internals/engine-v8-version' ) ;
8
11
var WEBKIT = require ( '../internals/engine-webkit-version' ) ;
9
12
10
13
var aTypedArray = ArrayBufferViewCore . aTypedArray ;
11
14
var exportTypedArrayMethod = ArrayBufferViewCore . exportTypedArrayMethod ;
15
+ var Uint16Array = global . Uint16Array ;
16
+ var nativeSort = Uint16Array && Uint16Array . prototype . sort ;
12
17
13
- var STABLE_SORT = ! fails ( function ( ) {
18
+ // WebKit
19
+ var ACCEPT_INCORRECT_ARGUMENTS = ! ! nativeSort && ! fails ( function ( ) {
20
+ var array = new Uint16Array ( 2 ) ;
21
+ array . sort ( null ) ;
22
+ array . sort ( { } ) ;
23
+ } ) ;
24
+
25
+ var STABLE_SORT = ! ! nativeSort && ! fails ( function ( ) {
14
26
// feature detection can be too slow, so check engines versions
15
- if ( V8 ) return V8 < 73 ;
27
+ if ( V8 ) return V8 < 74 ;
16
28
if ( FF ) return FF < 67 ;
17
29
if ( IE_OR_EDGE ) return true ;
18
30
if ( WEBKIT ) return WEBKIT < 602 ;
19
31
20
- // eslint-disable-next-line es/no-typed-arrays -- required for testing
21
32
var array = new Uint16Array ( 516 ) ;
22
33
var expected = Array ( 516 ) ;
23
34
var index , mod ;
@@ -40,5 +51,7 @@ var STABLE_SORT = !fails(function () {
40
51
// `%TypedArray%.prototype.sort` method
41
52
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.sort
42
53
exportTypedArrayMethod ( 'sort' , function sort ( comparefn ) {
43
- return $sort . call ( aTypedArray ( this ) , comparefn ) ;
44
- } , ! STABLE_SORT ) ;
54
+ if ( ! STABLE_SORT ) return arraySort . call ( aTypedArray ( this ) , comparefn ) ;
55
+ if ( comparefn !== undefined ) aFunction ( comparefn ) ;
56
+ return nativeSort . call ( this , comparefn ) ;
57
+ } , ! STABLE_SORT || ACCEPT_INCORRECT_ARGUMENTS ) ;
0 commit comments