1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var globalThis = require('../internals/global-this');
|
---|
4 | var apply = require('../internals/function-apply');
|
---|
5 | var slice = require('../internals/array-slice');
|
---|
6 | var newPromiseCapabilityModule = require('../internals/new-promise-capability');
|
---|
7 | var aCallable = require('../internals/a-callable');
|
---|
8 | var perform = require('../internals/perform');
|
---|
9 |
|
---|
10 | var Promise = globalThis.Promise;
|
---|
11 |
|
---|
12 | var ACCEPT_ARGUMENTS = false;
|
---|
13 | // Avoiding the use of polyfills of the previous iteration of this proposal
|
---|
14 | // that does not accept arguments of the callback
|
---|
15 | var FORCED = !Promise || !Promise['try'] || perform(function () {
|
---|
16 | Promise['try'](function (argument) {
|
---|
17 | ACCEPT_ARGUMENTS = argument === 8;
|
---|
18 | }, 8);
|
---|
19 | }).error || !ACCEPT_ARGUMENTS;
|
---|
20 |
|
---|
21 | // `Promise.try` method
|
---|
22 | // https://tc39.es/ecma262/#sec-promise.try
|
---|
23 | $({ target: 'Promise', stat: true, forced: FORCED }, {
|
---|
24 | 'try': function (callbackfn /* , ...args */) {
|
---|
25 | var args = arguments.length > 1 ? slice(arguments, 1) : [];
|
---|
26 | var promiseCapability = newPromiseCapabilityModule.f(this);
|
---|
27 | var result = perform(function () {
|
---|
28 | return apply(aCallable(callbackfn), undefined, args);
|
---|
29 | });
|
---|
30 | (result.error ? promiseCapability.reject : promiseCapability.resolve)(result.value);
|
---|
31 | return promiseCapability.promise;
|
---|
32 | }
|
---|
33 | });
|
---|