es.aggregate-error.cause.js 932 B

123456789101112131415161718192021
  1. var $ = require('../internals/export');
  2. var getBuiltIn = require('../internals/get-built-in');
  3. var apply = require('../internals/function-apply');
  4. var fails = require('../internals/fails');
  5. var wrapErrorConstructorWithCause = require('../internals/wrap-error-constructor-with-cause');
  6. var AGGREGATE_ERROR = 'AggregateError';
  7. var $AggregateError = getBuiltIn(AGGREGATE_ERROR);
  8. var FORCED = !fails(function () {
  9. return $AggregateError([1]).errors[0] !== 1;
  10. }) && fails(function () {
  11. return $AggregateError([1], AGGREGATE_ERROR, { cause: 7 }).cause !== 7;
  12. });
  13. // https://github.com/tc39/proposal-error-cause
  14. $({ global: true, forced: FORCED }, {
  15. AggregateError: wrapErrorConstructorWithCause(AGGREGATE_ERROR, function (init) {
  16. // eslint-disable-next-line no-unused-vars -- required for functions `.length`
  17. return function AggregateError(errors, message) { return apply(init, this, arguments); };
  18. }, FORCED, true)
  19. });