@poe-platform/safe-js 0.1.725 → 0.1.726

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 (57) hide show
  1. package/README.md +12 -0
  2. package/dist/safe-js/chunks/{chunk-QU2F65UQ.js → chunk-4VWGTW5F.js} +2 -2
  3. package/dist/safe-js/chunks/{chunk-V2ESZF34.js → chunk-EYIWCEOM.js} +4 -4
  4. package/dist/safe-js/chunks/{chunk-YRALPIEZ.js → chunk-JVWED75K.js} +2 -2
  5. package/dist/safe-js/chunks/{chunk-PKRGP34X.js → chunk-LAULA6ZA.js} +6 -6
  6. package/dist/safe-js/chunks/{chunk-O2CPPE6M.js → chunk-MFPMOTC3.js} +2 -2
  7. package/dist/safe-js/chunks/{chunk-FYSWUSHN.js → chunk-MLXEO7D4.js} +3 -3
  8. package/dist/safe-js/chunks/{chunk-Y7LSEUWV.js → chunk-QPG4Q7NQ.js} +3 -3
  9. package/dist/safe-js/chunks/{chunk-KOO6YGQG.js → chunk-T2HKPVB3.js} +77 -29
  10. package/dist/safe-js/chunks/chunk-T2HKPVB3.js.map +7 -0
  11. package/dist/safe-js/chunks/{chunk-6OE64YMG.js → chunk-TVAZK5TQ.js} +2 -2
  12. package/dist/safe-js/chunks/{chunk-K6F5QLZQ.js → chunk-UBLJ5GBD.js} +3 -3
  13. package/dist/safe-js/chunks/{chunk-ECTNNLWN.js → chunk-ZB7G7QNP.js} +4 -4
  14. package/dist/safe-js/chunks/{chunk-6YSHQ5ET.js → chunk-ZI6RZ6ZM.js} +2 -2
  15. package/dist/safe-js/chunks/{chunk-HG5QP5UC.js → chunk-ZUWFLRFV.js} +2 -2
  16. package/dist/safe-js/chunks/{cli-runtime-5HVEFMDB.js → cli-runtime-BUNU5UJA.js} +13 -13
  17. package/dist/safe-js/chunks/{dump-VKSKINUI.js → dump-NJBLBIHN.js} +4 -4
  18. package/dist/safe-js/chunks/{fs-CZ2TAPHK.js → fs-KSDQMVL3.js} +4 -4
  19. package/dist/safe-js/chunks/harness-4TVG72ZC.js +10 -0
  20. package/dist/safe-js/chunks/mcp-ABD5LZLV.js +11 -0
  21. package/dist/safe-js/chunks/migration-file-S6N7VAXE.js +12 -0
  22. package/dist/safe-js/chunks/restore-R2BQQ743.js +13 -0
  23. package/dist/safe-js/chunks/run-4W5TVAD4.js +17 -0
  24. package/dist/safe-js/chunks/runtime-modules-XRIAOBSC.js +10 -0
  25. package/dist/safe-js/cli.js +2 -2
  26. package/dist/safe-js/core.js +7 -7
  27. package/dist/safe-js/index.js +13 -13
  28. package/dist/safe-js/parse/tokenizer.d.ts +1 -1
  29. package/package.json +2 -2
  30. package/dist/safe-js/chunks/chunk-KOO6YGQG.js.map +0 -7
  31. package/dist/safe-js/chunks/harness-WNABEKDH.js +0 -10
  32. package/dist/safe-js/chunks/mcp-ZZDGN5CA.js +0 -11
  33. package/dist/safe-js/chunks/migration-file-QVT4W464.js +0 -12
  34. package/dist/safe-js/chunks/restore-PTIQHGKI.js +0 -13
  35. package/dist/safe-js/chunks/run-WNR7QYUJ.js +0 -17
  36. package/dist/safe-js/chunks/runtime-modules-YEOG62RU.js +0 -10
  37. /package/dist/safe-js/chunks/{chunk-QU2F65UQ.js.map → chunk-4VWGTW5F.js.map} +0 -0
  38. /package/dist/safe-js/chunks/{chunk-V2ESZF34.js.map → chunk-EYIWCEOM.js.map} +0 -0
  39. /package/dist/safe-js/chunks/{chunk-YRALPIEZ.js.map → chunk-JVWED75K.js.map} +0 -0
  40. /package/dist/safe-js/chunks/{chunk-PKRGP34X.js.map → chunk-LAULA6ZA.js.map} +0 -0
  41. /package/dist/safe-js/chunks/{chunk-O2CPPE6M.js.map → chunk-MFPMOTC3.js.map} +0 -0
  42. /package/dist/safe-js/chunks/{chunk-FYSWUSHN.js.map → chunk-MLXEO7D4.js.map} +0 -0
  43. /package/dist/safe-js/chunks/{chunk-Y7LSEUWV.js.map → chunk-QPG4Q7NQ.js.map} +0 -0
  44. /package/dist/safe-js/chunks/{chunk-6OE64YMG.js.map → chunk-TVAZK5TQ.js.map} +0 -0
  45. /package/dist/safe-js/chunks/{chunk-K6F5QLZQ.js.map → chunk-UBLJ5GBD.js.map} +0 -0
  46. /package/dist/safe-js/chunks/{chunk-ECTNNLWN.js.map → chunk-ZB7G7QNP.js.map} +0 -0
  47. /package/dist/safe-js/chunks/{chunk-6YSHQ5ET.js.map → chunk-ZI6RZ6ZM.js.map} +0 -0
  48. /package/dist/safe-js/chunks/{chunk-HG5QP5UC.js.map → chunk-ZUWFLRFV.js.map} +0 -0
  49. /package/dist/safe-js/chunks/{cli-runtime-5HVEFMDB.js.map → cli-runtime-BUNU5UJA.js.map} +0 -0
  50. /package/dist/safe-js/chunks/{dump-VKSKINUI.js.map → dump-NJBLBIHN.js.map} +0 -0
  51. /package/dist/safe-js/chunks/{fs-CZ2TAPHK.js.map → fs-KSDQMVL3.js.map} +0 -0
  52. /package/dist/safe-js/chunks/{harness-WNABEKDH.js.map → harness-4TVG72ZC.js.map} +0 -0
  53. /package/dist/safe-js/chunks/{mcp-ZZDGN5CA.js.map → mcp-ABD5LZLV.js.map} +0 -0
  54. /package/dist/safe-js/chunks/{migration-file-QVT4W464.js.map → migration-file-S6N7VAXE.js.map} +0 -0
  55. /package/dist/safe-js/chunks/{restore-PTIQHGKI.js.map → restore-R2BQQ743.js.map} +0 -0
  56. /package/dist/safe-js/chunks/{run-WNR7QYUJ.js.map → run-4W5TVAD4.js.map} +0 -0
  57. /package/dist/safe-js/chunks/{runtime-modules-YEOG62RU.js.map → runtime-modules-XRIAOBSC.js.map} +0 -0
