@poe-platform/safe-js 0.1.365 → 0.1.367

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.
@@ -25555,55 +25555,115 @@ function createRegexGlobals(options) {
25555
25555
  return { RegExp: constructor };
25556
25556
  }
25557
25557
 
25558
- // packages/safe-js/src/interp/globals/misc.ts
25559
- function createMiscGlobals(options) {
25560
- return {
25561
- structuredClone: createSandboxClosure({
25562
- sandbox: true,
25563
- call: ([value], context) => structuredCloneSandboxValue(value, options.budget, context?.compilation),
25564
- name: "structuredClone"
25565
- }),
25566
- ...createNumericParsers(options.budget),
25567
- isNaN: createSandboxClosure({
25568
- sandbox: true,
25569
- call: ([value], context) => {
25570
- const number = sandboxNumber(value, options.budget, context);
25571
- return typeof number === "number" ? Number.isNaN(number) : number.then(Number.isNaN);
25572
- },
25573
- name: "isNaN"
25574
- }),
25575
- isFinite: createSandboxClosure({
25576
- sandbox: true,
25577
- call: ([value], context) => {
25578
- const number = sandboxNumber(value, options.budget, context);
25579
- return typeof number === "number" ? Number.isFinite(number) : number.then(Number.isFinite);
25580
- },
25581
- name: "isFinite"
25558
+ // packages/safe-js/src/interp/globals/structured-clone.ts
25559
+ var transferBuffer = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "transfer")?.value;
25560
+ function createStructuredCloneGlobal(budget) {
25561
+ return createSandboxClosure({
25562
+ guest: true,
25563
+ sandbox: true,
25564
+ name: "structuredClone",
25565
+ length: 1,
25566
+ call: (args, context) => {
25567
+ if (args.length === 0) throw new TypeError("structuredClone requires a value argument.");
25568
+ const [value, options] = args;
25569
+ if (options === void 0 || options === null) return cloneStructuredValue(value, [], budget, context);
25570
+ if (typeof options !== "object") throw new TypeError("structuredClone options must be an object.");
25571
+ return cloneWithOptions(value, options, budget, context);
25572
+ }
25573
+ });
25574
+ }
25575
+ async function cloneWithOptions(value, options, budget, context) {
25576
+ const bridge = {
25577
+ ...context,
25578
+ stack: context?.stack ?? [],
25579
+ thisValue: void 0,
25580
+ getProperty: context?.getProperty ?? ((object, key) => {
25581
+ const descriptor = getSandboxPropertyDescriptor(object, key, budget);
25582
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, object, context);
25582
25583
  })
25583
25584
  };
25585
+ let current;
25586
+ let iterator;
25587
+ const items = [];
25588
+ const release = retainValues(budget, () => [value, options, current, items, iterator?.retainedValue]);
25589
+ try {
25590
+ current = await bridge.getProperty(options, "transfer");
25591
+ if (current !== void 0) {
25592
+ if (current === null || typeof current !== "object") throw new TypeError("Transfer list must be an iterable object.");
25593
+ iterator = await acquireSandboxIterator(current, budget, bridge);
25594
+ if (iterator === void 0) throw new TypeError("Transfer list must be iterable.");
25595
+ for (; ; ) {
25596
+ budget.visitNode();
25597
+ const result = await iterator.next();
25598
+ current = result;
25599
+ if ((await readIteratorResult(iterator, result, "done")).value) break;
25600
+ current = (await readIteratorResult(iterator, result, "value")).value;
25601
+ if (current === null || typeof current !== "object") {
25602
+ throw new TypeError("Transfer list elements must be objects.");
25603
+ }
25604
+ budget.allocateArrayLength(items.length + 1);
25605
+ budget.provisionDataUsage(items.length + 2)();
25606
+ items.push(current);
25607
+ }
25608
+ }
25609
+ const seen = /* @__PURE__ */ new Set();
25610
+ const transfers = [];
25611
+ for (const item of items) {
25612
+ budget.visitNode();
25613
+ if (!isSandboxArrayBuffer(item) || seen.has(item))
25614
+ throw new DOMException("Invalid or duplicate transferable.", "DataCloneError");
25615
+ seen.add(item);
25616
+ transfers.push(item);
25617
+ }
25618
+ return cloneStructuredValue(value, transfers, budget, context);
25619
+ } finally {
25620
+ release();
25621
+ }
25584
25622
  }
25585
- function structuredCloneSandboxValue(value, budget, parent) {
25623
+ function cloneStructuredValue(value, transfers, budget, context) {
25624
+ const parent = context?.compilation;
25586
25625
  const operation = budget.acquireCompileOwner(false, parent?.owner);
25587
25626
  const compilation = parent?.owner === operation.owner ? parent : new CompileScope(operation.owner);
25627
+ const buffers = /* @__PURE__ */ new WeakMap();
25628
+ let clone;
25629
+ const release = retainValues(budget, () => [value, clone, transfers]);
25588
25630
  try {
25589
- const clone = cloneSandboxValue(value, { compilation, resetRegexLastIndex: true, structuredClone: true });
25631
+ let transferSize = 0;
25632
+ for (const buffer of transfers) {
25633
+ const length = arrayBufferLength(buffer);
25634
+ budget.allocateArrayLength(arrayBufferOptions(buffer)?.maxByteLength ?? length);
25635
+ transferSize += length + 1;
25636
+ if (arrayBufferDetached(buffer)) buffers.set(buffer, new ArrayBuffer(0));
25637
+ }
25638
+ budget.provisionDataUsage(transferSize)();
25639
+ clone = cloneSandboxValue(value, { compilation, resetRegexLastIndex: true, structuredClone: true, float32Buffers: buffers });
25590
25640
  assertSandboxGraphDepth(clone);
25591
25641
  assertStructuredCloneable(clone, /* @__PURE__ */ new WeakSet());
25592
25642
  allocateProducedSandboxValue(clone, budget);
25593
25643
  if (compilation !== parent) reconcileCompiledValues(budget, [clone], compilation);
25644
+ if (transfers.length > 0) {
25645
+ createDataCheckpoint(budget, context)(clone, 0, true);
25646
+ budget.visitNode(transferSize + transfers.length);
25647
+ budget.provisionDataUsage(transferBuffer === void 0 ? transferSize : transfers.length)();
25648
+ for (const buffer of transfers) {
25649
+ if (arrayBufferDetached(buffer)) throw new DOMException("Cannot transfer a detached ArrayBuffer.", "DataCloneError");
25650
+ if (transferBuffer !== void 0) Reflect.apply(transferBuffer, buffer, [0]);
25651
+ else structuredClone(buffer, { transfer: [buffer] });
25652
+ if (!arrayBufferDetached(buffer)) throw new DOMException("ArrayBuffer cannot be transferred.", "DataCloneError");
25653
+ }
25654
+ }
25594
25655
  return clone;
25595
25656
  } finally {
25657
+ release();
25596
25658
  if (compilation !== parent) compilation.dispose();
25597
25659
  operation.release();
25598
25660
  }
25599
25661
  }
25600
25662
  function assertStructuredCloneable(value, seen) {
25601
- if (isSandboxClosure(value) || isSandboxPromise(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value)) {
25602
- throw new TypeError("structuredClone() cannot clone closures, promises, or collection iterators.");
25603
- }
25604
- if (typeof value !== "object" || value === null || seen.has(value)) {
25605
- return;
25606
- }
25663
+ if (typeof value === "symbol") throw new DOMException("Cannot clone a symbol value.", "DataCloneError");
25664
+ if (isSandboxClosure(value) || isSandboxPromise(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value))
25665
+ throw new DOMException("Cannot clone closures, promises, or collection iterators.", "DataCloneError");
25666
+ if (typeof value !== "object" || value === null || seen.has(value)) return;
25607
25667
  seen.add(value);
25608
25668
  if (isSandboxMap(value)) {
25609
25669
  for (const [key, entry] of value.entries) {
@@ -25613,14 +25673,34 @@ function assertStructuredCloneable(value, seen) {
25613
25673
  return;
25614
25674
  }
25615
25675
  if (isSandboxSet(value)) {
25616
- for (const entry of value.values) {
25617
- assertStructuredCloneable(entry, seen);
25618
- }
25676
+ for (const entry of value.values) assertStructuredCloneable(entry, seen);
25619
25677
  return;
25620
25678
  }
25621
- for (const entry of Object.values(value)) {
25622
- assertStructuredCloneable(entry, seen);
25623
- }
25679
+ for (const entry of Object.values(value)) assertStructuredCloneable(entry, seen);
25680
+ }
25681
+
25682
+ // packages/safe-js/src/interp/globals/misc.ts
25683
+ function createMiscGlobals(options) {
25684
+ return {
25685
+ structuredClone: createStructuredCloneGlobal(options.budget),
25686
+ ...createNumericParsers(options.budget),
25687
+ isNaN: createSandboxClosure({
25688
+ sandbox: true,
25689
+ call: ([value], context) => {
25690
+ const number = sandboxNumber(value, options.budget, context);
25691
+ return typeof number === "number" ? Number.isNaN(number) : number.then(Number.isNaN);
25692
+ },
25693
+ name: "isNaN"
25694
+ }),
25695
+ isFinite: createSandboxClosure({
25696
+ sandbox: true,
25697
+ call: ([value], context) => {
25698
+ const number = sandboxNumber(value, options.budget, context);
25699
+ return typeof number === "number" ? Number.isFinite(number) : number.then(Number.isFinite);
25700
+ },
25701
+ name: "isFinite"
25702
+ })
25703
+ };
25624
25704
  }
25625
25705
 
25626
25706
  // packages/safe-js/src/interp/globals/uri.ts
@@ -25955,7 +26035,7 @@ function createBigIntGlobal(budget) {
25955
26035
 
25956
26036
  // packages/safe-js/src/interp/globals/array-buffer.ts
25957
26037
  var resizeBuffer2 = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize")?.value;
25958
- var transferBuffer = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "transfer")?.value;
26038
+ var transferBuffer2 = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "transfer")?.value;
25959
26039
  function createArrayBufferGlobal(budget) {
25960
26040
  const prototype = /* @__PURE__ */ Object.create(null);
25961
26041
  const constructor = createSandboxClosure({
@@ -26128,9 +26208,9 @@ function createArrayBufferGlobal(budget) {
26128
26208
  const count = Math.min(length, arrayBufferLength(receiver));
26129
26209
  budget.visitNode(count);
26130
26210
  new Uint8Array(result, 0, count).set(new Uint8Array(receiver, 0, count));
26131
- if (transferBuffer !== void 0) {
26211
+ if (transferBuffer2 !== void 0) {
26132
26212
  budget.provisionDataUsage(1)();
26133
- Reflect.apply(transferBuffer, receiver, [0]);
26213
+ Reflect.apply(transferBuffer2, receiver, [0]);
26134
26214
  } else {
26135
26215
  budget.provisionDataUsage(arrayBufferLength(receiver) + 1)();
26136
26216
  budget.visitNode(arrayBufferLength(receiver));
@@ -43423,4 +43503,4 @@ export {
43423
43503
  FileSnapshotBackend,
43424
43504
  run
43425
43505
  };
43426
- //# sourceMappingURL=chunk-NLDDBHDH.js.map
43506
+ //# sourceMappingURL=chunk-2UQ2QDUV.js.map