@poe-platform/safe-js 0.1.275 → 0.1.277

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-MPVIYBZC.js";
30
+ } from "./chunk-VDDR5KKE.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-XDACAERJ.js.map
8252
+ //# sourceMappingURL=chunk-F6E3VH3T.js.map
@@ -11241,7 +11241,7 @@ function mapIteratorSnapshot(snapshot, map) {
11241
11241
  async function restoreSandboxIterator(snapshot, budget, context, signal) {
11242
11242
  if (snapshot.kind === "unsupported") throw new TypeError("Host-owned iterator cannot be restored.");
11243
11243
  if (snapshot.kind === "guest") return guestIterator(snapshot.value, snapshot.next, snapshot.async, budget, context, signal);
11244
- if (snapshot.kind === "async-from-sync") return asyncFromSyncIterator(await restoreSandboxIterator(snapshot.inner, budget, context, signal), budget, signal);
11244
+ if (snapshot.kind === "async-from-sync") return asyncFromSyncIterator(await restoreSandboxIterator(snapshot.inner, budget, context, signal), budget, signal, context);
11245
11245
  if (Array.isArray(snapshot.value)) return arrayIterator(snapshot.value, context, budget, snapshot.index);
11246
11246
  const iterator = isSandboxGenerator(snapshot.value) && snapshot.value.async ? getSandboxAsyncIterator(snapshot.value, budget, context, signal) : getSandboxIterator(snapshot.value, budget, context);
11247
11247
  if (iterator === void 0) throw new TypeError("Invalid builtin iterator snapshot.");
@@ -11257,7 +11257,7 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
11257
11257
  if (isSandboxGenerator(value) && value.async)
11258
11258
  return getSandboxAsyncIterator(value, budget, context, signal);
11259
11259
  const iterator2 = await acquireSandboxIterator(value, budget, context);
11260
- return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal);
11260
+ return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal, context);
11261
11261
  }
11262
11262
  const factory = await context.getProperty(value, key);
11263
11263
  if (!asyncProtocol && (isSandboxMap(value) || isSandboxSet(value)) && typeof factory === "object" && factory !== null && getIntrinsicIdentity(factory) === JSON.stringify(isSandboxMap(value) ? ["Map", "prototype", "entries"] : ["Set", "prototype", "values"])) {
@@ -11266,7 +11266,7 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
11266
11266
  if (factory === null || factory === void 0) {
11267
11267
  if (!asyncProtocol) return void 0;
11268
11268
  const iterator2 = await acquireSandboxIterator(value, budget, context);
11269
- return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal);
11269
+ return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal, context);
11270
11270
  }