package/README.md CHANGED
@@ -53,6 +53,18 @@ console.log(result.returnValue);
53
53
 
54
54
  Scripts have no ambient `process`, `require`, `fetch`, or filesystem access. Host functions still execute with the host's privileges. Register only the capabilities the script needs; this is not OS or process isolation.
55
55
 
56
+ `new Promise(executor)` is supported, as are the Promise static helpers and
57
+ `then`, `catch`, and `finally`. The executor runs synchronously with `resolve`
58
+ and `reject`; its return value is ignored, thrown errors reject the promise,
59
+ and the first resolve or reject call wins. Resolving adopts promises and
60
+ thenables; resolving a promise with itself rejects with a `TypeError`.
61
+ Executor work uses the interpreter's existing budgets, and budget exhaustion
62
+ remains fatal even after settlement. For example,
63
+ `await run("return await new Promise(resolve => resolve(42));")` returns a
64
+ successful result with `returnValue: 42`. Browser event and timer adapters
65
+ require the host to grant those capabilities; Promise construction does not
66
+ provide ambient browser APIs.
67
+
56
68
  ```js
57
69
  const result = await run(`
58
70
  function Counter(value) { this.value = value; }
@@ -39,7 +39,7 @@ import {
39
39
  sandboxErrorTypes,
40
40
  syntaxDiagnostics,
41
41
  templateRealms
42
- } from "./chunk-KOO6YGQG.js";
42
+ } from "./chunk-T2HKPVB3.js";
43
43
 
