mirror of
https://github.com/hanzoai/core-js.git
synced 2026-09-24 16:58:15 +00:00
use PromiseResolve semantics in Promise.try
https://github.com/tc39/ecma262/pull/3883
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
- `Promise.allKeyed`
|
||||
- `Promise.allSettledKeyed`
|
||||
- Throw a `RangeError` on finite unsafe integer `limit` in `Iterator.prototype.{ drop, take }`, following [tc39/ecma262/#3776](https://github.com/tc39/ecma262/pull/3776)
|
||||
- Use `PromiseResolve` semantics in `Promise.try`, following [tc39/ecma262/#3883](https://github.com/tc39/ecma262/pull/3883)
|
||||
- Deno 2.9+ [*replaces* `Object.prototype.__proto__`](https://github.com/denoland/deno/pull/35192) instead of removing it, so the feature detection updated
|
||||
- Ensure opaque paths always roundtrip in URL polyfill (still without adding to feature detection), [whatwg/url#844](https://github.com/whatwg/url/pull/844)
|
||||
- Fixed possible crash on some keys in `Symbol.for`
|
||||
@@ -41,6 +42,7 @@
|
||||
- [V8 ~ Chrome 150](https://github.com/v8/v8/commit/ce52c1d84268311648c9362e8d3bbb08fc58bd3c)
|
||||
- Safari 27.0
|
||||
- Next Bun (1.4.0?) release
|
||||
- Following [tc39/ecma262/#3883](https://github.com/tc39/ecma262/pull/3883), `Promise.try` marked unsupported in all engines
|
||||
- [`Iterator.prototype.{ chunks, windows }`](https://github.com/tc39/proposal-iterator-chunking) marked as [shipped in FF154](https://bugzilla.mozilla.org/show_bug.cgi?id=2047997)
|
||||
- [`Iterator.prototype.includes`](https://github.com/tc39/proposal-iterator-includes) marked as [shipped in FF154](https://bugzilla.mozilla.org/show_bug.cgi?id=2034104)
|
||||
- [`Iterator.prototype.join`](https://github.com/tc39/proposal-iterator-join) marked as [shipped in FF154](https://bugzilla.mozilla.org/show_bug.cgi?id=2047995)
|
||||
|
||||
@@ -1512,11 +1512,13 @@ export const data = {
|
||||
safari: '11.0',
|
||||
},
|
||||
'es.promise.try': {
|
||||
bun: '1.1.22',
|
||||
chrome: '128',
|
||||
firefox: '134',
|
||||
rhino: '1.9.0',
|
||||
safari: '18.2',
|
||||
// includes `PromiseResolve` semantics detection from
|
||||
// https://github.com/tc39/ecma262/pull/3883
|
||||
// bun: '1.1.22',
|
||||
// chrome: '128',
|
||||
// firefox: '134',
|
||||
// rhino: '1.9.0',
|
||||
// safari: '18.2',
|
||||
},
|
||||
'es.promise.with-resolvers': {
|
||||
bun: '0.7.1',
|
||||
|
||||
@@ -3,31 +3,39 @@ var $ = require('../internals/export');
|
||||
var globalThis = require('../internals/global-this');
|
||||
var apply = require('../internals/function-apply');
|
||||
var slice = require('../internals/array-slice');
|
||||
var promiseResolve = require('../internals/promise-resolve');
|
||||
var newPromiseCapabilityModule = require('../internals/new-promise-capability');
|
||||
var aCallable = require('../internals/a-callable');
|
||||
var perform = require('../internals/perform');
|
||||
var fails = require('../internals/fails');
|
||||
|
||||
var Promise = globalThis.Promise;
|
||||
|
||||
var ACCEPT_ARGUMENTS = false;
|
||||
// Avoiding the use of polyfills of the previous iteration of this proposal
|
||||
// that does not accept arguments of the callback
|
||||
var FORCED = !Promise || !Promise['try'] || perform(function () {
|
||||
Promise['try'](function (argument) {
|
||||
var FORCED = !Promise || !Promise['try'] || fails(function () {
|
||||
var p = Promise.resolve();
|
||||
return Promise['try'](function (argument) {
|
||||
// avoiding the use of polyfills of the previous iteration of this proposal
|
||||
// that does not accept arguments of the callback
|
||||
ACCEPT_ARGUMENTS = argument === 8;
|
||||
}, 8);
|
||||
}).error || !ACCEPT_ARGUMENTS;
|
||||
return p;
|
||||
// it should use `PromiseResolve`
|
||||
// https://github.com/tc39/ecma262/pull/3883
|
||||
}, 8) !== p;
|
||||
}) || !ACCEPT_ARGUMENTS;
|
||||
|
||||
// `Promise.try` method
|
||||
// https://tc39.es/ecma262/#sec-promise.try
|
||||
$({ target: 'Promise', stat: true, forced: FORCED }, {
|
||||
'try': function (callbackfn /* , ...args */) {
|
||||
var args = arguments.length > 1 ? slice(arguments, 1) : [];
|
||||
var promiseCapability = newPromiseCapabilityModule.f(this);
|
||||
var result = perform(function () {
|
||||
return apply(aCallable(callbackfn), undefined, args);
|
||||
});
|
||||
(result.error ? promiseCapability.reject : promiseCapability.resolve)(result.value);
|
||||
if (!result.error) return promiseResolve(this, result.value);
|
||||
var promiseCapability = newPromiseCapabilityModule.f(this);
|
||||
var reject = promiseCapability.reject;
|
||||
reject(result.value);
|
||||
return promiseCapability.promise;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1211,10 +1211,15 @@ GLOBAL.tests = {
|
||||
'es.promise.resolve': PROMISES_SUPPORT,
|
||||
'es.promise.try': [PROMISES_SUPPORT, function () {
|
||||
var ACCEPT_ARGUMENTS = false;
|
||||
var p = Promise.resolve();
|
||||
Promise['try'](function (argument) {
|
||||
// avoiding the use of polyfills of the previous iteration of this proposal
|
||||
// that does not accept arguments of the callback
|
||||
ACCEPT_ARGUMENTS = argument === 8;
|
||||
}, 8);
|
||||
return ACCEPT_ARGUMENTS;
|
||||
return p;
|
||||
// it should use `PromiseResolve`
|
||||
// https://github.com/tc39/ecma262/pull/3883
|
||||
}, 8) === p && ACCEPT_ARGUMENTS;
|
||||
}],
|
||||
'es.promise.with-resolvers': [PROMISES_SUPPORT, function () {
|
||||
return Promise.withResolvers;
|
||||
|
||||
@@ -18,6 +18,11 @@ QUnit.test('Promise.try, resolved, with args', assert => {
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('Promise.try, resolved, PromiseResolve inside', assert => {
|
||||
const p = Promise.resolve();
|
||||
assert.same(Promise.try(() => p), p, 'PromiseResolve inside');
|
||||
});
|
||||
|
||||
QUnit.test('Promise.try, rejected', assert => {
|
||||
return Promise.try(() => {
|
||||
throw new Error();
|
||||
|
||||
Reference in New Issue
Block a user