@poe-platform/safe-js 0.1.299 → 0.1.300

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-3QW2X67U.js";
30
+ } from "./chunk-ONR2CYEH.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-FTBN4WF3.js.map
8252
+ //# sourceMappingURL=chunk-JBOD6COV.js.map
@@ -7398,6 +7398,55 @@ function graphEntries(value) {
7398
7398
  return entries;
7399
7399
  }
7400
7400
 
7401
+ // packages/safe-js/src/interp/resources.ts
7402
+ import { AsyncLocalStorage } from "node:async_hooks";
7403
+ var runResources = new AsyncLocalStorage();
7404
+ function retainValues(budget, values) {
7405
+ const retained = {};
7406
+ budget.setRetainedValues(retained, values);
7407
+ const pending = runResources.getStore()?.referenceReleases;
7408
+ const release = () => {
7409
+ budget.setRetainedValues(retained, void 0);
7410
+ pending?.delete(release);
7411
+ };
7412
+ pending?.add(release);
7413
+ return release;
7414
+ }
7415
+ async function withRunResources(signal, execute) {
7416
+ const controller = new AbortController();
7417
+ const cancel = () => controller.abort(signal?.reason);
7418
+ const cleanups = /* @__PURE__ */ new Set();
7419
+ const resources = {
7420
+ signal: controller.signal,
7421
+ referenceReleases: /* @__PURE__ */ new Set(),
7422
+ add(close) {
7423
+ cleanups.add(close);
7424
+ }
7425
+ };
7426
+ signal?.addEventListener("abort", cancel, { once: true });
7427
+ if (signal?.aborted) cancel();
7428
+ let result;
7429
+ let failure;
7430
+ let errors = [];
7431
+ try {
7432
+ result = await runResources.run(resources, execute);
7433
+ } catch (error) {
7434
+ failure = { reason: error };
7435
+ } finally {
7436
+ signal?.removeEventListener("abort", cancel);
7437
+ controller.abort(new Error("SafeJS run finished."));
7438
+ for (const release of resources.referenceReleases) release();
7439
+ resources.referenceReleases.clear();
7440
+ const outcomes = await Promise.allSettled(
7441
+ [...cleanups].map((close) => Promise.resolve().then(close))
7442
+ );
7443
+ errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
7444
+ }
7445
+ if (failure !== void 0) throw failure.reason;
7446
+ if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
7447
+ return result;
7448
+ }
7449
+
7401
7450
  // packages/safe-js/src/interp/symbols.ts
