@poe-platform/safe-js 0.1.377 → 0.1.379

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.
@@ -7225,230 +7225,50 @@ function serializedDateTime(value) {
7225
7225
  // packages/safe-js/src/interp/internal-symbols.ts
7226
7226
  var internalSymbols = /* @__PURE__ */ new Set();
7227
7227
 
7228
- // packages/safe-js/src/interp/accessors.ts
7229
- var accessorClosures = /* @__PURE__ */ new WeakMap();
7230
- var getterAdapters = /* @__PURE__ */ new WeakMap();
7231
- var setterAdapters = /* @__PURE__ */ new WeakMap();
7232
- function accessorAdapter(closure, kind) {
7233
- if (kind === "get") {
7234
- let adapter2 = getterAdapters.get(closure);
7235
- if (adapter2 === void 0) {
7236
- adapter2 = () => void 0;
7237
- getterAdapters.set(closure, adapter2);
7238
- accessorClosures.set(adapter2, closure);
7239
- }
7240
- return adapter2;
7241
- }
7242
- let adapter = setterAdapters.get(closure);
7243
- if (adapter === void 0) {
7244
- adapter = () => {
7245
- throw new TypeError("Accessor writes require sandbox execution.");
7246
- };
7247
- setterAdapters.set(closure, adapter);
7248
- accessorClosures.set(adapter, closure);
7228
+ // packages/safe-js/src/interp/arguments.ts
7229
+ var sandboxArgumentsBrand = /* @__PURE__ */ Symbol("SandboxArguments");
7230
+ internalSymbols.add(sandboxArgumentsBrand);
7231
+ function createSandboxArguments(values) {
7232
+ const result = /* @__PURE__ */ (function() {
7233
+ return arguments;
7234
+ })();
7235
+ for (let index = 0; index < values.length; index += 1) {
7236
+ result[index] = values[index];
7249
7237
  }
7250
- return adapter;
7238
+ result.length = values.length;
7239
+ Object.defineProperty(result, sandboxArgumentsBrand, { value: true });
7240
+ return result;
7251
7241
  }
7252
- function accessorClosure(adapter) {
7253
- if (adapter === void 0) return void 0;
7254
- const closure = accessorClosures.get(adapter);
7255
- if (closure === void 0) throw new TypeError("Native accessors cannot execute in the sandbox.");
7256
- return closure;
7242
+ function isSandboxArguments(value) {
7243
+ return typeof value === "object" && value !== null && Object.hasOwn(value, sandboxArgumentsBrand);
7257
7244
  }
7258
- function retainedAccessorClosures(descriptor) {
7259
- const closures = [];
7260
- for (const adapter of [descriptor.get, descriptor.set]) {
7261
- const closure = adapter === void 0 ? void 0 : accessorClosures.get(adapter);
7262
- if (closure !== void 0) closures.push(closure);
7263
- }
7264
- return closures;
7245
+ function getSandboxArgumentEntries(value) {
7246
+ return Object.entries(Object.getOwnPropertyDescriptors(value)).flatMap(
7247
+ ([key, descriptor]) => "value" in descriptor ? [[key, descriptor.value]] : []
7248
+ );
7265
7249
  }
7266
- function readPropertyDescriptor(descriptor, receiver, context, allowNativeGetter = false) {
7267
- if ("value" in descriptor) return descriptor.value;
7268
- if (descriptor.get === void 0) return void 0;
7269
- const getter = accessorClosures.get(descriptor.get);
7270
- if (getter === void 0) {
7271
- if (!allowNativeGetter) throw new TypeError("Native accessors cannot execute in the sandbox.");
7272
- return Reflect.apply(descriptor.get, receiver, []);
7250
+ function copySandboxArgumentProperties(source, target, copyValue) {
7251
+ const names = Object.getOwnPropertyNames(source);
7252
+ if (!names.includes("length") || names.indexOf("length") > names.indexOf("callee")) {
7253
+ Reflect.deleteProperty(target, "length");
7273
7254
  }
7274
- if (context?.invokeClosure === void 0)
7275
- throw new TypeError("Accessor reads require sandbox execution.");
7276
- return context.invokeClosure(getter, [], receiver);
7277
- }
7278
- function writePropertyDescriptor(descriptor, receiver, value, context) {
7279
- const setter = accessorClosure(descriptor.set);
7280
- if (setter === void 0) throw new TypeError("Cannot assign to a getter-only property.");
7281
- if (context?.invokeClosure === void 0)
7282
- throw new TypeError("Accessor writes require sandbox execution.");
7283
- return context.invokeClosure(setter, [value], receiver).then(() => void 0);
7284
- }
7285
-
7286
- // packages/safe-js/src/interp/symbols.ts
7287
- var wellKnownSymbols = Object.freeze({
7288
- iterator: Symbol.iterator,
7289
- asyncIterator: Symbol.asyncIterator,
7290
- hasInstance: Symbol.hasInstance,
7291
- isConcatSpreadable: Symbol.isConcatSpreadable,
7292
- match: Symbol.match,
7293
- matchAll: Symbol.matchAll,
7294
- replace: Symbol.replace,
7295
- search: Symbol.search,
7296
- species: Symbol.species,
7297
- split: Symbol.split,
7298
- toPrimitive: Symbol.toPrimitive,
7299
- toStringTag: Symbol.toStringTag,
7300
- unscopables: Symbol.unscopables
7301
- });
7302
-
7303
- // packages/safe-js/src/interp/intrinsics.ts
7304
- var identities = /* @__PURE__ */ new WeakMap();
7305
- var realms2 = /* @__PURE__ */ new WeakMap();
7306
- function registerBuiltinIdentities(budget, bindings) {
7307
- let realm = realms2.get(budget);
7308
- if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
7309
- const pending = Object.entries(bindings).map(([name, value]) => [[name], value]);
7310
- const visited = /* @__PURE__ */ new WeakSet();
7311
- for (let index = 0; index < pending.length; index++) {
7312
- const [path, value] = pending[index];
7313
- if (value === null || typeof value !== "object") continue;
7314
- const id = JSON.stringify(path);
7315
- const previous = realm.get(id);
7316
- if (previous !== void 0 && previous !== value)
7317
- throw new TypeError(`Duplicate intrinsic identity: ${id}`);
7318
- realm.set(id, value);
7319
- if (!identities.has(value)) identities.set(value, id);
7320
- if (visited.has(value)) continue;
7321
- visited.add(value);
7322
- const owner = isSandboxClosure(value) ? value.properties : value;
7323
- if (owner === void 0) continue;
7324
- for (const key of Reflect.ownKeys(owner)) {
7325
- if (typeof key === "symbol" && internalSymbols.has(key)) continue;
7326
- const descriptor = Object.getOwnPropertyDescriptor(owner, key);
7327
- const symbolName = typeof key === "symbol" ? Object.entries(wellKnownSymbols).find(([, symbol]) => symbol === key)?.[0] : void 0;
7328
- if (typeof key === "symbol" && symbolName === void 0)
7329
- throw new TypeError("Intrinsic symbol keys must be well-known symbols.");
7330
- const member = [...path, typeof key === "string" ? key : { symbol: symbolName }];
7331
- if ("value" in descriptor) pending.push([member, descriptor.value]);
7332
- for (const kind of ["get", "set"]) {
7333
- const closure = accessorClosure(descriptor[kind]);
7334
- if (closure !== void 0) pending.push([[...member, kind], closure]);
7335
- }
7255
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(source))) {
7256
+ if (!("value" in descriptor)) {
7257
+ if (key !== "callee") throw new TypeError(`Cannot copy arguments accessor '${key}'.`);
7258
+ continue;
7336
7259
  }
7260
+ Object.defineProperty(target, key, { ...descriptor, value: copyValue(descriptor.value, key) });
7337
7261
  }
7338
- }
7339
- function getIntrinsicIdentity(value) {
7340
- return identities.get(value);
7341
- }
7342
- function resolveIntrinsicIdentity(budget, id) {
7343
- const value = realms2.get(budget)?.get(id);
7344
- if (value === void 0) throw new TypeError(`Unknown intrinsic identity: ${id}`);
7345
- return value;
7346
- }
7347
- function listIntrinsicIdentities(budget) {
7348
- return [...realms2.get(budget)?.keys() ?? []];
7349
- }
7350
- function releaseIntrinsicIdentities(budget) {
7351
- realms2.delete(budget);
7352
- }
7353
-
7354
- // packages/safe-js/src/interp/generator-properties.ts
7355
- var generatorGuestProperties = /* @__PURE__ */ new WeakMap();
7356
- function getGeneratorProperties(value) {
7357
- let properties = generatorGuestProperties.get(value);
7358
- if (properties === void 0) {
7359
- properties = /* @__PURE__ */ Object.create(null);
7360
- generatorGuestProperties.set(value, properties);
7361
- }
7362
- return properties;
7363
- }
7364
-
7365
- // packages/safe-js/src/interp/regexp-properties.ts
7366
- var regexGuestProperties = /* @__PURE__ */ new WeakMap();
7367
- function getRegexProperties(value) {
7368
- const properties = regexGuestProperties.get(value);
7369
- if (properties === void 0) throw new TypeError("Invalid sandbox RegExp storage.");
7370
- return properties;
7371
- }
7372
-
7373
- // packages/safe-js/src/interp/collection-properties.ts
7374
- var collectionGuestProperties = /* @__PURE__ */ new WeakMap();
7375
- function getCollectionProperties(value) {
7376
- const properties = collectionGuestProperties.get(value);
7377
- if (properties === void 0) throw new TypeError("Invalid sandbox collection storage.");
7378
- return properties;
7379
- }
7380
- function copyCollectionProperties(source, target, encode) {
7381
- const properties = collectionGuestProperties.get(source) ?? source;
7382
- for (const key of Reflect.ownKeys(properties)) {
7383
- const descriptor = Object.getOwnPropertyDescriptor(properties, key);
7384
- if (!("value" in descriptor)) throw new TypeError("Collection accessor properties cannot be copied as data.");
7385
- Object.defineProperty(target, key, { ...descriptor, value: encode(descriptor.value) });
7386
- }
7387
- if (!Object.isExtensible(properties)) Object.preventExtensions(target);
7388
- }
7389
-
7390
- // packages/safe-js/src/interp/resources.ts
7391
- import { AsyncLocalStorage } from "node:async_hooks";
7392
- var runResources = new AsyncLocalStorage();
7393
- function retainValues(budget, values) {
7394
- const retained = {};
7395
- budget.setRetainedValues(retained, values);
7396
- const pending = runResources.getStore()?.referenceReleases;
7397
- const release = () => {
7398
- budget.setRetainedValues(retained, void 0);
7399
- pending?.delete(release);
7400
- };
7401
- pending?.add(release);
7402
- return release;
7403
- }
7404
- async function withRunResources(signal, execute) {
7405
- const controller = new AbortController();
7406
- const cancel = () => controller.abort(signal?.reason);
7407
- const cleanups = /* @__PURE__ */ new Set();
7408
- const resources = {
7409
- signal: controller.signal,
7410
- referenceReleases: /* @__PURE__ */ new Set(),
7411
- add(close) {
7412
- cleanups.add(close);
7262
+ const iterator = Object.getOwnPropertyDescriptor(source, Symbol.iterator);
7263
+ if (iterator === void 0) {
7264
+ Reflect.deleteProperty(target, Symbol.iterator);
7265
+ } else {
7266
+ if (iterator.value !== Array.prototype.values) {
7267
+ throw new TypeError("Cannot copy a replaced arguments iterator.");
7413
7268
  }
7414
- };
7415
- signal?.addEventListener("abort", cancel, { once: true });
7416
- if (signal?.aborted) cancel();
7417
- let result;
7418
- let failure;
7419
- let errors = [];
7420
- try {
7421
- result = await runResources.run(resources, execute);
7422
- } catch (error) {
7423
- failure = { reason: error };
7424
- } finally {
7425
- signal?.removeEventListener("abort", cancel);
7426
- controller.abort(new Error("SafeJS run finished."));
7427
- for (const release of resources.referenceReleases) release();
7428
- resources.referenceReleases.clear();
7429
- const outcomes = await Promise.allSettled(
7430
- [...cleanups].map((close) => Promise.resolve().then(close))
7431
- );
7432
- errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
7269
+ Object.defineProperty(target, Symbol.iterator, iterator);
7433
7270
  }
7434
- if (failure !== void 0) throw failure.reason;
7435
- if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
7436
- return result;
7437
- }
7438
-
7439
- // packages/safe-js/src/interp/error-prototypes.ts
7440
- var errorPrototypes = /* @__PURE__ */ new WeakMap();
7441
-
7442
- // packages/safe-js/src/interp/collection-brands.ts
7443
- var sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
7444
- var sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
7445
- internalSymbols.add(sandboxMapBrand);
7446
- internalSymbols.add(sandboxSetBrand);
7447
- function isSandboxMap(value) {
7448
- return typeof value === "object" && value !== null && sandboxMapBrand in value;
7449
- }
7450
- function isSandboxSet(value) {
7451
- return typeof value === "object" && value !== null && sandboxSetBrand in value;
7271
+ if (!Object.isExtensible(source)) Object.preventExtensions(target);
7452
7272
  }
7453
7273
 
7454
7274
  // packages/safe-js/src/interp/collection-iterator.ts
@@ -7545,50 +7365,16 @@ function regexpIteratorState(value) {
7545
7365
  return state;
7546
7366
  }
7547
7367
 
7548
- // packages/safe-js/src/interp/arguments.ts
7549
- var sandboxArgumentsBrand = /* @__PURE__ */ Symbol("SandboxArguments");
7550
- internalSymbols.add(sandboxArgumentsBrand);
7551
- function createSandboxArguments(values) {
7552
- const result = /* @__PURE__ */ (function() {
7553
- return arguments;
7554
- })();
7555
- for (let index = 0; index < values.length; index += 1) {
7556
- result[index] = values[index];
7557
- }
7558
- result.length = values.length;
7559
- Object.defineProperty(result, sandboxArgumentsBrand, { value: true });
7560
- return result;
7561
- }
7562
- function isSandboxArguments(value) {
7563
- return typeof value === "object" && value !== null && Object.hasOwn(value, sandboxArgumentsBrand);
7564
- }
7565
- function getSandboxArgumentEntries(value) {
7566
- return Object.entries(Object.getOwnPropertyDescriptors(value)).flatMap(
7567
- ([key, descriptor]) => "value" in descriptor ? [[key, descriptor.value]] : []
7568
- );
7368
+ // packages/safe-js/src/interp/collection-brands.ts
7369
+ var sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
7370
+ var sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
7371
+ internalSymbols.add(sandboxMapBrand);
7372
+ internalSymbols.add(sandboxSetBrand);
7373
+ function isSandboxMap(value) {
7374
+ return typeof value === "object" && value !== null && sandboxMapBrand in value;
7569
7375
  }
7570
- function copySandboxArgumentProperties(source, target, copyValue) {
7571
- const names = Object.getOwnPropertyNames(source);
7572
- if (!names.includes("length") || names.indexOf("length") > names.indexOf("callee")) {
7573
- Reflect.deleteProperty(target, "length");
7574
- }
7575
- for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(source))) {
7576
- if (!("value" in descriptor)) {
7577
- if (key !== "callee") throw new TypeError(`Cannot copy arguments accessor '${key}'.`);
7578
- continue;
7579
- }
7580
- Object.defineProperty(target, key, { ...descriptor, value: copyValue(descriptor.value, key) });
7581
- }
7582
- const iterator = Object.getOwnPropertyDescriptor(source, Symbol.iterator);
7583
- if (iterator === void 0) {
7584
- Reflect.deleteProperty(target, Symbol.iterator);
7585
- } else {
7586
- if (iterator.value !== Array.prototype.values) {
7587
- throw new TypeError("Cannot copy a replaced arguments iterator.");
7588
- }
7589
- Object.defineProperty(target, Symbol.iterator, iterator);
7590
- }
7591
- if (!Object.isExtensible(source)) Object.preventExtensions(target);
7376
+ function isSandboxSet(value) {
7377
+ return typeof value === "object" && value !== null && sandboxSetBrand in value;
7592
7378
  }
7593
7379
 
7594
7380
  // packages/safe-js/src/interp/boxed.ts
@@ -7640,6 +7426,25 @@ function boxedDataProperties(value, includeSymbols = false) {
7640
7426
  });
7641
7427
  }
7642
7428
 
7429
+ // packages/safe-js/src/interp/regexp-properties.ts
7430
+ var regexGuestProperties = /* @__PURE__ */ new WeakMap();
7431
+ function getRegexProperties(value) {
7432
+ const properties = regexGuestProperties.get(value);
7433
+ if (properties === void 0) throw new TypeError("Invalid sandbox RegExp storage.");
7434
+ return properties;
7435
+ }
7436
+
7437
+ // packages/safe-js/src/interp/generator-properties.ts
7438
+ var generatorGuestProperties = /* @__PURE__ */ new WeakMap();
7439
+ function getGeneratorProperties(value) {
7440
+ let properties = generatorGuestProperties.get(value);
7441
+ if (properties === void 0) {
7442
+ properties = /* @__PURE__ */ Object.create(null);
7443
+ generatorGuestProperties.set(value, properties);
7444
+ }
7445
+ return properties;
7446
+ }
7447
+
7643
7448
  // packages/safe-js/src/graph-depth.ts
7644
7449
  var MAX_DATA_DEPTH = 1024;
7645
7450
  var SnapshotBudgetError = class extends Error {
@@ -7733,6 +7538,181 @@ function graphEntries(value) {
7733
7538
  // packages/safe-js/src/interp/generator-prototypes.ts
7734
7539
  var generatorPrototypes = /* @__PURE__ */ new WeakMap();
7735
7540
 
7541
+ // packages/safe-js/src/interp/resources.ts
7542
+ import { AsyncLocalStorage } from "node:async_hooks";
7543
+ var runResources = new AsyncLocalStorage();
7544
+ function retainValues(budget, values) {
7545
+ const retained = {};
7546
+ budget.setRetainedValues(retained, values);
7547
+ const pending = runResources.getStore()?.referenceReleases;
7548
+ const release = () => {
7549
+ budget.setRetainedValues(retained, void 0);
7550
+ pending?.delete(release);
7551
+ };
7552
+ pending?.add(release);
7553
+ return release;
7554
+ }
7555
+ async function withRunResources(signal, execute) {
7556
+ const controller = new AbortController();
7557
+ const cancel = () => controller.abort(signal?.reason);
7558
+ const cleanups = /* @__PURE__ */ new Set();
7559
+ const resources = {
7560
+ signal: controller.signal,
7561
+ referenceReleases: /* @__PURE__ */ new Set(),
7562
+ add(close) {
7563
+ cleanups.add(close);
7564
+ }
7565
+ };
7566
+ signal?.addEventListener("abort", cancel, { once: true });
7567
+ if (signal?.aborted) cancel();
7568
+ let result;
7569
+ let failure;
7570
+ let errors = [];
7571
+ try {
7572
+ result = await runResources.run(resources, execute);
7573
+ } catch (error) {
7574
+ failure = { reason: error };
7575
+ } finally {
7576
+ signal?.removeEventListener("abort", cancel);
7577
+ controller.abort(new Error("SafeJS run finished."));
7578
+ for (const release of resources.referenceReleases) release();
7579
+ resources.referenceReleases.clear();
7580
+ const outcomes = await Promise.allSettled(
7581
+ [...cleanups].map((close) => Promise.resolve().then(close))
7582
+ );
7583
+ errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
7584
+ }
7585
+ if (failure !== void 0) throw failure.reason;
7586
+ if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
7587
+ return result;
7588
+ }
7589
+
7590
+ // packages/safe-js/src/interp/accessors.ts
7591
+ var accessorClosures = /* @__PURE__ */ new WeakMap();
7592
+ var getterAdapters = /* @__PURE__ */ new WeakMap();
7593
+ var setterAdapters = /* @__PURE__ */ new WeakMap();
7594
+ function accessorAdapter(closure, kind) {
7595
+ if (kind === "get") {
7596
+ let adapter2 = getterAdapters.get(closure);
7597
+ if (adapter2 === void 0) {
7598
+ adapter2 = () => void 0;
7599
+ getterAdapters.set(closure, adapter2);
7600
+ accessorClosures.set(adapter2, closure);
7601
+ }
7602
+ return adapter2;
7603
+ }
7604
+ let adapter = setterAdapters.get(closure);
7605
+ if (adapter === void 0) {
7606
+ adapter = () => {
7607
+ throw new TypeError("Accessor writes require sandbox execution.");
7608
+ };
7609
+ setterAdapters.set(closure, adapter);
7610
+ accessorClosures.set(adapter, closure);
7611
+ }
7612
+ return adapter;
7613
+ }
7614
+ function accessorClosure(adapter) {
7615
+ if (adapter === void 0) return void 0;
7616
+ const closure = accessorClosures.get(adapter);
7617
+ if (closure === void 0) throw new TypeError("Native accessors cannot execute in the sandbox.");
7618
+ return closure;
7619
+ }
7620
+ function retainedAccessorClosures(descriptor) {
7621
+ const closures = [];
7622
+ for (const adapter of [descriptor.get, descriptor.set]) {
7623
+ const closure = adapter === void 0 ? void 0 : accessorClosures.get(adapter);
7624
+ if (closure !== void 0) closures.push(closure);
7625
+ }
7626
+ return closures;
7627
+ }
7628
+ function readPropertyDescriptor(descriptor, receiver, context, allowNativeGetter = false) {
7629
+ if ("value" in descriptor) return descriptor.value;
7630
+ if (descriptor.get === void 0) return void 0;
7631
+ const getter = accessorClosures.get(descriptor.get);
7632
+ if (getter === void 0) {
7633
+ if (!allowNativeGetter) throw new TypeError("Native accessors cannot execute in the sandbox.");
7634
+ return Reflect.apply(descriptor.get, receiver, []);
7635
+ }
7636
+ if (context?.invokeClosure === void 0)
7637
+ throw new TypeError("Accessor reads require sandbox execution.");
7638
+ return context.invokeClosure(getter, [], receiver);
7639
+ }
7640
+ function writePropertyDescriptor(descriptor, receiver, value, context) {
7641
+ const setter = accessorClosure(descriptor.set);
7642
+ if (setter === void 0) throw new TypeError("Cannot assign to a getter-only property.");
7643
+ if (context?.invokeClosure === void 0)
7644
+ throw new TypeError("Accessor writes require sandbox execution.");
7645
+ return context.invokeClosure(setter, [value], receiver).then(() => void 0);
7646
+ }
7647
+
7648
+ // packages/safe-js/src/interp/symbols.ts
7649
+ var wellKnownSymbols = Object.freeze({
7650
+ iterator: Symbol.iterator,
7651
+ asyncIterator: Symbol.asyncIterator,
7652
+ hasInstance: Symbol.hasInstance,
7653
+ isConcatSpreadable: Symbol.isConcatSpreadable,
7654
+ match: Symbol.match,
7655
+ matchAll: Symbol.matchAll,
7656
+ replace: Symbol.replace,
7657
+ search: Symbol.search,
7658
+ species: Symbol.species,
7659
+ split: Symbol.split,
7660
+ toPrimitive: Symbol.toPrimitive,
7661
+ toStringTag: Symbol.toStringTag,
7662
+ unscopables: Symbol.unscopables
7663
+ });
7664
+
7665
+ // packages/safe-js/src/interp/intrinsics.ts
7666
+ var identities = /* @__PURE__ */ new WeakMap();
7667
+ var realms2 = /* @__PURE__ */ new WeakMap();
7668
+ function registerBuiltinIdentities(budget, bindings) {
7669
+ let realm = realms2.get(budget);
7670
+ if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
7671
+ const pending = Object.entries(bindings).map(([name, value]) => [[name], value]);
7672
+ const visited = /* @__PURE__ */ new WeakSet();
7673
+ for (let index = 0; index < pending.length; index++) {
7674
+ const [path, value] = pending[index];
7675
+ if (value === null || typeof value !== "object") continue;
7676
+ const id = JSON.stringify(path);
7677
+ const previous = realm.get(id);
7678
+ if (previous !== void 0 && previous !== value)
7679
+ throw new TypeError(`Duplicate intrinsic identity: ${id}`);
7680
+ realm.set(id, value);
7681
+ if (!identities.has(value)) identities.set(value, id);
7682
+ if (visited.has(value)) continue;
7683
+ visited.add(value);
7684
+ const owner = isSandboxClosure(value) ? value.properties : value;
7685
+ if (owner === void 0) continue;
7686
+ for (const key of Reflect.ownKeys(owner)) {
7687
+ if (typeof key === "symbol" && internalSymbols.has(key)) continue;
7688
+ const descriptor = Object.getOwnPropertyDescriptor(owner, key);
7689
+ const symbolName = typeof key === "symbol" ? Object.entries(wellKnownSymbols).find(([, symbol]) => symbol === key)?.[0] : void 0;
7690
+ if (typeof key === "symbol" && symbolName === void 0)
7691
+ throw new TypeError("Intrinsic symbol keys must be well-known symbols.");
7692
+ const member = [...path, typeof key === "string" ? key : { symbol: symbolName }];
7693
+ if ("value" in descriptor) pending.push([member, descriptor.value]);
7694
+ for (const kind of ["get", "set"]) {
7695
+ const closure = accessorClosure(descriptor[kind]);
7696
+ if (closure !== void 0) pending.push([[...member, kind], closure]);
7697
+ }
7698
+ }
7699
+ }
7700
+ }
7701
+ function getIntrinsicIdentity(value) {
7702
+ return identities.get(value);
7703
+ }
7704
+ function resolveIntrinsicIdentity(budget, id) {
7705
+ const value = realms2.get(budget)?.get(id);
7706
+ if (value === void 0) throw new TypeError(`Unknown intrinsic identity: ${id}`);
7707
+ return value;
7708
+ }
7709
+ function listIntrinsicIdentities(budget) {
7710
+ return [...realms2.get(budget)?.keys() ?? []];
7711
+ }
7712
+ function releaseIntrinsicIdentities(budget) {
7713
+ realms2.delete(budget);
7714
+ }
7715
+
7736
7716
  // packages/safe-js/src/interp/host-capabilities.ts
7737
7717
  import { types as types6 } from "node:util";
7738
7718
  var MAX_INDEXED_LENGTH = 65536;
@@ -8077,6 +8057,9 @@ function namedKeys(state) {
8077
8057
  });
8078
8058
  }
8079
8059
 
8060
+ // packages/safe-js/src/interp/error-prototypes.ts
8061
+ var errorPrototypes = /* @__PURE__ */ new WeakMap();
8062
+
8080
8063
  // packages/safe-js/src/interp/typed-array-prototypes.ts
8081
8064
  var typedArrayPrototypes = /* @__PURE__ */ new WeakMap();
8082
8065
 
@@ -8475,6 +8458,51 @@ function hasGuestObjectState(value) {
8475
8458
  );
8476
8459
  }
8477
8460
 
8461
+ // packages/safe-js/src/interp/module-namespace.ts
8462
+ var namespaces = /* @__PURE__ */ new WeakSet();
8463
+ function isSandboxModuleNamespace(value) {
8464
+ return value !== null && typeof value === "object" && namespaces.has(value);
8465
+ }
8466
+ function createModuleNamespace(bindings) {
8467
+ const target = /* @__PURE__ */ Object.create(null);
8468
+ const namespace = new Proxy(target, {
8469
+ ownKeys: (owner) => [...Object.getOwnPropertyNames(owner).sort(), ...Object.getOwnPropertySymbols(owner)],
8470
+ set: () => false,
8471
+ defineProperty(owner, key, descriptor) {
8472
+ if (typeof key === "symbol") return Reflect.defineProperty(owner, key, descriptor);
8473
+ const current = Object.getOwnPropertyDescriptor(owner, key);
8474
+ if (current === void 0 || descriptor.configurable === true || descriptor.enumerable === false || "get" in descriptor || "set" in descriptor || descriptor.writable === false) return false;
8475
+ return !("value" in descriptor) || Object.is(descriptor.value, current.value);
8476
+ }
8477
+ });
8478
+ namespaces.add(namespace);
8479
+ const entries = typeof bindings === "function" ? bindings(namespace) : bindings;
8480
+ for (const key of Object.keys(entries).sort())
8481
+ Object.defineProperty(target, key, { value: entries[key], writable: true, enumerable: true });
8482
+ Object.defineProperty(target, Symbol.toStringTag, { value: "Module" });
8483
+ Object.preventExtensions(target);
8484
+ markDescriptorObject(namespace);
8485
+ setSandboxPrototype(namespace, null);
8486
+ return namespace;
8487
+ }
8488
+
8489
+ // packages/safe-js/src/interp/collection-properties.ts
8490
+ var collectionGuestProperties = /* @__PURE__ */ new WeakMap();
8491
+ function getCollectionProperties(value) {
8492
+ const properties = collectionGuestProperties.get(value);
8493
+ if (properties === void 0) throw new TypeError("Invalid sandbox collection storage.");
8494
+ return properties;
8495
+ }
8496
+ function copyCollectionProperties(source, target, encode) {
8497
+ const properties = collectionGuestProperties.get(source) ?? source;
8498
+ for (const key of Reflect.ownKeys(properties)) {
8499
+ const descriptor = Object.getOwnPropertyDescriptor(properties, key);
8500
+ if (!("value" in descriptor)) throw new TypeError("Collection accessor properties cannot be copied as data.");
8501
+ Object.defineProperty(target, key, { ...descriptor, value: encode(descriptor.value) });
8502
+ }
8503
+ if (!Object.isExtensible(properties)) Object.preventExtensions(target);
8504
+ }
8505
+
8478
8506
  // packages/safe-js/src/interp/raw-json.ts
8479
8507
  var rawJsonValues = /* @__PURE__ */ new WeakSet();
8480
8508
  function createRawJson(text) {
@@ -18537,15 +18565,15 @@ function getPropertyValue(target, property, context, receiver = target) {
18537
18565
  const prototype = getBoxedPrototype(target, context.budget);
18538
18566
  return prototype === void 0 ? void 0 : getPropertyValue(prototype, property, context, receiver);
18539
18567
  }
18540
- if (typeof property === "symbol") return void 0;
18541
18568
  if (typeof target === "string" || typeof target === "number" || typeof target === "boolean") {
18542
18569
  const prototype = getBoxedPrototype(target, context.budget);
18543
18570
  if (prototype !== void 0) {
18544
- if (typeof target === "string" && (property === "length" || getStringIndex(property) !== void 0))
18571
+ if (typeof target === "string" && typeof property !== "symbol" && (property === "length" || getStringIndex(property) !== void 0))
18545
18572
  return getStringMember(target, property, context.budget);
18546
18573
  return getPropertyValue(prototype, property, context, receiver);
18547
18574
  }
18548
18575
  }
18576
+ if (typeof property === "symbol") return void 0;
18549
18577
  if (typeof target === "string") return getStringMember(target, property, context.budget);
18550
18578
  if (typeof target === "number") return getNumberMember(property, context.budget);
18551
18579
  if (typeof target === "boolean") return void 0;
@@ -19383,6 +19411,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
19383
19411
  return;
19384
19412
  }
19385
19413
  const prototypeOwner = target;
19414
+ if (isSandboxModuleNamespace(target)) throw new TypeError("Cannot assign to a module namespace.");
19386
19415
  if (checkInherited) {
19387
19416
  const descriptor2 = getSandboxPropertyDescriptor(target, property, budget);
19388
19417
  if (descriptor2 !== void 0 && !("value" in descriptor2))
@@ -19422,6 +19451,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
19422
19451
  for (let prototype = getSandboxPrototype(prototypeOwner, budget); prototype !== null; prototype = getSandboxPrototype(prototype, budget)) {
19423
19452
  budget.visitNode();
19424
19453
  assertSandboxDataDepth(depth++);
19454
+ if (isSandboxModuleNamespace(prototype)) throw new TypeError("Cannot assign through a module namespace.");
19425
19455
  const properties = isSandboxGenerator(prototype) ? getGeneratorProperties(prototype) : isSandboxClosure(prototype) ? prototype.properties : prototype;
19426
19456
  const inherited = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key);
19427
19457
  if (inherited === void 0) continue;
@@ -19441,6 +19471,7 @@ function setSuperProperty(base, receiver, key, value, context) {
19441
19471
  for (let current = base; current !== null; current = getSandboxPrototype(current, budget)) {
19442
19472
  budget.visitNode();
19443
19473
  assertSandboxDataDepth(depth++);
19474
+ if (isSandboxModuleNamespace(current)) throw new TypeError("Cannot assign through a module namespace.");
19444
19475
  const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxClosure(current) ? current.properties : current;
19445
19476
  const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key);
19446
19477
  if (descriptor === void 0) continue;
@@ -21879,6 +21910,8 @@ function serializeCollectionProperties(value, encode, dataOnly = false) {
21879
21910
 
21880
21911
  // packages/safe-js/src/snapshot/guest-heap.ts
21881
21912
  function captureGuestHeapNode(value, encode) {
21913
+ if (isSandboxModuleNamespace(value))
21914
+ return { kind: "module-namespace", entries: Object.keys(value).map((key) => [key, encode(value[key])]) };
21882
21915
  if (isRawJson(value)) return { kind: "raw-json", text: value.rawJSON };
21883
21916
  const intrinsic = getIntrinsicIdentity(value);
21884
21917
  if (intrinsic !== void 0) {
@@ -22896,7 +22929,7 @@ function encodeReplayData(value, options = {}) {
22896
22929
  const id2 = options.identifyPromise?.(entry, path);
22897
22930
  if (typeof id2 === "string" && id2.length > 0) return { tag: "promise-capability", id: id2 };
22898
22931
  }
22899
- if (typeof entry === "object" && entry !== null && hasGuestObjectState(entry)) {
22932
+ if (typeof entry === "object" && entry !== null && hasGuestObjectState(entry) && !isSandboxModuleNamespace(entry)) {
22900
22933
  throw new MissingReplayCapabilityError("Guest function properties and prototype links cannot be serialized.");
22901
22934
  }
22902
22935
  let capabilityId;
@@ -22917,7 +22950,9 @@ function encodeReplayData(value, options = {}) {
22917
22950
  seen.set(entry, id);
22918
22951
  nodes.push(void 0);
22919
22952
  const child = (value2, key) => encode(value2, depth + 1, [...path, key]);
22920
- if (isSandboxClosure(entry)) {
22953
+ if (isSandboxModuleNamespace(entry)) {
22954
+ nodes[id] = { kind: "module-namespace", entries: Object.keys(entry).map((key) => [key, child(entry[key], key)]) };
22955
+ } else if (isSandboxClosure(entry)) {
22921
22956
  nodes[id] = {
22922
22957
  kind: "capability",
22923
22958
  id: capabilityId,
@@ -23126,6 +23161,20 @@ function decodeReplayData(input, options = {}, parent) {
23126
23161
  throw new TypeError("Invalid replay error metadata.");
23127
23162
  }
23128
23163
  const child = (value) => decode(value, depth + 1);
23164
+ if (kind === "module-namespace") {
23165
+ const entries = list(own(node, "entries"));
23166
+ const names = /* @__PURE__ */ new Set();
23167
+ return createModuleNamespace((namespace) => {
23168
+ restored.set(id, namespace);
23169
+ return Object.fromEntries(entries.map((raw) => {
23170
+ const entry2 = list(raw);
23171
+ if (entry2.length !== 2 || typeof entry2[0] !== "string" || names.has(entry2[0]))
23172
+ throw new TypeError("Invalid module namespace export.");
23173
+ names.add(entry2[0]);
23174
+ return [entry2[0], child(entry2[1])];
23175
+ }));
23176
+ });
23177
+ }
23129
23178
  if (kind === "symbol") {
23130
23179
  if (node.description !== void 0 && typeof node.description !== "string") throw new TypeError("Invalid replay symbol description.");
23131
23180
  let symbol;
@@ -26629,6 +26678,7 @@ function createReflectGlobal(budget) {
26629
26678
  for (let current = target; current !== null; current = getSandboxPrototype(current, budget)) {
26630
26679
  budget.visitNode();
26631
26680
  assertSandboxDataDepth(depth++);
26681
+ if (isSandboxModuleNamespace(current)) return false;
26632
26682
  if (isNumericTypedArray(current) && typeof property === "string" && isTypedArrayIndex(property)) {
26633
26683
  if (current === receiver) {
26634
26684
  await setTypedArrayMember(current, property, value, budget, context);
@@ -26773,6 +26823,19 @@ function absent(value) {
26773
26823
  }
26774
26824
  function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
26775
26825
  const node = record3(raw);
26826
+ if (node.kind === "module-namespace") {
26827
+ fields(node, ["kind", "entries"]);
26828
+ const entries = array(node.entries);
26829
+ if (entries.length > maxArrayLength) throw new TypeError("Module namespace exceeds allocation limit.");
26830
+ const names = /* @__PURE__ */ new Set();
26831
+ for (const rawEntry of entries) {
26832
+ const entry = array(rawEntry);
26833
+ if (entry.length !== 2 || typeof entry[0] !== "string" || names.has(entry[0]))
26834
+ throw new TypeError("Invalid module namespace export.");
26835
+ names.add(entry[0]);
26836
+ }
26837
+ return true;
26838
+ }
26776
26839
  if (node.kind === "raw-json") {
26777
26840
  fields(node, ["kind", "text"]);
26778
26841
  if (typeof node.text !== "string") throw new TypeError("Invalid raw JSON source.");
@@ -28643,7 +28706,7 @@ var structuredCloneErrorNames = ["Error", "EvalError", "RangeError", "ReferenceE
28643
28706
  function* cloneStructuredGraph(value, state, budget, depth = 0) {
28644
28707
  assertSandboxDataDepth(depth);
28645
28708
  budget.visitNode();
28646
- if (typeof value === "symbol" || isSandboxClosure(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxArrayIterator(value) || isSandboxArguments(value))
28709
+ if (typeof value === "symbol" || isSandboxModuleNamespace(value) || isSandboxClosure(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxArrayIterator(value) || isSandboxArguments(value))
28647
28710
  throw new DOMException("Value cannot be structured cloned.", "DataCloneError");
28648
28711
  if (typeof value !== "object" || value === null) return allocateProducedSandboxValue(value, budget);
28649
28712
  if (isLiveCapability(value)) throw new DOMException("Capabilities cannot be structured cloned.", "DataCloneError");
@@ -28993,6 +29056,8 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
28993
29056
  }
28994
29057
  if (state.structuredClone && nodeTypes.isSymbolObject(value))
28995
29058
  throw new DOMException("Cannot clone a boxed symbol.", "DataCloneError");
29059
+ if (state.structuredClone && isSandboxModuleNamespace(value))
29060
+ throw new DOMException("Cannot clone a module namespace.", "DataCloneError");
28996
29061
  if (isLiveCapability(value)) throw new TypeError("Live capabilities require their owning realm bridge.");
28997
29062
  if (isRawJson(value)) {
28998
29063
  const existing = state.seen.get(value);
@@ -41807,7 +41872,7 @@ function bindImportDeclaration(declaration, registry, wrappedModules, bindings,
41807
41872
  declaration.source.span
41808
41873
  );
41809
41874
  }
41810
- const wrappedExports = wrappedModules.get(moduleName) ?? createBindingRecord(
41875
+ const wrappedExports = wrappedModules.get(moduleName) ?? createModuleNamespace(
41811
41876
  wrapCancelableBindings(
41812
41877
  wrapCallerInjectedBindings(Object.fromEntries(moduleExports), {
41813
41878
  realm: options.realm,
@@ -41884,7 +41949,7 @@ function registerModuleHostOperationPolicies(registry) {
41884
41949
  function normalizeModuleExports(moduleExports) {
41885
41950
  const entries = moduleExports instanceof Map ? [...moduleExports.entries()] : Object.entries(moduleExports);
41886
41951
  return new Map(
41887
- entries.filter(([exportName]) => exportName.length > 0).sort(([left], [right]) => left.localeCompare(right))
41952
+ entries.sort(([left], [right]) => left.localeCompare(right))
41888
41953
  );
41889
41954
  }
41890
41955
  function createBindingRecord(entries) {
@@ -43891,4 +43956,4 @@ export {
43891
43956
  FileSnapshotBackend,
43892
43957
  run
43893
43958
  };
43894
- //# sourceMappingURL=chunk-MNH75BJN.js.map
43959
+ //# sourceMappingURL=chunk-L3DPV6WY.js.map