@poe-platform/safe-js 0.1.248 → 0.1.249

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-FAZ46PGV.js";
30
+ } from "./chunk-IKHGVNT5.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-HTFX2QV6.js.map
8252
+ //# sourceMappingURL=chunk-2I5DAEWD.js.map
@@ -7859,7 +7859,8 @@ function registerIntrinsicPrototype(budget, prototype, constructor) {
7859
7859
  }
7860
7860
  function registerIntrinsicFunction(budget, closure) {
7861
7861
  if (closure.name === void 0) throw new TypeError("Intrinsic functions require an installation name.");
7862
- registerBuiltinIdentities(budget, { [closure.name]: closure });
7862
+ if (getIntrinsicIdentity(closure) === void 0)
7863
+ registerBuiltinIdentities(budget, { [closure.name]: closure });
7863
7864
  trackIntrinsicState(budget, closure, closure, [closure]);
7864
7865
  }
7865
7866
  function trackIntrinsicState(budget, root, owner, targets) {
@@ -21306,6 +21307,7 @@ function serializeDate(value, encode) {
21306
21307
 
21307
21308
  // packages/safe-js/src/snapshot/dump-format.ts
21308
21309
  var DUMP_FORMAT_VERSION = 2;
21310
+ var inMemoryRunSnapshots = /* @__PURE__ */ new WeakSet();
21309
21311
  var EXECUTION_SEMANTICS = "jobs-v8";
21310
21312
  var SKIP_VALUE = /* @__PURE__ */ Symbol("SafeJS.skip-dump-value");
21311
21313
  function serializeSafeJSSnapshot(snapshot) {
@@ -21736,10 +21738,11 @@ async function parseJsonWithReviver(text, reviver, budget, context) {
21736
21738
  // packages/safe-js/src/interp/globals/console-json.ts
21737
21739
  function createConsoleJsonGlobals(options) {
21738
21740
  const sink = options.sink ?? console;
21739
- return {
21741
+ const globals = {
21740
21742
  JSON: {
21741
21743
  rawJSON: createSandboxClosure({
21742
21744
  sandbox: true,
21745
+ guest: true,
21743
21746
  name: "rawJSON",
21744
21747
  length: 1,
21745
21748
  call: async ([value], context) => {
@@ -21750,12 +21753,14 @@ function createConsoleJsonGlobals(options) {
21750
21753
  }),
21751
21754
  isRawJSON: createSandboxClosure({
21752
21755
  sandbox: true,
21756
+ guest: true,
21753
21757
  name: "isRawJSON",
21754
21758
  length: 1,
21755
21759
  call: ([value]) => isRawJson(value)
21756
21760
  }),
21757
21761
  parse: createSandboxClosure({
21758
21762
  sandbox: true,
21763
+ guest: true,
21759
21764
  length: 2,
21760
21765
  call: async ([text, reviver], context) => {
21761
21766
  const converted = sandboxString(text, options.budget, context);
@@ -21770,6 +21775,8 @@ function createConsoleJsonGlobals(options) {
21770
21775
  }),
21771
21776
  stringify: createSandboxClosure({
21772
21777
  sandbox: true,
21778
+ guest: true,
21779
+ length: 3,
21773
21780
  call: async ([value, replacer, indent], context) => stringifyJson(value, replacer, indent, options.budget, context),
21774
21781
  name: "stringify"
21775
21782
  })
@@ -21832,6 +21839,9 @@ function createConsoleJsonGlobals(options) {
21832
21839
  }
21833
21840
  )
21834
21841
  };
21842
+ registerBuiltinIdentities(options.budget, { JSON: globals.JSON });
21843
+ for (const method of Object.values(globals.JSON)) registerIntrinsicFunction(options.budget, method);
21844
+ return globals;
21835
21845
  }
21836
21846
  async function stringifyJson(value, replacer, indent, budget, context) {
21837
21847
  const allocation = {};
@@ -26332,7 +26342,13 @@ var SnapshotMismatchError = class extends Error {
26332
26342
  };
26333
26343
  function restore(snapshot, options, owner) {
26334
26344
  assertSnapshotInactive(snapshot);
26335
- validateDumpEnvelope(snapshot);
26345
+ try {
26346
+ validateDumpEnvelope(snapshot);
26347
+ } catch (error) {
26348
+ if (!(error instanceof SnapshotValidationError) || error.code !== "invalidState" || !inMemoryRunSnapshots.has(snapshot)) throw error;
26349
+ snapshot = JSON.parse(serializeSafeJSSnapshot(snapshot));
26350
+ validateDumpEnvelope(snapshot);
26351
+ }
26336
26352
  validateSnapshotMigration(snapshot.migration, snapshot.sourceHash, owner);
26337
26353
  if (snapshot.executionSemantics !== EXECUTION_SEMANTICS && snapshot.executionSemantics !== "jobs-v6" && snapshot.executionSemantics !== "jobs-v7" && (snapshot.executionSemantics !== void 0 || snapshot.promiseReplay !== void 0 || snapshot.replay !== void 0 || snapshot.initialInputs !== void 0)) {
26338
26354
  throw new SnapshotValidationError(
@@ -39004,7 +39020,7 @@ function run(source, options = {}) {
39004
39020
  runResources.getStore().functionSourceText = executionSemantics === EXECUTION_SEMANTICS;
39005
39021
  const convertInitialInput = (convert) => executionSemantics === "jobs-v6" ? convert() : promiseReplayContext.exit(convert);
39006
39022
  if (restoredSnapshot !== void 0) {
39007
- leaveSnapshotRun = enterSnapshotRun(restoredSnapshot);
39023
+ leaveSnapshotRun = enterSnapshotRun(options.snapshot ?? restoredSnapshot);
39008
39024
  }
39009
39025
  promiseReplay.attachBudget(budget);
39010
39026
  const filename = options.filename ?? "<input>";
@@ -39430,7 +39446,7 @@ function createExecutableNode(module) {
39430
39446
  };
39431
39447
  }
39432
39448
  function createRunSnapshot(input) {
39433
- return {
39449
+ const snapshot = {
39434
39450
  version: DUMP_FORMAT_VERSION,
39435
39451
  executionSemantics: input.executionSemantics,
39436
39452
  sourceHash: input.sourceHash,
@@ -39450,6 +39466,8 @@ function createRunSnapshot(input) {
39450
39466
  state: input.random.generator.snapshot()
39451
39467
  }
39452
39468
  };
39469
+ inMemoryRunSnapshots.add(snapshot);
39470
+ return snapshot;
39453
39471
  }
39454
39472
  function readHostCallSnapshot(snapshot) {
39455
39473
  if (snapshot === void 0 || !Array.isArray(snapshot.hostCalls)) {
@@ -39547,4 +39565,4 @@ export {
39547
39565
  FileSnapshotBackend,
39548
39566
  run
39549
39567
  };
39550
- //# sourceMappingURL=chunk-FAZ46PGV.js.map
39568
+ //# sourceMappingURL=chunk-IKHGVNT5.js.map