metano-runtime 3.3.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/system/disposable.d.ts +18 -2
- package/dist/system/disposable.js +28 -0
- package/dist/system/exceptions/to-exception.d.ts +5 -1
- package/dist/system/exceptions/to-exception.js +29 -1
- package/dist-unchecked/system/disposable.d.ts +18 -2
- package/dist-unchecked/system/disposable.js +28 -0
- package/dist-unchecked/system/exceptions/to-exception.d.ts +5 -1
- package/dist-unchecked/system/exceptions/to-exception.js +29 -1
- package/package.json +1 -1
- package/src/system/disposable.ts +38 -2
- package/src/system/exceptions/to-exception.ts +36 -1
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import type { InterfaceType } from "./reflection/runtime-type.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Runs `dispose` on `resource`: the body of the `[Symbol.dispose]()` alias every generated
|
|
4
|
+
* `IDisposable` implementer declares (spec FR-111), which passes the method that implements
|
|
5
|
+
* `Dispose()` under its emitted name (`disposeResource(this, this.dispose)`).
|
|
6
|
+
*
|
|
7
|
+
* The binding is the polyfill anchor. Building it installs `Symbol.dispose` first when the
|
|
8
|
+
* engine has none (stable Safari), as `Symbol.for("Symbol.dispose")`, the key TypeScript's
|
|
9
|
+
* downlevel `using` helpers then read. The ordering rests on the ESM graph: a generated
|
|
10
|
+
* module imports this one, and this module never imports generated code, so even in an
|
|
11
|
+
* import cycle between generated modules it is evaluated before any class whose
|
|
12
|
+
* `[Symbol.dispose]` key it defines; a bundle that keeps an implementer keeps this
|
|
13
|
+
* initializer (the alias reads it), and one that keeps none keeps nothing (spec 011 FR-043).
|
|
14
|
+
*/
|
|
15
|
+
export declare const disposeResource: <T>(resource: T, dispose: (this: T) => void) => void;
|
|
2
16
|
/**
|
|
3
17
|
* C# `System.IDisposable` (spec FR-111): `Dispose()` lowers to `dispose()`, and a C# `using`
|
|
4
|
-
* lowers to `
|
|
5
|
-
*
|
|
18
|
+
* lowers to a TypeScript `using` declaration, which calls `[Symbol.dispose]()`. Every
|
|
19
|
+
* generated implementer declares that member as an alias of `dispose()`, so hand-written
|
|
20
|
+
* TypeScript can hold an `IDisposable` in a `using` declaration too.
|
|
6
21
|
*/
|
|
7
22
|
export interface IDisposable {
|
|
8
23
|
dispose(): void;
|
|
24
|
+
[Symbol.dispose](): void;
|
|
9
25
|
}
|
|
10
26
|
/**
|
|
11
27
|
* The descriptor of {@link IDisposable}. The test is nominal, as in .NET: a value is
|
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
import { implementsInterface } from "./reflection/implements-interface.js";
|
|
2
|
+
/**
|
|
3
|
+
* Runs `dispose` on `resource`: the body of the `[Symbol.dispose]()` alias every generated
|
|
4
|
+
* `IDisposable` implementer declares (spec FR-111), which passes the method that implements
|
|
5
|
+
* `Dispose()` under its emitted name (`disposeResource(this, this.dispose)`).
|
|
6
|
+
*
|
|
7
|
+
* The binding is the polyfill anchor. Building it installs `Symbol.dispose` first when the
|
|
8
|
+
* engine has none (stable Safari), as `Symbol.for("Symbol.dispose")`, the key TypeScript's
|
|
9
|
+
* downlevel `using` helpers then read. The ordering rests on the ESM graph: a generated
|
|
10
|
+
* module imports this one, and this module never imports generated code, so even in an
|
|
11
|
+
* import cycle between generated modules it is evaluated before any class whose
|
|
12
|
+
* `[Symbol.dispose]` key it defines; a bundle that keeps an implementer keeps this
|
|
13
|
+
* initializer (the alias reads it), and one that keeps none keeps nothing (spec 011 FR-043).
|
|
14
|
+
*/
|
|
15
|
+
export const disposeResource =
|
|
16
|
+
// Pure for bundlers: kept, and run at load, only while a generated alias reads it.
|
|
17
|
+
/* @__PURE__ */ createResourceDisposer();
|
|
18
|
+
function createResourceDisposer() {
|
|
19
|
+
installSymbolDispose();
|
|
20
|
+
return disposeThrough;
|
|
21
|
+
}
|
|
22
|
+
/** Defines `Symbol.dispose` as `Symbol.for("Symbol.dispose")` on an engine without it. */
|
|
23
|
+
function installSymbolDispose() {
|
|
24
|
+
const symbols = Symbol;
|
|
25
|
+
symbols.dispose ??= Symbol.for("Symbol.dispose");
|
|
26
|
+
}
|
|
27
|
+
function disposeThrough(resource, dispose) {
|
|
28
|
+
dispose.call(resource);
|
|
29
|
+
}
|
|
2
30
|
/**
|
|
3
31
|
* The descriptor of {@link IDisposable}. The test is nominal, as in .NET: a value is
|
|
4
32
|
* `IDisposable` only when its class descriptor lists the interface, never because it has a
|
|
@@ -13,8 +13,12 @@ import { Exception } from "./exception.ts";
|
|
|
13
13
|
* A wrapper keeps the original's `message` and `stack`, and holds the original
|
|
14
14
|
* as its `innerException` (`cause`). A `TypeError` thrown on purpose by
|
|
15
15
|
* third-party JavaScript is also reported as a `NullReferenceException`.
|
|
16
|
+
*
|
|
17
|
+
* A `SuppressedError` (what a `using` declaration throws when its body and its
|
|
18
|
+
* disposal both fail) is unwrapped to its `error`, the disposal's exception,
|
|
19
|
+
* which is the one a C# `finally` lets through (spec FR-111).
|
|
16
20
|
*/
|
|
17
|
-
export declare function toException(
|
|
21
|
+
export declare function toException(thrown: unknown): Exception;
|
|
18
22
|
/**
|
|
19
23
|
* Runs a `when` filter of a `catch` clause. A filter that throws counts as
|
|
20
24
|
* `false`, as in C#: the exception is dropped and the next clause is tried.
|
|
@@ -6,6 +6,10 @@ import { TaskCanceledException } from "./task-canceled-exception.js";
|
|
|
6
6
|
* rejects with.
|
|
7
7
|
*/
|
|
8
8
|
const ABORT_ERROR_NAME = "AbortError";
|
|
9
|
+
/** The `name` of the error a `using` declaration throws when its disposal hides another error. */
|
|
10
|
+
const SUPPRESSED_ERROR_NAME = "SuppressedError";
|
|
11
|
+
/** How many nested `SuppressedError`s `toException` unwraps at most. */
|
|
12
|
+
const MAX_SUPPRESSION_DEPTH = 64;
|
|
9
13
|
/**
|
|
10
14
|
* Normalizes whatever a JavaScript `catch` caught to a `System.Exception`, as
|
|
11
15
|
* the typed clauses of a C# `try` see it:
|
|
@@ -20,8 +24,13 @@ const ABORT_ERROR_NAME = "AbortError";
|
|
|
20
24
|
* A wrapper keeps the original's `message` and `stack`, and holds the original
|
|
21
25
|
* as its `innerException` (`cause`). A `TypeError` thrown on purpose by
|
|
22
26
|
* third-party JavaScript is also reported as a `NullReferenceException`.
|
|
27
|
+
*
|
|
28
|
+
* A `SuppressedError` (what a `using` declaration throws when its body and its
|
|
29
|
+
* disposal both fail) is unwrapped to its `error`, the disposal's exception,
|
|
30
|
+
* which is the one a C# `finally` lets through (spec FR-111).
|
|
23
31
|
*/
|
|
24
|
-
export function toException(
|
|
32
|
+
export function toException(thrown) {
|
|
33
|
+
const value = withoutSuppression(thrown);
|
|
25
34
|
if (value instanceof Exception) {
|
|
26
35
|
return value;
|
|
27
36
|
}
|
|
@@ -34,6 +43,25 @@ export function toException(value) {
|
|
|
34
43
|
}
|
|
35
44
|
return wrapper;
|
|
36
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* The exception a chain of `SuppressedError`s ends with, following `error`. A chain longer
|
|
48
|
+
* than {@link MAX_SUPPRESSION_DEPTH} (a cyclic `error`) stops at the error it reached.
|
|
49
|
+
*/
|
|
50
|
+
function withoutSuppression(value, depth = 0) {
|
|
51
|
+
return isSuppressedError(value) && depth < MAX_SUPPRESSION_DEPTH
|
|
52
|
+
? withoutSuppression(value.error, depth + 1)
|
|
53
|
+
: value;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Whether `value` is a `SuppressedError`: the native class, or the stand-in TypeScript's
|
|
57
|
+
* downlevel `using` helpers build on an engine without one, which only carries the name.
|
|
58
|
+
*/
|
|
59
|
+
function isSuppressedError(value) {
|
|
60
|
+
return (value instanceof Error &&
|
|
61
|
+
!(value instanceof Exception) &&
|
|
62
|
+
value.name === SUPPRESSED_ERROR_NAME &&
|
|
63
|
+
"error" in value);
|
|
64
|
+
}
|
|
37
65
|
function wrap(error) {
|
|
38
66
|
if (error instanceof TypeError) {
|
|
39
67
|
return new NullReferenceException(error.message, error);
|
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import type { InterfaceType } from "./reflection/runtime-type.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Runs `dispose` on `resource`: the body of the `[Symbol.dispose]()` alias every generated
|
|
4
|
+
* `IDisposable` implementer declares (spec FR-111), which passes the method that implements
|
|
5
|
+
* `Dispose()` under its emitted name (`disposeResource(this, this.dispose)`).
|
|
6
|
+
*
|
|
7
|
+
* The binding is the polyfill anchor. Building it installs `Symbol.dispose` first when the
|
|
8
|
+
* engine has none (stable Safari), as `Symbol.for("Symbol.dispose")`, the key TypeScript's
|
|
9
|
+
* downlevel `using` helpers then read. The ordering rests on the ESM graph: a generated
|
|
10
|
+
* module imports this one, and this module never imports generated code, so even in an
|
|
11
|
+
* import cycle between generated modules it is evaluated before any class whose
|
|
12
|
+
* `[Symbol.dispose]` key it defines; a bundle that keeps an implementer keeps this
|
|
13
|
+
* initializer (the alias reads it), and one that keeps none keeps nothing (spec 011 FR-043).
|
|
14
|
+
*/
|
|
15
|
+
export declare const disposeResource: <T>(resource: T, dispose: (this: T) => void) => void;
|
|
2
16
|
/**
|
|
3
17
|
* C# `System.IDisposable` (spec FR-111): `Dispose()` lowers to `dispose()`, and a C# `using`
|
|
4
|
-
* lowers to `
|
|
5
|
-
*
|
|
18
|
+
* lowers to a TypeScript `using` declaration, which calls `[Symbol.dispose]()`. Every
|
|
19
|
+
* generated implementer declares that member as an alias of `dispose()`, so hand-written
|
|
20
|
+
* TypeScript can hold an `IDisposable` in a `using` declaration too.
|
|
6
21
|
*/
|
|
7
22
|
export interface IDisposable {
|
|
8
23
|
dispose(): void;
|
|
24
|
+
[Symbol.dispose](): void;
|
|
9
25
|
}
|
|
10
26
|
/**
|
|
11
27
|
* The descriptor of {@link IDisposable}. The test is nominal, as in .NET: a value is
|
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
import { implementsInterface } from "./reflection/implements-interface.js";
|
|
2
|
+
/**
|
|
3
|
+
* Runs `dispose` on `resource`: the body of the `[Symbol.dispose]()` alias every generated
|
|
4
|
+
* `IDisposable` implementer declares (spec FR-111), which passes the method that implements
|
|
5
|
+
* `Dispose()` under its emitted name (`disposeResource(this, this.dispose)`).
|
|
6
|
+
*
|
|
7
|
+
* The binding is the polyfill anchor. Building it installs `Symbol.dispose` first when the
|
|
8
|
+
* engine has none (stable Safari), as `Symbol.for("Symbol.dispose")`, the key TypeScript's
|
|
9
|
+
* downlevel `using` helpers then read. The ordering rests on the ESM graph: a generated
|
|
10
|
+
* module imports this one, and this module never imports generated code, so even in an
|
|
11
|
+
* import cycle between generated modules it is evaluated before any class whose
|
|
12
|
+
* `[Symbol.dispose]` key it defines; a bundle that keeps an implementer keeps this
|
|
13
|
+
* initializer (the alias reads it), and one that keeps none keeps nothing (spec 011 FR-043).
|
|
14
|
+
*/
|
|
15
|
+
export const disposeResource =
|
|
16
|
+
// Pure for bundlers: kept, and run at load, only while a generated alias reads it.
|
|
17
|
+
/* @__PURE__ */ createResourceDisposer();
|
|
18
|
+
function createResourceDisposer() {
|
|
19
|
+
installSymbolDispose();
|
|
20
|
+
return disposeThrough;
|
|
21
|
+
}
|
|
22
|
+
/** Defines `Symbol.dispose` as `Symbol.for("Symbol.dispose")` on an engine without it. */
|
|
23
|
+
function installSymbolDispose() {
|
|
24
|
+
const symbols = Symbol;
|
|
25
|
+
symbols.dispose ??= Symbol.for("Symbol.dispose");
|
|
26
|
+
}
|
|
27
|
+
function disposeThrough(resource, dispose) {
|
|
28
|
+
dispose.call(resource);
|
|
29
|
+
}
|
|
2
30
|
/**
|
|
3
31
|
* The descriptor of {@link IDisposable}. The test is nominal, as in .NET: a value is
|
|
4
32
|
* `IDisposable` only when its class descriptor lists the interface, never because it has a
|
|
@@ -13,8 +13,12 @@ import { Exception } from "./exception.ts";
|
|
|
13
13
|
* A wrapper keeps the original's `message` and `stack`, and holds the original
|
|
14
14
|
* as its `innerException` (`cause`). A `TypeError` thrown on purpose by
|
|
15
15
|
* third-party JavaScript is also reported as a `NullReferenceException`.
|
|
16
|
+
*
|
|
17
|
+
* A `SuppressedError` (what a `using` declaration throws when its body and its
|
|
18
|
+
* disposal both fail) is unwrapped to its `error`, the disposal's exception,
|
|
19
|
+
* which is the one a C# `finally` lets through (spec FR-111).
|
|
16
20
|
*/
|
|
17
|
-
export declare function toException(
|
|
21
|
+
export declare function toException(thrown: unknown): Exception;
|
|
18
22
|
/**
|
|
19
23
|
* Runs a `when` filter of a `catch` clause. A filter that throws counts as
|
|
20
24
|
* `false`, as in C#: the exception is dropped and the next clause is tried.
|
|
@@ -6,6 +6,10 @@ import { TaskCanceledException } from "./task-canceled-exception.js";
|
|
|
6
6
|
* rejects with.
|
|
7
7
|
*/
|
|
8
8
|
const ABORT_ERROR_NAME = "AbortError";
|
|
9
|
+
/** The `name` of the error a `using` declaration throws when its disposal hides another error. */
|
|
10
|
+
const SUPPRESSED_ERROR_NAME = "SuppressedError";
|
|
11
|
+
/** How many nested `SuppressedError`s `toException` unwraps at most. */
|
|
12
|
+
const MAX_SUPPRESSION_DEPTH = 64;
|
|
9
13
|
/**
|
|
10
14
|
* Normalizes whatever a JavaScript `catch` caught to a `System.Exception`, as
|
|
11
15
|
* the typed clauses of a C# `try` see it:
|
|
@@ -20,8 +24,13 @@ const ABORT_ERROR_NAME = "AbortError";
|
|
|
20
24
|
* A wrapper keeps the original's `message` and `stack`, and holds the original
|
|
21
25
|
* as its `innerException` (`cause`). A `TypeError` thrown on purpose by
|
|
22
26
|
* third-party JavaScript is also reported as a `NullReferenceException`.
|
|
27
|
+
*
|
|
28
|
+
* A `SuppressedError` (what a `using` declaration throws when its body and its
|
|
29
|
+
* disposal both fail) is unwrapped to its `error`, the disposal's exception,
|
|
30
|
+
* which is the one a C# `finally` lets through (spec FR-111).
|
|
23
31
|
*/
|
|
24
|
-
export function toException(
|
|
32
|
+
export function toException(thrown) {
|
|
33
|
+
const value = withoutSuppression(thrown);
|
|
25
34
|
if (value instanceof Exception) {
|
|
26
35
|
return value;
|
|
27
36
|
}
|
|
@@ -34,6 +43,25 @@ export function toException(value) {
|
|
|
34
43
|
}
|
|
35
44
|
return wrapper;
|
|
36
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* The exception a chain of `SuppressedError`s ends with, following `error`. A chain longer
|
|
48
|
+
* than {@link MAX_SUPPRESSION_DEPTH} (a cyclic `error`) stops at the error it reached.
|
|
49
|
+
*/
|
|
50
|
+
function withoutSuppression(value, depth = 0) {
|
|
51
|
+
return isSuppressedError(value) && depth < MAX_SUPPRESSION_DEPTH
|
|
52
|
+
? withoutSuppression(value.error, depth + 1)
|
|
53
|
+
: value;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Whether `value` is a `SuppressedError`: the native class, or the stand-in TypeScript's
|
|
57
|
+
* downlevel `using` helpers build on an engine without one, which only carries the name.
|
|
58
|
+
*/
|
|
59
|
+
function isSuppressedError(value) {
|
|
60
|
+
return (value instanceof Error &&
|
|
61
|
+
!(value instanceof Exception) &&
|
|
62
|
+
value.name === SUPPRESSED_ERROR_NAME &&
|
|
63
|
+
"error" in value);
|
|
64
|
+
}
|
|
37
65
|
function wrap(error) {
|
|
38
66
|
if (error instanceof TypeError) {
|
|
39
67
|
return new NullReferenceException(error.message, error);
|
package/package.json
CHANGED
package/src/system/disposable.ts
CHANGED
|
@@ -1,13 +1,49 @@
|
|
|
1
1
|
import { implementsInterface } from "./reflection/implements-interface.ts";
|
|
2
2
|
import type { InterfaceType } from "./reflection/runtime-type.ts";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Runs `dispose` on `resource`: the body of the `[Symbol.dispose]()` alias every generated
|
|
6
|
+
* `IDisposable` implementer declares (spec FR-111), which passes the method that implements
|
|
7
|
+
* `Dispose()` under its emitted name (`disposeResource(this, this.dispose)`).
|
|
8
|
+
*
|
|
9
|
+
* The binding is the polyfill anchor. Building it installs `Symbol.dispose` first when the
|
|
10
|
+
* engine has none (stable Safari), as `Symbol.for("Symbol.dispose")`, the key TypeScript's
|
|
11
|
+
* downlevel `using` helpers then read. The ordering rests on the ESM graph: a generated
|
|
12
|
+
* module imports this one, and this module never imports generated code, so even in an
|
|
13
|
+
* import cycle between generated modules it is evaluated before any class whose
|
|
14
|
+
* `[Symbol.dispose]` key it defines; a bundle that keeps an implementer keeps this
|
|
15
|
+
* initializer (the alias reads it), and one that keeps none keeps nothing (spec 011 FR-043).
|
|
16
|
+
*/
|
|
17
|
+
export const disposeResource: <T>(resource: T, dispose: (this: T) => void) => void =
|
|
18
|
+
// Pure for bundlers: kept, and run at load, only while a generated alias reads it.
|
|
19
|
+
/* @__PURE__ */ createResourceDisposer();
|
|
20
|
+
|
|
21
|
+
function createResourceDisposer(): <T>(resource: T, dispose: (this: T) => void) => void {
|
|
22
|
+
installSymbolDispose();
|
|
23
|
+
|
|
24
|
+
return disposeThrough;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Defines `Symbol.dispose` as `Symbol.for("Symbol.dispose")` on an engine without it. */
|
|
28
|
+
function installSymbolDispose(): void {
|
|
29
|
+
const symbols = Symbol as { dispose?: typeof Symbol.dispose };
|
|
30
|
+
|
|
31
|
+
symbols.dispose ??= Symbol.for("Symbol.dispose") as typeof Symbol.dispose;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function disposeThrough<T>(resource: T, dispose: (this: T) => void): void {
|
|
35
|
+
dispose.call(resource);
|
|
36
|
+
}
|
|
37
|
+
|
|
4
38
|
/**
|
|
5
39
|
* C# `System.IDisposable` (spec FR-111): `Dispose()` lowers to `dispose()`, and a C# `using`
|
|
6
|
-
* lowers to `
|
|
7
|
-
*
|
|
40
|
+
* lowers to a TypeScript `using` declaration, which calls `[Symbol.dispose]()`. Every
|
|
41
|
+
* generated implementer declares that member as an alias of `dispose()`, so hand-written
|
|
42
|
+
* TypeScript can hold an `IDisposable` in a `using` declaration too.
|
|
8
43
|
*/
|
|
9
44
|
export interface IDisposable {
|
|
10
45
|
dispose(): void;
|
|
46
|
+
[Symbol.dispose](): void;
|
|
11
47
|
}
|
|
12
48
|
|
|
13
49
|
/**
|
|
@@ -8,6 +8,12 @@ import { TaskCanceledException } from "./task-canceled-exception.ts";
|
|
|
8
8
|
*/
|
|
9
9
|
const ABORT_ERROR_NAME = "AbortError";
|
|
10
10
|
|
|
11
|
+
/** The `name` of the error a `using` declaration throws when its disposal hides another error. */
|
|
12
|
+
const SUPPRESSED_ERROR_NAME = "SuppressedError";
|
|
13
|
+
|
|
14
|
+
/** How many nested `SuppressedError`s `toException` unwraps at most. */
|
|
15
|
+
const MAX_SUPPRESSION_DEPTH = 64;
|
|
16
|
+
|
|
11
17
|
/**
|
|
12
18
|
* Normalizes whatever a JavaScript `catch` caught to a `System.Exception`, as
|
|
13
19
|
* the typed clauses of a C# `try` see it:
|
|
@@ -22,8 +28,14 @@ const ABORT_ERROR_NAME = "AbortError";
|
|
|
22
28
|
* A wrapper keeps the original's `message` and `stack`, and holds the original
|
|
23
29
|
* as its `innerException` (`cause`). A `TypeError` thrown on purpose by
|
|
24
30
|
* third-party JavaScript is also reported as a `NullReferenceException`.
|
|
31
|
+
*
|
|
32
|
+
* A `SuppressedError` (what a `using` declaration throws when its body and its
|
|
33
|
+
* disposal both fail) is unwrapped to its `error`, the disposal's exception,
|
|
34
|
+
* which is the one a C# `finally` lets through (spec FR-111).
|
|
25
35
|
*/
|
|
26
|
-
export function toException(
|
|
36
|
+
export function toException(thrown: unknown): Exception {
|
|
37
|
+
const value = withoutSuppression(thrown);
|
|
38
|
+
|
|
27
39
|
if (value instanceof Exception) {
|
|
28
40
|
return value;
|
|
29
41
|
}
|
|
@@ -41,6 +53,29 @@ export function toException(value: unknown): Exception {
|
|
|
41
53
|
return wrapper;
|
|
42
54
|
}
|
|
43
55
|
|
|
56
|
+
/**
|
|
57
|
+
* The exception a chain of `SuppressedError`s ends with, following `error`. A chain longer
|
|
58
|
+
* than {@link MAX_SUPPRESSION_DEPTH} (a cyclic `error`) stops at the error it reached.
|
|
59
|
+
*/
|
|
60
|
+
function withoutSuppression(value: unknown, depth = 0): unknown {
|
|
61
|
+
return isSuppressedError(value) && depth < MAX_SUPPRESSION_DEPTH
|
|
62
|
+
? withoutSuppression(value.error, depth + 1)
|
|
63
|
+
: value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Whether `value` is a `SuppressedError`: the native class, or the stand-in TypeScript's
|
|
68
|
+
* downlevel `using` helpers build on an engine without one, which only carries the name.
|
|
69
|
+
*/
|
|
70
|
+
function isSuppressedError(value: unknown): value is Error & { error: unknown } {
|
|
71
|
+
return (
|
|
72
|
+
value instanceof Error &&
|
|
73
|
+
!(value instanceof Exception) &&
|
|
74
|
+
value.name === SUPPRESSED_ERROR_NAME &&
|
|
75
|
+
"error" in value
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
44
79
|
function wrap(error: Error): Exception {
|
|
45
80
|
if (error instanceof TypeError) {
|
|
46
81
|
return new NullReferenceException(error.message, error);
|