@poe-platform/safe-js 0.1.255 → 0.1.257

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.
@@ -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
  },
@@ -14752,11 +14845,16 @@ function createCollectionGlobals(options) {
14752
14845
  budget: options.budget,
14753
14846
  context,
14754
14847
  retainedValues: () => [key, value],
14755
- append: (entry) => {
14848
+ append: (entry, adder) => {
14756
14849
  if (typeof entry !== "object" || entry === null)
14757
14850
  throw new TypeError("Map constructor requires entry objects.");
14758
14851
  const store = (entryValue) => {
14759
14852
  value = entryValue;
14853
+ if (adder !== void 0)
14854
+ return invokeBuiltinClosure(adder, [key, value], options.budget, context, map).then(() => {
14855
+ key = value = void 0;
14856
+ return 0;
14857
+ });
14760
14858
  const added = map.entries.has(key) ? 0 : 1;
14761
14859
  const growth = added + (options.budget.limits.dataSize === void 0 ? 0 : measureSandboxData([key, value]));
14762
14860
  options.budget.allocateCollectionEntries(map.entries.size + added);
@@ -14778,6 +14876,8 @@ function createCollectionGlobals(options) {
14778
14876
  });
14779
14877
  const setConstructor = createSandboxClosure({
14780
14878
  sandbox: true,
14879
+ guest: true,
14880
+ length: 0,
14781
14881
  call: () => {
14782
14882
  throw new TypeError("Constructor Set requires 'new'.");
14783
14883
  },
@@ -14787,7 +14887,9 @@ function createCollectionGlobals(options) {
14787
14887
  name: "Set",
14788
14888
  budget: options.budget,
14789
14889
  context,
14790
- append: (value) => {
14890
+ append: (value, adder) => {
14891
+ if (adder !== void 0)
14892
+ return invokeBuiltinClosure(adder, [value], options.budget, context, set).then(() => 0);
14791
14893
  const added = set.values.has(value) ? 0 : 1;
14792
14894
  const growth = added + (options.budget.limits.dataSize === void 0 ? 0 : measureSandboxData([value]));
14793
14895
  options.budget.allocateCollectionEntries(set.values.size + added);
@@ -14800,6 +14902,7 @@ function createCollectionGlobals(options) {
14800
14902
  });
14801
14903
  mapConstructors.add(mapConstructor);
14802
14904
  setConstructors.add(setConstructor);
14905
+ installCollectionPrototypes(options.budget, mapConstructor, setConstructor);
14803
14906
  return { Map: mapConstructor, Set: setConstructor };
14804
14907
  }
14805
14908
  function isSandboxMapConstructor(value) {
@@ -14817,15 +14920,17 @@ function populateCollection(source, collection, {
14817
14920
  }) {
14818
14921
  budget.allocateCollectionEntries(0);
14819
14922
  if (source === void 0 || source === null) return collection;
14820
- const populate = (iterator2) => {
14821
- if (iterator2 === void 0) throw new TypeError(`${name} constructor requires an iterable.`);
14923
+ let adder;
14924
+ const populate = (iterator) => {
14925
+ if (iterator === void 0) throw new TypeError(`${name} constructor requires an iterable.`);
14822
14926
  let entry;
14823
14927
  let failure;
14824
14928
  const retained = {};
14825
14929
  budget.setRetainedValues(retained, () => [
14826
14930
  source,
14827
- iterator2.retainedValue,
14931
+ iterator.retainedValue,
14828
14932
  collection,
14933
+ adder,
14829
14934
  entry,
14830
14935
  failure,
14831
14936
  ...retainedValues?.() ?? []
@@ -14837,13 +14942,13 @@ function populateCollection(source, collection, {
14837
14942
  if (!isFatalSandboxError(error) && isFatalSandboxError(closeError)) throw closeError;
14838
14943
  throw error;
14839
14944
  };
14840
- if (iterator2.getOperation !== void 0)
14841
- return closeIterator(iterator2, true).then(() => {
14945
+ if (iterator.getOperation !== void 0)
14946
+ return closeIterator(iterator, true).then(() => {
14842
14947
  throw error;
14843
14948
  }, rethrow);
14844
14949
  try {
14845
- const closing = iterator2.return?.();
14846
- if (iterator2.generator || iterator2.asynchronous)
14950
+ const closing = iterator.return?.();
14951
+ if (iterator.generator || iterator.asynchronous)
14847
14952
  return Promise.resolve(closing).then(() => {
14848
14953
  throw error;
14849
14954
  }, rethrow);
@@ -14859,7 +14964,7 @@ function populateCollection(source, collection, {
14859
14964
  entry = result.value;
14860
14965
  try {
14861
14966
  budget.visitNode();
14862
- const growth = append(entry);
14967
+ const growth = append(entry, adder);
14863
14968
  if (growth instanceof Promise)
14864
14969
  return growth.then((size) => {
14865
14970
  entry = void 0;
@@ -14873,16 +14978,16 @@ function populateCollection(source, collection, {
14873
14978
  }
14874
14979
  return false;
14875
14980
  };
14876
- if (iterator2.generator || iterator2.asynchronous || context !== void 0) {
14981
+ if (iterator.generator || iterator.asynchronous || context !== void 0 || adder !== void 0) {
14877
14982
  return (async () => {
14878
14983
  try {
14879
14984
  checkData(collection, 0, true);
14880
14985
  while (true) {
14881
- const result = await iterator2.next();
14986
+ const result = await iterator.next();
14882
14987
  if (typeof result !== "object" || result === null)
14883
14988
  throw new TypeError("Iterator result must be an object.");
14884
- if ((await readIteratorResult(iterator2, result, "done")).value) break;
14885
- const value = (await readIteratorResult(iterator2, result, "value")).value;
14989
+ if ((await readIteratorResult(iterator, result, "done")).value) break;
14990
+ const value = (await readIteratorResult(iterator, result, "value")).value;
14886
14991
  await consume({ done: false, value });
14887
14992
  }
14888
14993
  checkData(collection, 0, true);
@@ -14894,7 +14999,7 @@ function populateCollection(source, collection, {
14894
14999
  }
14895
15000
  try {
14896
15001
  checkData(collection, 0, true);
14897
- while (!consume(iterator2.next())) {
15002
+ while (!consume(iterator.next())) {
14898
15003
  }
14899
15004
  checkData(collection, 0, true);
14900
15005
  return collection;
@@ -14902,8 +15007,16 @@ function populateCollection(source, collection, {
14902
15007
  budget.setRetainedValues(retained, void 0);
14903
15008
  }
14904
15009
  };
14905
- const iterator = context === void 0 ? getSandboxIterator(source, budget) : acquireSandboxIterator(source, budget, context);
14906
- return iterator instanceof Promise ? iterator.then(populate) : populate(iterator);
15010
+ const method = name === "Map" ? "set" : "add";
15011
+ const start = (candidate2) => {
15012
+ if (!isSandboxClosure(candidate2)) throw new TypeError(`${name} constructor adder must be callable.`);
15013
+ if (getIntrinsicIdentity(candidate2) !== JSON.stringify([name, "prototype", method])) adder = candidate2;
15014
+ const iterator = context === void 0 ? getSandboxIterator(source, budget) : acquireSandboxIterator(source, budget, context);
15015
+ return iterator instanceof Promise ? iterator.then(populate) : populate(iterator);
15016
+ };
15017
+ const descriptor = getSandboxPropertyDescriptor(collection, method, budget);
15018
+ const candidate = context?.getProperty !== void 0 ? context.getProperty(collection, method) : descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, collection, context);
15019
+ return candidate instanceof Promise ? candidate.then(start) : start(candidate);
14907
15020
  }
14908
15021
 
14909
15022
  // packages/safe-js/src/interp/methods/collection-iterator.ts
@@ -17070,8 +17183,8 @@ function getPropertyValue(target, property, context, receiver = target) {
17070
17183
  if (isFloat32Array(target)) return getFloat32Member(target, property, context.budget);
17071
17184
  if (isSandboxDate(target))
17072
17185
  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));
17186
+ if (isSandboxMap(target)) return getSandboxPrototype(target, context.budget) === null ? getMapMember(target, property, createMapMethodOptions(context)) : void 0;
17187
+ if (isSandboxSet(target)) return getSandboxPrototype(target, context.budget) === null ? getSetMember(target, property, createSetMethodOptions(context)) : void 0;
17075
17188
  if (isSandboxCollectionIterator(target))
17076
17189
  return getCollectionIteratorMember(target, property, context.budget);
17077
17190
  if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
@@ -17301,6 +17414,8 @@ async function evaluateMemberCallExpression(node, context) {
17301
17414
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context, member.superReceiver.value), context, member.superReceiver.value);
17302
17415
  if (typeof member.property === "symbol")
17303
17416
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
17417
+ if ((isSandboxMap(member.object) || isSandboxSet(member.object)) && getSandboxPrototype(member.object, context.budget) !== null)
17418
+ return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
17304
17419
  if (Array.isArray(member.object) && hasExplicitSandboxPrototype(member.object))
17305
17420
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
17306
17421
  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 +17808,7 @@ function hasSandboxProperty(value, key, context) {
17693
17808
  while (typeof current === "object" && current !== null) {
17694
17809
  if (isGuestHostObject(current)) return typeof key === "symbol" ? false : hasHostObjectMember(current, String(key));
17695
17810
  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))) {
17811
+ 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
17812
  return getPropertyValue(current, key, context) !== void 0;
17698
17813
  }
17699
17814
  current = getSandboxPrototype(current, context.budget);
@@ -20764,6 +20879,9 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
20764
20879
  return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal);
20765
20880
  }
20766
20881
  const factory = await context.getProperty(value, key);
20882
+ if (!asyncProtocol && (isSandboxMap(value) || isSandboxSet(value)) && typeof factory === "object" && factory !== null && getIntrinsicIdentity(factory) === JSON.stringify(isSandboxMap(value) ? ["Map", "prototype", "entries"] : ["Set", "prototype", "values"])) {
20883
+ return getSandboxIterator(value, budget, context);
20884
+ }
20767
20885
  if (factory === null || factory === void 0) {
20768
20886
  if (!asyncProtocol) return void 0;
20769
20887
  const iterator2 = await acquireSandboxIterator(value, budget, context);
@@ -39697,4 +39815,4 @@ export {
39697
39815
  FileSnapshotBackend,
39698
39816
  run
39699
39817
  };
39700
- //# sourceMappingURL=chunk-PRWJXI5K.js.map
39818
+ //# sourceMappingURL=chunk-A2FDFKJ6.js.map