es.aggregate-error.cause.js 962 B

12345678910111213141516171819202122
  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, constructor: true, arity: 2, 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. });