@poe-platform/safe-js 0.1.257 → 0.1.258

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.
@@ -7015,6 +7015,23 @@ function getRegexProperties(value) {
7015
7015
  return properties;
7016
7016
  }
7017
7017
 
7018
+ // packages/safe-js/src/interp/collection-properties.ts
7019
+ var collectionGuestProperties = /* @__PURE__ */ new WeakMap();
7020
+ function getCollectionProperties(value) {
7021
+ const properties = collectionGuestProperties.get(value);
7022
+ if (properties === void 0) throw new TypeError("Invalid sandbox collection storage.");
7023
+ return properties;
7024
+ }
7025
+ function copyCollectionProperties(source, target, encode) {
7026
+ const properties = collectionGuestProperties.get(source) ?? source;
7027
+ for (const key of Reflect.ownKeys(properties)) {
7028
+ const descriptor = Object.getOwnPropertyDescriptor(properties, key);
7029
+ if (!("value" in descriptor)) throw new TypeError("Collection accessor properties cannot be copied as data.");
7030
+ Object.defineProperty(target, key, { ...descriptor, value: encode(descriptor.value) });
7031
+ }
7032
+ if (!Object.isExtensible(properties)) Object.preventExtensions(target);
7033
+ }
7034
+
7018
7035
  // packages/safe-js/src/interp/accessors.ts
7019
7036
  var accessorClosures = /* @__PURE__ */ new WeakMap();
7020
7037
  var getterAdapters = /* @__PURE__ */ new WeakMap();
@@ -7886,10 +7903,10 @@ function trackIntrinsicState(budget, root, owner, targets) {
7886
7903
  value: isGuestClosure(target) ? materializeFunctionProperties(target) : target,
7887
7904
  prototype: getSandboxPrototype(target),
7888
7905
  explicit: hasExplicitSandboxPrototype(target)
7889
- })).map((record3) => ({
7890
- ...record3,
7891
- extensible: Object.isExtensible(record3.value),
7892
- descriptors: new Map(Reflect.ownKeys(record3.value).map((key) => [key, Object.getOwnPropertyDescriptor(record3.value, key)]))
7906
+ })).map((record4) => ({
7907
+ ...record4,
7908
+ extensible: Object.isExtensible(record4.value),
7909
+ descriptors: new Map(Reflect.ownKeys(record4.value).map((key) => [key, Object.getOwnPropertyDescriptor(record4.value, key)]))
7893
7910
  }));
7894
7911
  for (const { target } of records)
7895
7912
  if (isGuestClosure(target)) intrinsicFunctions.add(target);
