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:
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user