@poe-platform/safe-js 0.1.442 → 0.1.444

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.
@@ -6993,6 +6993,9 @@ import { types as types10 } from "node:util";
6993
6993
  // packages/safe-js/src/interp/module-function-origin.ts
6994
6994
  var moduleFunctionOrigins = /* @__PURE__ */ new WeakMap();
6995
6995
 
6996
+ // packages/safe-js/src/interp/host-function-metadata.ts
6997
+ var hostFunctionMetadata = /* @__PURE__ */ new WeakMap();
6998
+
6996
6999
  // packages/safe-js/src/interp/running-state.ts
6997
7000
  var runningObjects = /* @__PURE__ */ new WeakSet();
6998
7001
  var lockedCollections = /* @__PURE__ */ new WeakSet();
@@ -8501,6 +8504,7 @@ var typedArrayPrototypes = /* @__PURE__ */ new WeakMap();
8501
8504
  // packages/safe-js/src/interp/object-model.ts
8502
8505
  var guestClosures = /* @__PURE__ */ new WeakSet();
8503
8506
  var functionProperties = /* @__PURE__ */ new WeakMap();
8507
+ var hostFunctionPropertyTables = /* @__PURE__ */ new WeakSet();
8504
8508
  var functionPropertyRevisions = /* @__PURE__ */ new WeakMap();
8505
8509
  var trackedIntrinsicObjects = /* @__PURE__ */ new WeakSet();
8506
8510
  var prototypes = /* @__PURE__ */ new WeakMap();
@@ -8545,16 +8549,21 @@ function intrinsicFunctionDataDescriptors(properties) {
8545
8549
  }
8546
8550
  return descriptors2;
8547
8551
  }
