Skip to content

Commit

Permalink
split es.promise
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Feb 23, 2022
1 parent 1ebeeb2 commit e2e8a5f
Show file tree
Hide file tree
Showing 14 changed files with 508 additions and 373 deletions.
38 changes: 38 additions & 0 deletions packages/core-js-compat/src/data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -862,12 +862,24 @@ export const data = {
safari: '7.1',
rhino: '1.7.13',
},
// TODO: remove this module from `core-js@4` since it's split to below modules
'es.promise': {
// V8 6.6 has a serious bug
chrome: '67', // '51',
firefox: '69',
safari: '11.0',
},
'es.promise.constructor': {
// V8 6.6 has a serious bug
chrome: '67', // '51',
firefox: '69',
safari: '11.0',
},
'es.promise.all': {
chrome: '67',
firefox: '69',
safari: '11.0',
},
'es.promise.all-settled': {
chrome: '76',
firefox: '71',
Expand All @@ -878,6 +890,11 @@ export const data = {
firefox: '79',
safari: '14.0',
},
'es.promise.catch': {
chrome: '67',
firefox: '69',
safari: '11.0',
},
'es.promise.finally': {
// V8 6.6 has a serious bug
chrome: '67', // '63',
Expand All @@ -887,6 +904,21 @@ export const data = {
ios: '13.2.3', // need to clarify the patch release, >13.0.0 && <= 13.2.3
safari: '13.0.3', // need to clarify the patch release, >13.0.0 && <= 13.0.3
},
'es.promise.race': {
chrome: '67',
firefox: '69',
safari: '11.0',
},
'es.promise.reject': {
chrome: '67',
firefox: '69',
safari: '11.0',
},
'es.promise.resolve': {
chrome: '67',
firefox: '69',
safari: '11.0',
},
'es.reflect.apply': {
chrome: '49',
edge: '15',
Expand Down Expand Up @@ -1940,5 +1972,11 @@ data['esnext.promise.any'] = data['es.promise.any'];
data['esnext.string.match-all'] = data['es.string.match-all'];
data['esnext.string.replace-all'] = data['es.string.replace-all'];
data['esnext.typed-array.at'] = data['es.typed-array.at'];
delete data['es.promise.constructor'];
delete data['es.promise.all'];
delete data['es.promise.catch'];
delete data['es.promise.race'];
delete data['es.promise.reject'];
delete data['es.promise.resolve'];

export const modules = Object.keys(data);
5 changes: 5 additions & 0 deletions packages/core-js/internals/promise-catch-implementation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// `Promise.prototype.catch` method implementation
// https://tc39.es/ecma262/#sec-promise.prototype.catch
module.exports = function (onRejected) {
return this.then(undefined, onRejected);
};
39 changes: 39 additions & 0 deletions packages/core-js/modules/es.promise.all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';
var $ = require('../internals/export');
var call = require('../internals/function-call');
var aCallable = require('../internals/a-callable');
var newPromiseCapabilityModule = require('../internals/new-promise-capability');
var perform = require('../internals/perform');
var iterate = require('../internals/iterate');
var PROMISE_STATICS_INCORRECT_ITERATION = require('../internals/promise-statics-incorrect-iteration');

// `Promise.all` method
// https://tc39.es/ecma262/#sec-promise.all
$({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION }, {
all: function all(iterable) {
var C = this;
var capability = newPromiseCapabilityModule.f(C);
var resolve = capability.resolve;
var reject = capability.reject;
var result = perform(function () {
var $promiseResolve = aCallable(C.resolve);
var values = [];
var counter = 0;
var remaining = 1;
iterate(iterable, function (promise) {
var index = counter++;
var alreadyCalled = false;
remaining++;
call($promiseResolve, C, promise).then(function (value) {
if (alreadyCalled) return;
alreadyCalled = true;
values[index] = value;
--remaining || resolve(values);
}, reject);
});
--remaining || resolve(values);
});
if (result.error) reject(result.value);
return capability.promise;
}
});
2 changes: 1 addition & 1 deletion packages/core-js/modules/es.promise.any.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
var $ = require('../internals/export');
var call = require('../internals/function-call');
var aCallable = require('../internals/a-callable');
var getBuiltIn = require('../internals/get-built-in');
var call = require('../internals/function-call');
var newPromiseCapabilityModule = require('../internals/new-promise-capability');
var perform = require('../internals/perform');
var iterate = require('../internals/iterate');
Expand Down
10 changes: 10 additions & 0 deletions packages/core-js/modules/es.promise.catch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
var $ = require('../internals/export');
var promiseCatchImplementation = require('../internals/promise-catch-implementation');
var FORCED_PROMISE_CONSTRUCTOR = require('../internals/promise-constructor-detection').CONSTRUCTOR;

// `Promise.prototype.catch` method
// https://tc39.es/ecma262/#sec-promise.prototype.catch
$({ target: 'Promise', proto: true, forced: FORCED_PROMISE_CONSTRUCTOR, real: true }, {
'catch': promiseCatchImplementation
});
Loading

0 comments on commit e2e8a5f

Please sign in to comment.