@poe-platform/safe-js 0.1.353 → 0.1.355

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.
@@ -14647,16 +14647,21 @@ function createFloat32ArrayGlobal(budget, nativePrototype = false) {
14647
14647
  const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
14648
14648
  if (!Number.isSafeInteger(offset) || offset < 0 || offset % 4 !== 0)
14649
14649
  throw new RangeError("Invalid Float32Array buffer offset.");
14650
- const bytes = arrayBufferLength(buffer);
14651
14650
  let length;
14652
- if (args[2] === void 0) {
14651
+ if (args[2] !== void 0) {
14652
+ const size = await sandboxNumber(args[2], budget, context);
14653
+ length = Number.isNaN(size) ? 0 : Math.trunc(size);
14654
+ if (!Number.isSafeInteger(length) || length < 0)
14655
+ throw new RangeError("Invalid Float32Array view length.");
14656
+ }
14657
+ if (arrayBufferDetached(buffer)) throw new TypeError("Cannot construct Float32Array from a detached ArrayBuffer.");
14658
+ const bytes = arrayBufferLength(buffer);
14659
+ if (length === void 0) {
14653
14660
  if (arrayBufferOptions(buffer) === void 0 && bytes % 4 !== 0 || offset > bytes)
14654
14661
  throw new RangeError("Invalid Float32Array buffer length.");
14655
14662
  length = Math.floor((bytes - offset) / 4);
14656
14663
  } else {
14657
- const size = await sandboxNumber(args[2], budget, context);
14658
- length = Number.isNaN(size) ? 0 : Math.trunc(size);
14659
- if (!Number.isSafeInteger(length) || length < 0 || offset + length * 4 > arrayBufferLength(buffer))
14664
+ if (offset + length * 4 > bytes)
14660
14665
  throw new RangeError("Invalid Float32Array view length.");
14661
14666
  }
14662
14667
  budget.allocateArrayLength(length);
@@ -21532,6 +21537,7 @@ function serializeArray(value, serializeValue) {
21532
21537
  // packages/safe-js/src/snapshot/float32array.ts
21533
21538
  function encodeFloat32Layout(value) {
21534
21539
  const storage = float32Storage(value);
21540
+ if (arrayBufferDetached(storage.buffer)) return { byteOffset: 0, length: 0 };
21535
21541
  if (arrayBufferOptions(storage.buffer) === void 0) return { byteOffset: storage.byteOffset, length: storage.length };
21536
21542
  const layout = float32ViewLayouts.get(value);
21537
21543
  if (layout === void 0) throw new TypeError("Resizable Float32Array snapshots require known view layout.");
@@ -21581,9 +21587,16 @@ function encodeArrayBufferStorage(value, id, buffers, reference) {
21581
21587
  arrayBufferLength(value);
21582
21588
  const existing = buffers.get(value);
21583
21589
  if (existing === void 0) buffers.set(value, id);
21584
- return { kind: "arraybuffer", ...existing === void 0 ? { bytes: Array.from(new Uint8Array(value)), ...arrayBufferOptions(value) } : { buffer: reference(existing) } };
21590
+ const detached = arrayBufferDetached(value);
21591
+ return { kind: "arraybuffer", ...existing === void 0 ? {
21592
+ bytes: detached ? [] : Array.from(new Uint8Array(value)),
21593
+ ...arrayBufferOptions(value),
21594
+ ...detached ? { detached: true } : {}
21595
+ } : { buffer: reference(existing) } };
21585
21596
  }
21586
21597
  function validateArrayBufferStorage(value) {
21598
+ if (Object.hasOwn(value, "detached") && (value.detached !== true || !Array.isArray(value.bytes) || value.bytes.length !== 0 || Object.hasOwn(value, "maxByteLength") && value.maxByteLength !== 0))
21599
+ throw new TypeError("Invalid detached ArrayBuffer storage.");
21587
21600
  if (Object.hasOwn(value, "bytes") === Object.hasOwn(value, "buffer"))
21588
21601
  throw new TypeError("ArrayBuffer requires one backing storage description.");
21589
21602
  if (Object.hasOwn(value, "bytes") && (!Array.isArray(value.bytes) || value.bytes.some((byte) => !Number.isInteger(byte) || byte < 0 || byte > 255)))
@@ -21591,7 +21604,7 @@ function validateArrayBufferStorage(value) {
21591
21604
  if (Object.hasOwn(value, "maxByteLength") && (!Array.isArray(value.bytes) || !Number.isSafeInteger(value.maxByteLength) || Number(value.maxByteLength) < value.bytes.length))
21592
21605
  throw new TypeError("Invalid ArrayBuffer maximum length.");
21593
21606
  }
21594
- function decodeArrayBufferStorage(value, resolve, budget) {
21607
+ function decodeArrayBufferStorage(value, resolve, budget, deferredDetachment) {
21595
21608
  validateArrayBufferStorage(value);
21596
21609
  if (Array.isArray(value.bytes)) {
21597
21610
  budget?.allocateArrayLength(Number(value.maxByteLength ?? value.bytes.length));
@@ -21602,6 +21615,15 @@ function decodeArrayBufferStorage(value, resolve, budget) {
21602
21615
  if (Object.hasOwn(value, "maxByteLength") && arrayBufferOptions(buffer)?.maxByteLength !== value.maxByteLength)
21603
21616
  throw new TypeError("Resizable ArrayBuffer restoration is not supported by this host.");
21604
21617
  new Uint8Array(buffer).set(value.bytes);
21618
+ if (value.detached === true) {
21619
+ const detach = () => {
21620
+ budget?.visitNode();
21621
+ structuredClone(buffer, { transfer: [buffer] });
21622
+ if (!arrayBufferDetached(buffer)) throw new TypeError("Restored ArrayBuffer could not be detached.");
21623
+ };
21624
+ if (deferredDetachment === void 0) detach();
21625
+ else deferredDetachment.push(detach);
21626
+ }
21605
21627
  return buffer;
21606
21628
  }
21607
21629
  const referenced = resolve(value.buffer);
@@ -22380,6 +22402,7 @@ function decodeReplayData(input, options = {}, parent) {
22380
22402
  const nodes = list(own(graph, "nodes"));
22381
22403
  const restored = /* @__PURE__ */ new Map();
22382
22404
  const initializeValues = [];
22405
+ const detachBuffers = [];
22383
22406
  const decode = (entry, depth = 0) => {
22384
22407
  if (depth > MAX_DATA_DEPTH) throw new TypeError("Replay data exceeds the nesting limit.");
22385
22408
  if (entry === null || typeof entry === "boolean" || typeof entry === "string") return entry;
@@ -22506,7 +22529,7 @@ function decodeReplayData(input, options = {}, parent) {
22506
22529
  }
22507
22530
  if (kind === "arraybuffer") {
22508
22531
  if (typeof node.extensible !== "boolean") throw new TypeError("Invalid ArrayBuffer extensibility.");
22509
- const result3 = decodeArrayBufferStorage(node, child, compilation.owner?.budget);
22532
+ const result3 = decodeArrayBufferStorage(node, child, compilation.owner?.budget, detachBuffers);
22510
22533
  restored.set(id, result3);
22511
22534
  initializeValues.push(() => {
22512
22535
  defineProperties(result3, record2(own(node, "properties")), child, node.symbolEntries);
@@ -22625,6 +22648,7 @@ function decodeReplayData(input, options = {}, parent) {
22625
22648
  };
22626
22649
  const result = decode(own(graph, "root"));
22627
22650
  for (const initialize of initializeValues) initialize();
22651
+ for (const detach of detachBuffers) detach();
22628
22652
  if (parent !== void 0) compilation.forward(compilation.tickets, parent);
22629
22653
  return result;
22630
22654
  } finally {
@@ -42736,4 +42760,4 @@ export {
42736
42760
  FileSnapshotBackend,
42737
42761
  run
42738
42762
  };
42739
- //# sourceMappingURL=chunk-LZ2NZ2PE.js.map
42763
+ //# sourceMappingURL=chunk-3OJO2L46.js.map