@optique/core 1.0.0-dev.1866 → 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.
@@ -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,60 +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 getProtectedProxyFallbackValue(target, key, context) {
111
- const ownDescriptor = Reflect.getOwnPropertyDescriptor(target, key);
112
- if (ownDescriptor != null && "value" in ownDescriptor) {
113
- if (ownDescriptor.configurable === false && ownDescriptor.writable === false) return ownDescriptor.value;
114
- const value$1 = ownDescriptor.value;
115
- return typeof value$1 === "function" ? value$1.bind(target) : protectAnnotationValue(value$1, context);
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;
116
128
  }
117
- const value = Reflect.get(target, key, target);
118
- return typeof value === "function" ? value.bind(target) : protectAnnotationValue(value, context);
119
129
  }
120
- function getProtectedProxyOwnPropertyDescriptor(target, key, context) {
121
- const descriptor = Reflect.getOwnPropertyDescriptor(target, key);
122
- if (descriptor == null || !("value" in descriptor)) return descriptor;
123
- if (descriptor.configurable === false && descriptor.writable === false) return descriptor;
124
- const value = protectAnnotationValue(descriptor.value, context);
125
- return value === descriptor.value ? descriptor : {
126
- ...descriptor,
127
- value
128
- };
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
+ }
129
139
  }
130
- function resolveProtectedMapLookup(target, lookup) {
131
- if (target.has(lookup)) return {
132
- found: true,
133
- value: target.get(lookup)
134
- };
135
- const rawLookup = unwrapProtectedAnnotationTarget(lookup);
136
- if (rawLookup !== lookup && target.has(rawLookup)) return {
137
- found: true,
138
- value: target.get(rawLookup)
139
- };
140
- for (const [entryKey, entryValue] of target.entries()) if (unwrapProtectedAnnotationTarget(entryKey) === rawLookup) return {
141
- found: true,
142
- value: entryValue
143
- };
144
- return { found: false };
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
+ }
145
149
  }
146
- function hasProtectedSetLookup(target, lookup) {
147
- if (target.has(lookup)) return true;
148
- const rawLookup = unwrapProtectedAnnotationTarget(lookup);
149
- if (rawLookup !== lookup && target.has(rawLookup)) return true;
150
- for (const value of target.values()) if (unwrapProtectedAnnotationTarget(value) === rawLookup) return true;
151
- return false;
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
+ }
152
159
  }
153
- function usesSubclassProxyFallback(target, basePrototype) {
154
- return Object.getPrototypeOf(target) !== basePrototype;
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
+ }
155
179
  }
156
180
  const regExpExcludedKeys = new Set(["lastIndex"]);
157
- function copyRegExpMetadata(source, target, transformValue) {
158
- copyOwnProperties(source, target, transformValue, regExpExcludedKeys);
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);
159
244
  target.lastIndex = source.lastIndex;
160
245
  }
161
246
  function cloneRegExpShape(source) {
162
- const cloned = new RegExp(source);
163
- copyRegExpMetadata(source, cloned);
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);
164
250
  return cloned;
165
251
  }