@@ -7947,7 +7964,7 @@ function getSandboxPropertyDescriptor(value, key, budget) {
7947
7964
  let current = value;
7948
7965
  let depth = 0;
7949
7966
  while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxDate(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
7950
- const properties = isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? void 0 : current;
7967
+ const properties = isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
7951
7968
  const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key);
7952
7969
  if (descriptor !== void 0) return descriptor;
7953
7970
  current = getSandboxPrototype(current, budget);
@@ -7964,6 +7981,7 @@ function getSandboxDataProperty(value, key, budget) {
7964
7981
  while (typeof current === "object" && current !== null) {
7965
7982
  if (isGuestHostObject(current)) return typeof key === "symbol" ? void 0 : getHostObjectMember(current, String(key));
7966
7983
  if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key)?.value;
7984
+ if (isSandboxMap(current) || isSandboxSet(current)) return Object.getOwnPropertyDescriptor(getCollectionProperties(current), key)?.value;
7967
7985
  if (isGuestClosure(current)) {
7968
7986
  const entry = getGuestFunctionProperty(current, key);
7969
7987
  if (entry !== void 0 || Object.hasOwn(current.properties ?? {}, key)) return entry;
@@ -8079,9 +8097,9 @@ var SandboxPromiseRejectionTracker = class {
8079
8097
  });
8080
8098
  }
8081
8099
  observe(promise) {
8082
- const record3 = this.recordsByPromise.get(promise);
8083
- if (record3 !== void 0) {
8084
- record3.observed = true;
8100
+ const record4 = this.recordsByPromise.get(promise);
8101
+ if (record4 !== void 0) {
8102
+ record4.observed = true;
8085
8103
  }
8086
8104
  }
8087
8105
  track(promise, outcome) {
@@ -8089,13 +8107,13 @@ var SandboxPromiseRejectionTracker = class {
8089
8107
  if (existing !== void 0 && outcome === void 0) {
8090
8108
  return;
8091
8109
  }
8092
- const record3 = existing ?? {
8110
+ const record4 = existing ?? {
8093
8111
  observed: false,
8094
8112
  promise,
8095
8113
  rejected: false
8096
8114
  };
8097
- this.records.add(record3);
8098
- this.recordsByPromise.set(promise, record3);
8115
+ this.records.add(record4);
8116
+ this.recordsByPromise.set(promise, record4);
8099
8117
  const pending = outcome ?? promise.promise;
8100
8118
  pending.then(
8101
8119
  () => void 0,
@@ -8105,9 +8123,9 @@ var SandboxPromiseRejectionTracker = class {
8105
8123
  for (const interrupt of this.fatalWaiters) interrupt(reason);
8106
8124
  this.fatalWaiters.clear();
8107
8125
  }
8108
- if (record3.rejected) return;
8109
- record3.rejected = true;
8110
- record3.rejectionReason = reason;
8126
+ if (record4.rejected) return;
8127
+ record4.rejected = true;
8128
+ record4.rejectionReason = reason;
8111
8129
  }
8112
8130
  );
8113
8131
  pending.catch(() => void 0);
@@ -8115,11 +8133,11 @@ var SandboxPromiseRejectionTracker = class {
8115
8133
  async findUnhandledRejection() {
8116
8134
  await flushPromiseJobs();
8117
8135
  if (this.fatalRejection !== void 0) throw this.fatalRejection;
8118
- for (const record3 of this.records) {
8119
- if (record3.rejected && !record3.observed) {
8136
+ for (const record4 of this.records) {
8137
+ if (record4.rejected && !record4.observed) {
8120
8138
  return {
8121
- reason: record3.rejectionReason,
8122
- span: record3.promise.span
8139
+ reason: record4.rejectionReason,
8140
+ span: record4.promise.span
8123
8141
  };
8124
8142
  }
8125
8143
  }
@@ -8569,6 +8587,81 @@ function serializePropertyDescriptors(target, encode) {
8569
8587
  extensible: Object.isExtensible(target)
8570
8588
  };
8571
8589
  }
8590
+ function record(value, names) {
8591
+ if (typeof value !== "object" || value === null || Array.isArray(value))
8592
+ throw new TypeError("Invalid property descriptor record.");
8593
+ const descriptors2 = Object.getOwnPropertyDescriptors(value);
8594
+ if (Reflect.ownKeys(descriptors2).length !== names.length || names.some((name) => !Object.hasOwn(descriptors2, name) || !("value" in descriptors2[name])))
8595
+ throw new TypeError("Invalid property descriptor fields.");
8596
+ return Object.fromEntries(names.map((name) => [name, descriptors2[name].value]));
8597
+ }
8598
+ function restorePropertyDescriptors(target, raw, decode) {
8599
+ const data = record(raw, ["properties", "extensible"]);
8600
+ if (!Array.isArray(data.properties) || typeof data.extensible !== "boolean")
8601
+ throw new TypeError("Invalid property descriptor state.");
8602
+ const decoded = /* @__PURE__ */ new Map();
8603
+ for (const entry of data.properties) {
8604
+ if (!Array.isArray(entry) || entry.length !== 2)
8605
+ throw new TypeError("Invalid property descriptor entry.");
8606
+ const key = decode(entry[0]);
8607
+ if (typeof key !== "string" && typeof key !== "symbol" || typeof key === "symbol" && internalSymbols.has(key))
8608
+ throw new TypeError("Invalid property key.");
8609
+ if (decoded.has(key)) throw new TypeError("Duplicate property key.");
8610
+ const kind = entry[1] !== null && typeof entry[1] === "object" ? Object.getOwnPropertyDescriptor(entry[1], "kind")?.value : void 0;
8611
+ if (kind !== "data" && kind !== "accessor") throw new TypeError("Invalid property descriptor kind.");
8612
+ const descriptor = record(entry[1], kind === "data" ? ["kind", "value", "writable", "enumerable", "configurable"] : ["kind", "get", "set", "enumerable", "configurable"]);
8613
+ if (typeof descriptor.enumerable !== "boolean" || typeof descriptor.configurable !== "boolean" || kind === "data" && typeof descriptor.writable !== "boolean")
8614
+ throw new TypeError("Invalid property descriptor flags.");
8615
+ const result = { enumerable: descriptor.enumerable, configurable: descriptor.configurable };
8616
+ if (kind === "data") {
8617
+ result.value = decode(descriptor.value);
8618
+ result.writable = descriptor.writable;
8619
+ } else {
8620
+ for (const accessor of ["get", "set"]) {
8621
+ const closure = decode(descriptor[accessor]);
8622
+ if (closure !== void 0 && !isSandboxClosure(closure))
8623
+ throw new TypeError("Property accessors require a sandbox closure.");
8624
+ result[accessor] = closure === void 0 ? void 0 : accessorAdapter(closure, accessor);
8625
+ }
8626
+ }
8627
+ decoded.set(key, result);
8628
+ }
8629
+ const trial = Object.defineProperties(Array.isArray(target) ? [] : /* @__PURE__ */ Object.create(null), Object.getOwnPropertyDescriptors(target));
8630
+ if (!Object.isExtensible(target)) Object.preventExtensions(trial);
8631
+ applyDescriptors(trial, decoded, data.extensible);
8632
+ applyDescriptors(target, decoded, data.extensible);
8633
+ markDescriptorObject(target);
8634
+ }
8635
+ function keyGroup(key) {
8636
+ if (typeof key === "symbol") return "symbol";
8637
+ const index = Number(key);
8638
+ return Number.isInteger(index) && index >= 0 && index < 4294967295 && String(index) === key ? "index" : "string";
8639
+ }
8640
+ function applyDescriptors(target, descriptors2, extensible) {
8641
+ if (extensible && !Object.isExtensible(target)) throw new TypeError("Cannot restore extensibility.");
8642
+ const original = Reflect.ownKeys(target).filter((key) => typeof key !== "symbol" || !internalSymbols.has(key));
8643
+ const keep = /* @__PURE__ */ new Set();
8644
+ for (const group of ["index", "string", "symbol"]) {
8645
+ const positions = new Map(original.filter((key) => keyGroup(key) === group).map((key, index) => [key, index]));
8646
+ let previous = -1;
8647
+ for (const key of descriptors2.keys()) {
8648
+ if (keyGroup(key) !== group) continue;
8649
+ const position = positions.get(key);
8650
+ if (group === "index") {
8651
+ if (position !== void 0) keep.add(key);
8652
+ } else {
8653
+ if (position === void 0 || position <= previous) break;
8654
+ keep.add(key);
8655
+ previous = position;
8656
+ }
8657
+ }
8658
+ }
8659
+ for (const key of original)
8660
+ if (!keep.has(key) && !Reflect.deleteProperty(target, key))
8661
+ throw new TypeError("Cannot restore nonconfigurable property order or deletion.");
8662
+ for (const [key, descriptor] of descriptors2) Object.defineProperty(target, key, descriptor);
8663
+ if (!extensible) Object.preventExtensions(target);
8664
+ }
8572
8665
 
8573
8666
  // packages/safe-js/src/interp/running-state.ts
8574
8667
  var runningObjects = /* @__PURE__ */ new WeakSet();
@@ -9842,7 +9935,8 @@ function hasOwnSandboxProperty(value, key, enumerable) {
9842
9935
  else if (isSandboxClosure(value)) {
9843
9936
  if (key === "length" || key === "name") return !enumerable;
9844
9937
  properties = value.properties ?? /* @__PURE__ */ Object.create(null);
9845
- } else if (isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxGenerator(value))
9938
+ } else if (isSandboxMap(value) || isSandboxSet(value)) properties = getCollectionProperties(value);
9939
+ else if (isSandboxPromise(value) || isSandboxGenerator(value))
9846
9940
  return false;
9847
9941
  else if (isSandboxRegex(value)) properties = getRegexProperties(value);
9848
9942
  else properties = Object(value);
@@ -12486,14 +12580,14 @@ function createObjectArrayGlobals(options) {
12486
12580
  call: ([value]) => {
12487
12581
  if (isGuestHostObject(value))
12488
12582
  throw new TypeError("Live host objects cannot be made non-extensible.");
12489
- Object.preventExtensions(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value);
12583
+ Object.preventExtensions(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
12490
12584
  return value;
12491
12585
  },
12492
12586
  name: "preventExtensions"
12493
12587
  }),
12494
12588
  isExtensible: createSandboxClosure({
12495
12589
  sandbox: true,
12496
- call: ([value]) => Object.isExtensible(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value),
12590
+ call: ([value]) => Object.isExtensible(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
12497
12591
  name: "isExtensible"
12498
12592
  }),
12499
12593
  seal: createSandboxClosure({
@@ -12501,14 +12595,14 @@ function createObjectArrayGlobals(options) {
12501
12595
  call: ([value]) => {
12502
12596
  if (isGuestHostObject(value))
12503
12597
  throw new TypeError("Live host objects cannot be sealed.");
12504
- Object.seal(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value);
12598
+ Object.seal(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
12505
12599
  return value;
12506
12600
  },
12507
12601
  name: "seal"
12508
12602
  }),
12509
12603
  isSealed: createSandboxClosure({
12510
12604
  sandbox: true,
12511
- call: ([value]) => Object.isSealed(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value),
12605
+ call: ([value]) => Object.isSealed(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
12512
12606
  name: "isSealed"
12513
12607
  }),
12514
12608
  freeze: createSandboxClosure({
@@ -12517,7 +12611,7 @@ function createObjectArrayGlobals(options) {
12517
12611
  if (isGuestHostObject(value))
12518
12612
  throw new TypeError("Live host objects cannot be frozen.");
12519
12613
  if (typeof value === "object" && value !== null) {
12520
- Object.freeze(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value);
12614
+ Object.freeze(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
12521
12615
  }
12522
12616
  return value;
12523
12617
  },
@@ -12525,7 +12619,7 @@ function createObjectArrayGlobals(options) {
12525
12619
  }),
12526
12620
  isFrozen: createSandboxClosure({
12527
12621
  sandbox: true,
12528
- call: ([value]) => Object.isFrozen(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value),
12622
+ call: ([value]) => Object.isFrozen(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
12529
12623
  name: "isFrozen"
12530
12624
  }),
12531
12625
  assign: createSandboxClosure({
@@ -12733,6 +12827,7 @@ function assignSandboxValues(target, sources, budget, context) {
12733
12827
  })();
12734
12828
  }
12735
12829
  function objectProperties(value, mutable = false) {
12830
+ if (isSandboxMap(value) || isSandboxSet(value)) return getCollectionProperties(value);
12736
12831
  if (isSandboxRegex(value)) return getRegexProperties(value);
12737
12832
  if (isSandboxDate(value)) {
12738
12833
  return value;
@@ -17076,7 +17171,7 @@ async function evaluateDeleteExpression(node, context) {
17076
17171
  }
17077
17172
  throw new TypeError("Cannot delete properties of null or undefined.");
17078
17173
  }
17079
- if (!isIndexableSandboxValue(member.object) && !isSandboxRegex(member.object)) {
17174
+ if (!isIndexableSandboxValue(member.object) && !isSandboxRegex(member.object) && !isSandboxMap(member.object) && !isSandboxSet(member.object)) {
17080
17175
  throw new TypeError("Unary operator 'delete' requires a sandbox object property.");
17081
17176
  }
17082
17177
  const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
@@ -18052,6 +18147,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
18052
18147
  return writePropertyDescriptor(descriptor2, target, value, context);
18053
18148
  }
18054
18149
  if (isGuestClosure(target)) target = materializeFunctionProperties(target);
18150
+ if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
18055
18151
  if (isFloat32Array(target)) {
18056
18152
  if (typeof property === "symbol") throw new TypeError("Typed array symbol properties are not yet supported.");
18057
18153
  setFloat32Member(target, property, value);
@@ -18120,6 +18216,7 @@ function deleteSandboxProperty(target, property) {
18120
18216
  if (isGuestHostObject(target)) return deleteHostObjectMember(target, String(property));
18121
18217
  if (isGuestClosure(target)) target = materializeFunctionProperties(target);
18122
18218
  if (isSandboxRegex(target)) target = getRegexProperties(target);
18219
+ if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
18123
18220
  if (Array.isArray(target)) {
18124
18221
  assertCollectionMutable(target);
18125
18222
  }
@@ -18736,6 +18833,15 @@ function normalizeClosureResult(result, budget) {
18736
18833
  });
18737
18834
  }
18738
18835
 
18836
+ // packages/safe-js/src/snapshot/collection-properties.ts
18837
+ function serializeCollectionProperties(value, encode, dataOnly = false) {
18838
+ const properties = getCollectionProperties(value);
18839
+ if (Reflect.ownKeys(properties).length === 0 && Object.isExtensible(properties)) return {};
18840
+ if (dataOnly && Reflect.ownKeys(properties).some((key) => !("value" in Object.getOwnPropertyDescriptor(properties, key))))
18841
+ throw new TypeError("Collection accessor properties cannot be serialized as replay data.");
18842
+ return { propertyState: serializePropertyDescriptors(properties, encode) };
18843
+ }
18844
+
18739
18845
  // packages/safe-js/src/snapshot/float32array.ts
18740
18846
  function encodeFloat32Storage(value, id, buffers, reference) {
18741
18847
  const storage = float32Storage(value);
@@ -18967,6 +19073,7 @@ function encodeReplayData(value, options = {}) {
18967
19073
  } else if (isSandboxMap(entry)) {
18968
19074
  nodes[id] = {
18969
19075
  kind: "map",
19076
+ ...serializeCollectionProperties(entry, (value2) => child(value2, "<collection-property>"), true),
18970
19077
  entries: [...entry.entries].map(([key, value2], index) => [
18971
19078
  child(key, `key:${index}`),
18972
19079
  child(value2, `value:${index}`)
@@ -18975,6 +19082,7 @@ function encodeReplayData(value, options = {}) {
18975
19082
  } else if (isSandboxSet(entry)) {
18976
19083
  nodes[id] = {
18977
19084
  kind: "set",
19085
+ ...serializeCollectionProperties(entry, (value2) => child(value2, "<collection-property>"), true),
18978
19086
  values: [...entry.values].map((value2, index) => child(value2, String(index)))
18979
19087
  };
18980
19088
  } else if (isSandboxRegex(entry)) {
@@ -19024,7 +19132,7 @@ function decodeReplayData(input, options = {}, parent) {
19024
19132
  const compilation = new CompileScope(parent?.owner);
19025
19133
  try {
19026
19134
  validateSnapshotData(input);
19027
- const graph = record(input);
19135
+ const graph = record2(input);
19028
19136
  const nodes = list(own(graph, "nodes"));
19029
19137
  const restored = /* @__PURE__ */ new Map();
19030
19138
  const initializeIterators = [];
@@ -19032,7 +19140,7 @@ function decodeReplayData(input, options = {}, parent) {
19032
19140
  if (depth > MAX_DATA_DEPTH) throw new TypeError("Replay data exceeds the nesting limit.");
19033
19141
  if (entry === null || typeof entry === "boolean" || typeof entry === "string") return entry;
19034
19142
  if (typeof entry === "number" && Number.isFinite(entry)) return entry;
19035
- const atom = record(entry);
19143
+ const atom = record2(entry);
19036
19144
  if (own(atom, "tag") === "promise-capability") {
19037
19145
  const id2 = own(atom, "id");
19038
19146
  if (typeof id2 !== "string" || id2.length === 0)
@@ -19076,7 +19184,7 @@ function decodeReplayData(input, options = {}, parent) {
19076
19184
  }
19077
19185
  const id = Number(atom.id);
19078
19186
  if (restored.has(id)) return restored.get(id);
19079
- const node = record(nodes[id]);
19187
+ const node = record2(nodes[id]);
19080
19188
  const kind = own(node, "kind");
19081
19189
  if (Object.hasOwn(node, "errorType") && (kind !== "object" || !sandboxErrorNames.includes(node.errorType))) {
19082
19190
  throw new TypeError("Invalid replay error metadata.");
@@ -19100,7 +19208,7 @@ function decodeReplayData(input, options = {}, parent) {
19100
19208
  const capability = options.resolveCapability?.(capabilityId);
19101
19209
  if (!isSandboxClosure(capability))
19102
19210
  throw new TypeError(`Missing replay capability '${capabilityId}'.`);
19103
- if (record(own(node, "properties")).tag === "undefined") {
19211
+ if (record2(own(node, "properties")).tag === "undefined") {
19104
19212
  restored.set(id, capability);
19105
19213
  return capability;
19106
19214
  }
@@ -19124,13 +19232,13 @@ function decodeReplayData(input, options = {}, parent) {
19124
19232
  if (kind === "boxed") {
19125
19233
  validateBoxedProperties(node);
19126
19234
  const payload = own(node, "value");
19127
- const payloadRecord = payload !== null && typeof payload === "object" ? record(payload) : void 0;
19128
- const symbolReference = payloadRecord !== void 0 && own(payloadRecord, "tag") === "ref" && Number.isSafeInteger(payloadRecord.id) && Number(payloadRecord.id) >= 0 && Number(payloadRecord.id) < nodes.length && own(record(nodes[Number(payloadRecord.id)]), "kind") === "symbol";
19129
- if (typeof payload !== "number" && typeof payload !== "string" && typeof payload !== "boolean" && !symbolReference && (payload === null || typeof payload !== "object" || !["number", "bigint"].includes(String(own(record(payload), "tag")))))
19235
+ const payloadRecord = payload !== null && typeof payload === "object" ? record2(payload) : void 0;
19236
+ const symbolReference = payloadRecord !== void 0 && own(payloadRecord, "tag") === "ref" && Number.isSafeInteger(payloadRecord.id) && Number(payloadRecord.id) >= 0 && Number(payloadRecord.id) < nodes.length && own(record2(nodes[Number(payloadRecord.id)]), "kind") === "symbol";
19237
+ if (typeof payload !== "number" && typeof payload !== "string" && typeof payload !== "boolean" && !symbolReference && (payload === null || typeof payload !== "object" || !["number", "bigint"].includes(String(own(record2(payload), "tag")))))
19130
19238
  throw new TypeError("Invalid boxed primitive payload.");
19131
19239
  const result3 = createSandboxBox(child(payload));
19132
19240
  restored.set(id, result3);
19133
- defineProperties(result3, record(own(node, "properties")), child, node.symbolEntries);
19241
+ defineProperties(result3, record2(own(node, "properties")), child, node.symbolEntries);
19134
19242
  if (!node.extensible) Object.preventExtensions(result3);
19135
19243
  return result3;
19136
19244
  }
@@ -19146,7 +19254,7 @@ function decodeReplayData(input, options = {}, parent) {
19146
19254
  if (node.extensible !== void 0 && typeof node.extensible !== "boolean") throw new TypeError("Invalid replay Date extensibility.");
19147
19255
  const result3 = restoreDateTime(own(node, "time"));
19148
19256
  restored.set(id, result3);
19149
- defineProperties(result3, node.properties === void 0 ? {} : record(node.properties), child, node.symbolProperties);
19257
+ defineProperties(result3, node.properties === void 0 ? {} : record2(node.properties), child, node.symbolProperties);
19150
19258
  if (node.extensible === false) Object.preventExtensions(result3);
19151
19259
  return result3;
19152
19260
  }
@@ -19155,7 +19263,7 @@ function decodeReplayData(input, options = {}, parent) {
19155
19263
  throw new TypeError("Invalid Float32Array extensibility.");
19156
19264
  const result3 = decodeFloat32Storage(node, child);
19157
19265
  restored.set(id, result3);
19158
- defineProperties(result3, record(own(node, "properties")), child);
19266
+ defineProperties(result3, record2(own(node, "properties")), child);
19159
19267
  if (!node.extensible) Object.preventExtensions(result3);
19160
19268
  return result3;
19161
19269
  }
@@ -19175,7 +19283,7 @@ function decodeReplayData(input, options = {}, parent) {
19175
19283
  exhausted,
19176
19284
  ...node.global === void 0 ? {} : { global: node.global, unicode: node.unicode }
19177
19285
  }, result3);
19178
- defineProperties(result3, record(own(node, "properties")), child, node.symbolEntries);
19286
+ defineProperties(result3, record2(own(node, "properties")), child, node.symbolEntries);
19179
19287
  if (!node.extensible) Object.preventExtensions(result3);
19180
19288
  return result3;
19181
19289
  }
@@ -19192,13 +19300,14 @@ function decodeReplayData(input, options = {}, parent) {
19192
19300
  initializeIterators.push(() => {
19193
19301
  restoreSandboxCollectionIterator({ collection, collectionKind, method, index, exhausted }, result3);
19194
19302
  });
19195
- defineProperties(result3, record(own(node, "properties")), child);
19303
+ defineProperties(result3, record2(own(node, "properties")), child);
19196
19304
  if (!node.extensible) Object.preventExtensions(result3);
19197
19305
  return result3;
19198
19306
  }
19199
19307
  if (kind === "map") {
19200
19308
  const result3 = createSandboxMap();
19201
19309
  restored.set(id, result3);
19310
+ restoreCollectionDataProperties(result3, node, child);
19202
19311
  for (const pair of list(own(node, "entries"))) {
19203
19312
  const entries = list(pair);
19204
19313
  if (entries.length !== 2) throw new TypeError("Invalid replay map entry.");
@@ -19209,6 +19318,7 @@ function decodeReplayData(input, options = {}, parent) {
19209
19318
  if (kind === "set") {
19210
19319
  const result3 = createSandboxSet();
19211
19320
  restored.set(id, result3);
19321
+ restoreCollectionDataProperties(result3, node, child);
19212
19322
  for (const value of list(own(node, "values"))) result3.values.add(child(value));
19213
19323
  return result3;
19214
19324
  }
@@ -19223,17 +19333,17 @@ function decodeReplayData(input, options = {}, parent) {
19223
19333
  return result3;
19224
19334
  }
19225
19335
  if (kind === "arguments") {
19226
- const data = record(own(node, "data"));
19336
+ const data = record2(own(node, "data"));
19227
19337
  validateArgumentsProperties(data, "arguments");
19228
19338
  if (data.kind !== "arguments") throw new TypeError("Invalid replay arguments.");
19229
19339
  const args = createSandboxArguments([]);
19230
19340
  restored.set(id, args);
19231
19341
  if (!data.lengthBeforeCallee) delete args.length;
19232
- defineProperties(args, record(data.properties), child);
19342
+ defineProperties(args, record2(data.properties), child);
19233
19343
  if (data.iterator === null) Reflect.deleteProperty(args, Symbol.iterator);
19234
19344
  else
19235
19345
  Object.defineProperty(args, Symbol.iterator, {
19236
- ...record(data.iterator),
19346
+ ...record2(data.iterator),
19237
19347
  value: Array.prototype.values
19238
19348
  });
19239
19349
  if (!data.extensible) Object.preventExtensions(args);
@@ -19253,7 +19363,7 @@ function decodeReplayData(input, options = {}, parent) {
19253
19363
  }
19254
19364
  if (kind === "array" && node.nullPrototype) Object.setPrototypeOf(result2, null);
19255
19365
  restored.set(id, result2);
19256
- defineProperties(result2, record(own(node, "properties")), child, node.symbolProperties);
19366
+ defineProperties(result2, record2(own(node, "properties")), child, node.symbolProperties);
19257
19367
  if (!node.extensible) Object.preventExtensions(result2);
19258
19368
  return result2;
19259
19369
  };
@@ -19279,7 +19389,7 @@ function defineProperties(target, properties, decode, symbolProperties) {
19279
19389
  }
19280
19390
  }
19281
19391
  for (const [key, value] of entries) {
19282
- const descriptor = record(value);
19392
+ const descriptor = record2(value);
19283
19393
  for (const field of Object.keys(descriptor)) {
19284
19394
  if (!["value", "writable", "enumerable", "configurable"].includes(field))
19285
19395
  throw new TypeError("Invalid replay property descriptor.");
@@ -19295,7 +19405,16 @@ function defineProperties(target, properties, decode, symbolProperties) {
19295
19405
  });
19296
19406
  }
19297
19407
  }
19298
- function record(value) {
19408
+ function restoreCollectionDataProperties(value, node, decode) {
19409
+ if (!Object.hasOwn(node, "propertyState")) return;
19410
+ const properties = record2(node.propertyState);
19411
+ for (const entry of list(own(properties, "properties"))) {
19412
+ const descriptor = record2(list(entry)[1]);
19413
+ if (own(descriptor, "kind") !== "data") throw new TypeError("Replay collection properties must be data descriptors.");
19414
+ }
19415
+ restorePropertyDescriptors(getCollectionProperties(value), properties, decode);
19416
+ }
19417
+ function record2(value) {
19299
19418
  if (value === null || typeof value !== "object" || Array.isArray(value))
19300
19419
  throw new TypeError("Expected replay data object.");
19301
19420
  return value;
@@ -19549,21 +19668,21 @@ function invokeHostCallback(invoke, options) {
19549
19668
  throw error;
19550
19669
  }
19551
19670
  }
19552
- function executeHostCall(record3, restored, invoke, stackFrames, options, span, callbacks, onReplay) {
19671
+ function executeHostCall(record4, restored, invoke, stackFrames, options, span, callbacks, onReplay) {
19553
19672
  const hostCalls = options.hostCalls;
19554
19673
  let replayed;
19555
19674
  try {
19556
- replayed = restored ? hostCalls.replayOutcome(record3) : void 0;
19675
+ replayed = restored ? hostCalls.replayOutcome(record4) : void 0;
19557
19676
  } catch (error) {
19558
- if (!(error instanceof UnresolvedReplayCapabilityError) || !record3.asynchronous) throw error;
19677
+ if (!(error instanceof UnresolvedReplayCapabilityError) || !record4.asynchronous) throw error;
19559
19678
  const promise = (async () => {
19560
19679
  let missing = error;
19561
19680
  while (true) {
19562
19681
  await hostCalls.waitForCapability(missing.id);
19563
19682
  try {
19564
- const outcome2 = hostCalls.replayOutcome(record3);
19683
+ const outcome2 = hostCalls.replayOutcome(record4);
19565
19684
  if (outcome2 === void 0) throw new TypeError("Missing restored host outcome.");
19566
- restoreReplayedHostState(record3, outcome2, onReplay);
19685
+ restoreReplayedHostState(record4, outcome2, onReplay);
19567
19686
  if (outcome2.status === "rejected") throw outcome2.reason;
19568
19687
  return outcome2.value;
19569
19688
  } catch (error2) {
@@ -19573,28 +19692,28 @@ function executeHostCall(record3, restored, invoke, stackFrames, options, span,
19573
19692
  }
19574
19693
  })();
19575
19694
  void promise.catch(() => void 0);
19576
- return createSandboxPromise(promise, { hostCall: record3, hostCallJournal: hostCalls });
19695
+ return createSandboxPromise(promise, { hostCall: record4, hostCallJournal: hostCalls });
19577
19696
  }
19578
19697
  if (replayed !== void 0) {
19579
- restoreReplayedHostState(record3, replayed, onReplay);
19580
- if (record3.asynchronous) return createReplayedHostCallResult(replayed, record3, hostCalls);
19698
+ restoreReplayedHostState(record4, replayed, onReplay);
19699
+ if (record4.asynchronous) return createReplayedHostCallResult(replayed, record4, hostCalls);
19581
19700
  if (replayed.status === "rejected") throw replayed.reason;
19582
19701
  return replayed.value;
19583
19702
  }
19584
- if (restored && record3.policy === "read-side-effect" && record3.lifecycle === "consumed" && record3.outcome !== void 0) {
19585
- return createReplayedHostCallResult(record3.outcome, record3, hostCalls);
19703
+ if (restored && record4.policy === "read-side-effect" && record4.lifecycle === "consumed" && record4.outcome !== void 0) {
19704
+ return createReplayedHostCallResult(record4.outcome, record4, hostCalls);
19586
19705
  }
19587
- if (restored && record3.policy === "read-side-effect" && record3.lifecycle === "settled" && record3.outcome !== void 0) {
19588
- return createHostCallPromise(record3, Promise.resolve(record3.outcome), hostCalls);
19706
+ if (restored && record4.policy === "read-side-effect" && record4.lifecycle === "settled" && record4.outcome !== void 0) {
19707
+ return createHostCallPromise(record4, Promise.resolve(record4.outcome), hostCalls);
19589
19708
  }
19590
- if (restored && record3.lifecycle === "cancelled" && record3.policy === "read-side-effect") {
19709
+ if (restored && record4.lifecycle === "cancelled" && record4.policy === "read-side-effect") {
19591
19710
  throw new HostCallResumabilityError(
19592
- record3,
19711
+ record4,
19593
19712
  "reset",
19594
- `Host call ${record3.id} was cancelled; reset is required.`
19713
+ `Host call ${record4.id} was cancelled; reset is required.`
19595
19714
  );
19596
19715
  }
19597
- if (restored && record3.policy === "read-side-effect" && record3.lifecycle !== "created") {
19716
+ if (restored && record4.policy === "read-side-effect" && record4.lifecycle !== "created") {
19598
19717
  let active = true;
19599
19718
  const context = callbacks === void 0 ? void 0 : {
19600
19719
  callbacks: new Map(callbacks.hostFunctions),
@@ -19617,13 +19736,13 @@ function executeHostCall(record3, restored, invoke, stackFrames, options, span,
19617
19736
  );
19618
19737
  }
19619
19738
  };
19620
- const outcome2 = hostCalls.reconcile(record3, context).finally(() => {
19739
+ const outcome2 = hostCalls.reconcile(record4, context).finally(() => {
19621
19740
  active = false;
19622
19741
  });
19623
- return createHostCallPromise(record3, outcome2, hostCalls);
19742
+ return createHostCallPromise(record4, outcome2, hostCalls);
19624
19743
  }
19625
19744
  if (restored && callbacks !== void 0) callbacks.nextReissuedInvocation = 0;
19626
- hostCalls.start(record3);
19745
+ hostCalls.start(record4);
19627
19746
  let result;
19628
19747
  try {
19629
19748
  result = invoke();
@@ -19632,17 +19751,17 @@ function executeHostCall(record3, restored, invoke, stackFrames, options, span,
19632
19751
  throw error;
19633
19752
  }
19634
19753
  const reason = createHostErrorValue(error, stackFrames, options.budget, span);
19635
- hostCalls.settle(record3, { status: "rejected", reason });
19754
+ hostCalls.settle(record4, { status: "rejected", reason });
19636
19755
  throw error;
19637
19756
  }
19638
19757
  if (!isPromiseLike3(result)) {
19639
- record3.asynchronous = false;
19758
+ record4.asynchronous = false;
19640
19759
  const value = copyHostResultToSandbox(result, stackFrames, options);
19641
- hostCalls.settle(record3, { status: "fulfilled", value });
19642
- hostCalls.consume(record3);
19760
+ hostCalls.settle(record4, { status: "fulfilled", value });
19761
+ hostCalls.consume(record4);
19643
19762
  return value;
19644
19763
  }
19645
- record3.asynchronous = true;
19764
+ record4.asynchronous = true;
19646
19765
  const outcome = wrapHostPromiseWithSignal(Promise.resolve(result), options.signal).then(
19647
19766
  (value) => {
19648
19767
  try {
@@ -19670,9 +19789,9 @@ function executeHostCall(record3, restored, invoke, stackFrames, options, span,
19670
19789
  };
19671
19790
  }
19672
19791
  );
19673
- return createHostCallPromise(record3, outcome, hostCalls);
19792
+ return createHostCallPromise(record4, outcome, hostCalls);
19674
19793
  }
19675
- function restoreReplayedHostState(record3, outcome, onReplay) {
19794
+ function restoreReplayedHostState(record4, outcome, onReplay) {
19676
19795
  try {
19677
19796
  const result = onReplay?.(outcome);
19678
19797
  if (isPromiseLike3(result)) {
@@ -19681,30 +19800,30 @@ function restoreReplayedHostState(record3, outcome, onReplay) {
19681
19800
  }
19682
19801
  } catch (reason) {
19683
19802
  const error = new HostCallResumabilityError(
19684
- record3,
19803
+ record4,
19685
19804
  "reset",
19686
- `Cannot restore host-local state for ${record3.id}: ${reason instanceof Error ? reason.message : String(reason)}`
19805
+ `Cannot restore host-local state for ${record4.id}: ${reason instanceof Error ? reason.message : String(reason)}`
19687
19806
  );
19688
19807
  promiseReplayContext.getStore()?.fail(error);
19689
19808
  throw error;
19690
19809
  }
19691
19810
  }
19692
- function createReplayedHostCallResult(outcome, record3, hostCalls) {
19811
+ function createReplayedHostCallResult(outcome, record4, hostCalls) {
19693
19812
  const promise = outcome.status === "fulfilled" ? Promise.resolve(outcome.value) : Promise.reject(outcome.reason);
19694
19813
  promise.catch(() => void 0);
19695
- return createSandboxPromise(promise, { hostCall: record3, hostCallJournal: hostCalls });
19814
+ return createSandboxPromise(promise, { hostCall: record4, hostCallJournal: hostCalls });
19696
19815
  }
19697
- function createHostCallPromise(record3, outcomePromise, hostCalls) {
19816
+ function createHostCallPromise(record4, outcomePromise, hostCalls) {
19698
19817
  const promise = outcomePromise.then((outcome) => {
19699
19818
  if (outcome.status === "rejected" && isAbortReason(outcome.reason)) {
19700
- hostCalls.cancel(record3, outcome.reason);
19819
+ hostCalls.cancel(record4, outcome.reason);
19701
19820
  } else {
19702
- hostCalls.settle(record3, outcome);
19821
+ hostCalls.settle(record4, outcome);
19703
19822
  }
19704
19823
  return outcome.status === "fulfilled" ? outcome.value : Promise.reject(outcome.reason);
19705
19824
  });
19706
19825
  promise.catch(() => void 0);
19707
- return createSandboxPromise(promise, { hostCall: record3, hostCallJournal: hostCalls });
19826
+ return createSandboxPromise(promise, { hostCall: record4, hostCallJournal: hostCalls });
19708
19827
  }
19709
19828
  function isAbortReason(reason) {
19710
19829
  return typeof reason === "object" && reason !== null && ("name" in reason && reason.name === "AbortError" || "code" in reason && reason.code === "aborted");
@@ -20506,7 +20625,7 @@ function conversionHook(value, name, budget, context) {
20506
20625
  let current = value;
20507
20626
  let depth = 0;
20508
20627
  while (current !== null) {
20509
- const properties = isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : current;
20628
+ const properties = isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
20510
20629
  const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, name);
20511
20630
  if (descriptor !== void 0) {
20512
20631
  return readPropertyDescriptor(descriptor, value, context);
@@ -21816,7 +21935,7 @@ async function parseJsonWithReviver(text, reviver, budget, context) {
21816
21935
  leave();
21817
21936
  }
21818
21937
  }
21819
- async function internalize(holder2, key, record3) {
21938
+ async function internalize(holder2, key, record4) {
21820
21939
  budget.visitNode();
21821
21940
  const leave = budget.enterCall();
21822
21941
  let value;
@@ -21828,7 +21947,7 @@ async function parseJsonWithReviver(text, reviver, budget, context) {
21828
21947
  const descriptor = getSandboxPropertyDescriptor(holder2, key, budget);
21829
21948
  value = descriptor === void 0 ? void 0 : await readPropertyDescriptor(descriptor, holder2, context);
21830
21949
  }
21831
- const original = record3 !== void 0 && Object.is(value, record3.value) ? record3 : void 0;
21950
+ const original = record4 !== void 0 && Object.is(value, record4.value) ? record4 : void 0;
21832
21951
  if (original?.source !== void 0) callbackContext.source = budget.allocateString(original.source);
21833
21952
  if (typeof value === "object" && value !== null) {
21834
21953
  if (Array.isArray(value)) budget.allocateArrayLength(value.length);
@@ -22109,7 +22228,7 @@ async function stringifyObject(value, state, indent) {
22109
22228
  const release = retainValues(state.budget, () => entries);
22110
22229
  try {
22111
22230
  const nextIndent = indent + state.gap;
22112
- for (const key of state.propertyList ?? Object.keys(value)) {
22231
+ for (const key of state.propertyList ?? ownEnumerableSandboxKeys(value)) {
22113
22232
  const serialized = await stringifyProperty(key, value, state, nextIndent);
22114
22233
  if (serialized !== void 0) {
22115
22234
  entries.push(`${quoteJsonString(key)}:${state.gap === "" ? "" : " "}${serialized}`);
@@ -22246,9 +22365,9 @@ async function sumPrecise(source, budget, context) {
22246
22365
  if (typeof result !== "object" && typeof result !== "function" || result === null)
22247
22366
  throw new TypeError("Iterator result must be an object.");
22248
22367
  recordValue = result;
22249
- const record3 = result;
22250
- if ((await readIteratorResult(iterator, record3, "done")).value) break;
22251
- current = (await readIteratorResult(iterator, record3, "value")).value;
22368
+ const record4 = result;
22369
+ if ((await readIteratorResult(iterator, record4, "done")).value) break;
22370
+ current = (await readIteratorResult(iterator, record4, "value")).value;
22252
22371
  if (count >= Number.MAX_SAFE_INTEGER || typeof current !== "number") {
22253
22372
  const error = count >= Number.MAX_SAFE_INTEGER ? new RangeError("Math.sumPrecise received too many elements.") : new TypeError("Math.sumPrecise requires number elements.");
22254
22373
  await closeIterator(iterator, true);
@@ -23120,7 +23239,7 @@ function intrinsicCatalogue() {
23120
23239
  releaseObjectPrototype(budget);
23121
23240
  }
23122
23241
  }
23123
- function record2(value) {
23242
+ function record3(value) {
23124
23243
  if (value === null || typeof value !== "object" || Array.isArray(value)) throw new TypeError("Expected a guest heap record.");
23125
23244
  return value;
23126
23245
  }
@@ -23137,23 +23256,23 @@ function integer(value) {
23137
23256
  }
23138
23257
  function absent(value) {
23139
23258
  if (value === null || typeof value !== "object") return false;
23140
- const node = record2(value);
23259
+ const node = record3(value);
23141
23260
  return node.kind === "undefined" && Object.keys(node).length === 1;
23142
23261
  }
23143
23262
  function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23144
- const node = record2(raw);
23263
+ const node = record3(raw);
23145
23264
  if (node.kind === "raw-json") {
23146
23265
  fields(node, ["kind", "text"]);
23147
23266
  if (typeof node.text !== "string") throw new TypeError("Invalid raw JSON source.");
23148
23267
  createRawJson(node.text);
23149
23268
  return true;
23150
23269
  }
23151
- if (!["intrinsic", "guest-function", "guest-generator", "scope-frame", "guest-object", "guest-array"].includes(String(node.kind))) return false;
23270
+ if (!["intrinsic", "guest-function", "guest-generator", "scope-frame", "guest-object", "guest-array", "map", "set"].includes(String(node.kind))) return false;
23152
23271
  const reference = (value, kinds) => {
23153
- const ref = record2(value);
23272
+ const ref = record3(value);
23154
23273
  fields(ref, ["kind", "id"]);
23155
23274
  if (ref.kind !== "ref" || integer(ref.id) < 1 || !Object.hasOwn(heap, String(ref.id))) throw new TypeError("Invalid guest heap reference.");
23156
- const target = record2(heap[String(ref.id)]);
23275
+ const target = record3(heap[String(ref.id)]);
23157
23276
  if (kinds !== void 0 && !kinds.includes(String(target.kind))) throw new TypeError("Wrong guest heap reference kind.");
23158
23277
  return target;
23159
23278
  };
@@ -23164,10 +23283,10 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23164
23283
  throw new TypeError("Guest accessor reference is not callable.");
23165
23284
  };
23166
23285
  const state = (value) => {
23167
- const object = record2(value);
23286
+ const object = record3(value);
23168
23287
  fields(object, ["properties"], ["prototype"]);
23169
23288
  if (Object.hasOwn(object, "prototype") && object.prototype !== null) reference(object.prototype);
23170
- const properties = record2(object.properties);
23289
+ const properties = record3(object.properties);
23171
23290
  fields(properties, ["properties", "extensible"]);
23172
23291
  if (typeof properties.extensible !== "boolean") throw new TypeError("Invalid guest extensibility.");
23173
23292
  const keys = /* @__PURE__ */ new Set();
@@ -23178,11 +23297,11 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23178
23297
  if (typeof entry[0] === "string") key = `string:${entry[0]}`;
23179
23298
  else {
23180
23299
  const symbol = reference(entry[0], ["symbol"]);
23181
- key = symbol.wellKnown === void 0 ? `symbol:${record2(entry[0]).id}` : `well-known:${symbol.wellKnown}`;
23300
+ key = symbol.wellKnown === void 0 ? `symbol:${record3(entry[0]).id}` : `well-known:${symbol.wellKnown}`;
23182
23301
  }
23183
23302
  if (keys.has(key)) throw new TypeError("Duplicate guest property key.");
23184
23303
  keys.add(key);
23185
- const descriptor = record2(entry[1]);
23304
+ const descriptor = record3(entry[1]);
23186
23305
  if (descriptor.kind === "data") {
23187
23306
  fields(descriptor, ["kind", "value", "writable", "enumerable", "configurable"]);
23188
23307
  if (typeof descriptor.writable !== "boolean") throw new TypeError("Invalid guest writable flag.");
@@ -23194,6 +23313,11 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23194
23313
  if (typeof descriptor.enumerable !== "boolean" || typeof descriptor.configurable !== "boolean") throw new TypeError("Invalid guest descriptor flags.");
23195
23314
  }
23196
23315
  };
23316
+ if (node.kind === "map" || node.kind === "set") {
23317
+ fields(node, ["kind", node.kind === "map" ? "entries" : "values"], ["propertyState"]);
23318
+ if (Object.hasOwn(node, "propertyState")) state({ properties: node.propertyState });
23319
+ return false;
23320
+ }
23197
23321
  if (node.kind === "intrinsic") {
23198
23322
  fields(node, ["kind", "id"], ["state"]);
23199
23323
  if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
@@ -23205,10 +23329,10 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23205
23329
  throw new TypeError("Invalid template source identity.");
23206
23330
  state(node.state);
23207
23331
  if (node.kind === "guest-array") {
23208
- const properties = array(record2(record2(node.state).properties).properties).map((entry) => array(entry));
23332
+ const properties = array(record3(record3(node.state).properties).properties).map((entry) => array(entry));
23209
23333
  const length = properties.find((entry) => entry[0] === "length");
23210
23334
  if (length === void 0) throw new TypeError("Missing guest array length.");
23211
- const descriptor = record2(length[1]);
23335
+ const descriptor = record3(length[1]);
23212
23336
  if (descriptor.kind !== "data" || descriptor.configurable !== false || descriptor.enumerable !== false || integer(descriptor.value) > 4294967295) throw new TypeError("Invalid guest array length.");
23213
23337
  if (descriptor.value > maxArrayLength) throw new TypeError("Guest array length exceeds allocation limit.");
23214
23338
  for (const [key] of properties) {
@@ -23223,7 +23347,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23223
23347
  reference(node.scope, ["scope-frame"]);
23224
23348
  if (Object.hasOwn(node, "name") && typeof node.name !== "string") throw new TypeError("Invalid guest function name.");
23225
23349
  if (Object.hasOwn(node, "environment")) {
23226
- const environment = record2(node.environment);
23350
+ const environment = record3(node.environment);
23227
23351
  fields(environment, [], ["homeObject", "newTarget"]);
23228
23352
  if (Object.hasOwn(environment, "homeObject")) reference(environment.homeObject);
23229
23353
  if (Object.hasOwn(environment, "newTarget")) callable(environment.newTarget);
@@ -23237,15 +23361,15 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23237
23361
  reference(node.closureScope, ["scope-frame"]);
23238
23362
  if (Object.hasOwn(node, "suspendedScope")) reference(node.suspendedScope, ["scope-frame"]);
23239
23363
  if (Object.hasOwn(node, "blockScopes")) {
23240
- for (const [id, scope] of Object.entries(record2(node.blockScopes))) {
23364
+ for (const [id, scope] of Object.entries(record3(node.blockScopes))) {
23241
23365
  if (integer(Number(id)) < 1 || String(Number(id)) !== id) throw new TypeError("Invalid generator block identity.");
23242
23366
  reference(scope, ["scope-frame"]);
23243
23367
  }
23244
23368
  }
23245
23369
  if (Object.hasOwn(node, "expressionStates")) {
23246
- for (const [id, raw2] of Object.entries(record2(node.expressionStates))) {
23370
+ for (const [id, raw2] of Object.entries(record3(node.expressionStates))) {
23247
23371
  if (integer(Number(id)) < 1 || String(Number(id)) !== id) throw new TypeError("Invalid expression identity.");
23248
- const expression = record2(raw2);
23372
+ const expression = record3(raw2);
23249
23373
  if (expression.kind === "binary") {
23250
23374
  fields(expression, ["kind", "left"]);
23251
23375
  } else if (expression.kind === "declaration") {
@@ -23284,13 +23408,13 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23284
23408
  if (expression.kind !== "yield-delegate") integer(expression.index);
23285
23409
  if (expression.kind === "for-of-array") reference(expression.values, ["array", "guest-array"]);
23286
23410
  else {
23287
- let iterator = record2(expression.iterator);
23411
+ let iterator = record3(expression.iterator);
23288
23412
  let depth = 0;
23289
23413
  let protocol = false;
23290
23414
  while (iterator.kind === "async-from-sync") {
23291
23415
  if (++depth > 1) throw new TypeError("Invalid nested async iterator adapter.");
23292
23416
  fields(iterator, ["kind", "inner"]);
23293
- iterator = record2(iterator.inner);
23417
+ iterator = record3(iterator.inner);
23294
23418
  protocol = true;
23295
23419
  }
23296
23420
  if (iterator.kind === "guest") {
@@ -23369,9 +23493,9 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23369
23493
  }
23370
23494
  }
23371
23495
  if (Object.hasOwn(node, "finallyCompletions")) {
23372
- for (const [id, raw2] of Object.entries(record2(node.finallyCompletions))) {
23496
+ for (const [id, raw2] of Object.entries(record3(node.finallyCompletions))) {
23373
23497
  if (integer(Number(id)) < 1 || String(Number(id)) !== id) throw new TypeError("Invalid finally identity.");
23374
- const completion = record2(raw2);
23498
+ const completion = record3(raw2);
23375
23499
  fields(completion, ["kind", "hasValue", "value"], ["nodeId", "label", "span", "stackFrames"]);
23376
23500
  if (!["normal", "return", "throw", "break", "continue"].includes(String(completion.kind)) || typeof completion.hasValue !== "boolean")
23377
23501
  throw new TypeError("Invalid finally completion.");
@@ -23383,12 +23507,12 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23383
23507
  if (Object.hasOwn(node, "yieldNodeId") && integer(node.yieldNodeId) < 1) throw new TypeError("Invalid generator yield identity.");
23384
23508
  if (node.state === "suspended" && (!Object.hasOwn(node, "yieldNodeId") || !Object.hasOwn(node, "suspendedScope"))) throw new TypeError("Missing suspended generator state.");
23385
23509
  for (const rawCompletion of array(node.sent)) {
23386
- const completion = record2(rawCompletion);
23510
+ const completion = record3(rawCompletion);
23387
23511
  fields(completion, ["type", "value"]);
23388
23512
  if (!["normal", "return", "throw"].includes(String(completion.type))) throw new TypeError("Invalid generator completion type.");
23389
23513
  }
23390
23514
  if (Object.hasOwn(node, "environment")) {
23391
- const environment = record2(node.environment);
23515
+ const environment = record3(node.environment);
23392
23516
  fields(environment, [], ["homeObject", "newTarget"]);
23393
23517
  if (Object.hasOwn(environment, "homeObject")) reference(environment.homeObject);
23394
23518
  if (Object.hasOwn(environment, "newTarget")) callable(environment.newTarget);
@@ -23399,7 +23523,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23399
23523
  if (typeof node.functionBoundary !== "boolean" || typeof node.chargeData !== "boolean") throw new TypeError("Invalid guest frame flags.");
23400
23524
  const cells = array(node.cells);
23401
23525
  for (const rawCell of cells) {
23402
- const cell = record2(rawCell);
23526
+ const cell = record3(rawCell);
23403
23527
  if (typeof cell.initialized !== "boolean" || !["var", "let", "const"].includes(String(cell.kind))) throw new TypeError("Invalid guest binding cell.");
23404
23528
  fields(cell, cell.initialized ? ["kind", "initialized", "value"] : ["kind", "initialized"]);
23405
23529
  }
@@ -23429,26 +23553,26 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
23429
23553
  function validateGuestScopeParents(heap) {
23430
23554
  const finished = /* @__PURE__ */ new Set();
23431
23555
  for (const [id, raw] of Object.entries(heap)) {
23432
- if (record2(raw).kind !== "scope-frame" || finished.has(id)) continue;
23556
+ if (record3(raw).kind !== "scope-frame" || finished.has(id)) continue;
23433
23557
  const path = /* @__PURE__ */ new Set();
23434
23558
  let current = id;
23435
23559
  while (current !== void 0 && !finished.has(current)) {
23436
23560
  if (path.has(current)) throw new TypeError("Cyclic guest scope parent graph.");
23437
23561
  path.add(current);
23438
- const parent = record2(heap[current]).parent;
23439
- current = absent(parent) ? void 0 : String(record2(parent).id);
23562
+ const parent = record3(heap[current]).parent;
23563
+ current = absent(parent) ? void 0 : String(record3(parent).id);
23440
23564
  }
23441
23565
  for (const visited of path) finished.add(visited);
23442
23566
  }
23443
23567
  }
23444
23568
 
23445
23569
  // packages/safe-js/src/snapshot/guest-ast-validation.ts
23446
- function validateGuestFunctionAst(record3, origin) {
23570
+ function validateGuestFunctionAst(record4, origin) {
23447
23571
  if (origin === null || typeof origin !== "object" || !["ArrowFunctionExpression", "FunctionExpression", "FunctionDeclaration"].includes(String(origin.type)))
23448
23572
  throw new TypeError("Unknown guest function AST identity");
23449
- if (record3.kind !== "guest-generator") return;
23573
+ if (record4.kind !== "guest-generator") return;
23450
23574
  const functionNode = origin;
23451
- if (functionNode.generator !== true || functionNode.async === true !== record3.async)
23575
+ if (functionNode.generator !== true || functionNode.async === true !== record4.async)
23452
23576
  throw new TypeError("Invalid generator AST identity");
23453
23577
  let yieldBlocks;
23454
23578
  let yieldFinalizers;
@@ -23463,10 +23587,10 @@ function validateGuestFunctionAst(record3, origin) {
23463
23587
  if (["ArrowFunctionExpression", "FunctionExpression", "FunctionDeclaration"].includes(String(node.type))) continue;
23464
23588
  let blocks = frame.blocks;
23465
23589
  if (node.type === "BlockStatement" && typeof node.nodeId === "number") blocks = /* @__PURE__ */ new Set([...blocks, node.nodeId]);
23466
- if (node.type === "YieldExpression" && node.nodeId === record3.yieldNodeId) {
23590
+ if (node.type === "YieldExpression" && node.nodeId === record4.yieldNodeId) {
23467
23591
  yieldBlocks = blocks;
23468
23592
  yieldFinalizers = frame.finalizers;
23469
- yieldExpressions = node.delegate === true && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "yield-delegate", async: record3.async === true }]]) : frame.expressions;
23593
+ yieldExpressions = node.delegate === true && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "yield-delegate", async: record4.async === true }]]) : frame.expressions;
23470
23594
  }
23471
23595
  for (const [key, value] of Object.entries(node)) {
23472
23596
  if (node.type === "SwitchStatement" && key === "cases" && typeof node.nodeId === "number" && Array.isArray(value)) {
@@ -23568,23 +23692,23 @@ function validateGuestFunctionAst(record3, origin) {
23568
23692
  });
23569
23693
  }
23570
23694
  }
23571
- if (record3.yieldNodeId !== void 0 && yieldBlocks === void 0)
23695
+ if (record4.yieldNodeId !== void 0 && yieldBlocks === void 0)
23572
23696
  throw new TypeError("Invalid generator AST identity");
23573
- if (record3.state === "suspended" && Object.keys(record3.blockScopes ?? {}).length !== yieldBlocks?.size)
23574
- throw new TypeError(`Invalid generator AST identity: expected blocks ${[...yieldBlocks ?? []]}, received ${Object.keys(record3.blockScopes ?? {})}.`);
23575
- if (record3.blockScopes !== void 0) {
23576
- for (const id of Object.keys(record3.blockScopes)) {
23697
+ if (record4.state === "suspended" && Object.keys(record4.blockScopes ?? {}).length !== yieldBlocks?.size)
23698
+ throw new TypeError(`Invalid generator AST identity: expected blocks ${[...yieldBlocks ?? []]}, received ${Object.keys(record4.blockScopes ?? {})}.`);
23699
+ if (record4.blockScopes !== void 0) {
23700
+ for (const id of Object.keys(record4.blockScopes)) {
23577
23701
  if (!yieldBlocks?.has(Number(id))) throw new TypeError("Invalid generator AST identity");
23578
23702
  }
23579
23703
  }
23580
- const completions = Object.keys(record3.finallyCompletions ?? {});
23581
- if (record3.state === "suspended" && completions.length !== yieldFinalizers?.size)
23704
+ const completions = Object.keys(record4.finallyCompletions ?? {});
23705
+ if (record4.state === "suspended" && completions.length !== yieldFinalizers?.size)
23582
23706
  throw new TypeError("Invalid generator AST identity: missing finally completion");
23583
23707
  for (const id of completions) {
23584
23708
  if (!yieldFinalizers?.has(Number(id))) throw new TypeError("Invalid generator AST identity: unrelated finally completion");
23585
23709
  }
23586
- const expressions = Object.entries(record3.expressionStates ?? {});
23587
- if (record3.state === "suspended" && expressions.length !== yieldExpressions?.size)
23710
+ const expressions = Object.entries(record4.expressionStates ?? {});
23711
+ if (record4.state === "suspended" && expressions.length !== yieldExpressions?.size)
23588
23712
  throw new TypeError("Invalid generator AST identity: missing expression continuation");
23589
23713
  for (const [id, expression] of expressions) {
23590
23714
  const expected = yieldExpressions?.get(Number(id));
@@ -23793,16 +23917,16 @@ function validateDumpReferences(value, path, depth, state, heapIds, heap, role =
23793
23917
  );
23794
23918
  return;
23795
23919
  }
23796
- const record3 = value;
23797
- if (record3.kind === "ref") {
23798
- const id = requireSafeInteger(record3.id, `${path}.id`, 1);
23920
+ const record4 = value;
23921
+ if (record4.kind === "ref") {
23922
+ const id = requireSafeInteger(record4.id, `${path}.id`, 1);
23799
23923
  if (!heapIds.has(id)) fail("danglingReference", `${path}.id`, `unknown heap value ${id}`);
23800
23924
  if (heap[String(id)].kind === "scope-frame" && !allowScopeReference)
23801
23925
  fail("invalidValue", path, "Internal scopes cannot be guest data");
23802
23926
  }
23803
- for (const [key, entry] of Object.entries(record3)) {
23804
- const childRole = role === "root" && key === "heap" ? "heap" : role === "heap" ? "heap-node" : role === "heap-node" && record3.kind === "guest-generator" && key === "blockScopes" ? "scope-map" : role === "heap-node" && record3.kind === "guest-generator" && key === "expressionStates" ? "expressions" : role === "expressions" ? "expression" : "data";
23805
- const scopeField = role === "scope-map" || role === "expression" && (record3.kind === "for" && ["loopScope", "activeScope"].includes(key) || ["switch", "for-in", "for-of-array", "for-of-iterator"].includes(String(record3.kind)) && key === "scope") || role === "heap-node" && (record3.kind === "scope-frame" && key === "parent" || record3.kind === "guest-function" && key === "scope" || record3.kind === "guest-generator" && ["scope", "closureScope", "suspendedScope"].includes(key));
23927
+ for (const [key, entry] of Object.entries(record4)) {
23928
+ const childRole = role === "root" && key === "heap" ? "heap" : role === "heap" ? "heap-node" : role === "heap-node" && record4.kind === "guest-generator" && key === "blockScopes" ? "scope-map" : role === "heap-node" && record4.kind === "guest-generator" && key === "expressionStates" ? "expressions" : role === "expressions" ? "expression" : "data";
23929
+ const scopeField = role === "scope-map" || role === "expression" && (record4.kind === "for" && ["loopScope", "activeScope"].includes(key) || ["switch", "for-in", "for-of-array", "for-of-iterator"].includes(String(record4.kind)) && key === "scope") || role === "heap-node" && (record4.kind === "scope-frame" && key === "parent" || record4.kind === "guest-function" && key === "scope" || record4.kind === "guest-generator" && ["scope", "closureScope", "suspendedScope"].includes(key));
23806
23930
  validateDumpReferences(entry, `${path}${formatKey(key)}`, depth + 1, state, heapIds, heap, childRole, scopeField);
23807
23931
  }
23808
23932
  }
@@ -23857,12 +23981,12 @@ function validatePosition(value, path) {
23857
23981
  function validateValue(value, path, depth, state) {
23858
23982
  validateGenericValue(value, path, depth, state);
23859
23983
  }
23860
- function validateTaggedValue(record3, path, state) {
23861
- switch (record3.kind) {
23984
+ function validateTaggedValue(record4, path, state) {
23985
+ switch (record4.kind) {
23862
23986
  case "bigint":
23863
- requireString(record3.value, `${path}.value`, state.limits);
23987
+ requireString(record4.value, `${path}.value`, state.limits);
23864
23988
  try {
23865
- validateBigIntData(record3.value);
23989
+ validateBigIntData(record4.value);
23866
23990
  } catch {
23867
23991
  fail("invalidValue", `${path}.value`, "invalid BigInt value");
23868
23992
  }
@@ -23870,34 +23994,34 @@ function validateTaggedValue(record3, path, state) {
23870
23994
  case "undefined":
23871
23995
  return;
23872
23996
  case "number":
23873
- if (!["-Infinity", "Infinity", "NaN", "-0"].includes(String(record3.value))) {
23997
+ if (!["-Infinity", "Infinity", "NaN", "-0"].includes(String(record4.value))) {
23874
23998
  fail("invalidValue", `${path}.value`, "unknown non-finite number value");
23875
23999
  }
23876
24000
  return;
23877
24001
  case "fn":
23878
- requireSafeInteger(record3.astNodeId, `${path}.astNodeId`, 0);
23879
- requireSnapshotId(record3.capturedScopeId, `${path}.capturedScopeId`);
24002
+ requireSafeInteger(record4.astNodeId, `${path}.astNodeId`, 0);
24003
+ requireSnapshotId(record4.capturedScopeId, `${path}.capturedScopeId`);
23880
24004
  return;
23881
24005
  case "generator":
23882
- validateGeneratorShape(record3, path, state);
24006
+ validateGeneratorShape(record4, path, state);
23883
24007
  return;
23884
24008
  case "promise":
23885
- requireSnapshotId(record3.id, `${path}.id`);
24009
+ requireSnapshotId(record4.id, `${path}.id`);
23886
24010
  return;
23887
24011
  case "ref":
23888
- requireSafeInteger(record3.id, `${path}.id`, 1);
24012
+ requireSafeInteger(record4.id, `${path}.id`, 1);
23889
24013
  return;
23890
24014
  case "regex":
23891
- requireString(record3.source, `${path}.source`, state.limits);
23892
- requireString(record3.flags, `${path}.flags`, state.limits);
23893
- requireSafeInteger(record3.lastIndex, `${path}.lastIndex`, 0);
24015
+ requireString(record4.source, `${path}.source`, state.limits);
24016
+ requireString(record4.flags, `${path}.flags`, state.limits);
24017
+ requireSafeInteger(record4.lastIndex, `${path}.lastIndex`, 0);
23894
24018
  return;
23895
24019
  case "regex-object":
23896
- requireString(record3.source, `${path}.source`, state.limits);
23897
- requireString(record3.flags, `${path}.flags`, state.limits);
23898
- if (!Object.hasOwn(record3, "lastIndex")) fail("invalidValue", `${path}.lastIndex`, "missing regex cursor");
24020
+ requireString(record4.source, `${path}.source`, state.limits);
24021
+ requireString(record4.flags, `${path}.flags`, state.limits);
24022
+ if (!Object.hasOwn(record4, "lastIndex")) fail("invalidValue", `${path}.lastIndex`, "missing regex cursor");
23899
24023
  try {
23900
- validateRegexProperties(record3);
24024
+ validateRegexProperties(record4);
23901
24025
  } catch {
23902
24026
  fail("invalidValue", path, "invalid RegExp property data");
23903
24027
  }
@@ -23906,7 +24030,7 @@ function validateTaggedValue(record3, path, state) {
23906
24030
  case "arguments":
23907
24031
  return;
23908
24032
  case "object":
23909
- if (Object.hasOwn(record3, "sandboxNullPrototype") && record3.sandboxNullPrototype !== true)
24033
+ if (Object.hasOwn(record4, "sandboxNullPrototype") && record4.sandboxNullPrototype !== true)
23910
24034
  fail("invalidValue", `${path}.sandboxNullPrototype`, "invalid object prototype");
23911
24035
  return;
23912
24036
  case "map":
@@ -23916,29 +24040,29 @@ function validateTaggedValue(record3, path, state) {
23916
24040
  return;
23917
24041
  }
23918
24042
  }
23919
- function validateGeneratorShape(record3, path, state) {
23920
- if (record3.async !== void 0 && typeof record3.async !== "boolean") {
24043
+ function validateGeneratorShape(record4, path, state) {
24044
+ if (record4.async !== void 0 && typeof record4.async !== "boolean") {
23921
24045
  fail("invalidType", `${path}.async`, "generator async flag must be a boolean");
23922
24046
  }
23923
- if (!["start", "suspended", "done"].includes(String(record3.state))) {
24047
+ if (!["start", "suspended", "done"].includes(String(record4.state))) {
23924
24048
  fail("invalidState", `${path}.state`, "unknown generator state");
23925
24049
  }
23926
- if (record3.state === "done") {
23927
- if (record3.astNodeId !== void 0 || record3.capturedScopeId !== void 0 || record3.sent !== void 0 || record3.yieldNodeId !== void 0) {
24050
+ if (record4.state === "done") {
24051
+ if (record4.astNodeId !== void 0 || record4.capturedScopeId !== void 0 || record4.sent !== void 0 || record4.yieldNodeId !== void 0) {
23928
24052
  fail("invalidState", path, "done generator cannot contain resume state");
23929
24053
  }
23930
24054
  return;
23931
24055
  }
23932
- requireSafeInteger(record3.astNodeId, `${path}.astNodeId`, 0);
23933
- requireSnapshotId(record3.capturedScopeId, `${path}.capturedScopeId`);
23934
- if (record3.state === "start") {
23935
- if (record3.sent !== void 0 || record3.yieldNodeId !== void 0) {
24056
+ requireSafeInteger(record4.astNodeId, `${path}.astNodeId`, 0);
24057
+ requireSnapshotId(record4.capturedScopeId, `${path}.capturedScopeId`);
24058
+ if (record4.state === "start") {
24059
+ if (record4.sent !== void 0 || record4.yieldNodeId !== void 0) {
23936
24060
  fail("invalidState", path, "unstarted generator cannot contain a resume cursor");
23937
24061
  }
23938
24062
  return;
23939
24063
  }
23940
- requireSafeInteger(record3.yieldNodeId, `${path}.yieldNodeId`, 0);
23941
- const sent = requireArray(record3.sent, `${path}.sent`, state);
24064
+ requireSafeInteger(record4.yieldNodeId, `${path}.yieldNodeId`, 0);
24065
+ const sent = requireArray(record4.sent, `${path}.sent`, state);
23942
24066
  sent.forEach((completion, index) => {
23943
24067
  const completionPath = `${path}.sent[${index}]`;
23944
24068
  const candidate = requireRecord(completion, completionPath);
@@ -23954,13 +24078,13 @@ function validateGeneratorShape(record3, path, state) {
23954
24078
  });
23955
24079
  }
23956
24080
  function validateHeapValue(value, path, state, heap) {
23957
- const record3 = requireRecord(value, path);
24081
+ const record4 = requireRecord(value, path);
23958
24082
  try {
23959
- if (validateGuestHeapNode(record3, heap, state.limits.maxEntries)) {
24083
+ if (validateGuestHeapNode(record4, heap, state.limits.maxEntries)) {
23960
24084
  const tagged = state.validateTaggedPayloads;
23961
24085
  state.validateTaggedPayloads = false;
23962
24086
  try {
23963
- validateValue(record3, path, 1, state);
24087
+ validateValue(record4, path, 1, state);
23964
24088
  } finally {
23965
24089
  state.validateTaggedPayloads = tagged;
23966
24090
  }
@@ -23969,49 +24093,49 @@ function validateHeapValue(value, path, state, heap) {
23969
24093
  } catch (error) {
23970
24094
  fail("invalidValue", path, String(error));
23971
24095
  }
23972
- validateErrorType(record3, path);
23973
- if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record3.kind)))
24096
+ validateErrorType(record4, path);
24097
+ if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record4.kind)))
23974
24098
  fail("unknownTag", `${path}.kind`, "unknown heap tag");
23975
- validateValue(record3, path, 1, state);
23976
- if (record3.kind === "symbol") validateSymbolRecord(record3, path, state);
23977
- if (record3.kind === "arguments") validateArgumentsProperties(record3, path);
23978
- if (record3.kind === "array") validateArrayHeap(record3, path, state);
23979
- if (record3.kind === "object") requireRecord(record3.entries, `${path}.entries`);
23980
- if (record3.kind === "boxed") validateBoxedRecord(record3, path, heap);
23981
- if (record3.kind === "date") validateDateRecord(record3, path);
23982
- if (record3.kind === "float32array") {
23983
- validateFloat32Storage(record3);
23984
- requireRecord(record3.entries, `${path}.entries`);
23985
- }
23986
- if (record3.kind === "map") {
23987
- const entries = requireArray(record3.entries, `${path}.entries`, state);
24099
+ validateValue(record4, path, 1, state);
24100
+ if (record4.kind === "symbol") validateSymbolRecord(record4, path, state);
24101
+ if (record4.kind === "arguments") validateArgumentsProperties(record4, path);
24102
+ if (record4.kind === "array") validateArrayHeap(record4, path, state);
24103
+ if (record4.kind === "object") requireRecord(record4.entries, `${path}.entries`);
24104
+ if (record4.kind === "boxed") validateBoxedRecord(record4, path, heap);
24105
+ if (record4.kind === "date") validateDateRecord(record4, path);
24106
+ if (record4.kind === "float32array") {
24107
+ validateFloat32Storage(record4);
24108
+ requireRecord(record4.entries, `${path}.entries`);
24109
+ }
24110
+ if (record4.kind === "map") {
24111
+ const entries = requireArray(record4.entries, `${path}.entries`, state);
23988
24112
  entries.forEach((entry, index) => {
23989
24113
  if (!Array.isArray(entry) || entry.length !== 2)
23990
24114
  fail("invalidValue", `${path}.entries[${index}]`, "map entry must contain two values");
23991
24115
  });
23992
24116
  }
23993
- if (record3.kind === "set") requireArray(record3.values, `${path}.values`, state);
23994
- if (record3.kind === "regexp-iterator") {
23995
- if ((record3.global !== void 0 || record3.unicode !== void 0) && (typeof record3.global !== "boolean" || typeof record3.unicode !== "boolean"))
24117
+ if (record4.kind === "set") requireArray(record4.values, `${path}.values`, state);
24118
+ if (record4.kind === "regexp-iterator") {
24119
+ if ((record4.global !== void 0 || record4.unicode !== void 0) && (typeof record4.global !== "boolean" || typeof record4.unicode !== "boolean"))
23996
24120
  fail("invalidValue", path, "invalid RegExp iterator modes");
23997
- if (typeof record3.exhausted !== "boolean") fail("invalidValue", `${path}.exhausted`, "invalid iterator exhaustion");
23998
- if (!Object.hasOwn(record3, "matcher") || !Object.hasOwn(record3, "input")) fail("invalidValue", path, "missing RegExp iterator state");
23999
- requireRecord(record3.entries, `${path}.entries`);
24000
- }
24001
- if (record3.kind === "collection-iterator") {
24002
- if (record3.collectionKind !== "map" && record3.collectionKind !== "set") fail("invalidValue", `${path}.collectionKind`, "invalid iterator brand");
24003
- if (record3.method !== "keys" && record3.method !== "values" && record3.method !== "entries") fail("invalidValue", `${path}.method`, "invalid iteration method");
24004
- if (typeof record3.exhausted !== "boolean") fail("invalidValue", `${path}.exhausted`, "invalid iterator exhaustion");
24005
- requireSafeInteger(record3.index, `${path}.index`, 0);
24006
- if (!Object.hasOwn(record3, "collection")) fail("invalidValue", `${path}.collection`, "missing iterator source");
24007
- requireRecord(record3.entries, `${path}.entries`);
24008
- }
24009
- }
24010
- function validateSymbolEntries(record3, path, state, heap) {
24011
- if (record3.symbolEntries === void 0) return;
24012
- if (record3.kind !== "object" && record3.kind !== "array" && record3.kind !== "date" && record3.kind !== "boxed" && record3.kind !== "regex-object" && record3.kind !== "regexp-iterator")
24121
+ if (typeof record4.exhausted !== "boolean") fail("invalidValue", `${path}.exhausted`, "invalid iterator exhaustion");
24122
+ if (!Object.hasOwn(record4, "matcher") || !Object.hasOwn(record4, "input")) fail("invalidValue", path, "missing RegExp iterator state");
24123
+ requireRecord(record4.entries, `${path}.entries`);
24124
+ }
24125
+ if (record4.kind === "collection-iterator") {
24126
+ if (record4.collectionKind !== "map" && record4.collectionKind !== "set") fail("invalidValue", `${path}.collectionKind`, "invalid iterator brand");
24127
+ if (record4.method !== "keys" && record4.method !== "values" && record4.method !== "entries") fail("invalidValue", `${path}.method`, "invalid iteration method");
24128
+ if (typeof record4.exhausted !== "boolean") fail("invalidValue", `${path}.exhausted`, "invalid iterator exhaustion");
24129
+ requireSafeInteger(record4.index, `${path}.index`, 0);
24130
+ if (!Object.hasOwn(record4, "collection")) fail("invalidValue", `${path}.collection`, "missing iterator source");
24131
+ requireRecord(record4.entries, `${path}.entries`);
24132
+ }
24133
+ }
24134
+ function validateSymbolEntries(record4, path, state, heap) {
24135
+ if (record4.symbolEntries === void 0) return;
24136
+ if (record4.kind !== "object" && record4.kind !== "array" && record4.kind !== "date" && record4.kind !== "boxed" && record4.kind !== "regex-object" && record4.kind !== "regexp-iterator")
24013
24137
  fail("invalidValue", `${path}.symbolEntries`, "symbol properties are unsupported for this heap kind");
24014
- const entries = requireArray(record3.symbolEntries, `${path}.symbolEntries`, state);
24138
+ const entries = requireArray(record4.symbolEntries, `${path}.symbolEntries`, state);
24015
24139
  const keys = /* @__PURE__ */ new Set();
24016
24140
  entries.forEach((entry, index) => {
24017
24141
  const entryPath = `${path}.symbolEntries[${index}]`;
@@ -24027,24 +24151,24 @@ function validateSymbolEntries(record3, path, state, heap) {
24027
24151
  validateDataDescriptor(requireRecord(entry[1], `${entryPath}[1]`), `${entryPath}[1]`);
24028
24152
  });
24029
24153
  }
24030
- function validateSymbolRecord(record3, path, state) {
24031
- if (record3.description !== void 0)
24032
- requireString(record3.description, `${path}.description`, state.limits);
24033
- if (record3.wellKnown !== void 0) {
24034
- requireString(record3.wellKnown, `${path}.wellKnown`, state.limits);
24035
- if (!Object.hasOwn(wellKnownSymbols, String(record3.wellKnown)))
24154
+ function validateSymbolRecord(record4, path, state) {
24155
+ if (record4.description !== void 0)
24156
+ requireString(record4.description, `${path}.description`, state.limits);
24157
+ if (record4.wellKnown !== void 0) {
24158
+ requireString(record4.wellKnown, `${path}.wellKnown`, state.limits);
24159
+ if (!Object.hasOwn(wellKnownSymbols, String(record4.wellKnown)))
24036
24160
  fail("invalidValue", `${path}.wellKnown`, "unknown well-known symbol");
24037
- if (Object.hasOwn(record3, "description"))
24161
+ if (Object.hasOwn(record4, "description"))
24038
24162
  fail("invalidValue", path, "well-known symbol cannot specify a description");
24039
24163
  }
24040
24164
  }
24041
- function validateBoxedRecord(record3, path, heap) {
24165
+ function validateBoxedRecord(record4, path, heap) {
24042
24166
  try {
24043
- validateBoxedProperties(record3);
24167
+ validateBoxedProperties(record4);
24044
24168
  } catch {
24045
24169
  fail("invalidValue", path, "invalid boxed primitive properties");
24046
24170
  }
24047
- const value = record3.value;
24171
+ const value = record4.value;
24048
24172
  if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") return;
24049
24173
  const number = requireRecord(value, `${path}.value`);
24050
24174
  if (number.kind === "bigint") {
@@ -24064,16 +24188,16 @@ function validateBoxedRecord(record3, path, heap) {
24064
24188
  if (number.kind !== "number" || !["NaN", "Infinity", "-Infinity", "-0"].includes(String(number.value)))
24065
24189
  fail("invalidValue", `${path}.value`, "invalid boxed primitive payload");
24066
24190
  }
24067
- function validateDateRecord(record3, path) {
24068
- if (Object.keys(record3).some((key) => !["kind", "time", "properties", "symbolEntries", "extensible"].includes(key))) fail("invalidValue", path, "invalid Date fields");
24191
+ function validateDateRecord(record4, path) {
24192
+ if (Object.keys(record4).some((key) => !["kind", "time", "properties", "symbolEntries", "extensible"].includes(key))) fail("invalidValue", path, "invalid Date fields");
24069
24193
  try {
24070
- restoreDateTime(record3.time);
24194
+ restoreDateTime(record4.time);
24071
24195
  } catch {
24072
24196
  fail("invalidValue", `${path}.time`, "invalid Date epoch");
24073
24197
  }
24074
- if (record3.extensible !== void 0 && typeof record3.extensible !== "boolean") fail("invalidType", `${path}.extensible`, "invalid Date extensibility");
24075
- if (record3.properties !== void 0) {
24076
- for (const [key, value] of Object.entries(requireRecord(record3.properties, `${path}.properties`))) {
24198
+ if (record4.extensible !== void 0 && typeof record4.extensible !== "boolean") fail("invalidType", `${path}.extensible`, "invalid Date extensibility");
24199
+ if (record4.properties !== void 0) {
24200
+ for (const [key, value] of Object.entries(requireRecord(record4.properties, `${path}.properties`))) {
24077
24201
  const propertyPath = `${path}.properties${formatKey(key)}`;
24078
24202
  validateDataDescriptor(requireRecord(value, propertyPath), propertyPath);
24079
24203
  }
@@ -24087,14 +24211,14 @@ function validateDataDescriptor(descriptor, path) {
24087
24211
  if (Object.keys(descriptor).some((key) => !["value", "enumerable", "writable", "configurable"].includes(key)))
24088
24212
  fail("invalidValue", path, "unsupported property descriptor field");
24089
24213
  }
24090
- function validateArrayHeap(record3, path, state) {
24091
- if (Object.hasOwn(record3, "items")) {
24092
- requireArray(record3.items, `${path}.items`, state);
24093
- if (Object.hasOwn(record3, "length") || Object.hasOwn(record3, "entries"))
24214
+ function validateArrayHeap(record4, path, state) {
24215
+ if (Object.hasOwn(record4, "items")) {
24216
+ requireArray(record4.items, `${path}.items`, state);
24217
+ if (Object.hasOwn(record4, "length") || Object.hasOwn(record4, "entries"))
24094
24218
  fail("invalidValue", path, "array must use either items or length and entries");
24095
24219
  return;
24096
24220
  }
24097
- const length = requireSafeInteger(record3.length, `${path}.length`, 0);
24221
+ const length = requireSafeInteger(record4.length, `${path}.length`, 0);
24098
24222
  if (length > 4294967295) fail("invalidValue", `${path}.length`, "exceeds maximum array length");
24099
24223
  if (length > state.limits.maxEntries)
24100
24224
  fail(
@@ -24102,7 +24226,7 @@ function validateArrayHeap(record3, path, state) {
24102
24226
  `${path}.length`,
24103
24227
  `exceeds collection entry limit ${state.limits.maxEntries}`
24104
24228
  );
24105
- const entries = requireRecord(record3.entries, `${path}.entries`);
24229
+ const entries = requireRecord(record4.entries, `${path}.entries`);
24106
24230
  for (const key of Object.keys(entries)) {
24107
24231
  if (key === "length")
24108
24232
  fail("invalidValue", `${path}.entries.length`, "array length is stored separately");
@@ -24111,22 +24235,22 @@ function validateArrayHeap(record3, path, state) {
24111
24235
  fail("invalidValue", `${path}.entries${formatKey(key)}`, "array index exceeds its length");
24112
24236
  }
24113
24237
  }
24114
- function validateErrorType(record3, path) {
24115
- if (!Object.hasOwn(record3, "errorType")) return;
24116
- if (record3.kind !== "object" || !sandboxErrorNames.includes(record3.errorType)) {
24238
+ function validateErrorType(record4, path) {
24239
+ if (!Object.hasOwn(record4, "errorType")) return;
24240
+ if (record4.kind !== "object" || !sandboxErrorNames.includes(record4.errorType)) {
24117
24241
  fail("invalidValue", `${path}.errorType`, "invalid error metadata");
24118
24242
  }
24119
24243
  }
24120
- function validateArgumentsProperties(record3, path) {
24121
- if (typeof record3.extensible !== "boolean") {
24244
+ function validateArgumentsProperties(record4, path) {
24245
+ if (typeof record4.extensible !== "boolean") {
24122
24246
  fail("invalidType", `${path}.extensible`, "expected boolean");
24123
24247
  }
24124
- if (typeof record3.lengthBeforeCallee !== "boolean") {
24248
+ if (typeof record4.lengthBeforeCallee !== "boolean") {
24125
24249
  fail("invalidType", `${path}.lengthBeforeCallee`, "expected boolean");
24126
24250
  }
24127
- const properties = requireRecord(record3.properties, `${path}.properties`);
24128
- if (record3.iterator !== null) {
24129
- const iterator = requireRecord(record3.iterator, `${path}.iterator`);
24251
+ const properties = requireRecord(record4.properties, `${path}.properties`);
24252
+ if (record4.iterator !== null) {
24253
+ const iterator = requireRecord(record4.iterator, `${path}.iterator`);
24130
24254
  for (const key of Object.keys(iterator)) {
24131
24255
  if (!["configurable", "enumerable", "writable"].includes(key)) {
24132
24256
  fail(
@@ -24141,7 +24265,7 @@ function validateArgumentsProperties(record3, path) {
24141
24265
  fail("invalidType", `${path}.iterator.${flag}`, "expected boolean");
24142
24266
  }
24143
24267
  }
24144
- if (record3.lengthBeforeCallee && !Object.hasOwn(properties, "length")) {
24268
+ if (record4.lengthBeforeCallee && !Object.hasOwn(properties, "length")) {
24145
24269
  fail("invalidValue", `${path}.properties`, "initial length property is required");
24146
24270
  }
24147
24271
  for (const [key, value] of Object.entries(properties)) {
@@ -24204,9 +24328,9 @@ function validateGenericValue(value, path, depth, state) {
24204
24328
  );
24205
24329
  }
24206
24330
  } else if (value !== null && typeof value === "object") {
24207
- const record3 = value;
24208
- if (state.validateTaggedPayloads && isTaggedValueShape(record3)) {
24209
- validateTaggedValue(record3, path, state);
24331
+ const record4 = value;
24332
+ if (state.validateTaggedPayloads && isTaggedValueShape(record4)) {
24333
+ validateTaggedValue(record4, path, state);
24210
24334
  }
24211
24335
  const entries = state.dataPropertiesOnly ? snapshotDataEntries(value, path) : Object.entries(value);
24212
24336
  for (const [key, entry] of entries) {
@@ -24715,6 +24839,7 @@ function ownEnumerableSandboxEntries(value, excludedKeys) {
24715
24839
  let entries;
24716
24840
  if (isGuestClosure(value)) entries = Object.entries(value.properties ?? {});
24717
24841
  else if (isSandboxRegex(value)) entries = Object.entries(getRegexProperties(value));
24842
+ else if (isSandboxMap(value) || isSandboxSet(value)) entries = Object.entries(getCollectionProperties(value));
24718
24843
  else if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
24719
24844
  else entries = Object.entries(Object(value));
24720
24845
  return excludedKeys === void 0 ? entries : entries.filter(([key]) => !excludedKeys.has(key));
@@ -24724,18 +24849,20 @@ function ownSandboxSymbolKeys(value) {
24724
24849
  if (isGuestHostObject(value)) return [];
24725
24850
  if (isSandboxClosure(value)) value = value.properties ?? {};
24726
24851
  else if (isSandboxRegex(value)) value = getRegexProperties(value);
24852
+ else if (isSandboxMap(value) || isSandboxSet(value)) value = getCollectionProperties(value);
24727
24853
  else if (isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
24728
24854
  return Object.getOwnPropertySymbols(Object(value)).filter((key) => !internalSymbols.has(key));
24729
24855
  }
24730
24856
  function ownEnumerableSandboxKeys(value, includeSymbols = false) {
24731
24857
  if (includeSymbols) {
24732
- const properties = isSandboxClosure(value) ? value.properties ?? {} : isSandboxRegex(value) ? getRegexProperties(value) : Object(value);
24858
+ const properties = isSandboxClosure(value) ? value.properties ?? {} : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : Object(value);
24733
24859
  return [...ownEnumerableSandboxKeys(value), ...ownSandboxSymbolKeys(value).filter((key) => Object.getOwnPropertyDescriptor(properties, key)?.enumerable === true)];
24734
24860
  }
24735
24861
  if (isGuestHostObject(value)) return getHostObjectKeys(value);
24736
24862
  if (value === null || value === void 0) throw new TypeError("Cannot convert undefined or null to object.");
24737
24863
  if (isGuestClosure(value)) return Object.keys(value.properties ?? {});
24738
24864
  if (isSandboxRegex(value)) return Object.keys(getRegexProperties(value));
24865
+ if (isSandboxMap(value) || isSandboxSet(value)) return Object.keys(getCollectionProperties(value));
24739
24866
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
24740
24867
  return Object.keys(Object(value));
24741
24868
  }
@@ -24789,6 +24916,7 @@ function createSandboxGenerator(channel, metadata = void 0) {
24789
24916
  }
24790
24917
  function createSandboxMap(entries = []) {
24791
24918
  const map = {};
24919
+ collectionGuestProperties.set(map, /* @__PURE__ */ Object.create(null));
24792
24920
  Object.defineProperties(map, {
24793
24921
  kind: {
24794
24922
  value: "map"
@@ -24805,6 +24933,7 @@ function createSandboxMap(entries = []) {
24805
24933
  }
24806
24934
  function createSandboxSet(values = []) {
24807
24935
  const set = {};
24936
+ collectionGuestProperties.set(set, /* @__PURE__ */ Object.create(null));
24808
24937
  Object.defineProperties(set, {
24809
24938
  kind: {
24810
24939
  value: "set"
@@ -24977,6 +25106,16 @@ function measureSandboxData(values, options = {}) {
24977
25106
  }
24978
25107
  return;
24979
25108
  }
25109
+ if (isSandboxMap(value) || isSandboxSet(value)) {
25110
+ const properties = getCollectionProperties(value);
25111
+ for (const key of Reflect.ownKeys(properties)) {
25112
+ const descriptor = Object.getOwnPropertyDescriptor(properties, key);
25113
+ usage += 1 + (typeof key === "string" ? key.length : 0);
25114
+ if (typeof key === "symbol") visit(key, depth + 1);
25115
+ if ("value" in descriptor) visit(descriptor.value, depth + 1);
25116
+ else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
25117
+ }
25118
+ }
24980
25119
  if (isSandboxMap(value)) {
24981
25120
  usage += value.entries.size;
24982
25121
  for (const [key, entry] of value.entries) {
@@ -25220,6 +25359,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
25220
25359
  if (existing !== void 0) return existing;
25221
25360
  const copy = createSandboxMap();
25222
25361
  state.seen.set(value, copy);
25362
+ if (!state.structuredClone) copyCollectionProperties(value, getCollectionProperties(copy), (entry) => copyToSandbox(entry, state, `${path}.<property>`, true, depth + 1));
25223
25363
  for (const [key, entry] of value.entries) {
25224
25364
  copy.entries.set(
25225
25365
  copyToSandbox(key, state, `${path}.<key>`, true, depth + 1),
@@ -25234,6 +25374,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
25234
25374
  if (existing !== void 0) return existing;
25235
25375
  const copy = createSandboxSet();
25236
25376
  state.seen.set(value, copy);
25377
+ if (!state.structuredClone) copyCollectionProperties(value, getCollectionProperties(copy), (entry) => copyToSandbox(entry, state, `${path}.<property>`, true, depth + 1));
25237
25378
  for (const entry of value.values) {
25238
25379
  copy.values.add(copyToSandbox(entry, state, `${path}.<value>`, true, depth + 1));
25239
25380
  }
@@ -25292,6 +25433,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
25292
25433
  }
25293
25434
  const copy = createSandboxMap();
25294
25435
  state.seen.set(value, copy);
25436
+ if (!state.structuredClone) copyCollectionProperties(value, getCollectionProperties(copy), (entry) => copyToSandbox(entry, state, `${path}.<property>`, cloneSandboxCollections, depth + 1));
25295
25437
  for (const [key, entry] of value) {
25296
25438
  copy.entries.set(
25297
25439
  copyToSandbox(key, state, `${path}.<key>`, cloneSandboxCollections, depth + 1),
@@ -25307,6 +25449,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
25307
25449
  }
25308
25450
  const copy = createSandboxSet();
25309
25451
  state.seen.set(value, copy);
25452
+ if (!state.structuredClone) copyCollectionProperties(value, getCollectionProperties(copy), (entry) => copyToSandbox(entry, state, `${path}.<property>`, cloneSandboxCollections, depth + 1));
25310
25453
  for (const entry of value) {
25311
25454
  copy.values.add(
25312
25455
  copyToSandbox(entry, state, `${path}.<value>`, cloneSandboxCollections, depth + 1)
@@ -25515,6 +25658,7 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
25515
25658
  }
25516
25659
  const copy = /* @__PURE__ */ new Map();
25517
25660
  state.seen.set(value, copy);
25661
+ copyCollectionProperties(value, copy, (entry) => copyFromSandbox(entry, state, `${path}.<property>`, options, depth + 1));
25518
25662
  for (const [key, entry] of value.entries) {
25519
25663
  copy.set(
25520
25664
  copyFromSandbox(key, state, `${path}.<key>`, options, depth + 1),
@@ -25530,6 +25674,7 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
25530
25674
  }
25531
25675
  const copy = /* @__PURE__ */ new Set();
25532
25676
  state.seen.set(value, copy);
25677
+ copyCollectionProperties(value, copy, (entry) => copyFromSandbox(entry, state, `${path}.<property>`, options, depth + 1));
25533
25678
  for (const entry of value.values) {
25534
25679
  copy.add(copyFromSandbox(entry, state, `${path}.<value>`, options, depth + 1));
25535
25680
  }
@@ -25757,12 +25902,12 @@ var HostCallResumabilityError = class extends Error {
25757
25902
  static [Symbol.hasInstance](value) {
25758
25903
  return typeof value === "object" && value !== null && #nativeInstance in value && Function.prototype[Symbol.hasInstance].call(this, value);
25759
25904
  }
25760
- constructor(record3, action, message) {
25905
+ constructor(record4, action, message) {
25761
25906
  super(message);
25762
25907
  this.name = "HostCallResumabilityError";
25763
25908
  this.action = action;
25764
- this.callId = record3.id;
25765
- this.lifecycle = record3.lifecycle;
25909
+ this.callId = record4.id;
25910
+ this.lifecycle = record4.lifecycle;
25766
25911
  }
25767
25912
  };
25768
25913
  var UnresolvedReplayCapabilityError = class extends TypeError {
@@ -25794,33 +25939,33 @@ var HostCallJournal = class {
25794
25939
  );
25795
25940
  const restoredRunId = replayRecords[0]?.runId ?? records[0]?.runId ?? randomUUID();
25796
25941
  validateRestoredRecords(records, restoredRunId, sourceHash);
25797
- for (const record3 of records) {
25798
- const replayRecord = replayRecords[readCallOrdinal(record3) - 1];
25799
- if (replayRecord === void 0 || !callIdentityMatches(record3, replayRecord) || record3.lifecycle !== replayRecord.lifecycle) {
25942
+ for (const record4 of records) {
25943
+ const replayRecord = replayRecords[readCallOrdinal(record4) - 1];
25944
+ if (replayRecord === void 0 || !callIdentityMatches(record4, replayRecord) || record4.lifecycle !== replayRecord.lifecycle) {
25800
25945
  throw new HostCallResumabilityError(
25801
- record3,
25946
+ record4,
25802
25947
  "reset",
25803
- `Host call ${record3.id} conflicts with the replay journal; reset is required.`
25948
+ `Host call ${record4.id} conflicts with the replay journal; reset is required.`
25804
25949
  );
25805
25950
  }
25806
25951
  }
25807
25952
  records = replayRecords;
25808
25953
  }
25809
25954
  this.runId = records[0]?.runId ?? randomUUID();
25810
- this.records = records.map((record3) => ({
25811
- ...record3,
25812
- ...record3.functions === void 0 ? {} : { functions: [...record3.functions] },
25813
- ...record3.callbacks === void 0 ? {} : { callbacks: structuredClone(record3.callbacks) },
25814
- ...record3.outcome === void 0 ? {} : { outcome: copyOutcome(record3.outcome) }
25955
+ this.records = records.map((record4) => ({
25956
+ ...record4,
25957
+ ...record4.functions === void 0 ? {} : { functions: [...record4.functions] },
25958
+ ...record4.callbacks === void 0 ? {} : { callbacks: structuredClone(record4.callbacks) },
25959
+ ...record4.outcome === void 0 ? {} : { outcome: copyOutcome(record4.outcome) }
25815
25960
  }));
25816
25961
  validateRestoredRecords(this.records, this.runId, sourceHash);
25817
25962
  this.retainedSize = this.records.length;
25818
25963
  try {
25819
25964
  this.budget?.setRetainedDataUsage(this, this.retainedSize);
25820
- for (const record3 of this.records) {
25821
- if (record3.outcome !== void 0) this.retainOutcome(record3, record3.outcome);
25822
- for (const [index, callback] of (record3.callbacks ?? []).entries()) {
25823
- let size = this.callbackSizes.get(`${record3.id}/callback/${index + 1}`);
25965
+ for (const record4 of this.records) {
25966
+ if (record4.outcome !== void 0) this.retainOutcome(record4, record4.outcome);
25967
+ for (const [index, callback] of (record4.callbacks ?? []).entries()) {
25968
+ let size = this.callbackSizes.get(`${record4.id}/callback/${index + 1}`);
25824
25969
  if (size === void 0) {
25825
25970
  const validation = new CompileScope(operation?.owner);
25826
25971
  try {
@@ -25894,7 +26039,7 @@ var HostCallJournal = class {
25894
26039
  createRecord(input) {
25895
26040
  this.budget?.setRetainedDataUsage(this, this.retainedSize + 1);
25896
26041
  this.retainedSize += 1;
25897
- const record3 = {
26042
+ const record4 = {
25898
26043
  id: `${this.runId}:${this.nextCall++}`,
25899
26044
  runId: this.runId,
25900
26045
  sourceHash: this.sourceHash,
@@ -25904,65 +26049,65 @@ var HostCallJournal = class {
25904
26049
  policy: input.policy,
25905
26050
  lifecycle: "created"
25906
26051
  };
25907
- this.records.push(record3);
26052
+ this.records.push(record4);
25908
26053
  this.records.sort((left, right) => readCallOrdinal(left) - readCallOrdinal(right));
25909
- return record3;
26054
+ return record4;
25910
26055
  }
25911
- start(record3) {
25912
- record3.lifecycle = "running";
26056
+ start(record4) {
26057
+ record4.lifecycle = "running";
25913
26058
  }
25914
- settle(record3, outcome) {
25915
- if (record3.lifecycle === "cancelled") return;
25916
- this.retainOutcome(record3, outcome);
25917
- record3.lifecycle = "settled";
26059
+ settle(record4, outcome) {
26060
+ if (record4.lifecycle === "cancelled") return;
26061
+ this.retainOutcome(record4, outcome);
26062
+ record4.lifecycle = "settled";
25918
26063
  }
25919
- consume(record3) {
25920
- if (record3.lifecycle === "consumed") {
26064
+ consume(record4) {
26065
+ if (record4.lifecycle === "consumed") {
25921
26066
  throw new HostCallResumabilityError(
25922
- record3,
26067
+ record4,
25923
26068
  "reset",
25924
- `Host call ${record3.id} result was already consumed; reset is required.`
26069
+ `Host call ${record4.id} result was already consumed; reset is required.`
25925
26070
  );
25926
26071
  }
25927
- if (record3.lifecycle !== "settled") return;
25928
- record3.lifecycle = "consumed";
26072
+ if (record4.lifecycle !== "settled") return;
26073
+ record4.lifecycle = "consumed";
25929
26074
  }
25930
- cancel(record3, reason) {
25931
- if (record3.lifecycle === "settled" || record3.lifecycle === "consumed") return;
25932
- this.retainOutcome(record3, { status: "rejected", reason });
25933
- record3.lifecycle = "cancelled";
26075
+ cancel(record4, reason) {
26076
+ if (record4.lifecycle === "settled" || record4.lifecycle === "consumed") return;
26077
+ this.retainOutcome(record4, { status: "rejected", reason });
26078
+ record4.lifecycle = "cancelled";
25934
26079
  }
25935
- async reconcile(record3, context) {
25936
- if (record3.lifecycle === "settled" && record3.outcome !== void 0) return record3.outcome;
25937
- if (record3.lifecycle === "consumed") {
26080
+ async reconcile(record4, context) {
26081
+ if (record4.lifecycle === "settled" && record4.outcome !== void 0) return record4.outcome;
26082
+ if (record4.lifecycle === "consumed") {
25938
26083
  throw new HostCallResumabilityError(
25939
- record3,
26084
+ record4,
25940
26085
  "reset",
25941
- `Host call ${record3.id} result was already consumed; reset is required.`
26086
+ `Host call ${record4.id} result was already consumed; reset is required.`
25942
26087
  );
25943
26088
  }
25944
- if (record3.lifecycle === "cancelled") {
26089
+ if (record4.lifecycle === "cancelled") {
25945
26090
  throw new HostCallResumabilityError(
25946
- record3,
26091
+ record4,
25947
26092
  "reset",
25948
- `Host call ${record3.id} was cancelled; reset is required.`
26093
+ `Host call ${record4.id} was cancelled; reset is required.`
25949
26094
  );
25950
26095
  }
25951
- if (record3.policy === "re-issue") {
26096
+ if (record4.policy === "re-issue") {
25952
26097
  throw new HostCallResumabilityError(
25953
- record3,
26098
+ record4,
25954
26099
  "reset",
25955
- `Host call ${record3.id} must be re-issued by the runtime.`
26100
+ `Host call ${record4.id} must be re-issued by the runtime.`
25956
26101
  );
25957
26102
  }
25958
26103
  if (this.resumeProvider === void 0) {
25959
26104
  throw new HostCallResumabilityError(
25960
- record3,
26105
+ record4,
25961
26106
  "external-reconciliation",
25962
- `Host call ${record3.id} may have executed before process death; external reconciliation is required.`
26107
+ `Host call ${record4.id} may have executed before process death; external reconciliation is required.`
25963
26108
  );
25964
26109
  }
25965
- const { id, outcome: ignoredOutcome, ...request } = record3;
26110
+ const { id, outcome: ignoredOutcome, ...request } = record4;
25966
26111
  void ignoredOutcome;
25967
26112
  const proof = await this.resumeProvider(
25968
26113
  {
@@ -25972,23 +26117,23 @@ var HostCallJournal = class {
25972
26117
  },
25973
26118
  context
25974
26119
  );
25975
- validateProof(record3, proof);
26120
+ validateProof(record4, proof);
25976
26121
  if (context !== void 0 && context.callbacks.size > 0 && proof.callbackDisposition === void 0) {
25977
26122
  throw new HostCallResumabilityError(
25978
- record3,
26123
+ record4,
25979
26124
  "external-reconciliation",
25980
- `Host call ${record3.id} has sandbox callbacks; its proof must specify callbackDisposition as joined or detached.`
26125
+ `Host call ${record4.id} has sandbox callbacks; its proof must specify callbackDisposition as joined or detached.`
25981
26126
  );
25982
26127
  }
25983
26128
  if (proof.callbackDisposition === "joined") await context?.waitForCallbacks();
25984
- this.settle(record3, proof.outcome);
26129
+ this.settle(record4, proof.outcome);
25985
26130
  return proof.outcome;
25986
26131
  }
25987
26132
  snapshot() {
25988
26133
  return this.records.filter(
25989
- (record3) => record3.policy === "read-side-effect" || record3.lifecycle === "created" || record3.lifecycle === "running" || record3.lifecycle === "cancelled"
25990
- ).map(({ outcome, ...record3 }) => ({
25991
- ...structuredClone(record3),
26134
+ (record4) => record4.policy === "read-side-effect" || record4.lifecycle === "created" || record4.lifecycle === "running" || record4.lifecycle === "cancelled"
26135
+ ).map(({ outcome, ...record4 }) => ({
26136
+ ...structuredClone(record4),
25992
26137
  ...outcome === void 0 ? {} : { outcome: copyOutcome(outcome) }
25993
26138
  }));
25994
26139
  }
@@ -26001,12 +26146,12 @@ var HostCallJournal = class {
26001
26146
  this.capabilityWaiters.clear();
26002
26147
  this.budget = void 0;
26003
26148
  }
26004
- registerCallbackFunction(record3, id, closure, native) {
26005
- const identity = `${record3.id}/function/${id}`;
26149
+ registerCallbackFunction(record4, id, closure, native) {
26150
+ const identity = `${record4.id}/function/${id}`;
26006
26151
  const existing = this.capabilities.get(identity);
26007
26152
  if (existing !== void 0 && existing !== closure)
26008
26153
  throw new TypeError(`Conflicting replay capability '${identity}'.`);
26009
- if (!(record3.functions ?? []).includes(id)) (record3.functions ??= []).push(id);
26154
+ if (!(record4.functions ?? []).includes(id)) (record4.functions ??= []).push(id);
26010
26155
  this.capabilities.set(identity, closure);
26011
26156
  this.capabilityWaiters.get(identity)?.resolve();
26012
26157
  this.capabilityWaiters.delete(identity);
@@ -26056,11 +26201,11 @@ var HostCallJournal = class {
26056
26201
  }
26057
26202
  return waiter.promise;
26058
26203
  }
26059
- trackCallbackCompletion(record3, callbacks) {
26204
+ trackCallbackCompletion(record4, callbacks) {
26060
26205
  const complete = () => {
26061
- this.completedCallbackOwners.add(record3.id);
26206
+ this.completedCallbackOwners.add(record4.id);
26062
26207
  for (const [id, waiter] of this.capabilityWaiters) {
26063
- if (!id.startsWith(`${record3.id}/function/`)) continue;
26208
+ if (!id.startsWith(`${record4.id}/function/`)) continue;
26064
26209
  waiter.reject(new UnresolvedReplayCapabilityError(id));
26065
26210
  this.capabilityWaiters.delete(id);
26066
26211
  }
@@ -26068,7 +26213,7 @@ var HostCallJournal = class {
26068
26213
  if (callbacks.length === 0) complete();
26069
26214
  else void Promise.allSettled(callbacks).then(complete);
26070
26215
  }
26071
- recordCallback(record3, id, args, step) {
26216
+ recordCallback(record4, id, args, step) {
26072
26217
  const retainedSize = this.retainedSize + 1 + measureSandboxData([args], { ignoreClosures: true });
26073
26218
  this.budget?.setRetainedDataUsage(this, retainedSize);
26074
26219
  let data;
@@ -26079,25 +26224,25 @@ var HostCallJournal = class {
26079
26224
  throw error;
26080
26225
  }
26081
26226
  this.retainedSize = retainedSize;
26082
- (record3.callbacks ??= []).push({ id, step, arguments: data });
26083
- return `${record3.id}/callback/${record3.callbacks.length}`;
26227
+ (record4.callbacks ??= []).push({ id, step, arguments: data });
26228
+ return `${record4.id}/callback/${record4.callbacks.length}`;
26084
26229
  }
26085
26230
  callbackPositions() {
26086
26231
  const positions = /* @__PURE__ */ new Map();
26087
- for (const record3 of this.records) {
26088
- for (const [index, callback] of (record3.callbacks ?? []).entries()) {
26089
- positions.set(`${record3.id}/callback/${index + 1}`, callback.step);
26232
+ for (const record4 of this.records) {
26233
+ for (const [index, callback] of (record4.callbacks ?? []).entries()) {
26234
+ positions.set(`${record4.id}/callback/${index + 1}`, callback.step);
26090
26235
  }
26091
26236
  }
26092
26237
  return positions;
26093
26238
  }
26094
- retainOutcome(record3, outcome, budget = this.budget) {
26239
+ retainOutcome(record4, outcome, budget = this.budget) {
26095
26240
  const included = /* @__PURE__ */ new Set();
26096
26241
  const size = measureSandboxData(
26097
26242
  [outcome.status === "fulfilled" ? outcome.value : outcome.reason],
26098
26243
  { ignoreClosures: true, compileTickets: included }
26099
26244
  );
26100
- const retainedSize = this.retainedSize + size - (this.outcomeSizes.get(record3.id) ?? 0);
26245
+ const retainedSize = this.retainedSize + size - (this.outcomeSizes.get(record4.id) ?? 0);
26101
26246
  budget?.reconcileCompileData(retainedSize, included, included, this);
26102
26247
  let copied;
26103
26248
  try {
@@ -26107,14 +26252,14 @@ var HostCallJournal = class {
26107
26252
  throw error;
26108
26253
  }
26109
26254
  this.retainedSize = retainedSize;
26110
- this.outcomeSizes.set(record3.id, size);
26111
- this.outcomes.set(record3.id, copied);
26112
- record3.outcome = copied;
26255
+ this.outcomeSizes.set(record4.id, size);
26256
+ this.outcomes.set(record4.id, copied);
26257
+ record4.outcome = copied;
26113
26258
  }
26114
- replayOutcome(record3) {
26115
- if (!this.recordedReplay || record3.lifecycle !== "settled" && record3.lifecycle !== "consumed")
26259
+ replayOutcome(record4) {
26260
+ if (!this.recordedReplay || record4.lifecycle !== "settled" && record4.lifecycle !== "consumed")
26116
26261
  return void 0;
26117
- const encoded = this.encodedOutcomes.get(record3.id);
26262
+ const encoded = this.encodedOutcomes.get(record4.id);
26118
26263
  if (encoded !== void 0) {
26119
26264
  const budget = this.compileOwner?.budget ?? this.budget;
26120
26265
  const operation = budget?.acquireCompileOwner(false, this.compileOwner);
@@ -26126,29 +26271,29 @@ var HostCallJournal = class {
26126
26271
  compilation
26127
26272
  );
26128
26273
  const outcome2 = encoded.status === "fulfilled" ? { status: "fulfilled", value } : { status: "rejected", reason: value };
26129
- this.retainOutcome(record3, outcome2, budget);
26274
+ this.retainOutcome(record4, outcome2, budget);
26130
26275
  return outcome2;
26131
26276
  } finally {
26132
26277
  compilation.dispose();
26133
26278
  operation?.release();
26134
26279
  }
26135
26280
  }
26136
- const outcome = this.outcomes.get(record3.id);
26281
+ const outcome = this.outcomes.get(record4.id);
26137
26282
  return outcome === void 0 ? void 0 : copyOutcome(outcome);
26138
26283
  }
26139
26284
  snapshotReplay() {
26140
26285
  return structuredClone({
26141
26286
  version: 1,
26142
- calls: this.records.map(({ outcome: ignoredOutcome, asynchronous, ...record3 }) => {
26287
+ calls: this.records.map(({ outcome: ignoredOutcome, asynchronous, ...record4 }) => {
26143
26288
  void ignoredOutcome;
26144
- const outcome = this.outcomes.get(record3.id);
26289
+ const outcome = this.outcomes.get(record4.id);
26145
26290
  return {
26146
- ...record3,
26291
+ ...record4,
26147
26292
  asynchronous: asynchronous === true,
26148
26293
  ...outcome === void 0 ? {} : {
26149
26294
  outcome: {
26150
26295
  status: outcome.status,
26151
- data: this.encodedOutcomes.get(record3.id)?.data ?? encodeReplayData(
26296
+ data: this.encodedOutcomes.get(record4.id)?.data ?? encodeReplayData(
26152
26297
  outcome.status === "fulfilled" ? outcome.value : outcome.reason,
26153
26298
  { identifyCapability: this.identifyCapability }
26154
26299
  )
@@ -26245,79 +26390,79 @@ function restoreReplayCalls(input, encodedOutcomes, callbackSizes, requiredHostC
26245
26390
  function validateRestoredRecords(records, runId, sourceHash) {
26246
26391
  const ids = /* @__PURE__ */ new Set();
26247
26392
  let previousOrdinal = 0;
26248
- for (const record3 of records) {
26249
- if (record3.runId !== runId || !record3.id.startsWith(`${runId}:`)) {
26393
+ for (const record4 of records) {
26394
+ if (record4.runId !== runId || !record4.id.startsWith(`${runId}:`)) {
26250
26395
  throw new HostCallResumabilityError(
26251
- record3,
26396
+ record4,
26252
26397
  "reset",
26253
- `Host call ${record3.id} does not belong to restored run ${runId}; reset is required.`
26398
+ `Host call ${record4.id} does not belong to restored run ${runId}; reset is required.`
26254
26399
  );
26255
26400
  }
26256
- if (record3.sourceHash !== sourceHash) {
26401
+ if (record4.sourceHash !== sourceHash) {
26257
26402
  throw new HostCallResumabilityError(
26258
- record3,
26403
+ record4,
26259
26404
  "reset",
26260
- `Host call ${record3.id} does not match the restored source; reset is required.`
26405
+ `Host call ${record4.id} does not match the restored source; reset is required.`
26261
26406
  );
26262
26407
  }
26263
- if (ids.has(record3.id)) {
26408
+ if (ids.has(record4.id)) {
26264
26409
  throw new HostCallResumabilityError(
26265
- record3,
26410
+ record4,
26266
26411
  "reset",
26267
- `Host call ${record3.id} appears more than once; reset is required.`
26412
+ `Host call ${record4.id} appears more than once; reset is required.`
26268
26413
  );
26269
26414
  }
26270
- const ordinal = readCallOrdinal(record3);
26415
+ const ordinal = readCallOrdinal(record4);
26271
26416
  if (ordinal <= previousOrdinal) {
26272
26417
  throw new HostCallResumabilityError(
26273
- record3,
26418
+ record4,
26274
26419
  "reset",
26275
- `Host call ${record3.id} is out of order; reset is required.`
26420
+ `Host call ${record4.id} is out of order; reset is required.`
26276
26421
  );
26277
26422
  }
26278
26423
  previousOrdinal = ordinal;
26279
- ids.add(record3.id);
26424
+ ids.add(record4.id);
26280
26425
  }
26281
26426
  }
26282
- function readCallOrdinal(record3) {
26283
- const ordinal = Number(record3.id.slice(record3.id.lastIndexOf(":") + 1));
26427
+ function readCallOrdinal(record4) {
26428
+ const ordinal = Number(record4.id.slice(record4.id.lastIndexOf(":") + 1));
26284
26429
  if (!Number.isSafeInteger(ordinal) || ordinal < 1) {
26285
26430
  throw new HostCallResumabilityError(
26286
- record3,
26431
+ record4,
26287
26432
  "reset",
26288
- `Host call ${record3.id} has an invalid ordinal; reset is required.`
26433
+ `Host call ${record4.id} has an invalid ordinal; reset is required.`
26289
26434
  );
26290
26435
  }
26291
26436
  return ordinal;
26292
26437
  }
26293
- function callIdentityMatches(record3, input) {
26294
- return record3.moduleId === input.moduleId && record3.operation === input.operation && record3.argumentDigest === input.argumentDigest && record3.policy === input.policy;
26438
+ function callIdentityMatches(record4, input) {
26439
+ return record4.moduleId === input.moduleId && record4.operation === input.operation && record4.argumentDigest === input.argumentDigest && record4.policy === input.policy;
26295
26440
  }
26296
26441
  function digestHostCallArguments(args) {
26297
26442
  return createHash("sha256").update(stableStringify(args)).digest("hex");
26298
26443
  }
26299
- function validateProof(record3, proof) {
26444
+ function validateProof(record4, proof) {
26300
26445
  if (proof.callbackDisposition !== void 0 && proof.callbackDisposition !== "joined" && proof.callbackDisposition !== "detached") {
26301
26446
  throw new HostCallResumabilityError(
26302
- record3,
26447
+ record4,
26303
26448
  "external-reconciliation",
26304
26449
  "Invalid callbackDisposition in external result proof."
26305
26450
  );
26306
26451
  }
26307
26452
  if (!pendingHostCallResumeIdentityMatches(
26308
26453
  {
26309
- argumentDigest: record3.argumentDigest,
26310
- callId: record3.id,
26311
- moduleId: record3.moduleId,
26312
- operation: record3.operation,
26313
- sourceHash: record3.sourceHash
26454
+ argumentDigest: record4.argumentDigest,
26455
+ callId: record4.id,
26456
+ moduleId: record4.moduleId,
26457
+ operation: record4.operation,
26458
+ sourceHash: record4.sourceHash
26314
26459
  },
26315
26460
  proof
26316
26461
  )) {
26317
26462
  throw new HostCallResumabilityError(
26318
- record3,
26463
+ record4,
26319
26464
  "external-reconciliation",
26320
- `External result proof does not match host call ${record3.id}.`
26465
+ `External result proof does not match host call ${record4.id}.`
26321
26466
  );
26322
26467
  }
26323
26468
  }
@@ -26426,7 +26571,7 @@ function hashParsedAst(ast, includeFunctionSource = true) {
26426
26571
  write(JSON.stringify(value));
26427
26572
  return;
26428
26573
  case "object": {
26429
- const record3 = value;
26574
+ const record4 = value;
26430
26575
  const source = includeFunctionSource ? functionSources.get(value) : void 0;
26431
26576
  if (source !== void 0 && !(enclosingSource !== void 0 && source.text === enclosingSource.text && source.start >= enclosingSource.start && source.end <= enclosingSource.end)) {
26432
26577
  write("function-source:");
@@ -26434,14 +26579,14 @@ function hashParsedAst(ast, includeFunctionSource = true) {
26434
26579
  write(":");
26435
26580
  write(source.text, source.start, source.end);
26436
26581
  }
26437
- const keys = Object.keys(value).filter((key) => shouldHashKey(record3, key, includeTemplateRaw)).sort();
26582
+ const keys = Object.keys(value).filter((key) => shouldHashKey(record4, key, includeTemplateRaw)).sort();
26438
26583
  write("{");
26439
26584
  for (const key of keys) {
26440
26585
  write(JSON.stringify(key));
26441
26586
  write(":");
26442
26587
  visit(
26443
- record3[key],
26444
- shouldIncludeTemplateRaw(record3, key, includeTemplateRaw),
26588
+ record4[key],
26589
+ shouldIncludeTemplateRaw(record4, key, includeTemplateRaw),
26445
26590
  source ?? enclosingSource
26446
26591
  );
26447
26592
  write(",");
@@ -26460,20 +26605,20 @@ function hashParsedAst(ast, includeFunctionSource = true) {
26460
26605
  }
26461
26606
  }
26462
26607
  }
26463
- function shouldHashKey(record3, key, includeTemplateRaw) {
26608
+ function shouldHashKey(record4, key, includeTemplateRaw) {
26464
26609
  if (key !== "raw") {
26465
26610
  return !IGNORED_KEYS.has(key);
26466
26611
  }
26467
- return includeTemplateRaw || record3.type === "RegexLiteral";
26612
+ return includeTemplateRaw || record4.type === "RegexLiteral";
26468
26613
  }
26469
- function shouldIncludeTemplateRaw(record3, key, includeTemplateRaw) {
26470
- if (record3.type === "TaggedTemplateExpression" && key === "quasi") {
26614
+ function shouldIncludeTemplateRaw(record4, key, includeTemplateRaw) {
26615
+ if (record4.type === "TaggedTemplateExpression" && key === "quasi") {
26471
26616
  return true;
26472
26617
  }
26473
- if (includeTemplateRaw && record3.type === "TemplateLiteral" && key === "quasis") {
26618
+ if (includeTemplateRaw && record4.type === "TemplateLiteral" && key === "quasis") {
26474
26619
  return true;
26475
26620
  }
26476
- if (includeTemplateRaw && record3.type === "TemplateElement" && key === "value") {
26621
+ if (includeTemplateRaw && record4.type === "TemplateElement" && key === "value") {
26477
26622
  return true;
26478
26623
  }
26479
26624
  return false;
@@ -26630,11 +26775,11 @@ function restore(snapshot, options, owner) {
26630
26775
  for (const entry of Object.values(node)) pending.push(entry);
26631
26776
  }
26632
26777
  for (const [id, value] of closures) {
26633
- const record3 = value;
26634
- if (record3.kind === "guest-array") continue;
26635
- const origin = functions.get(record3.astNodeId);
26778
+ const record4 = value;
26779
+ if (record4.kind === "guest-array") continue;
26780
+ const origin = functions.get(record4.astNodeId);
26636
26781
  try {
26637
- validateGuestFunctionAst(record3, origin);
26782
+ validateGuestFunctionAst(record4, origin);
26638
26783
  } catch (error) {
26639
26784
  throw new SnapshotValidationError("invalidValue", `$.heap[${JSON.stringify(id)}].astNodeId`, error instanceof Error ? error.message : String(error));
26640
26785
  }
@@ -38229,8 +38374,8 @@ var RealmState = class {
38229
38374
  this.assertOpen();
38230
38375
  const closure = readGuestCallback(callback, this);
38231
38376
  this.checkCollection(this.pendingCallbacks.size + 1, this.limits.callbacks, "pending callback");
38232
- const record3 = { closure };
38233
- this.pendingCallbacks.add(record3);
38377
+ const record4 = { closure };
38378
+ this.pendingCallbacks.add(record4);
38234
38379
  const invoke = async () => {
38235
38380
  this.assertOpen();
38236
38381
  readGuestCallback(callback, this);
@@ -38271,13 +38416,13 @@ var RealmState = class {
38271
38416
  )
38272
38417
  )
38273
38418
  );
38274
- record3.promise = active ? pending : this.perform(() => pending);
38275
- return await record3.promise;
38419
+ record4.promise = active ? pending : this.perform(() => pending);
38420
+ return await record4.promise;
38276
38421
  } catch (error) {
38277
38422
  if (error instanceof SandboxError) this.poison(error);
38278
38423
  throw error;
38279
38424
  } finally {
38280
- this.pendingCallbacks.delete(record3);
38425
+ this.pendingCallbacks.delete(record4);
38281
38426
  if (!this.closed && this.active === void 0)
38282
38427
  reconcileCompiledValues(
38283
38428
  this.budget,
@@ -39727,7 +39872,7 @@ function readHostCallSnapshot(snapshot) {
39727
39872
  if (typeof value !== "object" || value === null) {
39728
39873
  throw new TypeError(`Snapshot hostCalls[${index}] must be an object.`);
39729
39874
  }
39730
- const record3 = value;
39875
+ const record4 = value;
39731
39876
  const requiredStrings = [
39732
39877
  "id",
39733
39878
  "runId",
@@ -39737,23 +39882,23 @@ function readHostCallSnapshot(snapshot) {
39737
39882
  "argumentDigest"
39738
39883
  ];
39739
39884
  for (const key of requiredStrings) {
39740
- if (typeof record3[key] !== "string" || record3[key].length === 0) {
39885
+ if (typeof record4[key] !== "string" || record4[key].length === 0) {
39741
39886
  throw new TypeError(`Snapshot hostCalls[${index}].${key} must be a non-empty string.`);
39742
39887
  }
39743
39888
  }
39744
- if (record3.sourceHash !== snapshot.sourceHash) {
39889
+ if (record4.sourceHash !== snapshot.sourceHash) {
39745
39890
  throw new TypeError(`Snapshot hostCalls[${index}].sourceHash must match the snapshot.`);
39746
39891
  }
39747
- if (record3.policy !== "re-issue" && record3.policy !== "read-side-effect") {
39892
+ if (record4.policy !== "re-issue" && record4.policy !== "read-side-effect") {
39748
39893
  throw new TypeError(`Snapshot hostCalls[${index}].policy is invalid.`);
39749
39894
  }
39750
- if (record3.lifecycle !== "created" && record3.lifecycle !== "running" && record3.lifecycle !== "settled" && record3.lifecycle !== "consumed" && record3.lifecycle !== "cancelled") {
39895
+ if (record4.lifecycle !== "created" && record4.lifecycle !== "running" && record4.lifecycle !== "settled" && record4.lifecycle !== "consumed" && record4.lifecycle !== "cancelled") {
39751
39896
  throw new TypeError(`Snapshot hostCalls[${index}].lifecycle is invalid.`);
39752
39897
  }
39753
- if ((record3.lifecycle === "settled" || record3.lifecycle === "cancelled") && record3.outcome === void 0) {
39898
+ if ((record4.lifecycle === "settled" || record4.lifecycle === "cancelled") && record4.outcome === void 0) {
39754
39899
  throw new TypeError(`Snapshot hostCalls[${index}].outcome is required.`);
39755
39900
  }
39756
- return record3;
39901
+ return record4;
39757
39902
  });
39758
39903
  }
39759
39904
  function hasLoopIterationSnapshot(snapshot) {
@@ -39815,4 +39960,4 @@ export {
39815
39960
  FileSnapshotBackend,
39816
39961
  run
39817
39962
  };
39818
- //# sourceMappingURL=chunk-A2FDFKJ6.js.map
39963
+ //# sourceMappingURL=chunk-KBUVHGDL.js.map