44
44
  // packages/safe-js/src/interp/native-promise-properties.ts
45
45
  import { types } from "node:util";
@@ -49338,4 +49338,4 @@ authorization of the copyright holder.
49338
49338
  SPDX-License-Identifier: Unicode-3.0
49339
49339
 
49340
49340
  */
49341
- //# sourceMappingURL=chunk-QU2F65UQ.js.map
49341
+ //# sourceMappingURL=chunk-4VWGTW5F.js.map
@@ -2,7 +2,7 @@ import {
2
2
  hashParsedAst,
3
3
  hashSource,
4
4
  validateSnapshotMigration
5
- } from "./chunk-Y7LSEUWV.js";
5
+ } from "./chunk-QPG4Q7NQ.js";
6
6
  import {
7
7
  SnapshotValidationError,
8
8
  assertSnapshotInactive,
@@ -15,13 +15,13 @@ import {
15
15
  validateGuestFunctionAst,
16
16
  validateRuntimeSnapshotDescriptors,
17
17
  validateTemplateObjects
18
- } from "./chunk-QU2F65UQ.js";
18
+ } from "./chunk-4VWGTW5F.js";
19
19
  import {
20
20
  ParseError,
21
21
  parseExecutableModule,
22
22
  parseModule,
23
23
  replaceErrorStack
24
- } from "./chunk-KOO6YGQG.js";
24
+ } from "./chunk-T2HKPVB3.js";
25
25
 
26
26
  // packages/safe-js/src/restore.ts
27
27
  var SnapshotMismatchError = class extends Error {
@@ -111,4 +111,4 @@ export {
111
111
  SnapshotMismatchError,
112
112
  restore
113
113
  };
114
- //# sourceMappingURL=chunk-V2ESZF34.js.map
114
+ //# sourceMappingURL=chunk-EYIWCEOM.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isSandboxClosure
3
- } from "./chunk-QU2F65UQ.js";
3
+ } from "./chunk-4VWGTW5F.js";
4
4
 
5
5
  // packages/safe-js/src/lint/runtime-modules.ts
6
6
  var AsyncFunction = (async () => void 0).constructor;
