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 installErrorStack = require('../internals/error-stack-install');
|
---|
11 | var normalizeStringArgument = require('../internals/normalize-string-argument');
|
---|
12 | var wellKnownSymbol = require('../internals/well-known-symbol');
|
---|
13 |
|
---|
14 | var TO_STRING_TAG = wellKnownSymbol('toStringTag');
|
---|
15 | var $Error = Error;
|
---|
16 |
|
---|
17 | var $SuppressedError = function SuppressedError(error, suppressed, message) {
|
---|
18 | var isInstance = isPrototypeOf(SuppressedErrorPrototype, this);
|
---|
19 | var that;
|
---|
20 | if (setPrototypeOf) {
|
---|
21 | that = setPrototypeOf(new $Error(), isInstance ? getPrototypeOf(this) : SuppressedErrorPrototype);
|
---|
22 | } else {
|
---|
23 | that = isInstance ? this : create(SuppressedErrorPrototype);
|
---|
24 | createNonEnumerableProperty(that, TO_STRING_TAG, 'Error');
|
---|
25 | }
|
---|
26 | if (message !== undefined) createNonEnumerableProperty(that, 'message', normalizeStringArgument(message));
|
---|
27 | installErrorStack(that, $SuppressedError, that.stack, 1);
|
---|
28 | createNonEnumerableProperty(that, 'error', error);
|
---|
29 | createNonEnumerableProperty(that, 'suppressed', suppressed);
|
---|
30 | return that;
|
---|
31 | };
|
---|
32 |
|
---|
33 | if (setPrototypeOf) setPrototypeOf($SuppressedError, $Error);
|
---|
34 | else copyConstructorProperties($SuppressedError, $Error, { name: true });
|
---|
35 |
|
---|
36 | var SuppressedErrorPrototype = $SuppressedError.prototype = create($Error.prototype, {
|
---|
37 | constructor: createPropertyDescriptor(1, $SuppressedError),
|
---|
38 | message: createPropertyDescriptor(1, ''),
|
---|
39 | name: createPropertyDescriptor(1, 'SuppressedError')
|
---|
40 | });
|
---|
41 |
|
---|
42 | // `SuppressedError` constructor
|
---|
43 | // https://github.com/tc39/proposal-explicit-resource-management
|
---|
44 | $({ global: true, constructor: true, arity: 3 }, {
|
---|
45 | SuppressedError: $SuppressedError
|
---|
46 | });
|
---|