You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.3 KiB
34 lines
1.3 KiB
'use strict';
|
|
var $ = require('../internals/export');
|
|
var globalThis = require('../internals/global-this');
|
|
var apply = require('../internals/function-apply');
|
|
var slice = require('../internals/array-slice');
|
|
var newPromiseCapabilityModule = require('../internals/new-promise-capability');
|
|
var aCallable = require('../internals/a-callable');
|
|
var perform = require('../internals/perform');
|
|
|
|
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) {
|
|
ACCEPT_ARGUMENTS = argument === 8;
|
|
}, 8);
|
|
}).error || !ACCEPT_ARGUMENTS;
|
|
|
|
// `Promise.try` method
|
|
// https://github.com/tc39/proposal-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);
|
|
return promiseCapability.promise;
|
|
}
|
|
});
|