core-js 3.12.0 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/internals/array-sort.js +45 -0
- package/internals/call-with-safe-iteration-closing.js +0 -1
- package/internals/collection-strong.js +30 -14
- package/internals/collection-weak.js +12 -7
- package/internals/create-html.js +1 -1
- package/internals/date-to-primitive.js +2 -0
- package/internals/define-iterator.js +1 -1
- package/internals/engine-ff-version.js +5 -0
- package/internals/engine-is-ie-or-edge.js +3 -0
- package/internals/engine-webkit-version.js +5 -0
- package/internals/fix-regexp-well-known-symbol-logic.js +6 -3
- package/internals/get-substitution.js +1 -0
- package/internals/has.js +1 -1
- package/internals/inspect-source.js +1 -1
- package/internals/internal-state.js +1 -1
- package/internals/iterators-core.js +2 -1
- package/internals/native-symbol.js +4 -2
- package/internals/new-promise-capability.js +2 -1
- package/internals/object-prototype-accessors-forced.js +4 -0
- package/internals/regexp-exec.js +2 -1
- package/internals/shared.js +1 -1
- package/modules/es.array.sort.js +73 -4
- package/modules/es.typed-array.sort.js +77 -3
- package/package.json +2 -2
- package/stage/2.js +0 -1
- package/stage/3.js +1 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// TODO: use something more complex like timsort?
|
|
2
|
+
var floor = Math.floor;
|
|
3
|
+
|
|
4
|
+
var mergeSort = function (array, comparefn) {
|
|
5
|
+
var length = array.length;
|
|
6
|
+
var middle = floor(length / 2);
|
|
7
|
+
return length < 8 ? insertionSort(array, comparefn) : merge(
|
|
8
|
+
mergeSort(array.slice(0, middle), comparefn),
|
|
9
|
+
mergeSort(array.slice(middle), comparefn),
|
|
10
|
+
comparefn
|
|
11
|
+
);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
var insertionSort = function (array, comparefn) {
|
|
15
|
+
var length = array.length;
|
|
16
|
+
var i = 1;
|
|
17
|
+
var element, j;
|
|
18
|
+
|
|
19
|
+
while (i < length) {
|
|
20
|
+
j = i;
|
|
21
|
+
element = array[i];
|
|
22
|
+
while (j && comparefn(array[j - 1], element) > 0) {
|
|
23
|
+
array[j] = array[--j];
|
|
24
|
+
}
|
|
25
|
+
if (j !== i++) array[j] = element;
|
|
26
|
+
} return array;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var merge = function (left, right, comparefn) {
|
|
30
|
+
var llength = left.length;
|
|
31
|
+
var rlength = right.length;
|
|
32
|
+
var lindex = 0;
|
|
33
|
+
var rindex = 0;
|
|
34
|
+
var result = [];
|
|
35
|
+
|
|
36
|
+
while (lindex < llength || rindex < rlength) {
|
|
37
|
+
if (lindex < llength && rindex < rlength) {
|
|
38
|
+
result.push(comparefn(left[lindex], right[rindex]) <= 0 ? left[lindex++] : right[rindex++]);
|
|
39
|
+
} else {
|
|
40
|
+
result.push(lindex < llength ? left[lindex++] : right[rindex++]);
|
|
41
|
+
}
|
|
42
|
+
} return result;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = mergeSort;
|
|
@@ -5,7 +5,6 @@ var iteratorClose = require('../internals/iterator-close');
|
|
|
5
5
|
module.exports = function (iterator, fn, value, ENTRIES) {
|
|
6
6
|
try {
|
|
7
7
|
return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);
|
|
8
|
-
// 7.4.6 IteratorClose(iterator, completion)
|
|
9
8
|
} catch (error) {
|
|
10
9
|
iteratorClose(iterator);
|
|
11
10
|
throw error;
|
|
@@ -70,8 +70,9 @@ module.exports = {
|
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
redefineAll(C.prototype, {
|
|
73
|
-
//
|
|
74
|
-
//
|
|
73
|
+
// `{ Map, Set }.prototype.clear()` methods
|
|
74
|
+
// https://tc39.es/ecma262/#sec-map.prototype.clear
|
|
75
|
+
// https://tc39.es/ecma262/#sec-set.prototype.clear
|
|
75
76
|
clear: function clear() {
|
|
76
77
|
var that = this;
|
|
77
78
|
var state = getInternalState(that);
|
|
@@ -87,8 +88,9 @@ module.exports = {
|
|
|
87
88
|
if (DESCRIPTORS) state.size = 0;
|
|
88
89
|
else that.size = 0;
|
|
89
90
|
},
|
|
90
|
-
//
|
|
91
|
-
//
|
|
91
|
+
// `{ Map, Set }.prototype.delete(key)` methods
|
|
92
|
+
// https://tc39.es/ecma262/#sec-map.prototype.delete
|
|
93
|
+
// https://tc39.es/ecma262/#sec-set.prototype.delete
|
|
92
94
|
'delete': function (key) {
|
|
93
95
|
var that = this;
|
|
94
96
|
var state = getInternalState(that);
|
|
@@ -106,8 +108,9 @@ module.exports = {
|
|
|
106
108
|
else that.size--;
|
|
107
109
|
} return !!entry;
|
|
108
110
|
},
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
+
// `{ Map, Set }.prototype.forEach(callbackfn, thisArg = undefined)` methods
|
|
112
|
+
// https://tc39.es/ecma262/#sec-map.prototype.foreach
|
|
113
|
+
// https://tc39.es/ecma262/#sec-set.prototype.foreach
|
|
111
114
|
forEach: function forEach(callbackfn /* , that = undefined */) {
|
|
112
115
|
var state = getInternalState(this);
|
|
113
116
|
var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3);
|
|
@@ -118,25 +121,29 @@ module.exports = {
|
|
|
118
121
|
while (entry && entry.removed) entry = entry.previous;
|
|
119
122
|
}
|
|
120
123
|
},
|
|
121
|
-
//
|
|
122
|
-
//
|
|
124
|
+
// `{ Map, Set}.prototype.has(key)` methods
|
|
125
|
+
// https://tc39.es/ecma262/#sec-map.prototype.has
|
|
126
|
+
// https://tc39.es/ecma262/#sec-set.prototype.has
|
|
123
127
|
has: function has(key) {
|
|
124
128
|
return !!getEntry(this, key);
|
|
125
129
|
}
|
|
126
130
|
});
|
|
127
131
|
|
|
128
132
|
redefineAll(C.prototype, IS_MAP ? {
|
|
129
|
-
//
|
|
133
|
+
// `Map.prototype.get(key)` method
|
|
134
|
+
// https://tc39.es/ecma262/#sec-map.prototype.get
|
|
130
135
|
get: function get(key) {
|
|
131
136
|
var entry = getEntry(this, key);
|
|
132
137
|
return entry && entry.value;
|
|
133
138
|
},
|
|
134
|
-
//
|
|
139
|
+
// `Map.prototype.set(key, value)` method
|
|
140
|
+
// https://tc39.es/ecma262/#sec-map.prototype.set
|
|
135
141
|
set: function set(key, value) {
|
|
136
142
|
return define(this, key === 0 ? 0 : key, value);
|
|
137
143
|
}
|
|
138
144
|
} : {
|
|
139
|
-
//
|
|
145
|
+
// `Set.prototype.add(value)` method
|
|
146
|
+
// https://tc39.es/ecma262/#sec-set.prototype.add
|
|
140
147
|
add: function add(value) {
|
|
141
148
|
return define(this, value = value === 0 ? 0 : value, value);
|
|
142
149
|
}
|
|
@@ -152,8 +159,15 @@ module.exports = {
|
|
|
152
159
|
var ITERATOR_NAME = CONSTRUCTOR_NAME + ' Iterator';
|
|
153
160
|
var getInternalCollectionState = internalStateGetterFor(CONSTRUCTOR_NAME);
|
|
154
161
|
var getInternalIteratorState = internalStateGetterFor(ITERATOR_NAME);
|
|
155
|
-
//
|
|
156
|
-
//
|
|
162
|
+
// `{ Map, Set }.prototype.{ keys, values, entries, @@iterator }()` methods
|
|
163
|
+
// https://tc39.es/ecma262/#sec-map.prototype.entries
|
|
164
|
+
// https://tc39.es/ecma262/#sec-map.prototype.keys
|
|
165
|
+
// https://tc39.es/ecma262/#sec-map.prototype.values
|
|
166
|
+
// https://tc39.es/ecma262/#sec-map.prototype-@@iterator
|
|
167
|
+
// https://tc39.es/ecma262/#sec-set.prototype.entries
|
|
168
|
+
// https://tc39.es/ecma262/#sec-set.prototype.keys
|
|
169
|
+
// https://tc39.es/ecma262/#sec-set.prototype.values
|
|
170
|
+
// https://tc39.es/ecma262/#sec-set.prototype-@@iterator
|
|
157
171
|
defineIterator(C, CONSTRUCTOR_NAME, function (iterated, kind) {
|
|
158
172
|
setInternalState(this, {
|
|
159
173
|
type: ITERATOR_NAME,
|
|
@@ -180,7 +194,9 @@ module.exports = {
|
|
|
180
194
|
return { value: [entry.key, entry.value], done: false };
|
|
181
195
|
}, IS_MAP ? 'entries' : 'values', !IS_MAP, true);
|
|
182
196
|
|
|
183
|
-
//
|
|
197
|
+
// `{ Map, Set }.prototype[@@species]` accessors
|
|
198
|
+
// https://tc39.es/ecma262/#sec-get-map-@@species
|
|
199
|
+
// https://tc39.es/ecma262/#sec-get-set-@@species
|
|
184
200
|
setSpecies(CONSTRUCTOR_NAME);
|
|
185
201
|
}
|
|
186
202
|
};
|
|
@@ -75,8 +75,9 @@ module.exports = {
|
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
redefineAll(C.prototype, {
|
|
78
|
-
//
|
|
79
|
-
//
|
|
78
|
+
// `{ WeakMap, WeakSet }.prototype.delete(key)` methods
|
|
79
|
+
// https://tc39.es/ecma262/#sec-weakmap.prototype.delete
|
|
80
|
+
// https://tc39.es/ecma262/#sec-weakset.prototype.delete
|
|
80
81
|
'delete': function (key) {
|
|
81
82
|
var state = getInternalState(this);
|
|
82
83
|
if (!isObject(key)) return false;
|
|
@@ -84,8 +85,9 @@ module.exports = {
|
|
|
84
85
|
if (data === true) return uncaughtFrozenStore(state)['delete'](key);
|
|
85
86
|
return data && $has(data, state.id) && delete data[state.id];
|
|
86
87
|
},
|
|
87
|
-
//
|
|
88
|
-
//
|
|
88
|
+
// `{ WeakMap, WeakSet }.prototype.has(key)` methods
|
|
89
|
+
// https://tc39.es/ecma262/#sec-weakmap.prototype.has
|
|
90
|
+
// https://tc39.es/ecma262/#sec-weakset.prototype.has
|
|
89
91
|
has: function has(key) {
|
|
90
92
|
var state = getInternalState(this);
|
|
91
93
|
if (!isObject(key)) return false;
|
|
@@ -96,7 +98,8 @@ module.exports = {
|
|
|
96
98
|
});
|
|
97
99
|
|
|
98
100
|
redefineAll(C.prototype, IS_MAP ? {
|
|
99
|
-
//
|
|
101
|
+
// `WeakMap.prototype.get(key)` method
|
|
102
|
+
// https://tc39.es/ecma262/#sec-weakmap.prototype.get
|
|
100
103
|
get: function get(key) {
|
|
101
104
|
var state = getInternalState(this);
|
|
102
105
|
if (isObject(key)) {
|
|
@@ -105,12 +108,14 @@ module.exports = {
|
|
|
105
108
|
return data ? data[state.id] : undefined;
|
|
106
109
|
}
|
|
107
110
|
},
|
|
108
|
-
//
|
|
111
|
+
// `WeakMap.prototype.set(key, value)` method
|
|
112
|
+
// https://tc39.es/ecma262/#sec-weakmap.prototype.set
|
|
109
113
|
set: function set(key, value) {
|
|
110
114
|
return define(this, key, value);
|
|
111
115
|
}
|
|
112
116
|
} : {
|
|
113
|
-
//
|
|
117
|
+
// `WeakSet.prototype.add(value)` method
|
|
118
|
+
// https://tc39.es/ecma262/#sec-weakset.prototype.add
|
|
114
119
|
add: function add(value) {
|
|
115
120
|
return define(this, value, true);
|
|
116
121
|
}
|
package/internals/create-html.js
CHANGED
|
@@ -2,7 +2,7 @@ var requireObjectCoercible = require('../internals/require-object-coercible');
|
|
|
2
2
|
|
|
3
3
|
var quot = /"/g;
|
|
4
4
|
|
|
5
|
-
//
|
|
5
|
+
// `CreateHTML` abstract operation
|
|
6
6
|
// https://tc39.es/ecma262/#sec-createhtml
|
|
7
7
|
module.exports = function (string, tag, attribute, value) {
|
|
8
8
|
var S = String(requireObjectCoercible(string));
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
var anObject = require('../internals/an-object');
|
|
3
3
|
var toPrimitive = require('../internals/to-primitive');
|
|
4
4
|
|
|
5
|
+
// `Date.prototype[@@toPrimitive](hint)` method implementation
|
|
6
|
+
// https://tc39.es/ecma262/#sec-date.prototype-@@toprimitive
|
|
5
7
|
module.exports = function (hint) {
|
|
6
8
|
if (hint !== 'string' && hint !== 'number' && hint !== 'default') {
|
|
7
9
|
throw TypeError('Incorrect hint');
|
|
@@ -60,7 +60,7 @@ module.exports = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, I
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
// fix Array
|
|
63
|
+
// fix Array.prototype.{ values, @@iterator }.name in V8 / FF
|
|
64
64
|
if (DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) {
|
|
65
65
|
INCORRECT_VALUES_NAME = true;
|
|
66
66
|
defaultIterator = function values() { return nativeIterator.call(this); };
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
// TODO: Remove from `core-js@4` since it's moved to entry points
|
|
3
3
|
require('../modules/es.regexp.exec');
|
|
4
4
|
var redefine = require('../internals/redefine');
|
|
5
|
+
var regexpExec = require('../internals/regexp-exec');
|
|
5
6
|
var fails = require('../internals/fails');
|
|
6
7
|
var wellKnownSymbol = require('../internals/well-known-symbol');
|
|
7
8
|
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
|
8
9
|
|
|
9
10
|
var SPECIES = wellKnownSymbol('species');
|
|
11
|
+
var RegExpPrototype = RegExp.prototype;
|
|
10
12
|
|
|
11
13
|
var REPLACE_SUPPORTS_NAMED_GROUPS = !fails(function () {
|
|
12
14
|
// #replace needs built-in support for named groups.
|
|
@@ -94,7 +96,8 @@ module.exports = function (KEY, length, exec, sham) {
|
|
|
94
96
|
) {
|
|
95
97
|
var nativeRegExpMethod = /./[SYMBOL];
|
|
96
98
|
var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) {
|
|
97
|
-
|
|
99
|
+
var $exec = regexp.exec;
|
|
100
|
+
if ($exec === regexpExec || $exec === RegExpPrototype.exec) {
|
|
98
101
|
if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
|
|
99
102
|
// The native String method already delegates to @@method (this
|
|
100
103
|
// polyfilled function), leasing to infinite recursion.
|
|
@@ -112,7 +115,7 @@ module.exports = function (KEY, length, exec, sham) {
|
|
|
112
115
|
var regexMethod = methods[1];
|
|
113
116
|
|
|
114
117
|
redefine(String.prototype, KEY, stringMethod);
|
|
115
|
-
redefine(
|
|
118
|
+
redefine(RegExpPrototype, SYMBOL, length == 2
|
|
116
119
|
// 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
|
|
117
120
|
// 21.2.5.11 RegExp.prototype[@@split](string, limit)
|
|
118
121
|
? function (string, arg) { return regexMethod.call(string, this, arg); }
|
|
@@ -122,5 +125,5 @@ module.exports = function (KEY, length, exec, sham) {
|
|
|
122
125
|
);
|
|
123
126
|
}
|
|
124
127
|
|
|
125
|
-
if (sham) createNonEnumerableProperty(
|
|
128
|
+
if (sham) createNonEnumerableProperty(RegExpPrototype[SYMBOL], 'sham', true);
|
|
126
129
|
};
|
|
@@ -5,6 +5,7 @@ var replace = ''.replace;
|
|
|
5
5
|
var SUBSTITUTION_SYMBOLS = /\$([$&'`]|\d{1,2}|<[^>]*>)/g;
|
|
6
6
|
var SUBSTITUTION_SYMBOLS_NO_NAMED = /\$([$&'`]|\d{1,2})/g;
|
|
7
7
|
|
|
8
|
+
// `GetSubstitution` abstract operation
|
|
8
9
|
// https://tc39.es/ecma262/#sec-getsubstitution
|
|
9
10
|
module.exports = function (matched, str, position, captures, namedCaptures, replacement) {
|
|
10
11
|
var tailPos = position + matched.length;
|
package/internals/has.js
CHANGED
|
@@ -2,7 +2,7 @@ var store = require('../internals/shared-store');
|
|
|
2
2
|
|
|
3
3
|
var functionToString = Function.toString;
|
|
4
4
|
|
|
5
|
-
// this helper broken in `3.4.1-3.4.4`, so we can't use `shared` helper
|
|
5
|
+
// this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
|
|
6
6
|
if (typeof store.inspectSource != 'function') {
|
|
7
7
|
store.inspectSource = function (it) {
|
|
8
8
|
return functionToString.call(it);
|
|
@@ -34,7 +34,8 @@ var NEW_ITERATOR_PROTOTYPE = IteratorPrototype == undefined || fails(function ()
|
|
|
34
34
|
|
|
35
35
|
if (NEW_ITERATOR_PROTOTYPE) IteratorPrototype = {};
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// `%IteratorPrototype%[@@iterator]()` method
|
|
38
|
+
// https://tc39.es/ecma262/#sec-%iteratorprototype%-@@iterator
|
|
38
39
|
if ((!IS_PURE || NEW_ITERATOR_PROTOTYPE) && !has(IteratorPrototype, ITERATOR)) {
|
|
39
40
|
createNonEnumerableProperty(IteratorPrototype, ITERATOR, returnThis);
|
|
40
41
|
}
|
|
@@ -4,8 +4,10 @@ var fails = require('../internals/fails');
|
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
|
|
6
6
|
module.exports = !!Object.getOwnPropertySymbols && !fails(function () {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
var symbol = Symbol();
|
|
8
|
+
// Chrome 38 Symbol has incorrect toString conversion
|
|
9
|
+
// `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
|
|
10
|
+
return !String(symbol) || !(Object(symbol) instanceof Symbol) ||
|
|
9
11
|
// Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
|
|
10
12
|
!Symbol.sham && V8_VERSION && V8_VERSION < 41;
|
|
11
13
|
});
|
|
@@ -12,7 +12,8 @@ var PromiseCapability = function (C) {
|
|
|
12
12
|
this.reject = aFunction(reject);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
//
|
|
15
|
+
// `NewPromiseCapability` abstract operation
|
|
16
|
+
// https://tc39.es/ecma262/#sec-newpromisecapability
|
|
16
17
|
module.exports.f = function (C) {
|
|
17
18
|
return new PromiseCapability(C);
|
|
18
19
|
};
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
var IS_PURE = require('../internals/is-pure');
|
|
3
3
|
var global = require('../internals/global');
|
|
4
4
|
var fails = require('../internals/fails');
|
|
5
|
+
var WEBKIT = require('../internals/engine-webkit-version');
|
|
5
6
|
|
|
6
7
|
// Forced replacement object prototype accessors methods
|
|
7
8
|
module.exports = IS_PURE || !fails(function () {
|
|
9
|
+
// This feature detection crashes old WebKit
|
|
10
|
+
// https://github.com/zloirock/core-js/issues/232
|
|
11
|
+
if (WEBKIT && WEBKIT < 535) return;
|
|
8
12
|
var key = Math.random();
|
|
9
13
|
// In FF throws only define methods
|
|
10
14
|
// eslint-disable-next-line no-undef, no-useless-call -- required for testing
|
package/internals/regexp-exec.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
/* eslint-disable regexp/no-assertion-capturing-group, regexp/no-empty-group, regexp/no-lazy-ends -- testing */
|
|
3
|
+
/* eslint-disable regexp/no-useless-quantifier -- testing */
|
|
2
4
|
var regexpFlags = require('./regexp-flags');
|
|
3
5
|
var stickyHelpers = require('./regexp-sticky-helpers');
|
|
4
6
|
var shared = require('./shared');
|
|
@@ -19,7 +21,6 @@ var UPDATES_LAST_INDEX_WRONG = (function () {
|
|
|
19
21
|
var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y || stickyHelpers.BROKEN_CARET;
|
|
20
22
|
|
|
21
23
|
// nonparticipating capturing group, copied from es5-shim's String#split patch.
|
|
22
|
-
// eslint-disable-next-line regexp/no-assertion-capturing-group, regexp/no-empty-group, regexp/no-lazy-ends -- testing
|
|
23
24
|
var NPCG_INCLUDED = /()??/.exec('')[1] !== undefined;
|
|
24
25
|
|
|
25
26
|
var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED || UNSUPPORTED_Y;
|
package/internals/shared.js
CHANGED
|
@@ -4,7 +4,7 @@ var store = require('../internals/shared-store');
|
|
|
4
4
|
(module.exports = function (key, value) {
|
|
5
5
|
return store[key] || (store[key] = value !== undefined ? value : {});
|
|
6
6
|
})('versions', []).push({
|
|
7
|
-
version: '3.
|
|
7
|
+
version: '3.14.0',
|
|
8
8
|
mode: IS_PURE ? 'pure' : 'global',
|
|
9
9
|
copyright: '© 2021 Denis Pushkarev (zloirock.ru)'
|
|
10
10
|
});
|
package/modules/es.array.sort.js
CHANGED
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
var $ = require('../internals/export');
|
|
3
3
|
var aFunction = require('../internals/a-function');
|
|
4
4
|
var toObject = require('../internals/to-object');
|
|
5
|
+
var toLength = require('../internals/to-length');
|
|
5
6
|
var fails = require('../internals/fails');
|
|
7
|
+
var internalSort = require('../internals/array-sort');
|
|
6
8
|
var arrayMethodIsStrict = require('../internals/array-method-is-strict');
|
|
9
|
+
var FF = require('../internals/engine-ff-version');
|
|
10
|
+
var IE_OR_EDGE = require('../internals/engine-is-ie-or-edge');
|
|
11
|
+
var V8 = require('../internals/engine-v8-version');
|
|
12
|
+
var WEBKIT = require('../internals/engine-webkit-version');
|
|
7
13
|
|
|
8
14
|
var test = [];
|
|
9
15
|
var nativeSort = test.sort;
|
|
@@ -19,14 +25,77 @@ var FAILS_ON_NULL = fails(function () {
|
|
|
19
25
|
// Old WebKit
|
|
20
26
|
var STRICT_METHOD = arrayMethodIsStrict('sort');
|
|
21
27
|
|
|
22
|
-
var
|
|
28
|
+
var STABLE_SORT = !fails(function () {
|
|
29
|
+
// feature detection can be too slow, so check engines versions
|
|
30
|
+
if (V8) return V8 < 70;
|
|
31
|
+
if (FF && FF > 3) return;
|
|
32
|
+
if (IE_OR_EDGE) return true;
|
|
33
|
+
if (WEBKIT) return WEBKIT < 603;
|
|
34
|
+
|
|
35
|
+
var result = '';
|
|
36
|
+
var code, chr, value, index;
|
|
37
|
+
|
|
38
|
+
// generate an array with more 512 elements (Chakra and old V8 fails only in this case)
|
|
39
|
+
for (code = 65; code < 76; code++) {
|
|
40
|
+
chr = String.fromCharCode(code);
|
|
41
|
+
|
|
42
|
+
switch (code) {
|
|
43
|
+
case 66: case 69: case 70: case 72: value = 3; break;
|
|
44
|
+
case 68: case 71: value = 4; break;
|
|
45
|
+
default: value = 2;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (index = 0; index < 47; index++) {
|
|
49
|
+
test.push({ k: chr + index, v: value });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
test.sort(function (a, b) { return b.v - a.v; });
|
|
54
|
+
|
|
55
|
+
for (index = 0; index < test.length; index++) {
|
|
56
|
+
chr = test[index].k.charAt(0);
|
|
57
|
+
if (result.charAt(result.length - 1) !== chr) result += chr;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return result !== 'DGBEFHACIJK';
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
var FORCED = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || !STRICT_METHOD || !STABLE_SORT;
|
|
64
|
+
|
|
65
|
+
var getSortCompare = function (comparefn) {
|
|
66
|
+
return function (x, y) {
|
|
67
|
+
if (y === undefined) return -1;
|
|
68
|
+
if (x === undefined) return 1;
|
|
69
|
+
if (comparefn !== undefined) return +comparefn(x, y) || 0;
|
|
70
|
+
return String(x) > String(y) ? 1 : -1;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
23
73
|
|
|
24
74
|
// `Array.prototype.sort` method
|
|
25
75
|
// https://tc39.es/ecma262/#sec-array.prototype.sort
|
|
26
76
|
$({ target: 'Array', proto: true, forced: FORCED }, {
|
|
27
77
|
sort: function sort(comparefn) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
78
|
+
if (comparefn !== undefined) aFunction(comparefn);
|
|
79
|
+
|
|
80
|
+
var array = toObject(this);
|
|
81
|
+
|
|
82
|
+
if (STABLE_SORT) return comparefn === undefined ? nativeSort.call(array) : nativeSort.call(array, comparefn);
|
|
83
|
+
|
|
84
|
+
var items = [];
|
|
85
|
+
var arrayLength = toLength(array.length);
|
|
86
|
+
var itemsLength, index;
|
|
87
|
+
|
|
88
|
+
for (index = 0; index < arrayLength; index++) {
|
|
89
|
+
if (index in array) items.push(array[index]);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
items = internalSort(items, getSortCompare(comparefn));
|
|
93
|
+
itemsLength = items.length;
|
|
94
|
+
index = 0;
|
|
95
|
+
|
|
96
|
+
while (index < itemsLength) array[index] = items[index++];
|
|
97
|
+
while (index < arrayLength) delete array[index++];
|
|
98
|
+
|
|
99
|
+
return array;
|
|
31
100
|
}
|
|
32
101
|
});
|
|
@@ -1,12 +1,86 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
|
|
3
|
+
var global = require('../internals/global');
|
|
4
|
+
var fails = require('../internals/fails');
|
|
5
|
+
var aFunction = require('../internals/a-function');
|
|
6
|
+
var toLength = require('../internals/to-length');
|
|
7
|
+
var internalSort = require('../internals/array-sort');
|
|
8
|
+
var FF = require('../internals/engine-ff-version');
|
|
9
|
+
var IE_OR_EDGE = require('../internals/engine-is-ie-or-edge');
|
|
10
|
+
var V8 = require('../internals/engine-v8-version');
|
|
11
|
+
var WEBKIT = require('../internals/engine-webkit-version');
|
|
3
12
|
|
|
4
13
|
var aTypedArray = ArrayBufferViewCore.aTypedArray;
|
|
5
14
|
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
|
|
6
|
-
var
|
|
15
|
+
var Uint16Array = global.Uint16Array;
|
|
16
|
+
var nativeSort = Uint16Array && Uint16Array.prototype.sort;
|
|
17
|
+
|
|
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 () {
|
|
26
|
+
// feature detection can be too slow, so check engines versions
|
|
27
|
+
if (V8) return V8 < 74;
|
|
28
|
+
if (FF) return FF < 67;
|
|
29
|
+
if (IE_OR_EDGE) return true;
|
|
30
|
+
if (WEBKIT) return WEBKIT < 602;
|
|
31
|
+
|
|
32
|
+
var array = new Uint16Array(516);
|
|
33
|
+
var expected = Array(516);
|
|
34
|
+
var index, mod;
|
|
35
|
+
|
|
36
|
+
for (index = 0; index < 516; index++) {
|
|
37
|
+
mod = index % 4;
|
|
38
|
+
array[index] = 515 - index;
|
|
39
|
+
expected[index] = index - 2 * mod + 3;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
array.sort(function (a, b) {
|
|
43
|
+
return (a / 4 | 0) - (b / 4 | 0);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
for (index = 0; index < 516; index++) {
|
|
47
|
+
if (array[index] !== expected[index]) return true;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
var getSortCompare = function (comparefn) {
|
|
52
|
+
return function (x, y) {
|
|
53
|
+
if (comparefn !== undefined) return +comparefn(x, y) || 0;
|
|
54
|
+
// eslint-disable-next-line no-self-compare -- NaN check
|
|
55
|
+
if (y !== y) return -1;
|
|
56
|
+
// eslint-disable-next-line no-self-compare -- NaN check
|
|
57
|
+
if (x !== x) return 1;
|
|
58
|
+
if (x === 0 && y === 0) return 1 / x > 0 && 1 / y < 0 ? 1 : -1;
|
|
59
|
+
return x > y;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
7
62
|
|
|
8
63
|
// `%TypedArray%.prototype.sort` method
|
|
9
64
|
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.sort
|
|
10
65
|
exportTypedArrayMethod('sort', function sort(comparefn) {
|
|
11
|
-
|
|
12
|
-
|
|
66
|
+
var array = this;
|
|
67
|
+
if (comparefn !== undefined) aFunction(comparefn);
|
|
68
|
+
if (STABLE_SORT) return nativeSort.call(array, comparefn);
|
|
69
|
+
|
|
70
|
+
aTypedArray(array);
|
|
71
|
+
var arrayLength = toLength(array.length);
|
|
72
|
+
var items = Array(arrayLength);
|
|
73
|
+
var index;
|
|
74
|
+
|
|
75
|
+
for (index = 0; index < arrayLength; index++) {
|
|
76
|
+
items[index] = array[index];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
items = internalSort(array, getSortCompare(comparefn));
|
|
80
|
+
|
|
81
|
+
for (index = 0; index < arrayLength; index++) {
|
|
82
|
+
array[index] = items[index];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return array;
|
|
86
|
+
}, !STABLE_SORT || ACCEPT_INCORRECT_ARGUMENTS);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "core-js",
|
|
3
3
|
"description": "Standard library",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.14.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/zloirock/core-js.git",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"scripts": {
|
|
56
56
|
"postinstall": "node -e \"try{require('./postinstall')}catch(e){}\""
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "e386f3de7760ee2910d07efb9d35029aa5dda93b"
|
|
59
59
|
}
|
package/stage/2.js
CHANGED
package/stage/3.js
CHANGED