166
252
  function createProtectedObjectView(target, context) {
@@ -204,56 +290,10 @@ function createProtectedObjectView(target, context) {
204
290
  return Object.freeze(view);
205
291
  }
206
292
  function createProtectedMapView(target, context) {
207
- if (usesSubclassProxyFallback(target, Map.prototype)) {
208
- const methodCache$1 = /* @__PURE__ */ new Map();
209
- const view$1 = new Proxy(target, {
210
- get(target$1, key) {
211
- if (key === "size") return target$1.size;
212
- if (key === "valueOf") return cacheProtectedMethod(methodCache$1, key, () => () => view$1);
213
- if (key === "set" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache$1, key, () => (..._args) => throwReadonlyAnnotationMutation());
214
- if (key === "get") return cacheProtectedMethod(methodCache$1, key, () => (lookup) => {
215
- const resolved = resolveProtectedMapLookup(target$1, lookup);
216
- return resolved.found ? protectAnnotationValue(resolved.value, context) : void 0;
217
- });
218
- if (key === "has") return cacheProtectedMethod(methodCache$1, key, () => (lookup) => resolveProtectedMapLookup(target$1, lookup).found);
219
- if (key === "forEach") return cacheProtectedMethod(methodCache$1, key, () => (callback, thisArg) => target$1.forEach((value, mapKey) => {
220
- callback.call(thisArg, protectAnnotationValue(value, context), protectAnnotationValue(mapKey, context), view$1);
221
- }));
222
- if (key === "keys") return cacheProtectedMethod(methodCache$1, key, () => function* () {
223
- for (const value of target$1.keys()) yield protectAnnotationValue(value, context);
224
- });
225
- if (key === "values") return cacheProtectedMethod(methodCache$1, key, () => function* () {
226
- for (const value of target$1.values()) yield protectAnnotationValue(value, context);
227
- });
228
- if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache$1, key, () => function* () {
229
- for (const [entryKey, entryValue] of target$1.entries()) yield [protectAnnotationValue(entryKey, context), protectAnnotationValue(entryValue, context)];
230
- });
231
- return getProtectedProxyFallbackValue(target$1, key, context);
232
- },
233
- getOwnPropertyDescriptor(target$1, key) {
234
- return getProtectedProxyOwnPropertyDescriptor(target$1, key, context);
235
- },
236
- set() {
237
- throwReadonlyAnnotationMutation();
238
- },
239
- defineProperty() {
240
- throwReadonlyAnnotationMutation();
241
- },
242
- deleteProperty() {
243
- throwReadonlyAnnotationMutation();
244
- },
245
- setPrototypeOf() {
246
- throwReadonlyAnnotationMutation();
247
- },
248
- preventExtensions() {
249
- throwReadonlyAnnotationMutation();
250
- }
251
- });
252
- return registerProtectedAnnotationView(context, target, view$1);
253
- }
293
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, Map.prototype);
294
+ const entries = [...target.entries()].map(([entryKey, entryValue]) => [normalizeProtectedCollectionItem(entryKey, context), normalizeProtectedCollectionItem(entryValue, context)]);
254
295
  const methodCache = /* @__PURE__ */ new Map();