@@ -34,4 +34,4 @@ function isAsyncRuntimeExport(value) {
34
34
  export {
35
35
  createLintModulesFromRuntimeRegistry
36
36
  };
37
- //# sourceMappingURL=chunk-YRALPIEZ.js.map
37
+ //# sourceMappingURL=chunk-JVWED75K.js.map
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  restore
3
- } from "./chunk-V2ESZF34.js";
3
+ } from "./chunk-EYIWCEOM.js";
4
4
  import {
5
5
  attachDumpController,
6
6
  createDumpController
7
- } from "./chunk-FYSWUSHN.js";
7
+ } from "./chunk-MLXEO7D4.js";
8
8
  import {
9
9
  getOwnErrorCode,
10
10
  hasOwnErrorCode
@@ -12,7 +12,7 @@ import {
12
12
  import {
13
13
  hashParsedAst,
14
14
  hashSource
15
- } from "./chunk-Y7LSEUWV.js";
15
+ } from "./chunk-QPG4Q7NQ.js";
16
16
  import {
17
17
  DUMP_FORMAT_VERSION,
18
18
  EXECUTION_SEMANTICS,
@@ -100,7 +100,7 @@ import {
100
100
  withSandboxPromiseRejectionTracker,
101
101
  wrapCallerInjectedBindings,
102
102
  wrapCancelableBindings
103
- } from "./chunk-QU2F65UQ.js";
103
+ } from "./chunk-4VWGTW5F.js";
104
104
  import {
105
105
  Budget,
106
106
  CompileScope,
@@ -115,7 +115,7 @@ import {
115
115
  parseSourceModule,
116
116
  replaceErrorStack,
117
117
  safeAddEvent
118
- } from "./chunk-KOO6YGQG.js";
118
+ } from "./chunk-T2HKPVB3.js";
119
119
 
120
120
  // packages/safe-js/src/realm.ts
121
121
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
@@ -2825,4 +2825,4 @@ export {
2825
2825
  UnhandledRejectionError,
2826
2826
  run
2827
2827
  };
2828
- //# sourceMappingURL=chunk-PKRGP34X.js.map
2828
+ //# sourceMappingURL=chunk-LAULA6ZA.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  deepCopyToSandbox
3
- } from "./chunk-QU2F65UQ.js";
3
+ } from "./chunk-4VWGTW5F.js";
4
4
 
5
5
  // packages/safe-js/src/modules/harness.ts
