@poe-platform/safe-js 0.1.360 → 0.1.362

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.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-RHEDM44A.js";
30
+ } from "./chunk-QMF5YOGC.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8249,4 +8249,4 @@ export {
8249
8249
  parseMcpConfig,
8250
8250
  makeMcpModule
8251
8251
  };
8252
- //# sourceMappingURL=chunk-JFOSC26Y.js.map
8252
+ //# sourceMappingURL=chunk-EF6FLPF6.js.map
@@ -14638,6 +14638,96 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
14638
14638
  }
14639
14639
  }
14640
14640
 
14641
+ // packages/safe-js/src/interp/globals/uint8-hex.ts
14642
+ var hexDigits = "0123456789abcdef";
14643
+ function installUint8Hex(budget, constructor, prototype) {
14644
+ const fromHex = createSandboxClosure({
14645
+ guest: true,
14646
+ sandbox: true,
14647
+ name: "fromHex",
14648
+ length: 1,
14649
+ call: ([text]) => {
14650
+ if (typeof text !== "string") throw new TypeError("Hex input must be a string.");
14651
+ if (text.length % 2 !== 0) throw new SyntaxError("Hex input must have an even length.");
14652
+ checkTypedArrayAllocation(text.length / 2, budget, 1);
14653
+ const value = new Uint8Array(text.length / 2);
14654
+ decodeHexInto(text, value, budget);
14655
+ setSandboxPrototype(value, prototype, budget);
14656
+ return value;
14657
+ }
14658
+ });
14659
+ Object.defineProperty(materializeFunctionProperties(constructor), "fromHex", {
14660
+ value: fromHex,
14661
+ writable: true,
14662
+ configurable: true
14663
+ });
14664
+ registerIntrinsicFunction(budget, fromHex);
14665
+ Object.defineProperties(prototype, {
14666
+ toHex: {
14667
+ writable: true,
14668
+ configurable: true,
14669
+ value: createSandboxClosure({
14670
+ guest: true,
14671
+ sandbox: true,
14672
+ name: "toHex",
14673
+ length: 0,
14674
+ call: (_args, context) => {
14675
+ const value = uint8Receiver(context?.thisValue);
14676
+ const { length } = typedArrayStorage(value, true);
14677
+ budget.provisionDataUsage(length * 2)();
14678
+ let result = "";
14679
+ for (let index = 0; index < length; index++) {
14680
+ budget.visitNode();
14681
+ const byte = value[index];
14682
+ result = budget.allocateString(result + hexDigits[byte >> 4] + hexDigits[byte & 15]);
14683
+ }
14684
+ return result;
14685
+ }
14686
+ })
14687
+ },
14688
+ setFromHex: {
14689
+ writable: true,
14690
+ configurable: true,
14691
+ value: createSandboxClosure({
14692
+ guest: true,
14693
+ sandbox: true,
14694
+ name: "setFromHex",
14695
+ length: 1,
14696
+ call: ([text], context) => {
14697
+ const value = uint8Receiver(context?.thisValue);
14698
+ if (typeof text !== "string") throw new TypeError("Hex input must be a string.");
14699
+ typedArrayStorage(value, true);
14700
+ const written = decodeHexInto(text, value, budget);
14701
+ return { read: written * 2, written };
14702
+ }
14703
+ })
14704
+ }
14705
+ });
14706
+ }
14707
+ function uint8Receiver(value) {
14708
+ if (!isNumericTypedArray(value) || typedArrayStorage(value).Native !== Uint8Array)
14709
+ throw new TypeError("Hex conversion requires a Uint8Array receiver.");
14710
+ return value;
14711
+ }
14712
+ function decodeHexInto(text, value, budget) {
14713
+ if (text.length % 2 !== 0) throw new SyntaxError("Hex input must have an even length.");
14714
+ const length = Math.min(text.length / 2, typedArrayStorage(value).length);
14715
+ for (let index = 0; index < length; index++) {
14716
+ budget.visitNode();
14717
+ const high = hexNibble(text.charCodeAt(index * 2));
14718
+ const low = hexNibble(text.charCodeAt(index * 2 + 1));
14719
+ if (high < 0 || low < 0) throw new SyntaxError("Invalid hexadecimal digit.");
14720
+ value[index] = high * 16 + low;
14721
+ }
14722
+ return length;
14723
+ }
14724
+ function hexNibble(code) {
14725
+ if (code >= 48 && code <= 57) return code - 48;
14726
+ if (code >= 65 && code <= 70) return code - 55;
14727
+ if (code >= 97 && code <= 102) return code - 87;
14728
+ return -1;
14729
+ }
14730
+
14641
14731
  // packages/safe-js/src/interp/globals/numeric-typed-array.ts
