@poe-platform/safe-js 0.1.394 → 0.1.396

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.
@@ -8165,6 +8165,12 @@ var guestClosures = /* @__PURE__ */ new WeakSet();
8165
8165
  var functionProperties = /* @__PURE__ */ new WeakMap();
8166
8166
  var functionPropertyRevisions = /* @__PURE__ */ new WeakMap();
8167
8167
  var prototypes = /* @__PURE__ */ new WeakMap();
8168
+ var trackedPrototypes = /* @__PURE__ */ new WeakMap();
8169
+ function storePrototype(value, prototype) {
8170
+ prototypes.set(value, prototype);
8171
+ const tracked = trackedPrototypes.get(value);
8172
+ if (tracked !== void 0) tracked.current = prototype;
8173
+ }
8168
8174
  var intrinsicPrototypes = /* @__PURE__ */ new WeakMap();
8169
8175
  var boxedPrototypes = /* @__PURE__ */ new WeakMap();
8170
8176
  var regexPrototypes = /* @__PURE__ */ new WeakMap();
@@ -8249,7 +8255,7 @@ function getGuestFunctionProperty(closure, key) {
8249
8255
  return properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key)?.value;
8250
8256
  }
8251
8257
  function installObjectPrototype(budget, prototype, constructor) {
8252
- prototypes.set(prototype, null);
8258
+ storePrototype(prototype, null);
8253
8259
  intrinsicPrototypes.set(budget, prototype);
8254
8260
  registerIntrinsicPrototype(budget, prototype, constructor);
8255
8261
  }
@@ -8290,7 +8296,7 @@ function installDatePrototype(budget, prototype, constructor) {
8290
8296
  }
8291
8297
  function installArrayPrototype(budget, prototype, constructor) {
8292
8298
  arrayPrototypes.set(budget, prototype);
8293
- prototypes.set(prototype, intrinsicPrototypes.get(budget) ?? null);
8299
+ storePrototype(prototype, intrinsicPrototypes.get(budget) ?? null);
8294
8300
  initialArrayMethods.set(prototype, new Map(Object.entries(Object.getOwnPropertyDescriptors(prototype)).map(([key, descriptor]) => [key, descriptor.value])));
8295
8301
  registerIntrinsicPrototype(budget, prototype, constructor);
8296
8302
  }
