esnext.aggregate-error.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var DESCRIPTORS = require('../internals/descriptors');
  4. var getPrototypeOf = require('../internals/object-get-prototype-of');
  5. var setPrototypeOf = require('../internals/object-set-prototype-of');
  6. var create = require('../internals/object-create');
  7. var defineProperty = require('../internals/object-define-property');
  8. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  9. var iterate = require('../internals/iterate');
  10. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  11. var InternalStateModule = require('../internals/internal-state');
  12. var setInternalState = InternalStateModule.set;
  13. var getInternalAggregateErrorState = InternalStateModule.getterFor('AggregateError');
  14. var $AggregateError = function AggregateError(errors, message) {
  15. var that = this;
  16. if (!(that instanceof $AggregateError)) return new $AggregateError(errors, message);
  17. if (setPrototypeOf) {
  18. that = setPrototypeOf(new Error(message), getPrototypeOf(that));
  19. }
  20. var errorsArray = [];
  21. iterate(errors, errorsArray.push, errorsArray);
  22. if (DESCRIPTORS) setInternalState(that, { errors: errorsArray, type: 'AggregateError' });
  23. else that.errors = errorsArray;
  24. if (message !== undefined) createNonEnumerableProperty(that, 'message', String(message));
  25. return that;
  26. };
  27. $AggregateError.prototype = create(Error.prototype, {
  28. constructor: createPropertyDescriptor(5, $AggregateError),
  29. message: createPropertyDescriptor(5, ''),
  30. name: createPropertyDescriptor(5, 'AggregateError')
  31. });
  32. if (DESCRIPTORS) defineProperty.f($AggregateError.prototype, 'errors', {
  33. get: function () {
  34. return getInternalAggregateErrorState(this).errors;
  35. },
  36. configurable: true
  37. });
  38. $({ global: true }, {
  39. AggregateError: $AggregateError
  40. });