14642
14732
  var constructors = /* @__PURE__ */ new WeakMap();
14643
14733
  function createNumericTypedArrayGlobal(budget, nativePrototype = false, Native = Float32Array) {
@@ -14903,8 +14993,11 @@ function createNumericTypedArrayPrototypes(budget, bindings) {
14903
14993
  setSandboxPrototype(constructor, typedArray);
14904
14994
  setSandboxPrototype(prototype, shared);
14905
14995
  prototypes2.set(Native, prototype);
14906
- registerIntrinsicFunction(budget, constructor);
14907
- registerIntrinsicObject(budget, prototype);
14996
+ }
14997
+ installUint8Hex(budget, bindings.Uint8Array, prototypes2.get(Uint8Array));
14998
+ for (const [name, Native] of Object.entries(numericTypedArrayConstructors)) {
14999
+ registerIntrinsicFunction(budget, bindings[name]);
15000
+ registerIntrinsicObject(budget, prototypes2.get(Native));
14908
15001
  }
14909
15002
  Object.defineProperty(shared, "constructor", { value: typedArray, writable: true, configurable: true });
14910
15003
  setSandboxPrototype(shared, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
@@ -19703,6 +19796,7 @@ function typeTag(value, builtinOnly = false) {
19703
19796
 
19704
19797
  // packages/safe-js/src/interp/exceptions.ts
19705
19798
  var capturedExceptionBrand = /* @__PURE__ */ Symbol("CapturedException");
19799
+ var readDOMExceptionCode = Object.getOwnPropertyDescriptor(DOMException.prototype, "code").get;
19706
19800
  internalSymbols.add(capturedExceptionBrand);
19707
19801
  async function evaluateThrowStatement(node, context, evaluateNode2) {
19708
19802
  const argument = await evaluateNode2(node.argument, context);
@@ -19815,11 +19909,14 @@ function coerceThrownValue(reason, budget, stackFrames, span, sandbox = false) {
19815
19909
  return reason;
19816
19910
  }
19817
19911
  if (reason instanceof Error) {
19818
- return createSubsetErrorValue(reason.name || "Error", reason.message, stackFrames, budget, {
19912
+ const error = createSubsetErrorValue(reason.name || "Error", reason.message, stackFrames, budget, {
19819
19913
  chargeBudget: false,
19820
19914
  cause: readErrorCause(reason),
19821
19915
  span
19822
19916
  });
19917
+ if (reason instanceof DOMException)
19918
+ Object.defineProperty(error, "code", { value: Reflect.apply(readDOMExceptionCode, reason, []), enumerable: true });
19919
+ return error;
19823
19920
  }
19824
19921
  if (sandbox) {
19825
19922
  return reason;
@@ -28135,6 +28232,14 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
28135
28232
  if (isNumericTypedArray(value)) {
28136
28233
  const existing = state.seen.get(value);
28137
28234
  if (existing !== void 0) return existing;
28235
+ if (state.structuredClone) {
28236
+ try {
28237
+ typedArrayStorage(value, true);
28238
+ } catch (error) {
28239
+ if (!(error instanceof TypeError)) throw error;
28240
+ throw new DOMException("Cannot clone an out-of-bounds typed array.", "DataCloneError");
28241
+ }
28242
+ }
28138
28243
  const copy = copyTypedArrayStorage(value, state);
28139
28244
  state.seen.set(value, copy);
28140
28245
  if (state.structuredClone) return copy;
@@ -42816,4 +42921,4 @@ export {
42816
42921
  FileSnapshotBackend,
42817
42922
  run
42818
42923
  };
42819
- //# sourceMappingURL=chunk-RHEDM44A.js.map
42924
+ //# sourceMappingURL=chunk-QMF5YOGC.js.map