@poe-platform/safe-js 0.1.254 → 0.1.256

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-VFXTEJXR.js";
30
+ } from "./chunk-S2YTYPJP.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-4MBS7HVN.js.map
8252
+ //# sourceMappingURL=chunk-J5L6E3YK.js.map
@@ -7765,6 +7765,7 @@ var prototypes = /* @__PURE__ */ new WeakMap();
7765
7765
  var intrinsicPrototypes = /* @__PURE__ */ new WeakMap();
7766
7766
  var boxedPrototypes = /* @__PURE__ */ new WeakMap();
7767
7767
  var regexPrototypes = /* @__PURE__ */ new WeakMap();
7768
+ var collectionPrototypes = /* @__PURE__ */ new WeakMap();
7768
7769
  var initialRegexDescriptors = /* @__PURE__ */ new WeakMap();
7769
7770
  var intrinsicPrototypeRoots = /* @__PURE__ */ new WeakMap();
7770
7771
  var intrinsicConstructors = /* @__PURE__ */ new WeakMap();
@@ -7834,6 +7835,12 @@ function installRegexPrototype(budget, prototype, constructor) {
7834
7835
  initialRegexDescriptors.set(budget, Object.getOwnPropertyDescriptors(prototype));
7835
7836
  registerIntrinsicPrototype(budget, prototype, constructor);
7836
7837
  }
