es.aggregate-error.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var getPrototypeOf = require('../internals/object-get-prototype-of');
  4. var setPrototypeOf = require('../internals/object-set-prototype-of');
  5. var create = require('../internals/object-create');
  6. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  7. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  8. var iterate = require('../internals/iterate');
  9. var $AggregateError = function AggregateError(errors, message) {
  10. var that = this;
  11. if (!(that instanceof $AggregateError)) return new $AggregateError(errors, message);
  12. if (setPrototypeOf) {
  13. // eslint-disable-next-line unicorn/error-message -- expected
  14. that = setPrototypeOf(new Error(undefined), getPrototypeOf(that));
  15. }
  16. if (message !== undefined) createNonEnumerableProperty(that, 'message', String(message));
  17. var errorsArray = [];
  18. iterate(errors, errorsArray.push, { that: errorsArray });
  19. createNonEnumerableProperty(that, 'errors', errorsArray);
  20. return that;
  21. };
  22. $AggregateError.prototype = create(Error.prototype, {
  23. constructor: createPropertyDescriptor(5, $AggregateError),
  24. message: createPropertyDescriptor(5, ''),
  25. name: createPropertyDescriptor(5, 'AggregateError')
  26. });
  27. // `AggregateError` constructor
  28. // https://tc39.es/ecma262/#sec-aggregate-error-constructor
  29. $({ global: true }, {
  30. AggregateError: $AggregateError
  31. });