255
- const cloned = /* @__PURE__ */ new Map();
256
- 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);
257
297
  const view = new Proxy(cloned, {
258
298
  get(clonedTarget, key) {
259
299
  if (key === "size") return clonedTarget.size;
@@ -297,57 +337,15 @@ function createProtectedMapView(target, context) {
297
337
  });
298
338
  registerProtectedAnnotationView(context, target, view);
299
339
  cacheProtectedAnnotationViewAlias(context, cloned, view);
300
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
340
+ copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
341
+ installReadonlyMutationMethodGuards(cloned, mapMutationMethodKeys);
301
342
  return view;
302
343
  }
303
344
  function createProtectedSetView(target, context) {
304
- if (usesSubclassProxyFallback(target, Set.prototype)) {
305
- const methodCache$1 = /* @__PURE__ */ new Map();
306
- const view$1 = new Proxy(target, {
307
- get(target$1, key) {
308
- if (key === "size") return target$1.size;
309
- if (key === "valueOf") return cacheProtectedMethod(methodCache$1, key, () => () => view$1);
310
- if (key === "add" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache$1, key, () => (..._args) => throwReadonlyAnnotationMutation());
311
- if (key === "has") return cacheProtectedMethod(methodCache$1, key, () => (lookup) => hasProtectedSetLookup(target$1, lookup));
312
- if (key === "forEach") return cacheProtectedMethod(methodCache$1, key, () => (callback, thisArg) => target$1.forEach((value) => {
313
- const protectedValue = protectAnnotationValue(value, context);
314
- callback.call(thisArg, protectedValue, protectedValue, view$1);
315
- }));
316
- if (key === "keys" || key === "values" || key === Symbol.iterator) return cacheProtectedMethod(methodCache$1, key, () => function* () {
317
- for (const value of target$1.values()) yield protectAnnotationValue(value, context);
318
- });
319
- if (key === "entries") return cacheProtectedMethod(methodCache$1, key, () => function* () {
320
- for (const value of target$1.values()) {
321
- const protectedValue = protectAnnotationValue(value, context);
322
- yield [protectedValue, protectedValue];
323
- }
324
- });
325
- return getProtectedProxyFallbackValue(target$1, key, context);
326
- },
327
- getOwnPropertyDescriptor(target$1, key) {
328
- return getProtectedProxyOwnPropertyDescriptor(target$1, key, context);
329
- },
330
- set() {
331
- throwReadonlyAnnotationMutation();
332
- },
333
- defineProperty() {
334
- throwReadonlyAnnotationMutation();
335
- },
336
- deleteProperty() {
337
- throwReadonlyAnnotationMutation();
338
- },
339
- setPrototypeOf() {
340
- throwReadonlyAnnotationMutation();
341
- },
342
- preventExtensions() {
343
- throwReadonlyAnnotationMutation();
344
- }
345
- });
346
- return registerProtectedAnnotationView(context, target, view$1);
347
- }
345
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, Set.prototype);
346
+ const values = [...target.values()].map((value) => normalizeProtectedCollectionItem(value, context));
348
347
  const methodCache = /* @__PURE__ */ new Map();
349
- const cloned = /* @__PURE__ */ new Set();
350
- for (const value of target.values()) cloned.add(normalizeProtectedCollectionItem(value, context));
348
+ const cloned = syncPrototype ? new Set(values) : tryCloneSetSubclass(target, values) ?? new Set(values);
351
349
  const view = new Proxy(cloned, {
352
350
  get(clonedTarget, key) {
353
351
  if (key === "size") return clonedTarget.size;
@@ -388,40 +386,14 @@ function createProtectedSetView(target, context) {
388
386
  });
389
387
  registerProtectedAnnotationView(context, target, view);
390
388
  cacheProtectedAnnotationViewAlias(context, cloned, view);
391
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
389
+ copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
390
+ installReadonlyMutationMethodGuards(cloned, setMutationMethodKeys);
392
391
  return view;
393
392
  }
394
393
  function createProtectedDateView(target, context) {
395
- if (usesSubclassProxyFallback(target, Date.prototype)) {
396
- const methodCache$1 = /* @__PURE__ */ new Map();
397
- const view$1 = new Proxy(target, {
398
- get(target$1, key) {
399
- if (typeof key === "string" && key.startsWith("set")) return cacheProtectedMethod(methodCache$1, key, () => (..._args) => throwReadonlyAnnotationMutation());
400
- return getProtectedProxyFallbackValue(target$1, key, context);
401
- },
402
- getOwnPropertyDescriptor(target$1, key) {
403
- return getProtectedProxyOwnPropertyDescriptor(target$1, key, context);
404
- },
405
- set() {
406
- throwReadonlyAnnotationMutation();
407
- },
408
- defineProperty() {
409
- throwReadonlyAnnotationMutation();
410
- },
411
- deleteProperty() {
412
- throwReadonlyAnnotationMutation();
413
- },
414
- setPrototypeOf() {
415
- throwReadonlyAnnotationMutation();
416
- },
417
- preventExtensions() {
418
- throwReadonlyAnnotationMutation();
419
- }
420
- });
421
- return registerProtectedAnnotationView(context, target, view$1);
422
- }
394
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, Date.prototype);
423
395
  const methodCache = /* @__PURE__ */ new Map();
424
- const cloned = new Date(target.getTime());
396
+ const cloned = syncPrototype ? new Date(target.getTime()) : tryCloneDateSubclass(target) ?? new Date(target.getTime());
425
397
  const view = new Proxy(cloned, {
426
398
  get(clonedTarget, key) {
427
399
  const value = Reflect.get(clonedTarget, key, clonedTarget);
@@ -446,12 +418,14 @@ function createProtectedDateView(target, context) {
446
418
  });
447
419
  registerProtectedAnnotationView(context, target, view);
448
420
  cacheProtectedAnnotationViewAlias(context, cloned, view);
449
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
421
+ copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
422
+ installReadonlyMutationMethodGuards(cloned, dateMutationMethodKeys);
450
423
  return view;
451
424
  }
452
425
  function createProtectedRegExpView(target, context) {
426
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, RegExp.prototype);
453
427
  const methodCache = /* @__PURE__ */ new Map();
454
- const cloned = new RegExp(target);
428
+ const cloned = syncPrototype ? new RegExp(target) : tryCloneRegExpSubclass(target) ?? new RegExp(target);
455
429
  const view = new Proxy(cloned, {
456
430
  get(clonedTarget, key) {
457
431
  if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
@@ -479,51 +453,13 @@ function createProtectedRegExpView(target, context) {
479
453
  });
480
454
  registerProtectedAnnotationView(context, target, view);
481
455
  cacheProtectedAnnotationViewAlias(context, cloned, view);
482
- copyRegExpMetadata(target, cloned, (value) => protectAnnotationValue(value, context));
456
+ copyRegExpMetadata(target, cloned, (value) => protectAnnotationValue(value, context), syncPrototype);
483
457
  return view;
484
458
  }
485
459
  function createProtectedURLSearchParamsView(target, context) {
486
- if (usesSubclassProxyFallback(target, URLSearchParams.prototype)) {
487
- const methodCache$1 = /* @__PURE__ */ new Map();
488
- const view$1 = new Proxy(target, {
489
- get(target$1, key) {
490
- if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache$1, key, () => (..._args) => throwReadonlyAnnotationMutation());
491
- if (key === "valueOf") return cacheProtectedMethod(methodCache$1, key, () => () => view$1);
492
- if (key === "forEach") return cacheProtectedMethod(methodCache$1, key, () => (callback, thisArg) => target$1.forEach((value, name) => {
493
- callback.call(thisArg, value, name, view$1);
494
- }));
495
- if (key === "keys" || key === "values") return cacheProtectedMethod(methodCache$1, key, () => function* () {
496
- const iterator = key === "keys" ? target$1.keys() : target$1.values();
497
- for (const value of iterator) yield value;
498
- });
499
- if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache$1, key, () => function* () {
500
- for (const entry of target$1.entries()) yield entry;
501
- });
502
- return getProtectedProxyFallbackValue(target$1, key, context);
503
- },
504
- getOwnPropertyDescriptor(target$1, key) {
505
- return getProtectedProxyOwnPropertyDescriptor(target$1, key, context);
506
- },
507
- set() {
508
- throwReadonlyAnnotationMutation();
509
- },
510
- defineProperty() {
511
- throwReadonlyAnnotationMutation();
512
- },
513
- deleteProperty() {
514
- throwReadonlyAnnotationMutation();
515
- },
516
- setPrototypeOf() {
517
- throwReadonlyAnnotationMutation();
518
- },
519
- preventExtensions() {
520
- throwReadonlyAnnotationMutation();
521
- }
522
- });
523
- return registerProtectedAnnotationView(context, target, view$1);
524
- }
460
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, URLSearchParams.prototype);
525
461
  const methodCache = /* @__PURE__ */ new Map();
526
- const cloned = new URLSearchParams(target);
462
+ const cloned = syncPrototype ? new URLSearchParams(target) : tryCloneURLSearchParamsSubclass(target) ?? new URLSearchParams(target);
527
463
  const view = new Proxy(cloned, {
528
464
  get(clonedTarget, key) {
529
465
  if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
@@ -559,40 +495,13 @@ function createProtectedURLSearchParamsView(target, context) {
559
495
  });
560
496
  registerProtectedAnnotationView(context, target, view);
561
497
  cacheProtectedAnnotationViewAlias(context, cloned, view);
562
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
498
+ copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
499
+ installReadonlyMutationMethodGuards(cloned, urlSearchParamsMutationMethodKeys);
563
500
  return view;
564
501
  }
565
502
  function createProtectedURLView(target, context) {
566
- if (usesSubclassProxyFallback(target, URL.prototype)) {
567
- const methodCache = /* @__PURE__ */ new Map();
568
- const view$1 = new Proxy(target, {
569
- get(target$1, key) {
570
- if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view$1);
571
- if (key === "searchParams") return protectAnnotationValue(target$1.searchParams, context);
572
- return getProtectedProxyFallbackValue(target$1, key, context);
573
- },
574
- getOwnPropertyDescriptor(target$1, key) {
575
- return getProtectedProxyOwnPropertyDescriptor(target$1, key, context);
576
- },
577
- set() {
578
- throwReadonlyAnnotationMutation();
579
- },
580
- defineProperty() {
581
- throwReadonlyAnnotationMutation();
582
- },
583
- deleteProperty() {
584
- throwReadonlyAnnotationMutation();
585
- },
586
- setPrototypeOf() {
587
- throwReadonlyAnnotationMutation();
588
- },
589
- preventExtensions() {
590
- throwReadonlyAnnotationMutation();
591
- }
592
- });
593
- return registerProtectedAnnotationView(context, target, view$1);
594
- }
595
- const cloned = new URL(target.href);
503
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, URL.prototype);
504
+ const cloned = syncPrototype ? new URL(target.href) : tryCloneURLSubclass(target) ?? new URL(target.href);
596
505
  const view = new Proxy(cloned, {
597
506
  get(clonedTarget, key) {
598
507
  if (key === "valueOf") return () => view;
@@ -618,7 +527,8 @@ function createProtectedURLView(target, context) {
618
527
  });
619
528
  registerProtectedAnnotationView(context, target, view);
620
529
  cacheProtectedAnnotationViewAlias(context, cloned, view);
621
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
530
+ copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
531
+ installReadonlyURLGuards(cloned, context);
622
532
  return view;
623
533
  }
624
534
  function protectAnnotationValue(value, context) {
@@ -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,60 +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 getProtectedProxyFallbackValue(target, key, context) {
110
- const ownDescriptor = Reflect.getOwnPropertyDescriptor(target, key);
111
- if (ownDescriptor != null && "value" in ownDescriptor) {
112
- if (ownDescriptor.configurable === false && ownDescriptor.writable === false) return ownDescriptor.value;
113
- const value$1 = ownDescriptor.value;
114
- return typeof value$1 === "function" ? value$1.bind(target) : protectAnnotationValue(value$1, context);
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;
115
127
  }
116
- const value = Reflect.get(target, key, target);
117
- return typeof value === "function" ? value.bind(target) : protectAnnotationValue(value, context);
118
128
  }
119
- function getProtectedProxyOwnPropertyDescriptor(target, key, context) {
120
- const descriptor = Reflect.getOwnPropertyDescriptor(target, key);
121
- if (descriptor == null || !("value" in descriptor)) return descriptor;
122
- if (descriptor.configurable === false && descriptor.writable === false) return descriptor;
123
- const value = protectAnnotationValue(descriptor.value, context);
124
- return value === descriptor.value ? descriptor : {
125
- ...descriptor,
126
- value
127
- };
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
+ }
128
138
  }
129
- function resolveProtectedMapLookup(target, lookup) {
130
- if (target.has(lookup)) return {
131
- found: true,
132
- value: target.get(lookup)
133
- };
134
- const rawLookup = unwrapProtectedAnnotationTarget(lookup);
135
- if (rawLookup !== lookup && target.has(rawLookup)) return {
136
- found: true,
137
- value: target.get(rawLookup)
138
- };
139
- for (const [entryKey, entryValue] of target.entries()) if (unwrapProtectedAnnotationTarget(entryKey) === rawLookup) return {
140
- found: true,
141
- value: entryValue
142
- };
143
- return { found: false };
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
+ }
144
148
  }
145
- function hasProtectedSetLookup(target, lookup) {
146
- if (target.has(lookup)) return true;
147
- const rawLookup = unwrapProtectedAnnotationTarget(lookup);
148
- if (rawLookup !== lookup && target.has(rawLookup)) return true;
149
- for (const value of target.values()) if (unwrapProtectedAnnotationTarget(value) === rawLookup) return true;
150
- return false;
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
+ }
151
158
  }
152
- function usesSubclassProxyFallback(target, basePrototype) {
153
- return Object.getPrototypeOf(target) !== basePrototype;
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
+ }
154
178
  }
