@poe-platform/safe-js 0.1.271 → 0.1.273

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-KAZ53U6F.js";
30
+ } from "./chunk-Y7SBHDZT.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-XEN2XAGO.js.map
8252
+ //# sourceMappingURL=chunk-D6UH6V3H.js.map
@@ -11677,87 +11677,120 @@ function createPromiseGlobals(options) {
11677
11677
  }
11678
11678
  return pending;
11679
11679
  };
11680
+ const species = createSandboxClosure({
11681
+ guest: true,
11682
+ sandbox: true,
11683
+ name: "get [Symbol.species]",
11684
+ length: 0,
11685
+ call: (_args, context) => context?.thisValue
11686
+ });
11687
+ const properties = {
11688
+ prototype,
11689
+ all: createSandboxClosure({
11690
+ sandbox: true,
11691
+ call: ([values], context) => settleIterable(
11692
+ values,
11693
+ "all",
11694
+ options.budget,
11695
+ context === void 0 ? promiseConstructor : context.thisValue,
11696
+ context
11697
+ ),
11698
+ guest: true,
11699
+ name: "all",
11700
+ length: 1
11701
+ }),
11702
+ race: createSandboxClosure({
11703
+ sandbox: true,
11704
+ call: ([values], context) => settleIterable(
11705
+ values,
11706
+ "race",
11707
+ options.budget,
11708
+ context === void 0 ? promiseConstructor : context.thisValue,
11709
+ context
11710
+ ),
11711
+ guest: true,
11712
+ name: "race",
11713
+ length: 1
11714
+ }),
11715
+ allSettled: createSandboxClosure({
11716
+ sandbox: true,
11717
+ call: ([values], context) => settleIterable(
11718
+ values,
11719
+ "allSettled",
11720
+ options.budget,
11721
+ context === void 0 ? promiseConstructor : context.thisValue,
11722
+ context
11723
+ ),
11724
+ guest: true,
11725
+ name: "allSettled",
11726
+ length: 1
11727
+ }),
11728
+ any: createSandboxClosure({
11729
+ sandbox: true,
11730
+ call: ([values], context) => settleIterable(
11731
+ values,
11732
+ "any",
11733
+ options.budget,
11734
+ context === void 0 ? promiseConstructor : context.thisValue,
11735
+ context
11736
+ ),
11737
+ guest: true,
11738
+ name: "any",
11739
+ length: 1
11740
+ }),
11741
+ resolve: createSandboxClosure({
11742
+ sandbox: true,
11743
+ call: ([value], context) => {
11744
+ const constructor = context === void 0 ? promiseConstructor : context.thisValue;
11745
+ if (typeof constructor !== "object" || constructor === null) {
11746
+ throw new TypeError("Promise.resolve requires an object receiver.");
11747
+ }
11748
+ const finish = (actualConstructor2) => {
11749
+ if (isSandboxPromise(value) && actualConstructor2 === constructor) return value;
11750
+ return isSandboxPromiseConstructor(constructor) ? createSandboxPromise(resolveSandboxValue(value, { budget: options.budget })) : settleConstructedPromise(constructor, value, "fulfilled", options.budget, context);
11751
+ };
11752
+ if (!isSandboxPromise(value)) return finish(void 0);
11753
+ const descriptor = getSandboxPropertyDescriptor(value, "constructor", options.budget);
11754
+ const actualConstructor = descriptor === void 0 ? getPromiseMember("constructor", options.budget) : readPropertyDescriptor(descriptor, value, context, true);
11755
+ return actualConstructor instanceof Promise ? actualConstructor.then(finish) : finish(actualConstructor);
11756
+ },
11757
+ guest: true,
11758
+ name: "resolve",
11759
+ length: 1
11760
+ }),
11761
+ reject: createSandboxClosure({
11762
+ sandbox: true,
11763
+ call: ([reason], context) => {
11764
+ const constructor = context === void 0 ? promiseConstructor : context.thisValue;
11765
+ return isSandboxPromiseConstructor(constructor) ? createRejectedSandboxPromise(reason, options.budget, context?.span) : settleConstructedPromise(constructor, reason, "rejected", options.budget, context);
11766
+ },
11767
+ guest: true,
11768
+ name: "reject",
11769
+ length: 1
11770
+ })
11771
+ };
11680
11772
  const promiseConstructor = createSandboxClosure({
11773
+ guest: true,
11681
11774
  sandbox: true,
11682
11775
  name: "Promise",
11776
+ length: 1,
11683
11777
  construct,
11684
11778
  call: () => {
11685
11779
  throw new TypeError("Constructor Promise requires 'new'.");
11686
- },
11687
- properties: {
11688
- prototype,
11689
- all: createSandboxClosure({
11690
- sandbox: true,
11691
- call: ([values], context) => settleIterable(
11692
- values,
11693
- "all",
11694
- options.budget,
11695
- context === void 0 ? promiseConstructor : context.thisValue,
11696
- context
11697
- ),
11698
- name: "all"
11699
- }),
11700
- race: createSandboxClosure({
11701
- sandbox: true,
11702
- call: ([values], context) => settleIterable(
11703
- values,
11704
- "race",
11705
- options.budget,
11706
- context === void 0 ? promiseConstructor : context.thisValue,
11707
- context
11708
- ),
11709
- name: "race"
11710
- }),
11711
- allSettled: createSandboxClosure({
11712
- sandbox: true,
11713
- call: ([values], context) => settleIterable(
11714
- values,
11715
- "allSettled",
11716
- options.budget,
11717
- context === void 0 ? promiseConstructor : context.thisValue,
11718
- context
11719
- ),
11720
- name: "allSettled"
11721
- }),
11722
- any: createSandboxClosure({
11723
- sandbox: true,
11724
- call: ([values], context) => settleIterable(
11725
- values,
11726
- "any",
11727
- options.budget,
11728
- context === void 0 ? promiseConstructor : context.thisValue,
11729
- context
11730
- ),
11731
- name: "any"
11732
- }),
11733
- resolve: createSandboxClosure({
11734
- sandbox: true,
11735
- call: ([value], context) => {
11736
- const constructor = context === void 0 ? promiseConstructor : context.thisValue;
11737
- if (typeof constructor !== "object" || constructor === null) {
11738
- throw new TypeError("Promise.resolve requires an object receiver.");
11739
- }
11740
- const finish = (actualConstructor2) => {
11741
- if (isSandboxPromise(value) && actualConstructor2 === constructor) return value;
11742
- return isSandboxPromiseConstructor(constructor) ? createSandboxPromise(resolveSandboxValue(value, { budget: options.budget })) : settleConstructedPromise(constructor, value, "fulfilled", options.budget, context);
11743
- };
11744
- if (!isSandboxPromise(value)) return finish(void 0);
11745
- const descriptor = getSandboxPropertyDescriptor(value, "constructor", options.budget);
11746
- const actualConstructor = descriptor === void 0 ? getPromiseMember("constructor", options.budget) : readPropertyDescriptor(descriptor, value, context, true);
11747
- return actualConstructor instanceof Promise ? actualConstructor.then(finish) : finish(actualConstructor);
11748
- },
11749
- name: "resolve"
11750
- }),
11751
- reject: createSandboxClosure({
11752
- sandbox: true,
11753
- call: ([reason], context) => {
11754
- const constructor = context === void 0 ? promiseConstructor : context.thisValue;
11755
- return isSandboxPromiseConstructor(constructor) ? createRejectedSandboxPromise(reason, options.budget, context?.span) : settleConstructedPromise(constructor, reason, "rejected", options.budget, context);
11756
- },
11757
- name: "reject"
11758
- })
11759
11780
  }
11760
11781
  });