7402
7451
  var wellKnownSymbols = Object.freeze({
7403
7452
  iterator: Symbol.iterator,
@@ -7821,6 +7870,7 @@ var collectionPrototypes = /* @__PURE__ */ new WeakMap();
7821
7870
  var promisePrototypes = /* @__PURE__ */ new WeakMap();
7822
7871
  var datePrototypes = /* @__PURE__ */ new WeakMap();
7823
7872
  var arrayPrototypes = /* @__PURE__ */ new WeakMap();
7873
+ var functionPrototypes = /* @__PURE__ */ new WeakMap();
7824
7874
  var initialArrayMethods = /* @__PURE__ */ new WeakMap();
7825
7875
  var initialRegexDescriptors = /* @__PURE__ */ new WeakMap();
7826
7876
  var intrinsicPrototypeRoots = /* @__PURE__ */ new WeakMap();
@@ -7876,6 +7926,12 @@ function installObjectPrototype(budget, prototype, constructor) {
7876
7926
  intrinsicPrototypes.set(budget, prototype);
7877
7927
  registerIntrinsicPrototype(budget, prototype, constructor);
7878
7928
  }
7929
+ function installFunctionPrototype(budget, prototype) {
7930
+ functionPrototypes.set(budget, prototype);
7931
+ registerBuiltinIdentities(budget, { "%FunctionPrototype%": prototype });
7932
+ registerIntrinsicFunction(budget, prototype);
7933
+ registerIntrinsicObject(budget, materializeFunctionProperties(prototype));
7934
+ }
7879
7935
  function installBoxedPrototype(budget, prototype, constructor, kind = typeof boxedValue(prototype)) {
7880
7936
  let state = boxedPrototypes.get(budget);
7881
7937
  if (state === void 0) boxedPrototypes.set(budget, state = /* @__PURE__ */ new Map());
@@ -8000,11 +8056,14 @@ function releaseObjectPrototype(budget) {
8000
8056
  promisePrototypes.delete(budget);
8001
8057
  datePrototypes.delete(budget);
8002
8058
  arrayPrototypes.delete(budget);
8059
+ functionPrototypes.delete(budget);
8003
8060
  initialRegexDescriptors.delete(budget);
8004
8061
  intrinsicPrototypes.delete(budget);
8005
8062
  }
8006
8063
  function getSandboxPrototype(value, budget) {
8007
8064
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
8065
+ if (budget !== void 0 && isGuestClosure(value) && runResources.getStore()?.functionSourceText !== false)
8066
+ return functionPrototypes.get(budget) ?? null;
8008
8067
  if (budget !== void 0 && Array.isArray(value)) return arrayPrototypes.get(budget) ?? null;
8009
8068
  if (budget !== void 0 && isSandboxDate(value)) return datePrototypes.get(budget) ?? null;
8010
8069
  if (budget !== void 0 && isSandboxPromise(value)) return promisePrototypes.get(budget) ?? null;
@@ -8030,7 +8089,14 @@ function getSandboxPropertyDescriptor(value, key, budget) {
8030
8089
  let current = value;
8031
8090
  let depth = 0;
8032
8091
  while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxGenerator(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
8033
- const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
8092
+ const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? key === "prototype" && current.construct !== void 0 && current.boundTarget === void 0 ? materializeFunctionProperties(current) : getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
8093
+ if (properties === void 0 && isGuestClosure(current) && (key === "name" || key === "length"))
8094
+ return {
8095
+ value: key === "name" ? current.name ?? "" : current.length ?? 0,
8096
+ writable: false,
8097
+ enumerable: false,
8098
+ configurable: true
8099
+ };
8034
8100
  const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key);
8035
8101
  if (descriptor !== void 0) return descriptor;
8036
8102
  current = getSandboxPrototype(current, budget);
@@ -8141,7 +8207,7 @@ function isRawJson(value) {
8141
8207
  import { types as nodeTypes } from "node:util";
8142
8208
 
8143
8209
  // packages/safe-js/src/interp/promise-tracker.ts
8144
- import { AsyncLocalStorage } from "node:async_hooks";
8210
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
8145
8211
  var SandboxPromiseRejectionTracker = class {
8146
8212
  records = /* @__PURE__ */ new Set();
8147
8213
  recordsByPromise = /* @__PURE__ */ new WeakMap();
@@ -8218,8 +8284,8 @@ var SandboxPromiseRejectionTracker = class {
8218
8284
  return void 0;
8219
8285
  }
8220
8286
  };
8221
- var activePromiseTracker = new AsyncLocalStorage();
8222
- var fatalRejectionCleanup = new AsyncLocalStorage();
8287
+ var activePromiseTracker = new AsyncLocalStorage2();
8288
+ var fatalRejectionCleanup = new AsyncLocalStorage2();
8223
8289
  function assertPromiseExecutionAllowed() {
8224
8290
  const failure = activePromiseTracker.getStore()?.failure;
8225
8291
  if (failure !== void 0 && fatalRejectionCleanup.getStore() !== true) throw failure;
@@ -8781,55 +8847,6 @@ function isLineTerminator(character) {
8781
8847
  return character === "\n" || character === "\r" || character === "\u2028" || character === "\u2029";
8782
8848
  }
8783
8849
 
8784
- // packages/safe-js/src/interp/resources.ts
8785
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
8786
- var runResources = new AsyncLocalStorage2();
8787
- function retainValues(budget, values) {
8788
- const retained = {};
8789
- budget.setRetainedValues(retained, values);
8790
- const pending = runResources.getStore()?.referenceReleases;
8791
- const release = () => {
8792
- budget.setRetainedValues(retained, void 0);
8793
- pending?.delete(release);
8794
- };
8795
- pending?.add(release);
8796
- return release;
8797
- }
8798
- async function withRunResources(signal, execute) {
8799
- const controller = new AbortController();
8800
- const cancel = () => controller.abort(signal?.reason);
8801
- const cleanups = /* @__PURE__ */ new Set();
8802
- const resources = {
8803
- signal: controller.signal,
8804
- referenceReleases: /* @__PURE__ */ new Set(),
8805
- add(close) {
8806
- cleanups.add(close);
8807
- }
8808
- };
8809
- signal?.addEventListener("abort", cancel, { once: true });
8810
- if (signal?.aborted) cancel();
8811
- let result;
8812
- let failure;
8813
- let errors = [];
8814
- try {
8815
- result = await runResources.run(resources, execute);
8816
- } catch (error) {
8817
- failure = { reason: error };
8818
- } finally {
8819
- signal?.removeEventListener("abort", cancel);
8820
- controller.abort(new Error("SafeJS run finished."));
8821
- for (const release of resources.referenceReleases) release();
8822
- resources.referenceReleases.clear();
8823
- const outcomes = await Promise.allSettled(
8824
- [...cleanups].map((close) => Promise.resolve().then(close))
8825
- );
8826
- errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
8827
- }
8828
- if (failure !== void 0) throw failure.reason;
8829
- if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
8830
- return result;
8831
- }
8832
-
8833
8850
  // packages/safe-js/src/interp/bigint-operators.ts
8834
8851
  function bigIntOperation(operator, left, right, budget) {
8835
8852
  if (operator === ">>>") throw new TypeError("BigInts have no unsigned right shift.");
@@ -13973,7 +13990,7 @@ function getFunctionMember(target, property, options) {
13973
13990
  } else if (Object.hasOwn(current, String(property))) {
13974
13991
  return current[String(property)];
13975
13992
  }
13976
- if (isSandboxClosure(current) && !hasExplicitSandboxPrototype(current)) break;
13993
+ if (isSandboxClosure(current) && !hasExplicitSandboxPrototype(current) && getSandboxPrototype(current, options.budget) === null) break;
13977
13994
  current = getSandboxPrototype(current, options.budget);
13978
13995
  if (current !== null) {
13979
13996
  options.budget?.visitNode();
@@ -18312,7 +18329,7 @@ async function objectToPrimitive(value, budget, context, joining, hint, ordinary
18312
18329
  }
18313
18330
  }
18314
18331
  function conversionHook(value, name, budget, context) {
18315
- const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) && getSandboxPrototype(value, budget) === null || isFloat32Array(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxPromise(value) || isSandboxRegex(value) && getSandboxPrototype(value, budget) === null || isSandboxGenerator(value) || isGuestHostObject(value));
18332
+ const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) && getSandboxPrototype(value, budget) === null || isFloat32Array(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) && getSandboxPrototype(value, budget) === null || isSandboxMap(value) || isSandboxSet(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxPromise(value) || isSandboxRegex(value) && getSandboxPrototype(value, budget) === null || isSandboxGenerator(value) || isGuestHostObject(value));
18316
18333
  let current = value;
18317
18334
  let depth = 0;
18318
18335
  while (current !== null) {
@@ -23901,6 +23918,31 @@ function createUriGlobals(budget) {
23901
23918
  }));
23902
23919
  }
23903
23920
 
23921
+ // packages/safe-js/src/interp/globals/function.ts
23922
+ function createFunctionPrototype(budget) {
23923
+ const prototype = createSandboxClosure({ guest: true, sandbox: true, name: "", length: 0, call: () => void 0 });
23924
+ const properties = materializeFunctionProperties(prototype);
23925
+ Object.defineProperty(properties, "constructor", { value: void 0, writable: true, configurable: true });
23926
+ for (const [name, length] of [["call", 1], ["apply", 2], ["bind", 1], ["toString", 0]]) {
23927
+ Object.defineProperty(properties, name, {
23928
+ writable: true,
23929
+ configurable: true,
23930
+ value: createSandboxClosure({
23931
+ guest: true,
23932
+ sandbox: true,
23933
+ name,
23934
+ length,
23935
+ call: (args, context) => callFunctionMethod(context?.thisValue, name, args, {
23936
+ budget,
23937
+ callClosure: (target, values, stack, thisValue, construct, newTarget) => context?.invokeClosure !== void 0 ? context.invokeClosure(target, values, thisValue, construct, newTarget) : invokeBuiltinClosure(target, values, budget, { ...context, stack, thisValue, newTarget }, thisValue, construct)
23938
+ }, context?.stack ?? [], context)
23939
+ })
23940
+ });
23941
+ }
23942
+ setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
23943
+ installFunctionPrototype(budget, prototype);
23944
+ }
23945
+
23904
23946
  // packages/safe-js/src/interp/globals/symbol.ts
23905
23947
  var registries = /* @__PURE__ */ new WeakMap();
23906
23948
  function createSymbolGlobal(budget) {
@@ -24131,6 +24173,7 @@ function createBuiltinBindings(options) {
24131
24173
  ...createPromiseGlobals(options),
24132
24174
  ...createRegexGlobals(options)
24133
24175
  };
24176
+ createFunctionPrototype(options.budget);
24134
24177
  registerBuiltinIdentities(options.budget, bindings);
24135
24178
  return bindings;
24136
24179
  }
@@ -40948,12 +40991,12 @@ export {
40948
40991
  safeAddEvent,
40949
40992
  safeRecordException,
40950
40993
  safeEndSpan,
40994
+ runResources,
40951
40995
  defineExtension,
40952
40996
  encodeReplayData,
40953
40997
  HostOperationResumePolicyError,
40954
40998
  registerPendingHostCallPolicy,
40955
40999
  HostCallResumabilityError,
40956
- runResources,
40957
41000
  assertSnapshotInactive,
40958
41001
  isSandboxClosure,
40959
41002
  deepCopyToSandbox,
@@ -40981,4 +41024,4 @@ export {
40981
41024
  FileSnapshotBackend,
40982
41025
  run
40983
41026
  };
40984
- //# sourceMappingURL=chunk-3QW2X67U.js.map
41027
+ //# sourceMappingURL=chunk-ONR2CYEH.js.map