@poe-platform/safe-js 0.1.373 → 0.1.375

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.
@@ -6887,6 +6887,24 @@ function arrayBufferDataProperties(value) {
6887
6887
  });
6888
6888
  }
6889
6889
 
6890
+ // packages/safe-js/src/interp/float16-array.ts
6891
+ import { Float16Array as PonyfillFloat16Array } from "@petamoriken/float16";
6892
+ var float16BackingViews = /* @__PURE__ */ new WeakMap();
6893
+ var FallbackFloat16Array = class Float16Array extends PonyfillFloat16Array {
6894
+ constructor(input, byteOffset, length) {
6895
+ super(input, byteOffset, length);
6896
+ if (Object.getPrototypeOf(this) !== Float16Array.prototype) return;
6897
+ const buffer = this.buffer;
6898
+ float16BackingViews.set(this, new Uint16Array(
6899
+ buffer,
6900
+ this.byteOffset,
6901
+ input === buffer && length === void 0 ? void 0 : this.length
6902
+ ));
6903
+ }
6904
+ };
6905
+ Object.defineProperty(FallbackFloat16Array, "name", { value: "Float16Array", configurable: true });
6906
+ var Float16Array2 = Object.getOwnPropertyDescriptor(globalThis, "Float16Array")?.value ?? FallbackFloat16Array;
6907
+
6890
6908
  // packages/safe-js/src/interp/typed-array-constructors.ts
6891
6909
  var numericTypedArrayConstructors = {
6892
6910
  Float32Array,
@@ -6899,7 +6917,8 @@ var numericTypedArrayConstructors = {
6899
6917
  Uint32Array,
6900
6918
  Float64Array,
6901
6919
  BigInt64Array,
6902
- BigUint64Array
6920
+ BigUint64Array,
6921
+ Float16Array: Float16Array2
6903
6922
  };
6904
6923
 
6905
6924
  // packages/safe-js/src/interp/typed-array.ts
@@ -6934,23 +6953,27 @@ function restoreTypedArrayView(buffer, byteOffset, length, budget, Native = Floa
6934
6953
  }
6935
6954
  }
6936
6955
  function isNumericTypedArray(value) {
6956
+ if (typeof value === "object" && value !== null && float16BackingViews.has(value))
6957
+ return Object.getPrototypeOf(value) === Float16Array2.prototype;
6937
6958
  if (!ArrayBuffer.isView(value)) return false;
6938
6959
  const tag = Reflect.apply(readTag, value, []);
6939
6960
  return Object.hasOwn(numericTypedArrayConstructors, tag) && Object.getPrototypeOf(value) === numericTypedArrayConstructors[tag].prototype;
6940
6961
  }
6941
6962
  function typedArrayStorage(value, requireInBounds = false) {
6942
- if (requireInBounds) Reflect.apply(createValuesIterator, value, []);
6943
- const buffer = Reflect.apply(readBuffer, value, []);
6963
+ const backingView = float16BackingViews.get(value);
6964
+ const view = backingView ?? value;
6965
+ if (requireInBounds) Reflect.apply(createValuesIterator, view, []);
6966
+ const buffer = Reflect.apply(readBuffer, view, []);
6944
6967
  if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype) {
6945
6968
  throw new TypeError("Float32Array requires a non-shared ArrayBuffer.");
6946
6969
  }
6947
- const Native = numericTypedArrayConstructors[Reflect.apply(readTag, value, [])];
6970
+ const Native = backingView === void 0 ? numericTypedArrayConstructors[Reflect.apply(readTag, value, [])] : Float16Array2;
6948
6971
  return {
6949
6972
  Native,
6950
6973
  elementSize: Native.BYTES_PER_ELEMENT,
6951
6974
  buffer,
6952
- byteOffset: Reflect.apply(readOffset, value, []),
6953
- length: Reflect.apply(readLength2, value, []),
6975
+ byteOffset: Reflect.apply(readOffset, view, []),
6976
+ length: Reflect.apply(readLength2, view, []),
6954
6977
  byteLength: Reflect.apply(bufferLength, buffer, [])
6955
6978
  };
6956
6979
  }
@@ -11375,6 +11398,31 @@ var constructors = /* @__PURE__ */ new WeakMap();
11375
11398
  function hasBigIntContent(Native) {
11376
11399
  return Native === BigInt64Array || Native === BigUint64Array;
11377
11400
  }
