1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var globalThis = require('../internals/global-this');
|
---|
4 | var isPrototypeOf = require('../internals/object-is-prototype-of');
|
---|
5 | var getPrototypeOf = require('../internals/object-get-prototype-of');
|
---|
6 | var setPrototypeOf = require('../internals/object-set-prototype-of');
|
---|
7 | var copyConstructorProperties = require('../internals/copy-constructor-properties');
|
---|
8 | var create = require('../internals/object-create');
|
---|
9 | var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
|
---|
10 | var createPropertyDescriptor = require('../internals/create-property-descriptor');
|
---|
11 | var installErrorStack = require('../internals/error-stack-install');
|
---|
12 | var normalizeStringArgument = require('../internals/normalize-string-argument');
|
---|
13 | var wellKnownSymbol = require('../internals/well-known-symbol');
|
---|
14 | var fails = require('../internals/fails');
|
---|
15 | var IS_PURE = require('../internals/is-pure');
|
---|
16 |
|
---|
17 | var NativeSuppressedError = globalThis.SuppressedError;
|
---|
18 | var TO_STRING_TAG = wellKnownSymbol('toStringTag');
|
---|
19 | var $Error = Error;
|
---|
20 |
|
---|
21 | // https://github.com/oven-sh/bun/issues/9282
|
---|
22 | var WRONG_ARITY = !!NativeSuppressedError && NativeSuppressedError.length !== 3;
|
---|
23 |
|
---|
24 | // https://github.com/oven-sh/bun/issues/9283
|
---|
25 | var EXTRA_ARGS_SUPPORT = !!NativeSuppressedError && fails(function () {
|
---|
26 | return new NativeSuppressedError(1, 2, 3, { cause: 4 }).cause === 4;
|
---|
27 | });
|
---|
28 |
|
---|
29 | var PATCH = WRONG_ARITY || EXTRA_ARGS_SUPPORT;
|
---|
30 |
|
---|
31 | var $SuppressedError = function SuppressedError(error, suppressed, message) {
|
---|
32 | var isInstance = isPrototypeOf(SuppressedErrorPrototype, this);
|
---|
33 | var that;
|
---|
34 | if (setPrototypeOf) {
|
---|
35 | that = PATCH && (!isInstance || getPrototypeOf(this) === SuppressedErrorPrototype)
|
---|
36 | ? new NativeSuppressedError()
|
---|
37 | : setPrototypeOf(new $Error(), isInstance ? getPrototypeOf(this) : SuppressedErrorPrototype);
|
---|
38 | } else {
|
---|
39 | that = isInstance ? this : create(SuppressedErrorPrototype);
|
---|
40 | createNonEnumerableProperty(that, TO_STRING_TAG, 'Error');
|
---|
41 | }
|
---|
42 | if (message !== undefined) createNonEnumerableProperty(that, 'message', normalizeStringArgument(message));
|
---|
43 | installErrorStack(that, $SuppressedError, that.stack, 1);
|
---|
44 | createNonEnumerableProperty(that, 'error', error);
|
---|
45 | createNonEnumerableProperty(that, 'suppressed', suppressed);
|
---|
46 | return that;
|
---|
47 | };
|
---|
48 |
|
---|
49 | if (setPrototypeOf) setPrototypeOf($SuppressedError, $Error);
|
---|
50 | else copyConstructorProperties($SuppressedError, $Error, { name: true });
|
---|
51 |
|
---|
52 | var SuppressedErrorPrototype = $SuppressedError.prototype = PATCH ? NativeSuppressedError.prototype : create($Error.prototype, {
|
---|
53 | constructor: createPropertyDescriptor(1, $SuppressedError),
|
---|
54 | message: createPropertyDescriptor(1, ''),
|
---|
55 | name: createPropertyDescriptor(1, 'SuppressedError')
|
---|
56 | });
|
---|
57 |
|
---|
58 | if (PATCH && !IS_PURE) SuppressedErrorPrototype.constructor = $SuppressedError;
|
---|
59 |
|
---|
60 | // `SuppressedError` constructor
|
---|
61 | // https://github.com/tc39/proposal-explicit-resource-management
|
---|
62 | $({ global: true, constructor: true, arity: 3, forced: PATCH }, {
|
---|
63 | SuppressedError: $SuppressedError
|
---|
64 | });
|
---|