155
179
  const regExpExcludedKeys = new Set(["lastIndex"]);
156
- function copyRegExpMetadata(source, target, transformValue) {
157
- copyOwnProperties(source, target, transformValue, regExpExcludedKeys);
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);
158
243
  target.lastIndex = source.lastIndex;
159
244
  }
160
245
  function cloneRegExpShape(source) {
161
- const cloned = new RegExp(source);
162
- copyRegExpMetadata(source, cloned);
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);
163
249
  return cloned;
164
250
  }
165
251
  function createProtectedObjectView(target, context) {
@@ -203,56 +289,10 @@ function createProtectedObjectView(target, context) {
203
289
  return Object.freeze(view);
204
290
  }
205
291
  function createProtectedMapView(target, context) {
206
- if (usesSubclassProxyFallback(target, Map.prototype)) {
207
- const methodCache$1 = /* @__PURE__ */ new Map();
208
- const view$1 = new Proxy(target, {
209
- get(target$1, key) {
210
- if (key === "size") return target$1.size;
211
- if (key === "valueOf") return cacheProtectedMethod(methodCache$1, key, () => () => view$1);
212
- if (key === "set" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache$1, key, () => (..._args) => throwReadonlyAnnotationMutation());
213
- if (key === "get") return cacheProtectedMethod(methodCache$1, key, () => (lookup) => {
214
- const resolved = resolveProtectedMapLookup(target$1, lookup);
215
- return resolved.found ? protectAnnotationValue(resolved.value, context) : void 0;
216
- });
217
- if (key === "has") return cacheProtectedMethod(methodCache$1, key, () => (lookup) => resolveProtectedMapLookup(target$1, lookup).found);
218
- if (key === "forEach") return cacheProtectedMethod(methodCache$1, key, () => (callback, thisArg) => target$1.forEach((value, mapKey) => {
219
- callback.call(thisArg, protectAnnotationValue(value, context), protectAnnotationValue(mapKey, context), view$1);
220
- }));
221
- if (key === "keys") return cacheProtectedMethod(methodCache$1, key, () => function* () {
222
- for (const value of target$1.keys()) yield protectAnnotationValue(value, context);
223
- });
224
- if (key === "values") return cacheProtectedMethod(methodCache$1, key, () => function* () {
225
- for (const value of target$1.values()) yield protectAnnotationValue(value, context);
226
- });
227
- if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache$1, key, () => function* () {
228
- for (const [entryKey, entryValue] of target$1.entries()) yield [protectAnnotationValue(entryKey, context), protectAnnotationValue(entryValue, context)];
229
- });
230
- return getProtectedProxyFallbackValue(target$1, key, context);
231
- },
232
- getOwnPropertyDescriptor(target$1, key) {
233
- return getProtectedProxyOwnPropertyDescriptor(target$1, key, context);
234
- },
235
- set() {
236
- throwReadonlyAnnotationMutation();
237
- },
238
- defineProperty() {
239
- throwReadonlyAnnotationMutation();
240
- },
241
- deleteProperty() {
242
- throwReadonlyAnnotationMutation();
243
- },
244
- setPrototypeOf() {
245
- throwReadonlyAnnotationMutation();
246
- },
247
- preventExtensions() {
248
- throwReadonlyAnnotationMutation();
249
- }
250
- });
251
- return registerProtectedAnnotationView(context, target, view$1);
252
- }
292
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, Map.prototype);
293
+ const entries = [...target.entries()].map(([entryKey, entryValue]) => [normalizeProtectedCollectionItem(entryKey, context), normalizeProtectedCollectionItem(entryValue, context)]);
253
294
  const methodCache = /* @__PURE__ */ new Map();
