@poe-platform/safe-js 0.1.130 → 0.1.132
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.
- package/dist/safe-js/chunks/{chunk-ZTGKRKQH.js → chunk-7IGOMKO4.js} +173 -64
- package/dist/safe-js/chunks/chunk-7IGOMKO4.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-SGKEOIQL.js → chunk-TCWJR6OI.js} +7 -3
- package/dist/safe-js/chunks/chunk-TCWJR6OI.js.map +7 -0
- package/dist/safe-js/cli.js +2 -2
- package/dist/safe-js/core.js +1 -1
- package/dist/safe-js/index.js +2 -2
- package/dist/safe-js/interp/values.d.ts +3 -0
- package/dist/safe-js/parse/function-source.d.ts +7 -0
- package/dist/safe-js/snapshot/dump-format.d.ts +1 -1
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-SGKEOIQL.js.map +0 -7
- package/dist/safe-js/chunks/chunk-ZTGKRKQH.js.map +0 -7
|
@@ -1811,6 +1811,9 @@ function isAstNode(value) {
|
|
|
1811
1811
|
return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string" && "span" in value && typeof value.span?.start.offset === "number" && typeof value.span?.end.offset === "number";
|
|
1812
1812
|
}
|
|
1813
1813
|
|
|
1814
|
+
// packages/safe-js/src/parse/function-source.ts
|
|
1815
|
+
var functionSources = /* @__PURE__ */ new WeakMap();
|
|
1816
|
+
|
|
1814
1817
|
// packages/safe-js/src/parse/format-error.ts
|
|
1815
1818
|
var ParseError = class extends Error {
|
|
1816
1819
|
constructor(filename, message, line, column, excerpt, caret, span) {
|
|
@@ -2459,7 +2462,11 @@ function parse(source, filename = "<input>", owner) {
|
|
|
2459
2462
|
const compilation = new CompileScope(owner);
|
|
2460
2463
|
try {
|
|
2461
2464
|
const result = assignIds(
|
|
2462
|
-
|
|
2465
|
+
new Parser(
|
|
2466
|
+
tokenize(source, { allowRegexLiterals: true, compilation }),
|
|
2467
|
+
source,
|
|
2468
|
+
compilation
|
|
2469
|
+
).parseTopLevel()
|
|
2463
2470
|
);
|
|
2464
2471
|
const regexLiteral = findRegexLiteral(result);
|
|
2465
2472
|
if (regexLiteral !== void 0) {
|
|
@@ -2485,7 +2492,11 @@ function parseModule(source, filename = "<input>", owner) {
|
|
|
2485
2492
|
const compilation = new CompileScope(owner);
|
|
2486
2493
|
try {
|
|
2487
2494
|
return assignIds(
|
|
2488
|
-
|
|
2495
|
+
new Parser(
|
|
2496
|
+
tokenize(source, { allowRegexLiterals: true, compilation }),
|
|
2497
|
+
source,
|
|
2498
|
+
compilation
|
|
2499
|
+
).parseModule()
|
|
2489
2500
|
);
|
|
2490
2501
|
} catch (error) {
|
|
2491
2502
|
if (error instanceof DisallowedSyntaxError || error instanceof SandboxError) {
|
|
@@ -2503,7 +2514,11 @@ function parseExecutableModule(source, filename = "<input>", owner) {
|
|
|
2503
2514
|
const compilation = new CompileScope(owner);
|
|
2504
2515
|
try {
|
|
2505
2516
|
const result = assignIds(
|
|
2506
|
-
|
|
2517
|
+
new Parser(
|
|
2518
|
+
tokenize(source, { allowRegexLiterals: true, compilation }),
|
|
2519
|
+
source,
|
|
2520
|
+
compilation
|
|
2521
|
+
).parseModule()
|
|
2507
2522
|
);
|
|
2508
2523
|
throwIfImportMetaAssignment(result);
|
|
2509
2524
|
return result;
|
|
@@ -2519,20 +2534,16 @@ function parseExecutableModule(source, filename = "<input>", owner) {
|
|
|
2519
2534
|
compilation.dispose();
|
|
2520
2535
|
}
|
|
2521
2536
|
}
|
|
2522
|
-
function parseTokens(tokens, compilation) {
|
|
2523
|
-
return new Parser(tokens, compilation).parseTopLevel();
|
|
2524
|
-
}
|
|
2525
|
-
function parseModuleTokens(tokens, compilation) {
|
|
2526
|
-
return new Parser(tokens, compilation).parseModule();
|
|
2527
|
-
}
|
|
2528
2537
|
var Parser = class {
|
|
2529
|
-
constructor(tokens, compilation, functionContext = "normal") {
|
|
2538
|
+
constructor(tokens, source, compilation, functionContext = "normal") {
|
|
2530
2539
|
this.tokens = tokens;
|
|
2540
|
+
this.source = source;
|
|
2531
2541
|
this.compilation = compilation;
|
|
2532
2542
|
this.functionContext = functionContext;
|
|
2533
2543
|
this.functionScopes.add(this.scopes[0]);
|
|
2534
2544
|
}
|
|
2535
2545
|
tokens;
|
|
2546
|
+
source;
|
|
2536
2547
|
compilation;
|
|
2537
2548
|
functionContext;
|
|
2538
2549
|
index = 0;
|
|
@@ -2543,6 +2554,14 @@ var Parser = class {
|
|
|
2543
2554
|
scopes = [/* @__PURE__ */ new Map()];
|
|
2544
2555
|
functionScopes = /* @__PURE__ */ new WeakSet();
|
|
2545
2556
|
varNames = /* @__PURE__ */ new WeakMap();
|
|
2557
|
+
withFunctionSource(node) {
|
|
2558
|
+
functionSources.set(node, {
|
|
2559
|
+
text: this.source,
|
|
2560
|
+
start: node.span.start.offset,
|
|
2561
|
+
end: node.span.end.offset
|
|
2562
|
+
});
|
|
2563
|
+
return node;
|
|
2564
|
+
}
|
|
2546
2565
|
parseTopLevel() {
|
|
2547
2566
|
if (this.isExportToken(this.currentToken())) {
|
|
2548
2567
|
throw new DisallowedSyntaxError("export", this.currentToken().start);
|
|
@@ -2684,14 +2703,14 @@ var Parser = class {
|
|
|
2684
2703
|
});
|
|
2685
2704
|
this.expectPunctuator("=>");
|
|
2686
2705
|
const body = this.parseArrowFunctionBody(params);
|
|
2687
|
-
return {
|
|
2706
|
+
return this.withFunctionSource({
|
|
2688
2707
|
type: "ArrowFunctionExpression",
|
|
2689
2708
|
async: isAsync,
|
|
2690
2709
|
body,
|
|
2691
2710
|
expression: body.type !== "BlockStatement",
|
|
2692
2711
|
params,
|
|
2693
2712
|
span: createSpan2(start, body.span.end)
|
|
2694
|
-
};
|
|
2713
|
+
});
|
|
2695
2714
|
}
|
|
2696
2715
|
parseConditionalExpression() {
|
|
2697
2716
|
if (this.conditionalExpressionDepth >= MAX_CONDITIONAL_EXPRESSION_DEPTH) {
|
|
@@ -3331,8 +3350,11 @@ var Parser = class {
|
|
|
3331
3350
|
return parsedParams;
|
|
3332
3351
|
});
|
|
3333
3352
|
const generator = generatorToken !== void 0;
|
|
3334
|
-
const body = this.withFunctionContext(
|
|
3335
|
-
|
|
3353
|
+
const body = this.withFunctionContext(
|
|
3354
|
+
generator ? "generator" : "normal",
|
|
3355
|
+
() => this.parseBlockStatement(params)
|
|
3356
|
+
);
|
|
3357
|
+
return this.withFunctionSource({
|
|
3336
3358
|
type: "FunctionDeclaration",
|
|
3337
3359
|
async: asyncToken !== void 0,
|
|
3338
3360
|
body,
|
|
@@ -3340,7 +3362,7 @@ var Parser = class {
|
|
|
3340
3362
|
id,
|
|
3341
3363
|
params,
|
|
3342
3364
|
span: createSpan2(asyncToken?.start ?? functionToken.start, body.span.end)
|
|
3343
|
-
};
|
|
3365
|
+
});
|
|
3344
3366
|
}
|
|
3345
3367
|
parseVariableDeclarator(kind) {
|
|
3346
3368
|
const id = this.parseBindingTarget();
|
|
@@ -4108,7 +4130,11 @@ var Parser = class {
|
|
|
4108
4130
|
if (this.currentToken().type === "template") {
|
|
4109
4131
|
const quasi = createTemplateLiteral(
|
|
4110
4132
|
this.currentToken(),
|
|
4111
|
-
{
|
|
4133
|
+
{
|
|
4134
|
+
allowMalformedEscapes: true,
|
|
4135
|
+
functionContext: this.functionContext,
|
|
4136
|
+
source: this.source
|
|
4137
|
+
},
|
|
4112
4138
|
this.compilation
|
|
4113
4139
|
);
|
|
4114
4140
|
this.index += 1;
|
|
@@ -4197,7 +4223,11 @@ var Parser = class {
|
|
|
4197
4223
|
return {
|
|
4198
4224
|
node: createTemplateLiteral(
|
|
4199
4225
|
token,
|
|
4200
|
-
{
|
|
4226
|
+
{
|
|
4227
|
+
allowMalformedEscapes: false,
|
|
4228
|
+
functionContext: this.functionContext,
|
|
4229
|
+
source: this.source
|
|
4230
|
+
},
|
|
4201
4231
|
this.compilation
|
|
4202
4232
|
),
|
|
4203
4233
|
parenthesized: false
|
|
@@ -4282,7 +4312,8 @@ var Parser = class {
|
|
|
4282
4312
|
break;
|
|
4283
4313
|
}
|
|
4284
4314
|
const optional = this.consumePunctuator("?.");
|
|
4285
|
-
if (optional !== void 0)
|
|
4315
|
+
if (optional !== void 0)
|
|
4316
|
+
throw new DisallowedSyntaxError("new optional chain", optional.start);
|
|
4286
4317
|
const args = this.consumePunctuator("(") === void 0 ? [] : this.parseArguments();
|
|
4287
4318
|
const end = this.previousToken();
|
|
4288
4319
|
return {
|
|
@@ -4315,8 +4346,11 @@ var Parser = class {
|
|
|
4315
4346
|
return parsedParams;
|
|
4316
4347
|
});
|
|
4317
4348
|
const generator = generatorToken !== void 0;
|
|
4318
|
-
const body = this.withFunctionContext(
|
|
4319
|
-
|
|
4349
|
+
const body = this.withFunctionContext(
|
|
4350
|
+
generator ? "generator" : "normal",
|
|
4351
|
+
() => this.parseBlockStatement(params)
|
|
4352
|
+
);
|
|
4353
|
+
return this.withFunctionSource({
|
|
4320
4354
|
type: "FunctionExpression",
|
|
4321
4355
|
async: asyncToken !== void 0,
|
|
4322
4356
|
body,
|
|
@@ -4324,7 +4358,7 @@ var Parser = class {
|
|
|
4324
4358
|
id,
|
|
4325
4359
|
params,
|
|
4326
4360
|
span: createSpan2(asyncToken?.start ?? functionToken.start, body.span.end)
|
|
4327
|
-
};
|
|
4361
|
+
});
|
|
4328
4362
|
}
|
|
4329
4363
|
parseArrayExpression() {
|
|
4330
4364
|
const start = this.expectPunctuator("[");
|
|
@@ -4560,7 +4594,7 @@ var Parser = class {
|
|
|
4560
4594
|
return parsedParams;
|
|
4561
4595
|
});
|
|
4562
4596
|
const body = this.withFunctionContext("normal", () => this.parseBlockStatement(params));
|
|
4563
|
-
return {
|
|
4597
|
+
return this.withFunctionSource({
|
|
4564
4598
|
type: "FunctionExpression",
|
|
4565
4599
|
async: asyncToken !== void 0,
|
|
4566
4600
|
body,
|
|
@@ -4569,7 +4603,7 @@ var Parser = class {
|
|
|
4569
4603
|
method: true,
|
|
4570
4604
|
params,
|
|
4571
4605
|
span: createSpan2(asyncToken?.start ?? methodStart, body.span.end)
|
|
4572
|
-
};
|
|
4606
|
+
});
|
|
4573
4607
|
}
|
|
4574
4608
|
parseIdentifierName() {
|
|
4575
4609
|
const token = this.currentToken();
|
|
@@ -5432,6 +5466,7 @@ function createTemplateLiteral(token, options, compilation) {
|
|
|
5432
5466
|
raw.slice(expressionStart, expressionEnd),
|
|
5433
5467
|
positionWithinRaw(token.start, raw, expressionStart),
|
|
5434
5468
|
options.functionContext,
|
|
5469
|
+
options.source,
|
|
5435
5470
|
compilation
|
|
5436
5471
|
)
|
|
5437
5472
|
);
|
|
@@ -5794,13 +5829,13 @@ function decodeHexEscape(value, start) {
|
|
|
5794
5829
|
end: index + 2
|
|
5795
5830
|
};
|
|
5796
5831
|
}
|
|
5797
|
-
function parseEmbeddedExpression(source, base, functionContext, compilation) {
|
|
5832
|
+
function parseEmbeddedExpression(source, base, functionContext, fullSource, compilation) {
|
|
5798
5833
|
const tokens = tokenize(source, { allowRegexLiterals: true, compilation }).map((token) => ({
|
|
5799
5834
|
...token,
|
|
5800
5835
|
start: rebasePosition(token.start, base),
|
|
5801
5836
|
end: rebasePosition(token.end, base)
|
|
5802
5837
|
}));
|
|
5803
|
-
return new Parser(tokens, compilation, functionContext).parseExpressionOnly();
|
|
5838
|
+
return new Parser(tokens, fullSource, compilation, functionContext).parseExpressionOnly();
|
|
5804
5839
|
}
|
|
5805
5840
|
function findRegexLiteral(node) {
|
|
5806
5841
|
if (node === null || node === void 0) {
|
|
@@ -7247,7 +7282,7 @@ function decodeFloat32Storage(value, resolve) {
|
|
|
7247
7282
|
|
|
7248
7283
|
// packages/safe-js/src/snapshot/dump-format.ts
|
|
7249
7284
|
var DUMP_FORMAT_VERSION = 1;
|
|
7250
|
-
var EXECUTION_SEMANTICS = "jobs-
|
|
7285
|
+
var EXECUTION_SEMANTICS = "jobs-v8";
|
|
7251
7286
|
var SKIP_VALUE = /* @__PURE__ */ Symbol("SafeJS.skip-dump-value");
|
|
7252
7287
|
function serializeSafeJSSnapshot(snapshot) {
|
|
7253
7288
|
const replayError = Object.getOwnPropertyDescriptor(snapshot, "replayError");
|
|
@@ -8676,6 +8711,22 @@ async function withRunResources(signal, execute) {
|
|
|
8676
8711
|
return result;
|
|
8677
8712
|
}
|
|
8678
8713
|
|
|
8714
|
+
// packages/safe-js/src/interp/function-string.ts
|
|
8715
|
+
function functionString(value) {
|
|
8716
|
+
if (runResources.getStore()?.functionSourceText === false) return "[object Object]";
|
|
8717
|
+
const source = value.sourceRange;
|
|
8718
|
+
if (source !== void 0) return source.text.slice(source.start, source.end);
|
|
8719
|
+
let name = value.boundTarget === void 0 ? value.name?.split("#").at(-1) ?? "" : "";
|
|
8720
|
+
for (let index = 0; index < name.length; index++) {
|
|
8721
|
+
const code = name.charCodeAt(index);
|
|
8722
|
+
if (!(code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95 || index > 0 && code >= 48 && code <= 57)) {
|
|
8723
|
+
name = "";
|
|
8724
|
+
break;
|
|
8725
|
+
}
|
|
8726
|
+
}
|
|
8727
|
+
return `function ${name}() { [native code] }`;
|
|
8728
|
+
}
|
|
8729
|
+
|
|
8679
8730
|
// packages/safe-js/src/interp/string-coercion.ts
|
|
8680
8731
|
var defaultStringHook = /* @__PURE__ */ Symbol("defaultStringHook");
|
|
8681
8732
|
var defaultValueHook = /* @__PURE__ */ Symbol("defaultValueHook");
|
|
@@ -8743,6 +8794,7 @@ function conversionHook(value, name, budget) {
|
|
|
8743
8794
|
return void 0;
|
|
8744
8795
|
}
|
|
8745
8796
|
async function defaultToString(value, budget, context, joining) {
|
|
8797
|
+
if (isSandboxClosure(value)) return budget.allocateString(functionString(value));
|
|
8746
8798
|
if (isSandboxMap(value)) return "[object Map]";
|
|
8747
8799
|
if (isSandboxSet(value)) return "[object Set]";
|
|
8748
8800
|
if (isSandboxCollectionIterator(value)) return collectionIteratorState(value).collectionKind === "map" ? "[object Map Iterator]" : "[object Set Iterator]";
|
|
@@ -10427,6 +10479,9 @@ function createSandboxClosure(input) {
|
|
|
10427
10479
|
enumerable: false,
|
|
10428
10480
|
value: true
|
|
10429
10481
|
});
|
|
10482
|
+
if (input.sourceRange !== void 0) {
|
|
10483
|
+
Object.defineProperty(closure, "sourceRange", { value: input.sourceRange });
|
|
10484
|
+
}
|
|
10430
10485
|
if (input.sandbox === true) {
|
|
10431
10486
|
Object.defineProperty(closure, "sandbox", { value: true });
|
|
10432
10487
|
}
|
|
@@ -12274,19 +12329,19 @@ function normalize(value, seen) {
|
|
|
12274
12329
|
var FNV_OFFSET_BASIS = 2166136261;
|
|
12275
12330
|
var FNV_PRIME = 16777619;
|
|
12276
12331
|
var IGNORED_KEYS = /* @__PURE__ */ new Set(["nodeId", "raw", "span"]);
|
|
12277
|
-
function hashSource(source, owner) {
|
|
12332
|
+
function hashSource(source, owner, includeFunctionSource = true) {
|
|
12278
12333
|
try {
|
|
12279
|
-
return hashParsedAst(parse(source, "<input>", owner));
|
|
12334
|
+
return hashParsedAst(parse(source, "<input>", owner), includeFunctionSource);
|
|
12280
12335
|
} catch (error) {
|
|
12281
12336
|
if (error instanceof SandboxError) throw error;
|
|
12282
|
-
return hashParsedAst(parseModule(source, "<input>", owner));
|
|
12337
|
+
return hashParsedAst(parseModule(source, "<input>", owner), includeFunctionSource);
|
|
12283
12338
|
}
|
|
12284
12339
|
}
|
|
12285
|
-
function hashParsedAst(ast) {
|
|
12340
|
+
function hashParsedAst(ast, includeFunctionSource = true) {
|
|
12286
12341
|
let hash = FNV_OFFSET_BASIS;
|
|
12287
12342
|
visit(ast);
|
|
12288
12343
|
return hash.toString(16).padStart(8, "0");
|
|
12289
|
-
function visit(value, includeTemplateRaw = false) {
|
|
12344
|
+
function visit(value, includeTemplateRaw = false, enclosingSource) {
|
|
12290
12345
|
if (value === null) {
|
|
12291
12346
|
write("null");
|
|
12292
12347
|
return;
|
|
@@ -12298,7 +12353,7 @@ function hashParsedAst(ast) {
|
|
|
12298
12353
|
if (Array.isArray(value)) {
|
|
12299
12354
|
write("[");
|
|
12300
12355
|
for (const entry of value) {
|
|
12301
|
-
visit(entry, includeTemplateRaw);
|
|
12356
|
+
visit(entry, includeTemplateRaw, enclosingSource);
|
|
12302
12357
|
write(",");
|
|
12303
12358
|
}
|
|
12304
12359
|
write("]");
|
|
@@ -12316,12 +12371,23 @@ function hashParsedAst(ast) {
|
|
|
12316
12371
|
return;
|
|
12317
12372
|
case "object": {
|
|
12318
12373
|
const record2 = value;
|
|
12374
|
+
const source = includeFunctionSource ? functionSources.get(value) : void 0;
|
|
12375
|
+
if (source !== void 0 && !(enclosingSource !== void 0 && source.text === enclosingSource.text && source.start >= enclosingSource.start && source.end <= enclosingSource.end)) {
|
|
12376
|
+
write("function-source:");
|
|
12377
|
+
write(String(source.end - source.start));
|
|
12378
|
+
write(":");
|
|
12379
|
+
write(source.text, source.start, source.end);
|
|
12380
|
+
}
|
|
12319
12381
|
const keys = Object.keys(value).filter((key) => shouldHashKey(record2, key, includeTemplateRaw)).sort();
|
|
12320
12382
|
write("{");
|
|
12321
12383
|
for (const key of keys) {
|
|
12322
12384
|
write(JSON.stringify(key));
|
|
12323
12385
|
write(":");
|
|
12324
|
-
visit(
|
|
12386
|
+
visit(
|
|
12387
|
+
record2[key],
|
|
12388
|
+
shouldIncludeTemplateRaw(record2, key, includeTemplateRaw),
|
|
12389
|
+
source ?? enclosingSource
|
|
12390
|
+
);
|
|
12325
12391
|
write(",");
|
|
12326
12392
|
}
|
|
12327
12393
|
write("}");
|
|
@@ -12331,8 +12397,8 @@ function hashParsedAst(ast) {
|
|
|
12331
12397
|
throw new TypeError(`Unsupported AST value type: ${typeof value}`);
|
|
12332
12398
|
}
|
|
12333
12399
|
}
|
|
12334
|
-
function write(chunk) {
|
|
12335
|
-
for (let index =
|
|
12400
|
+
function write(chunk, start = 0, end = chunk.length) {
|
|
12401
|
+
for (let index = start; index < end; index += 1) {
|
|
12336
12402
|
hash ^= chunk.charCodeAt(index);
|
|
12337
12403
|
hash = Math.imul(hash, FNV_PRIME) >>> 0;
|
|
12338
12404
|
}
|
|
@@ -12359,11 +12425,11 @@ function shouldIncludeTemplateRaw(record2, key, includeTemplateRaw) {
|
|
|
12359
12425
|
|
|
12360
12426
|
// packages/safe-js/src/snapshot/migration.ts
|
|
12361
12427
|
function validateMigrationSemantics(value) {
|
|
12362
|
-
if (!["jobs-v1", "jobs-v2", "jobs-v3", "jobs-v4", "jobs-v5", "jobs-v6", "jobs-v7"].includes(
|
|
12428
|
+
if (!["jobs-v1", "jobs-v2", "jobs-v3", "jobs-v4", "jobs-v5", "jobs-v6", "jobs-v7", "jobs-v8"].includes(
|
|
12363
12429
|
value
|
|
12364
12430
|
))
|
|
12365
12431
|
throw new TypeError(
|
|
12366
|
-
"Migration requires a supported execution-semantics marker (jobs-v1 through jobs-
|
|
12432
|
+
"Migration requires a supported execution-semantics marker (jobs-v1 through jobs-v8)."
|
|
12367
12433
|
);
|
|
12368
12434
|
}
|
|
12369
12435
|
function validateMigrationJournal(sourceHash, replay, hostCalls = [], owner) {
|
|
@@ -12472,14 +12538,18 @@ function restore(snapshot, options, owner) {
|
|
|
12472
12538
|
assertSnapshotInactive(snapshot);
|
|
12473
12539
|
validateDumpEnvelope(snapshot);
|
|
12474
12540
|
validateSnapshotMigration(snapshot.migration, snapshot.sourceHash, owner);
|
|
12475
|
-
if (snapshot.executionSemantics !== EXECUTION_SEMANTICS && snapshot.executionSemantics !== "jobs-v6" && (snapshot.executionSemantics !== void 0 || snapshot.promiseReplay !== void 0 || snapshot.replay !== void 0 || snapshot.initialInputs !== void 0)) {
|
|
12541
|
+
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)) {
|
|
12476
12542
|
throw new SnapshotValidationError(
|
|
12477
12543
|
"unsupportedVersion",
|
|
12478
12544
|
"$.executionSemantics",
|
|
12479
12545
|
"incompatible execution semantics; resume with the SafeJS version that created this snapshot. Migration requires explicit reconciliation, not changing its version marker."
|
|
12480
12546
|
);
|
|
12481
12547
|
}
|
|
12482
|
-
const currentSourceHash = hashSource(
|
|
12548
|
+
const currentSourceHash = hashSource(
|
|
12549
|
+
options.source,
|
|
12550
|
+
owner,
|
|
12551
|
+
snapshot.executionSemantics !== "jobs-v6" && snapshot.executionSemantics !== "jobs-v7"
|
|
12552
|
+
);
|
|
12483
12553
|
if (snapshot.sourceHash !== currentSourceHash) {
|
|
12484
12554
|
throw new SnapshotMismatchError(snapshot.sourceHash, currentSourceHash);
|
|
12485
12555
|
}
|
|
@@ -24724,7 +24794,7 @@ function toIntegerOrInfinity(value) {
|
|
|
24724
24794
|
}
|
|
24725
24795
|
|
|
24726
24796
|
// packages/safe-js/src/interp/methods/function.ts
|
|
24727
|
-
var functionMethodNames = /* @__PURE__ */ new Set(["apply", "bind", "call"]);
|
|
24797
|
+
var functionMethodNames = /* @__PURE__ */ new Set(["apply", "bind", "call", "toString"]);
|
|
24728
24798
|
function getFunctionMember(target, property, options) {
|
|
24729
24799
|
if (isGuestClosure(target)) {
|
|
24730
24800
|
const value = getGuestFunctionProperty(target, String(property));
|
|
@@ -24738,12 +24808,14 @@ function getFunctionMember(target, property, options) {
|
|
|
24738
24808
|
if (property === "length") {
|
|
24739
24809
|
return target.length;
|
|
24740
24810
|
}
|
|
24811
|
+
if (property === "toString" && runResources.getStore()?.functionSourceText === false) return void 0;
|
|
24741
24812
|
if (!isFunctionMethodName(property)) {
|
|
24742
24813
|
return void 0;
|
|
24743
24814
|
}
|
|
24744
24815
|
return createSandboxClosure({
|
|
24745
24816
|
sandbox: true,
|
|
24746
24817
|
name: `Function#${property}`,
|
|
24818
|
+
...property === "toString" ? { length: 0 } : {},
|
|
24747
24819
|
call: (args, context) => callFunctionMethod(context?.thisValue, property, args, options, context?.stack ?? [])
|
|
24748
24820
|
});
|
|
24749
24821
|
}
|
|
@@ -24754,6 +24826,10 @@ function callFunctionMethod(target, methodName, args, options, stack) {
|
|
|
24754
24826
|
if (!isSandboxClosure(target)) {
|
|
24755
24827
|
throw new TypeError(`Function#${methodName} requires a callable receiver.`);
|
|
24756
24828
|
}
|
|
24829
|
+
if (methodName === "toString") {
|
|
24830
|
+
const text = functionString(target);
|
|
24831
|
+
return options.budget?.allocateString(text) ?? text;
|
|
24832
|
+
}
|
|
24757
24833
|
const thisValue = args[0];
|
|
24758
24834
|
if (methodName === "bind") {
|
|
24759
24835
|
const boundArgs = args.slice(1);
|
|
@@ -28938,6 +29014,7 @@ function createSetMethodOptions(context) {
|
|
|
28938
29014
|
}
|
|
28939
29015
|
function createFunctionMethodOptions(context) {
|
|
28940
29016
|
return {
|
|
29017
|
+
budget: context.budget,
|
|
28941
29018
|
callClosure: (closure, args, stack, thisValue, construct) => invokeSandboxClosure(closure, args, context, stack, void 0, thisValue, construct)
|
|
28942
29019
|
};
|
|
28943
29020
|
}
|
|
@@ -29175,6 +29252,7 @@ function createInterpretedClosure(node, context, evaluateNode2) {
|
|
|
29175
29252
|
return isConstructResult(result) ? result : thisValue;
|
|
29176
29253
|
} : void 0;
|
|
29177
29254
|
const closure = createSandboxClosure({
|
|
29255
|
+
sourceRange: functionSources.get(node),
|
|
29178
29256
|
guest: true,
|
|
29179
29257
|
sandbox: true,
|
|
29180
29258
|
length: getFunctionLength(node.params),
|
|
@@ -29237,6 +29315,7 @@ function executeAsyncFunction(execute, budget, signal) {
|
|
|
29237
29315
|
}
|
|
29238
29316
|
function createGeneratorClosure(node, context, evaluateNode2) {
|
|
29239
29317
|
return createSandboxClosure({
|
|
29318
|
+
sourceRange: functionSources.get(node),
|
|
29240
29319
|
guest: true,
|
|
29241
29320
|
generator: true,
|
|
29242
29321
|
sandbox: true,
|
|
@@ -30847,6 +30926,46 @@ function createRegexGlobals(options) {
|
|
|
30847
30926
|
};
|
|
30848
30927
|
}
|
|
30849
30928
|
|
|
30929
|
+
// packages/safe-js/src/interp/globals/numeric-parsers.ts
|
|
30930
|
+
function createNumericParsers(budget) {
|
|
30931
|
+
return {
|
|
30932
|
+
parseInt: createSandboxClosure({
|
|
30933
|
+
sandbox: true,
|
|
30934
|
+
name: "parseInt",
|
|
30935
|
+
call: ([value, radix], context) => {
|
|
30936
|
+
const parse2 = (text2) => {
|
|
30937
|
+
const release = retainValues(budget, () => [text2]);
|
|
30938
|
+
let convertedRadix;
|
|
30939
|
+
try {
|
|
30940
|
+
convertedRadix = sandboxNumber(radix, budget, context);
|
|
30941
|
+
} catch (error) {
|
|
30942
|
+
release();
|
|
30943
|
+
throw error;
|
|
30944
|
+
}
|
|
30945
|
+
if (typeof convertedRadix === "number") {
|
|
30946
|
+
try {
|
|
30947
|
+
return globalThis.parseInt(text2, convertedRadix);
|
|
30948
|
+
} finally {
|
|
30949
|
+
release();
|
|
30950
|
+
}
|
|
30951
|
+
}
|
|
30952
|
+
return convertedRadix.then((number) => globalThis.parseInt(text2, number)).finally(release);
|
|
30953
|
+
};
|
|
30954
|
+
const text = sandboxString(value, budget, context);
|
|
30955
|
+
return typeof text === "string" ? parse2(text) : text.then(parse2);
|
|
30956
|
+
}
|
|
30957
|
+
}),
|
|
30958
|
+
parseFloat: createSandboxClosure({
|
|
30959
|
+
sandbox: true,
|
|
30960
|
+
name: "parseFloat",
|
|
30961
|
+
call: ([value], context) => {
|
|
30962
|
+
const text = sandboxString(value, budget, context);
|
|
30963
|
+
return typeof text === "string" ? globalThis.parseFloat(text) : text.then(globalThis.parseFloat);
|
|
30964
|
+
}
|
|
30965
|
+
})
|
|
30966
|
+
};
|
|
30967
|
+
}
|
|
30968
|
+
|
|
30850
30969
|
// packages/safe-js/src/interp/globals/misc.ts
|
|
30851
30970
|
function createMiscGlobals(options) {
|
|
30852
30971
|
return {
|
|
@@ -30855,16 +30974,7 @@ function createMiscGlobals(options) {
|
|
|
30855
30974
|
call: ([value], context) => structuredCloneSandboxValue(value, options.budget, context?.compilation),
|
|
30856
30975
|
name: "structuredClone"
|
|
30857
30976
|
}),
|
|
30858
|
-
|
|
30859
|
-
sandbox: true,
|
|
30860
|
-
call: (args) => Reflect.apply(globalThis.parseInt, globalThis, [...args]),
|
|
30861
|
-
name: "parseInt"
|
|
30862
|
-
}),
|
|
30863
|
-
parseFloat: createSandboxClosure({
|
|
30864
|
-
sandbox: true,
|
|
30865
|
-
call: (args) => Reflect.apply(globalThis.parseFloat, globalThis, [...args]),
|
|
30866
|
-
name: "parseFloat"
|
|
30867
|
-
}),
|
|
30977
|
+
...createNumericParsers(options.budget),
|
|
30868
30978
|
isNaN: createSandboxClosure({
|
|
30869
30979
|
sandbox: true,
|
|
30870
30980
|
call: ([value]) => globalThis.isNaN(value),
|
|
@@ -31126,16 +31236,7 @@ function createObjectArrayGlobals(options) {
|
|
|
31126
31236
|
call: ([value]) => typeof value === "number" && Number.isInteger(value),
|
|
31127
31237
|
name: "isInteger"
|
|
31128
31238
|
}),
|
|
31129
|
-
|
|
31130
|
-
sandbox: true,
|
|
31131
|
-
call: (args) => Reflect.apply(Number.parseInt, Number, [...args]),
|
|
31132
|
-
name: "parseInt"
|
|
31133
|
-
}),
|
|
31134
|
-
parseFloat: createSandboxClosure({
|
|
31135
|
-
sandbox: true,
|
|
31136
|
-
call: (args) => Reflect.apply(Number.parseFloat, Number, [...args]),
|
|
31137
|
-
name: "parseFloat"
|
|
31138
|
-
}),
|
|
31239
|
+
...createNumericParsers(options.budget),
|
|
31139
31240
|
isSafeInteger: createSandboxClosure({
|
|
31140
31241
|
sandbox: true,
|
|
31141
31242
|
call: ([value]) => typeof value === "number" && Number.isSafeInteger(value),
|
|
@@ -32961,7 +33062,8 @@ function run(source, options = {}) {
|
|
|
32961
33062
|
options.signal?.addEventListener("abort", captureCancellationSnapshot, { once: true });
|
|
32962
33063
|
try {
|
|
32963
33064
|
const restoredSnapshot = options.snapshot === void 0 ? void 0 : restore(options.snapshot, { source }, operation.owner);
|
|
32964
|
-
const executionSemantics = restoredSnapshot?.executionSemantics === "jobs-v6"
|
|
33065
|
+
const executionSemantics = restoredSnapshot?.executionSemantics === "jobs-v6" || restoredSnapshot?.executionSemantics === "jobs-v7" ? restoredSnapshot.executionSemantics : EXECUTION_SEMANTICS;
|
|
33066
|
+
runResources.getStore().functionSourceText = executionSemantics === EXECUTION_SEMANTICS;
|
|
32965
33067
|
const convertInitialInput = (convert) => executionSemantics === "jobs-v6" ? convert() : promiseReplayContext.exit(convert);
|
|
32966
33068
|
if (restoredSnapshot !== void 0) {
|
|
32967
33069
|
leaveSnapshotRun = enterSnapshotRun(restoredSnapshot);
|
|
@@ -32970,7 +33072,7 @@ function run(source, options = {}) {
|
|
|
32970
33072
|
const filename = options.filename ?? "<input>";
|
|
32971
33073
|
const module = parseExecutableModule(source, filename, operation.owner);
|
|
32972
33074
|
promiseReplay.validateNodes(module);
|
|
32973
|
-
const sourceHash = findRegexLiteral(module) === void 0 ? hashSource(source, operation.owner) : hashParsedAst(module);
|
|
33075
|
+
const sourceHash = findRegexLiteral(module) === void 0 ? hashSource(source, operation.owner, executionSemantics === EXECUTION_SEMANTICS) : hashParsedAst(module, executionSemantics === EXECUTION_SEMANTICS);
|
|
32974
33076
|
const hostCalls = new HostCallJournal(
|
|
32975
33077
|
sourceHash,
|
|
32976
33078
|
readHostCallSnapshot(restoredSnapshot),
|
|
@@ -32997,7 +33099,14 @@ function run(source, options = {}) {
|
|
|
32997
33099
|
lifecycle
|
|
32998
33100
|
})
|
|
32999
33101
|
);
|
|
33000
|
-
const builtinBindings = createBuiltinBindings({
|
|
33102
|
+
const builtinBindings = createBuiltinBindings({
|
|
33103
|
+
compileOwner: operation.owner,
|
|
33104
|
+
budget,
|
|
33105
|
+
hostCalls,
|
|
33106
|
+
sink: options.sink,
|
|
33107
|
+
random: random?.generator.next,
|
|
33108
|
+
clock: options.clock
|
|
33109
|
+
});
|
|
33001
33110
|
const importMeta = convertInitialInput(
|
|
33002
33111
|
() => deepCopyToSandbox(options.importMeta ?? {})
|
|
33003
33112
|
);
|
|
@@ -33500,4 +33609,4 @@ export {
|
|
|
33500
33609
|
FileSnapshotBackend,
|
|
33501
33610
|
run
|
|
33502
33611
|
};
|
|
33503
|
-
//# sourceMappingURL=chunk-
|
|
33612
|
+
//# sourceMappingURL=chunk-7IGOMKO4.js.map
|