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