@@ -8338,12 +8344,20 @@ function trackIntrinsicState(budget, root, owner, targets) {
8338
8344
  let roots = intrinsicPrototypeRoots.get(budget);
8339
8345
  if (roots === void 0) intrinsicPrototypeRoots.set(budget, roots = /* @__PURE__ */ new Set());
8340
8346
  roots.add(root);
8341
- const records = [...new Set(targets)].map((target) => ({
8342
- target,
8343
- value: isGuestClosure(target) ? materializeFunctionProperties(target) : target,
8344
- prototype: getSandboxPrototype(target),
8345
- explicit: hasExplicitSandboxPrototype(target)
8346
- })).map((record4) => ({
8347
+ const records = [...new Set(targets)].map((target) => {
8348
+ let tracked = trackedPrototypes.get(target);
8349
+ if (tracked === void 0) {
8350
+ tracked = { current: getSandboxPrototype(target) };
8351
+ trackedPrototypes.set(target, tracked);
8352
+ }
8353
+ return {
8354
+ target,
8355
+ value: isGuestClosure(target) ? materializeFunctionProperties(target) : target,
8356
+ prototype: tracked.current,
8357
+ tracked,
8358
+ explicit: hasExplicitSandboxPrototype(target)
8359
+ };
8360
+ }).map((record4) => ({
8347
8361
  ...record4,
8348
8362
  revision: functionPropertyRevisions.get(record4.value),
8349
8363
  capturedRevision: -1,
@@ -8364,8 +8378,8 @@ function trackIntrinsicState(budget, root, owner, targets) {
8364
8378
  budget.setRetainedValues(root, () => {
8365
8379
  const retained = [];
8366
8380
  for (const record4 of records) {
8367
- const { target, value, descriptors: descriptors2, prototype: parent, revision } = record4;
8368
- const currentPrototype = getSandboxPrototype(target);
8381
+ const { value, descriptors: descriptors2, prototype: parent, revision } = record4;
8382
+ const currentPrototype = record4.tracked.current;
8369
8383
  if (currentPrototype !== parent) retained.push(currentPrototype);
8370
8384
  if (revision === void 0 || revision.revision !== record4.capturedRevision) {
8371
8385
  const captured = [];
@@ -8503,7 +8517,7 @@ function setSandboxPrototype(value, prototype, budget, throwOnFailure = true) {
8503
8517
  );
8504
8518
  }
8505
8519
  if (getSandboxPrototype(value, budget) === prototype) {
8506
- if (prototype === null) prototypes.set(value, null);
8520
+ if (prototype === null) storePrototype(value, null);
8507
8521
  return true;
8508
8522
  }
8509
8523
  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)) {
@@ -8519,7 +8533,7 @@ function setSandboxPrototype(value, prototype, budget, throwOnFailure = true) {
8519
8533
  throw new TypeError("Cyclic prototype value.");
8520
8534
  }
8521
8535
  }
8522
- prototypes.set(value, prototype);
8536
+ storePrototype(value, prototype);
8523
8537
  return true;
8524
8538
  }
8525
8539
  function isPrototypeRecord(value) {
@@ -22145,6 +22159,9 @@ function isPromiseLike2(value) {
22145
22159
  return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function" && !isSandboxClosure(value) && !isSandboxPromise(value);
22146
22160
  }
22147
22161
 
22162
+ // packages/safe-js/src/interp/symbol-registry.ts
22163
+ var symbolRegistryOrigins = /* @__PURE__ */ new WeakMap();
22164
+
22148
22165
  // packages/safe-js/src/snapshot/property-descriptors.ts
22149
22166
  function serializePropertyDescriptors(target, encode) {
22150
22167
  return {
@@ -22312,7 +22329,13 @@ function captureGuestHeapNode(value, encode) {
22312
22329
  const intrinsic = getIntrinsicIdentity(value);
22313
22330
  if (intrinsic !== void 0) {
22314
22331
  const state2 = captureObjectState(value, encode);
22315
- return { kind: "intrinsic", id: intrinsic, ...state2 === void 0 ? {} : { state: state2 } };
22332
+ const registry = isSandboxClosure(value) ? symbolRegistryOrigins.get(value) : void 0;
22333
+ return {
22334
+ kind: "intrinsic",
22335
+ id: intrinsic,
22336
+ ...state2 === void 0 ? {} : { state: state2 },
22337
+ ...registry === void 0 ? {} : { symbolRegistry: [...registry].map(([key, symbol]) => [key, encode(symbol)]) }
22338
+ };
22316
22339
  }
22317
22340
  const bound = boundFunctionStates.get(value);
22318
22341
  if (bound !== void 0 && isSandboxClosure(value)) {
@@ -27093,8 +27116,10 @@ function createSymbolGlobal(budget) {
27093
27116
  })
27094
27117
  };
27095
27118
  for (const [name, method] of Object.entries(methods2)) {
27119
+ symbolRegistryOrigins.set(method, entries);
27096
27120
  Object.defineProperty(properties, name, { value: method, writable: true, configurable: true });
27097
27121
  }
27122
+ symbolRegistryOrigins.set(constructor, entries);
27098
27123
  for (const [name, value] of Object.entries(wellKnownSymbols)) {
27099
27124
  Object.defineProperty(properties, name, { value });
27100
27125
  }
@@ -27832,8 +27857,23 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
27832
27857
  if (iterator.kind === "symbol" || iterator.kind === "scope-frame") throw new TypeError("Invalid wrapped iterator.");
27833
27858
  state(node.state);
27834
27859
  } else if (node.kind === "intrinsic") {
27835
- fields(node, ["kind", "id"], ["state"]);
27860
+ fields(node, ["kind", "id"], ["state", "symbolRegistry"]);
27836
27861
  if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
27862
+ if (Object.hasOwn(node, "symbolRegistry")) {
27863
+ if (![JSON.stringify(["Symbol"]), JSON.stringify(["Symbol", "for"]), JSON.stringify(["Symbol", "keyFor"])].includes(node.id) || !Array.isArray(node.symbolRegistry))
27864
+ throw new TypeError("Invalid symbol registry owner.");
27865
+ const keys = /* @__PURE__ */ new Set();
27866
+ const symbols = /* @__PURE__ */ new Set();
27867
+ for (const entry of node.symbolRegistry) {
27868
+ if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string" || keys.has(entry[0]))
27869
+ throw new TypeError("Invalid symbol registry entry.");
27870
+ const symbol = reference(entry[1], ["symbol"]);
27871
+ if (symbol.wellKnown !== void 0 || symbol.description !== entry[0] || symbols.has(symbol))
27872
+ throw new TypeError("Invalid registered symbol identity.");
27873
+ keys.add(entry[0]);
27874
+ symbols.add(symbol);
27875
+ }
27876
+ }
27837
27877
  if (Object.hasOwn(node, "state")) state(node.state);
27838
27878
  } else if (node.kind === "guest-regexp-iterator") {
27839
27879
  fields(node, ["kind", "matcher", "input", "exhausted", "state"], ["global", "unicode"]);
@@ -45001,4 +45041,4 @@ export {
45001
45041
  FileSnapshotBackend,
45002
45042
  run
45003
45043
  };
45004
- //# sourceMappingURL=chunk-XVBBWKP2.js.map
45044
+ //# sourceMappingURL=chunk-BVKIA2LQ.js.map