@poe-platform/safe-js 0.1.379 → 0.1.380

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.
@@ -9754,8 +9754,8 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9754
9754
  if (!asyncProtocol) return getSandboxIterator(value, budget, context);
9755
9755
  if (isSandboxGenerator(value) && value.async && !hasExplicitSandboxPrototype(value))
9756
9756
  return getSandboxAsyncIterator(value, budget, context, signal);
9757
- const iterator2 = await acquireSandboxIterator(value, budget, context);
9758
- return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal, context);
9757
+ const iterator = await acquireSandboxIterator(value, budget, context);
9758
+ return iterator === void 0 ? void 0 : asyncFromSyncIterator(iterator, budget, signal, context);
9759
9759
  }
9760
9760
  const factory = await context.getProperty(value, key);
9761
9761
  if (!asyncProtocol && factory === void 0 && Array.isArray(value) && !hasExplicitSandboxPrototype(value)) {
@@ -9763,13 +9763,16 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9763
9763
  if (typeof installed === "object" && installed !== null && getIntrinsicIdentity(installed) === JSON.stringify(["Array", "prototype", "values"]))
9764
9764
  return arrayIterator(value, context, budget);
9765
9765
  }
9766
- if (!asyncProtocol && (isSandboxMap(value) || isSandboxSet(value)) && typeof factory === "object" && factory !== null && getIntrinsicIdentity(factory) === JSON.stringify(isSandboxMap(value) ? ["Map", "prototype", "entries"] : ["Set", "prototype", "values"])) {
9767
- return getSandboxIterator(value, budget, context);
9768
- }
9769
9766
  if (factory === null || factory === void 0) {
9770
9767
  if (!asyncProtocol) return void 0;
9771
- const iterator2 = await acquireSandboxIterator(value, budget, context);
9772
- return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal, context);
9768
+ const iterator = await acquireSandboxIterator(value, budget, context);
9769
+ return iterator === void 0 ? void 0 : asyncFromSyncIterator(iterator, budget, signal, context);
9770
+ }
9771
+ return getSandboxIteratorFromMethod(value, factory, budget, context, asyncProtocol, signal);
9772
+ }
9773
+ async function getSandboxIteratorFromMethod(value, factory, budget, context, asyncProtocol = false, signal) {
9774
+ if (!asyncProtocol && (isSandboxMap(value) || isSandboxSet(value)) && typeof factory === "object" && factory !== null && getIntrinsicIdentity(factory) === JSON.stringify(isSandboxMap(value) ? ["Map", "prototype", "entries"] : ["Set", "prototype", "values"])) {
9775
+ return getSandboxIterator(value, budget, context);
9773
9776
  }
9774
9777
  if (!isSandboxClosure(factory)) {
9775
9778
  if (typeof factory !== "function") throw new TypeError("Iterator method must be callable.");
@@ -15266,7 +15269,12 @@ async function arrayFromSandboxValues(args, budget, context) {
15266
15269
  throw new TypeError("Array.from requires a non-null input.");
15267
15270
  }
15268
15271
  const read = (property) => context?.getProperty !== void 0 ? context.getProperty(items, property) : getSandboxDataProperty(items, property, budget);
15269
- const iterator = context === void 0 ? getSandboxIterator(items, budget) : await acquireSandboxIterator(items, budget, context);
15272
+ const observableMethod = context?.getProperty !== void 0 && !isGuestHostObject(items) && getSandboxPropertyDescriptor(typeof items === "object" ? items : getBoxedPrototype(items, budget), Symbol.iterator, budget) !== void 0;
15273
+ const iteratorMethod = observableMethod ? await context.getProperty(items, Symbol.iterator) : void 0;
15274
+ if (iteratorMethod !== null && iteratorMethod !== void 0 && !isSandboxClosure(iteratorMethod) && typeof iteratorMethod !== "function")
15275
+ throw new TypeError("Iterator method must be callable.");
15276
+ let iterator = observableMethod ? void 0 : context === void 0 ? getSandboxIterator(items, budget) : await acquireSandboxIterator(items, budget, context);
15277
+ const iterable = observableMethod ? iteratorMethod !== null && iteratorMethod !== void 0 : iterator !== void 0;
15270
15278
  const constructor = context?.thisValue;
15271
15279
  let result;
15272
15280
  let currentValue;
@@ -15274,6 +15282,7 @@ async function arrayFromSandboxValues(args, budget, context) {
15274
15282
  const retained = {};
15275
15283
  budget.setRetainedValues(retained, () => [
15276
15284
  items,
15285
+ iteratorMethod,
15277
15286
  iterator?.retainedValue,
15278
15287
  mapFn,
15279
15288
  constructor,
@@ -15293,19 +15302,21 @@ async function arrayFromSandboxValues(args, budget, context) {
15293
15302
  };
15294
15303
  try {
15295
15304
  let length = 0;
15296
- if (iterator === void 0) {
15305
+ if (!iterable) {
15297
15306
  const number = await sandboxNumber(await read("length"), budget, context);
15298
15307
  length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
15299
15308
  }
15300
15309
  result = isSandboxClosure(constructor) && constructor.construct !== void 0 ? await invokeBuiltinClosure(
15301
15310
  constructor,
15302
- iterator === void 0 ? [length] : [],
15311
+ iterable ? [] : [length],
15303
15312
  budget,
15304
15313
  context,
15305
15314
  void 0,
15306
15315
  true
15307
15316
  ) : createArrayFromConstructorArgs([length], budget);
15308
15317
  checkData(result, 0, true);
15318
+ if (observableMethod && iterable)
15319
+ iterator = await getSandboxIteratorFromMethod(items, iteratorMethod, budget, context);
15309
15320
  let index = 0;
15310
15321
  while (iterator !== void 0 || index < length) {
15311
15322
  try {
@@ -22177,6 +22188,14 @@ function serializeArray(value, serializeValue) {
22177
22188
  }
22178
22189
 
22179
22190
  // packages/safe-js/src/snapshot/typed-array.ts
22191
+ function captureTypedArrayState(value, encode) {
22192
+ const metadata = Object.defineProperties(/* @__PURE__ */ Object.create(null), Object.fromEntries(typedArrayProperties(value)));
22193
+ if (!Object.isExtensible(value)) Object.preventExtensions(metadata);
22194
+ return {
22195
+ properties: serializePropertyDescriptors(metadata, encode),
22196
+ ...hasExplicitSandboxPrototype(value) ? { prototype: encode(getSandboxPrototype(value)) } : {}
22197
+ };
22198
+ }
22180
22199
  function encodeTypedArrayLayout(value) {
22181
22200
  const storage = typedArrayStorage(value);
22182
22201
  const identity = storage.Native === Float32Array ? { kind: "float32array" } : { kind: "typedarray", arrayType: storage.Native.name };
@@ -22444,7 +22463,7 @@ function serializeDumpValue(value, path, state) {
22444
22463
  }
22445
22464
  return { kind: "ref", id };
22446
22465
  }
22447
- if (hasGuestObjectState(value) && !isSandboxDataView(value) && !(state.trustedRunReplay && (isSandboxDate(value) || isSandboxPromise(value) || isPromiseResolvingFunction(value)))) {
22466
+ if (hasGuestObjectState(value) && !isSandboxDataView(value) && !isNumericTypedArray(value) && !(state.trustedRunReplay && (isSandboxDate(value) || isSandboxPromise(value) || isPromiseResolvingFunction(value)))) {
22448
22467
  throw new TypeError("Guest function properties and prototype links cannot be serialized.");
22449
22468
  }
22450
22469
  if (isSandboxDataView(value) || isSandboxArrayBuffer(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isNumericTypedArray(value)) return serializeHeapReference(value, path, state);
@@ -22545,12 +22564,17 @@ function serializeHeapReference(value, path, state) {
22545
22564
  ...encodeTypedArrayLayout(value),
22546
22565
  buffer: serializeHeapReference(backing.buffer, `${path}.buffer`, state)
22547
22566
  };
22548
- const entries = /* @__PURE__ */ Object.create(null);
22549
- state.heap[String(id)] = { ...storage, entries };
22550
- for (const [key, descriptor] of typedArrayDataProperties(value)) {
22551
- const serialized = serializeDumpValue(descriptor.value, `${path}.${key}`, state);
22552
- entries[key] = serialized === SKIP_VALUE ? { kind: "undefined" } : serialized;
22553
- }
22567
+ state.heap[String(id)] = {
22568
+ ...storage,
22569
+ entries: {},
22570
+ state: captureTypedArrayState(value, (entry) => {
22571
+ if (entry === void 0) return { kind: "undefined" };
22572
+ if (Object.is(entry, -0)) return { kind: "number", value: "-0" };
22573
+ const serialized = serializeDumpValue(entry, `${path}.<typed-array>`, state);
22574
+ if (serialized === SKIP_VALUE) throw new TypeError("Unsupported typed array property in public dump.");
22575
+ return serialized;
22576
+ })
22577
+ };
22554
22578
  } else if (isSandboxArguments(value)) {
22555
22579
  state.heap[String(id)] = serializeArguments(value, (entry, key) => {
22556
22580
  const serialized = serializeDumpValue(entry, `${path}.${key}`, state);
@@ -22647,6 +22671,9 @@ function collectContainerStats(value, stats, ancestors, guestValues, depth = 0)
22647
22671
  const guest = isSandboxDataView(value) ? { kind: "dataview", state: captureDataViewState(value, (entry) => {
22648
22672
  guestEntries.push(entry);
22649
22673
  return null;
22674
+ }) } : isNumericTypedArray(value) ? { kind: "typedarray", state: captureTypedArrayState(value, (entry) => {
22675
+ guestEntries.push(entry);
22676
+ return null;
22650
22677
  }) } : isSandboxArrayBuffer(value) ? { kind: "arraybuffer", state: captureArrayBufferState(value, (entry) => {
22651
22678
  guestEntries.push(entry);
22652
22679
  return null;
@@ -22655,7 +22682,7 @@ function collectContainerStats(value, stats, ancestors, guestValues, depth = 0)
22655
22682
  return null;
22656
22683
  });
22657
22684
  if (guest !== void 0) {
22658
- if (!isSandboxArrayBuffer(value) && !isSandboxDataView(value)) guestValues.add(value);
22685
+ if (!isSandboxArrayBuffer(value) && !isSandboxDataView(value) && !isNumericTypedArray(value)) guestValues.add(value);
22659
22686
  for (const entry of guestEntries) {
22660
22687
  collectContainerStats(entry, stats, ancestors, guestValues, depth + 1);
22661
22688
  if (entry !== null && typeof entry === "object") stats.get(entry).forceHeap = true;
@@ -43956,4 +43983,4 @@ export {
43956
43983
  FileSnapshotBackend,
43957
43984
  run
43958
43985
  };
43959
- //# sourceMappingURL=chunk-L3DPV6WY.js.map
43986
+ //# sourceMappingURL=chunk-DYT6M5F7.js.map