@optique/core 1.0.0-dev.1864 → 1.0.0-dev.1868
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/annotations.cjs +163 -20
- package/dist/annotations.js +163 -20
- package/package.json +1 -1
package/dist/annotations.cjs
CHANGED
|
@@ -87,9 +87,9 @@ function defineProtectedDataProperty(context, target, key, descriptor) {
|
|
|
87
87
|
set: () => throwReadonlyAnnotationMutation()
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
function copyOwnProperties(source, target, transformValue, excludedKeys) {
|
|
90
|
+
function copyOwnProperties(source, target, transformValue, excludedKeys, syncPrototype = true) {
|
|
91
91
|
const sourcePrototype = Object.getPrototypeOf(source);
|
|
92
|
-
if (Object.getPrototypeOf(target) !== sourcePrototype) Object.setPrototypeOf(target, sourcePrototype);
|
|
92
|
+
if (syncPrototype && Object.getPrototypeOf(target) !== sourcePrototype) Object.setPrototypeOf(target, sourcePrototype);
|
|
93
93
|
for (const key of Reflect.ownKeys(source)) {
|
|
94
94
|
if (excludedKeys?.has(key) === true) continue;
|
|
95
95
|
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
@@ -107,14 +107,146 @@ function copyOwnProperties(source, target, transformValue, excludedKeys) {
|
|
|
107
107
|
function normalizeProtectedCollectionItem(value, context) {
|
|
108
108
|
return context.rewrapProtectedViews && isProtectedAnnotationView(value) ? unwrapProtectedAnnotationTarget(value) : value;
|
|
109
109
|
}
|
|
110
|
+
function resolveCloneConstructor(source) {
|
|
111
|
+
const constructorValue = source.constructor;
|
|
112
|
+
if (typeof constructorValue !== "function") return void 0;
|
|
113
|
+
const species = Reflect.get(constructorValue, Symbol.species);
|
|
114
|
+
const cloneConstructor = species == null ? constructorValue : species;
|
|
115
|
+
return typeof cloneConstructor === "function" ? cloneConstructor : void 0;
|
|
116
|
+
}
|
|
117
|
+
function hasBuiltInSubclassPrototype(target, basePrototype) {
|
|
118
|
+
return Object.getPrototypeOf(target) !== basePrototype;
|
|
119
|
+
}
|
|
120
|
+
function tryCloneMapSubclass(source, entries) {
|
|
121
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
122
|
+
if (cloneConstructor == null) return void 0;
|
|
123
|
+
try {
|
|
124
|
+
const cloned = new cloneConstructor(entries);
|
|
125
|
+
return cloned instanceof Map ? cloned : void 0;
|
|
126
|
+
} catch {
|
|
127
|
+
return void 0;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function tryCloneSetSubclass(source, values) {
|
|
131
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
132
|
+
if (cloneConstructor == null) return void 0;
|
|
133
|
+
try {
|
|
134
|
+
const cloned = new cloneConstructor(values);
|
|
135
|
+
return cloned instanceof Set ? cloned : void 0;
|
|
136
|
+
} catch {
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function tryCloneDateSubclass(source) {
|
|
141
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
142
|
+
if (cloneConstructor == null) return void 0;
|
|
143
|
+
try {
|
|
144
|
+
const cloned = new cloneConstructor(source.getTime());
|
|
145
|
+
return cloned instanceof Date ? cloned : void 0;
|
|
146
|
+
} catch {
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function tryCloneRegExpSubclass(source) {
|
|
151
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
152
|
+
if (cloneConstructor == null) return void 0;
|
|
153
|
+
try {
|
|
154
|
+
const cloned = new cloneConstructor(source.source, source.flags);
|
|
155
|
+
return cloned instanceof RegExp ? cloned : void 0;
|
|
156
|
+
} catch {
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function tryCloneURLSearchParamsSubclass(source) {
|
|
161
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
162
|
+
if (cloneConstructor == null) return void 0;
|
|
163
|
+
try {
|
|
164
|
+
const cloned = new cloneConstructor(source);
|
|
165
|
+
return cloned instanceof URLSearchParams ? cloned : void 0;
|
|
166
|
+
} catch {
|
|
167
|
+
return void 0;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function tryCloneURLSubclass(source) {
|
|
171
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
172
|
+
if (cloneConstructor == null) return void 0;
|
|
173
|
+
try {
|
|
174
|
+
const cloned = new cloneConstructor(source.href);
|
|
175
|
+
return cloned instanceof URL ? cloned : void 0;
|
|
176
|
+
} catch {
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
110
180
|
const regExpExcludedKeys = new Set(["lastIndex"]);
|
|
111
|
-
|
|
112
|
-
|
|
181
|
+
const mapMutationMethodKeys = [
|
|
182
|
+
"set",
|
|
183
|
+
"delete",
|
|
184
|
+
"clear"
|
|
185
|
+
];
|
|
186
|
+
const setMutationMethodKeys = [
|
|
187
|
+
"add",
|
|
188
|
+
"delete",
|
|
189
|
+
"clear"
|
|
190
|
+
];
|
|
191
|
+
const urlSearchParamsMutationMethodKeys = [
|
|
192
|
+
"append",
|
|
193
|
+
"delete",
|
|
194
|
+
"set",
|
|
195
|
+
"sort"
|
|
196
|
+
];
|
|
197
|
+
const urlMutationPropertyKeys = [
|
|
198
|
+
"hash",
|
|
199
|
+
"host",
|
|
200
|
+
"hostname",
|
|
201
|
+
"href",
|
|
202
|
+
"password",
|
|
203
|
+
"pathname",
|
|
204
|
+
"port",
|
|
205
|
+
"protocol",
|
|
206
|
+
"search",
|
|
207
|
+
"username"
|
|
208
|
+
];
|
|
209
|
+
const dateMutationMethodKeys = Object.getOwnPropertyNames(Date.prototype).filter((key) => key.startsWith("set"));
|
|
210
|
+
function installReadonlyMutationMethodGuards(target, keys) {
|
|
211
|
+
for (const key of keys) {
|
|
212
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
213
|
+
if (descriptor?.configurable === false) continue;
|
|
214
|
+
Object.defineProperty(target, key, {
|
|
215
|
+
configurable: true,
|
|
216
|
+
enumerable: false,
|
|
217
|
+
writable: true,
|
|
218
|
+
value: (..._args) => throwReadonlyAnnotationMutation()
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function installReadonlyURLGuards(target, context) {
|
|
223
|
+
const searchParams = target.searchParams;
|
|
224
|
+
const searchParamsDescriptor = Object.getOwnPropertyDescriptor(target, "searchParams");
|
|
225
|
+
if (searchParamsDescriptor?.configurable !== false) Object.defineProperty(target, "searchParams", {
|
|
226
|
+
configurable: true,
|
|
227
|
+
enumerable: false,
|
|
228
|
+
get: () => protectAnnotationValue(searchParams, context),
|
|
229
|
+
set: () => throwReadonlyAnnotationMutation()
|
|
230
|
+
});
|
|
231
|
+
for (const key of urlMutationPropertyKeys) {
|
|
232
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
233
|
+
if (descriptor?.configurable === false) continue;
|
|
234
|
+
Object.defineProperty(target, key, {
|
|
235
|
+
configurable: true,
|
|
236
|
+
enumerable: false,
|
|
237
|
+
get: () => Reflect.get(URL.prototype, key, target),
|
|
238
|
+
set: () => throwReadonlyAnnotationMutation()
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function copyRegExpMetadata(source, target, transformValue, syncPrototype = true) {
|
|
243
|
+
copyOwnProperties(source, target, transformValue, regExpExcludedKeys, syncPrototype);
|
|
113
244
|
target.lastIndex = source.lastIndex;
|
|
114
245
|
}
|
|
115
246
|
function cloneRegExpShape(source) {
|
|
116
|
-
const
|
|
117
|
-
|
|
247
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(source, RegExp.prototype);
|
|
248
|
+
const cloned = syncPrototype ? new RegExp(source) : tryCloneRegExpSubclass(source) ?? new RegExp(source);
|
|
249
|
+
copyRegExpMetadata(source, cloned, void 0, syncPrototype);
|
|
118
250
|
return cloned;
|
|
119
251
|
}
|
|
120
252
|
function createProtectedObjectView(target, context) {
|
|
@@ -158,9 +290,10 @@ function createProtectedObjectView(target, context) {
|
|
|
158
290
|
return Object.freeze(view);
|
|
159
291
|
}
|
|
160
292
|
function createProtectedMapView(target, context) {
|
|
293
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, Map.prototype);
|
|
294
|
+
const entries = [...target.entries()].map(([entryKey, entryValue]) => [normalizeProtectedCollectionItem(entryKey, context), normalizeProtectedCollectionItem(entryValue, context)]);
|
|
161
295
|
const methodCache = /* @__PURE__ */ new Map();
|
|
162
|
-
const cloned =
|
|
163
|
-
for (const [entryKey, entryValue] of target.entries()) cloned.set(normalizeProtectedCollectionItem(entryKey, context), normalizeProtectedCollectionItem(entryValue, context));
|
|
296
|
+
const cloned = syncPrototype ? new Map(entries) : tryCloneMapSubclass(target, entries) ?? new Map(entries);
|
|
164
297
|
const view = new Proxy(cloned, {
|
|
165
298
|
get(clonedTarget, key) {
|
|
166
299
|
if (key === "size") return clonedTarget.size;
|
|
@@ -204,13 +337,15 @@ function createProtectedMapView(target, context) {
|
|
|
204
337
|
});
|
|
205
338
|
registerProtectedAnnotationView(context, target, view);
|
|
206
339
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
207
|
-
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
340
|
+
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
|
|
341
|
+
installReadonlyMutationMethodGuards(cloned, mapMutationMethodKeys);
|
|
208
342
|
return view;
|
|
209
343
|
}
|
|
210
344
|
function createProtectedSetView(target, context) {
|
|
345
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, Set.prototype);
|
|
346
|
+
const values = [...target.values()].map((value) => normalizeProtectedCollectionItem(value, context));
|
|
211
347
|
const methodCache = /* @__PURE__ */ new Map();
|
|
212
|
-
const cloned =
|
|
213
|
-
for (const value of target.values()) cloned.add(normalizeProtectedCollectionItem(value, context));
|
|
348
|
+
const cloned = syncPrototype ? new Set(values) : tryCloneSetSubclass(target, values) ?? new Set(values);
|
|
214
349
|
const view = new Proxy(cloned, {
|
|
215
350
|
get(clonedTarget, key) {
|
|
216
351
|
if (key === "size") return clonedTarget.size;
|
|
@@ -251,12 +386,14 @@ function createProtectedSetView(target, context) {
|
|
|
251
386
|
});
|
|
252
387
|
registerProtectedAnnotationView(context, target, view);
|
|
253
388
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
254
|
-
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
389
|
+
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
|
|
390
|
+
installReadonlyMutationMethodGuards(cloned, setMutationMethodKeys);
|
|
255
391
|
return view;
|
|
256
392
|
}
|
|
257
393
|
function createProtectedDateView(target, context) {
|
|
394
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, Date.prototype);
|
|
258
395
|
const methodCache = /* @__PURE__ */ new Map();
|
|
259
|
-
const cloned = new Date(target.getTime());
|
|
396
|
+
const cloned = syncPrototype ? new Date(target.getTime()) : tryCloneDateSubclass(target) ?? new Date(target.getTime());
|
|
260
397
|
const view = new Proxy(cloned, {
|
|
261
398
|
get(clonedTarget, key) {
|
|
262
399
|
const value = Reflect.get(clonedTarget, key, clonedTarget);
|
|
@@ -281,12 +418,14 @@ function createProtectedDateView(target, context) {
|
|
|
281
418
|
});
|
|
282
419
|
registerProtectedAnnotationView(context, target, view);
|
|
283
420
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
284
|
-
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
421
|
+
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
|
|
422
|
+
installReadonlyMutationMethodGuards(cloned, dateMutationMethodKeys);
|
|
285
423
|
return view;
|
|
286
424
|
}
|
|
287
425
|
function createProtectedRegExpView(target, context) {
|
|
426
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, RegExp.prototype);
|
|
288
427
|
const methodCache = /* @__PURE__ */ new Map();
|
|
289
|
-
const cloned = new RegExp(target);
|
|
428
|
+
const cloned = syncPrototype ? new RegExp(target) : tryCloneRegExpSubclass(target) ?? new RegExp(target);
|
|
290
429
|
const view = new Proxy(cloned, {
|
|
291
430
|
get(clonedTarget, key) {
|
|
292
431
|
if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
@@ -314,12 +453,13 @@ function createProtectedRegExpView(target, context) {
|
|
|
314
453
|
});
|
|
315
454
|
registerProtectedAnnotationView(context, target, view);
|
|
316
455
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
317
|
-
copyRegExpMetadata(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
456
|
+
copyRegExpMetadata(target, cloned, (value) => protectAnnotationValue(value, context), syncPrototype);
|
|
318
457
|
return view;
|
|
319
458
|
}
|
|
320
459
|
function createProtectedURLSearchParamsView(target, context) {
|
|
460
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, URLSearchParams.prototype);
|
|
321
461
|
const methodCache = /* @__PURE__ */ new Map();
|
|
322
|
-
const cloned = new URLSearchParams(target);
|
|
462
|
+
const cloned = syncPrototype ? new URLSearchParams(target) : tryCloneURLSearchParamsSubclass(target) ?? new URLSearchParams(target);
|
|
323
463
|
const view = new Proxy(cloned, {
|
|
324
464
|
get(clonedTarget, key) {
|
|
325
465
|
if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
@@ -355,11 +495,13 @@ function createProtectedURLSearchParamsView(target, context) {
|
|
|
355
495
|
});
|
|
356
496
|
registerProtectedAnnotationView(context, target, view);
|
|
357
497
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
358
|
-
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
498
|
+
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
|
|
499
|
+
installReadonlyMutationMethodGuards(cloned, urlSearchParamsMutationMethodKeys);
|
|
359
500
|
return view;
|
|
360
501
|
}
|
|
361
502
|
function createProtectedURLView(target, context) {
|
|
362
|
-
const
|
|
503
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, URL.prototype);
|
|
504
|
+
const cloned = syncPrototype ? new URL(target.href) : tryCloneURLSubclass(target) ?? new URL(target.href);
|
|
363
505
|
const view = new Proxy(cloned, {
|
|
364
506
|
get(clonedTarget, key) {
|
|
365
507
|
if (key === "valueOf") return () => view;
|
|
@@ -385,7 +527,8 @@ function createProtectedURLView(target, context) {
|
|
|
385
527
|
});
|
|
386
528
|
registerProtectedAnnotationView(context, target, view);
|
|
387
529
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
388
|
-
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
530
|
+
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
|
|
531
|
+
installReadonlyURLGuards(cloned, context);
|
|
389
532
|
return view;
|
|
390
533
|
}
|
|
391
534
|
function protectAnnotationValue(value, context) {
|
package/dist/annotations.js
CHANGED
|
@@ -86,9 +86,9 @@ function defineProtectedDataProperty(context, target, key, descriptor) {
|
|
|
86
86
|
set: () => throwReadonlyAnnotationMutation()
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
function copyOwnProperties(source, target, transformValue, excludedKeys) {
|
|
89
|
+
function copyOwnProperties(source, target, transformValue, excludedKeys, syncPrototype = true) {
|
|
90
90
|
const sourcePrototype = Object.getPrototypeOf(source);
|
|
91
|
-
if (Object.getPrototypeOf(target) !== sourcePrototype) Object.setPrototypeOf(target, sourcePrototype);
|
|
91
|
+
if (syncPrototype && Object.getPrototypeOf(target) !== sourcePrototype) Object.setPrototypeOf(target, sourcePrototype);
|
|
92
92
|
for (const key of Reflect.ownKeys(source)) {
|
|
93
93
|
if (excludedKeys?.has(key) === true) continue;
|
|
94
94
|
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
@@ -106,14 +106,146 @@ function copyOwnProperties(source, target, transformValue, excludedKeys) {
|
|
|
106
106
|
function normalizeProtectedCollectionItem(value, context) {
|
|
107
107
|
return context.rewrapProtectedViews && isProtectedAnnotationView(value) ? unwrapProtectedAnnotationTarget(value) : value;
|
|
108
108
|
}
|
|
109
|
+
function resolveCloneConstructor(source) {
|
|
110
|
+
const constructorValue = source.constructor;
|
|
111
|
+
if (typeof constructorValue !== "function") return void 0;
|
|
112
|
+
const species = Reflect.get(constructorValue, Symbol.species);
|
|
113
|
+
const cloneConstructor = species == null ? constructorValue : species;
|
|
114
|
+
return typeof cloneConstructor === "function" ? cloneConstructor : void 0;
|
|
115
|
+
}
|
|
116
|
+
function hasBuiltInSubclassPrototype(target, basePrototype) {
|
|
117
|
+
return Object.getPrototypeOf(target) !== basePrototype;
|
|
118
|
+
}
|
|
119
|
+
function tryCloneMapSubclass(source, entries) {
|
|
120
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
121
|
+
if (cloneConstructor == null) return void 0;
|
|
122
|
+
try {
|
|
123
|
+
const cloned = new cloneConstructor(entries);
|
|
124
|
+
return cloned instanceof Map ? cloned : void 0;
|
|
125
|
+
} catch {
|
|
126
|
+
return void 0;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function tryCloneSetSubclass(source, values) {
|
|
130
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
131
|
+
if (cloneConstructor == null) return void 0;
|
|
132
|
+
try {
|
|
133
|
+
const cloned = new cloneConstructor(values);
|
|
134
|
+
return cloned instanceof Set ? cloned : void 0;
|
|
135
|
+
} catch {
|
|
136
|
+
return void 0;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function tryCloneDateSubclass(source) {
|
|
140
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
141
|
+
if (cloneConstructor == null) return void 0;
|
|
142
|
+
try {
|
|
143
|
+
const cloned = new cloneConstructor(source.getTime());
|
|
144
|
+
return cloned instanceof Date ? cloned : void 0;
|
|
145
|
+
} catch {
|
|
146
|
+
return void 0;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function tryCloneRegExpSubclass(source) {
|
|
150
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
151
|
+
if (cloneConstructor == null) return void 0;
|
|
152
|
+
try {
|
|
153
|
+
const cloned = new cloneConstructor(source.source, source.flags);
|
|
154
|
+
return cloned instanceof RegExp ? cloned : void 0;
|
|
155
|
+
} catch {
|
|
156
|
+
return void 0;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function tryCloneURLSearchParamsSubclass(source) {
|
|
160
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
161
|
+
if (cloneConstructor == null) return void 0;
|
|
162
|
+
try {
|
|
163
|
+
const cloned = new cloneConstructor(source);
|
|
164
|
+
return cloned instanceof URLSearchParams ? cloned : void 0;
|
|
165
|
+
} catch {
|
|
166
|
+
return void 0;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function tryCloneURLSubclass(source) {
|
|
170
|
+
const cloneConstructor = resolveCloneConstructor(source);
|
|
171
|
+
if (cloneConstructor == null) return void 0;
|
|
172
|
+
try {
|
|
173
|
+
const cloned = new cloneConstructor(source.href);
|
|
174
|
+
return cloned instanceof URL ? cloned : void 0;
|
|
175
|
+
} catch {
|
|
176
|
+
return void 0;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
109
179
|
const regExpExcludedKeys = new Set(["lastIndex"]);
|
|
110
|
-
|
|
111
|
-
|
|
180
|
+
const mapMutationMethodKeys = [
|
|
181
|
+
"set",
|
|
182
|
+
"delete",
|
|
183
|
+
"clear"
|
|
184
|
+
];
|
|
185
|
+
const setMutationMethodKeys = [
|
|
186
|
+
"add",
|
|
187
|
+
"delete",
|
|
188
|
+
"clear"
|
|
189
|
+
];
|
|
190
|
+
const urlSearchParamsMutationMethodKeys = [
|
|
191
|
+
"append",
|
|
192
|
+
"delete",
|
|
193
|
+
"set",
|
|
194
|
+
"sort"
|
|
195
|
+
];
|
|
196
|
+
const urlMutationPropertyKeys = [
|
|
197
|
+
"hash",
|
|
198
|
+
"host",
|
|
199
|
+
"hostname",
|
|
200
|
+
"href",
|
|
201
|
+
"password",
|
|
202
|
+
"pathname",
|
|
203
|
+
"port",
|
|
204
|
+
"protocol",
|
|
205
|
+
"search",
|
|
206
|
+
"username"
|
|
207
|
+
];
|
|
208
|
+
const dateMutationMethodKeys = Object.getOwnPropertyNames(Date.prototype).filter((key) => key.startsWith("set"));
|
|
209
|
+
function installReadonlyMutationMethodGuards(target, keys) {
|
|
210
|
+
for (const key of keys) {
|
|
211
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
212
|
+
if (descriptor?.configurable === false) continue;
|
|
213
|
+
Object.defineProperty(target, key, {
|
|
214
|
+
configurable: true,
|
|
215
|
+
enumerable: false,
|
|
216
|
+
writable: true,
|
|
217
|
+
value: (..._args) => throwReadonlyAnnotationMutation()
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function installReadonlyURLGuards(target, context) {
|
|
222
|
+
const searchParams = target.searchParams;
|
|
223
|
+
const searchParamsDescriptor = Object.getOwnPropertyDescriptor(target, "searchParams");
|
|
224
|
+
if (searchParamsDescriptor?.configurable !== false) Object.defineProperty(target, "searchParams", {
|
|
225
|
+
configurable: true,
|
|
226
|
+
enumerable: false,
|
|
227
|
+
get: () => protectAnnotationValue(searchParams, context),
|
|
228
|
+
set: () => throwReadonlyAnnotationMutation()
|
|
229
|
+
});
|
|
230
|
+
for (const key of urlMutationPropertyKeys) {
|
|
231
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
232
|
+
if (descriptor?.configurable === false) continue;
|
|
233
|
+
Object.defineProperty(target, key, {
|
|
234
|
+
configurable: true,
|
|
235
|
+
enumerable: false,
|
|
236
|
+
get: () => Reflect.get(URL.prototype, key, target),
|
|
237
|
+
set: () => throwReadonlyAnnotationMutation()
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function copyRegExpMetadata(source, target, transformValue, syncPrototype = true) {
|
|
242
|
+
copyOwnProperties(source, target, transformValue, regExpExcludedKeys, syncPrototype);
|
|
112
243
|
target.lastIndex = source.lastIndex;
|
|
113
244
|
}
|
|
114
245
|
function cloneRegExpShape(source) {
|
|
115
|
-
const
|
|
116
|
-
|
|
246
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(source, RegExp.prototype);
|
|
247
|
+
const cloned = syncPrototype ? new RegExp(source) : tryCloneRegExpSubclass(source) ?? new RegExp(source);
|
|
248
|
+
copyRegExpMetadata(source, cloned, void 0, syncPrototype);
|
|
117
249
|
return cloned;
|
|
118
250
|
}
|
|
119
251
|
function createProtectedObjectView(target, context) {
|
|
@@ -157,9 +289,10 @@ function createProtectedObjectView(target, context) {
|
|
|
157
289
|
return Object.freeze(view);
|
|
158
290
|
}
|
|
159
291
|
function createProtectedMapView(target, context) {
|
|
292
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, Map.prototype);
|
|
293
|
+
const entries = [...target.entries()].map(([entryKey, entryValue]) => [normalizeProtectedCollectionItem(entryKey, context), normalizeProtectedCollectionItem(entryValue, context)]);
|
|
160
294
|
const methodCache = /* @__PURE__ */ new Map();
|
|
161
|
-
const cloned =
|
|
162
|
-
for (const [entryKey, entryValue] of target.entries()) cloned.set(normalizeProtectedCollectionItem(entryKey, context), normalizeProtectedCollectionItem(entryValue, context));
|
|
295
|
+
const cloned = syncPrototype ? new Map(entries) : tryCloneMapSubclass(target, entries) ?? new Map(entries);
|
|
163
296
|
const view = new Proxy(cloned, {
|
|
164
297
|
get(clonedTarget, key) {
|
|
165
298
|
if (key === "size") return clonedTarget.size;
|
|
@@ -203,13 +336,15 @@ function createProtectedMapView(target, context) {
|
|
|
203
336
|
});
|
|
204
337
|
registerProtectedAnnotationView(context, target, view);
|
|
205
338
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
206
|
-
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
339
|
+
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
|
|
340
|
+
installReadonlyMutationMethodGuards(cloned, mapMutationMethodKeys);
|
|
207
341
|
return view;
|
|
208
342
|
}
|
|
209
343
|
function createProtectedSetView(target, context) {
|
|
344
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, Set.prototype);
|
|
345
|
+
const values = [...target.values()].map((value) => normalizeProtectedCollectionItem(value, context));
|
|
210
346
|
const methodCache = /* @__PURE__ */ new Map();
|
|
211
|
-
const cloned =
|
|
212
|
-
for (const value of target.values()) cloned.add(normalizeProtectedCollectionItem(value, context));
|
|
347
|
+
const cloned = syncPrototype ? new Set(values) : tryCloneSetSubclass(target, values) ?? new Set(values);
|
|
213
348
|
const view = new Proxy(cloned, {
|
|
214
349
|
get(clonedTarget, key) {
|
|
215
350
|
if (key === "size") return clonedTarget.size;
|
|
@@ -250,12 +385,14 @@ function createProtectedSetView(target, context) {
|
|
|
250
385
|
});
|
|
251
386
|
registerProtectedAnnotationView(context, target, view);
|
|
252
387
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
253
|
-
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
388
|
+
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
|
|
389
|
+
installReadonlyMutationMethodGuards(cloned, setMutationMethodKeys);
|
|
254
390
|
return view;
|
|
255
391
|
}
|
|
256
392
|
function createProtectedDateView(target, context) {
|
|
393
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, Date.prototype);
|
|
257
394
|
const methodCache = /* @__PURE__ */ new Map();
|
|
258
|
-
const cloned = new Date(target.getTime());
|
|
395
|
+
const cloned = syncPrototype ? new Date(target.getTime()) : tryCloneDateSubclass(target) ?? new Date(target.getTime());
|
|
259
396
|
const view = new Proxy(cloned, {
|
|
260
397
|
get(clonedTarget, key) {
|
|
261
398
|
const value = Reflect.get(clonedTarget, key, clonedTarget);
|
|
@@ -280,12 +417,14 @@ function createProtectedDateView(target, context) {
|
|
|
280
417
|
});
|
|
281
418
|
registerProtectedAnnotationView(context, target, view);
|
|
282
419
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
283
|
-
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
420
|
+
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
|
|
421
|
+
installReadonlyMutationMethodGuards(cloned, dateMutationMethodKeys);
|
|
284
422
|
return view;
|
|
285
423
|
}
|
|
286
424
|
function createProtectedRegExpView(target, context) {
|
|
425
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, RegExp.prototype);
|
|
287
426
|
const methodCache = /* @__PURE__ */ new Map();
|
|
288
|
-
const cloned = new RegExp(target);
|
|
427
|
+
const cloned = syncPrototype ? new RegExp(target) : tryCloneRegExpSubclass(target) ?? new RegExp(target);
|
|
289
428
|
const view = new Proxy(cloned, {
|
|
290
429
|
get(clonedTarget, key) {
|
|
291
430
|
if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
@@ -313,12 +452,13 @@ function createProtectedRegExpView(target, context) {
|
|
|
313
452
|
});
|
|
314
453
|
registerProtectedAnnotationView(context, target, view);
|
|
315
454
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
316
|
-
copyRegExpMetadata(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
455
|
+
copyRegExpMetadata(target, cloned, (value) => protectAnnotationValue(value, context), syncPrototype);
|
|
317
456
|
return view;
|
|
318
457
|
}
|
|
319
458
|
function createProtectedURLSearchParamsView(target, context) {
|
|
459
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, URLSearchParams.prototype);
|
|
320
460
|
const methodCache = /* @__PURE__ */ new Map();
|
|
321
|
-
const cloned = new URLSearchParams(target);
|
|
461
|
+
const cloned = syncPrototype ? new URLSearchParams(target) : tryCloneURLSearchParamsSubclass(target) ?? new URLSearchParams(target);
|
|
322
462
|
const view = new Proxy(cloned, {
|
|
323
463
|
get(clonedTarget, key) {
|
|
324
464
|
if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
@@ -354,11 +494,13 @@ function createProtectedURLSearchParamsView(target, context) {
|
|
|
354
494
|
});
|
|
355
495
|
registerProtectedAnnotationView(context, target, view);
|
|
356
496
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
357
|
-
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
497
|
+
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
|
|
498
|
+
installReadonlyMutationMethodGuards(cloned, urlSearchParamsMutationMethodKeys);
|
|
358
499
|
return view;
|
|
359
500
|
}
|
|
360
501
|
function createProtectedURLView(target, context) {
|
|
361
|
-
const
|
|
502
|
+
const syncPrototype = !hasBuiltInSubclassPrototype(target, URL.prototype);
|
|
503
|
+
const cloned = syncPrototype ? new URL(target.href) : tryCloneURLSubclass(target) ?? new URL(target.href);
|
|
362
504
|
const view = new Proxy(cloned, {
|
|
363
505
|
get(clonedTarget, key) {
|
|
364
506
|
if (key === "valueOf") return () => view;
|
|
@@ -384,7 +526,8 @@ function createProtectedURLView(target, context) {
|
|
|
384
526
|
});
|
|
385
527
|
registerProtectedAnnotationView(context, target, view);
|
|
386
528
|
cacheProtectedAnnotationViewAlias(context, cloned, view);
|
|
387
|
-
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
|
|
529
|
+
copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
|
|
530
|
+
installReadonlyURLGuards(cloned, context);
|
|
388
531
|
return view;
|
|
389
532
|
}
|
|
390
533
|
function protectAnnotationValue(value, context) {
|