Skip to content

Commit e7e81d8

Browse files
committed
Safari 10.0 - 14.0 %TypedArray%.prototype.sort accept incorrect arguments
1 parent 39919be commit e7e81d8

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Changelog
22
##### Unreleased
33
- Added polyfill of stable sort in `{ Array, %TypedArray% }.prototype.sort`, [#769](https://github.com/zloirock/core-js/issues/769)
4+
- Fixed `Safari` 14.0- `{ Array, %TypedArray% }.prototype.sort` validation of arguments bug
45
- `.at` marked as supported from V8 9.2
56

67
##### 3.13.1 - 2021.05.29

packages/core-js-compat/src/data.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,8 @@ const data = {
12301230
'es.typed-array.sort': {
12311231
chrome: '74',
12321232
firefox: '67',
1233-
safari: '10.0',
1233+
// 10.0 - 14.0 accept incorrect arguments
1234+
safari: '14.1',
12341235
},
12351236
'es.typed-array.subarray': {
12361237
chrome: '26',

packages/core-js/modules/es.typed-array.sort.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
'use strict';
2+
/* eslint-disable es/no-typed-arrays -- required for testing */
23
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
4+
var global = require('../internals/global');
35
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');
58
var FF = require('../internals/engine-ff-version');
69
var IE_OR_EDGE = require('../internals/engine-is-ie-or-edge');
710
var V8 = require('../internals/engine-v8-version');
811
var WEBKIT = require('../internals/engine-webkit-version');
912

1013
var aTypedArray = ArrayBufferViewCore.aTypedArray;
1114
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
15+
var Uint16Array = global.Uint16Array;
16+
var nativeSort = Uint16Array && Uint16Array.prototype.sort;
1217

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 () {
1426
// feature detection can be too slow, so check engines versions
15-
if (V8) return V8 < 73;
27+
if (V8) return V8 < 74;
1628
if (FF) return FF < 67;
1729
if (IE_OR_EDGE) return true;
1830
if (WEBKIT) return WEBKIT < 602;
1931

20-
// eslint-disable-next-line es/no-typed-arrays -- required for testing
2132
var array = new Uint16Array(516);
2233
var expected = Array(516);
2334
var index, mod;
@@ -40,5 +51,7 @@ var STABLE_SORT = !fails(function () {
4051
// `%TypedArray%.prototype.sort` method
4152
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.sort
4253
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

Comments
 (0)