254
- const cloned = /* @__PURE__ */ new Map();
255
- 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);
256
296
  const view = new Proxy(cloned, {
257
297
  get(clonedTarget, key) {
258
298
  if (key === "size") return clonedTarget.size;
@@ -296,57 +336,15 @@ function createProtectedMapView(target, context) {
296
336
  });
297
337
  registerProtectedAnnotationView(context, target, view);
298
338
  cacheProtectedAnnotationViewAlias(context, cloned, view);
299
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
339
+ copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
340
+ installReadonlyMutationMethodGuards(cloned, mapMutationMethodKeys);
300
341
  return view;
301
342
  }
302
343
  function createProtectedSetView(target, context) {
303
- if (usesSubclassProxyFallback(target, Set.prototype)) {
304
- const methodCache$1 = /* @__PURE__ */ new Map();
305
- const view$1 = new Proxy(target, {
306
- get(target$1, key) {
307
- if (key === "size") return target$1.size;
308
- if (key === "valueOf") return cacheProtectedMethod(methodCache$1, key, () => () => view$1);
309
- if (key === "add" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache$1, key, () => (..._args) => throwReadonlyAnnotationMutation());
310
- if (key === "has") return cacheProtectedMethod(methodCache$1, key, () => (lookup) => hasProtectedSetLookup(target$1, lookup));
311
- if (key === "forEach") return cacheProtectedMethod(methodCache$1, key, () => (callback, thisArg) => target$1.forEach((value) => {
312
- const protectedValue = protectAnnotationValue(value, context);
313
- callback.call(thisArg, protectedValue, protectedValue, view$1);
314
- }));
315
- if (key === "keys" || key === "values" || key === Symbol.iterator) return cacheProtectedMethod(methodCache$1, key, () => function* () {
316
- for (const value of target$1.values()) yield protectAnnotationValue(value, context);
317
- });
318
- if (key === "entries") return cacheProtectedMethod(methodCache$1, key, () => function* () {
319
- for (const value of target$1.values()) {
320
- const protectedValue = protectAnnotationValue(value, context);
321
- yield [protectedValue, protectedValue];
322
- }
323
- });
324
- return getProtectedProxyFallbackValue(target$1, key, context);
325
- },
326
- getOwnPropertyDescriptor(target$1, key) {
327
- return getProtectedProxyOwnPropertyDescriptor(target$1, key, context);
328
- },
329
- set() {
330
- throwReadonlyAnnotationMutation();
331
- },
332
- defineProperty() {
333
- throwReadonlyAnnotationMutation();
334
- },
335
- deleteProperty() {
336
- throwReadonlyAnnotationMutation();
337
- },
338
- setPrototypeOf() {
339
- throwReadonlyAnnotationMutation();
340
- },
341
- preventExtensions() {
342
- throwReadonlyAnnotationMutation();
343
- }
344
- });
345
- return registerProtectedAnnotationView(context, target, view$1);
346
- }
344
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, Set.prototype);
345
+ const values = [...target.values()].map((value) => normalizeProtectedCollectionItem(value, context));
347
346
  const methodCache = /* @__PURE__ */ new Map();
348
- const cloned = /* @__PURE__ */ new Set();
349
- for (const value of target.values()) cloned.add(normalizeProtectedCollectionItem(value, context));
347
+ const cloned = syncPrototype ? new Set(values) : tryCloneSetSubclass(target, values) ?? new Set(values);
350
348
  const view = new Proxy(cloned, {
351
349
  get(clonedTarget, key) {
352
350
  if (key === "size") return clonedTarget.size;
@@ -387,40 +385,14 @@ function createProtectedSetView(target, context) {
387
385
  });
388
386
  registerProtectedAnnotationView(context, target, view);
389
387
  cacheProtectedAnnotationViewAlias(context, cloned, view);
390
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
388
+ copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
389
+ installReadonlyMutationMethodGuards(cloned, setMutationMethodKeys);
391
390
  return view;
392
391
  }
393
392
  function createProtectedDateView(target, context) {
394
- if (usesSubclassProxyFallback(target, Date.prototype)) {
395
- const methodCache$1 = /* @__PURE__ */ new Map();
396
- const view$1 = new Proxy(target, {
397
- get(target$1, key) {
398
- if (typeof key === "string" && key.startsWith("set")) return cacheProtectedMethod(methodCache$1, key, () => (..._args) => throwReadonlyAnnotationMutation());
399
- return getProtectedProxyFallbackValue(target$1, key, context);
400
- },
401
- getOwnPropertyDescriptor(target$1, key) {
402
- return getProtectedProxyOwnPropertyDescriptor(target$1, key, context);
403
- },
404
- set() {
405
- throwReadonlyAnnotationMutation();
406
- },
407
- defineProperty() {
408
- throwReadonlyAnnotationMutation();
409
- },
410
- deleteProperty() {
411
- throwReadonlyAnnotationMutation();
412
- },
413
- setPrototypeOf() {
414
- throwReadonlyAnnotationMutation();
415
- },
416
- preventExtensions() {
417
- throwReadonlyAnnotationMutation();
418
- }
419
- });
420
- return registerProtectedAnnotationView(context, target, view$1);
421
- }
393
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, Date.prototype);
422
394
  const methodCache = /* @__PURE__ */ new Map();
423
- const cloned = new Date(target.getTime());
395
+ const cloned = syncPrototype ? new Date(target.getTime()) : tryCloneDateSubclass(target) ?? new Date(target.getTime());
424
396
  const view = new Proxy(cloned, {
425
397
  get(clonedTarget, key) {
426
398
  const value = Reflect.get(clonedTarget, key, clonedTarget);
@@ -445,12 +417,14 @@ function createProtectedDateView(target, context) {
445
417
  });
446
418
  registerProtectedAnnotationView(context, target, view);
447
419
  cacheProtectedAnnotationViewAlias(context, cloned, view);
448
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
420
+ copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
421
+ installReadonlyMutationMethodGuards(cloned, dateMutationMethodKeys);
449
422
  return view;
450
423
  }
451
424
  function createProtectedRegExpView(target, context) {
425
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, RegExp.prototype);
452
426
  const methodCache = /* @__PURE__ */ new Map();
453
- const cloned = new RegExp(target);
427
+ const cloned = syncPrototype ? new RegExp(target) : tryCloneRegExpSubclass(target) ?? new RegExp(target);
454
428
  const view = new Proxy(cloned, {
455
429
  get(clonedTarget, key) {
456
430
  if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
@@ -478,51 +452,13 @@ function createProtectedRegExpView(target, context) {
478
452
  });
479
453
  registerProtectedAnnotationView(context, target, view);
480
454
  cacheProtectedAnnotationViewAlias(context, cloned, view);
481
- copyRegExpMetadata(target, cloned, (value) => protectAnnotationValue(value, context));
455
+ copyRegExpMetadata(target, cloned, (value) => protectAnnotationValue(value, context), syncPrototype);
482
456
  return view;
483
457
  }
484
458
  function createProtectedURLSearchParamsView(target, context) {
485
- if (usesSubclassProxyFallback(target, URLSearchParams.prototype)) {
486
- const methodCache$1 = /* @__PURE__ */ new Map();
487
- const view$1 = new Proxy(target, {
488
- get(target$1, key) {
489
- if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache$1, key, () => (..._args) => throwReadonlyAnnotationMutation());
490
- if (key === "valueOf") return cacheProtectedMethod(methodCache$1, key, () => () => view$1);
491
- if (key === "forEach") return cacheProtectedMethod(methodCache$1, key, () => (callback, thisArg) => target$1.forEach((value, name) => {
492
- callback.call(thisArg, value, name, view$1);
493
- }));
494
- if (key === "keys" || key === "values") return cacheProtectedMethod(methodCache$1, key, () => function* () {
495
- const iterator = key === "keys" ? target$1.keys() : target$1.values();
496
- for (const value of iterator) yield value;
497
- });
498
- if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache$1, key, () => function* () {
499
- for (const entry of target$1.entries()) yield entry;
500
- });
501
- return getProtectedProxyFallbackValue(target$1, key, context);
502
- },
503
- getOwnPropertyDescriptor(target$1, key) {
504
- return getProtectedProxyOwnPropertyDescriptor(target$1, key, context);
505
- },
506
- set() {
507
- throwReadonlyAnnotationMutation();
508
- },
509
- defineProperty() {
510
- throwReadonlyAnnotationMutation();
511
- },
512
- deleteProperty() {
513
- throwReadonlyAnnotationMutation();
514
- },
515
- setPrototypeOf() {
516
- throwReadonlyAnnotationMutation();
517
- },
518
- preventExtensions() {
519
- throwReadonlyAnnotationMutation();
520
- }
521
- });
522
- return registerProtectedAnnotationView(context, target, view$1);
523
- }
459
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, URLSearchParams.prototype);
524
460
  const methodCache = /* @__PURE__ */ new Map();
525
- const cloned = new URLSearchParams(target);
461
+ const cloned = syncPrototype ? new URLSearchParams(target) : tryCloneURLSearchParamsSubclass(target) ?? new URLSearchParams(target);
526
462
  const view = new Proxy(cloned, {
527
463
  get(clonedTarget, key) {
528
464
  if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
@@ -558,40 +494,13 @@ function createProtectedURLSearchParamsView(target, context) {
558
494
  });
559
495
  registerProtectedAnnotationView(context, target, view);
560
496
  cacheProtectedAnnotationViewAlias(context, cloned, view);
561
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
497
+ copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
498
+ installReadonlyMutationMethodGuards(cloned, urlSearchParamsMutationMethodKeys);
562
499
  return view;
563
500
  }
564
501
  function createProtectedURLView(target, context) {
565
- if (usesSubclassProxyFallback(target, URL.prototype)) {
566
- const methodCache = /* @__PURE__ */ new Map();
567
- const view$1 = new Proxy(target, {
568
- get(target$1, key) {
569
- if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view$1);
570
- if (key === "searchParams") return protectAnnotationValue(target$1.searchParams, context);
571
- return getProtectedProxyFallbackValue(target$1, key, context);
572
- },
573
- getOwnPropertyDescriptor(target$1, key) {
574
- return getProtectedProxyOwnPropertyDescriptor(target$1, key, context);
575
- },
576
- set() {
577
- throwReadonlyAnnotationMutation();
578
- },
579
- defineProperty() {
580
- throwReadonlyAnnotationMutation();
581
- },
582
- deleteProperty() {
583
- throwReadonlyAnnotationMutation();
584
- },
585
- setPrototypeOf() {
586
- throwReadonlyAnnotationMutation();
587
- },
588
- preventExtensions() {
589
- throwReadonlyAnnotationMutation();
590
- }
591
- });
592
- return registerProtectedAnnotationView(context, target, view$1);
593
- }
594
- const cloned = new URL(target.href);
502
+ const syncPrototype = !hasBuiltInSubclassPrototype(target, URL.prototype);
503
+ const cloned = syncPrototype ? new URL(target.href) : tryCloneURLSubclass(target) ?? new URL(target.href);
595
504
  const view = new Proxy(cloned, {
596
505
  get(clonedTarget, key) {
597
506
  if (key === "valueOf") return () => view;
@@ -617,7 +526,8 @@ function createProtectedURLView(target, context) {
617
526
  });
618
527
  registerProtectedAnnotationView(context, target, view);
619
528
  cacheProtectedAnnotationViewAlias(context, cloned, view);
620
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context));
529
+ copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
530
+ installReadonlyURLGuards(cloned, context);
621
531
  return view;
622
532
  }
623
533
  function protectAnnotationValue(value, context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1866+7ab2516f",
3
+ "version": "1.0.0-dev.1868+54bdb27a",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",