Node-Red configuration
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.

esnext.promise.try.js 1.3KB

123456789101112131415161718192021222324252627282930313233
  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. var Promise = globalThis.Promise;
  10. var ACCEPT_ARGUMENTS = false;
  11. // Avoiding the use of polyfills of the previous iteration of this proposal
  12. // that does not accept arguments of the callback
  13. var FORCED = !Promise || !Promise['try'] || perform(function () {
  14. Promise['try'](function (argument) {
  15. ACCEPT_ARGUMENTS = argument === 8;
  16. }, 8);
  17. }).error || !ACCEPT_ARGUMENTS;
  18. // `Promise.try` method
  19. // https://github.com/tc39/proposal-promise-try
  20. $({ target: 'Promise', stat: true, forced: FORCED }, {
  21. 'try': function (callbackfn /* , ...args */) {
  22. var args = arguments.length > 1 ? slice(arguments, 1) : [];
  23. var promiseCapability = newPromiseCapabilityModule.f(this);
  24. var result = perform(function () {
  25. return apply(aCallable(callbackfn), undefined, args);
  26. });
  27. (result.error ? promiseCapability.reject : promiseCapability.resolve)(result.value);
  28. return promiseCapability.promise;
  29. }
  30. });