11782
+ const constructorProperties = materializeFunctionProperties(promiseConstructor);
11783
+ for (const [key, value] of Object.entries(properties)) {
11784
+ Object.defineProperty(constructorProperties, key, {
11785
+ value,
11786
+ writable: key !== "prototype",
11787
+ configurable: key !== "prototype"
11788
+ });
11789
+ }
11790
+ Object.defineProperty(constructorProperties, Symbol.species, {
11791
+ get: accessorAdapter(species, "get"),
11792
+ configurable: true
11793
+ });
11761
11794
  Object.defineProperty(prototype, "constructor", {
11762
11795
  value: promiseConstructor,
11763
11796
  writable: true,
@@ -11765,9 +11798,18 @@ function createPromiseGlobals(options) {
11765
11798
  });
11766
11799
  promiseConstructors.add(promiseConstructor);
11767
11800
  intrinsicPromiseConstructors.set(options.budget, promiseConstructor);
11801
+ registerIntrinsicFunction(options.budget, species);
11802
+ registerIntrinsicFunction(options.budget, promiseConstructor);
11803
+ for (const method of [
11804
+ ...Object.values(properties),
11805
+ ...Object.values(Object.getOwnPropertyDescriptors(prototype)).map((descriptor) => descriptor.value)
11806
+ ]) {
11807
+ if (isSandboxClosure(method)) registerIntrinsicFunction(options.budget, method);
11808
+ }
11768
11809
  return { Promise: promiseConstructor };
11769
11810
  }
