bunshin-clone 1.5.5 → 1.5.7
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/README.md +2 -2
- package/dist/index.cjs +79 -78
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +79 -78
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,10 +23,10 @@ import { bunshinClone } from 'https://esm.unpkg.com/bunshin-clone@<x.x.x>';
|
|
|
23
23
|
## 📦 APIs
|
|
24
24
|
|
|
25
25
|
```ts
|
|
26
|
-
bunshinClone<T>(
|
|
26
|
+
bunshinClone<T>(value, options);
|
|
27
27
|
// => T
|
|
28
28
|
//
|
|
29
|
-
//
|
|
29
|
+
// value: T
|
|
30
30
|
// options (optional): BunshinCloneOptions
|
|
31
31
|
```
|
|
32
32
|
|
package/dist/index.cjs
CHANGED
|
@@ -3,124 +3,125 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
var EMPTY_OPTIONS = {};
|
|
5
5
|
var { hasOwnProperty: HAS_OWN } = Object.prototype;
|
|
6
|
-
function bunshinClone(
|
|
7
|
-
return clone(
|
|
6
|
+
function bunshinClone(value, options = EMPTY_OPTIONS, refs = /* @__PURE__ */ new WeakMap()) {
|
|
7
|
+
return clone(value, resolveOptions(options), refs);
|
|
8
8
|
}
|
|
9
|
-
function clone(
|
|
10
|
-
if (!isObject(
|
|
11
|
-
return
|
|
9
|
+
function clone(value, settings, refs) {
|
|
10
|
+
if (!isObject(value)) {
|
|
11
|
+
return value;
|
|
12
12
|
}
|
|
13
|
-
if (refs.has(
|
|
14
|
-
return refs.get(
|
|
13
|
+
if (refs.has(value)) {
|
|
14
|
+
return refs.get(value);
|
|
15
15
|
}
|
|
16
|
-
if (settings.preserveDescriptors && isPlainObject(
|
|
17
|
-
return cloneWithDescriptors(
|
|
16
|
+
if (settings.preserveDescriptors && isPlainObject(value)) {
|
|
17
|
+
return cloneWithDescriptors(value, settings, refs);
|
|
18
18
|
}
|
|
19
|
-
if (Array.isArray(
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
const { length } = value;
|
|
21
|
+
const result = new Array(length);
|
|
22
|
+
refs.set(value, result);
|
|
23
|
+
for (let i = 0; i < length; i++) {
|
|
24
|
+
result[i] = clone(value[i], settings, refs);
|
|
24
25
|
}
|
|
25
26
|
return result;
|
|
26
27
|
}
|
|
27
|
-
if (isPlainObject(
|
|
28
|
-
const result = Object.create(Object.getPrototypeOf(
|
|
29
|
-
refs.set(
|
|
30
|
-
for (const key in
|
|
31
|
-
if (HAS_OWN.call(
|
|
32
|
-
result[key] = clone(
|
|
28
|
+
if (isPlainObject(value)) {
|
|
29
|
+
const result = Object.create(Object.getPrototypeOf(value));
|
|
30
|
+
refs.set(value, result);
|
|
31
|
+
for (const key in value) {
|
|
32
|
+
if (HAS_OWN.call(value, key) && !isUnsafeKey(key)) {
|
|
33
|
+
result[key] = clone(value[key], settings, refs);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
return result;
|
|
36
37
|
}
|
|
37
|
-
if (
|
|
38
|
+
if (value instanceof Map) {
|
|
38
39
|
const result = /* @__PURE__ */ new Map();
|
|
39
|
-
refs.set(
|
|
40
|
-
for (const [key,
|
|
41
|
-
result.set(clone(key, settings, refs), clone(
|
|
40
|
+
refs.set(value, result);
|
|
41
|
+
for (const [key, v] of value) {
|
|
42
|
+
result.set(clone(key, settings, refs), clone(v, settings, refs));
|
|
42
43
|
}
|
|
43
44
|
return result;
|
|
44
45
|
}
|
|
45
|
-
if (
|
|
46
|
+
if (value instanceof Set) {
|
|
46
47
|
const result = /* @__PURE__ */ new Set();
|
|
47
|
-
refs.set(
|
|
48
|
-
for (const item of
|
|
48
|
+
refs.set(value, result);
|
|
49
|
+
for (const item of value) {
|
|
49
50
|
result.add(clone(item, settings, refs));
|
|
50
51
|
}
|
|
51
52
|
return result;
|
|
52
53
|
}
|
|
53
|
-
if (
|
|
54
|
-
const result = new Date(
|
|
55
|
-
refs.set(
|
|
54
|
+
if (value instanceof Date) {
|
|
55
|
+
const result = new Date(value.getTime());
|
|
56
|
+
refs.set(value, result);
|
|
56
57
|
return result;
|
|
57
58
|
}
|
|
58
|
-
if (
|
|
59
|
-
const result = new RegExp(
|
|
60
|
-
refs.set(
|
|
61
|
-
result.lastIndex =
|
|
59
|
+
if (value instanceof RegExp) {
|
|
60
|
+
const result = new RegExp(value.source, value.flags);
|
|
61
|
+
refs.set(value, result);
|
|
62
|
+
result.lastIndex = value.lastIndex;
|
|
62
63
|
return result;
|
|
63
64
|
}
|
|
64
|
-
if (
|
|
65
|
-
const result =
|
|
66
|
-
refs.set(
|
|
65
|
+
if (value instanceof ArrayBuffer) {
|
|
66
|
+
const result = value.slice(0);
|
|
67
|
+
refs.set(value, result);
|
|
67
68
|
return result;
|
|
68
69
|
}
|
|
69
|
-
if (ArrayBuffer.isView(
|
|
70
|
-
if (
|
|
71
|
-
const { buffer: buffer2, byteOffset: byteOffset2, byteLength } =
|
|
70
|
+
if (ArrayBuffer.isView(value)) {
|
|
71
|
+
if (value instanceof DataView) {
|
|
72
|
+
const { buffer: buffer2, byteOffset: byteOffset2, byteLength } = value;
|
|
72
73
|
const result2 = new DataView(
|
|
73
74
|
cloneBuffer(buffer2, refs),
|
|
74
75
|
byteOffset2,
|
|
75
76
|
byteLength
|
|
76
77
|
);
|
|
77
|
-
refs.set(
|
|
78
|
+
refs.set(value, result2);
|
|
78
79
|
return result2;
|
|
79
80
|
}
|
|
80
|
-
const view =
|
|
81
|
+
const view = value;
|
|
81
82
|
if (!settings.preserveBufferSharing) {
|
|
82
83
|
const Ctor2 = view.constructor;
|
|
83
84
|
const result2 = new Ctor2(view);
|
|
84
|
-
refs.set(
|
|
85
|
+
refs.set(value, result2);
|
|
85
86
|
return result2;
|
|
86
87
|
}
|
|
87
88
|
const Ctor = view.constructor;
|
|
88
89
|
const { buffer, byteOffset, length } = view;
|
|
89
90
|
const result = new Ctor(cloneBuffer(buffer, refs), byteOffset, length);
|
|
90
|
-
refs.set(
|
|
91
|
+
refs.set(value, result);
|
|
91
92
|
return result;
|
|
92
93
|
}
|
|
93
|
-
if (
|
|
94
|
-
return cloneError(
|
|
94
|
+
if (value instanceof DOMException || value instanceof Error) {
|
|
95
|
+
return cloneError(value, settings, refs);
|
|
95
96
|
}
|
|
96
|
-
if (
|
|
97
|
-
const result =
|
|
98
|
-
refs.set(
|
|
97
|
+
if (value instanceof Blob) {
|
|
98
|
+
const result = value.slice(0, value.size, value.type);
|
|
99
|
+
refs.set(value, result);
|
|
99
100
|
return result;
|
|
100
101
|
}
|
|
101
|
-
if (typeof ImageData !== "undefined" &&
|
|
102
|
-
const { data, width, height, colorSpace } =
|
|
102
|
+
if (typeof ImageData !== "undefined" && value instanceof ImageData) {
|
|
103
|
+
const { data, width, height, colorSpace } = value;
|
|
103
104
|
const result = new ImageData(new Uint8ClampedArray(data), width, height, {
|
|
104
105
|
colorSpace
|
|
105
106
|
});
|
|
106
|
-
refs.set(
|
|
107
|
+
refs.set(value, result);
|
|
107
108
|
return result;
|
|
108
109
|
}
|
|
109
|
-
if (
|
|
110
|
-
const result = new URL(
|
|
111
|
-
refs.set(
|
|
110
|
+
if (value instanceof URL) {
|
|
111
|
+
const result = new URL(value.href);
|
|
112
|
+
refs.set(value, result);
|
|
112
113
|
return result;
|
|
113
114
|
}
|
|
114
|
-
if (
|
|
115
|
+
if (value instanceof URLSearchParams) {
|
|
115
116
|
const result = new URLSearchParams();
|
|
116
|
-
refs.set(
|
|
117
|
-
for (const [key,
|
|
118
|
-
result.append(key,
|
|
117
|
+
refs.set(value, result);
|
|
118
|
+
for (const [key, v] of value) {
|
|
119
|
+
result.append(key, v);
|
|
119
120
|
}
|
|
120
121
|
return result;
|
|
121
122
|
}
|
|
122
|
-
refs.set(
|
|
123
|
-
return
|
|
123
|
+
refs.set(value, value);
|
|
124
|
+
return value;
|
|
124
125
|
}
|
|
125
126
|
function cloneBuffer(buffer, refs) {
|
|
126
127
|
if (refs.has(buffer)) {
|
|
@@ -130,31 +131,31 @@ function cloneBuffer(buffer, refs) {
|
|
|
130
131
|
refs.set(buffer, result);
|
|
131
132
|
return result;
|
|
132
133
|
}
|
|
133
|
-
function cloneError(
|
|
134
|
-
const result = createErrorInstance(
|
|
135
|
-
refs.set(
|
|
136
|
-
if (
|
|
134
|
+
function cloneError(error, settings, refs) {
|
|
135
|
+
const result = createErrorInstance(error, settings, refs);
|
|
136
|
+
refs.set(error, result);
|
|
137
|
+
if (error instanceof DOMException) {
|
|
137
138
|
return result;
|
|
138
139
|
}
|
|
139
|
-
const { stack, cause } =
|
|
140
|
+
const { stack, cause } = error;
|
|
140
141
|
if (stack) {
|
|
141
142
|
try {
|
|
142
143
|
result.stack = stack;
|
|
143
144
|
} catch {
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
|
-
if ("cause" in
|
|
147
|
+
if ("cause" in error && cause !== void 0) {
|
|
147
148
|
result.cause = clone(cause, settings, refs);
|
|
148
149
|
}
|
|
149
|
-
for (const key of Object.keys(
|
|
150
|
-
Reflect.set(result, key, clone(Reflect.get(
|
|
150
|
+
for (const key of Object.keys(error)) {
|
|
151
|
+
Reflect.set(result, key, clone(Reflect.get(error, key), settings, refs));
|
|
151
152
|
}
|
|
152
153
|
return result;
|
|
153
154
|
}
|
|
154
|
-
function cloneWithDescriptors(
|
|
155
|
-
const result = Object.create(Object.getPrototypeOf(
|
|
156
|
-
refs.set(
|
|
157
|
-
const descs = Object.getOwnPropertyDescriptors(
|
|
155
|
+
function cloneWithDescriptors(object, settings, refs) {
|
|
156
|
+
const result = Object.create(Object.getPrototypeOf(object));
|
|
157
|
+
refs.set(object, result);
|
|
158
|
+
const descs = Object.getOwnPropertyDescriptors(object);
|
|
158
159
|
forEachOwnKey(descs, (key) => {
|
|
159
160
|
if (isUnsafeKey(key)) {
|
|
160
161
|
return;
|
|
@@ -181,14 +182,14 @@ var ERROR_CTORS = {
|
|
|
181
182
|
TypeError,
|
|
182
183
|
URIError
|
|
183
184
|
};
|
|
184
|
-
function createErrorInstance(
|
|
185
|
-
const { message, name } =
|
|
186
|
-
if (
|
|
185
|
+
function createErrorInstance(error, settings, refs) {
|
|
186
|
+
const { message, name } = error;
|
|
187
|
+
if (error instanceof DOMException) {
|
|
187
188
|
return new DOMException(message, name);
|
|
188
189
|
}
|
|
189
|
-
if (
|
|
190
|
+
if (error instanceof AggregateError) {
|
|
190
191
|
return new AggregateError(
|
|
191
|
-
|
|
192
|
+
error.errors.map((e) => clone(e, settings, refs)),
|
|
192
193
|
message
|
|
193
194
|
);
|
|
194
195
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ interface BunshinCloneOptions {
|
|
|
5
5
|
}
|
|
6
6
|
type PlainObject = Record<PropertyKey, unknown>;
|
|
7
7
|
type Refs = WeakMap<object, unknown>;
|
|
8
|
-
declare function bunshinClone<T>(
|
|
8
|
+
declare function bunshinClone<T>(value: T, options?: Partial<BunshinCloneOptions>, refs?: Refs): T;
|
|
9
9
|
declare function forEachOwnKey(object: PlainObject, callback: (key: string | symbol) => void): void;
|
|
10
10
|
declare function isObject(value: unknown): value is object;
|
|
11
11
|
declare function isPlainObject(value: unknown): value is PlainObject;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ interface BunshinCloneOptions {
|
|
|
5
5
|
}
|
|
6
6
|
type PlainObject = Record<PropertyKey, unknown>;
|
|
7
7
|
type Refs = WeakMap<object, unknown>;
|
|
8
|
-
declare function bunshinClone<T>(
|
|
8
|
+
declare function bunshinClone<T>(value: T, options?: Partial<BunshinCloneOptions>, refs?: Refs): T;
|
|
9
9
|
declare function forEachOwnKey(object: PlainObject, callback: (key: string | symbol) => void): void;
|
|
10
10
|
declare function isObject(value: unknown): value is object;
|
|
11
11
|
declare function isPlainObject(value: unknown): value is PlainObject;
|
package/dist/index.js
CHANGED
|
@@ -1,124 +1,125 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
var EMPTY_OPTIONS = {};
|
|
3
3
|
var { hasOwnProperty: HAS_OWN } = Object.prototype;
|
|
4
|
-
function bunshinClone(
|
|
5
|
-
return clone(
|
|
4
|
+
function bunshinClone(value, options = EMPTY_OPTIONS, refs = /* @__PURE__ */ new WeakMap()) {
|
|
5
|
+
return clone(value, resolveOptions(options), refs);
|
|
6
6
|
}
|
|
7
|
-
function clone(
|
|
8
|
-
if (!isObject(
|
|
9
|
-
return
|
|
7
|
+
function clone(value, settings, refs) {
|
|
8
|
+
if (!isObject(value)) {
|
|
9
|
+
return value;
|
|
10
10
|
}
|
|
11
|
-
if (refs.has(
|
|
12
|
-
return refs.get(
|
|
11
|
+
if (refs.has(value)) {
|
|
12
|
+
return refs.get(value);
|
|
13
13
|
}
|
|
14
|
-
if (settings.preserveDescriptors && isPlainObject(
|
|
15
|
-
return cloneWithDescriptors(
|
|
14
|
+
if (settings.preserveDescriptors && isPlainObject(value)) {
|
|
15
|
+
return cloneWithDescriptors(value, settings, refs);
|
|
16
16
|
}
|
|
17
|
-
if (Array.isArray(
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
const { length } = value;
|
|
19
|
+
const result = new Array(length);
|
|
20
|
+
refs.set(value, result);
|
|
21
|
+
for (let i = 0; i < length; i++) {
|
|
22
|
+
result[i] = clone(value[i], settings, refs);
|
|
22
23
|
}
|
|
23
24
|
return result;
|
|
24
25
|
}
|
|
25
|
-
if (isPlainObject(
|
|
26
|
-
const result = Object.create(Object.getPrototypeOf(
|
|
27
|
-
refs.set(
|
|
28
|
-
for (const key in
|
|
29
|
-
if (HAS_OWN.call(
|
|
30
|
-
result[key] = clone(
|
|
26
|
+
if (isPlainObject(value)) {
|
|
27
|
+
const result = Object.create(Object.getPrototypeOf(value));
|
|
28
|
+
refs.set(value, result);
|
|
29
|
+
for (const key in value) {
|
|
30
|
+
if (HAS_OWN.call(value, key) && !isUnsafeKey(key)) {
|
|
31
|
+
result[key] = clone(value[key], settings, refs);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
return result;
|
|
34
35
|
}
|
|
35
|
-
if (
|
|
36
|
+
if (value instanceof Map) {
|
|
36
37
|
const result = /* @__PURE__ */ new Map();
|
|
37
|
-
refs.set(
|
|
38
|
-
for (const [key,
|
|
39
|
-
result.set(clone(key, settings, refs), clone(
|
|
38
|
+
refs.set(value, result);
|
|
39
|
+
for (const [key, v] of value) {
|
|
40
|
+
result.set(clone(key, settings, refs), clone(v, settings, refs));
|
|
40
41
|
}
|
|
41
42
|
return result;
|
|
42
43
|
}
|
|
43
|
-
if (
|
|
44
|
+
if (value instanceof Set) {
|
|
44
45
|
const result = /* @__PURE__ */ new Set();
|
|
45
|
-
refs.set(
|
|
46
|
-
for (const item of
|
|
46
|
+
refs.set(value, result);
|
|
47
|
+
for (const item of value) {
|
|
47
48
|
result.add(clone(item, settings, refs));
|
|
48
49
|
}
|
|
49
50
|
return result;
|
|
50
51
|
}
|
|
51
|
-
if (
|
|
52
|
-
const result = new Date(
|
|
53
|
-
refs.set(
|
|
52
|
+
if (value instanceof Date) {
|
|
53
|
+
const result = new Date(value.getTime());
|
|
54
|
+
refs.set(value, result);
|
|
54
55
|
return result;
|
|
55
56
|
}
|
|
56
|
-
if (
|
|
57
|
-
const result = new RegExp(
|
|
58
|
-
refs.set(
|
|
59
|
-
result.lastIndex =
|
|
57
|
+
if (value instanceof RegExp) {
|
|
58
|
+
const result = new RegExp(value.source, value.flags);
|
|
59
|
+
refs.set(value, result);
|
|
60
|
+
result.lastIndex = value.lastIndex;
|
|
60
61
|
return result;
|
|
61
62
|
}
|
|
62
|
-
if (
|
|
63
|
-
const result =
|
|
64
|
-
refs.set(
|
|
63
|
+
if (value instanceof ArrayBuffer) {
|
|
64
|
+
const result = value.slice(0);
|
|
65
|
+
refs.set(value, result);
|
|
65
66
|
return result;
|
|
66
67
|
}
|
|
67
|
-
if (ArrayBuffer.isView(
|
|
68
|
-
if (
|
|
69
|
-
const { buffer: buffer2, byteOffset: byteOffset2, byteLength } =
|
|
68
|
+
if (ArrayBuffer.isView(value)) {
|
|
69
|
+
if (value instanceof DataView) {
|
|
70
|
+
const { buffer: buffer2, byteOffset: byteOffset2, byteLength } = value;
|
|
70
71
|
const result2 = new DataView(
|
|
71
72
|
cloneBuffer(buffer2, refs),
|
|
72
73
|
byteOffset2,
|
|
73
74
|
byteLength
|
|
74
75
|
);
|
|
75
|
-
refs.set(
|
|
76
|
+
refs.set(value, result2);
|
|
76
77
|
return result2;
|
|
77
78
|
}
|
|
78
|
-
const view =
|
|
79
|
+
const view = value;
|
|
79
80
|
if (!settings.preserveBufferSharing) {
|
|
80
81
|
const Ctor2 = view.constructor;
|
|
81
82
|
const result2 = new Ctor2(view);
|
|
82
|
-
refs.set(
|
|
83
|
+
refs.set(value, result2);
|
|
83
84
|
return result2;
|
|
84
85
|
}
|
|
85
86
|
const Ctor = view.constructor;
|
|
86
87
|
const { buffer, byteOffset, length } = view;
|
|
87
88
|
const result = new Ctor(cloneBuffer(buffer, refs), byteOffset, length);
|
|
88
|
-
refs.set(
|
|
89
|
+
refs.set(value, result);
|
|
89
90
|
return result;
|
|
90
91
|
}
|
|
91
|
-
if (
|
|
92
|
-
return cloneError(
|
|
92
|
+
if (value instanceof DOMException || value instanceof Error) {
|
|
93
|
+
return cloneError(value, settings, refs);
|
|
93
94
|
}
|
|
94
|
-
if (
|
|
95
|
-
const result =
|
|
96
|
-
refs.set(
|
|
95
|
+
if (value instanceof Blob) {
|
|
96
|
+
const result = value.slice(0, value.size, value.type);
|
|
97
|
+
refs.set(value, result);
|
|
97
98
|
return result;
|
|
98
99
|
}
|
|
99
|
-
if (typeof ImageData !== "undefined" &&
|
|
100
|
-
const { data, width, height, colorSpace } =
|
|
100
|
+
if (typeof ImageData !== "undefined" && value instanceof ImageData) {
|
|
101
|
+
const { data, width, height, colorSpace } = value;
|
|
101
102
|
const result = new ImageData(new Uint8ClampedArray(data), width, height, {
|
|
102
103
|
colorSpace
|
|
103
104
|
});
|
|
104
|
-
refs.set(
|
|
105
|
+
refs.set(value, result);
|
|
105
106
|
return result;
|
|
106
107
|
}
|
|
107
|
-
if (
|
|
108
|
-
const result = new URL(
|
|
109
|
-
refs.set(
|
|
108
|
+
if (value instanceof URL) {
|
|
109
|
+
const result = new URL(value.href);
|
|
110
|
+
refs.set(value, result);
|
|
110
111
|
return result;
|
|
111
112
|
}
|
|
112
|
-
if (
|
|
113
|
+
if (value instanceof URLSearchParams) {
|
|
113
114
|
const result = new URLSearchParams();
|
|
114
|
-
refs.set(
|
|
115
|
-
for (const [key,
|
|
116
|
-
result.append(key,
|
|
115
|
+
refs.set(value, result);
|
|
116
|
+
for (const [key, v] of value) {
|
|
117
|
+
result.append(key, v);
|
|
117
118
|
}
|
|
118
119
|
return result;
|
|
119
120
|
}
|
|
120
|
-
refs.set(
|
|
121
|
-
return
|
|
121
|
+
refs.set(value, value);
|
|
122
|
+
return value;
|
|
122
123
|
}
|
|
123
124
|
function cloneBuffer(buffer, refs) {
|
|
124
125
|
if (refs.has(buffer)) {
|
|
@@ -128,31 +129,31 @@ function cloneBuffer(buffer, refs) {
|
|
|
128
129
|
refs.set(buffer, result);
|
|
129
130
|
return result;
|
|
130
131
|
}
|
|
131
|
-
function cloneError(
|
|
132
|
-
const result = createErrorInstance(
|
|
133
|
-
refs.set(
|
|
134
|
-
if (
|
|
132
|
+
function cloneError(error, settings, refs) {
|
|
133
|
+
const result = createErrorInstance(error, settings, refs);
|
|
134
|
+
refs.set(error, result);
|
|
135
|
+
if (error instanceof DOMException) {
|
|
135
136
|
return result;
|
|
136
137
|
}
|
|
137
|
-
const { stack, cause } =
|
|
138
|
+
const { stack, cause } = error;
|
|
138
139
|
if (stack) {
|
|
139
140
|
try {
|
|
140
141
|
result.stack = stack;
|
|
141
142
|
} catch {
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
|
-
if ("cause" in
|
|
145
|
+
if ("cause" in error && cause !== void 0) {
|
|
145
146
|
result.cause = clone(cause, settings, refs);
|
|
146
147
|
}
|
|
147
|
-
for (const key of Object.keys(
|
|
148
|
-
Reflect.set(result, key, clone(Reflect.get(
|
|
148
|
+
for (const key of Object.keys(error)) {
|
|
149
|
+
Reflect.set(result, key, clone(Reflect.get(error, key), settings, refs));
|
|
149
150
|
}
|
|
150
151
|
return result;
|
|
151
152
|
}
|
|
152
|
-
function cloneWithDescriptors(
|
|
153
|
-
const result = Object.create(Object.getPrototypeOf(
|
|
154
|
-
refs.set(
|
|
155
|
-
const descs = Object.getOwnPropertyDescriptors(
|
|
153
|
+
function cloneWithDescriptors(object, settings, refs) {
|
|
154
|
+
const result = Object.create(Object.getPrototypeOf(object));
|
|
155
|
+
refs.set(object, result);
|
|
156
|
+
const descs = Object.getOwnPropertyDescriptors(object);
|
|
156
157
|
forEachOwnKey(descs, (key) => {
|
|
157
158
|
if (isUnsafeKey(key)) {
|
|
158
159
|
return;
|
|
@@ -179,14 +180,14 @@ var ERROR_CTORS = {
|
|
|
179
180
|
TypeError,
|
|
180
181
|
URIError
|
|
181
182
|
};
|
|
182
|
-
function createErrorInstance(
|
|
183
|
-
const { message, name } =
|
|
184
|
-
if (
|
|
183
|
+
function createErrorInstance(error, settings, refs) {
|
|
184
|
+
const { message, name } = error;
|
|
185
|
+
if (error instanceof DOMException) {
|
|
185
186
|
return new DOMException(message, name);
|
|
186
187
|
}
|
|
187
|
-
if (
|
|
188
|
+
if (error instanceof AggregateError) {
|
|
188
189
|
return new AggregateError(
|
|
189
|
-
|
|
190
|
+
error.errors.map((e) => clone(e, settings, refs)),
|
|
190
191
|
message
|
|
191
192
|
);
|
|
192
193
|
}
|