poe-code 14.0.59 → 14.0.61
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/index.js +148 -108
- package/dist/index.js.map +4 -4
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safe-js/dist/chunks/{chunk-YZGYOQK3.js → chunk-VAYQP2VZ.js} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-D4YY44EF.js → chunk-ZTGKRKQH.js} +141 -104
- package/packages/safe-js/dist/chunks/chunk-ZTGKRKQH.js.map +7 -0
- package/packages/safe-js/dist/cli.js +2 -2
- package/packages/safe-js/dist/core.js +1 -1
- package/packages/safe-js/dist/index.js +2 -2
- package/packages/safe-js/dist/interp/interpreter.js +8 -14
- package/packages/safe-js/dist/interp/methods/string.js +18 -0
- package/packages/safe-js/dist/interp/resources.d.ts +2 -0
- package/packages/safe-js/dist/interp/resources.js +11 -0
- package/packages/safe-js/dist/interp/string-coercion.js +13 -4
- package/packages/safe-js/dist/parse/parser.js +45 -42
- package/packages/safe-js/dist/chunks/chunk-D4YY44EF.js.map +0 -7
- /package/packages/safe-js/dist/chunks/{chunk-YZGYOQK3.js.map → chunk-VAYQP2VZ.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -122161,9 +122161,6 @@ function parseTokens(tokens, compilation) {
|
|
|
122161
122161
|
function parseModuleTokens(tokens, compilation) {
|
|
122162
122162
|
return new Parser(tokens, compilation).parseModule();
|
|
122163
122163
|
}
|
|
122164
|
-
function parseExpressionTokens(tokens, compilation) {
|
|
122165
|
-
return new Parser(tokens, compilation).parseExpressionOnly();
|
|
122166
|
-
}
|
|
122167
122164
|
function createIdentifier2(token) {
|
|
122168
122165
|
return {
|
|
122169
122166
|
type: "Identifier",
|
|
@@ -122451,7 +122448,7 @@ function createLiteralFromToken(token) {
|
|
|
122451
122448
|
}
|
|
122452
122449
|
return createKeywordLiteral(token);
|
|
122453
122450
|
}
|
|
122454
|
-
function createTemplateLiteral(token, options
|
|
122451
|
+
function createTemplateLiteral(token, options, compilation) {
|
|
122455
122452
|
const raw = token.value;
|
|
122456
122453
|
const expressions = [];
|
|
122457
122454
|
const quasis = [];
|
|
@@ -122471,6 +122468,7 @@ function createTemplateLiteral(token, options = { allowMalformedEscapes: false }
|
|
|
122471
122468
|
parseEmbeddedExpression(
|
|
122472
122469
|
raw.slice(expressionStart, expressionEnd),
|
|
122473
122470
|
positionWithinRaw(token.start, raw, expressionStart),
|
|
122471
|
+
options.functionContext,
|
|
122474
122472
|
compilation
|
|
122475
122473
|
)
|
|
122476
122474
|
);
|
|
@@ -122833,13 +122831,13 @@ function decodeHexEscape(value, start) {
|
|
|
122833
122831
|
end: index + 2
|
|
122834
122832
|
};
|
|
122835
122833
|
}
|
|
122836
|
-
function parseEmbeddedExpression(source, base, compilation) {
|
|
122834
|
+
function parseEmbeddedExpression(source, base, functionContext, compilation) {
|
|
122837
122835
|
const tokens = tokenize3(source, { allowRegexLiterals: true, compilation }).map((token) => ({
|
|
122838
122836
|
...token,
|
|
122839
122837
|
start: rebasePosition(token.start, base),
|
|
122840
122838
|
end: rebasePosition(token.end, base)
|
|
122841
122839
|
}));
|
|
122842
|
-
return
|
|
122840
|
+
return new Parser(tokens, compilation, functionContext).parseExpressionOnly();
|
|
122843
122841
|
}
|
|
122844
122842
|
function findRegexLiteral(node) {
|
|
122845
122843
|
if (node === null || node === void 0) {
|
|
@@ -123024,19 +123022,20 @@ var init_parser3 = __esm({
|
|
|
123024
123022
|
"while"
|
|
123025
123023
|
]);
|
|
123026
123024
|
Parser = class {
|
|
123027
|
-
constructor(tokens, compilation) {
|
|
123025
|
+
constructor(tokens, compilation, functionContext = "normal") {
|
|
123028
123026
|
this.tokens = tokens;
|
|
123029
123027
|
this.compilation = compilation;
|
|
123028
|
+
this.functionContext = functionContext;
|
|
123030
123029
|
this.functionScopes.add(this.scopes[0]);
|
|
123031
123030
|
}
|
|
123032
123031
|
tokens;
|
|
123033
123032
|
compilation;
|
|
123033
|
+
functionContext;
|
|
123034
123034
|
index = 0;
|
|
123035
123035
|
breakableDepth = 0;
|
|
123036
123036
|
conditionalExpressionDepth = 0;
|
|
123037
123037
|
ifStatementDepth = 0;
|
|
123038
123038
|
loopDepth = 0;
|
|
123039
|
-
generatorBody = false;
|
|
123040
123039
|
scopes = [/* @__PURE__ */ new Map()];
|
|
123041
123040
|
functionScopes = /* @__PURE__ */ new WeakSet();
|
|
123042
123041
|
varNames = /* @__PURE__ */ new WeakMap();
|
|
@@ -123222,9 +123221,9 @@ var init_parser3 = __esm({
|
|
|
123222
123221
|
}
|
|
123223
123222
|
parseArrowFunctionBody(params) {
|
|
123224
123223
|
if (this.currentToken().type === "punctuator" && this.currentToken().value === "{") {
|
|
123225
|
-
return this.withFunctionContext(
|
|
123224
|
+
return this.withFunctionContext("normal", () => this.parseBlockStatement(params));
|
|
123226
123225
|
}
|
|
123227
|
-
return this.withFunctionContext(
|
|
123226
|
+
return this.withFunctionContext("normal", () => this.parseExpression().node);
|
|
123228
123227
|
}
|
|
123229
123228
|
parseBlockStatement(params, catchParam) {
|
|
123230
123229
|
const start = this.expectPunctuator("{");
|
|
@@ -123828,7 +123827,7 @@ var init_parser3 = __esm({
|
|
|
123828
123827
|
return parsedParams;
|
|
123829
123828
|
});
|
|
123830
123829
|
const generator = generatorToken !== void 0;
|
|
123831
|
-
const body = this.withFunctionContext(generator, () => this.parseBlockStatement(params));
|
|
123830
|
+
const body = this.withFunctionContext(generator ? "generator" : "normal", () => this.parseBlockStatement(params));
|
|
123832
123831
|
return {
|
|
123833
123832
|
type: "FunctionDeclaration",
|
|
123834
123833
|
async: asyncToken !== void 0,
|
|
@@ -123863,32 +123862,34 @@ var init_parser3 = __esm({
|
|
|
123863
123862
|
};
|
|
123864
123863
|
}
|
|
123865
123864
|
parseArrowParameters() {
|
|
123866
|
-
this.
|
|
123867
|
-
|
|
123868
|
-
|
|
123869
|
-
|
|
123870
|
-
|
|
123871
|
-
while (true) {
|
|
123872
|
-
const param = this.parseBindingElement();
|
|
123873
|
-
params.push(param);
|
|
123874
|
-
const comma = this.consumePunctuator(",");
|
|
123875
|
-
if (comma === void 0) {
|
|
123876
|
-
break;
|
|
123865
|
+
return this.withFunctionContext("parameters", () => {
|
|
123866
|
+
this.expectPunctuator("(");
|
|
123867
|
+
const params = [];
|
|
123868
|
+
if (this.consumePunctuator(")") !== void 0) {
|
|
123869
|
+
return params;
|
|
123877
123870
|
}
|
|
123878
|
-
|
|
123871
|
+
while (true) {
|
|
123872
|
+
const param = this.parseBindingElement();
|
|
123873
|
+
params.push(param);
|
|
123874
|
+
const comma = this.consumePunctuator(",");
|
|
123875
|
+
if (comma === void 0) {
|
|
123876
|
+
break;
|
|
123877
|
+
}
|
|
123878
|
+
if (param.type === "RestElement") {
|
|
123879
|
+
if (this.currentToken().type === "punctuator" && this.currentToken().value === ")") {
|
|
123880
|
+
throw unexpectedTokenError(comma);
|
|
123881
|
+
}
|
|
123882
|
+
throw new Error(
|
|
123883
|
+
`Rest element must be the last parameter at line ${comma.start.line}, column ${comma.start.column}.`
|
|
123884
|
+
);
|
|
123885
|
+
}
|
|
123879
123886
|
if (this.currentToken().type === "punctuator" && this.currentToken().value === ")") {
|
|
123880
|
-
|
|
123887
|
+
break;
|
|
123881
123888
|
}
|
|
123882
|
-
throw new Error(
|
|
123883
|
-
`Rest element must be the last parameter at line ${comma.start.line}, column ${comma.start.column}.`
|
|
123884
|
-
);
|
|
123885
123889
|
}
|
|
123886
|
-
|
|
123887
|
-
|
|
123888
|
-
|
|
123889
|
-
}
|
|
123890
|
-
this.expectPunctuator(")");
|
|
123891
|
-
return params;
|
|
123890
|
+
this.expectPunctuator(")");
|
|
123891
|
+
return params;
|
|
123892
|
+
});
|
|
123892
123893
|
}
|
|
123893
123894
|
parseBindingElement() {
|
|
123894
123895
|
if (this.consumePunctuator("...") !== void 0) {
|
|
@@ -124442,7 +124443,7 @@ var init_parser3 = __esm({
|
|
|
124442
124443
|
};
|
|
124443
124444
|
}
|
|
124444
124445
|
if (token.type === "keyword" && token.value === "yield") {
|
|
124445
|
-
if (
|
|
124446
|
+
if (this.functionContext !== "generator") {
|
|
124446
124447
|
throw new Error(
|
|
124447
124448
|
`yield is only valid inside a generator body at line ${token.start.line}, column ${token.start.column}.`
|
|
124448
124449
|
);
|
|
@@ -124469,11 +124470,16 @@ var init_parser3 = __esm({
|
|
|
124469
124470
|
};
|
|
124470
124471
|
}
|
|
124471
124472
|
if (token.type === "keyword" && token.value === "await") {
|
|
124472
|
-
if (this.
|
|
124473
|
+
if (this.functionContext === "generator") {
|
|
124473
124474
|
throw new Error(
|
|
124474
124475
|
`generators cannot await; use a regular async function at line ${token.start.line}, column ${token.start.column}.`
|
|
124475
124476
|
);
|
|
124476
124477
|
}
|
|
124478
|
+
if (this.functionContext === "parameters") {
|
|
124479
|
+
throw new Error(
|
|
124480
|
+
`await is not valid in function parameters at line ${token.start.line}, column ${token.start.column}.`
|
|
124481
|
+
);
|
|
124482
|
+
}
|
|
124477
124483
|
this.index += 1;
|
|
124478
124484
|
const argument = this.parseUnaryExpression();
|
|
124479
124485
|
return {
|
|
@@ -124598,7 +124604,7 @@ var init_parser3 = __esm({
|
|
|
124598
124604
|
if (this.currentToken().type === "template") {
|
|
124599
124605
|
const quasi = createTemplateLiteral(
|
|
124600
124606
|
this.currentToken(),
|
|
124601
|
-
{ allowMalformedEscapes: true },
|
|
124607
|
+
{ allowMalformedEscapes: true, functionContext: this.functionContext },
|
|
124602
124608
|
this.compilation
|
|
124603
124609
|
);
|
|
124604
124610
|
this.index += 1;
|
|
@@ -124685,7 +124691,11 @@ var init_parser3 = __esm({
|
|
|
124685
124691
|
if (token.type === "template") {
|
|
124686
124692
|
this.index += 1;
|
|
124687
124693
|
return {
|
|
124688
|
-
node: createTemplateLiteral(
|
|
124694
|
+
node: createTemplateLiteral(
|
|
124695
|
+
token,
|
|
124696
|
+
{ allowMalformedEscapes: false, functionContext: this.functionContext },
|
|
124697
|
+
this.compilation
|
|
124698
|
+
),
|
|
124689
124699
|
parenthesized: false
|
|
124690
124700
|
};
|
|
124691
124701
|
}
|
|
@@ -124801,7 +124811,7 @@ var init_parser3 = __esm({
|
|
|
124801
124811
|
return parsedParams;
|
|
124802
124812
|
});
|
|
124803
124813
|
const generator = generatorToken !== void 0;
|
|
124804
|
-
const body = this.withFunctionContext(generator, () => this.parseBlockStatement(params));
|
|
124814
|
+
const body = this.withFunctionContext(generator ? "generator" : "normal", () => this.parseBlockStatement(params));
|
|
124805
124815
|
return {
|
|
124806
124816
|
type: "FunctionExpression",
|
|
124807
124817
|
async: asyncToken !== void 0,
|
|
@@ -125045,7 +125055,7 @@ var init_parser3 = __esm({
|
|
|
125045
125055
|
}
|
|
125046
125056
|
return parsedParams;
|
|
125047
125057
|
});
|
|
125048
|
-
const body = this.withFunctionContext(
|
|
125058
|
+
const body = this.withFunctionContext("normal", () => this.parseBlockStatement(params));
|
|
125049
125059
|
return {
|
|
125050
125060
|
type: "FunctionExpression",
|
|
125051
125061
|
async: asyncToken !== void 0,
|
|
@@ -125450,19 +125460,19 @@ var init_parser3 = __esm({
|
|
|
125450
125460
|
hasReturnArgument(returnToken, nextToken) {
|
|
125451
125461
|
return !(hasLineBreakBetween(returnToken, nextToken) || nextToken.type === "punctuator" && (nextToken.value === ";" || nextToken.value === "}") || nextToken.type === "eof");
|
|
125452
125462
|
}
|
|
125453
|
-
withFunctionContext(
|
|
125463
|
+
withFunctionContext(functionContext, callback) {
|
|
125454
125464
|
const previousBreakableDepth = this.breakableDepth;
|
|
125455
125465
|
const previousLoopDepth = this.loopDepth;
|
|
125456
|
-
const
|
|
125466
|
+
const previousFunctionContext = this.functionContext;
|
|
125457
125467
|
this.breakableDepth = 0;
|
|
125458
125468
|
this.loopDepth = 0;
|
|
125459
|
-
this.
|
|
125469
|
+
this.functionContext = functionContext;
|
|
125460
125470
|
try {
|
|
125461
125471
|
return callback();
|
|
125462
125472
|
} finally {
|
|
125463
125473
|
this.breakableDepth = previousBreakableDepth;
|
|
125464
125474
|
this.loopDepth = previousLoopDepth;
|
|
125465
|
-
this.
|
|
125475
|
+
this.functionContext = previousFunctionContext;
|
|
125466
125476
|
}
|
|
125467
125477
|
}
|
|
125468
125478
|
withLoopContext(callback) {
|
|
@@ -128603,6 +128613,61 @@ var init_regex = __esm({
|
|
|
128603
128613
|
}
|
|
128604
128614
|
});
|
|
128605
128615
|
|
|
128616
|
+
// packages/safe-js/src/interp/resources.ts
|
|
128617
|
+
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
128618
|
+
function retainValues(budget, values) {
|
|
128619
|
+
const retained = {};
|
|
128620
|
+
budget.setRetainedValues(retained, values);
|
|
128621
|
+
const pending = runResources.getStore()?.referenceReleases;
|
|
128622
|
+
const release2 = () => {
|
|
128623
|
+
budget.setRetainedValues(retained, void 0);
|
|
128624
|
+
pending?.delete(release2);
|
|
128625
|
+
};
|
|
128626
|
+
pending?.add(release2);
|
|
128627
|
+
return release2;
|
|
128628
|
+
}
|
|
128629
|
+
async function withRunResources(signal, execute2) {
|
|
128630
|
+
const controller = new AbortController();
|
|
128631
|
+
const cancel2 = () => controller.abort(signal?.reason);
|
|
128632
|
+
const cleanups = /* @__PURE__ */ new Set();
|
|
128633
|
+
const resources = {
|
|
128634
|
+
signal: controller.signal,
|
|
128635
|
+
referenceReleases: /* @__PURE__ */ new Set(),
|
|
128636
|
+
add(close) {
|
|
128637
|
+
cleanups.add(close);
|
|
128638
|
+
}
|
|
128639
|
+
};
|
|
128640
|
+
signal?.addEventListener("abort", cancel2, { once: true });
|
|
128641
|
+
if (signal?.aborted) cancel2();
|
|
128642
|
+
let result;
|
|
128643
|
+
let failure;
|
|
128644
|
+
let errors2 = [];
|
|
128645
|
+
try {
|
|
128646
|
+
result = await runResources.run(resources, execute2);
|
|
128647
|
+
} catch (error3) {
|
|
128648
|
+
failure = { reason: error3 };
|
|
128649
|
+
} finally {
|
|
128650
|
+
signal?.removeEventListener("abort", cancel2);
|
|
128651
|
+
controller.abort(new Error("SafeJS run finished."));
|
|
128652
|
+
for (const release2 of resources.referenceReleases) release2();
|
|
128653
|
+
resources.referenceReleases.clear();
|
|
128654
|
+
const outcomes = await Promise.allSettled(
|
|
128655
|
+
[...cleanups].map((close) => Promise.resolve().then(close))
|
|
128656
|
+
);
|
|
128657
|
+
errors2 = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
128658
|
+
}
|
|
128659
|
+
if (failure !== void 0) throw failure.reason;
|
|
128660
|
+
if (errors2.length > 0) throw new AggregateError(errors2, "SafeJS resource cleanup failed.");
|
|
128661
|
+
return result;
|
|
128662
|
+
}
|
|
128663
|
+
var runResources;
|
|
128664
|
+
var init_resources = __esm({
|
|
128665
|
+
"packages/safe-js/src/interp/resources.ts"() {
|
|
128666
|
+
"use strict";
|
|
128667
|
+
runResources = new AsyncLocalStorage6();
|
|
128668
|
+
}
|
|
128669
|
+
});
|
|
128670
|
+
|
|
128606
128671
|
// packages/safe-js/src/interp/string-coercion.ts
|
|
128607
128672
|
function sandboxNumber(value, budget, context) {
|
|
128608
128673
|
if (value === null || typeof value !== "object") {
|
|
@@ -128687,9 +128752,10 @@ async function defaultToString(value, budget, context, joining) {
|
|
|
128687
128752
|
}
|
|
128688
128753
|
if (joining.has(value)) return "";
|
|
128689
128754
|
joining.add(value);
|
|
128755
|
+
let text5 = "";
|
|
128756
|
+
const release2 = retainValues(budget, () => [text5]);
|
|
128690
128757
|
try {
|
|
128691
128758
|
const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
|
|
128692
|
-
let text5 = "";
|
|
128693
128759
|
for (let index = 0; index < length; index++) {
|
|
128694
128760
|
budget.visitNode();
|
|
128695
128761
|
const element = ownDataValue(value, String(index));
|
|
@@ -128698,15 +128764,21 @@ async function defaultToString(value, budget, context, joining) {
|
|
|
128698
128764
|
}
|
|
128699
128765
|
return text5;
|
|
128700
128766
|
} finally {
|
|
128767
|
+
release2();
|
|
128701
128768
|
joining.delete(value);
|
|
128702
128769
|
}
|
|
128703
128770
|
}
|
|
128704
128771
|
if (sandboxErrorTypes.has(value)) {
|
|
128705
128772
|
const nameValue = ownDataValue(value, "name");
|
|
128706
128773
|
const name = nameValue === void 0 ? "Error" : await sandboxString(nameValue, budget, context, joining);
|
|
128707
|
-
const
|
|
128708
|
-
|
|
128709
|
-
|
|
128774
|
+
const release2 = retainValues(budget, () => [name]);
|
|
128775
|
+
try {
|
|
128776
|
+
const messageValue2 = ownDataValue(value, "message");
|
|
128777
|
+
const message2 = messageValue2 === void 0 ? "" : await sandboxString(messageValue2, budget, context, joining);
|
|
128778
|
+
return name === "" ? message2 : message2 === "" ? name : `${name}: ${message2}`;
|
|
128779
|
+
} finally {
|
|
128780
|
+
release2();
|
|
128781
|
+
}
|
|
128710
128782
|
}
|
|
128711
128783
|
return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
|
|
128712
128784
|
}
|
|
@@ -128730,6 +128802,7 @@ var init_string_coercion = __esm({
|
|
|
128730
128802
|
init_collection_iterator();
|
|
128731
128803
|
init_object_model();
|
|
128732
128804
|
init_regex();
|
|
128805
|
+
init_resources();
|
|
128733
128806
|
init_values();
|
|
128734
128807
|
defaultStringHook = /* @__PURE__ */ Symbol("defaultStringHook");
|
|
128735
128808
|
defaultValueHook = /* @__PURE__ */ Symbol("defaultValueHook");
|
|
@@ -129370,7 +129443,7 @@ var init_iteration = __esm({
|
|
|
129370
129443
|
});
|
|
129371
129444
|
|
|
129372
129445
|
// packages/safe-js/src/interp/jobs.ts
|
|
129373
|
-
import { AsyncLocalStorage as
|
|
129446
|
+
import { AsyncLocalStorage as AsyncLocalStorage7 } from "node:async_hooks";
|
|
129374
129447
|
function runPromiseJob(task) {
|
|
129375
129448
|
const job = activeJob.getStore();
|
|
129376
129449
|
return job === void 0 ? Promise.resolve().then(task) : job.queue.run(task);
|
|
@@ -129404,7 +129477,7 @@ var activeJob, SandboxJobQueue;
|
|
|
129404
129477
|
var init_jobs4 = __esm({
|
|
129405
129478
|
"packages/safe-js/src/interp/jobs.ts"() {
|
|
129406
129479
|
"use strict";
|
|
129407
|
-
activeJob = new
|
|
129480
|
+
activeJob = new AsyncLocalStorage7();
|
|
129408
129481
|
SandboxJobQueue = class {
|
|
129409
129482
|
running = false;
|
|
129410
129483
|
pending = [];
|
|
@@ -130218,7 +130291,7 @@ var init_promise = __esm({
|
|
|
130218
130291
|
});
|
|
130219
130292
|
|
|
130220
130293
|
// packages/safe-js/src/interp/cancel.ts
|
|
130221
|
-
import { AsyncLocalStorage as
|
|
130294
|
+
import { AsyncLocalStorage as AsyncLocalStorage8 } from "node:async_hooks";
|
|
130222
130295
|
function withCancellationSignal(signal, task) {
|
|
130223
130296
|
return activeCancellation.run({ signal, host: false }, task);
|
|
130224
130297
|
}
|
|
@@ -130403,7 +130476,7 @@ var init_cancel2 = __esm({
|
|
|
130403
130476
|
init_promise_tracker();
|
|
130404
130477
|
init_shape();
|
|
130405
130478
|
init_promise();
|
|
130406
|
-
activeCancellation = new
|
|
130479
|
+
activeCancellation = new AsyncLocalStorage8();
|
|
130407
130480
|
sandboxPromises = /* @__PURE__ */ new WeakSet();
|
|
130408
130481
|
cancelableOutcomes = /* @__PURE__ */ new WeakMap();
|
|
130409
130482
|
}
|
|
@@ -144084,50 +144157,6 @@ var init_var_hoist = __esm({
|
|
|
144084
144157
|
}
|
|
144085
144158
|
});
|
|
144086
144159
|
|
|
144087
|
-
// packages/safe-js/src/interp/resources.ts
|
|
144088
|
-
import { AsyncLocalStorage as AsyncLocalStorage8 } from "node:async_hooks";
|
|
144089
|
-
async function withRunResources(signal, execute2) {
|
|
144090
|
-
const controller = new AbortController();
|
|
144091
|
-
const cancel2 = () => controller.abort(signal?.reason);
|
|
144092
|
-
const cleanups = /* @__PURE__ */ new Set();
|
|
144093
|
-
const resources = {
|
|
144094
|
-
signal: controller.signal,
|
|
144095
|
-
referenceReleases: /* @__PURE__ */ new Set(),
|
|
144096
|
-
add(close) {
|
|
144097
|
-
cleanups.add(close);
|
|
144098
|
-
}
|
|
144099
|
-
};
|
|
144100
|
-
signal?.addEventListener("abort", cancel2, { once: true });
|
|
144101
|
-
if (signal?.aborted) cancel2();
|
|
144102
|
-
let result;
|
|
144103
|
-
let failure;
|
|
144104
|
-
let errors2 = [];
|
|
144105
|
-
try {
|
|
144106
|
-
result = await runResources.run(resources, execute2);
|
|
144107
|
-
} catch (error3) {
|
|
144108
|
-
failure = { reason: error3 };
|
|
144109
|
-
} finally {
|
|
144110
|
-
signal?.removeEventListener("abort", cancel2);
|
|
144111
|
-
controller.abort(new Error("SafeJS run finished."));
|
|
144112
|
-
for (const release2 of resources.referenceReleases) release2();
|
|
144113
|
-
resources.referenceReleases.clear();
|
|
144114
|
-
const outcomes = await Promise.allSettled(
|
|
144115
|
-
[...cleanups].map((close) => Promise.resolve().then(close))
|
|
144116
|
-
);
|
|
144117
|
-
errors2 = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
144118
|
-
}
|
|
144119
|
-
if (failure !== void 0) throw failure.reason;
|
|
144120
|
-
if (errors2.length > 0) throw new AggregateError(errors2, "SafeJS resource cleanup failed.");
|
|
144121
|
-
return result;
|
|
144122
|
-
}
|
|
144123
|
-
var runResources;
|
|
144124
|
-
var init_resources = __esm({
|
|
144125
|
-
"packages/safe-js/src/interp/resources.ts"() {
|
|
144126
|
-
"use strict";
|
|
144127
|
-
runResources = new AsyncLocalStorage8();
|
|
144128
|
-
}
|
|
144129
|
-
});
|
|
144130
|
-
|
|
144131
144160
|
// packages/safe-js/src/interp/methods/array.ts
|
|
144132
144161
|
function getArrayMember(value, property, options) {
|
|
144133
144162
|
const index = getArrayIndex(property);
|
|
@@ -145291,6 +145320,9 @@ function isStringMethodName(property) {
|
|
|
145291
145320
|
function validateStringMethodArguments(_methodName, _args) {
|
|
145292
145321
|
}
|
|
145293
145322
|
function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent, context) {
|
|
145323
|
+
if (methodName === "concat" && args.some((argument) => argument !== null && typeof argument === "object")) {
|
|
145324
|
+
return callConcat(value, args, budget, context);
|
|
145325
|
+
}
|
|
145294
145326
|
if (methodName === "isWellFormed") {
|
|
145295
145327
|
for (let index = 0; index < value.length; index++) {
|
|
145296
145328
|
const codeUnit = value.charCodeAt(index);
|
|
@@ -145446,6 +145478,19 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
|
|
|
145446
145478
|
operation.release();
|
|
145447
145479
|
}
|
|
145448
145480
|
}
|
|
145481
|
+
async function callConcat(value, args, budget, context) {
|
|
145482
|
+
let result = budget.allocateString(value);
|
|
145483
|
+
const release2 = retainValues(budget, () => [result]);
|
|
145484
|
+
try {
|
|
145485
|
+
for (const argument of args) {
|
|
145486
|
+
const text5 = sandboxString(argument, budget, context);
|
|
145487
|
+
result = budget.allocateString(result + (typeof text5 === "string" ? text5 : await text5));
|
|
145488
|
+
}
|
|
145489
|
+
return result;
|
|
145490
|
+
} finally {
|
|
145491
|
+
release2();
|
|
145492
|
+
}
|
|
145493
|
+
}
|
|
145449
145494
|
function callReplaceLikeMethod(value, methodName, args, budget, callClosure, context) {
|
|
145450
145495
|
const search = args[0];
|
|
145451
145496
|
const replacement = args[1];
|
|
@@ -145699,6 +145744,7 @@ var init_string = __esm({
|
|
|
145699
145744
|
init_compile_guard();
|
|
145700
145745
|
init_engine2();
|
|
145701
145746
|
init_string_coercion();
|
|
145747
|
+
init_resources();
|
|
145702
145748
|
init_values();
|
|
145703
145749
|
init_regex();
|
|
145704
145750
|
SPLIT_STRING_MESSAGE = "String#split only supports string separator values.";
|
|
@@ -146983,14 +147029,18 @@ function isObjectPrototypeSetterProperty(property, key3) {
|
|
|
146983
147029
|
}
|
|
146984
147030
|
async function evaluateTemplateLiteral(node, context) {
|
|
146985
147031
|
let value = context.budget.allocateString(node.quasis[0]?.value.cooked ?? "");
|
|
146986
|
-
|
|
147032
|
+
let input = void 0;
|
|
147033
|
+
const release2 = retainValues(context.budget, () => [value, input]);
|
|
146987
147034
|
try {
|
|
146988
147035
|
for (let index = 0; index < node.expressions.length; index += 1) {
|
|
146989
147036
|
const expression = await evaluateNode2(node.expressions[index], context);
|
|
146990
147037
|
if (expression.kind !== "normal") {
|
|
146991
147038
|
return expression;
|
|
146992
147039
|
}
|
|
146993
|
-
|
|
147040
|
+
input = expression.value;
|
|
147041
|
+
const text5 = sandboxString(input, context.budget, createCoercionContext(context));
|
|
147042
|
+
const expressionText = typeof text5 === "string" ? text5 : await text5;
|
|
147043
|
+
input = void 0;
|
|
146994
147044
|
value = context.budget.allocateString(value + expressionText);
|
|
146995
147045
|
const quasiText = context.budget.allocateString(node.quasis[index + 1]?.value.cooked ?? "");
|
|
146996
147046
|
value = context.budget.allocateString(value + quasiText);
|
|
@@ -148437,17 +148487,6 @@ async function evaluateMemberAccess(node, context, consume) {
|
|
|
148437
148487
|
release2();
|
|
148438
148488
|
}
|
|
148439
148489
|
}
|
|
148440
|
-
function retainValues(budget, values) {
|
|
148441
|
-
const retained = {};
|
|
148442
|
-
budget.setRetainedValues(retained, values);
|
|
148443
|
-
const pending = runResources.getStore()?.referenceReleases;
|
|
148444
|
-
const release2 = () => {
|
|
148445
|
-
budget.setRetainedValues(retained, void 0);
|
|
148446
|
-
pending?.delete(release2);
|
|
148447
|
-
};
|
|
148448
|
-
pending?.add(release2);
|
|
148449
|
-
return release2;
|
|
148450
|
-
}
|
|
148451
148490
|
async function evaluateMemberProperty(node, context) {
|
|
148452
148491
|
const property = await evaluateNode2(node, context);
|
|
148453
148492
|
if (property.kind !== "normal") {
|
|
@@ -149397,6 +149436,7 @@ var init_interpreter = __esm({
|
|
|
149397
149436
|
init_jobs4();
|
|
149398
149437
|
init_cancel2();
|
|
149399
149438
|
init_resources();
|
|
149439
|
+
init_string_coercion();
|
|
149400
149440
|
init_shape();
|
|
149401
149441
|
init_async();
|
|
149402
149442
|
init_host_call();
|