@poe-platform/safe-js 0.1.126 → 0.1.128

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-D4YY44EF.js";
30
+ } from "./chunk-LZEDWYSI.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8245,4 +8245,4 @@ export {
8245
8245
  parseMcpConfig,
8246
8246
  makeMcpModule
8247
8247
  };
8248
- //# sourceMappingURL=chunk-AHZ74NTE.js.map
8248
+ //# sourceMappingURL=chunk-EAKCL5OK.js.map
@@ -2525,23 +2525,21 @@ function parseTokens(tokens, compilation) {
2525
2525
  function parseModuleTokens(tokens, compilation) {
2526
2526
  return new Parser(tokens, compilation).parseModule();
2527
2527
  }
2528
- function parseExpressionTokens(tokens, compilation) {
2529
- return new Parser(tokens, compilation).parseExpressionOnly();
2530
- }
2531
2528
  var Parser = class {
2532
- constructor(tokens, compilation) {
2529
+ constructor(tokens, compilation, functionContext = "normal") {
2533
2530
  this.tokens = tokens;
2534
2531
  this.compilation = compilation;
2532
+ this.functionContext = functionContext;
2535
2533
  this.functionScopes.add(this.scopes[0]);
2536
2534
  }
2537
2535
  tokens;
2538
2536
  compilation;
2537
+ functionContext;
2539
2538
  index = 0;
2540
2539
  breakableDepth = 0;
2541
2540
  conditionalExpressionDepth = 0;
2542
2541
  ifStatementDepth = 0;
2543
2542
  loopDepth = 0;
2544
- generatorBody = false;
2545
2543
  scopes = [/* @__PURE__ */ new Map()];
2546
2544
  functionScopes = /* @__PURE__ */ new WeakSet();
2547
2545
  varNames = /* @__PURE__ */ new WeakMap();
@@ -2727,9 +2725,9 @@ var Parser = class {
2727
2725
  }
2728
2726
  parseArrowFunctionBody(params) {
2729
2727
  if (this.currentToken().type === "punctuator" && this.currentToken().value === "{") {
2730
- return this.withFunctionContext(false, () => this.parseBlockStatement(params));
2728
+ return this.withFunctionContext("normal", () => this.parseBlockStatement(params));
2731
2729
  }
2732
- return this.withFunctionContext(false, () => this.parseExpression().node);
2730
+ return this.withFunctionContext("normal", () => this.parseExpression().node);
2733
2731
  }
2734
2732
  parseBlockStatement(params, catchParam) {
2735
2733
  const start = this.expectPunctuator("{");
@@ -3333,7 +3331,7 @@ var Parser = class {
3333
3331
  return parsedParams;
3334
3332
  });
3335
3333
  const generator = generatorToken !== void 0;
3336
- const body = this.withFunctionContext(generator, () => this.parseBlockStatement(params));
3334
+ const body = this.withFunctionContext(generator ? "generator" : "normal", () => this.parseBlockStatement(params));
3337
3335
  return {
3338
3336
  type: "FunctionDeclaration",
3339
3337
  async: asyncToken !== void 0,
@@ -3368,32 +3366,34 @@ var Parser = class {
3368
3366
  };
3369
3367
  }
3370
3368
  parseArrowParameters() {
3371
- this.expectPunctuator("(");
3372
- const params = [];
3373
- if (this.consumePunctuator(")") !== void 0) {
3374
- return params;
3375
- }
3376
- while (true) {
3377
- const param = this.parseBindingElement();
3378
- params.push(param);
3379
- const comma = this.consumePunctuator(",");
3380
- if (comma === void 0) {
3381
- break;
3369
+ return this.withFunctionContext("parameters", () => {
3370
+ this.expectPunctuator("(");
3371
+ const params = [];
3372
+ if (this.consumePunctuator(")") !== void 0) {
3373
+ return params;
3382
3374
  }
3383
- if (param.type === "RestElement") {
3375
+ while (true) {
3376
+ const param = this.parseBindingElement();
3377
+ params.push(param);
3378
+ const comma = this.consumePunctuator(",");
3379
+ if (comma === void 0) {
3380
+ break;
3381
+ }
3382
+ if (param.type === "RestElement") {
3383
+ if (this.currentToken().type === "punctuator" && this.currentToken().value === ")") {
3384
+ throw unexpectedTokenError(comma);
3385
+ }
3386
+ throw new Error(
3387
+ `Rest element must be the last parameter at line ${comma.start.line}, column ${comma.start.column}.`
3388
+ );
3389
+ }
3384
3390
  if (this.currentToken().type === "punctuator" && this.currentToken().value === ")") {
3385
- throw unexpectedTokenError(comma);
3391
+ break;
3386
3392
  }
3387
- throw new Error(
3388
- `Rest element must be the last parameter at line ${comma.start.line}, column ${comma.start.column}.`
3389
- );
3390
3393
  }
3391
- if (this.currentToken().type === "punctuator" && this.currentToken().value === ")") {
3392
- break;
3393
- }
3394
- }
3395
- this.expectPunctuator(")");
3396
- return params;
3394
+ this.expectPunctuator(")");
3395
+ return params;
3396
+ });
3397
3397
  }
3398
3398
  parseBindingElement() {
3399
3399
  if (this.consumePunctuator("...") !== void 0) {
@@ -3947,7 +3947,7 @@ var Parser = class {
3947
3947
  };
3948
3948
  }
3949
3949
  if (token.type === "keyword" && token.value === "yield") {
3950
- if (!this.generatorBody) {
3950
+ if (this.functionContext !== "generator") {
3951
3951
  throw new Error(
3952
3952
  `yield is only valid inside a generator body at line ${token.start.line}, column ${token.start.column}.`
3953
3953
  );
@@ -3974,11 +3974,16 @@ var Parser = class {
3974
3974
  };
3975
3975
  }
3976
3976
  if (token.type === "keyword" && token.value === "await") {
3977
- if (this.generatorBody) {
3977
+ if (this.functionContext === "generator") {
3978
3978
  throw new Error(
3979
3979
  `generators cannot await; use a regular async function at line ${token.start.line}, column ${token.start.column}.`
3980
3980
  );
3981
3981
  }
3982
+ if (this.functionContext === "parameters") {
3983
+ throw new Error(
3984
+ `await is not valid in function parameters at line ${token.start.line}, column ${token.start.column}.`
3985
+ );
3986
+ }
3982
3987
  this.index += 1;
3983
3988
  const argument = this.parseUnaryExpression();
3984
3989
  return {
@@ -4103,7 +4108,7 @@ var Parser = class {
4103
4108
  if (this.currentToken().type === "template") {
4104
4109
  const quasi = createTemplateLiteral(
4105
4110
  this.currentToken(),
4106
- { allowMalformedEscapes: true },
4111
+ { allowMalformedEscapes: true, functionContext: this.functionContext },
4107
4112
  this.compilation
4108
4113
  );
4109
4114
  this.index += 1;
@@ -4190,7 +4195,11 @@ var Parser = class {
4190
4195
  if (token.type === "template") {
4191
4196
  this.index += 1;
4192
4197
  return {
4193
- node: createTemplateLiteral(token, { allowMalformedEscapes: false }, this.compilation),
4198
+ node: createTemplateLiteral(
4199
+ token,
4200
+ { allowMalformedEscapes: false, functionContext: this.functionContext },
4201
+ this.compilation
4202
+ ),
4194
4203
  parenthesized: false
4195
4204
  };
4196
4205
  }
@@ -4306,7 +4315,7 @@ var Parser = class {
4306
4315
  return parsedParams;
4307
4316
  });
4308
4317
  const generator = generatorToken !== void 0;
4309
- const body = this.withFunctionContext(generator, () => this.parseBlockStatement(params));
4318
+ const body = this.withFunctionContext(generator ? "generator" : "normal", () => this.parseBlockStatement(params));
4310
4319
  return {
4311
4320
  type: "FunctionExpression",
4312
4321
  async: asyncToken !== void 0,
@@ -4550,7 +4559,7 @@ var Parser = class {
4550
4559
  }
4551
4560
  return parsedParams;
4552
4561
  });
4553
- const body = this.withFunctionContext(false, () => this.parseBlockStatement(params));
4562
+ const body = this.withFunctionContext("normal", () => this.parseBlockStatement(params));
4554
4563
  return {
4555
4564
  type: "FunctionExpression",
4556
4565
  async: asyncToken !== void 0,
@@ -4955,19 +4964,19 @@ var Parser = class {
4955
4964
  hasReturnArgument(returnToken, nextToken) {
4956
4965
  return !(hasLineBreakBetween(returnToken, nextToken) || nextToken.type === "punctuator" && (nextToken.value === ";" || nextToken.value === "}") || nextToken.type === "eof");
4957
4966
  }
4958
- withFunctionContext(generatorBody, callback) {
4967
+ withFunctionContext(functionContext, callback) {
4959
4968
  const previousBreakableDepth = this.breakableDepth;
4960
4969
  const previousLoopDepth = this.loopDepth;
4961
- const previousGeneratorBody = this.generatorBody;
4970
+ const previousFunctionContext = this.functionContext;
4962
4971
  this.breakableDepth = 0;
4963
4972
  this.loopDepth = 0;
4964
- this.generatorBody = generatorBody;
4973
+ this.functionContext = functionContext;
4965
4974
  try {
4966
4975
  return callback();
4967
4976
  } finally {
4968
4977
  this.breakableDepth = previousBreakableDepth;
4969
4978
  this.loopDepth = previousLoopDepth;
4970
- this.generatorBody = previousGeneratorBody;
4979
+ this.functionContext = previousFunctionContext;
4971
4980
  }
4972
4981
  }
4973
4982
  withLoopContext(callback) {
@@ -5402,7 +5411,7 @@ function createLiteralFromToken(token) {
5402
5411
  }
5403
5412
  return createKeywordLiteral(token);
5404
5413
  }
5405
- function createTemplateLiteral(token, options = { allowMalformedEscapes: false }, compilation) {
5414
+ function createTemplateLiteral(token, options, compilation) {
5406
5415
  const raw = token.value;
5407
5416
  const expressions = [];
5408
5417
  const quasis = [];
@@ -5422,6 +5431,7 @@ function createTemplateLiteral(token, options = { allowMalformedEscapes: false }
5422
5431
  parseEmbeddedExpression(
5423
5432
  raw.slice(expressionStart, expressionEnd),
5424
5433
  positionWithinRaw(token.start, raw, expressionStart),
5434
+ options.functionContext,
5425
5435
  compilation
5426
5436
  )
5427
5437
  );
@@ -5784,13 +5794,13 @@ function decodeHexEscape(value, start) {
5784
5794
  end: index + 2
5785
5795
  };
5786
5796
  }
5787
- function parseEmbeddedExpression(source, base, compilation) {
5797
+ function parseEmbeddedExpression(source, base, functionContext, compilation) {
5788
5798
  const tokens = tokenize(source, { allowRegexLiterals: true, compilation }).map((token) => ({
5789
5799
  ...token,
5790
5800
  start: rebasePosition(token.start, base),
5791
5801
  end: rebasePosition(token.end, base)
5792
5802
  }));
5793
- return parseExpressionTokens(tokens, compilation);
5803
+ return new Parser(tokens, compilation, functionContext).parseExpressionOnly();
5794
5804
  }
5795
5805
  function findRegexLiteral(node) {
5796
5806
  if (node === null || node === void 0) {
@@ -8257,7 +8267,7 @@ function isCounter(value) {
8257
8267
  }
8258
8268
 
8259
8269
  // packages/safe-js/src/interp/cancel.ts
8260
- import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
8270
+ import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
8261
8271
 
8262
8272
  // packages/safe-js/src/interp/builtin-call.ts
8263
8273
  async function invokeBuiltinClosure(closure, args, budget, context, thisValue, construct = false) {
@@ -8617,6 +8627,55 @@ function toMatchArray(match, input) {
8617
8627
  return result;
8618
8628
  }
8619
8629
 
8630
+ // packages/safe-js/src/interp/resources.ts
8631
+ import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
8632
+ var runResources = new AsyncLocalStorage3();
8633
+ function retainValues(budget, values) {
8634
+ const retained = {};
8635
+ budget.setRetainedValues(retained, values);
8636
+ const pending = runResources.getStore()?.referenceReleases;
8637
+ const release = () => {
8638
+ budget.setRetainedValues(retained, void 0);
8639
+ pending?.delete(release);
8640
+ };
8641
+ pending?.add(release);
8642
+ return release;
8643
+ }
8644
+ async function withRunResources(signal, execute) {
8645
+ const controller = new AbortController();
8646
+ const cancel = () => controller.abort(signal?.reason);
8647
+ const cleanups = /* @__PURE__ */ new Set();
8648
+ const resources = {
8649
+ signal: controller.signal,
8650
+ referenceReleases: /* @__PURE__ */ new Set(),
8651
+ add(close) {
8652
+ cleanups.add(close);
8653
+ }
8654
+ };
8655
+ signal?.addEventListener("abort", cancel, { once: true });
8656
+ if (signal?.aborted) cancel();
8657
+ let result;
8658
+ let failure;
8659
+ let errors = [];
8660
+ try {
8661
+ result = await runResources.run(resources, execute);
8662
+ } catch (error) {
8663
+ failure = { reason: error };
8664
+ } finally {
8665
+ signal?.removeEventListener("abort", cancel);
8666
+ controller.abort(new Error("SafeJS run finished."));
8667
+ for (const release of resources.referenceReleases) release();
8668
+ resources.referenceReleases.clear();
8669
+ const outcomes = await Promise.allSettled(
8670
+ [...cleanups].map((close) => Promise.resolve().then(close))
8671
+ );
8672
+ errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
8673
+ }
8674
+ if (failure !== void 0) throw failure.reason;
8675
+ if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
8676
+ return result;
8677
+ }
8678
+
8620
8679
  // packages/safe-js/src/interp/string-coercion.ts
8621
8680
  var defaultStringHook = /* @__PURE__ */ Symbol("defaultStringHook");
8622
8681
  var defaultValueHook = /* @__PURE__ */ Symbol("defaultValueHook");
@@ -8703,9 +8762,10 @@ async function defaultToString(value, budget, context, joining) {
8703
8762
  }
8704
8763
  if (joining.has(value)) return "";
8705
8764
  joining.add(value);
8765
+ let text = "";
8766
+ const release = retainValues(budget, () => [text]);
8706
8767
  try {
8707
8768
  const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
8708
- let text = "";
8709
8769
  for (let index = 0; index < length; index++) {
8710
8770
  budget.visitNode();
8711
8771
  const element = ownDataValue(value, String(index));
@@ -8714,15 +8774,21 @@ async function defaultToString(value, budget, context, joining) {
8714
8774
  }
8715
8775
  return text;
8716
8776
  } finally {
8777
+ release();
8717
8778
  joining.delete(value);
8718
8779
  }
8719
8780
  }
8720
8781
  if (sandboxErrorTypes.has(value)) {
8721
8782
  const nameValue = ownDataValue(value, "name");
8722
8783
  const name = nameValue === void 0 ? "Error" : await sandboxString(nameValue, budget, context, joining);
8723
- const messageValue = ownDataValue(value, "message");
8724
- const message = messageValue === void 0 ? "" : await sandboxString(messageValue, budget, context, joining);
8725
- return name === "" ? message : message === "" ? name : `${name}: ${message}`;
8784
+ const release = retainValues(budget, () => [name]);
8785
+ try {
8786
+ const messageValue = ownDataValue(value, "message");
8787
+ const message = messageValue === void 0 ? "" : await sandboxString(messageValue, budget, context, joining);
8788
+ return name === "" ? message : message === "" ? name : `${name}: ${message}`;
8789
+ } finally {
8790
+ release();
8791
+ }
8726
8792
  }
8727
8793
  return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
8728
8794
  }
@@ -9332,8 +9398,8 @@ function syncIterator(iterator) {
9332
9398
  }
9333
9399
 
9334
9400
  // packages/safe-js/src/interp/jobs.ts
9335
- import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
9336
- var activeJob = new AsyncLocalStorage3();
9401
+ import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
9402
+ var activeJob = new AsyncLocalStorage4();
9337
9403
  var SandboxJobQueue = class {
9338
9404
  running = false;
9339
9405
  pending = [];
@@ -10162,7 +10228,7 @@ function isPromiseLike(value) {
10162
10228
  }
10163
10229
 
10164
10230
  // packages/safe-js/src/interp/cancel.ts
10165
- var activeCancellation = new AsyncLocalStorage4();
10231
+ var activeCancellation = new AsyncLocalStorage5();
10166
10232
  var sandboxPromises = /* @__PURE__ */ new WeakSet();
10167
10233
  var cancelableOutcomes = /* @__PURE__ */ new WeakMap();
10168
10234
  function withCancellationSignal(signal, task) {
@@ -23880,44 +23946,6 @@ function hoistVarDeclarations(node, scope) {
23880
23946
  }
23881
23947
  }
23882
23948
 
23883
- // packages/safe-js/src/interp/resources.ts
23884
- import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
23885
- var runResources = new AsyncLocalStorage5();
23886
- async function withRunResources(signal, execute) {
23887
- const controller = new AbortController();
23888
- const cancel = () => controller.abort(signal?.reason);
23889
- const cleanups = /* @__PURE__ */ new Set();
23890
- const resources = {
23891
- signal: controller.signal,
23892
- referenceReleases: /* @__PURE__ */ new Set(),
23893
- add(close) {
23894
- cleanups.add(close);
23895
- }
23896
- };
23897
- signal?.addEventListener("abort", cancel, { once: true });
23898
- if (signal?.aborted) cancel();
23899
- let result;
23900
- let failure;
23901
- let errors = [];
23902
- try {
23903
- result = await runResources.run(resources, execute);
23904
- } catch (error) {
23905
- failure = { reason: error };
23906
- } finally {
23907
- signal?.removeEventListener("abort", cancel);
23908
- controller.abort(new Error("SafeJS run finished."));
23909
- for (const release of resources.referenceReleases) release();
23910
- resources.referenceReleases.clear();
23911
- const outcomes = await Promise.allSettled(
23912
- [...cleanups].map((close) => Promise.resolve().then(close))
23913
- );
23914
- errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
23915
- }
23916
- if (failure !== void 0) throw failure.reason;
23917
- if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
23918
- return result;
23919
- }
23920
-
23921
23949
  // packages/safe-js/src/interp/methods/array.ts
23922
23950
  var arrayLikeSources = /* @__PURE__ */ new WeakMap();
23923
23951
  var activeArrayCallbacks = /* @__PURE__ */ new WeakMap();
@@ -28133,17 +28161,6 @@ async function evaluateMemberAccess(node, context, consume) {
28133
28161
  release();
28134
28162
  }
28135
28163
  }
28136
- function retainValues(budget, values) {
28137
- const retained = {};
28138
- budget.setRetainedValues(retained, values);
28139
- const pending = runResources.getStore()?.referenceReleases;
28140
- const release = () => {
28141
- budget.setRetainedValues(retained, void 0);
28142
- pending?.delete(release);
28143
- };
28144
- pending?.add(release);
28145
- return release;
28146
- }
28147
28164
  async function evaluateMemberProperty(node, context) {
28148
28165
  const property = await evaluateNode(node, context);
28149
28166
  if (property.kind !== "normal") {
@@ -33435,6 +33452,7 @@ export {
33435
33452
  HostOperationResumePolicyError,
33436
33453
  registerPendingHostCallPolicy,
33437
33454
  HostCallResumabilityError,
33455
+ runResources,
33438
33456
  assertSnapshotInactive,
33439
33457
  isSandboxClosure,
33440
33458
  deepCopyToSandbox,
@@ -33451,7 +33469,6 @@ export {
33451
33469
  validateSnapshotMigration,
33452
33470
  restore,
33453
33471
  lint,
33454
- runResources,
33455
33472
  declareHostOperation,
33456
33473
  createSeededRandom,
33457
33474
  createReplayableRandom,
@@ -33463,4 +33480,4 @@ export {
33463
33480
  FileSnapshotBackend,
33464
33481
  run
33465
33482
  };
33466
- //# sourceMappingURL=chunk-D4YY44EF.js.map
33483
+ //# sourceMappingURL=chunk-LZEDWYSI.js.map