1 | 'use strict';
|
2 | var $ = require('../internals/export');
|
3 | var aFunction = require('../internals/a-function');
|
4 | var toObject = require('../internals/to-object');
|
5 | var fails = require('../internals/fails');
|
6 | var sloppyArrayMethod = require('../internals/sloppy-array-method');
|
7 |
|
8 | var nativeSort = [].sort;
|
9 | var test = [1, 2, 3];
|
10 |
|
11 |
|
12 | var FAILS_ON_UNDEFINED = fails(function () {
|
13 | test.sort(undefined);
|
14 | });
|
15 |
|
16 | var FAILS_ON_NULL = fails(function () {
|
17 | test.sort(null);
|
18 | });
|
19 |
|
20 | var SLOPPY_METHOD = sloppyArrayMethod('sort');
|
21 |
|
22 | var FORCED = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || SLOPPY_METHOD;
|
23 |
|
24 |
|
25 |
|
26 | $({ target: 'Array', proto: true, forced: FORCED }, {
|
27 | sort: function sort(comparefn) {
|
28 | return comparefn === undefined
|
29 | ? nativeSort.call(toObject(this))
|
30 | : nativeSort.call(toObject(this), aFunction(comparefn));
|
31 | }
|
32 | });
|