6
6
  function makeHarnessModule(frontmatter, meta) {
@@ -52,4 +52,4 @@ ${prompt}`;
52
52
  export {
53
53
  makeHarnessModule
54
54
  };
55
- //# sourceMappingURL=chunk-O2CPPE6M.js.map
55
+ //# sourceMappingURL=chunk-MFPMOTC3.js.map
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  SnapshotNotReadyError,
3
3
  serializeSafeJSSnapshot
4
- } from "./chunk-QU2F65UQ.js";
4
+ } from "./chunk-4VWGTW5F.js";
5
5
  import {
6
6
  SandboxError
7
- } from "./chunk-KOO6YGQG.js";
7
+ } from "./chunk-T2HKPVB3.js";
8
8
 
9
9
  // packages/safe-js/src/snapshot/dump.ts
10
10
  var RUN_DUMP_CONTROLLER = /* @__PURE__ */ Symbol("SafeJS.run-dump-controller");
@@ -195,4 +195,4 @@ export {
195
195
  dumpCurrent,
196
196
  serializeRunSnapshot
197
197
  };
198
- //# sourceMappingURL=chunk-FYSWUSHN.js.map
198
+ //# sourceMappingURL=chunk-MLXEO7D4.js.map
@@ -2,14 +2,14 @@ import {
2
2
  HostCallJournal,
3
3
  decodeReplayData,
4
4
  validateSnapshotData
5
- } from "./chunk-QU2F65UQ.js";
5
+ } from "./chunk-4VWGTW5F.js";
6
6
  import {
7
7
  CompileScope,
8
8
  SandboxError,
9
9
  functionSources,
10
10
  parse,
11
11
  parseModule
12
- } from "./chunk-KOO6YGQG.js";
12
+ } from "./chunk-T2HKPVB3.js";
13
13
 
14
14
  // packages/safe-js/src/parse/hash.ts
15
15
  var FNV_OFFSET_BASIS = 2166136261;
@@ -219,4 +219,4 @@ export {
219
219
  validateMigrationReconciliation,
220
220
  validateSnapshotMigration
221
221
  };
222
- //# sourceMappingURL=chunk-Y7LSEUWV.js.map
222
+ //# sourceMappingURL=chunk-QPG4Q7NQ.js.map
@@ -2009,8 +2009,30 @@ var stride = 3;
2009
2009
  var legacyEscape = 256;
2010
2010
  var tokenCacheSize = 256;
2011
2011
  var CompactTokens = class {
2012
- constructor(sourcePositions) {
2012
+ constructor(sourcePositions, lazyPositions = false) {
2013
2013
  this.sourcePositions = sourcePositions;
2014
+ if (!lazyPositions) return;
2015
+ class ParserToken {
2016
+ constructor(type, value, start, end) {
2017
+ this.type = type;
2018
+ this.value = value;
2019
+ this.#start = start;
2020
+ this.#end = end;
2021
+ }
2022
+ type;
2023
+ value;
2024
+ #start;
2025
+ #end;
2026
+ get start() {
2027
+ if (typeof this.#start === "number") this.#start = sourcePositions.position(this.#start);
2028
+ return this.#start;
2029
+ }
2030
+ get end() {
2031
+ if (typeof this.#end === "number") this.#end = sourcePositions.position(this.#end);
2032
+ return this.#end;
2033
+ }
2034
+ }
2035
+ this.parserToken = (type, value, start, end) => new ParserToken(type, value, start, end);
2014
2036
  }
2015
2037
  sourcePositions;
2016
2038
  rows = new Uint32Array(1024 * stride);
@@ -2018,6 +2040,7 @@ var CompactTokens = class {
2018
2040
  templates = /* @__PURE__ */ new Map();
2019
2041
  tokens = /* @__PURE__ */ new Map();
2020
2042
  last;
2043
+ parserToken;
2021
2044
  // Only indexing, iteration, length, push and at are used by the lexer/parser.
2022
2045
  // Historical tokens are materialized on demand in a bounded cache.
2023
2046
  indexed = new Proxy([], {
@@ -2065,7 +2088,12 @@ var CompactTokens = class {
2065
2088
  if (cached !== void 0) return cached;
2066
2089
  const base = index * stride;
2067
2090
  const bits = this.rows[base + 2];
2068
- const token = {
2091
+ const token = this.parserToken?.(
2092
+ types[bits & 255],
2093
+ this.values[index],
2094
+ this.rows[base],
2095
+ this.rows[base + 1]
2096
+ ) ?? {
2069
2097
  type: types[bits & 255],
2070
2098
  value: this.values[index],
2071
2099
  start: this.sourcePositions.position(this.rows[base]),
@@ -2194,8 +2222,8 @@ function tokenize(source, options = {}) {
2194
2222
  const lexer = new Lexer(source, options);
2195
2223
  return lexer.tokenize();
2196
2224
  }
2197
- function tokenizeCompact(source, options, positions) {
2198
- const tokens = new CompactTokens(positions);
2225
+ function tokenizeCompact(source, options, positions, lazyPositions = false) {
2226
+ const tokens = new CompactTokens(positions, lazyPositions);
2199
2227
  new Lexer(source, { ...options, sharedPositions: true }, tokens.indexed).tokenize();
2200
2228
  return tokens.finish();
2201
2229
  }
@@ -4233,7 +4261,7 @@ function parseSourceModule(source, filename = "<input>", owner, options = {}) {
4233
4261
  throw new SandboxError({ budget: "stringLength", current: source.length, limit });
4234
4262
  owner?.budget.visitNode(source.length);
4235
4263
  const tokenOptions = { allowRegexLiterals: true, statementList: true, compilation, sharedPositions: options.sharedPositions };
4236
- const tokens = options.compactAst ? tokenizeCompact(source, tokenOptions, new CompactSourcePositions(source)) : tokenize(source, tokenOptions);
4264
+ const tokens = options.compactAst ? tokenizeCompact(source, tokenOptions, new CompactSourcePositions(source), true) : tokenize(source, tokenOptions);
4237
4265
  parser = new Parser(
4238
4266
  tokens,
4239
4267
  source,
@@ -4323,7 +4351,7 @@ function parseEvalScript(source, context = {}, owner, filename = "<eval>", optio
4323
4351
  allowHtmlComments: true,
4324
4352
  compilation
4325
4353
  };
4326
- const tokens = options.compactAst ? tokenizeCompact(source, tokenOptions, new CompactSourcePositions(source)) : tokenize(source, tokenOptions);
4354
+ const tokens = options.compactAst ? tokenizeCompact(source, tokenOptions, new CompactSourcePositions(source), true) : tokenize(source, tokenOptions);
4327
4355
  const parser = new Parser(tokens, source, compilation, "normal", {
4328
4356
  grammar,
4329
4357
  newTarget: context.newTarget === true,
@@ -5012,30 +5040,50 @@ var Parser = class {
5012
5040
  return { type: "BlockStatement", body: [statement], span: statement.span };
5013
5041
  }
5014
5042
  parseIfStatement() {
5015
- if (this.ifStatementDepth >= MAX_IF_STATEMENT_DEPTH) {
5016
- const token = this.currentToken();
5017
- throw new Error(
5018
- `If statement nesting limit exceeded at line ${token.start.line}, column ${token.start.column}.`
5019
- );
5020
- }
5021
- this.ifStatementDepth += 1;
5043
+ const pending = [];
5044
+ let entered = 0;
5022
5045
  try {
5023
- const ifToken = this.expectKeyword("if");
5024
- this.expectPunctuator("(");
5025
- const test = this.parseExpression({ allowSequence: true }).node;
5026
- this.expectPunctuator(")");
5027
- const consequent = this.parseIfClause();
5028
- const elseToken = this.consumeKeyword("else");
5029
- const alternate = elseToken === void 0 ? void 0 : this.parseIfClause();
5030
- return {
5031
- type: "IfStatement",
5032
- test,
5033
- consequent,
5034
- alternate,
5035
- span: createSpan2(ifToken.start, alternate?.span.end ?? consequent.span.end)
5036
- };
5046
+ for (; ; ) {
5047
+ if (this.ifStatementDepth >= MAX_IF_STATEMENT_DEPTH) {
5048
+ const token2 = this.currentToken();
5049
+ throw new Error(
5050
+ `If statement nesting limit exceeded at line ${token2.start.line}, column ${token2.start.column}.`
5051
+ );
5052
+ }
5053
+ this.ifStatementDepth++;
5054
+ entered++;
5055
+ const token = this.expectKeyword("if");
5056
+ this.expectPunctuator("(");
5057
+ const test = this.parseExpression({ allowSequence: true }).node;
5058
+ this.expectPunctuator(")");
5059
+ const consequent = this.parseIfClause();
5060
+ const hasElse = this.consumeKeyword("else") !== void 0;
5061
+ if (hasElse && this.currentToken().type === "keyword" && this.currentToken().value === "if") {
5062
+ pending.push({ token, test, consequent });
5063
+ continue;
5064
+ }
5065
+ const alternate = hasElse ? this.parseIfClause() : void 0;
5066
+ let result = {
5067
+ type: "IfStatement",
5068
+ test,
5069
+ consequent,
5070
+ alternate,
5071
+ span: createSpan2(token.start, alternate?.span.end ?? consequent.span.end)
5072
+ };
5073
+ while (pending.length > 0) {
5074
+ const parent = pending.pop();
5075
+ result = {
5076
+ type: "IfStatement",
5077
+ test: parent.test,
5078
+ consequent: parent.consequent,
5079
+ alternate: result,
5080
+ span: createSpan2(parent.token.start, result.span.end)
5081
+ };
5082
+ }
5083
+ return result;
5084
+ }
5037
5085
  } finally {
5038
- this.ifStatementDepth -= 1;
5086
+ this.ifStatementDepth -= entered;
5039
5087
  }
5040
5088
  }
5041
5089
  parseSwitchStatement() {
@@ -8661,4 +8709,4 @@ export {
8661
8709
  Float16Array2 as Float16Array,
8662
8710
  numericTypedArrayConstructors
8663
8711
  };
8664
- //# sourceMappingURL=chunk-KOO6YGQG.js.map
8712
+ //# sourceMappingURL=chunk-T2HKPVB3.js.map