@poe-platform/safe-js 0.1.392 → 0.1.393

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.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-GYLSKXNZ.js";
30
+ } from "./chunk-UDQ7HBDC.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8249,4 +8249,4 @@ export {
8249
8249
  parseMcpConfig,
8250
8250
  makeMcpModule
8251
8251
  };
8252
- //# sourceMappingURL=chunk-VN2F4GHQ.js.map
8252
+ //# sourceMappingURL=chunk-CTMJJJQL.js.map
@@ -8792,6 +8792,9 @@ async function flushPromiseJobs() {
8792
8792
  }
8793
8793
  }
8794
8794
 
8795
+ // packages/safe-js/src/interp/promise-state.ts
8796
+ var promiseStates = /* @__PURE__ */ new WeakMap();
8797
+
8795
8798
  // packages/safe-js/src/interp/promise-replay.ts
8796
8799
  import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
8797
8800
 
@@ -22239,6 +22242,12 @@ function serializeCollectionProperties(value, encode, dataOnly = false) {
22239
22242
 
22240
22243
  // packages/safe-js/src/snapshot/guest-heap.ts
22241
22244
  function captureGuestHeapNode(value, encode) {
22245
+ if (isSandboxPromise(value)) {
22246
+ const settlement = promiseStates.get(value);
22247
+ if (settlement !== void 0 && settlement.status !== "pending")
22248
+ return { kind: "guest-promise", status: settlement.status, value: encode(settlement.value), state: captureObjectState(value, encode) };
22249
+ return void 0;
22250
+ }
22242
22251
  if (hasGuestObjectState(value) || privateElements.has(value)) {
22243
22252
  if (isSandboxRegex(value)) return { kind: "guest-regex", source: value.source, flags: value.flags, state: captureObjectState(value, encode) };
22244
22253
  if (isSandboxBox(value)) return { kind: "guest-boxed", value: encode(boxedValue(value)), state: captureObjectState(value, encode) };
@@ -22501,6 +22510,7 @@ function captureGuestHeapNode(value, encode) {
22501
22510
  function captureObjectState(value, encode) {
22502
22511
  let properties = value;
22503
22512
  if (isSandboxRegex(value)) properties = getRegexProperties(value);
22513
+ if (isSandboxPromise(value)) properties = getPromiseProperties(value);
22504
22514
  if (isSandboxGenerator(value)) properties = getGeneratorProperties(value);
22505
22515
  if (isSandboxClosure(value)) {
22506
22516
  properties = value.properties;
@@ -27681,7 +27691,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
27681
27691
  createRawJson(node.text);
27682
27692
  return true;
27683
27693
  }
27684
- if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "guest-boxed", "guest-date", "guest-regex", "array-iterator", "string-iterator", "iterator-wrapper", "iterator-helper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
27694
+ if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "guest-boxed", "guest-date", "guest-regex", "guest-promise", "array-iterator", "string-iterator", "iterator-wrapper", "iterator-helper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
27685
27695
  const reference = (value, kinds) => {
27686
27696
  const ref = record3(value);
27687
27697
  fields(ref, ["kind", "id"]);
@@ -27762,7 +27772,13 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
27762
27772
  });
27763
27773
  return false;
27764
27774
  }
27765
- if (node.kind === "guest-regex") {
27775
+ if (node.kind === "guest-promise") {
27776
+ fields(node, ["kind", "status", "value", "state"]);
27777
+ if (node.status !== "fulfilled" && node.status !== "rejected") throw new TypeError("Invalid guest promise settlement.");
27778
+ if (node.status === "fulfilled" && node.value !== null && typeof node.value === "object" && record3(node.value).kind === "ref" && reference(node.value) === node)
27779
+ throw new TypeError("A promise cannot fulfill with itself.");
27780
+ state(node.state);
27781
+ } else if (node.kind === "guest-regex") {
27766
27782
  fields(node, ["kind", "source", "flags", "state"]);
27767
27783
  if (typeof node.source !== "string" || typeof node.flags !== "string") throw new TypeError("Invalid guest RegExp payload.");
27768
27784
  state(node.state);
@@ -29546,6 +29562,15 @@ function createSandboxPromise(promise, metadata = {}) {
29546
29562
  value: metadata.hostCallJournal
29547
29563
  });
29548
29564
  }
29565
+ promiseStates.set(sandboxPromise, { status: "pending" });
29566
+ original.then(
29567
+ (value) => {
29568
+ promiseStates.set(sandboxPromise, { status: "fulfilled", value });
29569
+ },
29570
+ (value) => {
29571
+ promiseStates.set(sandboxPromise, { status: "rejected", value });
29572
+ }
29573
+ );
29549
29574
  trackSandboxPromise(sandboxPromise);
29550
29575
  registerPromiseCancellation(sandboxPromise);
29551
29576
  return Object.freeze(sandboxPromise);
@@ -29947,6 +29972,8 @@ function measureSandboxData(values, options = {}) {
29947
29972
  return;
29948
29973
  }
29949
29974
  if (isSandboxPromise(value)) {
29975
+ const settlement = promiseStates.get(value);
29976
+ if (settlement !== void 0 && settlement.status !== "pending") visit(settlement.value, depth + 1);
29950
29977
  for (const key of Reflect.ownKeys(getPromiseProperties(value))) {
29951
29978
  const descriptor = Object.getOwnPropertyDescriptor(getPromiseProperties(value), key);
29952
29979
  usage += typeof key === "string" ? key.length + 1 : 1;
@@ -44962,4 +44989,4 @@ export {
44962
44989
  FileSnapshotBackend,
44963
44990
  run
44964
44991
  };
44965
- //# sourceMappingURL=chunk-GYLSKXNZ.js.map
44992
+ //# sourceMappingURL=chunk-UDQ7HBDC.js.map