8548
- function materializeFunctionProperties(closure) {
8549
- if (!isGuestClosure(closure)) throw new TypeError("Host function properties are read only.");
8552
+ function materializeFunctionProperties(closure, initialProperties) {
8550
8553
  const existing = functionProperties.get(closure);
8551
8554
  if (existing !== void 0) return existing;
8555
+ if (initialProperties !== void 0) {
8556
+ descriptorObjects.add(initialProperties);
8557
+ if (!isGuestClosure(closure)) hostFunctionPropertyTables.add(initialProperties);
8558
+ functionProperties.set(closure, initialProperties);
8559
+ return initialProperties;
8560
+ }
8552
8561
  const properties = /* @__PURE__ */ Object.create(null);
8553
8562
  Object.defineProperties(properties, {
8554
8563
  length: { value: closure.length ?? 0, configurable: true },
8555
8564
  name: { value: closure.name ?? "", configurable: true }
8556
8565
  });
8557
- if (closure.construct !== void 0 && closure.boundTarget === void 0) {
8566
+ if (isGuestClosure(closure) && closure.construct !== void 0 && closure.boundTarget === void 0) {
8558
8567
  const prototype = /* @__PURE__ */ Object.create(null);
8559
8568
  Object.defineProperty(prototype, "constructor", {
8560
8569
  value: closure,
@@ -8566,6 +8575,7 @@ function materializeFunctionProperties(closure) {
8566
8575
  }
8567
8576
  const tracked = trackPropertyTable(properties);
8568
8577
  descriptorObjects.add(tracked);
8578
+ if (!isGuestClosure(closure)) hostFunctionPropertyTables.add(tracked);
8569
8579
  functionProperties.set(closure, tracked);
8570
8580
  return tracked;
8571
8581
  }
@@ -8778,7 +8788,7 @@ function getSandboxPrototype(value, budget) {
8778
8788
  const prototype = errorPrototypes.get(budget)?.get(errorType);
8779
8789
  if (prototype !== void 0) return prototype;
8780
8790
  }
8781
- if (budget !== void 0 && isGuestClosure(value) && runResources.getStore()?.functionSourceText !== false)
8791
+ if (budget !== void 0 && isSandboxClosure(value) && runResources.getStore()?.functionSourceText !== false)
8782
8792
  return functionPrototypes.get(budget) ?? null;
8783
8793
  if (budget !== void 0 && Array.isArray(value)) return arrayPrototypes.get(budget) ?? null;
8784
8794
  if (budget !== void 0 && isSandboxDate(value)) return datePrototypes.get(budget) ?? null;
@@ -8799,16 +8809,13 @@ function hasNullObjectPrototype(value) {
8799
8809
  return prototypes.get(value) === null && !Array.isArray(value) && !isSandboxClosure(value) && !isSandboxRegex(value);
8800
8810
  }
8801
8811
  function getSandboxPropertyDescriptor(value, key, budget) {
8802
- const hostProperties = isSandboxClosure(value) ? value.properties : void 0;
8803
- if (isSandboxClosure(value) && !isGuestClosure(value))
8804
- return hostProperties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(hostProperties, key);
8805
8812
  let current = value;
8806
8813
  let depth = 0;
8807
8814
  while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxGenerator(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
8808
8815
  if (isNumericTypedArray(current) && typeof key !== "symbol" && isTypedArrayIndex(String(key)))
8809
8816
  return Object.getOwnPropertyDescriptor(current, key);
8810
- const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? key === "prototype" && current.construct !== void 0 && current.boundTarget === void 0 ? materializeFunctionProperties(current) : getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
8811
- if (properties === void 0 && isGuestClosure(current) && (key === "name" || key === "length"))
8817
+ const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isSandboxClosure(current) ? key === "prototype" && current.construct !== void 0 && current.boundTarget === void 0 ? materializeFunctionProperties(current) : getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
8818
+ if (properties === void 0 && isSandboxClosure(current) && (key === "name" || key === "length"))
8812
8819
  return {
8813
8820
  value: key === "name" ? current.name ?? "" : current.length ?? 0,
8814
8821
  writable: false,
@@ -8839,12 +8846,9 @@ function getSandboxDataProperty(value, key, budget) {
8839
8846
  if (descriptor !== void 0) return descriptor.value;
8840
8847
  }
8841
8848
  if (isSandboxMap(current) || isSandboxSet(current)) return Object.getOwnPropertyDescriptor(getCollectionProperties(current), key)?.value;
8842
- if (isGuestClosure(current)) {
8849
+ if (isSandboxClosure(current)) {
8843
8850
  const entry = getGuestFunctionProperty(current, key);
8844
8851
  if (entry !== void 0 || Object.hasOwn(current.properties ?? {}, key)) return entry;
8845
- } else if (isSandboxClosure(current)) {
8846
- const properties = current.properties;
8847
- return properties !== void 0 && Object.hasOwn(properties, key) ? properties[key] : void 0;
8848
8852
  }
8849
8853
  if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current))
8850
8854
  return void 0;
@@ -8871,7 +8875,7 @@ function setSandboxPrototype(value, prototype, budget, throwOnFailure = true) {
8871
8875
  if (prototype === null) storePrototype(value, null);
8872
8876
  return true;
8873
8877
  }
8874
- if (!Object.isExtensible(isSandboxGenerator(value) ? getGeneratorProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value)) {
8878
+ if (!Object.isExtensible(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxClosure(value) ? materializeFunctionProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value)) {
8875
8879
  if (!throwOnFailure) return false;
8876
8880
  throw new TypeError("Cannot change the prototype of a non-extensible object.");
8877
8881
  }
@@ -8891,7 +8895,7 @@ function isPrototypeRecord(value) {
8891
8895
  if (isSandboxDataView(value)) return true;
8892
8896
  if (isSandboxArrayBuffer(value)) return true;
8893
8897
  if (isNumericTypedArray(value)) return true;
8894
- if (isGuestClosure(value)) return true;
8898
+ if (isSandboxClosure(value)) return true;
8895
8899
  if (isGuestHostObject(value)) return false;
8896
8900
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxSet(value))
8897
8901
  return false;
@@ -11863,14 +11867,10 @@ function getFunctionMember(target, property, options) {
11863
11867
  let current = target;
11864
11868
  let depth = 0;
11865
11869
  while (current !== null) {
11866
- if (isGuestClosure(current)) {
11870
+ if (isSandboxClosure(current)) {
11867
11871
  const value = getGuestFunctionProperty(current, String(property));
11868
11872
  if (value !== void 0 || Object.hasOwn(current.properties ?? {}, String(property)))
11869
11873
  return value;
11870
- } else if (isSandboxClosure(current)) {
11871
- if (current.properties !== void 0 && Object.hasOwn(current.properties, String(property)))
11872
- return current.properties[String(property)];
11873
- if (property === "length") return current.length;
11874
11874
  } else if (Object.hasOwn(current, String(property))) {
11875
11875
  return current[String(property)];
11876
11876
  }
@@ -14068,11 +14068,8 @@ function hasOwnSandboxProperty(value, key, enumerable) {
14068
14068
  requireReceiver(value);
14069
14069
  if (isGuestHostObject(value)) return typeof key === "symbol" ? false : hasHostObjectMember(value, String(key), enumerable);
14070
14070
  let properties;
14071
- if (isGuestClosure(value)) properties = materializeFunctionProperties(value);
14072
- else if (isSandboxClosure(value)) {
14073
- if (key === "length" || key === "name") return !enumerable;
14074
- properties = value.properties ?? /* @__PURE__ */ Object.create(null);
14075
- } else if (isSandboxMap(value) || isSandboxSet(value)) properties = getCollectionProperties(value);
14071
+ if (isSandboxClosure(value)) properties = materializeFunctionProperties(value);
14072
+ else if (isSandboxMap(value) || isSandboxSet(value)) properties = getCollectionProperties(value);
14076
14073
  else if (isSandboxPromise(value)) properties = getPromiseProperties(value);
14077
14074
  else if (isSandboxGenerator(value)) properties = getGeneratorProperties(value);
14078
14075
  else if (isSandboxRegex(value)) properties = getRegexProperties(value);
@@ -17588,8 +17585,8 @@ async function evaluateForInStatement(node, context) {
17588
17585
  return normalEmptyResult();
17589
17586
  }
17590
17587
  function forInObject(value) {
17591
- if (isGuestClosure(value)) return value;
17592
- if (value === null || value === void 0 || isSandboxClosure(value)) {
17588
+ if (isSandboxClosure(value)) return value;
17589
+ if (value === null || value === void 0) {
17593
17590
  return void 0;
17594
17591
  }
17595
17592
  if (typeof value === "string" || Array.isArray(value) || isNumericTypedArray(value) || isPlainForInObject(value)) {
@@ -19038,7 +19035,7 @@ function toString(value) {
19038
19035
  }
19039
19036
  function isIndexableSandboxValue(value) {
19040
19037
  if (isSandboxDate(value)) return true;
19041
- return Array.isArray(value) || isPlainSandboxObject(value) || isGuestClosure(value);
19038
+ return Array.isArray(value) || isPlainSandboxObject(value) || isSandboxClosure(value);
19042
19039
  }
19043
19040
  function appendArrayValues2(target, values) {
19044
19041
  for (const value of values) {
@@ -19088,7 +19085,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
19088
19085
  if (descriptor2 !== void 0 && !("value" in descriptor2))
19089
19086
  return writePropertyDescriptor(descriptor2, target, value, context);
19090
19087
  }
19091
- if (isGuestClosure(target)) target = materializeFunctionProperties(target);
19088
+ if (isSandboxClosure(target)) target = materializeFunctionProperties(target);
19092
19089
  if (isSandboxPromise(target)) target = getPromiseProperties(target);
19093
19090
  if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
19094
19091
  if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
@@ -19158,7 +19155,7 @@ function setSuperProperty(base, receiver, key, value, context) {
19158
19155
  }
19159
19156
  function deleteSandboxProperty(target, property) {
19160
19157
  if (isGuestHostObject(target)) return deleteHostObjectMember(target, String(property));
19161
- if (isGuestClosure(target)) target = materializeFunctionProperties(target);
19158
+ if (isSandboxClosure(target)) target = materializeFunctionProperties(target);
19162
19159
  if (isSandboxRegex(target)) target = getRegexProperties(target);
19163
19160
  if (isSandboxPromise(target)) target = getPromiseProperties(target);
19164
19161
  if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
@@ -19390,11 +19387,6 @@ async function evaluateObjectSpread(node, context) {
19390
19387
  }
19391
19388
  return { ok: true, value: entries2 };
19392
19389
  }
19393
- if (isSandboxClosure(value.value) && !isGuestClosure(value.value)) {
19394
- throw new TypeError(
19395
- `Cannot spread ${describeObjectSpreadValue(value.value)} into object literal.`
19396
- );
19397
- }
19398
19390
  const keys = ownEnumerableSandboxKeys(value.value, true);
19399
19391
  context.budget.allocateArrayLength(keys.length);
19400
19392
  const entries = [];
@@ -19409,21 +19401,6 @@ async function evaluateObjectSpread(node, context) {
19409
19401
  release();
19410
19402
  }
19411
19403
  }
19412
- function describeObjectSpreadValue(value) {
19413
- if (value === null) {
19414
- return "null";
19415
- }
19416
- if (value === void 0) {
19417
- return "undefined";
19418
- }
19419
- if (isSandboxClosure(value)) {
19420
- return "function";
19421
- }
19422
- if (isSandboxPromise(value)) {
19423
- return "promise";
19424
- }
19425
- return typeof value;
19426
- }
19427
19404
  function defineSandboxProperty(target, key, value) {
19428
19405
  Object.defineProperty(target, key, {
19429
19406
  configurable: true,
@@ -20139,14 +20116,14 @@ function createObjectArrayGlobals(options) {
20139
20116
  call: ([value]) => {
20140
20117
  if (isGuestHostObject(value))
20141
20118
  throw new TypeError("Live host objects cannot be made non-extensible.");
20142
- Object.preventExtensions(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
20119
+ Object.preventExtensions(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
20143
20120
  return value;
20144
20121
  },
20145
20122
  name: "preventExtensions"
20146
20123
  }),
20147
20124
  isExtensible: createSandboxClosure({
20148
20125
  sandbox: true,
20149
- call: ([value]) => Object.isExtensible(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
20126
+ call: ([value]) => Object.isExtensible(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
20150
20127
  name: "isExtensible"
20151
20128
  }),
20152
20129
  seal: createSandboxClosure({
@@ -20154,14 +20131,14 @@ function createObjectArrayGlobals(options) {
20154
20131
  call: ([value]) => {
20155
20132
  if (isGuestHostObject(value))
20156
20133
  throw new TypeError("Live host objects cannot be sealed.");
20157
- Object.seal(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
20134
+ Object.seal(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
20158
20135
  return value;
20159
20136
  },
20160
20137
  name: "seal"
20161
20138
  }),
20162
20139
  isSealed: createSandboxClosure({
20163
20140
  sandbox: true,
20164
- call: ([value]) => Object.isSealed(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
20141
+ call: ([value]) => Object.isSealed(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
20165
20142
  name: "isSealed"
20166
20143
  }),
20167
20144
  freeze: createSandboxClosure({
@@ -20170,7 +20147,7 @@ function createObjectArrayGlobals(options) {
20170
20147
  if (isGuestHostObject(value))
20171
20148
  throw new TypeError("Live host objects cannot be frozen.");
20172
20149
  if (typeof value === "object" && value !== null) {
20173
- Object.freeze(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
20150
+ Object.freeze(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
20174
20151
  }
20175
20152
  return value;
20176
20153
  },
@@ -20178,7 +20155,7 @@ function createObjectArrayGlobals(options) {
20178
20155
  }),
20179
20156
  isFrozen: createSandboxClosure({
20180
20157
  sandbox: true,
20181
- call: ([value]) => Object.isFrozen(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
20158
+ call: ([value]) => Object.isFrozen(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
20182
20159
  name: "isFrozen"
20183
20160
  }),
20184
20161
  assign: createSandboxClosure({
@@ -20561,7 +20538,7 @@ function reflectionProperties(value) {
20561
20538
  value = createSandboxBox(value);
20562
20539
  return objectProperties(value);
20563
20540
  }
20564
- function objectProperties(value, mutable = false) {
20541
+ function objectProperties(value, _mutable = false) {
20565
20542
  if (isSandboxGenerator(value)) return getGeneratorProperties(value);
20566
20543
  if (isSandboxPromise(value)) return getPromiseProperties(value);
20567
20544
  if (isSandboxMap(value) || isSandboxSet(value)) return getCollectionProperties(value);
@@ -20571,11 +20548,7 @@ function objectProperties(value, mutable = false) {
20571
20548
  }
20572
20549
  if (isGuestHostObject(value))
20573
20550
  throw new TypeError("Live host object descriptors are not supported.");
20574
- if (isGuestClosure(value)) return materializeFunctionProperties(value);
20575
- if (isSandboxClosure(value)) {
20576
- if (mutable) throw new TypeError("Host function properties are read only.");
20577
- return value.properties ?? /* @__PURE__ */ Object.create(null);
20578
- }
20551
+ if (isSandboxClosure(value)) return materializeFunctionProperties(value);
20579
20552
  if (!isAssignableSandboxTarget(value))
20580
20553
  throw new TypeError("Expected a sandbox object or function.");
20581
20554
  return value;
@@ -22070,7 +22043,7 @@ function serializeDumpValue(value, path, state) {
22070
22043
  }
22071
22044
  return { kind: "ref", id };
22072
22045
  }
22073
- if (hasGuestObjectState(value) && !isSandboxDataView(value) && !isNumericTypedArray(value) && !(state.trustedRunReplay && (isSandboxDate(value) || isSandboxPromise(value) || isPromiseResolvingFunction(value)))) {
22046
+ if (hasGuestObjectState(value) && !isSandboxDataView(value) && !isNumericTypedArray(value) && !(state.trustedRunReplay && (isSandboxClosure(value) && !isGuestClosure(value) || isSandboxDate(value) || isSandboxPromise(value) || isPromiseResolvingFunction(value)))) {
22074
22047
  throw new TypeError("Guest function properties and prototype links cannot be serialized.");
22075
22048
  }
22076
22049
  if (isSandboxDataView(value) || isSandboxArrayBuffer(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isNumericTypedArray(value)) return serializeHeapReference(value, path, state);
@@ -22738,7 +22711,6 @@ function createConsoleJsonGlobals(options) {
22738
22711
  console: options.hostCalls === void 0 ? {
22739
22712
  error: createSandboxClosure({
22740
22713
  sandbox: true,
22741
- properties: {},
22742
22714
  call: async (args, context) => {
22743
22715
  const operation = options.budget.acquireCompileOwner(
22744
22716
  false,
@@ -22757,7 +22729,6 @@ function createConsoleJsonGlobals(options) {
22757
22729
  }),
22758
22730
  log: createSandboxClosure({
22759
22731
  sandbox: true,
22760
- properties: {},
22761
22732
  call: async (args, context) => {
22762
22733
  const operation = options.budget.acquireCompileOwner(
22763
22734
  false,
@@ -22793,6 +22764,10 @@ function createConsoleJsonGlobals(options) {
22793
22764
  }
22794
22765
  )
22795
22766
  };
22767
+ for (const method of Object.values(globals.console)) {
22768
+ const properties = materializeFunctionProperties(method);
22769
+ hostFunctionMetadata.set(properties, new Map(Object.entries(Object.getOwnPropertyDescriptors(properties))));
22770
+ }
22796
22771
  const jsonMethods = Object.entries(globals.JSON);
22797
22772
  for (const [name] of jsonMethods) {
22798
22773
  Object.defineProperty(globals.JSON, name, { enumerable: false });
@@ -26794,7 +26769,7 @@ function validateSnapshotData(value) {
26794
26769
  dataPropertiesOnly: true
26795
26770
  });
26796
26771
  }
26797
- function validateDumpEnvelope(snapshot) {
26772
+ function validateDumpEnvelope(snapshot, options = {}) {
26798
26773
  const limits = defaultLimits();
26799
26774
  const root = requireRecord(snapshot, "$");
26800
26775
  if (root.version !== 1 && root.version !== DUMP_FORMAT_VERSION) {
@@ -26807,7 +26782,22 @@ function validateDumpEnvelope(snapshot) {
26807
26782
  const reason = requireNonEmptyString(replayError.value, "$.replayError", limits);
26808
26783
  fail("invalidState", "$.replayError", `snapshot is not replayable: ${reason}`);
26809
26784
  }
26785
+ const semanticsDescriptor = Object.getOwnPropertyDescriptor(root, "executionSemantics");
26786
+ if (semanticsDescriptor !== void 0 && !("value" in semanticsDescriptor))
26787
+ fail("invalidType", "$.executionSemantics", "must be a data property");
26788
+ const semantics = semanticsDescriptor?.value;
26789
+ if (options.resume === true && semantics !== EXECUTION_SEMANTICS && semantics !== "jobs-v6" && semantics !== "jobs-v7" && (semantics !== void 0 || ["promiseReplay", "replay", "initialInputs"].some((key) => {
26790
+ const descriptor = Object.getOwnPropertyDescriptor(root, key);
26791
+ return descriptor !== void 0 && (!("value" in descriptor) || descriptor.value !== void 0);
26792
+ }))) {
26793
+ fail(
26794
+ "unsupportedVersion",
26795
+ "$.executionSemantics",
26796
+ "incompatible execution semantics; resume with the SafeJS version that created this snapshot. Migration requires explicit reconciliation, not changing its version marker."
26797
+ );
26798
+ }
26810
26799
  const state = {
26800
+ allowHostFunctionState: inMemoryRunSnapshots.has(root),
26811
26801
  allowFunctions: true,
26812
26802
  allowUndefined: true,
26813
26803
  entries: 0,
@@ -27305,7 +27295,7 @@ function validateArgumentsProperties(record4, path) {
27305
27295
  }
27306
27296
  }
27307
27297
  function validateGenericValue(value, path, depth, state) {
27308
- if (typeof value === "object" && value !== null && hasGuestObjectState(value)) {
27298
+ if (typeof value === "object" && value !== null && hasGuestObjectState(value) && !(state.allowHostFunctionState && isSandboxClosure(value) && !isGuestClosure(value))) {
27309
27299
  fail("invalidState", path, "guest function properties, prototype links and custom descriptors cannot be restored");
27310
27300
  }
27311
27301
  if (state.dataPropertiesOnly && types9.isProxy(value)) {
@@ -29204,18 +29194,14 @@ function createSandboxClosure(input) {
29204
29194
  value: input.cancellationSignal
29205
29195
  });
29206
29196
  }
29207
- if (input.guest === true) {
29208
- registerGuestClosure(closure);
29209
- Object.defineProperty(closure, "properties", {
29210
- get: () => getGuestFunctionProperties(closure)
29211
- });
29212
- } else if (input.properties !== void 0) {
29213
- Object.defineProperty(closure, "properties", {
29214
- enumerable: false,
29215
- value: Object.freeze(
29216
- typeof input.properties === "function" ? input.properties(closure) : input.properties
29217
- )
29218
- });
29197
+ if (input.guest === true) registerGuestClosure(closure);
29198
+ Object.defineProperty(closure, "properties", {
29199
+ get: () => getGuestFunctionProperties(closure)
29200
+ });
29201
+ if (input.guest !== true && input.properties !== void 0) {
29202
+ const properties = typeof input.properties === "function" ? input.properties(closure) : input.properties;
29203
+ const target = materializeFunctionProperties(closure, properties);
29204
+ if (!Object.isExtensible(properties)) Object.preventExtensions(target);
29219
29205
  }
29220
29206
  if (input.retainedValues !== void 0) {
29221
29207
  Object.defineProperty(closure, sandboxRetainedValues, {
@@ -29235,12 +29221,11 @@ function ownEnumerableSandboxEntries(value, excludedKeys) {
29235
29221
  }
29236
29222
  if (value === null || value === void 0) throw new TypeError("Cannot convert undefined or null to object.");
29237
29223
  let entries;
29238
- if (isGuestClosure(value)) entries = Object.entries(value.properties ?? {});
29224
+ if (isSandboxClosure(value)) entries = Object.entries(value.properties ?? {});
29239
29225
  else if (isSandboxRegex(value)) entries = Object.entries(getRegexProperties(value));
29240
29226
  else if (isSandboxPromise(value)) entries = Object.entries(getPromiseProperties(value));
29241
29227
  else if (isSandboxGenerator(value)) entries = Object.entries(getGeneratorProperties(value));
29242
29228
  else if (isSandboxMap(value) || isSandboxSet(value)) entries = Object.entries(getCollectionProperties(value));
29243
- else if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
29244
29229
  else entries = Object.entries(Object(value));
29245
29230
  return excludedKeys === void 0 ? entries : entries.filter(([key]) => !excludedKeys.has(key));
29246
29231
  }
@@ -29261,12 +29246,11 @@ function ownEnumerableSandboxKeys(value, includeSymbols = false) {
29261
29246
  }
29262
29247
  if (isGuestHostObject(value)) return getHostObjectKeys(value);
29263
29248
  if (value === null || value === void 0) throw new TypeError("Cannot convert undefined or null to object.");
29264
- if (isGuestClosure(value)) return Object.keys(value.properties ?? {});
29249
+ if (isSandboxClosure(value)) return Object.keys(value.properties ?? {});
29265
29250
  if (isSandboxPromise(value)) return Object.keys(getPromiseProperties(value));
29266
29251
  if (isSandboxGenerator(value)) return Object.keys(getGeneratorProperties(value));
29267
29252
  if (isSandboxRegex(value)) return Object.keys(getRegexProperties(value));
29268
29253
  if (isSandboxMap(value) || isSandboxSet(value)) return Object.keys(getCollectionProperties(value));
29269
- if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
29270
29254
  return Object.keys(Object(value));
29271
29255
  }
29272
29256
  function createSandboxPromise(promise, metadata = {}) {
@@ -29811,12 +29795,15 @@ function measureSandboxData(values, options = {}) {
29811
29795
  const proxyDescriptors = proxyKeys?.map((key) => Object.getOwnPropertyDescriptor(value, key));
29812
29796
  const includeNonEnumerable = isSandboxDate(value) || isSandboxArrayBuffer(value) || isSandboxDataView(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
29813
29797
  const keys = proxyKeys ?? (includeNonEnumerable ? Object.getOwnPropertyNames(value) : Object.keys(value));
29798
+ const metadata = hostFunctionMetadata.get(value);
29814
29799
  const retained = [];
29815
29800
  for (let index = 0; index < keys.length; index++) {
29816
29801
  const key = keys[index];
29817
29802
  const descriptor = proxyDescriptors === void 0 ? Object.getOwnPropertyDescriptor(value, key) : proxyDescriptors[index];
29818
29803
  if (descriptor === void 0) continue;
29819
29804
  if (!descriptor.enumerable && !includeNonEnumerable) continue;
29805
+ const initial = metadata?.get(key);
29806
+ if (initial !== void 0 && "value" in descriptor && Object.is(initial.value, descriptor.value) && initial.enumerable === descriptor.enumerable && initial.configurable === descriptor.configurable && initial.writable === descriptor.writable) continue;
29820
29807
  usage += 1 + key.length;
29821
29808
  if ("value" in descriptor) retained.push(descriptor.value);
29822
29809
  else for (const closure of retainedAccessorClosures(descriptor)) retained.push(closure);
@@ -30686,7 +30673,7 @@ function encodeReplayData(value, options = {}) {
30686
30673
  if (context.failed) throw new TypeError("Cannot extend an incomplete graph.");
30687
30674
  const { nodes, seen, symbols, float32Buffers } = context;
30688
30675
  const initialNodeCount = nodes.length;
30689
- const encode = (entry, depth, path) => {
30676
+ const encode = (entry, depth, path, capabilityProperties = false) => {
30690
30677
  if (depth > MAX_DATA_DEPTH) throw new TypeError("Replay data exceeds the nesting limit.");
30691
30678
  if (entry === null || typeof entry === "boolean" || typeof entry === "string") return entry;
30692
30679
  if (entry === void 0) return { tag: "undefined" };
@@ -30713,7 +30700,7 @@ function encodeReplayData(value, options = {}) {
30713
30700
  const id2 = options.identifyPromise?.(entry, path);
30714
30701
  if (typeof id2 === "string" && id2.length > 0) return { tag: "promise-capability", id: id2 };
30715
30702
  }
30716
- if (typeof entry === "object" && entry !== null && hasGuestObjectState(entry) && !isSandboxModuleNamespace(entry)) {
30703
+ if (typeof entry === "object" && entry !== null && hasGuestObjectState(entry) && !isSandboxModuleNamespace(entry) && !(!hasExplicitSandboxPrototype(entry) && (capabilityProperties || hostFunctionPropertyTables.has(entry) || isSandboxClosure(entry) && !isGuestClosure(entry)))) {
30717
30704
  throw new MissingReplayCapabilityError("Guest function properties and prototype links cannot be serialized.");
30718
30705
  }
30719
30706
  let capabilityId;
@@ -30741,7 +30728,7 @@ function encodeReplayData(value, options = {}) {
30741
30728
  nodes[id] = {
30742
30729
  kind: "capability",
30743
30730
  id: capabilityId,
30744
- properties: child(entry.properties, "properties")
30731
+ properties: encode(entry.properties, depth + 1, [...path, "properties"], true)
30745
30732
  };
30746
30733
  } else if (isRawJson(entry)) {
30747
30734
  nodes[id] = { kind: "raw-json", text: entry.rawJSON };
@@ -31004,6 +30991,8 @@ function decodeReplayData(input, options = {}, parent) {
31004
30991
  return properties;
31005
30992
  }
31006
30993
  });
30994
+ const metadata = capability.properties === void 0 ? void 0 : hostFunctionMetadata.get(capability.properties);
30995
+ if (copy.properties !== void 0 && metadata !== void 0) hostFunctionMetadata.set(copy.properties, metadata);
31007
30996
  options.onCapabilityRestored?.(capability, copy);
31008
30997
  const moduleFunction = moduleFunctionOrigins.get(capability);
31009
30998
  if (moduleFunction !== void 0) moduleFunctionOrigins.set(copy, moduleFunction);
@@ -33083,7 +33072,8 @@ function wrapCallerInjectedBindings(bindings, options) {
33083
33072
  function wrapCallerInjectedFunction(name, value, options, state) {
33084
33073
  const existing = state.seen.get(value) ?? options.hostCalls?.nativeClosures.get(value);
33085
33074
  if (existing !== void 0) return existing;
33086
- const bindingName = name === "default" && value.name.length > 0 ? value.name : name;
33075
+ const nativeName = name === "default" ? Object.getOwnPropertyDescriptor(value, "name")?.value : void 0;
33076
+ const bindingName = typeof nativeName === "string" && nativeName.length > 0 ? nativeName : name;
33087
33077
  const callable = value;
33088
33078
  return createSandboxClosure({
33089
33079
  ...isAsyncFunction(callable) && !options.realm?.awaitResult(callable) ? { async: true } : {},
@@ -34054,6 +34044,7 @@ function readStringProperty(value, key) {
34054
34044
  }
34055
34045
  function copyFunctionProperties(callable, stackFrames, options, state, path) {
34056
34046
  const properties = {};
34047
+ const metadata = /* @__PURE__ */ new Map();
34057
34048
  for (const key of Object.getOwnPropertyNames(callable)) {
34058
34049
  const descriptor = Object.getOwnPropertyDescriptor(callable, key);
34059
34050
  if (descriptor === void 0) {
@@ -34062,6 +34053,11 @@ function copyFunctionProperties(callable, stackFrames, options, state, path) {
34062
34053
  if ("get" in descriptor || "set" in descriptor) {
34063
34054
  continue;
34064
34055
  }
34056
+ if (key === "name" && typeof descriptor.value === "string" || key === "length" && typeof descriptor.value === "number") {
34057
+ Object.defineProperty(properties, key, descriptor);
34058
+ metadata.set(key, descriptor);
34059
+ continue;
34060
+ }
34065
34061
  if (typeof descriptor.value !== "function") {
34066
34062
  continue;
34067
34063
  }
@@ -34073,7 +34069,8 @@ function copyFunctionProperties(callable, stackFrames, options, state, path) {
34073
34069
  joinPath2(path, key)
34074
34070
  );
34075
34071
  }
34076
- return Object.keys(properties).length > 0 ? properties : void 0;
34072
+ if (metadata.size > 0) hostFunctionMetadata.set(properties, metadata);
34073
+ return Reflect.ownKeys(properties).length > 0 ? properties : void 0;
34077
34074
  }
34078
34075
  function isPlainObject4(value) {
34079
34076
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
@@ -34323,20 +34320,13 @@ var SnapshotMismatchError = class extends Error {
34323
34320
  function restore(snapshot, options, owner) {
34324
34321
  assertSnapshotInactive(snapshot);
34325
34322
  try {
34326
- validateDumpEnvelope(snapshot);
34323
+ validateDumpEnvelope(snapshot, { resume: true });
34327
34324
  } catch (error) {
34328
34325
  if (!(error instanceof SnapshotValidationError) || error.code !== "invalidState" || !inMemoryRunSnapshots.has(snapshot)) throw error;
34329
34326
  snapshot = JSON.parse(serializeSafeJSSnapshot(snapshot));
34330
- validateDumpEnvelope(snapshot);
34327
+ validateDumpEnvelope(snapshot, { resume: true });
34331
34328
  }
34332
34329
  validateSnapshotMigration(snapshot.migration, snapshot.sourceHash, owner);
34333
- if (snapshot.executionSemantics !== EXECUTION_SEMANTICS && snapshot.executionSemantics !== "jobs-v6" && snapshot.executionSemantics !== "jobs-v7" && (snapshot.executionSemantics !== void 0 || snapshot.promiseReplay !== void 0 || snapshot.replay !== void 0 || snapshot.initialInputs !== void 0)) {
34334
- throw new SnapshotValidationError(
34335
- "unsupportedVersion",
34336
- "$.executionSemantics",
34337
- "incompatible execution semantics; resume with the SafeJS version that created this snapshot. Migration requires explicit reconciliation, not changing its version marker."
34338
- );
34339
- }
34340
34330
  const currentSourceHash = hashSource(
34341
34331
  options.source,
34342
34332
  owner,
@@ -46858,6 +46848,10 @@ function prepareReplayInputs(current, saved, preparePromise, onCapabilityRestore
46858
46848
  value = [...value.values][index];
46859
46849
  continue;
46860
46850
  }
46851
+ if (key === "properties" && isSandboxClosure(value)) {
46852
+ value = value.properties;
46853
+ continue;
46854
+ }
46861
46855
  if (value === null || typeof value !== "object") return void 0;
46862
46856
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
46863
46857
  if (descriptor === void 0 || !("value" in descriptor)) return void 0;
@@ -47594,4 +47588,4 @@ export {
47594
47588
  FileSnapshotBackend,
47595
47589
  run
47596
47590
  };
47597
- //# sourceMappingURL=chunk-GL3SJA4W.js.map
47591
+ //# sourceMappingURL=chunk-27FJUX7D.js.map