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