use PromiseResolve semantics in Promise.try

https://github.com/tc39/ecma262/pull/3883
This commit is contained in:
Denis Pushkarev
2026-07-25 19:11:15 +03:00
parent 001916d14b
commit f80ae13f92
5 changed files with 37 additions and 15 deletions
+7 -5
View File
@@ -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',
+16 -8
View File
@@ -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;
}
});