1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var isPrototypeOf = require('../internals/object-is-prototype-of');
|
---|
4 | var getPrototypeOf = require('../internals/object-get-prototype-of');
|
---|
5 | var setPrototypeOf = require('../internals/object-set-prototype-of');
|
---|
6 | var copyConstructorProperties = require('../internals/copy-constructor-properties');
|
---|
7 | var create = require('../internals/object-create');
|
---|
8 | var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
---|
9 | var createPropertyDescriptor = require('../internals/create-property-descriptor');
|
---|
10 | var installErrorCause = require('../internals/install-error-cause');
|
---|
11 | var installErrorStack = require('../internals/error-stack-install');
|
---|
12 | var iterate = require('../internals/iterate');
|
---|
13 | var normalizeStringArgument = require('../internals/normalize-string-argument');
|
---|
14 | var wellKnownSymbol = require('../internals/well-known-symbol');
|
---|
15 |
|
---|
16 | var TO_STRING_TAG = wellKnownSymbol('toStringTag');
|
---|
17 | var $Error = Error;
|
---|
18 | var push = [].push;
|
---|
19 |
|
---|
20 | var $AggregateError = function AggregateError(errors, message /* , options */) {
|
---|
21 | var isInstance = isPrototypeOf(AggregateErrorPrototype, this);
|
---|
22 | var that;
|
---|
23 | if (setPrototypeOf) {
|
---|
24 | that = setPrototypeOf(new $Error(), isInstance ? getPrototypeOf(this) : AggregateErrorPrototype);
|
---|
25 | } else {
|
---|
26 | that = isInstance ? this : create(AggregateErrorPrototype);
|
---|
27 | createNonEnumerableProperty(that, TO_STRING_TAG, 'Error');
|
---|
28 | }
|
---|
29 | if (message !== undefined) createNonEnumerableProperty(that, 'message', normalizeStringArgument(message));
|
---|
30 | installErrorStack(that, $AggregateError, that.stack, 1);
|
---|
31 | if (arguments.length > 2) installErrorCause(that, arguments[2]);
|
---|
32 | var errorsArray = [];
|
---|
33 | iterate(errors, push, { that: errorsArray });
|
---|
34 | createNonEnumerableProperty(that, 'errors', errorsArray);
|
---|
35 | return that;
|
---|
36 | };
|
---|
37 |
|
---|
38 | if (setPrototypeOf) setPrototypeOf($AggregateError, $Error);
|
---|
39 | else copyConstructorProperties($AggregateError, $Error, { name: true });
|
---|
40 |
|
---|
41 | var AggregateErrorPrototype = $AggregateError.prototype = create($Error.prototype, {
|
---|
42 | constructor: createPropertyDescriptor(1, $AggregateError),
|
---|
43 | message: createPropertyDescriptor(1, ''),
|
---|
44 | name: createPropertyDescriptor(1, 'AggregateError')
|
---|
45 | });
|
---|
46 |
|
---|
47 | // `AggregateError` constructor
|
---|
48 | // https://tc39.es/ecma262/#sec-aggregate-error-constructor
|
---|
49 | $({ global: true, constructor: true, arity: 2 }, {
|
---|
50 | AggregateError: $AggregateError
|
---|
51 | });
|
---|