esnext.promise.try.js 611 B

12345678910111213141516
  1. 'use strict';
  2. // TODO: Remove from `core-js@4`
  3. var $ = require('../internals/export');
  4. var newPromiseCapabilityModule = require('../internals/new-promise-capability');
  5. var perform = require('../internals/perform');
  6. // `Promise.try` method
  7. // https://github.com/tc39/proposal-promise-try
  8. $({ target: 'Promise', stat: true, forced: true }, {
  9. 'try': function (callbackfn) {
  10. var promiseCapability = newPromiseCapabilityModule.f(this);
  11. var result = perform(callbackfn);
  12. (result.error ? promiseCapability.reject : promiseCapability.resolve)(result.value);
  13. return promiseCapability.promise;
  14. }
  15. });