move Promise.withResolvers to stable ES

This commit is contained in:
Denis Pushkarev
2023-11-28 04:20:09 +07:00
parent 14b398a3f0
commit f8306cdc79
16 changed files with 81 additions and 59 deletions
+5
View File
@@ -6,6 +6,11 @@
- `Map.groupBy` method
- Moved to stable ES, [November 2023 TC39 meeting](https://github.com/tc39/proposal-array-grouping/issues/60)
- Added `es.` namespace modules, `/es/` and `/stable/` namespaces entries
- [`Promise.withResolvers` proposal](https://github.com/tc39/proposal-promise-with-resolvers):
- Method:
- `Promise.withResolvers`
- Moved to stable ES, November 2023 TC39 meeting
- Added `es.` namespace module, `/es/` and `/stable/` namespaces entries
- Some minor `atob` / `btoa` improvements
- Compat data improvements:
- [`Promise.withResolvers`](https://github.com/tc39/proposal-promise-with-resolvers) marked as shipped from FF121
+22 -23
View File
@@ -148,6 +148,7 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
- [`Promise.allSettled`](#promiseallsettled)
- [`Promise.any`](#promiseany)
- [`Promise.prototype.finally`](#promiseprototypefinally)
- [`Promise.withResolvers`](#promisewithresolvers)
- [`Symbol.asyncIterator` for asynchronous iteration](#symbolasynciterator-for-asynchronous-iteration)
- [`Symbol.prototype.description`](#symbolprototypedescription)
- [Well-formed `JSON.stringify`](#well-formed-jsonstringify)
@@ -156,7 +157,6 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
- [`Iterator` helpers](#iterator-helpers)
- [`Array.fromAsync`](#arrayfromasync)
- [New `Set` methods](#new-set-methods)
- [`Promise.withResolvers`](#promisewithresolvers)
- [`JSON.parse` source text access](#jsonparse-source-text-access)
- [`Float16` methods](#float16-methods)
- [`ArrayBuffer.prototype.transfer` and friends](#arraybufferprototypetransfer-and-friends)
@@ -1143,19 +1143,20 @@ core-js(-pure)/es|stable|actual|full/date/to-primitive
new Date(NaN).toString(); // => 'Invalid Date'
```
#### ECMAScript: Promise[⬆](#index)
Modules [`es.promise`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.promise.js), [`es.promise.all-settled`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.promise.all-settled.js), [`es.promise.any`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.promise.any.js) and [`es.promise.finally`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.promise.finally.js).
Modules [`es.promise`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.promise.js), [`es.promise.all-settled`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.promise.all-settled.js), [`es.promise.any`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.promise.any.js), [`es.promise.finally`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.promise.finally.js) and [`es.promise.with-resolvers`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.promise.with-resolvers.js).
```js
class Promise {
constructor(executor: (resolve: Function, reject: Function) => void): Promise;
then(onFulfilled: Function, onRejected: Function): Promise;
catch(onRejected: Function): Promise;
finally(onFinally: Function): Promise;
static resolve(x: any): Promise;
static reject(r: any): Promise;
static all(iterable: Iterable): Promise;
static allSettled(iterable: Iterable): Promise;
static any(promises: Iterable): Promise;
static race(iterable: Iterable): Promise;
static reject(r: any): Promise;
static resolve(x: any): Promise;
static withResolvers(): { promise: Promise, resolve: function, reject: function };
}
```
[*CommonJS entry points:*](#commonjs-api)
@@ -1164,6 +1165,7 @@ core-js(-pure)/es|stable|actual|full/promise
core-js(-pure)/es|stable|actual|full/promise/all-settled
core-js(-pure)/es|stable|actual|full/promise/any
core-js(-pure)/es|stable|actual|full/promise/finally
core-js(-pure)/es|stable|actual|full/promise/with-resolvers
```
Basic [*example*](https://goo.gl/vGrtUC):
```js
@@ -1241,6 +1243,12 @@ Promise.any([
Promise.reject(3),
]).catch(({ errors }) => console.log(errors)); // => [1, 2, 3]
```
`Promise.withResolvers` [*examples*](https://tinyurl.com/2gx4t3xu):
```js
const d = Promise.withResolvers();
d.resolve(42);
d.promise.then(console.log); // => 42
```
[Example](https://goo.gl/wnQS4j) with async functions:
```js
let delay = time => new Promise(resolve => setTimeout(resolve, time))
@@ -2145,6 +2153,16 @@ class Promise {
```js
core-js/proposals/promise-finally
```
##### [`Promise.withResolvers`](https://github.com/tc39/proposal-promise-with-resolvers)[⬆](#index)
```js
class Promise {
static withResolvers(): { promise: Promise, resolve: function, reject: function };
}
```
[*CommonJS entry points:*](#commonjs-api)
```js
core-js/proposals/promise-with-resolvers
```
##### [`Symbol.asyncIterator` for asynchronous iteration](https://github.com/tc39/proposal-async-iteration)[⬆](#index)
```js
class Symbol {
@@ -2299,25 +2317,6 @@ new Set([1, 2, 3]).isSubsetOf(new Set([5, 4, 3, 2, 1])); // => true
new Set([5, 4, 3, 2, 1]).isSupersetOf(new Set([1, 2, 3])); // => true
```
##### [`Promise.withResolvers`](https://github.com/tc39/proposal-promise-with-resolvers)[⬆](#index)
Module [`esnext.promise.with-resolvers`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.promise.with-resolvers.js)
```js
class Promise {
static withResolvers(): { promise: Promise, resolve: function, reject: function };
}
```
[*CommonJS entry points:*](#commonjs-api)
```js
core-js/proposals/promise-with-resolvers
core-js(-pure)/actual|full/promise/with-resolvers
```
[*Examples*](https://tinyurl.com/2gx4t3xu):
```js
const d = Promise.withResolvers();
d.resolve(42);
d.promise.then(console.log); // => 42
```
##### [`JSON.parse` source text access](https://github.com/tc39/proposal-json-parse-with-source)[⬆](#index)
Modules [`esnext.json.is-raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.is-raw-json.js), [`esnext.json.parse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.parse.js), [`esnext.json.raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.raw-json.js).
```js
+8 -5
View File
@@ -1166,6 +1166,11 @@ export const data = {
rhino: '1.7.14',
safari: '11.0',
},
'es.promise.with-resolvers': {
bun: '0.7.1',
chrome: '119',
firefox: '121',
},
'es.reflect.apply': {
chrome: '49',
edge: '15',
@@ -2167,11 +2172,8 @@ export const data = {
// TODO: Remove from `core-js@4`
'esnext.promise.try': {
},
'esnext.promise.with-resolvers': {
bun: '0.7.1',
chrome: '119',
firefox: '121',
},
// TODO: Remove from `core-js@4`
'esnext.promise.with-resolvers': null,
// TODO: Remove from `core-js@4`
'esnext.reflect.define-metadata': {
},
@@ -2597,6 +2599,7 @@ export const renamed = new Map([
['esnext.object.group-by', 'es.object.group-by'],
['esnext.promise.all-settled', 'es.promise.all-settled'],
['esnext.promise.any', 'es.promise.any'],
['esnext.promise.with-resolvers', 'es.promise.with-resolvers'],
['esnext.string.is-well-formed', 'es.string.is-well-formed'],
['esnext.string.match-all', 'es.string.match-all'],
['esnext.string.replace-all', 'es.string.replace-all'],
@@ -226,5 +226,6 @@ export default {
3.34: [
'es.map.group-by',
'es.object.group-by',
'es.promise.with-resolvers',
],
};
@@ -1,13 +1,6 @@
'use strict';
require('../../modules/es.promise');
var parent = require('../../stable/promise/with-resolvers');
// TODO: Remove from `core-js@4`
require('../../modules/esnext.promise.with-resolvers');
var call = require('../../internals/function-call');
var isCallable = require('../../internals/is-callable');
var path = require('../../internals/path');
var Promise = path.Promise;
var promiseWithResolvers = Promise.withResolvers;
module.exports = function withResolvers() {
return call(promiseWithResolvers, isCallable(this) ? this : Promise);
};
module.exports = parent;
+1
View File
@@ -5,6 +5,7 @@ require('../../modules/es.object.to-string');
require('../../modules/es.promise');
require('../../modules/es.promise.all-settled');
require('../../modules/es.promise.any');
require('../../modules/es.promise.with-resolvers');
require('../../modules/es.promise.finally');
require('../../modules/es.string.iterator');
var path = require('../../internals/path');
@@ -0,0 +1,13 @@
'use strict';
require('../../modules/es.promise');
require('../../modules/es.promise.with-resolvers');
var call = require('../../internals/function-call');
var isCallable = require('../../internals/is-callable');
var path = require('../../internals/path');
var Promise = path.Promise;
var promiseWithResolvers = Promise.withResolvers;
module.exports = function withResolvers() {
return call(promiseWithResolvers, isCallable(this) ? this : Promise);
};
@@ -0,0 +1,16 @@
'use strict';
var $ = require('../internals/export');
var newPromiseCapabilityModule = require('../internals/new-promise-capability');
// `Promise.withResolvers` method
// https://github.com/tc39/proposal-promise-with-resolvers
$({ target: 'Promise', stat: true }, {
withResolvers: function withResolvers() {
var promiseCapability = newPromiseCapabilityModule.f(this);
return {
promise: promiseCapability.promise,
resolve: promiseCapability.resolve,
reject: promiseCapability.reject
};
}
});
@@ -1,16 +1,3 @@
'use strict';
var $ = require('../internals/export');
var newPromiseCapabilityModule = require('../internals/new-promise-capability');
// `Promise.withResolvers` method
// https://github.com/tc39/proposal-promise-with-resolvers
$({ target: 'Promise', stat: true }, {
withResolvers: function withResolvers() {
var promiseCapability = newPromiseCapabilityModule.f(this);
return {
promise: promiseCapability.promise,
resolve: promiseCapability.resolve,
reject: promiseCapability.reject
};
}
});
// TODO: Remove from `core-js@4`
require('../modules/es.promise.with-resolvers');
@@ -0,0 +1,4 @@
'use strict';
var parent = require('../../es/promise/with-resolvers');
module.exports = parent;
-1
View File
@@ -8,7 +8,6 @@ require('../proposals/explicit-resource-management');
require('../proposals/float16');
require('../proposals/iterator-helpers-stage-3-2');
require('../proposals/json-parse-with-source');
require('../proposals/promise-with-resolvers');
require('../proposals/set-methods-v2');
// TODO: Obsolete versions, remove from `core-js@4`
require('../proposals/array-grouping-stage-3');
+1
View File
@@ -8,6 +8,7 @@ require('../proposals/change-array-by-copy-stage-4');
require('../proposals/global-this');
require('../proposals/promise-all-settled');
require('../proposals/promise-any');
require('../proposals/promise-with-resolvers');
require('../proposals/relative-indexing-method');
require('../proposals/string-match-all');
require('../proposals/string-replace-all-stage-4');
+3 -3
View File
@@ -963,6 +963,9 @@ GLOBAL.tests = {
}],
'es.promise.reject': PROMISES_SUPPORT,
'es.promise.resolve': PROMISES_SUPPORT,
'es.promise.with-resolvers': [PROMISES_SUPPORT, function () {
return Promise.withResolvers;
}],
'es.reflect.apply': function () {
try {
return Reflect.apply(function () {
@@ -1744,9 +1747,6 @@ GLOBAL.tests = {
'esnext.number.from-string': function () {
return Number.fromString;
},
'esnext.promise.with-resolvers': [PROMISES_SUPPORT, function () {
return Promise.withResolvers;
}],
'esnext.regexp.escape': function () {
return RegExp.escape;
},
+1 -1
View File
@@ -321,6 +321,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
ok(load(NS, 'promise/all-settled')([1, 2, 3]) instanceof Promise);
ok(load(NS, 'promise/any')([1, 2, 3]) instanceof Promise);
ok(load(NS, 'promise/finally')(new Promise(resolve => resolve), it => it) instanceof Promise);
ok(load(NS, 'promise/with-resolvers')().promise instanceof load(NS, 'promise'));
ok(load(NS, 'is-iterable')([]));
ok(typeof load(NS, 'get-iterator-method')([]) == 'function');
ok('next' in load(NS, 'get-iterator')([]));
@@ -696,7 +697,6 @@ for (PATH of ['core-js-pure', 'core-js']) {
ok(load(NS, 'json/parse')('[42]', (key, value, { source }) => typeof value == 'number' ? source + source : value)[0] === '4242');
ok(typeof load(NS, 'json/raw-json')(42) == 'object');
ok(load(NS, 'math/f16round')(1.337) === 1.3369140625);
ok(load(NS, 'promise/with-resolvers')().promise instanceof load(NS, 'promise'));
ok(load(NS, 'set/difference')(new Set([1, 2, 3]), new Set([3, 4, 5])).size === 2);
ok(load(NS, 'set/intersection')(new Set([1, 2, 3]), new Set([1, 3, 4])).size === 2);
ok(load(NS, 'set/is-disjoint-from')(new Set([1, 2, 3]), new Set([4, 5, 6])));
@@ -1,4 +1,4 @@
import Promise from 'core-js-pure/full/promise';
import Promise from 'core-js-pure/es/promise';
import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
QUnit.test('Promise.withResolvers', assert => {