core-js 3.6.2 → 3.7.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/es/aggregate-error.js +6 -0
- package/es/index.js +33 -29
- package/es/object/index.js +2 -1
- package/es/object/to-string.js +3 -2
- package/es/promise/any.js +12 -0
- package/es/promise/index.js +4 -2
- package/es/reflect/index.js +1 -0
- package/es/reflect/to-string-tag.js +3 -0
- package/es/string/index.js +1 -0
- package/es/string/replace-all.js +4 -0
- package/es/string/virtual/index.js +1 -0
- package/es/string/virtual/replace-all.js +4 -0
- package/es/symbol/index.js +2 -1
- package/es/symbol/to-string-tag.js +2 -1
- package/features/aggregate-error.js +4 -4
- package/features/map/emplace.js +5 -0
- package/features/map/index.js +2 -0
- package/features/promise/any.js +4 -9
- package/features/reflect/to-string-tag.js +3 -0
- package/features/string/replace-all.js +4 -2
- package/features/string/virtual/replace-all.js +4 -2
- package/features/weak-map/emplace.js +5 -0
- package/features/weak-map/index.js +2 -0
- package/internals/array-last-index-of.js +2 -1
- package/internals/array-method-uses-to-length.js +5 -8
- package/internals/async-iterator-iteration.js +25 -6
- package/internals/call-with-safe-iteration-closing.js +2 -2
- package/internals/collection-from.js +5 -5
- package/internals/collection-strong.js +1 -1
- package/internals/collection-weak.js +1 -1
- package/internals/collection.js +1 -1
- package/internals/correct-is-regexp-logic.js +2 -2
- package/internals/engine-is-node.js +4 -0
- package/internals/fix-regexp-well-known-symbol-logic.js +18 -2
- package/internals/global.js +1 -1
- package/internals/internal-state.js +4 -1
- package/internals/iterate.js +26 -11
- package/internals/iterator-close.js +8 -0
- package/internals/map-emplace.js +13 -0
- package/internals/microtask.js +8 -8
- package/internals/redefine.js +8 -2
- package/internals/shared.js +1 -1
- package/internals/task.js +9 -3
- package/modules/es.aggregate-error.js +31 -0
- package/modules/es.array.reduce-right.js +8 -2
- package/modules/es.array.reduce.js +6 -1
- package/modules/es.object.from-entries.js +1 -1
- package/modules/es.promise.all-settled.js +2 -2
- package/modules/es.promise.any.js +46 -0
- package/modules/es.promise.js +27 -25
- package/modules/es.reflect.set.js +3 -2
- package/modules/es.reflect.to-string-tag.js +9 -0
- package/modules/es.string.replace-all.js +50 -0
- package/modules/es.string.replace.js +8 -1
- package/modules/esnext.aggregate-error.js +2 -45
- package/modules/esnext.async-iterator.take.js +12 -3
- package/modules/esnext.iterator.every.js +3 -3
- package/modules/esnext.iterator.find.js +3 -3
- package/modules/esnext.iterator.flat-map.js +21 -15
- package/modules/esnext.iterator.for-each.js +1 -1
- package/modules/esnext.iterator.reduce.js +1 -1
- package/modules/esnext.iterator.some.js +3 -3
- package/modules/esnext.iterator.take.js +4 -2
- package/modules/esnext.iterator.to-array.js +1 -1
- package/modules/esnext.map.emplace.js +10 -0
- package/modules/esnext.map.every.js +3 -3
- package/modules/esnext.map.filter.js +1 -1
- package/modules/esnext.map.find-key.js +3 -3
- package/modules/esnext.map.find.js +3 -3
- package/modules/esnext.map.includes.js +3 -3
- package/modules/esnext.map.key-of.js +3 -3
- package/modules/esnext.map.map-keys.js +1 -1
- package/modules/esnext.map.map-values.js +1 -1
- package/modules/esnext.map.merge.js +1 -1
- package/modules/esnext.map.reduce.js +1 -1
- package/modules/esnext.map.some.js +3 -3
- package/modules/esnext.map.update-or-insert.js +1 -1
- package/modules/esnext.map.upsert.js +2 -1
- package/modules/esnext.observable.js +3 -3
- package/modules/esnext.promise.any.js +2 -46
- package/modules/esnext.reflect.get-metadata-keys.js +1 -1
- package/modules/esnext.set.every.js +3 -3
- package/modules/esnext.set.filter.js +1 -1
- package/modules/esnext.set.find.js +3 -3
- package/modules/esnext.set.is-disjoint-from.js +3 -3
- package/modules/esnext.set.is-subset-of.js +3 -3
- package/modules/esnext.set.is-superset-of.js +3 -3
- package/modules/esnext.set.join.js +1 -1
- package/modules/esnext.set.map.js +1 -1
- package/modules/esnext.set.reduce.js +1 -1
- package/modules/esnext.set.some.js +3 -3
- package/modules/esnext.set.union.js +1 -1
- package/modules/esnext.string.replace-all.js +2 -50
- package/modules/esnext.weak-map.emplace.js +10 -0
- package/modules/esnext.weak-map.upsert.js +3 -2
- package/modules/web.queue-microtask.js +2 -3
- package/modules/web.url-search-params.js +1 -1
- package/modules/web.url.js +1 -1
- package/package.json +1 -1
- package/postinstall.js +3 -1
- package/proposals/efficient-64-bit-arithmetic.js +1 -0
- package/proposals/map-upsert.js +4 -0
- package/proposals/object-iteration.js +1 -0
- package/stable/aggregate-error.js +6 -0
- package/stable/promise/any.js +3 -0
- package/stable/reflect/to-string-tag.js +3 -0
- package/stable/string/replace-all.js +3 -0
- package/stable/string/virtual/replace-all.js +3 -0
- package/stage/3.js +0 -2
- package/stage/4.js +2 -0
package/internals/iterate.js
CHANGED
|
@@ -3,17 +3,33 @@ var isArrayIteratorMethod = require('../internals/is-array-iterator-method');
|
|
|
3
3
|
var toLength = require('../internals/to-length');
|
|
4
4
|
var bind = require('../internals/function-bind-context');
|
|
5
5
|
var getIteratorMethod = require('../internals/get-iterator-method');
|
|
6
|
-
var
|
|
6
|
+
var iteratorClose = require('../internals/iterator-close');
|
|
7
7
|
|
|
8
8
|
var Result = function (stopped, result) {
|
|
9
9
|
this.stopped = stopped;
|
|
10
10
|
this.result = result;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
var
|
|
13
|
+
module.exports = function (iterable, unboundFunction, options) {
|
|
14
|
+
var that = options && options.that;
|
|
15
|
+
var AS_ENTRIES = !!(options && options.AS_ENTRIES);
|
|
16
|
+
var IS_ITERATOR = !!(options && options.IS_ITERATOR);
|
|
17
|
+
var INTERRUPTED = !!(options && options.INTERRUPTED);
|
|
18
|
+
var fn = bind(unboundFunction, that, 1 + AS_ENTRIES + INTERRUPTED);
|
|
15
19
|
var iterator, iterFn, index, length, result, next, step;
|
|
16
20
|
|
|
21
|
+
var stop = function (condition) {
|
|
22
|
+
if (iterator) iteratorClose(iterator);
|
|
23
|
+
return new Result(true, condition);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
var callFn = function (value) {
|
|
27
|
+
if (AS_ENTRIES) {
|
|
28
|
+
anObject(value);
|
|
29
|
+
return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]);
|
|
30
|
+
} return INTERRUPTED ? fn(value, stop) : fn(value);
|
|
31
|
+
};
|
|
32
|
+
|
|
17
33
|
if (IS_ITERATOR) {
|
|
18
34
|
iterator = iterable;
|
|
19
35
|
} else {
|
|
@@ -22,9 +38,7 @@ var iterate = module.exports = function (iterable, fn, that, AS_ENTRIES, IS_ITER
|
|
|
22
38
|
// optimisation for array iterators
|
|
23
39
|
if (isArrayIteratorMethod(iterFn)) {
|
|
24
40
|
for (index = 0, length = toLength(iterable.length); length > index; index++) {
|
|
25
|
-
result =
|
|
26
|
-
? boundFunction(anObject(step = iterable[index])[0], step[1])
|
|
27
|
-
: boundFunction(iterable[index]);
|
|
41
|
+
result = callFn(iterable[index]);
|
|
28
42
|
if (result && result instanceof Result) return result;
|
|
29
43
|
} return new Result(false);
|
|
30
44
|
}
|
|
@@ -33,11 +47,12 @@ var iterate = module.exports = function (iterable, fn, that, AS_ENTRIES, IS_ITER
|
|
|
33
47
|
|
|
34
48
|
next = iterator.next;
|
|
35
49
|
while (!(step = next.call(iterator)).done) {
|
|
36
|
-
|
|
50
|
+
try {
|
|
51
|
+
result = callFn(step.value);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
iteratorClose(iterator);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
37
56
|
if (typeof result == 'object' && result && result instanceof Result) return result;
|
|
38
57
|
} return new Result(false);
|
|
39
58
|
};
|
|
40
|
-
|
|
41
|
-
iterate.stop = function (result) {
|
|
42
|
-
return new Result(true, result);
|
|
43
|
-
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var anObject = require('../internals/an-object');
|
|
3
|
+
|
|
4
|
+
// `Map.prototype.emplace` method
|
|
5
|
+
// https://github.com/thumbsupep/proposal-upsert
|
|
6
|
+
module.exports = function emplace(key, handler) {
|
|
7
|
+
var map = anObject(this);
|
|
8
|
+
var value = (map.has(key) && 'update' in handler)
|
|
9
|
+
? handler.update(map.get(key), key, map)
|
|
10
|
+
: handler.insert(key, map);
|
|
11
|
+
map.set(key, value);
|
|
12
|
+
return value;
|
|
13
|
+
};
|
package/internals/microtask.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
var global = require('../internals/global');
|
|
2
2
|
var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
|
|
3
|
-
var classof = require('../internals/classof-raw');
|
|
4
3
|
var macrotask = require('../internals/task').set;
|
|
5
4
|
var IS_IOS = require('../internals/engine-is-ios');
|
|
5
|
+
var IS_NODE = require('../internals/engine-is-node');
|
|
6
6
|
|
|
7
7
|
var MutationObserver = global.MutationObserver || global.WebKitMutationObserver;
|
|
8
|
+
var document = global.document;
|
|
8
9
|
var process = global.process;
|
|
9
10
|
var Promise = global.Promise;
|
|
10
|
-
var IS_NODE = classof(process) == 'process';
|
|
11
11
|
// Node.js 11 shows ExperimentalWarning on getting `queueMicrotask`
|
|
12
12
|
var queueMicrotaskDescriptor = getOwnPropertyDescriptor(global, 'queueMicrotask');
|
|
13
13
|
var queueMicrotask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value;
|
|
@@ -33,13 +33,8 @@ if (!queueMicrotask) {
|
|
|
33
33
|
if (parent) parent.enter();
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
// Node.js
|
|
37
|
-
if (IS_NODE) {
|
|
38
|
-
notify = function () {
|
|
39
|
-
process.nextTick(flush);
|
|
40
|
-
};
|
|
41
36
|
// browsers with MutationObserver, except iOS - https://github.com/zloirock/core-js/issues/339
|
|
42
|
-
|
|
37
|
+
if (!IS_IOS && !IS_NODE && MutationObserver && document) {
|
|
43
38
|
toggle = true;
|
|
44
39
|
node = document.createTextNode('');
|
|
45
40
|
new MutationObserver(flush).observe(node, { characterData: true });
|
|
@@ -54,6 +49,11 @@ if (!queueMicrotask) {
|
|
|
54
49
|
notify = function () {
|
|
55
50
|
then.call(promise, flush);
|
|
56
51
|
};
|
|
52
|
+
// Node.js without promises
|
|
53
|
+
} else if (IS_NODE) {
|
|
54
|
+
notify = function () {
|
|
55
|
+
process.nextTick(flush);
|
|
56
|
+
};
|
|
57
57
|
// for other environments - macrotask based on:
|
|
58
58
|
// - setImmediate
|
|
59
59
|
// - MessageChannel
|
package/internals/redefine.js
CHANGED
|
@@ -13,9 +13,15 @@ var TEMPLATE = String(String).split('String');
|
|
|
13
13
|
var unsafe = options ? !!options.unsafe : false;
|
|
14
14
|
var simple = options ? !!options.enumerable : false;
|
|
15
15
|
var noTargetGet = options ? !!options.noTargetGet : false;
|
|
16
|
+
var state;
|
|
16
17
|
if (typeof value == 'function') {
|
|
17
|
-
if (typeof key == 'string' && !has(value, 'name'))
|
|
18
|
-
|
|
18
|
+
if (typeof key == 'string' && !has(value, 'name')) {
|
|
19
|
+
createNonEnumerableProperty(value, 'name', key);
|
|
20
|
+
}
|
|
21
|
+
state = enforceInternalState(value);
|
|
22
|
+
if (!state.source) {
|
|
23
|
+
state.source = TEMPLATE.join(typeof key == 'string' ? key : '');
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
if (O === global) {
|
|
21
27
|
if (simple) O[key] = value;
|
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.7.0',
|
|
8
8
|
mode: IS_PURE ? 'pure' : 'global',
|
|
9
9
|
copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
|
|
10
10
|
});
|
package/internals/task.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var global = require('../internals/global');
|
|
2
2
|
var fails = require('../internals/fails');
|
|
3
|
-
var classof = require('../internals/classof-raw');
|
|
4
3
|
var bind = require('../internals/function-bind-context');
|
|
5
4
|
var html = require('../internals/html');
|
|
6
5
|
var createElement = require('../internals/document-create-element');
|
|
7
6
|
var IS_IOS = require('../internals/engine-is-ios');
|
|
7
|
+
var IS_NODE = require('../internals/engine-is-node');
|
|
8
8
|
|
|
9
9
|
var location = global.location;
|
|
10
10
|
var set = global.setImmediate;
|
|
@@ -58,7 +58,7 @@ if (!set || !clear) {
|
|
|
58
58
|
delete queue[id];
|
|
59
59
|
};
|
|
60
60
|
// Node.js 0.8-
|
|
61
|
-
if (
|
|
61
|
+
if (IS_NODE) {
|
|
62
62
|
defer = function (id) {
|
|
63
63
|
process.nextTick(runner(id));
|
|
64
64
|
};
|
|
@@ -76,7 +76,13 @@ if (!set || !clear) {
|
|
|
76
76
|
defer = bind(port.postMessage, port, 1);
|
|
77
77
|
// Browsers with postMessage, skip WebWorkers
|
|
78
78
|
// IE8 has postMessage, but it's sync & typeof its postMessage is 'object'
|
|
79
|
-
} else if (
|
|
79
|
+
} else if (
|
|
80
|
+
global.addEventListener &&
|
|
81
|
+
typeof postMessage == 'function' &&
|
|
82
|
+
!global.importScripts &&
|
|
83
|
+
location && location.protocol !== 'file:' &&
|
|
84
|
+
!fails(post)
|
|
85
|
+
) {
|
|
80
86
|
defer = post;
|
|
81
87
|
global.addEventListener('message', listener, false);
|
|
82
88
|
// IE8-
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var $ = require('../internals/export');
|
|
3
|
+
var getPrototypeOf = require('../internals/object-get-prototype-of');
|
|
4
|
+
var setPrototypeOf = require('../internals/object-set-prototype-of');
|
|
5
|
+
var create = require('../internals/object-create');
|
|
6
|
+
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
|
7
|
+
var createPropertyDescriptor = require('../internals/create-property-descriptor');
|
|
8
|
+
var iterate = require('../internals/iterate');
|
|
9
|
+
|
|
10
|
+
var $AggregateError = function AggregateError(errors, message) {
|
|
11
|
+
var that = this;
|
|
12
|
+
if (!(that instanceof $AggregateError)) return new $AggregateError(errors, message);
|
|
13
|
+
if (setPrototypeOf) {
|
|
14
|
+
that = setPrototypeOf(new Error(undefined), getPrototypeOf(that));
|
|
15
|
+
}
|
|
16
|
+
if (message !== undefined) createNonEnumerableProperty(that, 'message', String(message));
|
|
17
|
+
var errorsArray = [];
|
|
18
|
+
iterate(errors, errorsArray.push, { that: errorsArray });
|
|
19
|
+
createNonEnumerableProperty(that, 'errors', errorsArray);
|
|
20
|
+
return that;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
$AggregateError.prototype = create(Error.prototype, {
|
|
24
|
+
constructor: createPropertyDescriptor(5, $AggregateError),
|
|
25
|
+
message: createPropertyDescriptor(5, ''),
|
|
26
|
+
name: createPropertyDescriptor(5, 'AggregateError')
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
$({ global: true }, {
|
|
30
|
+
AggregateError: $AggregateError
|
|
31
|
+
});
|
|
@@ -3,13 +3,19 @@ var $ = require('../internals/export');
|
|
|
3
3
|
var $reduceRight = require('../internals/array-reduce').right;
|
|
4
4
|
var arrayMethodIsStrict = require('../internals/array-method-is-strict');
|
|
5
5
|
var arrayMethodUsesToLength = require('../internals/array-method-uses-to-length');
|
|
6
|
+
var CHROME_VERSION = require('../internals/engine-v8-version');
|
|
7
|
+
var IS_NODE = require('../internals/engine-is-node');
|
|
6
8
|
|
|
7
9
|
var STRICT_METHOD = arrayMethodIsStrict('reduceRight');
|
|
8
|
-
|
|
10
|
+
// For preventing possible almost infinite loop in non-standard implementations, test the forward version of the method
|
|
11
|
+
var USES_TO_LENGTH = arrayMethodUsesToLength('reduce', { 1: 0 });
|
|
12
|
+
// Chrome 80-82 has a critical bug
|
|
13
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=1049982
|
|
14
|
+
var CHROME_BUG = !IS_NODE && CHROME_VERSION > 79 && CHROME_VERSION < 83;
|
|
9
15
|
|
|
10
16
|
// `Array.prototype.reduceRight` method
|
|
11
17
|
// https://tc39.github.io/ecma262/#sec-array.prototype.reduceright
|
|
12
|
-
$({ target: 'Array', proto: true, forced: !STRICT_METHOD || !USES_TO_LENGTH }, {
|
|
18
|
+
$({ target: 'Array', proto: true, forced: !STRICT_METHOD || !USES_TO_LENGTH || CHROME_BUG }, {
|
|
13
19
|
reduceRight: function reduceRight(callbackfn /* , initialValue */) {
|
|
14
20
|
return $reduceRight(this, callbackfn, arguments.length, arguments.length > 1 ? arguments[1] : undefined);
|
|
15
21
|
}
|
|
@@ -3,13 +3,18 @@ var $ = require('../internals/export');
|
|
|
3
3
|
var $reduce = require('../internals/array-reduce').left;
|
|
4
4
|
var arrayMethodIsStrict = require('../internals/array-method-is-strict');
|
|
5
5
|
var arrayMethodUsesToLength = require('../internals/array-method-uses-to-length');
|
|
6
|
+
var CHROME_VERSION = require('../internals/engine-v8-version');
|
|
7
|
+
var IS_NODE = require('../internals/engine-is-node');
|
|
6
8
|
|
|
7
9
|
var STRICT_METHOD = arrayMethodIsStrict('reduce');
|
|
8
10
|
var USES_TO_LENGTH = arrayMethodUsesToLength('reduce', { 1: 0 });
|
|
11
|
+
// Chrome 80-82 has a critical bug
|
|
12
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=1049982
|
|
13
|
+
var CHROME_BUG = !IS_NODE && CHROME_VERSION > 79 && CHROME_VERSION < 83;
|
|
9
14
|
|
|
10
15
|
// `Array.prototype.reduce` method
|
|
11
16
|
// https://tc39.github.io/ecma262/#sec-array.prototype.reduce
|
|
12
|
-
$({ target: 'Array', proto: true, forced: !STRICT_METHOD || !USES_TO_LENGTH }, {
|
|
17
|
+
$({ target: 'Array', proto: true, forced: !STRICT_METHOD || !USES_TO_LENGTH || CHROME_BUG }, {
|
|
13
18
|
reduce: function reduce(callbackfn /* , initialValue */) {
|
|
14
19
|
return $reduce(this, callbackfn, arguments.length, arguments.length > 1 ? arguments[1] : undefined);
|
|
15
20
|
}
|
|
@@ -28,10 +28,10 @@ $({ target: 'Promise', stat: true }, {
|
|
|
28
28
|
alreadyCalled = true;
|
|
29
29
|
values[index] = { status: 'fulfilled', value: value };
|
|
30
30
|
--remaining || resolve(values);
|
|
31
|
-
}, function (
|
|
31
|
+
}, function (error) {
|
|
32
32
|
if (alreadyCalled) return;
|
|
33
33
|
alreadyCalled = true;
|
|
34
|
-
values[index] = { status: 'rejected', reason:
|
|
34
|
+
values[index] = { status: 'rejected', reason: error };
|
|
35
35
|
--remaining || resolve(values);
|
|
36
36
|
});
|
|
37
37
|
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var $ = require('../internals/export');
|
|
3
|
+
var aFunction = require('../internals/a-function');
|
|
4
|
+
var getBuiltIn = require('../internals/get-built-in');
|
|
5
|
+
var newPromiseCapabilityModule = require('../internals/new-promise-capability');
|
|
6
|
+
var perform = require('../internals/perform');
|
|
7
|
+
var iterate = require('../internals/iterate');
|
|
8
|
+
|
|
9
|
+
var PROMISE_ANY_ERROR = 'No one promise resolved';
|
|
10
|
+
|
|
11
|
+
// `Promise.any` method
|
|
12
|
+
// https://github.com/tc39/proposal-promise-any
|
|
13
|
+
$({ target: 'Promise', stat: true }, {
|
|
14
|
+
any: function any(iterable) {
|
|
15
|
+
var C = this;
|
|
16
|
+
var capability = newPromiseCapabilityModule.f(C);
|
|
17
|
+
var resolve = capability.resolve;
|
|
18
|
+
var reject = capability.reject;
|
|
19
|
+
var result = perform(function () {
|
|
20
|
+
var promiseResolve = aFunction(C.resolve);
|
|
21
|
+
var errors = [];
|
|
22
|
+
var counter = 0;
|
|
23
|
+
var remaining = 1;
|
|
24
|
+
var alreadyResolved = false;
|
|
25
|
+
iterate(iterable, function (promise) {
|
|
26
|
+
var index = counter++;
|
|
27
|
+
var alreadyRejected = false;
|
|
28
|
+
errors.push(undefined);
|
|
29
|
+
remaining++;
|
|
30
|
+
promiseResolve.call(C, promise).then(function (value) {
|
|
31
|
+
if (alreadyRejected || alreadyResolved) return;
|
|
32
|
+
alreadyResolved = true;
|
|
33
|
+
resolve(value);
|
|
34
|
+
}, function (error) {
|
|
35
|
+
if (alreadyRejected || alreadyResolved) return;
|
|
36
|
+
alreadyRejected = true;
|
|
37
|
+
errors[index] = error;
|
|
38
|
+
--remaining || reject(new (getBuiltIn('AggregateError'))(errors, PROMISE_ANY_ERROR));
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
--remaining || reject(new (getBuiltIn('AggregateError'))(errors, PROMISE_ANY_ERROR));
|
|
42
|
+
});
|
|
43
|
+
if (result.error) reject(result.value);
|
|
44
|
+
return capability.promise;
|
|
45
|
+
}
|
|
46
|
+
});
|
package/modules/es.promise.js
CHANGED
|
@@ -11,7 +11,6 @@ var setSpecies = require('../internals/set-species');
|
|
|
11
11
|
var isObject = require('../internals/is-object');
|
|
12
12
|
var aFunction = require('../internals/a-function');
|
|
13
13
|
var anInstance = require('../internals/an-instance');
|
|
14
|
-
var classof = require('../internals/classof-raw');
|
|
15
14
|
var inspectSource = require('../internals/inspect-source');
|
|
16
15
|
var iterate = require('../internals/iterate');
|
|
17
16
|
var checkCorrectnessOfIteration = require('../internals/check-correctness-of-iteration');
|
|
@@ -25,6 +24,7 @@ var perform = require('../internals/perform');
|
|
|
25
24
|
var InternalStateModule = require('../internals/internal-state');
|
|
26
25
|
var isForced = require('../internals/is-forced');
|
|
27
26
|
var wellKnownSymbol = require('../internals/well-known-symbol');
|
|
27
|
+
var IS_NODE = require('../internals/engine-is-node');
|
|
28
28
|
var V8_VERSION = require('../internals/engine-v8-version');
|
|
29
29
|
|
|
30
30
|
var SPECIES = wellKnownSymbol('species');
|
|
@@ -39,8 +39,8 @@ var process = global.process;
|
|
|
39
39
|
var $fetch = getBuiltIn('fetch');
|
|
40
40
|
var newPromiseCapability = newPromiseCapabilityModule.f;
|
|
41
41
|
var newGenericPromiseCapability = newPromiseCapability;
|
|
42
|
-
var IS_NODE = classof(process) == 'process';
|
|
43
42
|
var DISPATCH_EVENT = !!(document && document.createEvent && global.dispatchEvent);
|
|
43
|
+
var NATIVE_REJECTION_EVENT = typeof PromiseRejectionEvent == 'function';
|
|
44
44
|
var UNHANDLED_REJECTION = 'unhandledrejection';
|
|
45
45
|
var REJECTION_HANDLED = 'rejectionhandled';
|
|
46
46
|
var PENDING = 0;
|
|
@@ -58,7 +58,7 @@ var FORCED = isForced(PROMISE, function () {
|
|
|
58
58
|
// We can't detect it synchronously, so just check versions
|
|
59
59
|
if (V8_VERSION === 66) return true;
|
|
60
60
|
// Unhandled rejections tracking support, NodeJS Promise without it fails @@species test
|
|
61
|
-
if (!IS_NODE &&
|
|
61
|
+
if (!IS_NODE && !NATIVE_REJECTION_EVENT) return true;
|
|
62
62
|
}
|
|
63
63
|
// We need Promise#finally in the pure version for preventing prototype pollution
|
|
64
64
|
if (IS_PURE && !PromiseConstructor.prototype['finally']) return true;
|
|
@@ -86,7 +86,7 @@ var isThenable = function (it) {
|
|
|
86
86
|
return isObject(it) && typeof (then = it.then) == 'function' ? then : false;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
var notify = function (
|
|
89
|
+
var notify = function (state, isReject) {
|
|
90
90
|
if (state.notified) return;
|
|
91
91
|
state.notified = true;
|
|
92
92
|
var chain = state.reactions;
|
|
@@ -105,7 +105,7 @@ var notify = function (promise, state, isReject) {
|
|
|
105
105
|
try {
|
|
106
106
|
if (handler) {
|
|
107
107
|
if (!ok) {
|
|
108
|
-
if (state.rejection === UNHANDLED) onHandleUnhandled(
|
|
108
|
+
if (state.rejection === UNHANDLED) onHandleUnhandled(state);
|
|
109
109
|
state.rejection = HANDLED;
|
|
110
110
|
}
|
|
111
111
|
if (handler === true) result = value;
|
|
@@ -130,7 +130,7 @@ var notify = function (promise, state, isReject) {
|
|
|
130
130
|
}
|
|
131
131
|
state.reactions = [];
|
|
132
132
|
state.notified = false;
|
|
133
|
-
if (isReject && !state.rejection) onUnhandled(
|
|
133
|
+
if (isReject && !state.rejection) onUnhandled(state);
|
|
134
134
|
});
|
|
135
135
|
};
|
|
136
136
|
|
|
@@ -143,12 +143,13 @@ var dispatchEvent = function (name, promise, reason) {
|
|
|
143
143
|
event.initEvent(name, false, true);
|
|
144
144
|
global.dispatchEvent(event);
|
|
145
145
|
} else event = { promise: promise, reason: reason };
|
|
146
|
-
if (handler = global['on' + name]) handler(event);
|
|
146
|
+
if (!NATIVE_REJECTION_EVENT && (handler = global['on' + name])) handler(event);
|
|
147
147
|
else if (name === UNHANDLED_REJECTION) hostReportErrors('Unhandled promise rejection', reason);
|
|
148
148
|
};
|
|
149
149
|
|
|
150
|
-
var onUnhandled = function (
|
|
150
|
+
var onUnhandled = function (state) {
|
|
151
151
|
task.call(global, function () {
|
|
152
|
+
var promise = state.facade;
|
|
152
153
|
var value = state.value;
|
|
153
154
|
var IS_UNHANDLED = isUnhandled(state);
|
|
154
155
|
var result;
|
|
@@ -169,55 +170,56 @@ var isUnhandled = function (state) {
|
|
|
169
170
|
return state.rejection !== HANDLED && !state.parent;
|
|
170
171
|
};
|
|
171
172
|
|
|
172
|
-
var onHandleUnhandled = function (
|
|
173
|
+
var onHandleUnhandled = function (state) {
|
|
173
174
|
task.call(global, function () {
|
|
175
|
+
var promise = state.facade;
|
|
174
176
|
if (IS_NODE) {
|
|
175
177
|
process.emit('rejectionHandled', promise);
|
|
176
178
|
} else dispatchEvent(REJECTION_HANDLED, promise, state.value);
|
|
177
179
|
});
|
|
178
180
|
};
|
|
179
181
|
|
|
180
|
-
var bind = function (fn,
|
|
182
|
+
var bind = function (fn, state, unwrap) {
|
|
181
183
|
return function (value) {
|
|
182
|
-
fn(
|
|
184
|
+
fn(state, value, unwrap);
|
|
183
185
|
};
|
|
184
186
|
};
|
|
185
187
|
|
|
186
|
-
var internalReject = function (
|
|
188
|
+
var internalReject = function (state, value, unwrap) {
|
|
187
189
|
if (state.done) return;
|
|
188
190
|
state.done = true;
|
|
189
191
|
if (unwrap) state = unwrap;
|
|
190
192
|
state.value = value;
|
|
191
193
|
state.state = REJECTED;
|
|
192
|
-
notify(
|
|
194
|
+
notify(state, true);
|
|
193
195
|
};
|
|
194
196
|
|
|
195
|
-
var internalResolve = function (
|
|
197
|
+
var internalResolve = function (state, value, unwrap) {
|
|
196
198
|
if (state.done) return;
|
|
197
199
|
state.done = true;
|
|
198
200
|
if (unwrap) state = unwrap;
|
|
199
201
|
try {
|
|
200
|
-
if (
|
|
202
|
+
if (state.facade === value) throw TypeError("Promise can't be resolved itself");
|
|
201
203
|
var then = isThenable(value);
|
|
202
204
|
if (then) {
|
|
203
205
|
microtask(function () {
|
|
204
206
|
var wrapper = { done: false };
|
|
205
207
|
try {
|
|
206
208
|
then.call(value,
|
|
207
|
-
bind(internalResolve,
|
|
208
|
-
bind(internalReject,
|
|
209
|
+
bind(internalResolve, wrapper, state),
|
|
210
|
+
bind(internalReject, wrapper, state)
|
|
209
211
|
);
|
|
210
212
|
} catch (error) {
|
|
211
|
-
internalReject(
|
|
213
|
+
internalReject(wrapper, error, state);
|
|
212
214
|
}
|
|
213
215
|
});
|
|
214
216
|
} else {
|
|
215
217
|
state.value = value;
|
|
216
218
|
state.state = FULFILLED;
|
|
217
|
-
notify(
|
|
219
|
+
notify(state, false);
|
|
218
220
|
}
|
|
219
221
|
} catch (error) {
|
|
220
|
-
internalReject(
|
|
222
|
+
internalReject({ done: false }, error, state);
|
|
221
223
|
}
|
|
222
224
|
};
|
|
223
225
|
|
|
@@ -230,9 +232,9 @@ if (FORCED) {
|
|
|
230
232
|
Internal.call(this);
|
|
231
233
|
var state = getInternalState(this);
|
|
232
234
|
try {
|
|
233
|
-
executor(bind(internalResolve,
|
|
235
|
+
executor(bind(internalResolve, state), bind(internalReject, state));
|
|
234
236
|
} catch (error) {
|
|
235
|
-
internalReject(
|
|
237
|
+
internalReject(state, error);
|
|
236
238
|
}
|
|
237
239
|
};
|
|
238
240
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -259,7 +261,7 @@ if (FORCED) {
|
|
|
259
261
|
reaction.domain = IS_NODE ? process.domain : undefined;
|
|
260
262
|
state.parent = true;
|
|
261
263
|
state.reactions.push(reaction);
|
|
262
|
-
if (state.state != PENDING) notify(
|
|
264
|
+
if (state.state != PENDING) notify(state, false);
|
|
263
265
|
return reaction.promise;
|
|
264
266
|
},
|
|
265
267
|
// `Promise.prototype.catch` method
|
|
@@ -272,8 +274,8 @@ if (FORCED) {
|
|
|
272
274
|
var promise = new Internal();
|
|
273
275
|
var state = getInternalState(promise);
|
|
274
276
|
this.promise = promise;
|
|
275
|
-
this.resolve = bind(internalResolve,
|
|
276
|
-
this.reject = bind(internalReject,
|
|
277
|
+
this.resolve = bind(internalResolve, state);
|
|
278
|
+
this.reject = bind(internalReject, state);
|
|
277
279
|
};
|
|
278
280
|
newPromiseCapabilityModule.f = newPromiseCapability = function (C) {
|
|
279
281
|
return C === PromiseConstructor || C === PromiseWrapper
|
|
@@ -35,9 +35,10 @@ function set(target, propertyKey, V /* , receiver */) {
|
|
|
35
35
|
// MS Edge 17-18 Reflect.set allows setting the property to object
|
|
36
36
|
// with non-writable property on the prototype
|
|
37
37
|
var MS_EDGE_BUG = fails(function () {
|
|
38
|
-
var
|
|
38
|
+
var Constructor = function () { /* empty */ };
|
|
39
|
+
var object = definePropertyModule.f(new Constructor(), 'a', { configurable: true });
|
|
39
40
|
// eslint-disable-next-line no-undef
|
|
40
|
-
return Reflect.set(
|
|
41
|
+
return Reflect.set(Constructor.prototype, 'a', 1, object) !== false;
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
$({ target: 'Reflect', stat: true, forced: MS_EDGE_BUG }, {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var $ = require('../internals/export');
|
|
2
|
+
var global = require('../internals/global');
|
|
3
|
+
var setToStringTag = require('../internals/set-to-string-tag');
|
|
4
|
+
|
|
5
|
+
$({ global: true }, { Reflect: {} });
|
|
6
|
+
|
|
7
|
+
// Reflect[@@toStringTag] property
|
|
8
|
+
// https://tc39.es/ecma262/#sec-reflect-@@tostringtag
|
|
9
|
+
setToStringTag(global.Reflect, 'Reflect', true);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var $ = require('../internals/export');
|
|
3
|
+
var requireObjectCoercible = require('../internals/require-object-coercible');
|
|
4
|
+
var isRegExp = require('../internals/is-regexp');
|
|
5
|
+
var getRegExpFlags = require('../internals/regexp-flags');
|
|
6
|
+
var wellKnownSymbol = require('../internals/well-known-symbol');
|
|
7
|
+
var IS_PURE = require('../internals/is-pure');
|
|
8
|
+
|
|
9
|
+
var REPLACE = wellKnownSymbol('replace');
|
|
10
|
+
var RegExpPrototype = RegExp.prototype;
|
|
11
|
+
|
|
12
|
+
// `String.prototype.replaceAll` method
|
|
13
|
+
// https://github.com/tc39/proposal-string-replace-all
|
|
14
|
+
$({ target: 'String', proto: true }, {
|
|
15
|
+
replaceAll: function replaceAll(searchValue, replaceValue) {
|
|
16
|
+
var O = requireObjectCoercible(this);
|
|
17
|
+
var IS_REG_EXP, flags, replacer, string, searchString, template, result, position, index;
|
|
18
|
+
if (searchValue != null) {
|
|
19
|
+
IS_REG_EXP = isRegExp(searchValue);
|
|
20
|
+
if (IS_REG_EXP) {
|
|
21
|
+
flags = String(requireObjectCoercible('flags' in RegExpPrototype
|
|
22
|
+
? searchValue.flags
|
|
23
|
+
: getRegExpFlags.call(searchValue)
|
|
24
|
+
));
|
|
25
|
+
if (!~flags.indexOf('g')) throw TypeError('`.replaceAll` does not allow non-global regexes');
|
|
26
|
+
}
|
|
27
|
+
replacer = searchValue[REPLACE];
|
|
28
|
+
if (replacer !== undefined) {
|
|
29
|
+
return replacer.call(searchValue, O, replaceValue);
|
|
30
|
+
} else if (IS_PURE && IS_REG_EXP) {
|
|
31
|
+
return String(O).replace(searchValue, replaceValue);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
string = String(O);
|
|
35
|
+
searchString = String(searchValue);
|
|
36
|
+
if (searchString === '') return replaceAll.call(string, /(?:)/g, replaceValue);
|
|
37
|
+
template = string.split(searchString);
|
|
38
|
+
if (typeof replaceValue !== 'function') {
|
|
39
|
+
return template.join(String(replaceValue));
|
|
40
|
+
}
|
|
41
|
+
result = template[0];
|
|
42
|
+
position = result.length;
|
|
43
|
+
for (index = 1; index < template.length; index++) {
|
|
44
|
+
result += String(replaceValue(searchString, position, string));
|
|
45
|
+
position += searchString.length + template[index].length;
|
|
46
|
+
result += template[index];
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
@@ -20,6 +20,10 @@ var maybeToString = function (it) {
|
|
|
20
20
|
|
|
21
21
|
// @@replace logic
|
|
22
22
|
fixRegExpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, maybeCallNative, reason) {
|
|
23
|
+
var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = reason.REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE;
|
|
24
|
+
var REPLACE_KEEPS_$0 = reason.REPLACE_KEEPS_$0;
|
|
25
|
+
var UNSAFE_SUBSTITUTE = REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE ? '$' : '$0';
|
|
26
|
+
|
|
23
27
|
return [
|
|
24
28
|
// `String.prototype.replace` method
|
|
25
29
|
// https://tc39.github.io/ecma262/#sec-string.prototype.replace
|
|
@@ -33,7 +37,10 @@ fixRegExpWellKnownSymbolLogic('replace', 2, function (REPLACE, nativeReplace, ma
|
|
|
33
37
|
// `RegExp.prototype[@@replace]` method
|
|
34
38
|
// https://tc39.github.io/ecma262/#sec-regexp.prototype-@@replace
|
|
35
39
|
function (regexp, replaceValue) {
|
|
36
|
-
if (
|
|
40
|
+
if (
|
|
41
|
+
(!REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE && REPLACE_KEEPS_$0) ||
|
|
42
|
+
(typeof replaceValue === 'string' && replaceValue.indexOf(UNSAFE_SUBSTITUTE) === -1)
|
|
43
|
+
) {
|
|
37
44
|
var res = maybeCallNative(nativeReplace, regexp, this, replaceValue);
|
|
38
45
|
if (res.done) return res.value;
|
|
39
46
|
}
|