poe-code 14.0.61 → 14.0.62

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.
Files changed (39) hide show
  1. package/dist/index.js +218 -70
  2. package/dist/index.js.map +4 -4
  3. package/dist/metafile.json +1 -1
  4. package/package.json +1 -1
  5. package/packages/safe-js/dist/chunks/{chunk-VAYQP2VZ.js → chunk-F7TJSPDZ.js} +7 -3
  6. package/packages/safe-js/dist/chunks/chunk-F7TJSPDZ.js.map +7 -0
  7. package/packages/safe-js/dist/chunks/{chunk-ZTGKRKQH.js → chunk-VKGWGZBH.js} +181 -66
  8. package/packages/safe-js/dist/chunks/chunk-VKGWGZBH.js.map +7 -0
  9. package/packages/safe-js/dist/cli.js +2 -2
  10. package/packages/safe-js/dist/core.js +1 -1
  11. package/packages/safe-js/dist/index.js +2 -2
  12. package/packages/safe-js/dist/interp/async.js +3 -0
  13. package/packages/safe-js/dist/interp/function-string.d.ts +2 -0
  14. package/packages/safe-js/dist/interp/function-string.js +21 -0
  15. package/packages/safe-js/dist/interp/globals/misc.js +11 -12
  16. package/packages/safe-js/dist/interp/globals/numeric-parsers.d.ts +5 -0
  17. package/packages/safe-js/dist/interp/globals/numeric-parsers.js +47 -0
  18. package/packages/safe-js/dist/interp/globals/object-array.js +2 -10
  19. package/packages/safe-js/dist/interp/interpreter.js +1 -0
  20. package/packages/safe-js/dist/interp/methods/function.d.ts +2 -0
  21. package/packages/safe-js/dist/interp/methods/function.js +10 -1
  22. package/packages/safe-js/dist/interp/resources.d.ts +1 -0
  23. package/packages/safe-js/dist/interp/string-coercion.js +3 -0
  24. package/packages/safe-js/dist/interp/values.d.ts +3 -0
  25. package/packages/safe-js/dist/interp/values.js +3 -0
  26. package/packages/safe-js/dist/migrate.js +1 -1
  27. package/packages/safe-js/dist/parse/function-source.d.ts +7 -0
  28. package/packages/safe-js/dist/parse/function-source.js +1 -0
  29. package/packages/safe-js/dist/parse/hash.d.ts +2 -2
  30. package/packages/safe-js/dist/parse/hash.js +23 -9
  31. package/packages/safe-js/dist/parse/parser.js +36 -23
  32. package/packages/safe-js/dist/restore.js +2 -1
  33. package/packages/safe-js/dist/run.js +16 -5
  34. package/packages/safe-js/dist/snapshot/dump-format.d.ts +1 -1
  35. package/packages/safe-js/dist/snapshot/dump-format.js +1 -1
  36. package/packages/safe-js/dist/snapshot/migration.js +2 -2
  37. package/packages/safe-js/dist/snapshot/restore.js +2 -0
  38. package/packages/safe-js/dist/chunks/chunk-VAYQP2VZ.js.map +0 -7
  39. package/packages/safe-js/dist/chunks/chunk-ZTGKRKQH.js.map +0 -7