11770
11811
  function getPromiseMember(property, budget) {
11812
+ if (!intrinsicPromiseConstructors.has(budget)) createPromiseGlobals({ budget });
11771
11813
  const prototype = getPromisePrototype(budget);
11772
11814
  return Object.hasOwn(prototype, property) ? prototype[property] : void 0;
11773
11815
  }
@@ -11842,7 +11884,23 @@ function getPromisePrototype(budget) {
11842
11884
  const target = context?.thisValue;
11843
11885
  if (!isSandboxPromise(target))
11844
11886
  throw new TypeError("Promise.then requires a promise receiver.");
11845
- const finish = () => {
11887
+ const finish = (constructor2) => {
11888
+ if (!isSandboxPromiseConstructor(constructor2)) {
11889
+ return createPromiseCapability(constructor2, budget, context).then((capability) => {
11890
+ observeSandboxPromise(target);
11891
+ createSandboxPromise(target.promise.then(
11892
+ (value) => {
11893
+ consumeSettledHostCall(target);
11894
+ return runCapabilityReaction(onFulfilled, value, "fulfilled", capability, budget, context);
11895
+ },
11896
+ (reason) => {
11897
+ consumeSettledHostCall(target);
11898
+ return runCapabilityReaction(onRejected, reason, "rejected", capability, budget, context);
11899
+ }
11900
+ ));
11901
+ return capability.promise;
11902
+ });
11903
+ }
11846
11904
  observeSandboxPromise(target);
11847
11905
  const chained = createSandboxPromise(
11848
11906
  target.promise.then(
@@ -11858,10 +11916,12 @@ function getPromisePrototype(budget) {
11858
11916
  );
11859
11917
  return chained;
11860
11918
  };
11861
- const validation = validatePromiseConstructorProperty(target, prototype, budget, context);
11862
- return validation instanceof Promise ? validation.then(finish) : finish();
11919
+ const constructor = getPromiseSpeciesConstructor(target, prototype, budget, context);
11920
+ return constructor instanceof Promise ? constructor.then(finish) : finish(constructor);
11863
11921
  },
11864
- name: "then"
11922
+ guest: true,
11923
+ name: "then",
11924
+ length: 2
11865
11925
  }),
11866
11926
  catch: createSandboxClosure({
11867
11927
  sandbox: true,
@@ -11881,7 +11941,9 @@ function getPromisePrototype(budget) {
11881
11941
  const then = descriptor === void 0 ? readPromiseReceiverProperty(target, "then", prototype, context) : readPropertyDescriptor(descriptor, target, context, true);
11882
11942
  return then instanceof Promise ? then.then(invoke) : invoke(then);
11883
11943
  },
11884
- name: "catch"
11944
+ guest: true,
11945
+ name: "catch",
11946
+ length: 1
11885
11947
  }),
11886
11948
  finally: createSandboxClosure({
11887
11949
  sandbox: true,
@@ -11890,13 +11952,13 @@ function getPromisePrototype(budget) {
11890
11952
  if (typeof target !== "object" || target === null) {
11891
11953
  throw new TypeError("Promise.finally requires an object receiver.");
11892
11954
  }
11893
- const invoke = (then) => {
11955
+ const invoke = (then, constructor2) => {
11894
11956
  if (!isSandboxClosure(then))
11895
11957
  throw new TypeError("Promise.finally requires a callable then.");
11896
11958
  const handlers = isSandboxClosure(onFinally) ? ["fulfilled", "rejected"].map(
11897
11959
  (state) => createSandboxClosure({
11898
11960
  sandbox: true,
11899
- retainedValues: () => [onFinally],
11961
+ retainedValues: () => [onFinally, constructor2],
11900
11962
  call: async ([value]) => {
11901
11963
  const result = await callPromiseClosure(
11902
11964
  onFinally,
@@ -11905,8 +11967,16 @@ function getPromisePrototype(budget) {
11905
11967
  budget,
11906
11968
  context
11907
11969
  );
11908
- const pending = isSandboxPromise(result) && getPromiseMember("constructor", budget) === intrinsicPromiseConstructors.get(budget) ? result : createSandboxPromise(resolveSandboxValue(result, { budget }));
11909
- const cleanupThen = getPromiseMember("then", budget);
11970
+ let pending;
11971
+ const actualConstructor = isSandboxPromise(result) ? await readPromiseProperty(result, "constructor", prototype, budget, context) : void 0;
11972
+ if (isSandboxPromise(result) && actualConstructor === constructor2) {
11973
+ pending = result;
11974
+ } else if (isSandboxPromiseConstructor(constructor2)) {
11975
+ pending = createSandboxPromise(resolveSandboxValue(result, { budget }));
11976
+ } else {
11977
+ pending = await settleConstructedPromise(constructor2, result, "fulfilled", budget, context);
11978
+ }
11979
+ const cleanupThen = await readPromiseProperty(pending, "then", prototype, budget, context);
11910
11980
  if (!isSandboxClosure(cleanupThen))
11911
11981
  throw new TypeError("Promise cleanup requires a callable then.");
11912
11982
  return callPromiseClosure(
@@ -11935,15 +12005,17 @@ function getPromisePrototype(budget) {
11935
12005
  newTarget: void 0
11936
12006
  });
11937
12007
  };
11938
- const finish = () => {
12008
+ const finish = (constructor2) => {
11939
12009
  const descriptor = getSandboxPropertyDescriptor(target, "then", budget);
11940
12010
  const then = descriptor === void 0 ? readPromiseReceiverProperty(target, "then", prototype, context) : readPropertyDescriptor(descriptor, target, context, true);
11941
- return then instanceof Promise ? then.then(invoke) : invoke(then);
12011
+ return then instanceof Promise ? then.then((method) => invoke(method, constructor2)) : invoke(then, constructor2);
11942
12012
  };
11943
- const validation = validatePromiseConstructorProperty(target, prototype, budget, context);
11944
- return validation instanceof Promise ? validation.then(finish) : finish();
12013
+ const constructor = getPromiseSpeciesConstructor(target, prototype, budget, context);
12014
+ return constructor instanceof Promise ? constructor.then(finish) : finish(constructor);
11945
12015
  },
11946
- name: "finally"
12016
+ guest: true,
12017
+ name: "finally",
12018
+ length: 1
11947
12019
  })
11948
12020
  };
11949
12021
  for (const name of Object.keys(prototype)) {
@@ -11958,15 +12030,32 @@ function readPromiseReceiverProperty(receiver, property, prototype, context) {
11958
12030
  const properties = isSandboxPromise(receiver) ? prototype : isSandboxClosure(receiver) ? receiver.properties : receiver;
11959
12031
  return typeof properties === "object" && properties !== null && Object.hasOwn(properties, property) ? properties[property] : void 0;
11960
12032
  }
11961
- function validatePromiseConstructorProperty(receiver, prototype, budget, context) {
12033
+ function getPromiseSpeciesConstructor(receiver, prototype, budget, context) {
12034
+ const defaultConstructor = intrinsicPromiseConstructors.get(budget);
11962
12035
  const validate = (constructor2) => {
11963
- if (constructor2 !== void 0 && (typeof constructor2 !== "object" || constructor2 === null))
12036
+ if (constructor2 === void 0) return defaultConstructor;
12037
+ if (typeof constructor2 !== "object" || constructor2 === null)
11964
12038
  throw new TypeError("Promise constructor property must be an object.");
12039
+ const finish = (species2) => {
12040
+ if (species2 === void 0 || species2 === null) return defaultConstructor;
12041
+ if (!isSandboxClosure(species2) || species2.construct === void 0)
12042
+ throw new TypeError("Promise species must be a constructor.");
12043
+ return species2;
12044
+ };
12045
+ const species = readPromiseProperty(constructor2, Symbol.species, prototype, budget, context);
12046
+ return species instanceof Promise ? species.then(finish) : finish(species);
11965
12047
  };
11966
- const descriptor = getSandboxPropertyDescriptor(receiver, "constructor", budget);
11967
- const constructor = descriptor === void 0 ? readPromiseReceiverProperty(receiver, "constructor", prototype, context) : readPropertyDescriptor(descriptor, receiver, context, true);
12048
+ const constructor = readPromiseProperty(receiver, "constructor", prototype, budget, context);
11968
12049
  return constructor instanceof Promise ? constructor.then(validate) : validate(constructor);
11969
12050
  }
12051
+ function readPromiseProperty(receiver, property, prototype, budget, context) {
12052
+ const descriptor = getSandboxPropertyDescriptor(receiver, property, budget);
12053
+ if (descriptor !== void 0 && !("value" in descriptor) && context?.invokeClosure === void 0) {
12054
+ const getter = accessorClosure(descriptor.get);
12055
+ return getter?.call([], { ...context, stack: context?.stack ?? [], thisValue: receiver });
12056
+ }
12057
+ return descriptor === void 0 ? typeof property === "string" ? readPromiseReceiverProperty(receiver, property, prototype, context) : void 0 : readPropertyDescriptor(descriptor, receiver, context, true);
12058
+ }
11970
12059
  async function settleIterable(iterable, method, budget, constructor, context) {
11971
12060
  const capability = await createPromiseCapability(constructor, budget, context);
11972
12061
  const prototype = getPromisePrototype(budget);
@@ -12217,6 +12306,35 @@ function resolveThenable(value, then, options) {
12217
12306
  ).catch(reject);
12218
12307
  });
12219
12308
  }
12309
+ function runCapabilityReaction(handler, value, state, capability, budget, context) {
12310
+ return runPromiseJob(async () => {
12311
+ if (value instanceof SandboxError && (value.code === "budgetExceeded" || value.code === "reentry")) {
12312
+ throw value;
12313
+ }
12314
+ let completion = state;
12315
+ let result = state === "rejected" && value instanceof Error ? coerceThrownValue(value, budget, []) : value;
12316
+ if (isSandboxClosure(handler)) {
12317
+ try {
12318
+ result = await callPromiseClosure(handler, [result], void 0, budget, context);
12319
+ completion = "fulfilled";
12320
+ } catch (error) {
12321
+ if (error instanceof SandboxError && (error.code === "budgetExceeded" || error.code === "reentry")) {
12322
+ throw error;
12323
+ }
12324
+ completion = "rejected";
12325
+ result = error;
12326
+ }
12327
+ }
12328
+ await callPromiseClosure(
12329
+ completion === "fulfilled" ? capability.resolve : capability.reject,
12330
+ [result],
12331
+ void 0,
12332
+ budget,
12333
+ context
12334
+ );
12335
+ return void 0;
12336
+ });
12337
+ }
12220
12338
  function runPromiseReaction(handler, value, state, budget, self, context) {
12221
12339
  return new Promise((resolve, reject) => {
12222
12340
  if (state === "rejected" && value instanceof SandboxError && (value.code === "budgetExceeded" || value.code === "reentry")) {
@@ -40106,4 +40224,4 @@ export {
40106
40224
  FileSnapshotBackend,
40107
40225
  run
40108
40226
  };
40109
- //# sourceMappingURL=chunk-KAZ53U6F.js.map
40227
+ //# sourceMappingURL=chunk-Y7SBHDZT.js.map