11271
11271
  if (!isSandboxClosure(factory)) {
11272
11272
  if (typeof factory !== "function") throw new TypeError("Iterator method must be callable.");
@@ -11286,7 +11286,7 @@ function guestIterator(iterator, next, asyncProtocol, budget, context, signal) {
11286
11286
  const invoke = async (operation, args) => {
11287
11287
  if (!isSandboxClosure(operation)) throw new TypeError("Iterator operation must be callable.");
11288
11288
  const returned = await invokeBuiltinClosure(operation, args, budget, context, iterator);
11289
- const result = asyncProtocol ? await awaitSandboxValue(returned, signal, budget) : returned;
11289
+ const result = asyncProtocol ? await awaitSandboxValue(returned, signal, budget, context) : returned;
11290
11290
  if (typeof result !== "object" && typeof result !== "function" || result === null)
11291
11291
  throw new TypeError("Iterator result must be an object.");
11292
11292
  return result;
@@ -11311,7 +11311,7 @@ async function readIteratorResult(iterator, result, property) {
11311
11311
  }
11312
11312
  function getSandboxAsyncIterator(value, budget, context, signal) {
11313
11313
  if (isSandboxGenerator(value) && value.async) {
11314
- return { ...generatorIterator(value, budget), asyncProtocol: true };
11314
+ return { ...generatorIterator(value, budget, context), asyncProtocol: true };
11315
11315
  }
11316
11316
  if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
11317
11317
  const method = value[Symbol.asyncIterator];
@@ -11320,7 +11320,7 @@ function getSandboxAsyncIterator(value, budget, context, signal) {
11320
11320
  }
11321
11321
  }
11322
11322
  const iterator = getSandboxIterator(value, budget, context);
11323
- return iterator === void 0 ? void 0 : asyncFromSyncIterator(iterator, budget, signal);
11323
+ return iterator === void 0 ? void 0 : asyncFromSyncIterator(iterator, budget, signal, context);
11324
11324
  }
11325
11325
  function nativeAsyncIterator(value, method, signal) {
11326
11326
  if (typeof method !== "function") throw new TypeError("Async iterator method must be callable.");
@@ -11362,7 +11362,7 @@ function nativeAsyncIterator(value, method, signal) {
11362
11362
  }
11363
11363
  };
11364
11364
  }
11365
- function asyncFromSyncIterator(iterator, budget, signal) {
11365
+ function asyncFromSyncIterator(iterator, budget, signal, context) {
11366
11366
  const invoke = async (method, args) => {
11367
11367
  const operation = iterator.getOperation === void 0 ? iterator[method] : await iterator.getOperation(method);
11368
11368
  if (operation === void 0) {
@@ -11380,7 +11380,7 @@ function asyncFromSyncIterator(iterator, budget, signal) {
11380
11380
  const done = Boolean((await readIteratorResult(iterator, result, "done")).value);
11381
11381
  const resultValue = (await readIteratorResult(iterator, result, "value")).value;
11382
11382
  try {
11383
- return { done, value: await awaitSandboxValue(resultValue, signal, budget) };
11383
+ return { done, value: await awaitSandboxValue(resultValue, signal, budget, context) };
11384
11384
  } catch (error) {
11385
11385
  if (isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
11386
11386
  if (!done && method !== "return") await closeIterator(iterator, true);
@@ -11538,7 +11538,7 @@ function collectionIterator(collection, value) {
11538
11538
  return adapter;
11539
11539
  }
11540
11540
  var asyncGeneratorRequests = /* @__PURE__ */ new WeakMap();
11541
- function generatorIterator(generator, budget) {
11541
+ function generatorIterator(generator, budget, context) {
11542
11542
  const invoke = async (method, value) => {
11543
11543
  const leaveRunning = enterRunningState(generator);
11544
11544
  const initialState = generator.state;
@@ -11546,7 +11546,7 @@ function generatorIterator(generator, budget) {
11546
11546
  try {
11547
11547
  if (generator.async && method === "return" && (initialState === "start" || initialState === "done")) {
11548
11548
  if (initialState === "start") await generator.channel.return();
11549
- value = await awaitSandboxValue(value, void 0, budget);
11549
+ value = await awaitSandboxValue(value, void 0, budget, context);
11550
11550
  }
11551
11551
  const result = await generator.channel[method](value);
11552
11552
  generator.state = result.done ? "done" : "suspended";
@@ -11616,6 +11616,8 @@ function createPromiseGlobals(options) {
11616
11616
  const prototype = getPromisePrototype(options.budget);
11617
11617
  const construct = async ([executor], context) => {
11618
11618
  if (!isSandboxClosure(executor)) throw new TypeError("Promise executor must be a function.");
11619
+ const prototypeValue = context?.newTarget === void 0 ? prototype : context.getProperty === void 0 ? getSandboxDataProperty(context.newTarget, "prototype", options.budget) : context.getProperty(context.newTarget, "prototype");
11620
+ const targetPrototype = prototypeValue instanceof Promise ? await prototypeValue : prototypeValue;
11619
11621
  let fulfill;
11620
11622
  let reject;
11621
11623
  const pending = createSandboxPromise(
@@ -11625,6 +11627,8 @@ function createPromiseGlobals(options) {
11625
11627
  }),
11626
11628
  { span: context?.span }
11627
11629
  );
11630
+ if (typeof targetPrototype === "object" && targetPrototype !== null && targetPrototype !== prototype)
11631
+ setSandboxPrototype(pending, targetPrototype, options.budget);
11628
11632
  let settled = false;
11629
11633
  const settle = (state, value) => {
11630
11634
  if (settled) return;
@@ -11642,7 +11646,7 @@ function createPromiseGlobals(options) {
11642
11646
  )
11643
11647
  );
11644
11648
  } else {
11645
- fulfill(resolveSandboxValue(value, { budget: options.budget, self: pending }));
11649
+ fulfill(resolveSandboxValue(value, { budget: options.budget, self: pending, context }));
11646
11650
  }
11647
11651
  } catch (error) {
11648
11652
  reject(error);
@@ -11755,7 +11759,7 @@ function createPromiseGlobals(options) {
11755
11759
  }
11756
11760
  const finish = (actualConstructor2) => {
11757
11761
  if (isSandboxPromise(value) && actualConstructor2 === constructor) return value;
11758
- return isSandboxPromiseConstructor(constructor) ? createSandboxPromise(resolveSandboxValue(value, { budget: options.budget })) : settleConstructedPromise(constructor, value, "fulfilled", options.budget, context);
11762
+ return isSandboxPromiseConstructor(constructor) ? createSandboxPromise(resolveSandboxValue(value, { budget: options.budget, context })) : settleConstructedPromise(constructor, value, "fulfilled", options.budget, context);
11759
11763
  };
11760
11764
  if (!isSandboxPromise(value)) return finish(void 0);
11761
11765
  const descriptor = getSandboxPropertyDescriptor(value, "constructor", options.budget);
@@ -11853,9 +11857,10 @@ async function createPromiseCapability(constructor, budget, context) {
11853
11857
  const leaveCall = budget.enterCall();
11854
11858
  try {
11855
11859
  const promise = await constructor.construct([executor], {
11860
+ ...context,
11856
11861
  stack: context?.stack ?? [],
11857
11862
  thisValue: void 0,
11858
- ...context?.span === void 0 ? {} : { span: context.span }
11863
+ newTarget: constructor
11859
11864
  });
11860
11865
  if (!isSandboxClosure(resolve) || !isSandboxClosure(reject)) {
11861
11866
  throw new TypeError("Promise capability requires callable resolve and reject functions.");
@@ -11981,7 +11986,7 @@ function getPromisePrototype(budget) {
11981
11986
  if (isSandboxPromise(result) && actualConstructor === constructor2) {
11982
11987
  pending = result;
11983
11988
  } else if (isSandboxPromiseConstructor(constructor2)) {
11984
- pending = createSandboxPromise(resolveSandboxValue(result, { budget }));
11989
+ pending = createSandboxPromise(resolveSandboxValue(result, { budget, context }));
11985
11990
  } else {
11986
11991
  pending = await settleConstructedPromise(constructor2, result, "fulfilled", budget, context);
11987
11992
  }
@@ -12150,7 +12155,7 @@ async function settleIterable(iterable, method, budget, constructor, context) {
12150
12155
  });
12151
12156
  });
12152
12157
  remaining++;
12153
- const then = await readPromiseReceiverProperty(entry, "then", prototype, context);
12158
+ const then = await readPromiseProperty(entry, "then", prototype, budget, context);
12154
12159
  if (!isSandboxClosure(then))
12155
12160
  throw new TypeError("Promise resolver result requires a callable then.");
12156
12161
  await callPromiseClosure(then, handlers, entry, budget, context);
@@ -12223,7 +12228,7 @@ function resolveSandboxValueNow(value, options) {
12223
12228
  }
12224
12229
  if (isSandboxPromise(value) && !hasCustomPromiseThen(value, options.budget)) {
12225
12230
  if (options.budget !== void 0) {
12226
- return resolvePromiseResult(value, options.budget, options.self);
12231
+ return resolvePromiseResult(value, options.budget, options.self, options.context);
12227
12232
  }
12228
12233
  observeSandboxPromise(value);
12229
12234
  return value.promise.then(
@@ -12313,7 +12318,8 @@ function resolveThenable(value, then, options) {
12313
12318
  recordSettlement("rejected", error);
12314
12319
  complete();
12315
12320
  }
12316
- }
12321
+ },
12322
+ options.context
12317
12323
  ).catch(reject);
12318
12324
  });
12319
12325
  }
@@ -12355,13 +12361,13 @@ function runPromiseReaction(handler, value, state, budget, self, context) {
12355
12361
  const argument = state === "rejected" && value instanceof Error ? coerceThrownValue(value, budget, []) : value;
12356
12362
  const fulfilled = (result) => {
12357
12363
  if (isPromiseLike2(result)) {
12358
- resolve(resolvePromiseResult(result, budget, self));
12364
+ resolve(resolvePromiseResult(result, budget, self, context));
12359
12365
  } else if (isSelfResolution(result, self)) {
12360
12366
  reject(
12361
12367
  createSubsetErrorValue("TypeError", "Promise cannot resolve to itself.", [], budget)
12362
12368
  );
12363
12369
  } else if (requiresPromiseResolution(result, budget)) {
12364
- resolve(resolvePromiseResult(result, budget, self));
12370
+ resolve(resolvePromiseResult(result, budget, self, context));
12365
12371
  } else {
12366
12372
  resolve(budgetSandboxValue(result, budget));
12367
12373
  }
@@ -12395,9 +12401,9 @@ function callInPromiseJob(handler, args, thisValue = void 0, completion, context
12395
12401
  }
12396
12402
  });
12397
12403
  }
12398
- function resolvePromiseResult(result, budget, self) {
12404
+ function resolvePromiseResult(result, budget, self, context) {
12399
12405
  if (isPromiseLike2(result)) {
12400
- return Promise.resolve(result).then((resolved) => resolvePromiseResult(resolved, budget, self));
12406
+ return Promise.resolve(result).then((resolved) => resolvePromiseResult(resolved, budget, self, context));
12401
12407
  }
12402
12408
  if (isSelfResolution(result, self)) {
12403
12409
  return Promise.reject(
@@ -12405,7 +12411,7 @@ function resolvePromiseResult(result, budget, self) {
12405
12411
  );
12406
12412
  }
12407
12413
  if (!isSandboxPromise(result) || hasCustomPromiseThen(result, budget)) {
12408
- return resolveSandboxValue(result, { budget, self });
12414
+ return resolveSandboxValue(result, { budget, self, context });
12409
12415
  }
12410
12416
  const then = getSandboxPropertyDescriptor(result, "then", budget)?.value ?? getPromiseMember("then", budget);
12411
12417
  if (!isSandboxClosure(then)) return Promise.resolve(result);
@@ -12417,7 +12423,7 @@ function resolvePromiseResult(result, budget, self) {
12417
12423
  try {
12418
12424
  if (state === "rejected") reject(budgetSandboxValue(value, budget));
12419
12425
  else if (requiresPromiseResolution(value, budget)) {
12420
- resolve(resolvePromiseResult(value, budget, self));
12426
+ resolve(resolvePromiseResult(value, budget, self, context));
12421
12427
  } else {
12422
12428
  resolve(budgetSandboxValue(value, budget));
12423
12429
  }
@@ -12446,7 +12452,8 @@ function resolvePromiseResult(result, budget, self) {
12446
12452
  })
12447
12453
  ],
12448
12454
  result,
12449
- budget
12455
+ budget,
12456
+ context
12450
12457
  );
12451
12458
  if (isSandboxPromise(completion)) {
12452
12459
  completion.promise.catch((reason) => {
@@ -12610,7 +12617,7 @@ function registerCancelablePromises(value, signal) {
12610
12617
  }
12611
12618
  }
12612
12619
  }
12613
- function awaitSandboxValue(value, signal, budget) {
12620
+ function awaitSandboxValue(value, signal, budget, context) {
12614
12621
  let resolved;
12615
12622
  if (isSandboxPromise(value)) {
12616
12623
  observeSandboxPromise(value);
@@ -12633,7 +12640,7 @@ function awaitSandboxValue(value, signal, budget) {
12633
12640
  );
12634
12641
  });
12635
12642
  } else {
12636
- resolved = resolveSandboxValue(value, { budget });
12643
+ resolved = resolveSandboxValue(value, { budget, context });
12637
12644
  }
12638
12645
  const pending = isSandboxPromise(value) && (value.synchronousPrefix !== void 0 || signal !== void 0 && cancelableOutcomes.get(value)?.has(signal)) ? resolved : awaitWithSignal(resolved, signal);
12639
12646
  return isSandboxPromise(value) ? pending : interruptOnFatalPromiseRejection(pending);
@@ -15872,8 +15879,8 @@ function getGeneratorMember(target, property, budget) {
15872
15879
  return createSandboxClosure({
15873
15880
  sandbox: true,
15874
15881
  name: property,
15875
- call: ([value]) => {
15876
- const iterator = generatorIterator(target, budget);
15882
+ call: ([value], context) => {
15883
+ const iterator = generatorIterator(target, budget, context);
15877
15884
  const result = Promise.resolve(iterator[property](value)).then((result2) => allocateProducedSandboxValue(
15878
15885
  { value: result2.value, done: result2.done === true },
15879
15886
  budget
@@ -17884,7 +17891,7 @@ async function evaluateReturnStatement(node, context) {
17884
17891
  return {
17885
17892
  kind: "return",
17886
17893
  hasValue: argument.hasValue,
17887
- value: context.asyncGenerator ? await suspendJob(awaitSandboxValue(argument.value, context.signal, context.budget)) : argument.value
17894
+ value: context.asyncGenerator ? await suspendJob(awaitSandboxValue(argument.value, context.signal, context.budget, createCoercionContext(context))) : argument.value
17888
17895
  };
17889
17896
  }
17890
17897
  async function evaluateYieldExpression(node, context) {
@@ -17908,7 +17915,7 @@ async function evaluateYieldExpression(node, context) {
17908
17915
  return generatorCompletionResult(completion);
17909
17916
  }
17910
17917
  async function yieldGeneratorValue(value, node, context) {
17911
- if (context.asyncGenerator && !node.delegate) value = await suspendJob(awaitSandboxValue(value, context.signal, context.budget));
17918
+ if (context.asyncGenerator && !node.delegate) value = await suspendJob(awaitSandboxValue(value, context.signal, context.budget, createCoercionContext(context)));
17912
17919
  context.captureGeneratorScope?.(context.scope, context.generatorBlockScopes, context.finallyCompletions, context.generatorExpressionStates);
17913
17920
  const completionPromise = context.generatorYield(allocateProducedSandboxValue(value, context.budget), node.nodeId);
17914
17921
  emitResumeBreakpoint(context, {
@@ -17919,7 +17926,7 @@ async function yieldGeneratorValue(value, node, context) {
17919
17926
  const completion = await (context.asyncGenerator ? suspendJob(completionPromise) : completionPromise);
17920
17927
  if (context.asyncGenerator && completion.type === "return") {
17921
17928
  try {
17922
- return { type: "return", value: await suspendJob(awaitSandboxValue(completion.value, context.signal, context.budget)) };
17929
+ return { type: "return", value: await suspendJob(awaitSandboxValue(completion.value, context.signal, context.budget, createCoercionContext(context))) };
17923
17930
  } catch (error) {
17924
17931
  return { type: "throw", value: error };
17925
17932
  }
@@ -18800,7 +18807,7 @@ function createCoercionContext(context) {
18800
18807
  compilation: context.compilation,
18801
18808
  getProperty: (value, property) => getPropertyValue(value, property, context),
18802
18809
  reconcileData: (value) => reconcileDataBudget(context.budget, context.stats, context.scope, value, context.compilation, context.compilation?.parent),
18803
- invokeClosure: (closure, args, thisValue, construct) => invokeSandboxClosure(closure, args, context, context.callStack, void 0, thisValue, construct)
18810
+ invokeClosure: (closure, args, thisValue, construct, newTarget) => invokeSandboxClosure(closure, args, context, context.callStack, void 0, thisValue, construct, newTarget)
18804
18811
  };
18805
18812
  }
18806
18813
  function hasSandboxProperty(value, key, context) {
@@ -20853,14 +20860,15 @@ function createInterpretedClosure(node, context, evaluateNode2, homeObject) {
20853
20860
  evaluateNode2
20854
20861
  ),
20855
20862
  context.budget,
20856
- context.signal
20863
+ context.signal,
20864
+ callContext
20857
20865
  );
20858
20866
  }
20859
20867
  });
20860
20868
  registerClosureOrigin(closure, node, context);
20861
20869
  return closure;
20862
20870
  }
20863
- function executeAsyncFunction(execute, budget, signal) {
20871
+ function executeAsyncFunction(execute, budget, signal, callContext) {
20864
20872
  let completePrefix;
20865
20873
  const synchronousPrefix = new Promise((resolve) => {
20866
20874
  completePrefix = resolve;
@@ -20871,7 +20879,7 @@ function executeAsyncFunction(execute, budget, signal) {
20871
20879
  const value = await execute(completePrefix);
20872
20880
  resolve(
20873
20881
  requiresPromiseResolution(value, budget) ? awaitSandboxValue(
20874
- createSandboxPromise(resolveSandboxValue(value, { budget }), {
20882
+ createSandboxPromise(resolveSandboxValue(value, { budget, context: callContext }), {
20875
20883
  trackReplay: false
20876
20884
  }),
20877
20885
  signal,
@@ -20939,7 +20947,7 @@ function createGeneratorClosure(node, context, evaluateNode2) {
20939
20947
  throw result.value;
20940
20948
  }
20941
20949
  const value = result.hasValue ? result.value : void 0;
20942
- return node.async ? awaitSandboxValue(value, context.signal, context.budget) : value;
20950
+ return node.async ? awaitSandboxValue(value, context.signal, context.budget, createCoercionContext(context)) : value;
20943
20951
  };
20944
20952
  return node.async ? runAsyncPrefix(execute) : execute();
20945
20953
  });
@@ -20973,7 +20981,7 @@ async function evaluateAwaitExpression(node, context, evaluateNode2) {
20973
20981
  return {
20974
20982
  kind: "normal",
20975
20983
  hasValue: true,
20976
- value: await suspendJob(awaitSandboxValue(argument.value, context.signal, context.budget))
20984
+ value: await suspendJob(awaitSandboxValue(argument.value, context.signal, context.budget, createCoercionContext(context)))
20977
20985
  };
20978
20986
  } finally {
20979
20987
  leaveAwait();
@@ -40241,4 +40249,4 @@ export {
40241
40249
  FileSnapshotBackend,
40242
40250
  run
40243
40251
  };
40244
- //# sourceMappingURL=chunk-MPVIYBZC.js.map
40252
+ //# sourceMappingURL=chunk-VDDR5KKE.js.map