11401
+ function copyTypedArrayElements(target, source, offset, budget) {
11402
+ if (!float16BackingViews.has(target) && !float16BackingViews.has(source)) {
11403
+ Reflect.apply(Float32Array.prototype.set, target, [source, offset]);
11404
+ return;
11405
+ }
11406
+ const to = typedArrayStorage(target, true);
11407
+ const from = typedArrayStorage(source, true);
11408
+ if (hasBigIntContent(to.Native) !== hasBigIntContent(from.Native))
11409
+ throw new TypeError("Cannot mix BigInt and Number typed arrays.");
11410
+ if (to.Native === from.Native) {
11411
+ new Uint8Array(to.buffer, to.byteOffset + offset * to.elementSize, from.length * from.elementSize).set(new Uint8Array(from.buffer, from.byteOffset, from.length * from.elementSize));
11412
+ return;
11413
+ }
11414
+ if (to.buffer === from.buffer) {
11415
+ checkTypedArrayAllocation(from.length, budget, from.elementSize);
11416
+ const copy = new from.Native(from.length);
11417
+ const copyStorage = typedArrayStorage(copy);
11418
+ new Uint8Array(copyStorage.buffer).set(new Uint8Array(from.buffer, from.byteOffset, from.length * from.elementSize));
11419
+ source = copy;
11420
+ }
11421
+ for (let index = 0; index < from.length; index++) {
11422
+ budget.visitNode();
11423
+ target[offset + index] = source[index];
11424
+ }
11425
+ }
11378
11426
  function typedArrayElement(value, Native, budget, context) {
11379
11427
  return hasBigIntContent(Native) ? sandboxBigInt(value, budget, context) : sandboxNumber(value, budget, context);
11380
11428
  }
@@ -11493,7 +11541,12 @@ function allocateTypedArray(source, budget, Native) {
11493
11541
  if (Array.isArray(source) || isNumericTypedArray(source)) {
11494
11542
  const length2 = isNumericTypedArray(source) ? typedArrayStorage(source).length : source.length;
11495
11543
  checkTypedArrayAllocation(length2, budget, Native.BYTES_PER_ELEMENT);
11496
- if (isNumericTypedArray(source)) return Reflect.construct(Native, [source]);
11544
+ if (isNumericTypedArray(source)) {
11545
+ typedArrayStorage(source, true);
11546
+ const result2 = new Native(length2);
11547
+ copyTypedArrayElements(result2, source, 0, budget);
11548
+ return result2;
11549
+ }
11497
11550
  const result = new Native(length2);
11498
11551
  for (let index = 0; index < length2; index += 1) {
11499
11552
  budget.visitNode();
@@ -12081,7 +12134,7 @@ function getTypedArrayMember(value, property, budget, bindings) {
12081
12134
  length = Number.isNaN(size) || size <= 0 ? 0 : Math.min(Math.trunc(size), Number.MAX_SAFE_INTEGER);
12082
12135
  }
12083
12136
  if (offset + length > targetStorage.length) throw new RangeError("Float32Array#set source is out of bounds.");
12084
- if (isNumericTypedArray(source)) Reflect.apply(Float32Array.prototype.set, receiver, [source, offset]);
12137
+ if (isNumericTypedArray(source)) copyTypedArrayElements(receiver, source, offset, budget);
12085
12138
  else for (let index = 0; index < length; index++) {
12086
12139
  budget.visitNode();
12087
12140
  current = await bridge.getProperty(sourceObject, String(index));
@@ -26162,7 +26215,7 @@ function createArrayBufferGlobal(budget) {
26162
26215
  sandbox: true,
26163
26216
  name: "isView",
26164
26217
  length: 1,
26165
- call: (args) => ArrayBuffer.isView(args[0])
26218
+ call: (args) => ArrayBuffer.isView(args[0]) || isNumericTypedArray(args[0])
26166
26219
  })
26167
26220
  });
26168
26221
  Object.defineProperties(prototype, {
@@ -28552,8 +28605,13 @@ function measureSandboxData(values, options = {}) {
28552
28605
  if (Array.isArray(value)) {
28553
28606
  usage += value.length;
28554
28607
  if (hasManagedDescriptors(value)) {
28555
- for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
28608
+ const descriptors3 = [];
28609
+ for (const key of Object.getOwnPropertyNames(value)) {
28556
28610
  if (key === "length") continue;
28611
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
28612
+ if (descriptor !== void 0) descriptors3.push([key, descriptor]);
28613
+ }
28614
+ for (const [key, descriptor] of descriptors3) {
28557
28615
  usage += key.length + 1;
28558
28616
  if ("value" in descriptor) visit(descriptor.value, depth + 1);
28559
28617
  else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
@@ -29064,7 +29122,7 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
29064
29122
  if (options.unwrapHostObject === void 0) throw new TypeError("Live capabilities require their owning realm bridge.");
29065
29123
  return options.unwrapHostObject(value);
29066
29124
  }
29067
- if (nodeTypes.isProxy(value)) throw new TypeError("Unsupported proxy sandbox value.");
29125
+ if (nodeTypes.isProxy(value) && !isNumericTypedArray(value)) throw new TypeError("Unsupported proxy sandbox value.");
29068
29126
  if (sandboxErrorTypes.has(value) && hasExplicitSandboxPrototype(value)) {
29069
29127
  const prototype = getSandboxPrototype(value);
29070
29128
  let nativePrototype = null;
@@ -43642,4 +43700,4 @@ export {
43642
43700
  FileSnapshotBackend,
43643
43701
  run
43644
43702
  };
43645
- //# sourceMappingURL=chunk-SCIKHRZS.js.map
43703
+ //# sourceMappingURL=chunk-M22DVZY3.js.map