7838
+ function installCollectionPrototype(budget, name, prototype, constructor) {
7839
+ let state = collectionPrototypes.get(budget);
7840
+ if (state === void 0) collectionPrototypes.set(budget, state = /* @__PURE__ */ new Map());
7841
+ state.set(name, prototype);
7842
+ registerIntrinsicPrototype(budget, prototype, constructor);
7843
+ }
7837
7844
  function hasRegexPropertyOverride(value, keys, budget) {
7838
7845
  const initial = initialRegexDescriptors.get(budget);
7839
7846
  const prototype = regexPrototypes.get(budget);
@@ -7854,7 +7861,10 @@ function isIntrinsicFunction(value) {
7854
7861
  function registerIntrinsicPrototype(budget, prototype, constructor) {
7855
7862
  if (constructor.name === void 0) throw new TypeError("Intrinsic constructors require an installation name.");
7856
7863
  registerBuiltinIdentities(budget, { [constructor.name]: constructor });
7857
- const methods = [prototype, materializeFunctionProperties(constructor)].flatMap((owner) => Reflect.ownKeys(owner).map((key) => Object.getOwnPropertyDescriptor(owner, key)?.value)).filter(isGuestClosure);
7864
+ const methods = [prototype, materializeFunctionProperties(constructor)].flatMap((owner) => Reflect.ownKeys(owner).flatMap((key) => {
7865
+ const descriptor = Object.getOwnPropertyDescriptor(owner, key);
7866
+ return [descriptor.value, ...retainedAccessorClosures(descriptor)];
7867
+ })).filter(isGuestClosure);
7858
7868
  trackIntrinsicState(budget, prototype, constructor, [prototype, constructor, ...methods]);
7859
7869
  }
7860
7870
  function registerIntrinsicFunction(budget, closure) {
@@ -7909,11 +7919,14 @@ function releaseObjectPrototype(budget) {
7909
7919
  intrinsicPrototypeRoots.delete(budget);
7910
7920
  boxedPrototypes.delete(budget);
7911
7921
  regexPrototypes.delete(budget);
7922
+ collectionPrototypes.delete(budget);
7912
7923
  initialRegexDescriptors.delete(budget);
7913
7924
  intrinsicPrototypes.delete(budget);
7914
7925
  }
7915
7926
  function getSandboxPrototype(value, budget) {
7916
7927
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
7928
+ if (budget !== void 0 && (isSandboxMap(value) || isSandboxSet(value)))
7929
+ return collectionPrototypes.get(budget)?.get(isSandboxMap(value) ? "Map" : "Set") ?? null;
7917
7930
  if (budget !== void 0 && isSandboxRegex(value)) return regexPrototypes.get(budget) ?? null;
7918
7931
  if (budget !== void 0 && isSandboxBox(value)) {
7919
7932
  const prototype = getBoxedPrototype(boxedValue(value), budget);
@@ -7933,8 +7946,8 @@ function getSandboxPropertyDescriptor(value, key, budget) {
7933
7946
  return hostProperties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(hostProperties, key);
7934
7947
  let current = value;
7935
7948
  let depth = 0;
7936
- while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxDate(current) || isSandboxRegex(current) || isPrototypeRecord(current))) {
7937
- const properties = isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : current;
7949
+ while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxDate(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
7950
+ const properties = isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? void 0 : current;
7938
7951
  const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key);
7939
7952
  if (descriptor !== void 0) return descriptor;
7940
7953
  current = getSandboxPrototype(current, budget);
@@ -12403,6 +12416,8 @@ function createObjectArrayGlobals(options) {
12403
12416
  getPrototypeOf: createSandboxClosure({
12404
12417
  sandbox: true,
12405
12418
  call: ([value]) => {
12419
+ if (isSandboxMap(value) || isSandboxSet(value))
12420
+ return getSandboxPrototype(value, options.budget);
12406
12421
  if (isSandboxDate(value))
12407
12422
  return getDatePrototype(value, options.budget, options.compileOwner);
12408
12423
  if (value !== null && value !== void 0 && typeof value !== "object")
@@ -14734,12 +14749,90 @@ function isObjectLike(value) {
14734
14749
  return typeof value === "object" && value !== null;
14735
14750
  }
14736
14751
 
14752
+ // packages/safe-js/src/interp/globals/collection-prototypes.ts
14753
+ function installCollectionPrototypes(budget, mapConstructor, setConstructor) {
14754
+ const mapMethods = Object.fromEntries([...mapMethodNames].map((name) => [name, createSandboxClosure({
14755
+ guest: true,
14756
+ sandbox: true,
14757
+ name,
14758
+ length: Map.prototype[name].length,
14759
+ call: (args, context) => {
14760
+ const receiver = context?.thisValue;
14761
+ if (!isSandboxMap(receiver)) throw new TypeError(`Map.prototype.${name} requires a Map receiver.`);
14762
+ return callMapMethod(receiver, name, args, {
14763
+ budget,
14764
+ callClosure: (closure, values, _stack, thisValue) => invokeBuiltinClosure(closure, values, budget, context, thisValue)
14765
+ }, context?.stack ?? []);
14766
+ }
14767
+ })]));
14768
+ const setMethods = Object.fromEntries([...setMethodNames].filter((name) => name !== "keys").map((name) => [name, createSandboxClosure({
14769
+ guest: true,
14770
+ sandbox: true,
14771
+ name,
14772
+ length: Set.prototype[name].length,
14773
+ call: (args, context) => {
14774
+ const receiver = context?.thisValue;
14775
+ if (!isSandboxSet(receiver)) throw new TypeError(`Set.prototype.${name} requires a Set receiver.`);
14776
+ return callSetMethod(receiver, name, args, {
14777
+ budget,
14778
+ callClosure: (closure, values, _stack, thisValue) => invokeBuiltinClosure(closure, values, budget, context, thisValue)
14779
+ }, context?.stack ?? []);
14780
+ }
14781
+ })]));
14782
+ setMethods.keys = setMethods.values;
14783
+ const mapSize = createSandboxClosure({
14784
+ guest: true,
14785
+ sandbox: true,
14786
+ name: "get size",
14787
+ length: 0,
14788
+ call: (_args, context) => {
14789
+ if (!isSandboxMap(context?.thisValue)) throw new TypeError("Map.prototype.size requires a Map receiver.");
14790
+ return context.thisValue.entries.size;
14791
+ }
14792
+ });
14793
+ const setSize = createSandboxClosure({
14794
+ guest: true,
14795
+ sandbox: true,
14796
+ name: "get size",
14797
+ length: 0,
14798
+ call: (_args, context) => {
14799
+ if (!isSandboxSet(context?.thisValue)) throw new TypeError("Set.prototype.size requires a Set receiver.");
14800
+ return context.thisValue.values.size;
14801
+ }
14802
+ });
14803
+ for (const { name, constructor, methods, size, iterator } of [
14804
+ { name: "Map", constructor: mapConstructor, methods: mapMethods, size: mapSize, iterator: mapMethods.entries },
14805
+ { name: "Set", constructor: setConstructor, methods: setMethods, size: setSize, iterator: setMethods.values }
14806
+ ]) {
14807
+ const prototype = /* @__PURE__ */ Object.create(null);
14808
+ const species = createSandboxClosure({
14809
+ guest: true,
14810
+ sandbox: true,
14811
+ name: "get [Symbol.species]",
14812
+ length: 0,
14813
+ call: (_args, context) => context?.thisValue
14814
+ });
14815
+ Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
14816
+ Object.defineProperty(materializeFunctionProperties(constructor), Symbol.species, { get: accessorAdapter(species, "get"), configurable: true });
14817
+ Object.defineProperty(prototype, "constructor", { value: constructor, writable: true, configurable: true });
14818
+ for (const [key, method] of Object.entries(methods))
14819
+ Object.defineProperty(prototype, key, { value: method, writable: true, configurable: true });
14820
+ Object.defineProperty(prototype, "size", { get: accessorAdapter(size, "get"), configurable: true });
14821
+ Object.defineProperty(prototype, Symbol.toStringTag, { value: name, configurable: true });
14822
+ Object.defineProperty(prototype, Symbol.iterator, { value: iterator, writable: true, configurable: true });
14823
+ installCollectionPrototype(budget, name, prototype, constructor);
14824
+ for (const method of /* @__PURE__ */ new Set([...Object.values(methods), size, species])) registerIntrinsicFunction(budget, method);
14825
+ }
14826
+ }
14827
+
14737
14828
  // packages/safe-js/src/interp/globals/collections.ts
14738
14829
  var mapConstructors = /* @__PURE__ */ new WeakSet();
14739
14830
  var setConstructors = /* @__PURE__ */ new WeakSet();
14740
14831
  function createCollectionGlobals(options) {
14741
14832
  const mapConstructor = createSandboxClosure({
14742
14833
  sandbox: true,
14834
+ guest: true,
14835
+ length: 0,
14743
14836
  call: () => {
14744
14837
  throw new TypeError("Constructor Map requires 'new'.");
14745
14838
  },
@@ -14778,6 +14871,8 @@ function createCollectionGlobals(options) {
14778
14871
  });
14779
14872
  const setConstructor = createSandboxClosure({
14780
14873
  sandbox: true,
14874
+ guest: true,
14875
+ length: 0,
14781
14876
  call: () => {
14782
14877
  throw new TypeError("Constructor Set requires 'new'.");
14783
14878
  },
@@ -14800,6 +14895,7 @@ function createCollectionGlobals(options) {
14800
14895
  });
14801
14896
  mapConstructors.add(mapConstructor);
14802
14897
  setConstructors.add(setConstructor);
14898
+ installCollectionPrototypes(options.budget, mapConstructor, setConstructor);
14803
14899
  return { Map: mapConstructor, Set: setConstructor };
14804
14900
  }
14805
14901
  function isSandboxMapConstructor(value) {
@@ -17070,8 +17166,8 @@ function getPropertyValue(target, property, context, receiver = target) {
17070
17166
  if (isFloat32Array(target)) return getFloat32Member(target, property, context.budget);
17071
17167
  if (isSandboxDate(target))
17072
17168
  return getDateMember(property, context.budget, context.compilation?.owner);
17073
- if (isSandboxMap(target)) return getMapMember(target, property, createMapMethodOptions(context));
17074
- if (isSandboxSet(target)) return getSetMember(target, property, createSetMethodOptions(context));
17169
+ if (isSandboxMap(target)) return getSandboxPrototype(target, context.budget) === null ? getMapMember(target, property, createMapMethodOptions(context)) : void 0;
17170
+ if (isSandboxSet(target)) return getSandboxPrototype(target, context.budget) === null ? getSetMember(target, property, createSetMethodOptions(context)) : void 0;
17075
17171
  if (isSandboxCollectionIterator(target))
17076
17172
  return getCollectionIteratorMember(target, property, context.budget);
17077
17173
  if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
@@ -17301,6 +17397,8 @@ async function evaluateMemberCallExpression(node, context) {
17301
17397
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context, member.superReceiver.value), context, member.superReceiver.value);
17302
17398
  if (typeof member.property === "symbol")
17303
17399
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
17400
+ if ((isSandboxMap(member.object) || isSandboxSet(member.object)) && getSandboxPrototype(member.object, context.budget) !== null)
17401
+ return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
17304
17402
  if (Array.isArray(member.object) && hasExplicitSandboxPrototype(member.object))
17305
17403
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
17306
17404
  if ((typeof member.object === "string" || typeof member.object === "number" || typeof member.object === "bigint" || typeof member.object === "boolean" || typeof member.object === "symbol") && getBoxedPrototype(member.object, context.budget) !== void 0) {
@@ -17693,7 +17791,7 @@ function hasSandboxProperty(value, key, context) {
17693
17791
  while (typeof current === "object" && current !== null) {
17694
17792
  if (isGuestHostObject(current)) return typeof key === "symbol" ? false : hasHostObjectMember(current, String(key));
17695
17793
  if (hasOwnSandboxProperty(current, key, false)) return true;
17696
- if (!isSandboxRegex(current) && !((isGuestClosure(current) || Array.isArray(current)) && hasExplicitSandboxPrototype(current)) && (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isSandboxRegExpIterator(current))) {
17794
+ if (!isSandboxRegex(current) && !isSandboxMap(current) && !isSandboxSet(current) && !((isGuestClosure(current) || Array.isArray(current)) && hasExplicitSandboxPrototype(current)) && (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isSandboxRegExpIterator(current))) {
17697
17795
  return getPropertyValue(current, key, context) !== void 0;
17698
17796
  }
17699
17797
  current = getSandboxPrototype(current, context.budget);
@@ -20764,6 +20862,9 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
20764
20862
  return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal);
20765
20863
  }
20766
20864
  const factory = await context.getProperty(value, key);
20865
+ if (!asyncProtocol && (isSandboxMap(value) || isSandboxSet(value)) && typeof factory === "object" && factory !== null && getIntrinsicIdentity(factory) === JSON.stringify(isSandboxMap(value) ? ["Map", "prototype", "entries"] : ["Set", "prototype", "values"])) {
20866
+ return getSandboxIterator(value, budget, context);
20867
+ }
20767
20868
  if (factory === null || factory === void 0) {
20768
20869
  if (!asyncProtocol) return void 0;
20769
20870
  const iterator2 = await acquireSandboxIterator(value, budget, context);
@@ -22103,6 +22204,76 @@ function defineDataProperty2(target, key, value) {
22103
22204
  });
22104
22205
  }
22105
22206
 
22207
+ // packages/safe-js/src/interp/globals/math-sum-precise.ts
22208
+ async function sumPrecise(source, budget, context) {
22209
+ let iterator;
22210
+ let current;
22211
+ let recordValue;
22212
+ let sum = 0n;
22213
+ let sumSize = 1;
22214
+ let special;
22215
+ let minusZero = true;
22216
+ let count = 0;
22217
+ const storage = new DataView(new ArrayBuffer(8));
22218
+ const checkData = createDataCheckpoint(budget, context);
22219
+ const release = retainValues(budget, () => [source, iterator?.retainedValue, recordValue, current, sum]);
22220
+ try {
22221
+ if (source === void 0 || source === null) throw new TypeError("Math.sumPrecise requires an iterable.");
22222
+ iterator = context === void 0 ? getSandboxIterator(source, budget) : await acquireSandboxIterator(source, budget, context);
22223
+ if (iterator === void 0) throw new TypeError("Math.sumPrecise requires an iterable.");
22224
+ checkData(source, 0, true);
22225
+ while (true) {
22226
+ budget.visitNode();
22227
+ const next = iterator.next();
22228
+ const result = iterator.asynchronous || iterator.generator ? await next : next;
22229
+ if (typeof result !== "object" && typeof result !== "function" || result === null)
22230
+ throw new TypeError("Iterator result must be an object.");
22231
+ recordValue = result;
22232
+ const record3 = result;
22233
+ if ((await readIteratorResult(iterator, record3, "done")).value) break;
22234
+ current = (await readIteratorResult(iterator, record3, "value")).value;
22235
+ if (count >= Number.MAX_SAFE_INTEGER || typeof current !== "number") {
22236
+ const error = count >= Number.MAX_SAFE_INTEGER ? new RangeError("Math.sumPrecise received too many elements.") : new TypeError("Math.sumPrecise requires number elements.");
22237
+ await closeIterator(iterator, true);
22238
+ throw error;
22239
+ }
22240
+ count++;
22241
+ if (!Object.is(current, -0)) minusZero = false;
22242
+ if (Number.isNaN(current)) special = NaN;
22243
+ else if (!Number.isFinite(current)) {
22244
+ special = special === void 0 || special === current ? current : NaN;
22245
+ } else if (special === void 0) {
22246
+ storage.setFloat64(0, current);
22247
+ const bits = storage.getBigUint64(0);
22248
+ const exponent = Number(bits >> 52n & 2047n);
22249
+ const fraction = bits & (1n << 52n) - 1n;
22250
+ const significand = exponent === 0 ? fraction : 1n << 52n | fraction;
22251
+ const units = significand << BigInt(Math.max(0, exponent - 1));
22252
+ sum += bits >> 63n ? -units : units;
22253
+ }
22254
+ current = void 0;
22255
+ recordValue = void 0;
22256
+ const size = sum.toString(16).length;
22257
+ checkData(source, Math.max(0, size - sumSize));
22258
+ sumSize = size;
22259
+ }
22260
+ if (special !== void 0) return special;
22261
+ if (minusZero) return -0;
22262
+ const sign = sum < 0n ? -1 : 1;
22263
+ if (sum < 0n) sum = -sum;
22264
+ const shift = Math.max(0, sum.toString(2).length - 53);
22265
+ let rounded = sum >> BigInt(shift);
22266
+ if (shift > 0) {
22267
+ const remainder = sum - (rounded << BigInt(shift));
22268
+ const half = 1n << BigInt(shift - 1);
22269
+ if (remainder > half || remainder === half && (rounded & 1n) === 1n) rounded++;
22270
+ }
22271
+ return sign * Number(rounded) * 2 ** (shift - 1074);
22272
+ } finally {
22273
+ release();
22274
+ }
22275
+ }
22276
+
22106
22277
  // packages/safe-js/src/interp/globals/math.ts
22107
22278
  var mathMethods = {
22108
22279
  abs: Math.abs,
@@ -22174,7 +22345,14 @@ function createMathGlobals(options = {}) {
22174
22345
  PI: Math.PI,
22175
22346
  SQRT1_2: Math.SQRT1_2,
22176
22347
  SQRT2: Math.SQRT2,
22177
- random: createSandboxClosure({ sandbox: true, guest: true, call: () => random(), name: "random", length: 0 })
22348
+ random: createSandboxClosure({ sandbox: true, guest: true, call: () => random(), name: "random", length: 0 }),
22349
+ sumPrecise: createSandboxClosure({
22350
+ sandbox: true,
22351
+ guest: true,
22352
+ name: "sumPrecise",
22353
+ length: 1,
22354
+ call: ([source], context) => sumPrecise(source, budget, context)
22355
+ })
22178
22356
  };
22179
22357
  for (const [name, method] of Object.entries(mathMethods)) {
22180
22358
  const variadic = method === Math.max || method === Math.min || method === Math.hypot;
@@ -39620,4 +39798,4 @@ export {
39620
39798
  FileSnapshotBackend,
39621
39799
  run
39622
39800
  };
39623
- //# sourceMappingURL=chunk-VFXTEJXR.js.map
39801
+ //# sourceMappingURL=chunk-S2YTYPJP.js.map