package/dist/index.js CHANGED
@@ -107711,7 +107711,7 @@ function registerUsageCommand(program, container) {
107711
107711
  const modelName = entry.bot_name.length > modelMaxWidth ? entry.bot_name.slice(0, modelMaxWidth - 1) + "\u2026" : entry.bot_name;
107712
107712
  const costText = `$${entry.cost_usd} (${entry.cost_points} points)`;
107713
107713
  const bd = entry.cost_breakdown_in_points;
107714
- const parseTokens2 = (s) => {
107714
+ const parseTokens = (s) => {
107715
107715
  if (!s) return "-";
107716
107716
  const start = s.indexOf("(");
107717
107717
  const end = s.indexOf(" tokens");
@@ -107722,9 +107722,9 @@ function registerUsageCommand(program, container) {
107722
107722
  Date: theme.muted(formatted),
107723
107723
  Model: theme.accent(modelName),
107724
107724
  Cost: entry.cost_points < 0 ? theme.error(costText) : theme.success(costText),
107725
- Input: theme.muted(parseTokens2(bd?.Input)),
107726
- Output: theme.muted(parseTokens2(bd?.Output)),
107727
- Cached: theme.muted(parseTokens2(bd?.["Cache discount"]))
107725
+ Input: theme.muted(parseTokens(bd?.Input)),
107726
+ Output: theme.muted(parseTokens(bd?.Output)),
107727
+ Cached: theme.muted(parseTokens(bd?.["Cache discount"]))
107728
107728
  };
107729
107729
  };
107730
107730
  let totalFetched = 0;
@@ -121455,6 +121455,15 @@ var init_assign_ids = __esm({
121455
121455
  }
121456
121456
  });
121457
121457
 
121458
+ // packages/safe-js/src/parse/function-source.ts
121459
+ var functionSources;
121460
+ var init_function_source = __esm({
121461
+ "packages/safe-js/src/parse/function-source.ts"() {
121462
+ "use strict";
121463
+ functionSources = /* @__PURE__ */ new WeakMap();
121464
+ }
121465
+ });
121466
+
121458
121467
  // packages/safe-js/src/parse/format-error.ts
121459
121468
  function formatParseError(source, filename, error3) {
121460
121469
  const location = parseErrorLocation(error3.message);
@@ -122095,7 +122104,11 @@ function parse15(source, filename = "<input>", owner) {
122095
122104
  const compilation = new CompileScope(owner);
122096
122105
  try {
122097
122106
  const result = assignIds(
122098
- parseTokens(tokenize3(source, { allowRegexLiterals: true, compilation }), compilation)
122107
+ new Parser(
122108
+ tokenize3(source, { allowRegexLiterals: true, compilation }),
122109
+ source,
122110
+ compilation
122111
+ ).parseTopLevel()
122099
122112
  );
122100
122113
  const regexLiteral = findRegexLiteral(result);
122101
122114
  if (regexLiteral !== void 0) {
@@ -122121,7 +122134,11 @@ function parseModule(source, filename = "<input>", owner) {
122121
122134
  const compilation = new CompileScope(owner);
122122
122135
  try {
122123
122136
  return assignIds(
122124
- parseModuleTokens(tokenize3(source, { allowRegexLiterals: true, compilation }), compilation)
122137
+ new Parser(
122138
+ tokenize3(source, { allowRegexLiterals: true, compilation }),
122139
+ source,
122140
+ compilation
122141
+ ).parseModule()
122125
122142
  );
122126
122143
  } catch (error3) {
122127
122144
  if (error3 instanceof DisallowedSyntaxError || error3 instanceof SandboxError) {
@@ -122139,7 +122156,11 @@ function parseExecutableModule(source, filename = "<input>", owner) {
122139
122156
  const compilation = new CompileScope(owner);
122140
122157
  try {
122141
122158
  const result = assignIds(
122142
- parseModuleTokens(tokenize3(source, { allowRegexLiterals: true, compilation }), compilation)
122159
+ new Parser(
122160
+ tokenize3(source, { allowRegexLiterals: true, compilation }),
122161
+ source,
122162
+ compilation
122163
+ ).parseModule()
122143
122164
  );
122144
122165
  throwIfImportMetaAssignment(result);
122145
122166
  return result;
@@ -122155,12 +122176,6 @@ function parseExecutableModule(source, filename = "<input>", owner) {
122155
122176
  compilation.dispose();
122156
122177
  }
122157
122178
  }
122158
- function parseTokens(tokens, compilation) {
122159
- return new Parser(tokens, compilation).parseTopLevel();
122160
- }
122161
- function parseModuleTokens(tokens, compilation) {
122162
- return new Parser(tokens, compilation).parseModule();
122163
- }
122164
122179
  function createIdentifier2(token) {
122165
122180
  return {
122166
122181
  type: "Identifier",
@@ -122469,6 +122484,7 @@ function createTemplateLiteral(token, options, compilation) {
122469
122484
  raw.slice(expressionStart, expressionEnd),
122470
122485
  positionWithinRaw(token.start, raw, expressionStart),
122471
122486
  options.functionContext,
122487
+ options.source,
122472
122488
  compilation
122473
122489
  )
122474
122490
  );
@@ -122831,13 +122847,13 @@ function decodeHexEscape(value, start) {
122831
122847
  end: index + 2
122832
122848
  };
122833
122849
  }
122834
- function parseEmbeddedExpression(source, base, functionContext, compilation) {
122850
+ function parseEmbeddedExpression(source, base, functionContext, fullSource, compilation) {
122835
122851
  const tokens = tokenize3(source, { allowRegexLiterals: true, compilation }).map((token) => ({
122836
122852
  ...token,
122837
122853
  start: rebasePosition(token.start, base),
122838
122854
  end: rebasePosition(token.end, base)
122839
122855
  }));
122840
- return new Parser(tokens, compilation, functionContext).parseExpressionOnly();
122856
+ return new Parser(tokens, fullSource, compilation, functionContext).parseExpressionOnly();
122841
122857
  }
122842
122858
  function findRegexLiteral(node) {
122843
122859
  if (node === null || node === void 0) {
@@ -122983,6 +122999,7 @@ var init_parser3 = __esm({
122983
122999
  init_bindings();
122984
123000
  init_tokenizer2();
122985
123001
  init_assign_ids();
123002
+ init_function_source();
122986
123003
  init_format_error();
122987
123004
  init_parse_export();
122988
123005
  init_parse_import_meta();
@@ -123022,13 +123039,15 @@ var init_parser3 = __esm({
123022
123039
  "while"
123023
123040
  ]);
123024
123041
  Parser = class {
123025
- constructor(tokens, compilation, functionContext = "normal") {
123042
+ constructor(tokens, source, compilation, functionContext = "normal") {
123026
123043
  this.tokens = tokens;
123044
+ this.source = source;
123027
123045
  this.compilation = compilation;
123028
123046
  this.functionContext = functionContext;
123029
123047
  this.functionScopes.add(this.scopes[0]);
123030
123048
  }
123031
123049
  tokens;
123050
+ source;
123032
123051
  compilation;
123033
123052
  functionContext;
123034
123053
  index = 0;
@@ -123039,6 +123058,14 @@ var init_parser3 = __esm({
123039
123058
  scopes = [/* @__PURE__ */ new Map()];
123040
123059
  functionScopes = /* @__PURE__ */ new WeakSet();
123041
123060
  varNames = /* @__PURE__ */ new WeakMap();
123061
+ withFunctionSource(node) {
123062
+ functionSources.set(node, {
123063
+ text: this.source,
123064
+ start: node.span.start.offset,
123065
+ end: node.span.end.offset
123066
+ });
123067
+ return node;
123068
+ }
123042
123069
  parseTopLevel() {
123043
123070
  if (this.isExportToken(this.currentToken())) {
123044
123071
  throw new DisallowedSyntaxError("export", this.currentToken().start);
@@ -123180,14 +123207,14 @@ var init_parser3 = __esm({
123180
123207
  });
123181
123208
  this.expectPunctuator("=>");
123182
123209
  const body = this.parseArrowFunctionBody(params);
123183
- return {
123210
+ return this.withFunctionSource({
123184
123211
  type: "ArrowFunctionExpression",
123185
123212
  async: isAsync,
123186
123213
  body,
123187
123214
  expression: body.type !== "BlockStatement",
123188
123215
  params,
123189
123216
  span: createSpan2(start, body.span.end)
123190
- };
123217
+ });
123191
123218
  }
123192
123219
  parseConditionalExpression() {
123193
123220
  if (this.conditionalExpressionDepth >= MAX_CONDITIONAL_EXPRESSION_DEPTH) {
@@ -123827,8 +123854,11 @@ var init_parser3 = __esm({
123827
123854
  return parsedParams;
123828
123855
  });
123829
123856
  const generator = generatorToken !== void 0;
123830
- const body = this.withFunctionContext(generator ? "generator" : "normal", () => this.parseBlockStatement(params));
123831
- return {
123857
+ const body = this.withFunctionContext(
123858
+ generator ? "generator" : "normal",
123859
+ () => this.parseBlockStatement(params)
123860
+ );
123861
+ return this.withFunctionSource({
123832
123862
  type: "FunctionDeclaration",
123833
123863
  async: asyncToken !== void 0,
123834
123864
  body,
@@ -123836,7 +123866,7 @@ var init_parser3 = __esm({
123836
123866
  id,
123837
123867
  params,
123838
123868
  span: createSpan2(asyncToken?.start ?? functionToken.start, body.span.end)
123839
- };
123869
+ });
123840
123870
  }
123841
123871
  parseVariableDeclarator(kind) {
123842
123872
  const id = this.parseBindingTarget();
@@ -124604,7 +124634,11 @@ var init_parser3 = __esm({
124604
124634
  if (this.currentToken().type === "template") {
124605
124635
  const quasi = createTemplateLiteral(
124606
124636
  this.currentToken(),
124607
- { allowMalformedEscapes: true, functionContext: this.functionContext },
124637
+ {
124638
+ allowMalformedEscapes: true,
124639
+ functionContext: this.functionContext,
124640
+ source: this.source
124641
+ },
124608
124642
  this.compilation
124609
124643
  );
124610
124644
  this.index += 1;
@@ -124693,7 +124727,11 @@ var init_parser3 = __esm({
124693
124727
  return {
124694
124728
  node: createTemplateLiteral(
124695
124729
  token,
124696
- { allowMalformedEscapes: false, functionContext: this.functionContext },
124730
+ {
124731
+ allowMalformedEscapes: false,
124732
+ functionContext: this.functionContext,
124733
+ source: this.source
124734
+ },
124697
124735
  this.compilation
124698
124736
  ),
124699
124737
  parenthesized: false
@@ -124778,7 +124816,8 @@ var init_parser3 = __esm({
124778
124816
  break;
124779
124817
  }
124780
124818
  const optional = this.consumePunctuator("?.");
124781
- if (optional !== void 0) throw new DisallowedSyntaxError("new optional chain", optional.start);
124819
+ if (optional !== void 0)
124820
+ throw new DisallowedSyntaxError("new optional chain", optional.start);
124782
124821
  const args = this.consumePunctuator("(") === void 0 ? [] : this.parseArguments();
124783
124822
  const end = this.previousToken();
124784
124823
  return {
@@ -124811,8 +124850,11 @@ var init_parser3 = __esm({
124811
124850
  return parsedParams;
124812
124851
  });
124813
124852
  const generator = generatorToken !== void 0;
124814
- const body = this.withFunctionContext(generator ? "generator" : "normal", () => this.parseBlockStatement(params));
124815
- return {
124853
+ const body = this.withFunctionContext(
124854
+ generator ? "generator" : "normal",
124855
+ () => this.parseBlockStatement(params)
124856
+ );
124857
+ return this.withFunctionSource({
124816
124858
  type: "FunctionExpression",
124817
124859
  async: asyncToken !== void 0,
124818
124860
  body,
@@ -124820,7 +124862,7 @@ var init_parser3 = __esm({
124820
124862
  id,
124821
124863
  params,
124822
124864
  span: createSpan2(asyncToken?.start ?? functionToken.start, body.span.end)
124823
- };
124865
+ });
124824
124866
  }
124825
124867
  parseArrayExpression() {
124826
124868
  const start = this.expectPunctuator("[");
@@ -125056,7 +125098,7 @@ var init_parser3 = __esm({
125056
125098
  return parsedParams;
125057
125099
  });
125058
125100
  const body = this.withFunctionContext("normal", () => this.parseBlockStatement(params));
125059
- return {
125101
+ return this.withFunctionSource({
125060
125102
  type: "FunctionExpression",
125061
125103
  async: asyncToken !== void 0,
125062
125104
  body,
@@ -125065,7 +125107,7 @@ var init_parser3 = __esm({
125065
125107
  method: true,
125066
125108
  params,
125067
125109
  span: createSpan2(asyncToken?.start ?? methodStart, body.span.end)
125068
- };
125110
+ });
125069
125111
  }
125070
125112
  parseIdentifierName() {
125071
125113
  const token = this.currentToken();
@@ -125624,19 +125666,19 @@ var init_parser3 = __esm({
125624
125666
  });
125625
125667
 
125626
125668
  // packages/safe-js/src/parse/hash.ts
125627
- function hashSource(source, owner) {
125669
+ function hashSource(source, owner, includeFunctionSource = true) {
125628
125670
  try {
125629
- return hashParsedAst(parse15(source, "<input>", owner));
125671
+ return hashParsedAst(parse15(source, "<input>", owner), includeFunctionSource);
125630
125672
  } catch (error3) {
125631
125673
  if (error3 instanceof SandboxError) throw error3;
125632
- return hashParsedAst(parseModule(source, "<input>", owner));
125674
+ return hashParsedAst(parseModule(source, "<input>", owner), includeFunctionSource);
125633
125675
  }
125634
125676
  }
125635
- function hashParsedAst(ast) {
125677
+ function hashParsedAst(ast, includeFunctionSource = true) {
125636
125678
  let hash = FNV_OFFSET_BASIS;
125637
125679
  visit(ast);
125638
125680
  return hash.toString(16).padStart(8, "0");
125639
- function visit(value, includeTemplateRaw = false) {
125681
+ function visit(value, includeTemplateRaw = false, enclosingSource) {
125640
125682
  if (value === null) {
125641
125683
  write2("null");
125642
125684
  return;
@@ -125648,7 +125690,7 @@ function hashParsedAst(ast) {
125648
125690
  if (Array.isArray(value)) {
125649
125691
  write2("[");
125650
125692
  for (const entry of value) {
125651
- visit(entry, includeTemplateRaw);
125693
+ visit(entry, includeTemplateRaw, enclosingSource);
125652
125694
  write2(",");
125653
125695
  }
125654
125696
  write2("]");
@@ -125666,12 +125708,23 @@ function hashParsedAst(ast) {
125666
125708
  return;
125667
125709
  case "object": {
125668
125710
  const record2 = value;
125711
+ const source = includeFunctionSource ? functionSources.get(value) : void 0;
125712
+ if (source !== void 0 && !(enclosingSource !== void 0 && source.text === enclosingSource.text && source.start >= enclosingSource.start && source.end <= enclosingSource.end)) {
125713
+ write2("function-source:");
125714
+ write2(String(source.end - source.start));
125715
+ write2(":");
125716
+ write2(source.text, source.start, source.end);
125717
+ }
125669
125718
  const keys = Object.keys(value).filter((key3) => shouldHashKey(record2, key3, includeTemplateRaw)).sort();
125670
125719
  write2("{");
125671
125720
  for (const key3 of keys) {
125672
125721
  write2(JSON.stringify(key3));
125673
125722
  write2(":");
125674
- visit(record2[key3], shouldIncludeTemplateRaw(record2, key3, includeTemplateRaw));
125723
+ visit(
125724
+ record2[key3],
125725
+ shouldIncludeTemplateRaw(record2, key3, includeTemplateRaw),
125726
+ source ?? enclosingSource
125727
+ );
125675
125728
  write2(",");
125676
125729
  }
125677
125730
  write2("}");
@@ -125681,8 +125734,8 @@ function hashParsedAst(ast) {
125681
125734
  throw new TypeError(`Unsupported AST value type: ${typeof value}`);
125682
125735
  }
125683
125736
  }
125684
- function write2(chunk) {
125685
- for (let index = 0; index < chunk.length; index += 1) {
125737
+ function write2(chunk, start = 0, end = chunk.length) {
125738
+ for (let index = start; index < end; index += 1) {
125686
125739
  hash ^= chunk.charCodeAt(index);
125687
125740
  hash = Math.imul(hash, FNV_PRIME) >>> 0;
125688
125741
  }
@@ -125712,6 +125765,7 @@ var init_hash = __esm({
125712
125765
  "use strict";
125713
125766
  init_parser3();
125714
125767
  init_budget2();
125768
+ init_function_source();
125715
125769
  FNV_OFFSET_BASIS = 2166136261;
125716
125770
  FNV_PRIME = 16777619;
125717
125771
  IGNORED_KEYS = /* @__PURE__ */ new Set(["nodeId", "raw", "span"]);
@@ -128668,6 +128722,28 @@ var init_resources = __esm({
128668
128722
  }
128669
128723
  });
128670
128724
 
128725
+ // packages/safe-js/src/interp/function-string.ts
128726
+ function functionString(value) {
128727
+ if (runResources.getStore()?.functionSourceText === false) return "[object Object]";
128728
+ const source = value.sourceRange;
128729
+ if (source !== void 0) return source.text.slice(source.start, source.end);
128730
+ let name = value.boundTarget === void 0 ? value.name?.split("#").at(-1) ?? "" : "";
128731
+ for (let index = 0; index < name.length; index++) {
128732
+ const code = name.charCodeAt(index);
128733
+ if (!(code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95 || index > 0 && code >= 48 && code <= 57)) {
128734
+ name = "";
128735
+ break;
128736
+ }
128737
+ }
128738
+ return `function ${name}() { [native code] }`;
128739
+ }
128740
+ var init_function_string = __esm({
128741
+ "packages/safe-js/src/interp/function-string.ts"() {
128742
+ "use strict";
128743
+ init_resources();
128744
+ }
128745
+ });
128746
+
128671
128747
  // packages/safe-js/src/interp/string-coercion.ts
128672
128748
  function sandboxNumber(value, budget, context) {
128673
128749
  if (value === null || typeof value !== "object") {
@@ -128733,6 +128809,7 @@ function conversionHook(value, name, budget) {
128733
128809
  return void 0;
128734
128810
  }
128735
128811
  async function defaultToString(value, budget, context, joining) {
128812
+ if (isSandboxClosure(value)) return budget.allocateString(functionString(value));
128736
128813
  if (isSandboxMap(value)) return "[object Map]";
128737
128814
  if (isSandboxSet(value)) return "[object Set]";
128738
128815
  if (isSandboxCollectionIterator(value)) return collectionIteratorState(value).collectionKind === "map" ? "[object Map Iterator]" : "[object Set Iterator]";
@@ -128803,6 +128880,7 @@ var init_string_coercion = __esm({
128803
128880
  init_object_model();
128804
128881
  init_regex();
128805
128882
  init_resources();
128883
+ init_function_string();
128806
128884
  init_values();
128807
128885
  defaultStringHook = /* @__PURE__ */ Symbol("defaultStringHook");
128808
128886
  defaultValueHook = /* @__PURE__ */ Symbol("defaultValueHook");
@@ -130498,6 +130576,9 @@ function createSandboxClosure(input) {
130498
130576
  enumerable: false,
130499
130577
  value: true
130500
130578
  });
130579
+ if (input.sourceRange !== void 0) {
130580
+ Object.defineProperty(closure, "sourceRange", { value: input.sourceRange });
130581
+ }
130501
130582
  if (input.sandbox === true) {
130502
130583
  Object.defineProperty(closure, "sandbox", { value: true });
130503
130584
  }
@@ -131808,7 +131889,7 @@ var init_dump_format = __esm({
131808
131889
  init_float32array();
131809
131890
  init_date();
131810
131891
  DUMP_FORMAT_VERSION = 1;
131811
- EXECUTION_SEMANTICS = "jobs-v7";
131892
+ EXECUTION_SEMANTICS = "jobs-v8";
131812
131893
  SKIP_VALUE = /* @__PURE__ */ Symbol("SafeJS.skip-dump-value");
131813
131894
  }
131814
131895
  });
@@ -132289,11 +132370,11 @@ var init_validation = __esm({
132289
132370
 
132290
132371
  // packages/safe-js/src/snapshot/migration.ts
132291
132372
  function validateMigrationSemantics(value) {
132292
- if (!["jobs-v1", "jobs-v2", "jobs-v3", "jobs-v4", "jobs-v5", "jobs-v6", "jobs-v7"].includes(
132373
+ if (!["jobs-v1", "jobs-v2", "jobs-v3", "jobs-v4", "jobs-v5", "jobs-v6", "jobs-v7", "jobs-v8"].includes(
132293
132374
  value
132294
132375
  ))
132295
132376
  throw new TypeError(
132296
- "Migration requires a supported execution-semantics marker (jobs-v1 through jobs-v7)."
132377
+ "Migration requires a supported execution-semantics marker (jobs-v1 through jobs-v8)."
132297
132378
  );
132298
132379
  }
132299
132380
  function validateMigrationJournal(sourceHash, replay, hostCalls = [], owner) {
@@ -132398,14 +132479,18 @@ function restore2(snapshot2, options, owner) {
132398
132479
  assertSnapshotInactive(snapshot2);
132399
132480
  validateDumpEnvelope(snapshot2);
132400
132481
  validateSnapshotMigration(snapshot2.migration, snapshot2.sourceHash, owner);
132401
- if (snapshot2.executionSemantics !== EXECUTION_SEMANTICS && snapshot2.executionSemantics !== "jobs-v6" && (snapshot2.executionSemantics !== void 0 || snapshot2.promiseReplay !== void 0 || snapshot2.replay !== void 0 || snapshot2.initialInputs !== void 0)) {
132482
+ if (snapshot2.executionSemantics !== EXECUTION_SEMANTICS && snapshot2.executionSemantics !== "jobs-v6" && snapshot2.executionSemantics !== "jobs-v7" && (snapshot2.executionSemantics !== void 0 || snapshot2.promiseReplay !== void 0 || snapshot2.replay !== void 0 || snapshot2.initialInputs !== void 0)) {
132402
132483
  throw new SnapshotValidationError(
132403
132484
  "unsupportedVersion",
132404
132485
  "$.executionSemantics",
132405
132486
  "incompatible execution semantics; resume with the SafeJS version that created this snapshot. Migration requires explicit reconciliation, not changing its version marker."
132406
132487
  );
132407
132488
  }
132408
- const currentSourceHash = hashSource(options.source, owner);
132489
+ const currentSourceHash = hashSource(
132490
+ options.source,
132491
+ owner,
132492
+ snapshot2.executionSemantics !== "jobs-v6" && snapshot2.executionSemantics !== "jobs-v7"
132493
+ );
132409
132494
  if (snapshot2.sourceHash !== currentSourceHash) {
132410
132495
  throw new SnapshotMismatchError(snapshot2.sourceHash, currentSourceHash);
132411
132496
  }
@@ -144958,12 +145043,14 @@ function getFunctionMember(target, property, options) {
144958
145043
  if (property === "length") {
144959
145044
  return target.length;
144960
145045
  }
145046
+ if (property === "toString" && runResources.getStore()?.functionSourceText === false) return void 0;
144961
145047
  if (!isFunctionMethodName(property)) {
144962
145048
  return void 0;
144963
145049
  }
144964
145050
  return createSandboxClosure({
144965
145051
  sandbox: true,
144966
145052
  name: `Function#${property}`,
145053
+ ...property === "toString" ? { length: 0 } : {},
144967
145054
  call: (args, context) => callFunctionMethod(context?.thisValue, property, args, options, context?.stack ?? [])
144968
145055
  });
144969
145056
  }
@@ -144974,6 +145061,10 @@ function callFunctionMethod(target, methodName, args, options, stack) {
144974
145061
  if (!isSandboxClosure(target)) {
144975
145062
  throw new TypeError(`Function#${methodName} requires a callable receiver.`);
144976
145063
  }
145064
+ if (methodName === "toString") {
145065
+ const text5 = functionString(target);
145066
+ return options.budget?.allocateString(text5) ?? text5;
145067
+ }
144977
145068
  const thisValue = args[0];
144978
145069
  if (methodName === "bind") {
144979
145070
  const boundArgs = args.slice(1);
@@ -145014,7 +145105,9 @@ var init_function = __esm({
145014
145105
  "use strict";
145015
145106
  init_values();
145016
145107
  init_object_model();
145017
- functionMethodNames = /* @__PURE__ */ new Set(["apply", "bind", "call"]);
145108
+ init_function_string();
145109
+ init_resources();
145110
+ functionMethodNames = /* @__PURE__ */ new Set(["apply", "bind", "call", "toString"]);
145018
145111
  }
145019
145112
  });
145020
145113
 
@@ -149244,6 +149337,7 @@ function createSetMethodOptions(context) {
149244
149337
  }
149245
149338
  function createFunctionMethodOptions(context) {
149246
149339
  return {
149340
+ budget: context.budget,
149247
149341
  callClosure: (closure, args, stack, thisValue, construct) => invokeSandboxClosure(closure, args, context, stack, void 0, thisValue, construct)
149248
149342
  };
149249
149343
  }
@@ -149577,6 +149671,7 @@ function createInterpretedClosure(node, context, evaluateNode3) {
149577
149671
  return isConstructResult(result) ? result : thisValue;
149578
149672
  } : void 0;
149579
149673
  const closure = createSandboxClosure({
149674
+ sourceRange: functionSources.get(node),
149580
149675
  guest: true,
149581
149676
  sandbox: true,
149582
149677
  length: getFunctionLength(node.params),
@@ -149639,6 +149734,7 @@ function executeAsyncFunction(execute2, budget, signal) {
149639
149734
  }
149640
149735
  function createGeneratorClosure(node, context, evaluateNode3) {
149641
149736
  return createSandboxClosure({
149737
+ sourceRange: functionSources.get(node),
149642
149738
  guest: true,
149643
149739
  generator: true,
149644
149740
  sandbox: true,
@@ -149830,6 +149926,7 @@ var init_async = __esm({
149830
149926
  init_var_hoist();
149831
149927
  init_interpreter();
149832
149928
  init_object_model();
149929
+ init_function_source();
149833
149930
  init_bindings();
149834
149931
  init_values();
149835
149932
  }
@@ -151292,6 +151389,54 @@ var init_regex2 = __esm({
151292
151389
  }
151293
151390
  });
151294
151391
 
151392
+ // packages/safe-js/src/interp/globals/numeric-parsers.ts
151393
+ function createNumericParsers(budget) {
151394
+ return {
151395
+ parseInt: createSandboxClosure({
151396
+ sandbox: true,
151397
+ name: "parseInt",
151398
+ call: ([value, radix], context) => {
151399
+ const parse18 = (text6) => {
151400
+ const release2 = retainValues(budget, () => [text6]);
151401
+ let convertedRadix;
151402
+ try {
151403
+ convertedRadix = sandboxNumber(radix, budget, context);
151404
+ } catch (error3) {
151405
+ release2();
151406
+ throw error3;
151407
+ }
151408
+ if (typeof convertedRadix === "number") {
151409
+ try {
151410
+ return globalThis.parseInt(text6, convertedRadix);
151411
+ } finally {
151412
+ release2();
151413
+ }
151414
+ }
151415
+ return convertedRadix.then((number) => globalThis.parseInt(text6, number)).finally(release2);
151416
+ };
151417
+ const text5 = sandboxString(value, budget, context);
151418
+ return typeof text5 === "string" ? parse18(text5) : text5.then(parse18);
151419
+ }
151420
+ }),
151421
+ parseFloat: createSandboxClosure({
151422
+ sandbox: true,
151423
+ name: "parseFloat",
151424
+ call: ([value], context) => {
151425
+ const text5 = sandboxString(value, budget, context);
151426
+ return typeof text5 === "string" ? globalThis.parseFloat(text5) : text5.then(globalThis.parseFloat);
151427
+ }
151428
+ })
151429
+ };
151430
+ }
151431
+ var init_numeric_parsers = __esm({
151432
+ "packages/safe-js/src/interp/globals/numeric-parsers.ts"() {
151433
+ "use strict";
151434
+ init_resources();
151435
+ init_string_coercion();
151436
+ init_values();
151437
+ }
151438
+ });
151439
+
151295
151440
  // packages/safe-js/src/interp/globals/misc.ts
151296
151441
  function createMiscGlobals(options) {
151297
151442
  return {
@@ -151300,24 +151445,21 @@ function createMiscGlobals(options) {
151300
151445
  call: ([value], context) => structuredCloneSandboxValue(value, options.budget, context?.compilation),
151301
151446
  name: "structuredClone"
151302
151447
  }),
151303
- parseInt: createSandboxClosure({
151304
- sandbox: true,
151305
- call: (args) => Reflect.apply(globalThis.parseInt, globalThis, [...args]),
151306
- name: "parseInt"
151307
- }),
151308
- parseFloat: createSandboxClosure({
151309
- sandbox: true,
151310
- call: (args) => Reflect.apply(globalThis.parseFloat, globalThis, [...args]),
151311
- name: "parseFloat"
151312
- }),
151448
+ ...createNumericParsers(options.budget),
151313
151449
  isNaN: createSandboxClosure({
151314
151450
  sandbox: true,
151315
- call: ([value]) => globalThis.isNaN(value),
151451
+ call: ([value], context) => {
151452
+ const number = sandboxNumber(value, options.budget, context);
151453
+ return typeof number === "number" ? Number.isNaN(number) : number.then(Number.isNaN);
151454
+ },
151316
151455
  name: "isNaN"
151317
151456
  }),
151318
151457
  isFinite: createSandboxClosure({
151319
151458
  sandbox: true,
151320
- call: ([value]) => globalThis.isFinite(value),
151459
+ call: ([value], context) => {
151460
+ const number = sandboxNumber(value, options.budget, context);
151461
+ return typeof number === "number" ? Number.isFinite(number) : number.then(Number.isFinite);
151462
+ },
151321
151463
  name: "isFinite"
151322
151464
  })
151323
151465
  };
@@ -151368,6 +151510,8 @@ var init_misc = __esm({
151368
151510
  init_collection_iterator();
151369
151511
  init_graph_depth();
151370
151512
  init_compile_guard();
151513
+ init_numeric_parsers();
151514
+ init_string_coercion();
151371
151515
  init_values();
151372
151516
  }
151373
151517
  });
@@ -151580,16 +151724,7 @@ function createObjectArrayGlobals(options) {
151580
151724
  call: ([value]) => typeof value === "number" && Number.isInteger(value),
151581
151725
  name: "isInteger"
151582
151726
  }),
151583
- parseInt: createSandboxClosure({
151584
- sandbox: true,
151585
- call: (args) => Reflect.apply(Number.parseInt, Number, [...args]),
151586
- name: "parseInt"
151587
- }),
151588
- parseFloat: createSandboxClosure({
151589
- sandbox: true,
151590
- call: (args) => Reflect.apply(Number.parseFloat, Number, [...args]),
151591
- name: "parseFloat"
151592
- }),
151727
+ ...createNumericParsers(options.budget),
151593
151728
  isSafeInteger: createSandboxClosure({
151594
151729
  sandbox: true,
151595
151730
  call: ([value]) => typeof value === "number" && Number.isSafeInteger(value),
@@ -151865,6 +152000,7 @@ var init_object_array = __esm({
151865
152000
  init_interpreter();
151866
152001
  init_iteration();
151867
152002
  init_string_coercion();
152003
+ init_numeric_parsers();
151868
152004
  init_object_model();
151869
152005
  init_values();
151870
152006
  }
@@ -153502,7 +153638,8 @@ function run(source, options = {}) {
153502
153638
  options.signal?.addEventListener("abort", captureCancellationSnapshot, { once: true });
153503
153639
  try {
153504
153640
  const restoredSnapshot = options.snapshot === void 0 ? void 0 : restore2(options.snapshot, { source }, operation.owner);
153505
- const executionSemantics = restoredSnapshot?.executionSemantics === "jobs-v6" ? "jobs-v6" : EXECUTION_SEMANTICS;
153641
+ const executionSemantics = restoredSnapshot?.executionSemantics === "jobs-v6" || restoredSnapshot?.executionSemantics === "jobs-v7" ? restoredSnapshot.executionSemantics : EXECUTION_SEMANTICS;
153642
+ runResources.getStore().functionSourceText = executionSemantics === EXECUTION_SEMANTICS;
153506
153643
  const convertInitialInput = (convert) => executionSemantics === "jobs-v6" ? convert() : promiseReplayContext.exit(convert);
153507
153644
  if (restoredSnapshot !== void 0) {
153508
153645
  leaveSnapshotRun = enterSnapshotRun(restoredSnapshot);
@@ -153511,7 +153648,7 @@ function run(source, options = {}) {
153511
153648
  const filename = options.filename ?? "<input>";
153512
153649
  const module = parseExecutableModule(source, filename, operation.owner);
153513
153650
  promiseReplay.validateNodes(module);
153514
- const sourceHash = findRegexLiteral(module) === void 0 ? hashSource(source, operation.owner) : hashParsedAst(module);
153651
+ const sourceHash = findRegexLiteral(module) === void 0 ? hashSource(source, operation.owner, executionSemantics === EXECUTION_SEMANTICS) : hashParsedAst(module, executionSemantics === EXECUTION_SEMANTICS);
153515
153652
  const hostCalls = new HostCallJournal(
153516
153653
  sourceHash,
153517
153654
  readHostCallSnapshot(restoredSnapshot),
@@ -153538,7 +153675,14 @@ function run(source, options = {}) {
153538
153675
  lifecycle
153539
153676
  })
153540
153677
  );
153541
- const builtinBindings = createBuiltinBindings({ compileOwner: operation.owner, budget, hostCalls, sink: options.sink, random: random?.generator.next, clock: options.clock });
153678
+ const builtinBindings = createBuiltinBindings({
153679
+ compileOwner: operation.owner,
153680
+ budget,
153681
+ hostCalls,
153682
+ sink: options.sink,
153683
+ random: random?.generator.next,
153684
+ clock: options.clock
153685
+ });
153542
153686
  const importMeta = convertInitialInput(
153543
153687
  () => deepCopyToSandbox(options.importMeta ?? {})
153544
153688
  );
@@ -154053,7 +154197,11 @@ function inspectSnapshotMigration(snapshot2, options) {
154053
154197
  validateSnapshotData(snapshot2);
154054
154198
  validateDumpEnvelope(snapshot2);
154055
154199
  validateMigrationSemantics(snapshot2.executionSemantics);
154056
- const sourceHash = hashSource(options.source);
154200
+ const sourceHash = hashSource(
154201
+ options.source,
154202
+ void 0,
154203
+ snapshot2.executionSemantics === EXECUTION_SEMANTICS
154204
+ );
154057
154205
  if (snapshot2.sourceHash !== sourceHash)
154058
154206
  throw new TypeError(
154059
154207
  `Migration requires the original executable source (checkpoint hash ${snapshot2.sourceHash}, supplied ${sourceHash}). Preserve the checkpoint; do not replace its hash.`