@poe-platform/safe-js 0.1.426 → 0.1.428
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-V3XJABDF.js → chunk-KHHM7HUO.js} +1343 -374
- package/dist/safe-js/chunks/chunk-KHHM7HUO.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-MYKH5PM4.js → chunk-LXXUZNYA.js} +2 -2
- 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/async-disposable-stack.d.ts +36 -0
- package/dist/safe-js/interp/async.d.ts +7 -3
- package/dist/safe-js/interp/exceptions.d.ts +4 -1
- package/dist/safe-js/interp/generator-expression-state.d.ts +15 -3
- package/dist/safe-js/interp/generator.d.ts +3 -3
- package/dist/safe-js/interp/iteration.d.ts +10 -1
- package/dist/safe-js/interp/jobs.d.ts +4 -0
- package/dist/safe-js/interp/resource-management.d.ts +26 -0
- package/dist/safe-js/interp/scope.d.ts +4 -0
- package/dist/safe-js/parse/parser.d.ts +1 -0
- package/dist/safe-js/snapshot/guest-heap.d.ts +46 -0
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-V3XJABDF.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-MYKH5PM4.js.map → chunk-LXXUZNYA.js.map} +0 -0
|
@@ -3315,12 +3315,16 @@ var Parser = class {
|
|
|
3315
3315
|
span: createSpan2(start.start, this.previousToken().end)
|
|
3316
3316
|
};
|
|
3317
3317
|
}
|
|
3318
|
-
parseStatement() {
|
|
3318
|
+
parseStatement(allowResourceDeclaration = true) {
|
|
3319
3319
|
const emptyStatement = this.parseEmptyStatement();
|
|
3320
3320
|
if (emptyStatement !== void 0) {
|
|
3321
3321
|
return emptyStatement;
|
|
3322
3322
|
}
|
|
3323
3323
|
const token = this.currentToken();
|
|
3324
|
+
if (this.resourceDeclarationHint() !== void 0) {
|
|
3325
|
+
if (!allowResourceDeclaration) throw unexpectedTokenError(token);
|
|
3326
|
+
return this.parseResourceDeclaration();
|
|
3327
|
+
}
|
|
3324
3328
|
if (token.type === "identifier" && this.peekToken(1).type === "punctuator" && this.peekToken(1).value === ":") {
|
|
3325
3329
|
this.index += 2;
|
|
3326
3330
|
return this.parseLabeledStatement([token.value], token);
|
|
@@ -3455,7 +3459,7 @@ var Parser = class {
|
|
|
3455
3459
|
if (token.type === "keyword" && token.value === "while") return this.parseWhileStatement(labels);
|
|
3456
3460
|
if (token.type === "keyword" && token.value === "do") return this.parseDoWhileStatement(labels);
|
|
3457
3461
|
if (token.type === "punctuator" && token.value === "{") return { ...this.parseBlockStatement(), labels };
|
|
3458
|
-
if (["let", "const", "class", "function", "import", "export"].includes(token.value) || this.isAsyncFunctionDeclarationStart())
|
|
3462
|
+
if (["let", "const", "class", "function", "import", "export"].includes(token.value) || this.isAsyncFunctionDeclarationStart() || this.resourceDeclarationHint() !== void 0)
|
|
3459
3463
|
throw new DisallowedSyntaxError("labeled declaration", firstLabelToken.start);
|
|
3460
3464
|
const statement = this.parseStatement();
|
|
3461
3465
|
if (statement.type === "ImportDeclaration" || statement.type === "ExportDefaultDeclaration" || statement.type === "ExportNamedDeclaration")
|
|
@@ -3478,14 +3482,14 @@ var Parser = class {
|
|
|
3478
3482
|
this.expectPunctuator("(");
|
|
3479
3483
|
const test = this.parseExpression({ allowSequence: true }).node;
|
|
3480
3484
|
this.expectPunctuator(")");
|
|
3481
|
-
const consequent = this.parseStatement();
|
|
3485
|
+
const consequent = this.parseStatement(false);
|
|
3482
3486
|
if (consequent.type !== "BlockStatement") {
|
|
3483
3487
|
while (this.currentToken().type === "punctuator" && this.currentToken().value === ";" && this.peekToken(1).type === "keyword" && this.peekToken(1).value === "else") {
|
|
3484
3488
|
this.index += 1;
|
|
3485
3489
|
}
|
|
3486
3490
|
}
|
|
3487
3491
|
const elseToken = this.consumeKeyword("else");
|
|
3488
|
-
const alternate = elseToken === void 0 ? void 0 : this.parseStatement();
|
|
3492
|
+
const alternate = elseToken === void 0 ? void 0 : this.parseStatement(false);
|
|
3489
3493
|
return {
|
|
3490
3494
|
type: "IfStatement",
|
|
3491
3495
|
test,
|
|
@@ -3576,11 +3580,12 @@ var Parser = class {
|
|
|
3576
3580
|
throw new Error("for await requires an of loop.");
|
|
3577
3581
|
}
|
|
3578
3582
|
if (iterationOperator?.value === "in") {
|
|
3583
|
+
if (this.resourceDeclarationHint() !== void 0) throw unexpectedTokenError(this.currentToken());
|
|
3579
3584
|
const left = this.parseForOfLeft();
|
|
3580
3585
|
this.expectKeyword("in");
|
|
3581
3586
|
const right = this.parseExpression().node;
|
|
3582
3587
|
this.expectPunctuator(")");
|
|
3583
|
-
const body2 = this.withLoopContext(() => this.parseStatement());
|
|
3588
|
+
const body2 = this.withLoopContext(() => this.parseStatement(false));
|
|
3584
3589
|
return {
|
|
3585
3590
|
type: "ForInStatement",
|
|
3586
3591
|
left,
|
|
@@ -3595,7 +3600,7 @@ var Parser = class {
|
|
|
3595
3600
|
this.expectKeyword("of");
|
|
3596
3601
|
const right = this.parseExpression().node;
|
|
3597
3602
|
this.expectPunctuator(")");
|
|
3598
|
-
const body2 = this.withLoopContext(() => this.parseStatement());
|
|
3603
|
+
const body2 = this.withLoopContext(() => this.parseStatement(false));
|
|
3599
3604
|
return {
|
|
3600
3605
|
type: "ForOfStatement",
|
|
3601
3606
|
...awaitToken === void 0 ? {} : { await: true },
|
|
@@ -3608,7 +3613,7 @@ var Parser = class {
|
|
|
3608
3613
|
}
|
|
3609
3614
|
let init;
|
|
3610
3615
|
if (this.consumePunctuator(";") === void 0) {
|
|
3611
|
-
init = (this.currentToken().type === "keyword" || this.currentToken().type === "identifier") && (this.currentToken().value === "const" || this.currentToken().value === "let" || this.currentToken().value === "var") ? this.parseVariableDeclaration() : this.parseExpression({ allowSequence: true }).node;
|
|
3616
|
+
init = this.resourceDeclarationHint() !== void 0 ? this.parseResourceDeclaration() : (this.currentToken().type === "keyword" || this.currentToken().type === "identifier") && (this.currentToken().value === "const" || this.currentToken().value === "let" || this.currentToken().value === "var") ? this.parseVariableDeclaration() : this.parseExpression({ allowSequence: true }).node;
|
|
3612
3617
|
this.expectPunctuator(";");
|
|
3613
3618
|
}
|
|
3614
3619
|
let test;
|
|
@@ -3618,7 +3623,7 @@ var Parser = class {
|
|
|
3618
3623
|
}
|
|
3619
3624
|
const update = this.currentToken().type === "punctuator" && this.currentToken().value === ")" ? void 0 : this.parseExpression({ allowSequence: true }).node;
|
|
3620
3625
|
this.expectPunctuator(")");
|
|
3621
|
-
const body = this.withLoopContext(() => this.parseStatement());
|
|
3626
|
+
const body = this.withLoopContext(() => this.parseStatement(false));
|
|
3622
3627
|
return {
|
|
3623
3628
|
type: "ForStatement",
|
|
3624
3629
|
init,
|
|
@@ -3631,6 +3636,9 @@ var Parser = class {
|
|
|
3631
3636
|
});
|
|
3632
3637
|
}
|
|
3633
3638
|
parseForOfLeft() {
|
|
3639
|
+
if (this.resourceDeclarationHint() !== void 0 && this.peekToken(1).value !== "of") {
|
|
3640
|
+
return this.parseResourceDeclaration(true);
|
|
3641
|
+
}
|
|
3634
3642
|
if ((this.currentToken().type === "keyword" || this.currentToken().type === "identifier") && (this.currentToken().value === "const" || this.currentToken().value === "let" || this.currentToken().value === "var")) {
|
|
3635
3643
|
return this.parseForOfDeclaration();
|
|
3636
3644
|
}
|
|
@@ -3671,7 +3679,7 @@ var Parser = class {
|
|
|
3671
3679
|
this.expectPunctuator("(");
|
|
3672
3680
|
const test = this.parseExpression({ allowSequence: true }).node;
|
|
3673
3681
|
this.expectPunctuator(")");
|
|
3674
|
-
const body = this.withLoopContext(() => this.parseStatement());
|
|
3682
|
+
const body = this.withLoopContext(() => this.parseStatement(false));
|
|
3675
3683
|
return {
|
|
3676
3684
|
type: "WhileStatement",
|
|
3677
3685
|
test,
|
|
@@ -3682,7 +3690,7 @@ var Parser = class {
|
|
|
3682
3690
|
}
|
|
3683
3691
|
parseDoWhileStatement(labels) {
|
|
3684
3692
|
const doToken = this.expectKeyword("do");
|
|
3685
|
-
const body = this.withLoopContext(() => this.parseStatement());
|
|
3693
|
+
const body = this.withLoopContext(() => this.parseStatement(false));
|
|
3686
3694
|
this.expectKeyword("while");
|
|
3687
3695
|
this.expectPunctuator("(");
|
|
3688
3696
|
const test = this.parseExpression({ allowSequence: true }).node;
|
|
@@ -3877,6 +3885,35 @@ var Parser = class {
|
|
|
3877
3885
|
span: createSpan2(kindToken.start, declarations[declarations.length - 1].span.end)
|
|
3878
3886
|
};
|
|
3879
3887
|
}
|
|
3888
|
+
resourceDeclarationHint() {
|
|
3889
|
+
const token = this.currentToken();
|
|
3890
|
+
const offset = token.value === "await" && this.peekToken(1).value === "using" ? 1 : 0;
|
|
3891
|
+
const using = offset === 0 ? token : this.peekToken(1);
|
|
3892
|
+
const binding = this.peekToken(offset + 1);
|
|
3893
|
+
if (using.value !== "using" || hasLineBreakBetween(using, binding) || !isIdentifierLikeToken(binding)) return void 0;
|
|
3894
|
+
if (offset === 1 && hasLineBreakBetween(token, using)) throw unexpectedTokenError(using);
|
|
3895
|
+
return offset === 1 ? "async" : "sync";
|
|
3896
|
+
}
|
|
3897
|
+
parseResourceDeclaration(iteration = false) {
|
|
3898
|
+
const start = this.currentToken();
|
|
3899
|
+
const disposal = this.resourceDeclarationHint();
|
|
3900
|
+
if (disposal === "async") {
|
|
3901
|
+
if (!this.lexicalContext.await || !["top-level", "async", "async-generator"].includes(this.functionContext)) {
|
|
3902
|
+
throw unexpectedTokenError(start);
|
|
3903
|
+
}
|
|
3904
|
+
this.index++;
|
|
3905
|
+
}
|
|
3906
|
+
this.index++;
|
|
3907
|
+
const declarations = [];
|
|
3908
|
+
do {
|
|
3909
|
+
const id = this.parseBindingIdentifier();
|
|
3910
|
+
if (id.name === "let" || disposal === "async" && id.name === "await" || iteration && disposal === "sync" && id.name === "of") throw new Error(`Invalid resource binding '${id.name}'.`);
|
|
3911
|
+
this.declarePatternBindings(id);
|
|
3912
|
+
const init = iteration ? void 0 : (this.expectPunctuator("="), this.parseExpression().node);
|
|
3913
|
+
declarations.push({ type: "VariableDeclarator", id, ...init === void 0 ? {} : { init }, span: createSpan2(id.span.start, init?.span.end ?? id.span.end) });
|
|
3914
|
+
} while (!iteration && this.consumePunctuator(",") !== void 0);
|
|
3915
|
+
return { type: "VariableDeclaration", kind: "const", disposal, declarations, span: createSpan2(start.start, declarations.at(-1).span.end) };
|
|
3916
|
+
}
|
|
3880
3917
|
parseFunctionDeclaration(defaultExport = false) {
|
|
3881
3918
|
const asyncToken = this.consumeKeyword("async");
|
|
3882
3919
|
const functionToken = this.expectKeyword("function");
|
|
@@ -5683,6 +5720,7 @@ var Parser = class {
|
|
|
5683
5720
|
}
|
|
5684
5721
|
shouldParseTopLevelStatement() {
|
|
5685
5722
|
const token = this.currentToken();
|
|
5723
|
+
if (this.resourceDeclarationHint() !== void 0) return true;
|
|
5686
5724
|
if (this.isAsyncFunctionDeclarationStart()) {
|
|
5687
5725
|
return true;
|
|
5688
5726
|
}
|
|
@@ -7786,6 +7824,7 @@ var wellKnownSymbols = Object.freeze({
|
|
|
7786
7824
|
// packages/safe-js/src/interp/intrinsics.ts
|
|
7787
7825
|
var identities = /* @__PURE__ */ new WeakMap();
|
|
7788
7826
|
var realms2 = /* @__PURE__ */ new WeakMap();
|
|
7827
|
+
var mutableBuiltinBindings = /* @__PURE__ */ new WeakMap();
|
|
7789
7828
|
function registerBuiltinIdentities(budget, bindings) {
|
|
7790
7829
|
let realm = realms2.get(budget);
|
|
7791
7830
|
if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
|
|
@@ -9336,6 +9375,485 @@ function restoreRegexProperties(value, data, decode) {
|
|
|
9336
9375
|
// packages/safe-js/src/snapshot/validation.ts
|
|
9337
9376
|
import { types as types10 } from "node:util";
|
|
9338
9377
|
|
|
9378
|
+
// packages/safe-js/src/interp/promise-continuations.ts
|
|
9379
|
+
var thenableContinuations = /* @__PURE__ */ new WeakMap();
|
|
9380
|
+
var thenableStates = /* @__PURE__ */ new WeakMap();
|
|
9381
|
+
var thenableResolvers = /* @__PURE__ */ new WeakMap();
|
|
9382
|
+
var promiseCapabilityExecutors = /* @__PURE__ */ new WeakMap();
|
|
9383
|
+
var promiseAggregateHandlers = /* @__PURE__ */ new WeakMap();
|
|
9384
|
+
var promiseAggregateStates = /* @__PURE__ */ new WeakMap();
|
|
9385
|
+
var promiseAggregateEntries = /* @__PURE__ */ new WeakMap();
|
|
9386
|
+
var promiseAdoptions = /* @__PURE__ */ new WeakMap();
|
|
9387
|
+
var promiseAdoptionBridges = /* @__PURE__ */ new WeakMap();
|
|
9388
|
+
var promiseAdoptionResolvers = /* @__PURE__ */ new WeakMap();
|
|
9389
|
+
var promiseContinuations = /* @__PURE__ */ new WeakMap();
|
|
9390
|
+
var promiseReactionResults = /* @__PURE__ */ new WeakMap();
|
|
9391
|
+
var promiseProducers = /* @__PURE__ */ new WeakMap();
|
|
9392
|
+
function linkPromiseAggregateProducer(producer, aggregate) {
|
|
9393
|
+
const continuation = promiseContinuations.get(producer);
|
|
9394
|
+
if (continuation?.kind !== "reaction") return;
|
|
9395
|
+
continuation.aggregate = aggregate;
|
|
9396
|
+
let producers = promiseProducers.get(aggregate);
|
|
9397
|
+
if (producers === void 0) promiseProducers.set(aggregate, producers = /* @__PURE__ */ new Set());
|
|
9398
|
+
producers.add(producer);
|
|
9399
|
+
}
|
|
9400
|
+
function trackPromiseContinuation(promise, continuation) {
|
|
9401
|
+
promiseContinuations.set(promise, continuation);
|
|
9402
|
+
if (continuation.kind === "reaction") {
|
|
9403
|
+
let results = promiseReactionResults.get(continuation.source);
|
|
9404
|
+
if (results === void 0) promiseReactionResults.set(continuation.source, results = /* @__PURE__ */ new Set());
|
|
9405
|
+
results.add(promise);
|
|
9406
|
+
if (continuation.capability !== void 0) {
|
|
9407
|
+
let producers = promiseProducers.get(continuation.capability.promise);
|
|
9408
|
+
if (producers === void 0) promiseProducers.set(continuation.capability.promise, producers = /* @__PURE__ */ new Set());
|
|
9409
|
+
producers.add(promise);
|
|
9410
|
+
}
|
|
9411
|
+
}
|
|
9412
|
+
const release = () => {
|
|
9413
|
+
promiseContinuations.delete(promise);
|
|
9414
|
+
if (continuation.kind === "capability") delete continuation.resolution;
|
|
9415
|
+
else {
|
|
9416
|
+
const results = promiseReactionResults.get(continuation.source);
|
|
9417
|
+
results?.delete(promise);
|
|
9418
|
+
if (results?.size === 0) promiseReactionResults.delete(continuation.source);
|
|
9419
|
+
if (continuation.capability !== void 0) {
|
|
9420
|
+
const producers = promiseProducers.get(continuation.capability.promise);
|
|
9421
|
+
producers?.delete(promise);
|
|
9422
|
+
if (producers?.size === 0) promiseProducers.delete(continuation.capability.promise);
|
|
9423
|
+
}
|
|
9424
|
+
if (continuation.aggregate !== void 0) {
|
|
9425
|
+
const producers = promiseProducers.get(continuation.aggregate);
|
|
9426
|
+
producers?.delete(promise);
|
|
9427
|
+
if (producers?.size === 0) promiseProducers.delete(continuation.aggregate);
|
|
9428
|
+
}
|
|
9429
|
+
}
|
|
9430
|
+
};
|
|
9431
|
+
promise.promise.then(release, release);
|
|
9432
|
+
}
|
|
9433
|
+
|
|
9434
|
+
// packages/safe-js/src/interp/jobs.ts
|
|
9435
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
9436
|
+
var activeJob = new AsyncLocalStorage3();
|
|
9437
|
+
var SandboxJobQueue = class {
|
|
9438
|
+
running = false;
|
|
9439
|
+
pending = [];
|
|
9440
|
+
ready = [];
|
|
9441
|
+
idle = [];
|
|
9442
|
+
generation = 0;
|
|
9443
|
+
bind(task) {
|
|
9444
|
+
return activeJob.run({ queue: this, ownsExecution: false }, task);
|
|
9445
|
+
}
|
|
9446
|
+
acquire(job) {
|
|
9447
|
+
return new Promise((resolve) => {
|
|
9448
|
+
this.pending.push(() => {
|
|
9449
|
+
this.running = true;
|
|
9450
|
+
this.generation += 1;
|
|
9451
|
+
job.ownsExecution = true;
|
|
9452
|
+
resolve();
|
|
9453
|
+
});
|
|
9454
|
+
this.advance();
|
|
9455
|
+
});
|
|
9456
|
+
}
|
|
9457
|
+
release(job) {
|
|
9458
|
+
job.prefixParent = void 0;
|
|
9459
|
+
if (!job.ownsExecution) return;
|
|
9460
|
+
job.ownsExecution = false;
|
|
9461
|
+
this.running = false;
|
|
9462
|
+
this.advance();
|
|
9463
|
+
}
|
|
9464
|
+
async run(task) {
|
|
9465
|
+
const job = { queue: this, ownsExecution: false };
|
|
9466
|
+
await this.acquire(job);
|
|
9467
|
+
return activeJob.run(job, async () => {
|
|
9468
|
+
try {
|
|
9469
|
+
return await task();
|
|
9470
|
+
} finally {
|
|
9471
|
+
this.release(job);
|
|
9472
|
+
}
|
|
9473
|
+
});
|
|
9474
|
+
}
|
|
9475
|
+
async drain() {
|
|
9476
|
+
let idleTurns = 0;
|
|
9477
|
+
while (idleTurns < 20) {
|
|
9478
|
+
const generation = this.generation;
|
|
9479
|
+
if (this.running) await new Promise((resolve) => this.idle.push(resolve));
|
|
9480
|
+
await Promise.resolve();
|
|
9481
|
+
idleTurns = generation === this.generation ? idleTurns + 1 : 0;
|
|
9482
|
+
}
|
|
9483
|
+
}
|
|
9484
|
+
advance() {
|
|
9485
|
+
if (this.running) return;
|
|
9486
|
+
if (this.ready.length === 0 && this.pending.length > 0) {
|
|
9487
|
+
const empty = this.ready;
|
|
9488
|
+
this.ready = this.pending.reverse();
|
|
9489
|
+
this.pending = empty;
|
|
9490
|
+
}
|
|
9491
|
+
const next = this.ready.pop();
|
|
9492
|
+
if (next !== void 0) {
|
|
9493
|
+
next();
|
|
9494
|
+
} else {
|
|
9495
|
+
for (const resolve of this.idle.splice(0)) resolve();
|
|
9496
|
+
}
|
|
9497
|
+
}
|
|
9498
|
+
};
|
|
9499
|
+
function runPromiseJob(task) {
|
|
9500
|
+
const job = activeJob.getStore();
|
|
9501
|
+
return job === void 0 ? Promise.resolve().then(task) : job.queue.run(task);
|
|
9502
|
+
}
|
|
9503
|
+
function createResumableJobContext() {
|
|
9504
|
+
let frame;
|
|
9505
|
+
return { run: (task) => {
|
|
9506
|
+
const parent = activeJob.getStore();
|
|
9507
|
+
if (parent === void 0) return task();
|
|
9508
|
+
frame ??= { queue: parent.queue, ownsExecution: false };
|
|
9509
|
+
for (let ancestor = parent; ancestor !== void 0; ancestor = ancestor.prefixParent) {
|
|
9510
|
+
if (ancestor === frame) return activeJob.run(frame, task);
|
|
9511
|
+
}
|
|
9512
|
+
frame.queue = parent.queue;
|
|
9513
|
+
frame.prefixParent = parent;
|
|
9514
|
+
return activeJob.run(frame, task);
|
|
9515
|
+
}, release: () => {
|
|
9516
|
+
if (frame !== void 0) frame.queue.release(frame);
|
|
9517
|
+
} };
|
|
9518
|
+
}
|
|
9519
|
+
function runAsyncPrefix(task) {
|
|
9520
|
+
const parent = activeJob.getStore();
|
|
9521
|
+
if (parent === void 0) return task();
|
|
9522
|
+
let owner = parent;
|
|
9523
|
+
while (owner !== void 0 && !owner.ownsExecution) owner = owner.prefixParent;
|
|
9524
|
+
if (owner === void 0) return parent.queue.run(task);
|
|
9525
|
+
const job = { queue: parent.queue, ownsExecution: false, prefixParent: parent };
|
|
9526
|
+
return activeJob.run(job, async () => {
|
|
9527
|
+
try {
|
|
9528
|
+
return await task();
|
|
9529
|
+
} finally {
|
|
9530
|
+
job.queue.release(job);
|
|
9531
|
+
}
|
|
9532
|
+
});
|
|
9533
|
+
}
|
|
9534
|
+
async function suspendJob(pending) {
|
|
9535
|
+
const job = activeJob.getStore();
|
|
9536
|
+
if (job === void 0) return pending;
|
|
9537
|
+
job.queue.release(job);
|
|
9538
|
+
try {
|
|
9539
|
+
return await pending;
|
|
9540
|
+
} finally {
|
|
9541
|
+
await job.queue.acquire(job);
|
|
9542
|
+
}
|
|
9543
|
+
}
|
|
9544
|
+
|
|
9545
|
+
// packages/safe-js/src/interp/async-function-driver.ts
|
|
9546
|
+
var asyncFunctionDrivers = /* @__PURE__ */ new WeakMap();
|
|
9547
|
+
var asyncFunctionHandlers = /* @__PURE__ */ new WeakMap();
|
|
9548
|
+
var asyncFunctionSignals = /* @__PURE__ */ new WeakMap();
|
|
9549
|
+
var abortReleases = /* @__PURE__ */ new WeakMap();
|
|
9550
|
+
function bindAsyncFunctionSignal(driver, signal, budget, context) {
|
|
9551
|
+
abortReleases.get(driver)?.();
|
|
9552
|
+
if (signal === void 0) asyncFunctionSignals.delete(driver);
|
|
9553
|
+
else asyncFunctionSignals.set(driver, signal);
|
|
9554
|
+
if (driver.phase !== "waiting") return;
|
|
9555
|
+
const generation = driver.generation;
|
|
9556
|
+
let notify;
|
|
9557
|
+
const aborted = new Promise((resolve) => {
|
|
9558
|
+
notify = resolve;
|
|
9559
|
+
});
|
|
9560
|
+
let active = true;
|
|
9561
|
+
const abort = () => notify(signal?.reason ?? new DOMException("The operation was aborted.", "AbortError"));
|
|
9562
|
+
const release = () => {
|
|
9563
|
+
active = false;
|
|
9564
|
+
signal?.removeEventListener("abort", abort);
|
|
9565
|
+
detachFatal?.();
|
|
9566
|
+
if (abortReleases.get(driver) === release) abortReleases.delete(driver);
|
|
9567
|
+
};
|
|
9568
|
+
abortReleases.set(driver, release);
|
|
9569
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
9570
|
+
const detachFatal = onFatalPromiseRejection(notify);
|
|
9571
|
+
void aborted.then((reason) => runPromiseJob(async () => {
|
|
9572
|
+
if (!active || driver.phase !== "waiting" || driver.generation !== generation) return;
|
|
9573
|
+
if (isFatalSandboxError(reason)) {
|
|
9574
|
+
release();
|
|
9575
|
+
driver.phase = "running";
|
|
9576
|
+
await withFatalPromiseCleanup(async () => {
|
|
9577
|
+
if (driver.generator?.state !== "done") await driver.generator?.channel.throw(reason);
|
|
9578
|
+
});
|
|
9579
|
+
throw reason;
|
|
9580
|
+
}
|
|
9581
|
+
const handler = createAsyncFunctionHandler(driver, "rejected", generation, budget, context);
|
|
9582
|
+
await handler.call([createThrowCompletion(reason, budget, context?.stack ?? []).value], context);
|
|
9583
|
+
})).catch((error) => {
|
|
9584
|
+
release();
|
|
9585
|
+
driver.phase = "done";
|
|
9586
|
+
if (driver.generator !== void 0) driver.generator.state = "done";
|
|
9587
|
+
const reject = pendingPromiseRejectors.get(driver.capability.promise);
|
|
9588
|
+
if (reject === void 0) throw new TypeError("Missing async function rejection capability.");
|
|
9589
|
+
reject(error);
|
|
9590
|
+
});
|
|
9591
|
+
if (signal?.aborted) abort();
|
|
9592
|
+
}
|
|
9593
|
+
function startAsyncFunction(initialize, budget, context, signal) {
|
|
9594
|
+
let completePrefix;
|
|
9595
|
+
let failPrefix;
|
|
9596
|
+
const prefix = new Promise((resolve, reject) => {
|
|
9597
|
+
completePrefix = resolve;
|
|
9598
|
+
failPrefix = reject;
|
|
9599
|
+
});
|
|
9600
|
+
void prefix.catch(() => void 0);
|
|
9601
|
+
const capability = createPendingPromiseCapability(budget, context, prefix);
|
|
9602
|
+
const driver = { capability: { promise: capability.promise, resolve: capability.resolve, reject: capability.reject }, phase: "running", generation: 0 };
|
|
9603
|
+
asyncFunctionDrivers.set(driver, driver);
|
|
9604
|
+
bindAsyncFunctionSignal(driver, signal, budget, context);
|
|
9605
|
+
void runAsyncPrefix(async () => {
|
|
9606
|
+
try {
|
|
9607
|
+
driver.generator = await initialize(completePrefix);
|
|
9608
|
+
await advanceAsyncFunction(driver, "fulfilled", void 0, budget, context);
|
|
9609
|
+
} catch (error) {
|
|
9610
|
+
driver.phase = "done";
|
|
9611
|
+
if (isFatalSandboxError(error)) throw error;
|
|
9612
|
+
await capability.reject.call([createThrowCompletion(error, budget, context?.stack ?? []).value], context);
|
|
9613
|
+
}
|
|
9614
|
+
}).then(completePrefix, (error) => {
|
|
9615
|
+
capability.rejectNative(error);
|
|
9616
|
+
failPrefix(error);
|
|
9617
|
+
});
|
|
9618
|
+
return capability.promise;
|
|
9619
|
+
}
|
|
9620
|
+
function createAsyncFunctionHandler(driver, action, generation, budget, context) {
|
|
9621
|
+
const handler = createSandboxClosure({
|
|
9622
|
+
guest: true,
|
|
9623
|
+
sandbox: true,
|
|
9624
|
+
name: "",
|
|
9625
|
+
length: 1,
|
|
9626
|
+
retainedValues: () => [driver],
|
|
9627
|
+
call: async ([value]) => {
|
|
9628
|
+
if (driver.phase !== "waiting" || driver.generation !== generation) return void 0;
|
|
9629
|
+
abortReleases.get(driver)?.();
|
|
9630
|
+
driver.phase = "running";
|
|
9631
|
+
if (driver.generator?.state === "done") {
|
|
9632
|
+
driver.phase = "done";
|
|
9633
|
+
const settle = (action === "fulfilled" ? pendingPromiseFulfillers : pendingPromiseRejectors).get(driver.capability.promise);
|
|
9634
|
+
if (settle === void 0) throw new TypeError("Missing async function settlement capability.");
|
|
9635
|
+
settle(value);
|
|
9636
|
+
return void 0;
|
|
9637
|
+
}
|
|
9638
|
+
await advanceAsyncFunction(driver, action, value, budget, context);
|
|
9639
|
+
return void 0;
|
|
9640
|
+
}
|
|
9641
|
+
});
|
|
9642
|
+
asyncFunctionHandlers.set(handler, { driver, action, generation });
|
|
9643
|
+
return handler;
|
|
9644
|
+
}
|
|
9645
|
+
async function advanceAsyncFunction(driver, action, value, budget, context) {
|
|
9646
|
+
const release = retainValues(budget, () => [driver]);
|
|
9647
|
+
try {
|
|
9648
|
+
const generator = driver.generator;
|
|
9649
|
+
if (generator === void 0) throw new TypeError("Missing async function frame.");
|
|
9650
|
+
generator.state = "running";
|
|
9651
|
+
const result = await generator.channel[action === "fulfilled" ? "next" : "throw"](value);
|
|
9652
|
+
if (result.done) {
|
|
9653
|
+
generator.state = "done";
|
|
9654
|
+
if (!requiresPromiseResolution(result.value, budget)) {
|
|
9655
|
+
driver.phase = "done";
|
|
9656
|
+
await driver.capability.resolve.call([result.value], context);
|
|
9657
|
+
return;
|
|
9658
|
+
}
|
|
9659
|
+
} else {
|
|
9660
|
+
generator.state = "suspended";
|
|
9661
|
+
}
|
|
9662
|
+
const prepared = result.value;
|
|
9663
|
+
let awaited;
|
|
9664
|
+
if (!result.done && isSandboxPromise(prepared)) awaited = prepared;
|
|
9665
|
+
else {
|
|
9666
|
+
const wrapper = promiseReplayContext.exit(() => createPendingPromiseCapability(budget, context));
|
|
9667
|
+
await wrapper.resolve.call([prepared], context);
|
|
9668
|
+
awaited = wrapper.promise;
|
|
9669
|
+
}
|
|
9670
|
+
driver.phase = "waiting";
|
|
9671
|
+
driver.generation++;
|
|
9672
|
+
bindAsyncFunctionSignal(driver, asyncFunctionSignals.get(driver), budget, context);
|
|
9673
|
+
const reaction = promiseReplayContext.exit(() => createPendingPromiseCapability(budget, context));
|
|
9674
|
+
attachPendingPromiseReaction(
|
|
9675
|
+
awaited,
|
|
9676
|
+
reaction,
|
|
9677
|
+
createAsyncFunctionHandler(driver, "fulfilled", driver.generation, budget, context),
|
|
9678
|
+
createAsyncFunctionHandler(driver, "rejected", driver.generation, budget, context),
|
|
9679
|
+
budget,
|
|
9680
|
+
context
|
|
9681
|
+
);
|
|
9682
|
+
linkPromiseAggregateProducer(reaction.promise, driver.capability.promise);
|
|
9683
|
+
} catch (error) {
|
|
9684
|
+
abortReleases.get(driver)?.();
|
|
9685
|
+
driver.phase = "done";
|
|
9686
|
+
if (driver.generator !== void 0) driver.generator.state = "done";
|
|
9687
|
+
if (isFatalSandboxError(error)) throw error;
|
|
9688
|
+
await driver.capability.reject.call([createThrowCompletion(error, budget, context?.stack ?? []).value], context);
|
|
9689
|
+
} finally {
|
|
9690
|
+
release();
|
|
9691
|
+
}
|
|
9692
|
+
}
|
|
9693
|
+
|
|
9694
|
+
// packages/safe-js/src/interp/async-generator-driver.ts
|
|
9695
|
+
var asyncGeneratorDrivers = /* @__PURE__ */ new WeakMap();
|
|
9696
|
+
var asyncGeneratorRequestOwners = /* @__PURE__ */ new WeakMap();
|
|
9697
|
+
var asyncGeneratorHandlers = /* @__PURE__ */ new WeakMap();
|
|
9698
|
+
var generatorSignals = /* @__PURE__ */ new WeakMap();
|
|
9699
|
+
var interruptReleases = /* @__PURE__ */ new WeakMap();
|
|
9700
|
+
function bindAsyncGeneratorSignal(generator, signal, budget, context) {
|
|
9701
|
+
if (signal === void 0) generatorSignals.delete(generator);
|
|
9702
|
+
else generatorSignals.set(generator, signal);
|
|
9703
|
+
const driver = asyncGeneratorDrivers.get(generator);
|
|
9704
|
+
if (driver === void 0) return;
|
|
9705
|
+
interruptReleases.get(driver)?.();
|
|
9706
|
+
if (driver.phase !== "waiting") return;
|
|
9707
|
+
const generation = driver.generation;
|
|
9708
|
+
let notify;
|
|
9709
|
+
const interrupted = new Promise((resolve) => {
|
|
9710
|
+
notify = resolve;
|
|
9711
|
+
});
|
|
9712
|
+
let active = true;
|
|
9713
|
+
const abort = () => notify(signal?.reason ?? new DOMException("The operation was aborted.", "AbortError"));
|
|
9714
|
+
const release = () => {
|
|
9715
|
+
active = false;
|
|
9716
|
+
signal?.removeEventListener("abort", abort);
|
|
9717
|
+
detachFatal?.();
|
|
9718
|
+
if (interruptReleases.get(driver) === release) interruptReleases.delete(driver);
|
|
9719
|
+
};
|
|
9720
|
+
interruptReleases.set(driver, release);
|
|
9721
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
9722
|
+
const detachFatal = onFatalPromiseRejection(notify);
|
|
9723
|
+
void interrupted.then((reason) => runPromiseJob(async () => {
|
|
9724
|
+
if (!active || driver.phase !== "waiting" || driver.generation !== generation) return;
|
|
9725
|
+
if (isFatalSandboxError(reason)) {
|
|
9726
|
+
release();
|
|
9727
|
+
driver.phase = "running";
|
|
9728
|
+
await withFatalPromiseCleanup(async () => {
|
|
9729
|
+
if (generator.state !== "done") await generator.channel.throw(reason, false);
|
|
9730
|
+
});
|
|
9731
|
+
throw reason;
|
|
9732
|
+
}
|
|
9733
|
+
const handler = createAsyncGeneratorHandler(driver, "rejected", generation, budget, context);
|
|
9734
|
+
await handler.call([createThrowCompletion(reason, budget, context?.stack ?? []).value], context);
|
|
9735
|
+
})).catch((error) => rejectGeneratorQueue(driver, error));
|
|
9736
|
+
if (signal?.aborted) abort();
|
|
9737
|
+
}
|
|
9738
|
+
function enqueueAsyncGeneratorRequest(generator, method, value, budget, context) {
|
|
9739
|
+
let driver = asyncGeneratorDrivers.get(generator);
|
|
9740
|
+
if (driver === void 0) {
|
|
9741
|
+
driver = { generator, requests: [], phase: "idle", suspension: "yield", awaitKind: "body", generation: 0 };
|
|
9742
|
+
asyncGeneratorDrivers.set(generator, driver);
|
|
9743
|
+
asyncGeneratorDrivers.set(driver, driver);
|
|
9744
|
+
}
|
|
9745
|
+
const startsRequest = driver.phase === "idle";
|
|
9746
|
+
let completePrefix;
|
|
9747
|
+
const prefix = startsRequest ? new Promise((resolve) => {
|
|
9748
|
+
completePrefix = resolve;
|
|
9749
|
+
}) : void 0;
|
|
9750
|
+
const capability = createPendingPromiseCapability(budget, context, prefix);
|
|
9751
|
+
driver.requests.push({ method, value, capability: { promise: capability.promise, resolve: capability.resolve, reject: capability.reject } });
|
|
9752
|
+
asyncGeneratorRequestOwners.set(capability.promise, driver);
|
|
9753
|
+
if (startsRequest) {
|
|
9754
|
+
driver.phase = "running";
|
|
9755
|
+
const active = driver;
|
|
9756
|
+
void runAsyncPrefix(() => advanceAsyncGenerator(active, method, value, budget, context)).then(
|
|
9757
|
+
() => completePrefix?.(),
|
|
9758
|
+
(error) => {
|
|
9759
|
+
rejectGeneratorQueue(active, error);
|
|
9760
|
+
completePrefix?.();
|
|
9761
|
+
}
|
|
9762
|
+
);
|
|
9763
|
+
}
|
|
9764
|
+
return capability.promise;
|
|
9765
|
+
}
|
|
9766
|
+
function rejectGeneratorQueue(driver, error) {
|
|
9767
|
+
interruptReleases.get(driver)?.();
|
|
9768
|
+
driver.generator.state = "done";
|
|
9769
|
+
driver.phase = "idle";
|
|
9770
|
+
for (const request of driver.requests.splice(0)) {
|
|
9771
|
+
asyncGeneratorRequestOwners.delete(request.capability.promise);
|
|
9772
|
+
pendingPromiseRejectors.get(request.capability.promise)?.(error);
|
|
9773
|
+
}
|
|
9774
|
+
}
|
|
9775
|
+
function createAsyncGeneratorHandler(driver, action, generation, budget, context, owner = driver.requests[0]?.capability.promise) {
|
|
9776
|
+
if (owner === void 0) throw new TypeError("Missing async generator handler owner.");
|
|
9777
|
+
const handler = createSandboxClosure({
|
|
9778
|
+
guest: true,
|
|
9779
|
+
sandbox: true,
|
|
9780
|
+
name: "",
|
|
9781
|
+
length: 1,
|
|
9782
|
+
retainedValues: () => [driver, owner],
|
|
9783
|
+
call: async ([value]) => {
|
|
9784
|
+
if (driver.phase !== "waiting" || driver.generation !== generation) return void 0;
|
|
9785
|
+
interruptReleases.get(driver)?.();
|
|
9786
|
+
driver.phase = "running";
|
|
9787
|
+
if (driver.awaitKind === "return") await settleGeneratorRequest(driver, action, value, true, budget, context);
|
|
9788
|
+
else await advanceAsyncGenerator(driver, action === "fulfilled" ? "next" : "throw", value, budget, context, false);
|
|
9789
|
+
return void 0;
|
|
9790
|
+
}
|
|
9791
|
+
});
|
|
9792
|
+
asyncGeneratorHandlers.set(handler, { driver, owner, action, generation });
|
|
9793
|
+
return handler;
|
|
9794
|
+
}
|
|
9795
|
+
async function settleGeneratorRequest(driver, action, value, done, budget, context) {
|
|
9796
|
+
const request = driver.requests[0];
|
|
9797
|
+
if (request === void 0) throw new TypeError("Missing async generator request.");
|
|
9798
|
+
if (action === "fulfilled") await request.capability.resolve.call([allocateProducedSandboxValue({ value, done }, budget)], context);
|
|
9799
|
+
else await request.capability.reject.call([value], context);
|
|
9800
|
+
driver.requests.shift();
|
|
9801
|
+
asyncGeneratorRequestOwners.delete(request.capability.promise);
|
|
9802
|
+
const next = driver.requests[0];
|
|
9803
|
+
if (next === void 0) driver.phase = "idle";
|
|
9804
|
+
else await advanceAsyncGenerator(driver, next.method, next.value, budget, context);
|
|
9805
|
+
}
|
|
9806
|
+
async function awaitGeneratorRequest(driver, value, kind, budget, context) {
|
|
9807
|
+
let awaited;
|
|
9808
|
+
if (kind === "body" && isSandboxPromise(value)) awaited = value;
|
|
9809
|
+
else {
|
|
9810
|
+
const wrapper = promiseReplayContext.exit(() => createPendingPromiseCapability(budget, context));
|
|
9811
|
+
await wrapper.resolve.call([value], context);
|
|
9812
|
+
awaited = wrapper.promise;
|
|
9813
|
+
}
|
|
9814
|
+
driver.phase = "waiting";
|
|
9815
|
+
driver.awaitKind = kind;
|
|
9816
|
+
driver.generation++;
|
|
9817
|
+
const reaction = promiseReplayContext.exit(() => createPendingPromiseCapability(budget, context));
|
|
9818
|
+
attachPendingPromiseReaction(
|
|
9819
|
+
awaited,
|
|
9820
|
+
reaction,
|
|
9821
|
+
createAsyncGeneratorHandler(driver, "fulfilled", driver.generation, budget, context),
|
|
9822
|
+
createAsyncGeneratorHandler(driver, "rejected", driver.generation, budget, context),
|
|
9823
|
+
budget,
|
|
9824
|
+
context
|
|
9825
|
+
);
|
|
9826
|
+
const request = driver.requests[0];
|
|
9827
|
+
if (request === void 0) throw new TypeError("Missing async generator await owner.");
|
|
9828
|
+
linkPromiseAggregateProducer(reaction.promise, request.capability.promise);
|
|
9829
|
+
bindAsyncGeneratorSignal(driver.generator, generatorSignals.get(driver.generator), budget, context);
|
|
9830
|
+
}
|
|
9831
|
+
async function advanceAsyncGenerator(driver, method, value, budget, context, record4 = true) {
|
|
9832
|
+
const release = retainValues(budget, () => [driver]);
|
|
9833
|
+
const generator = driver.generator;
|
|
9834
|
+
try {
|
|
9835
|
+
driver.phase = "running";
|
|
9836
|
+
const initial = generator.state;
|
|
9837
|
+
generator.state = "running";
|
|
9838
|
+
const result = await generator.channel[method](value, record4);
|
|
9839
|
+
generator.state = result.done ? "done" : "suspended";
|
|
9840
|
+
const produced = result.value;
|
|
9841
|
+
if (!result.done && driver.suspension === "await") await awaitGeneratorRequest(driver, produced, "body", budget, context);
|
|
9842
|
+
else if (result.done && (requiresPromiseResolution(produced, budget) || method === "return" && (initial === "start" || initial === "done")))
|
|
9843
|
+
await awaitGeneratorRequest(driver, produced, "return", budget, context);
|
|
9844
|
+
else await settleGeneratorRequest(driver, "fulfilled", produced, result.done === true, budget, context);
|
|
9845
|
+
} catch (error) {
|
|
9846
|
+
generator.state = "done";
|
|
9847
|
+
if (isFatalSandboxError(error)) {
|
|
9848
|
+
rejectGeneratorQueue(driver, error);
|
|
9849
|
+
throw error;
|
|
9850
|
+
}
|
|
9851
|
+
await settleGeneratorRequest(driver, "rejected", createThrowCompletion(error, budget, context?.stack ?? []).value, true, budget, context);
|
|
9852
|
+
} finally {
|
|
9853
|
+
release();
|
|
9854
|
+
}
|
|
9855
|
+
}
|
|
9856
|
+
|
|
9339
9857
|
// packages/safe-js/src/interp/running-state.ts
|
|
9340
9858
|
var runningObjects = /* @__PURE__ */ new WeakSet();
|
|
9341
9859
|
var lockedCollections = /* @__PURE__ */ new WeakSet();
|
|
@@ -9457,8 +9975,8 @@ function getRegExpIteratorMember(property, budget) {
|
|
|
9457
9975
|
}
|
|
9458
9976
|
|
|
9459
9977
|
// packages/safe-js/src/interp/cancel.ts
|
|
9460
|
-
import { AsyncLocalStorage as
|
|
9461
|
-
var activeCancellation = new
|
|
9978
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
9979
|
+
var activeCancellation = new AsyncLocalStorage4();
|
|
9462
9980
|
var sandboxPromises = /* @__PURE__ */ new WeakSet();
|
|
9463
9981
|
var cancelableOutcomes = /* @__PURE__ */ new WeakMap();
|
|
9464
9982
|
function withCancellationSignal(signal, task) {
|
|
@@ -9643,101 +10161,6 @@ function isPromiseLike(value) {
|
|
|
9643
10161
|
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
9644
10162
|
}
|
|
9645
10163
|
|
|
9646
|
-
// packages/safe-js/src/interp/jobs.ts
|
|
9647
|
-
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
9648
|
-
var activeJob = new AsyncLocalStorage4();
|
|
9649
|
-
var SandboxJobQueue = class {
|
|
9650
|
-
running = false;
|
|
9651
|
-
pending = [];
|
|
9652
|
-
ready = [];
|
|
9653
|
-
idle = [];
|
|
9654
|
-
generation = 0;
|
|
9655
|
-
bind(task) {
|
|
9656
|
-
return activeJob.run({ queue: this, ownsExecution: false }, task);
|
|
9657
|
-
}
|
|
9658
|
-
acquire(job) {
|
|
9659
|
-
return new Promise((resolve) => {
|
|
9660
|
-
this.pending.push(() => {
|
|
9661
|
-
this.running = true;
|
|
9662
|
-
this.generation += 1;
|
|
9663
|
-
job.ownsExecution = true;
|
|
9664
|
-
resolve();
|
|
9665
|
-
});
|
|
9666
|
-
this.advance();
|
|
9667
|
-
});
|
|
9668
|
-
}
|
|
9669
|
-
release(job) {
|
|
9670
|
-
job.prefixParent = void 0;
|
|
9671
|
-
if (!job.ownsExecution) return;
|
|
9672
|
-
job.ownsExecution = false;
|
|
9673
|
-
this.running = false;
|
|
9674
|
-
this.advance();
|
|
9675
|
-
}
|
|
9676
|
-
async run(task) {
|
|
9677
|
-
const job = { queue: this, ownsExecution: false };
|
|
9678
|
-
await this.acquire(job);
|
|
9679
|
-
return activeJob.run(job, async () => {
|
|
9680
|
-
try {
|
|
9681
|
-
return await task();
|
|
9682
|
-
} finally {
|
|
9683
|
-
this.release(job);
|
|
9684
|
-
}
|
|
9685
|
-
});
|
|
9686
|
-
}
|
|
9687
|
-
async drain() {
|
|
9688
|
-
let idleTurns = 0;
|
|
9689
|
-
while (idleTurns < 20) {
|
|
9690
|
-
const generation = this.generation;
|
|
9691
|
-
if (this.running) await new Promise((resolve) => this.idle.push(resolve));
|
|
9692
|
-
await Promise.resolve();
|
|
9693
|
-
idleTurns = generation === this.generation ? idleTurns + 1 : 0;
|
|
9694
|
-
}
|
|
9695
|
-
}
|
|
9696
|
-
advance() {
|
|
9697
|
-
if (this.running) return;
|
|
9698
|
-
if (this.ready.length === 0 && this.pending.length > 0) {
|
|
9699
|
-
const empty = this.ready;
|
|
9700
|
-
this.ready = this.pending.reverse();
|
|
9701
|
-
this.pending = empty;
|
|
9702
|
-
}
|
|
9703
|
-
const next = this.ready.pop();
|
|
9704
|
-
if (next !== void 0) {
|
|
9705
|
-
next();
|
|
9706
|
-
} else {
|
|
9707
|
-
for (const resolve of this.idle.splice(0)) resolve();
|
|
9708
|
-
}
|
|
9709
|
-
}
|
|
9710
|
-
};
|
|
9711
|
-
function runPromiseJob(task) {
|
|
9712
|
-
const job = activeJob.getStore();
|
|
9713
|
-
return job === void 0 ? Promise.resolve().then(task) : job.queue.run(task);
|
|
9714
|
-
}
|
|
9715
|
-
function runAsyncPrefix(task) {
|
|
9716
|
-
const parent = activeJob.getStore();
|
|
9717
|
-
if (parent === void 0) return task();
|
|
9718
|
-
let owner = parent;
|
|
9719
|
-
while (owner !== void 0 && !owner.ownsExecution) owner = owner.prefixParent;
|
|
9720
|
-
if (owner === void 0) return parent.queue.run(task);
|
|
9721
|
-
const job = { queue: parent.queue, ownsExecution: false, prefixParent: parent };
|
|
9722
|
-
return activeJob.run(job, async () => {
|
|
9723
|
-
try {
|
|
9724
|
-
return await task();
|
|
9725
|
-
} finally {
|
|
9726
|
-
job.queue.release(job);
|
|
9727
|
-
}
|
|
9728
|
-
});
|
|
9729
|
-
}
|
|
9730
|
-
async function suspendJob(pending) {
|
|
9731
|
-
const job = activeJob.getStore();
|
|
9732
|
-
if (job === void 0) return pending;
|
|
9733
|
-
job.queue.release(job);
|
|
9734
|
-
try {
|
|
9735
|
-
return await pending;
|
|
9736
|
-
} finally {
|
|
9737
|
-
await job.queue.acquire(job);
|
|
9738
|
-
}
|
|
9739
|
-
}
|
|
9740
|
-
|
|
9741
10164
|
// packages/safe-js/src/interp/iteration.ts
|
|
9742
10165
|
function mapIteratorSnapshot(snapshot, map) {
|
|
9743
10166
|
if (snapshot.kind === "unsupported") throw new TypeError("Host-owned iterator cannot be portably snapshotted.");
|
|
@@ -9808,15 +10231,25 @@ async function getSandboxIteratorFromMethod(value, factory, budget, context, asy
|
|
|
9808
10231
|
return guestIterator(iterator, next, asyncProtocol, budget, context, signal);
|
|
9809
10232
|
}
|
|
9810
10233
|
function guestIterator(iterator, next, asyncProtocol, budget, context, signal) {
|
|
10234
|
+
const resumeAwait = async (state, value) => {
|
|
10235
|
+
if (state.kind !== "result") throw new TypeError("Invalid async iterator await state.");
|
|
10236
|
+
const result = await value();
|
|
10237
|
+
if (typeof result !== "object" && typeof result !== "function" || result === null)
|
|
10238
|
+
throw new TypeError("Iterator result must be an object.");
|
|
10239
|
+
return result;
|
|
10240
|
+
};
|
|
9811
10241
|
const invoke = async (operation, args) => {
|
|
9812
10242
|
if (!isSandboxClosure(operation)) throw new TypeError("Iterator operation must be callable.");
|
|
9813
10243
|
const returned = await invokeBuiltinClosure(operation, args, budget, context, iterator);
|
|
10244
|
+
if (asyncProtocol && wrapper.awaitValue !== void 0)
|
|
10245
|
+
return resumeAwait({ kind: "result" }, () => wrapper.awaitValue(returned, { kind: "result" }));
|
|
9814
10246
|
const result = asyncProtocol ? await awaitSandboxValue(returned, signal, budget, context) : returned;
|
|
9815
10247
|
if (typeof result !== "object" && typeof result !== "function" || result === null)
|
|
9816
10248
|
throw new TypeError("Iterator result must be an object.");
|
|
9817
10249
|
return result;
|
|
9818
10250
|
};
|
|
9819
|
-
|
|
10251
|
+
const wrapper = {
|
|
10252
|
+
resumeAwait,
|
|
9820
10253
|
...asyncProtocol ? { asyncProtocol: true } : {},
|
|
9821
10254
|
asynchronous: true,
|
|
9822
10255
|
retainedValue: [iterator, next],
|
|
@@ -9830,6 +10263,7 @@ function guestIterator(iterator, next, asyncProtocol, budget, context, signal) {
|
|
|
9830
10263
|
value: await context.getProperty(result, property)
|
|
9831
10264
|
})
|
|
9832
10265
|
};
|
|
10266
|
+
return wrapper;
|
|
9833
10267
|
}
|
|
9834
10268
|
async function readIteratorResult(iterator, result, property) {
|
|
9835
10269
|
return iterator.readResultProperty === void 0 ? { value: result[property] } : iterator.readResultProperty(result, property);
|
|
@@ -9888,6 +10322,16 @@ function nativeAsyncIterator(value, method, signal) {
|
|
|
9888
10322
|
};
|
|
9889
10323
|
}
|
|
9890
10324
|
function asyncFromSyncIterator(iterator, budget, signal, context) {
|
|
10325
|
+
const resumeAwait = async (state, value) => {
|
|
10326
|
+
if (state.kind !== "value") throw new TypeError("Invalid async-from-sync await state.");
|
|
10327
|
+
try {
|
|
10328
|
+
return { done: state.done, value: await value() };
|
|
10329
|
+
} catch (error) {
|
|
10330
|
+
if (isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
|
|
10331
|
+
if (state.closeOnReject) await closeIterator(iterator, true);
|
|
10332
|
+
throw error;
|
|
10333
|
+
}
|
|
10334
|
+
};
|
|
9891
10335
|
const invoke = async (method, args) => {
|
|
9892
10336
|
const operation = iterator.getOperation === void 0 ? iterator[method] : await iterator.getOperation(method);
|
|
9893
10337
|
if (operation === void 0) {
|
|
@@ -9904,6 +10348,10 @@ function asyncFromSyncIterator(iterator, budget, signal, context) {
|
|
|
9904
10348
|
}
|
|
9905
10349
|
const done = Boolean((await readIteratorResult(iterator, result, "done")).value);
|
|
9906
10350
|
const resultValue = (await readIteratorResult(iterator, result, "value")).value;
|
|
10351
|
+
if (wrapper.awaitValue !== void 0) {
|
|
10352
|
+
const state = { kind: "value", done, closeOnReject: !done && method !== "return" };
|
|
10353
|
+
return resumeAwait(state, () => wrapper.awaitValue(resultValue, state));
|
|
10354
|
+
}
|
|
9907
10355
|
try {
|
|
9908
10356
|
return { done, value: await awaitSandboxValue(resultValue, signal, budget, context) };
|
|
9909
10357
|
} catch (error) {
|
|
@@ -9912,7 +10360,8 @@ function asyncFromSyncIterator(iterator, budget, signal, context) {
|
|
|
9912
10360
|
throw error;
|
|
9913
10361
|
}
|
|
9914
10362
|
};
|
|
9915
|
-
|
|
10363
|
+
const wrapper = {
|
|
10364
|
+
resumeAwait,
|
|
9916
10365
|
asyncProtocol: true,
|
|
9917
10366
|
snapshotIndex: iterator.snapshotIndex,
|
|
9918
10367
|
snapshot: () => ({ kind: "async-from-sync", inner: iterator.snapshot?.() ?? { kind: "unsupported" } }),
|
|
@@ -9923,13 +10372,14 @@ function asyncFromSyncIterator(iterator, budget, signal, context) {
|
|
|
9923
10372
|
return: (...args) => invoke("return", args),
|
|
9924
10373
|
throw: (...args) => invoke("throw", args)
|
|
9925
10374
|
};
|
|
10375
|
+
return wrapper;
|
|
9926
10376
|
}
|
|
9927
|
-
async function closeIterator(iterator, preserveThrow = false) {
|
|
10377
|
+
async function closeIterator(iterator, preserveThrow = false, awaitResult = suspendJob) {
|
|
9928
10378
|
try {
|
|
9929
10379
|
const close = iterator.getOperation === void 0 ? iterator.return : await iterator.getOperation("return");
|
|
9930
10380
|
if (close === void 0) return;
|
|
9931
10381
|
const returned = close();
|
|
9932
|
-
const result = iterator.asyncProtocol ? await
|
|
10382
|
+
const result = iterator.asyncProtocol ? iterator.awaitValue === void 0 ? await awaitResult(Promise.resolve(returned)) : await returned : iterator.generator || iterator.asynchronous ? await returned : returned;
|
|
9933
10383
|
if (typeof result !== "object" && typeof result !== "function" || result === null) {
|
|
9934
10384
|
throw new TypeError("Iterator return result must be an object.");
|
|
9935
10385
|
}
|
|
@@ -10072,7 +10522,6 @@ function collectionIterator(collection, value) {
|
|
|
10072
10522
|
adapter.snapshot = () => ({ kind: "builtin", value, index: adapter.snapshotIndex() });
|
|
10073
10523
|
return adapter;
|
|
10074
10524
|
}
|
|
10075
|
-
var asyncGeneratorRequests = /* @__PURE__ */ new WeakMap();
|
|
10076
10525
|
function guestProtocolAdapter(value, budget, context, asyncProtocol, signal) {
|
|
10077
10526
|
const bridge = {
|
|
10078
10527
|
...context,
|
|
@@ -10128,13 +10577,8 @@ function generatorObjectIterator(generator, budget, context) {
|
|
|
10128
10577
|
function generatorIterator(generator, budget, context) {
|
|
10129
10578
|
const invoke = async (method, value) => {
|
|
10130
10579
|
const leaveRunning = enterRunningState(generator);
|
|
10131
|
-
const initialState = generator.state;
|
|
10132
10580
|
generator.state = "running";
|
|
10133
10581
|
try {
|
|
10134
|
-
if (generator.async && method === "return" && (initialState === "start" || initialState === "done")) {
|
|
10135
|
-
if (initialState === "start") await generator.channel.return();
|
|
10136
|
-
value = await awaitSandboxValue(value, void 0, budget, context);
|
|
10137
|
-
}
|
|
10138
10582
|
const result = await generator.channel[method](value);
|
|
10139
10583
|
generator.state = result.done ? "done" : "suspended";
|
|
10140
10584
|
return result;
|
|
@@ -10147,13 +10591,7 @@ function generatorIterator(generator, budget, context) {
|
|
|
10147
10591
|
};
|
|
10148
10592
|
const request = (method, value) => {
|
|
10149
10593
|
if (!generator.async) return invoke(method, value);
|
|
10150
|
-
|
|
10151
|
-
const result = previous.then(() => invoke(method, value));
|
|
10152
|
-
asyncGeneratorRequests.set(
|
|
10153
|
-
generator,
|
|
10154
|
-
result.catch(() => void 0)
|
|
10155
|
-
);
|
|
10156
|
-
return result;
|
|
10594
|
+
return enqueueAsyncGeneratorRequest(generator, method, value, budget ?? new Budget(), context).promise;
|
|
10157
10595
|
};
|
|
10158
10596
|
return {
|
|
10159
10597
|
generator: true,
|
|
@@ -10194,67 +10632,13 @@ function syncIterator(iterator) {
|
|
|
10194
10632
|
var promiseResolvingFunctions = /* @__PURE__ */ new WeakMap();
|
|
10195
10633
|
var promiseResolverActions = /* @__PURE__ */ new WeakMap();
|
|
10196
10634
|
|
|
10197
|
-
// packages/safe-js/src/interp/promise-continuations.ts
|
|
10198
|
-
var thenableContinuations = /* @__PURE__ */ new WeakMap();
|
|
10199
|
-
var thenableStates = /* @__PURE__ */ new WeakMap();
|
|
10200
|
-
var thenableResolvers = /* @__PURE__ */ new WeakMap();
|
|
10201
|
-
var promiseCapabilityExecutors = /* @__PURE__ */ new WeakMap();
|
|
10202
|
-
var promiseAggregateHandlers = /* @__PURE__ */ new WeakMap();
|
|
10203
|
-
var promiseAggregateStates = /* @__PURE__ */ new WeakMap();
|
|
10204
|
-
var promiseAggregateEntries = /* @__PURE__ */ new WeakMap();
|
|
10205
|
-
var promiseAdoptions = /* @__PURE__ */ new WeakMap();
|
|
10206
|
-
var promiseAdoptionBridges = /* @__PURE__ */ new WeakMap();
|
|
10207
|
-
var promiseAdoptionResolvers = /* @__PURE__ */ new WeakMap();
|
|
10208
|
-
var promiseContinuations = /* @__PURE__ */ new WeakMap();
|
|
10209
|
-
var promiseReactionResults = /* @__PURE__ */ new WeakMap();
|
|
10210
|
-
var promiseProducers = /* @__PURE__ */ new WeakMap();
|
|
10211
|
-
function linkPromiseAggregateProducer(producer, aggregate) {
|
|
10212
|
-
const continuation = promiseContinuations.get(producer);
|
|
10213
|
-
if (continuation?.kind !== "reaction") return;
|
|
10214
|
-
continuation.aggregate = aggregate;
|
|
10215
|
-
let producers = promiseProducers.get(aggregate);
|
|
10216
|
-
if (producers === void 0) promiseProducers.set(aggregate, producers = /* @__PURE__ */ new Set());
|
|
10217
|
-
producers.add(producer);
|
|
10218
|
-
}
|
|
10219
|
-
function trackPromiseContinuation(promise, continuation) {
|
|
10220
|
-
promiseContinuations.set(promise, continuation);
|
|
10221
|
-
if (continuation.kind === "reaction") {
|
|
10222
|
-
let results = promiseReactionResults.get(continuation.source);
|
|
10223
|
-
if (results === void 0) promiseReactionResults.set(continuation.source, results = /* @__PURE__ */ new Set());
|
|
10224
|
-
results.add(promise);
|
|
10225
|
-
if (continuation.capability !== void 0) {
|
|
10226
|
-
let producers = promiseProducers.get(continuation.capability.promise);
|
|
10227
|
-
if (producers === void 0) promiseProducers.set(continuation.capability.promise, producers = /* @__PURE__ */ new Set());
|
|
10228
|
-
producers.add(promise);
|
|
10229
|
-
}
|
|
10230
|
-
}
|
|
10231
|
-
const release = () => {
|
|
10232
|
-
promiseContinuations.delete(promise);
|
|
10233
|
-
if (continuation.kind === "capability") delete continuation.resolution;
|
|
10234
|
-
else {
|
|
10235
|
-
const results = promiseReactionResults.get(continuation.source);
|
|
10236
|
-
results?.delete(promise);
|
|
10237
|
-
if (results?.size === 0) promiseReactionResults.delete(continuation.source);
|
|
10238
|
-
if (continuation.capability !== void 0) {
|
|
10239
|
-
const producers = promiseProducers.get(continuation.capability.promise);
|
|
10240
|
-
producers?.delete(promise);
|
|
10241
|
-
if (producers?.size === 0) promiseProducers.delete(continuation.capability.promise);
|
|
10242
|
-
}
|
|
10243
|
-
if (continuation.aggregate !== void 0) {
|
|
10244
|
-
const producers = promiseProducers.get(continuation.aggregate);
|
|
10245
|
-
producers?.delete(promise);
|
|
10246
|
-
if (producers?.size === 0) promiseProducers.delete(continuation.aggregate);
|
|
10247
|
-
}
|
|
10248
|
-
}
|
|
10249
|
-
};
|
|
10250
|
-
promise.promise.then(release, release);
|
|
10251
|
-
}
|
|
10252
|
-
|
|
10253
10635
|
// packages/safe-js/src/interp/promise.ts
|
|
10254
10636
|
var promiseConstructors = /* @__PURE__ */ new WeakSet();
|
|
10255
10637
|
var intrinsicPromiseThenMethods = /* @__PURE__ */ new WeakSet();
|
|
10256
10638
|
var intrinsicPromiseConstructors = /* @__PURE__ */ new WeakMap();
|
|
10257
10639
|
var promisePrototypes2 = /* @__PURE__ */ new WeakMap();
|
|
10640
|
+
var pendingPromiseRejectors = /* @__PURE__ */ new WeakMap();
|
|
10641
|
+
var pendingPromiseFulfillers = /* @__PURE__ */ new WeakMap();
|
|
10258
10642
|
function isSandboxPromiseConstructor(value) {
|
|
10259
10643
|
return isSandboxClosure(value) && promiseConstructors.has(value);
|
|
10260
10644
|
}
|
|
@@ -10268,6 +10652,8 @@ function createPendingPromiseCapability(budget, context, synchronousPrefix) {
|
|
|
10268
10652
|
fulfill = resolve;
|
|
10269
10653
|
reject = rejectPromise;
|
|
10270
10654
|
}), { span: context?.span, synchronousPrefix });
|
|
10655
|
+
pendingPromiseRejectors.set(promise, reject);
|
|
10656
|
+
pendingPromiseFulfillers.set(promise, fulfill);
|
|
10271
10657
|
const resolverState = { promise, settled: false };
|
|
10272
10658
|
const continuation = { kind: "capability", state: resolverState };
|
|
10273
10659
|
trackPromiseContinuation(promise, continuation);
|
|
@@ -10321,6 +10707,11 @@ function attachPendingPromiseReaction(source, capability, onFulfilled, onRejecte
|
|
|
10321
10707
|
continuation.phase = "running";
|
|
10322
10708
|
try {
|
|
10323
10709
|
consumeSettledHostCall(source);
|
|
10710
|
+
const asyncContinuation = isSandboxClosure(handler) ? asyncFunctionHandlers.get(handler) : void 0;
|
|
10711
|
+
if (isSandboxClosure(handler) && asyncContinuation?.driver.generator?.state === "done") {
|
|
10712
|
+
capability.fulfill(handler.call([value], context));
|
|
10713
|
+
return;
|
|
10714
|
+
}
|
|
10324
10715
|
capability.fulfill(reactionCapability === void 0 ? runPromiseReaction(handler, value, status, budget, capability.promise, context) : runCapabilityReaction(handler, value, status, reactionCapability, budget, context));
|
|
10325
10716
|
} catch (error) {
|
|
10326
10717
|
capability.rejectNative(error);
|
|
@@ -10328,6 +10719,21 @@ function attachPendingPromiseReaction(source, capability, onFulfilled, onRejecte
|
|
|
10328
10719
|
};
|
|
10329
10720
|
source.promise.then((value) => react(onFulfilled, value, "fulfilled"), (reason) => react(onRejected, reason, "rejected"));
|
|
10330
10721
|
trackPromiseContinuation(capability.promise, continuation);
|
|
10722
|
+
const asyncHandler = isSandboxClosure(onRejected) ? asyncFunctionHandlers.get(onRejected) : void 0;
|
|
10723
|
+
const generatorHandler = isSandboxClosure(onRejected) ? asyncGeneratorHandlers.get(onRejected) : void 0;
|
|
10724
|
+
if (generatorHandler !== void 0) {
|
|
10725
|
+
observeSandboxPromise(capability.promise, true);
|
|
10726
|
+
void capability.promise.promise.catch((error) => rejectGeneratorQueue(generatorHandler.driver, error));
|
|
10727
|
+
}
|
|
10728
|
+
if (asyncHandler !== void 0) {
|
|
10729
|
+
observeSandboxPromise(capability.promise, true);
|
|
10730
|
+
void capability.promise.promise.catch((error) => {
|
|
10731
|
+
asyncHandler.driver.phase = "done";
|
|
10732
|
+
const reject = pendingPromiseRejectors.get(asyncHandler.driver.capability.promise);
|
|
10733
|
+
if (reject === void 0) throw new TypeError("Missing async function rejection capability.");
|
|
10734
|
+
reject(error);
|
|
10735
|
+
});
|
|
10736
|
+
}
|
|
10331
10737
|
}
|
|
10332
10738
|
function createPromiseGlobals(options) {
|
|
10333
10739
|
promisePrototypes2.delete(options.budget);
|
|
@@ -11388,9 +11794,10 @@ var Scope = class _Scope {
|
|
|
11388
11794
|
this.importMeta = importMeta;
|
|
11389
11795
|
this.options = options;
|
|
11390
11796
|
this.#restoredBindings = parent === void 0 ? new Map(Object.entries(restoredBindings ?? {})) : parent.#restoredBindings;
|
|
11797
|
+
const mutable = mutableBuiltinBindings.get(bindings);
|
|
11391
11798
|
for (const [name, value] of Object.entries(bindings)) {
|
|
11392
11799
|
this.#bindings.set(name, {
|
|
11393
|
-
kind: "const",
|
|
11800
|
+
kind: mutable?.has(name) ? "var" : "const",
|
|
11394
11801
|
value
|
|
11395
11802
|
});
|
|
11396
11803
|
}
|
|
@@ -11398,8 +11805,10 @@ var Scope = class _Scope {
|
|
|
11398
11805
|
parent;
|
|
11399
11806
|
importMeta;
|
|
11400
11807
|
options;
|
|
11808
|
+
resourceState;
|
|
11401
11809
|
privateNames;
|
|
11402
11810
|
#bindings = /* @__PURE__ */ new Map();
|
|
11811
|
+
#replacedBindings = /* @__PURE__ */ new Set();
|
|
11403
11812
|
#restoredBindings;
|
|
11404
11813
|
#frameHydrated = false;
|
|
11405
11814
|
child(bindings = {}, options = {}) {
|
|
@@ -11466,12 +11875,17 @@ var Scope = class _Scope {
|
|
|
11466
11875
|
}
|
|
11467
11876
|
retainedValues() {
|
|
11468
11877
|
const values = this.parent?.retainedValues() ?? [];
|
|
11878
|
+
if (this.resourceState !== void 0) values.push(this.resourceState);
|
|
11469
11879
|
if (this.options.chargeData !== false) {
|
|
11470
11880
|
if (this.importMeta !== void 0) values.push(this.importMeta);
|
|
11471
11881
|
if (this.privateNames !== void 0) values.push(...this.privateNames.values());
|
|
11472
11882
|
for (const binding of this.#bindings.values()) {
|
|
11473
11883
|
if (binding.value !== uninitialized) values.push(binding.value);
|
|
11474
11884
|
}
|
|
11885
|
+
} else {
|
|
11886
|
+
for (const binding of this.#replacedBindings) {
|
|
11887
|
+
if (binding.value !== uninitialized) values.push(binding.value);
|
|
11888
|
+
}
|
|
11475
11889
|
}
|
|
11476
11890
|
return values;
|
|
11477
11891
|
}
|
|
@@ -11538,6 +11952,7 @@ var Scope = class _Scope {
|
|
|
11538
11952
|
throw new TypeError(`Cannot assign to const binding '${name}'.`);
|
|
11539
11953
|
}
|
|
11540
11954
|
binding.value = value;
|
|
11955
|
+
scope.trackReplacement(name, binding);
|
|
11541
11956
|
}
|
|
11542
11957
|
lookup(name) {
|
|
11543
11958
|
const binding = this.#bindings.get(name);
|
|
@@ -11596,6 +12011,7 @@ var Scope = class _Scope {
|
|
|
11596
12011
|
chargeData: this.options.chargeData !== false,
|
|
11597
12012
|
bindings,
|
|
11598
12013
|
cells,
|
|
12014
|
+
...this.resourceState === void 0 ? {} : { resourceState: this.resourceState },
|
|
11599
12015
|
...this.privateNames === void 0 ? {} : { privateNames: [...this.privateNames] },
|
|
11600
12016
|
...this.parent === void 0 ? { restoredBindings: [...this.#restoredBindings] } : {}
|
|
11601
12017
|
};
|
|
@@ -11623,8 +12039,12 @@ var Scope = class _Scope {
|
|
|
11623
12039
|
const restored = new Map(frame.restoredBindings ?? []);
|
|
11624
12040
|
if (restored.size !== (frame.restoredBindings?.length ?? 0)) throw new TypeError("Duplicate restored binding.");
|
|
11625
12041
|
this.importMeta = frame.importMeta;
|
|
12042
|
+
this.resourceState = frame.resourceState;
|
|
11626
12043
|
if (frame.privateNames !== void 0) this.privateNames = new Map(frame.privateNames);
|
|
11627
|
-
for (const [name, binding] of bindings)
|
|
12044
|
+
for (const [name, binding] of bindings) {
|
|
12045
|
+
this.#bindings.set(name, binding);
|
|
12046
|
+
this.trackReplacement(name, binding);
|
|
12047
|
+
}
|
|
11628
12048
|
if (this.parent === void 0)
|
|
11629
12049
|
for (const [name, value] of restored) this.#restoredBindings.set(name, value);
|
|
11630
12050
|
this.#frameHydrated = true;
|
|
@@ -11648,6 +12068,13 @@ var Scope = class _Scope {
|
|
|
11648
12068
|
}
|
|
11649
12069
|
return this.parent?.resolveScope(name);
|
|
11650
12070
|
}
|
|
12071
|
+
trackReplacement(name, binding) {
|
|
12072
|
+
if (this.options.chargeData !== false || binding.kind === "const") return;
|
|
12073
|
+
const value = binding.value;
|
|
12074
|
+
if (typeof value === "object" && value !== null && getIntrinsicIdentity(value) === JSON.stringify([name]))
|
|
12075
|
+
this.#replacedBindings.delete(binding);
|
|
12076
|
+
else this.#replacedBindings.add(binding);
|
|
12077
|
+
}
|
|
11651
12078
|
requireInitializedBinding(name) {
|
|
11652
12079
|
const scope = this.resolveScope(name);
|
|
11653
12080
|
const binding = scope === void 0 ? void 0 : scope.#bindings.get(name);
|
|
@@ -11781,27 +12208,34 @@ function createGeneratorChannel(body) {
|
|
|
11781
12208
|
let state = "unstarted";
|
|
11782
12209
|
let signal = deferred();
|
|
11783
12210
|
let resume;
|
|
11784
|
-
const
|
|
12211
|
+
const resumeJob = createResumableJobContext();
|
|
11785
12212
|
const sent = [];
|
|
11786
12213
|
let yieldNodeId;
|
|
11787
|
-
|
|
11788
|
-
|
|
11789
|
-
|
|
11790
|
-
|
|
11791
|
-
|
|
11792
|
-
|
|
11793
|
-
state = "done";
|
|
11794
|
-
signal.resolve({ type: "complete", value });
|
|
11795
|
-
},
|
|
11796
|
-
(error) => {
|
|
11797
|
-
if (state === "done") {
|
|
11798
|
-
return;
|
|
11799
|
-
}
|
|
11800
|
-
state = "done";
|
|
11801
|
-
signal.resolve({ type: "error", error });
|
|
12214
|
+
function startBody() {
|
|
12215
|
+
let bodyPromise;
|
|
12216
|
+
try {
|
|
12217
|
+
bodyPromise = body(yieldValue);
|
|
12218
|
+
} catch (error) {
|
|
12219
|
+
bodyPromise = Promise.reject(error);
|
|
11802
12220
|
}
|
|
11803
|
-
|
|
11804
|
-
|
|
12221
|
+
void bodyPromise.then(
|
|
12222
|
+
(value) => {
|
|
12223
|
+
if (state === "done") {
|
|
12224
|
+
return;
|
|
12225
|
+
}
|
|
12226
|
+
state = "done";
|
|
12227
|
+
signal.resolve({ type: "complete", value });
|
|
12228
|
+
},
|
|
12229
|
+
(error) => {
|
|
12230
|
+
if (state === "done") {
|
|
12231
|
+
return;
|
|
12232
|
+
}
|
|
12233
|
+
state = "done";
|
|
12234
|
+
signal.resolve({ type: "error", error });
|
|
12235
|
+
}
|
|
12236
|
+
);
|
|
12237
|
+
void bodyPromise.catch(() => void 0);
|
|
12238
|
+
}
|
|
11805
12239
|
async function yieldValue(value, nodeId) {
|
|
11806
12240
|
resume = deferred();
|
|
11807
12241
|
yieldNodeId = nodeId;
|
|
@@ -11809,7 +12243,7 @@ function createGeneratorChannel(body) {
|
|
|
11809
12243
|
signal.resolve({ type: "yield", value });
|
|
11810
12244
|
return resume.promise;
|
|
11811
12245
|
}
|
|
11812
|
-
async function deliver(completion) {
|
|
12246
|
+
async function deliver(completion, record4) {
|
|
11813
12247
|
const leaveRunning = enterRunningState(channelIdentity);
|
|
11814
12248
|
try {
|
|
11815
12249
|
if (state === "done") {
|
|
@@ -11831,11 +12265,11 @@ function createGeneratorChannel(body) {
|
|
|
11831
12265
|
throw completion.value;
|
|
11832
12266
|
}
|
|
11833
12267
|
state = "running";
|
|
11834
|
-
sent.push(completion);
|
|
11835
|
-
|
|
12268
|
+
if (record4) sent.push(completion);
|
|
12269
|
+
startBody();
|
|
11836
12270
|
} else {
|
|
11837
12271
|
state = "running";
|
|
11838
|
-
sent.push(completion);
|
|
12272
|
+
if (record4) sent.push(completion);
|
|
11839
12273
|
signal = deferred();
|
|
11840
12274
|
const pendingResume = resume;
|
|
11841
12275
|
resume = void 0;
|
|
@@ -11851,13 +12285,14 @@ function createGeneratorChannel(body) {
|
|
|
11851
12285
|
return { value: settled.value, done: true };
|
|
11852
12286
|
} finally {
|
|
11853
12287
|
leaveRunning();
|
|
12288
|
+
resumeJob.release();
|
|
11854
12289
|
}
|
|
11855
12290
|
}
|
|
11856
12291
|
const channelIdentity = {};
|
|
11857
12292
|
return {
|
|
11858
|
-
next: (value) => deliver({ type: "normal", value }),
|
|
11859
|
-
return: (value) => deliver({ type: "return", value }),
|
|
11860
|
-
throw: (error) => deliver({ type: "throw", value: error }),
|
|
12293
|
+
next: (value, record4 = true) => resumeJob.run(() => deliver({ type: "normal", value }, record4)),
|
|
12294
|
+
return: (value, record4 = true) => resumeJob.run(() => deliver({ type: "return", value }, record4)),
|
|
12295
|
+
throw: (error, record4 = true) => resumeJob.run(() => deliver({ type: "throw", value: error }, record4)),
|
|
11861
12296
|
snapshot: () => ({
|
|
11862
12297
|
...yieldNodeId === void 0 ? {} : { yieldNodeId },
|
|
11863
12298
|
sent: sent.map((completion) => ({ ...completion }))
|
|
@@ -12313,18 +12748,56 @@ function createInterpretedClosure(node, context, evaluateNode2, homeObject, init
|
|
|
12313
12748
|
};
|
|
12314
12749
|
if (!node.async)
|
|
12315
12750
|
return executeClosure(node, args, callContext?.thisValue, invocationContext, evaluateNode2);
|
|
12316
|
-
return
|
|
12317
|
-
|
|
12318
|
-
|
|
12319
|
-
|
|
12320
|
-
|
|
12321
|
-
|
|
12322
|
-
|
|
12323
|
-
|
|
12324
|
-
|
|
12325
|
-
|
|
12326
|
-
|
|
12327
|
-
|
|
12751
|
+
return startAsyncFunction(async (onSuspend) => {
|
|
12752
|
+
const parent = invocationContext.compilation;
|
|
12753
|
+
const operation = context.budget.acquireCompileOwner(false, parent?.owner);
|
|
12754
|
+
const compilation = new CompileScope(operation.owner, parent);
|
|
12755
|
+
const executionContext = { ...invocationContext, compilation, onSuspend };
|
|
12756
|
+
let scope;
|
|
12757
|
+
try {
|
|
12758
|
+
scope = await createClosureScope(node, args, callContext?.thisValue, executionContext, evaluateNode2);
|
|
12759
|
+
} catch (error) {
|
|
12760
|
+
compilation.dispose();
|
|
12761
|
+
operation.release();
|
|
12762
|
+
throw error;
|
|
12763
|
+
}
|
|
12764
|
+
const channel = createGeneratorChannel(async (generatorYield) => {
|
|
12765
|
+
try {
|
|
12766
|
+
const result = await evaluateNode2(node.body, {
|
|
12767
|
+
...executionContext,
|
|
12768
|
+
scope,
|
|
12769
|
+
asyncFunction: true,
|
|
12770
|
+
asyncGenerator: false,
|
|
12771
|
+
asyncGeneratorFrame: void 0,
|
|
12772
|
+
functionBody: node.body.type === "BlockStatement" ? node.body : void 0,
|
|
12773
|
+
generatorBlockScopes: /* @__PURE__ */ new Map(),
|
|
12774
|
+
generatorExpressionStates: /* @__PURE__ */ new Map(),
|
|
12775
|
+
captureGeneratorScope: (current, blocks, completions, expressions) => {
|
|
12776
|
+
origin.suspendedScope = current;
|
|
12777
|
+
origin.blockScopes = blocks;
|
|
12778
|
+
origin.finallyCompletions = completions;
|
|
12779
|
+
origin.expressionStates = expressions;
|
|
12780
|
+
},
|
|
12781
|
+
generatorYield: (value2, nodeId) => {
|
|
12782
|
+
generator.state = "suspended";
|
|
12783
|
+
return generatorYield(value2, nodeId);
|
|
12784
|
+
}
|
|
12785
|
+
});
|
|
12786
|
+
const value = "hasValue" in result && result.hasValue ? result.value : void 0;
|
|
12787
|
+
reconcileCompiledValues(context.budget, [...scope.retainedValues(), value], compilation, parent, [value]);
|
|
12788
|
+
if (result.kind === "error") throw result.error;
|
|
12789
|
+
if (result.kind === "throw") throw result.value;
|
|
12790
|
+
return value;
|
|
12791
|
+
} finally {
|
|
12792
|
+
compilation.dispose();
|
|
12793
|
+
operation.release();
|
|
12794
|
+
}
|
|
12795
|
+
});
|
|
12796
|
+
const generator = createSandboxGenerator(channel);
|
|
12797
|
+
const origin = registerGeneratorOrigin(generator, node, scope, invocationContext);
|
|
12798
|
+
origin.asyncFunction = true;
|
|
12799
|
+
return generator;
|
|
12800
|
+
}, context.budget, callContext, context.signal);
|
|
12328
12801
|
}
|
|
12329
12802
|
});
|
|
12330
12803
|
registerClosureOrigin(closure, node, context);
|
|
@@ -12391,8 +12864,11 @@ function createGeneratorClosure(node, context, evaluateNode2, initializePrototyp
|
|
|
12391
12864
|
const execute = async () => {
|
|
12392
12865
|
const result = await evaluateNode2(node.body, {
|
|
12393
12866
|
...closureContext,
|
|
12867
|
+
asyncFunction: false,
|
|
12394
12868
|
functionBody: node.body,
|
|
12395
12869
|
asyncGenerator: node.async,
|
|
12870
|
+
asyncGeneratorFrame: node.async ? generator : void 0,
|
|
12871
|
+
onSuspend: void 0,
|
|
12396
12872
|
generatorBlockScopes: /* @__PURE__ */ new Map(),
|
|
12397
12873
|
generatorExpressionStates: /* @__PURE__ */ new Map(),
|
|
12398
12874
|
captureGeneratorScope: (suspendedScope, blocks, completions, expressions) => {
|
|
@@ -12414,11 +12890,12 @@ function createGeneratorClosure(node, context, evaluateNode2, initializePrototyp
|
|
|
12414
12890
|
throw result.value;
|
|
12415
12891
|
}
|
|
12416
12892
|
const value = result.hasValue ? result.value : void 0;
|
|
12417
|
-
return
|
|
12893
|
+
return value;
|
|
12418
12894
|
};
|
|
12419
|
-
return
|
|
12895
|
+
return execute();
|
|
12420
12896
|
});
|
|
12421
12897
|
const generator = createSandboxGenerator(channel, { async: node.async });
|
|
12898
|
+
if (node.async) bindAsyncGeneratorSignal(generator, context.signal, context.budget);
|
|
12422
12899
|
if (prototype !== void 0) setSandboxPrototype(generator, prototype, context.budget);
|
|
12423
12900
|
const origin = registerGeneratorOrigin(generator, node, scope, closureContext);
|
|
12424
12901
|
return generator;
|
|
@@ -12441,11 +12918,17 @@ function isConstructResult(value) {
|
|
|
12441
12918
|
return typeof value === "object" && value !== null;
|
|
12442
12919
|
}
|
|
12443
12920
|
async function evaluateAwaitExpression(node, context, evaluateNode2) {
|
|
12921
|
+
if ((context.asyncFunction || context.asyncGeneratorFrame !== void 0) && context.generatorResume?.completed !== true && context.generatorResume?.yieldNodeId === node.nodeId) {
|
|
12922
|
+
return { kind: "normal", hasValue: true, value: await suspendAsyncFunctionValue(void 0, node, context) };
|
|
12923
|
+
}
|
|
12444
12924
|
const replayState = context.captureReplayState?.();
|
|
12445
12925
|
const argument = await evaluateNode2(node.argument, context);
|
|
12446
12926
|
if (argument.kind !== "normal") {
|
|
12447
12927
|
return argument;
|
|
12448
12928
|
}
|
|
12929
|
+
if (context.asyncFunction || context.asyncGeneratorFrame !== void 0) {
|
|
12930
|
+
return { kind: "normal", hasValue: true, value: await suspendAsyncFunctionValue(argument.value, node, context, replayState, createCoercionContext(context)) };
|
|
12931
|
+
}
|
|
12449
12932
|
context.onSuspend?.();
|
|
12450
12933
|
emitResumeBreakpoint(context, {
|
|
12451
12934
|
kind: "await",
|
|
@@ -12465,6 +12948,51 @@ async function evaluateAwaitExpression(node, context, evaluateNode2) {
|
|
|
12465
12948
|
leaveAwait();
|
|
12466
12949
|
}
|
|
12467
12950
|
}
|
|
12951
|
+
async function suspendAsyncFunctionValue(value, node, context, replayState = context.captureReplayState?.(), callContext, phase = "await") {
|
|
12952
|
+
if (context.generatorYield === void 0 || node.nodeId === void 0) throw new TypeError("Missing async function suspension identity.");
|
|
12953
|
+
let awaited;
|
|
12954
|
+
if (isSandboxPromise(value)) {
|
|
12955
|
+
const prepared = prepareAwaitedPromise(value, context.budget, callContext);
|
|
12956
|
+
awaited = prepared instanceof Promise ? await prepared : prepared;
|
|
12957
|
+
} else {
|
|
12958
|
+
const wrapper = promiseReplayContext.exit(() => createPendingPromiseCapability(context.budget, callContext));
|
|
12959
|
+
const prefix = wrapper.resolve.call([value], callContext);
|
|
12960
|
+
if (prefix instanceof Promise) await prefix;
|
|
12961
|
+
awaited = wrapper.promise;
|
|
12962
|
+
}
|
|
12963
|
+
if (context.signal?.aborted) {
|
|
12964
|
+
observeSandboxPromise(awaited, true);
|
|
12965
|
+
await awaitWithSignal(awaited.promise, context.signal);
|
|
12966
|
+
}
|
|
12967
|
+
context.captureGeneratorScope?.(context.scope, context.generatorBlockScopes, context.finallyCompletions, context.generatorExpressionStates);
|
|
12968
|
+
context.onSuspend?.();
|
|
12969
|
+
const otelSpan = getBoundOtelSpan(value);
|
|
12970
|
+
emitResumeBreakpoint(context, {
|
|
12971
|
+
kind: "await",
|
|
12972
|
+
nodeId: node.nodeId,
|
|
12973
|
+
span: node.span,
|
|
12974
|
+
replayState,
|
|
12975
|
+
...otelSpan === void 0 ? {} : { otelSpan }
|
|
12976
|
+
});
|
|
12977
|
+
const leaveAwait = context.budget.enterAwait();
|
|
12978
|
+
const generator = context.asyncGeneratorFrame;
|
|
12979
|
+
const origin = generator === void 0 ? void 0 : getGeneratorOrigin(generator);
|
|
12980
|
+
if (generator !== void 0) {
|
|
12981
|
+
const driver = asyncGeneratorDrivers.get(generator);
|
|
12982
|
+
if (driver === void 0 || origin === void 0) throw new TypeError("Missing async generator suspension owner.");
|
|
12983
|
+
driver.suspension = "await";
|
|
12984
|
+
origin.awaitPhase = phase;
|
|
12985
|
+
}
|
|
12986
|
+
try {
|
|
12987
|
+
const completion = await context.generatorYield(awaited, node.nodeId);
|
|
12988
|
+
if (context.generatorResume !== void 0) context.generatorResume.completed = true;
|
|
12989
|
+
if (completion.type === "throw") throw completion.value;
|
|
12990
|
+
return completion.value;
|
|
12991
|
+
} finally {
|
|
12992
|
+
if (origin !== void 0) origin.awaitPhase = void 0;
|
|
12993
|
+
leaveAwait();
|
|
12994
|
+
}
|
|
12995
|
+
}
|
|
12468
12996
|
async function executeClosure(node, args, thisValue, context, evaluateNode2) {
|
|
12469
12997
|
const parent = context.compilation;
|
|
12470
12998
|
const operation = context.budget.acquireCompileOwner(false, parent?.owner);
|
|
@@ -12475,6 +13003,8 @@ async function executeClosure(node, args, thisValue, context, evaluateNode2) {
|
|
|
12475
13003
|
const result = await evaluateNode2(node.body, {
|
|
12476
13004
|
...context,
|
|
12477
13005
|
asyncGenerator: false,
|
|
13006
|
+
asyncFunction: false,
|
|
13007
|
+
asyncGeneratorFrame: void 0,
|
|
12478
13008
|
functionBody: node.body.type === "BlockStatement" ? node.body : void 0,
|
|
12479
13009
|
scope
|
|
12480
13010
|
});
|
|
@@ -17486,10 +18016,56 @@ function captureAsyncResources(resources, encode) {
|
|
|
17486
18016
|
method: encode(resource.method),
|
|
17487
18017
|
receiver: encode(resource.receiver),
|
|
17488
18018
|
args: resource.args.map(encode),
|
|
17489
|
-
syncFallback: resource.syncFallback
|
|
18019
|
+
syncFallback: resource.syncFallback,
|
|
18020
|
+
...resource.synchronous === void 0 ? {} : { synchronous: resource.synchronous }
|
|
17490
18021
|
}));
|
|
17491
18022
|
}
|
|
17492
18023
|
function captureGuestHeapNode(value, encode) {
|
|
18024
|
+
const generatorDriver = asyncGeneratorDrivers.get(value);
|
|
18025
|
+
if (generatorDriver === value) {
|
|
18026
|
+
if (generatorDriver.phase === "running") throw new SnapshotNotReadyError("Cannot snapshot an active async generator request.");
|
|
18027
|
+
return {
|
|
18028
|
+
kind: "async-generator-driver",
|
|
18029
|
+
generator: encode(generatorDriver.generator),
|
|
18030
|
+
phase: generatorDriver.phase,
|
|
18031
|
+
suspension: generatorDriver.suspension,
|
|
18032
|
+
awaitKind: generatorDriver.awaitKind,
|
|
18033
|
+
generation: generatorDriver.generation,
|
|
18034
|
+
requests: generatorDriver.requests.map((request) => ({
|
|
18035
|
+
method: request.method,
|
|
18036
|
+
value: encode(request.value),
|
|
18037
|
+
capability: { promise: encode(request.capability.promise), resolve: encode(request.capability.resolve), reject: encode(request.capability.reject) }
|
|
18038
|
+
}))
|
|
18039
|
+
};
|
|
18040
|
+
}
|
|
18041
|
+
const generatorHandler = isSandboxClosure(value) ? asyncGeneratorHandlers.get(value) : void 0;
|
|
18042
|
+
if (generatorHandler !== void 0) return {
|
|
18043
|
+
kind: "async-generator-handler",
|
|
18044
|
+
driver: encode(generatorHandler.driver),
|
|
18045
|
+
owner: encode(generatorHandler.owner),
|
|
18046
|
+
action: generatorHandler.action,
|
|
18047
|
+
generation: generatorHandler.generation,
|
|
18048
|
+
state: captureObjectState(value, encode)
|
|
18049
|
+
};
|
|
18050
|
+
const driver = asyncFunctionDrivers.get(value);
|
|
18051
|
+
if (driver !== void 0) {
|
|
18052
|
+
if (driver.phase === "running" || driver.generator === void 0) throw new SnapshotNotReadyError("Cannot snapshot an active async function.");
|
|
18053
|
+
return {
|
|
18054
|
+
kind: "async-function-driver",
|
|
18055
|
+
generator: encode(driver.generator),
|
|
18056
|
+
phase: driver.phase,
|
|
18057
|
+
generation: driver.generation,
|
|
18058
|
+
capability: { promise: encode(driver.capability.promise), resolve: encode(driver.capability.resolve), reject: encode(driver.capability.reject) }
|
|
18059
|
+
};
|
|
18060
|
+
}
|
|
18061
|
+
const asyncHandler = isSandboxClosure(value) ? asyncFunctionHandlers.get(value) : void 0;
|
|
18062
|
+
if (asyncHandler !== void 0) return {
|
|
18063
|
+
kind: "async-function-handler",
|
|
18064
|
+
driver: encode(asyncHandler.driver),
|
|
18065
|
+
action: asyncHandler.action,
|
|
18066
|
+
generation: asyncHandler.generation,
|
|
18067
|
+
state: captureObjectState(value, encode)
|
|
18068
|
+
};
|
|
17493
18069
|
const asyncStack = asyncDisposableStackStates.get(value);
|
|
17494
18070
|
if (asyncStack !== void 0) return {
|
|
17495
18071
|
kind: "async-disposable-stack",
|
|
@@ -17609,6 +18185,8 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17609
18185
|
return { kind: "promise-resolver", promise: encode(resolver.promise), state: captureObjectState(value, encode) };
|
|
17610
18186
|
}
|
|
17611
18187
|
if (isSandboxPromise(value)) {
|
|
18188
|
+
const generatorOwner = asyncGeneratorRequestOwners.get(value);
|
|
18189
|
+
const ownerState = generatorOwner === void 0 ? {} : { generatorOwner: encode(generatorOwner) };
|
|
17612
18190
|
const producerState = promiseProducers.has(value) ? { producers: [...promiseProducers.get(value)].map(encode) } : {};
|
|
17613
18191
|
const settlement = promiseStates.get(value);
|
|
17614
18192
|
if (settlement !== void 0 && settlement.status !== "pending")
|
|
@@ -17616,6 +18194,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17616
18194
|
kind: "guest-promise",
|
|
17617
18195
|
status: settlement.status,
|
|
17618
18196
|
value: encode(settlement.value),
|
|
18197
|
+
...ownerState,
|
|
17619
18198
|
...producerState,
|
|
17620
18199
|
...promiseReactionResults.has(value) ? { reactions: [...promiseReactionResults.get(value)].map(encode) } : {},
|
|
17621
18200
|
state: captureObjectState(value, encode)
|
|
@@ -17623,6 +18202,8 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17623
18202
|
const continuation = promiseContinuations.get(value);
|
|
17624
18203
|
if (unrepresentedPromiseContinuations.has(value))
|
|
17625
18204
|
throw new TypeError("Cannot serialize host reference: unrepresented promise continuation.");
|
|
18205
|
+
if (continuation?.kind === "reaction" && continuation.phase === "running")
|
|
18206
|
+
throw new SnapshotNotReadyError("Cannot snapshot an active promise reaction.");
|
|
17626
18207
|
if (continuation?.kind === "capability") {
|
|
17627
18208
|
const thenable2 = thenableContinuations.get(value);
|
|
17628
18209
|
if (continuation.state.settled && thenable2 !== void 0 && !thenable2.completed && thenable2.owner === value)
|
|
@@ -17630,6 +18211,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17630
18211
|
kind: "pending-promise",
|
|
17631
18212
|
thenable: encode(thenable2),
|
|
17632
18213
|
...producerState,
|
|
18214
|
+
...ownerState,
|
|
17633
18215
|
reactions: [...promiseReactionResults.get(value) ?? []].map(encode),
|
|
17634
18216
|
state: captureObjectState(value, encode)
|
|
17635
18217
|
};
|
|
@@ -17639,6 +18221,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17639
18221
|
return {
|
|
17640
18222
|
kind: "pending-promise",
|
|
17641
18223
|
...continuation.state.settled ? { adoption: encode(adoption) } : {},
|
|
18224
|
+
...ownerState,
|
|
17642
18225
|
...producerState,
|
|
17643
18226
|
reactions: [...promiseReactionResults.get(value) ?? []].map(encode),
|
|
17644
18227
|
state: captureObjectState(value, encode)
|
|
@@ -17787,6 +18370,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17787
18370
|
functionBoundary: frame.functionBoundary,
|
|
17788
18371
|
chargeData: frame.chargeData,
|
|
17789
18372
|
bindings: frame.bindings,
|
|
18373
|
+
...frame.resourceState === void 0 ? {} : { resourceState: encode(frame.resourceState) },
|
|
17790
18374
|
...frame.privateNames === void 0 ? {} : { privateNames: frame.privateNames.map(([name, identity]) => [name, encode(identity)]) },
|
|
17791
18375
|
cells: frame.cells.map((cell) => cell.initialized ? { ...cell, value: encode(cell.value) } : cell),
|
|
17792
18376
|
...frame.restoredBindings === void 0 ? {} : {
|
|
@@ -17803,6 +18387,9 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17803
18387
|
state: value.state,
|
|
17804
18388
|
astNodeId: origin2.node.nodeId,
|
|
17805
18389
|
async: value.async === true,
|
|
18390
|
+
...origin2.asyncFunction ? { asyncFunction: true } : {},
|
|
18391
|
+
...generatorDriver === void 0 ? {} : { driver: encode(generatorDriver) },
|
|
18392
|
+
...origin2.awaitPhase === void 0 ? {} : { awaitPhase: origin2.awaitPhase },
|
|
17806
18393
|
objectState: captureObjectState(value, encode),
|
|
17807
18394
|
scope: encode(origin2.scope),
|
|
17808
18395
|
closureScope: encode(origin2.closureScope),
|
|
@@ -17826,9 +18413,13 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17826
18413
|
expressionStates: Object.fromEntries([...origin2.expressionStates].map(([id, expression]) => [
|
|
17827
18414
|
String(id),
|
|
17828
18415
|
expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "declaration" ? { ...expression } : expression.kind === "switch" ? { ...expression, value: encode(expression.value), scope: encode(expression.scope) } : expression.kind === "yield-delegate" ? {
|
|
17829
|
-
|
|
18416
|
+
kind: expression.kind,
|
|
18417
|
+
async: expression.async,
|
|
17830
18418
|
value: encode(expression.value),
|
|
17831
18419
|
current: encode(expression.current),
|
|
18420
|
+
...expression.phase === void 0 ? {} : { phase: expression.phase },
|
|
18421
|
+
...expression.awaitState === void 0 ? {} : { awaitState: expression.awaitState },
|
|
18422
|
+
...expression.completion === void 0 ? {} : { completion: { ...expression.completion, value: encode(expression.completion.value) } },
|
|
17832
18423
|
iterator: mapIteratorSnapshot("kind" in expression.iterator ? expression.iterator : expression.iterator.snapshot?.() ?? { kind: "unsupported" }, encode)
|
|
17833
18424
|
} : expression.kind === "pattern-source" ? { kind: "pattern-source", value: encode(expression.value) } : expression.kind === "object-pattern" ? {
|
|
17834
18425
|
kind: "object-pattern",
|
|
@@ -17849,10 +18440,15 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17849
18440
|
iterator: mapIteratorSnapshot("kind" in expression.iterator ? expression.iterator : expression.iterator.snapshot?.() ?? { kind: "unsupported" }, encode),
|
|
17850
18441
|
...Object.hasOwn(expression, "referenceObject") ? { referenceObject: encode(expression.referenceObject), referenceKey: encode(expression.referenceKey) } : {}
|
|
17851
18442
|
} : expression.kind === "for-of-array" ? { ...expression, values: encode(expression.values), current: encode(expression.current), scope: encode(expression.scope) } : expression.kind === "for-of-iterator" ? {
|
|
17852
|
-
|
|
18443
|
+
kind: expression.kind,
|
|
18444
|
+
phase: expression.phase,
|
|
18445
|
+
async: expression.async,
|
|
18446
|
+
index: expression.index,
|
|
18447
|
+
...expression.awaitState === void 0 ? {} : { awaitState: expression.awaitState },
|
|
17853
18448
|
value: encode(expression.value),
|
|
17854
18449
|
current: encode(expression.current),
|
|
17855
18450
|
scope: encode(expression.scope),
|
|
18451
|
+
...expression.closeCompletion === void 0 ? {} : { closeCompletion: { ...expression.closeCompletion, value: encode(expression.closeCompletion.value) } },
|
|
17856
18452
|
iterator: mapIteratorSnapshot("kind" in expression.iterator ? expression.iterator : expression.iterator.snapshot?.() ?? { kind: "unsupported" }, encode)
|
|
17857
18453
|
} : expression.kind === "for-in" ? { ...expression, keys: [...expression.keys], object: encode(expression.object), scope: encode(expression.scope) } : expression.kind === "for" ? { kind: "for", phase: expression.phase, loopScope: encode(expression.loopScope), activeScope: encode(expression.activeScope) } : expression.kind === "identifier-assignment" ? { kind: "identifier-assignment", current: encode(expression.current) } : expression.kind === "member-assignment" ? {
|
|
17858
18454
|
kind: "member-assignment",
|
|
@@ -18228,6 +18824,29 @@ function serializeSafeJSSnapshot(snapshot) {
|
|
|
18228
18824
|
}
|
|
18229
18825
|
return JSON.stringify(createDumpFile(snapshot), null, 2);
|
|
18230
18826
|
}
|
|
18827
|
+
function requiresPromiseReplay(promise) {
|
|
18828
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18829
|
+
const pending = [promise];
|
|
18830
|
+
while (pending.length > 0) {
|
|
18831
|
+
const current = pending.pop();
|
|
18832
|
+
if (seen.has(current)) continue;
|
|
18833
|
+
seen.add(current);
|
|
18834
|
+
const continuation = promiseContinuations.get(current);
|
|
18835
|
+
if (promiseStates.get(current)?.status === "pending" && (unrepresentedPromiseContinuations.has(current) || continuation === void 0)) return true;
|
|
18836
|
+
pending.push(...promiseProducers.get(current) ?? [], ...promiseReactionResults.get(current) ?? []);
|
|
18837
|
+
if (continuation?.kind === "reaction") {
|
|
18838
|
+
pending.push(continuation.source);
|
|
18839
|
+
if (continuation.aggregate !== void 0) pending.push(continuation.aggregate);
|
|
18840
|
+
if (continuation.capability !== void 0) pending.push(continuation.capability.promise);
|
|
18841
|
+
} else if (continuation?.resolution !== void 0 && isSandboxPromise(continuation.resolution.value)) {
|
|
18842
|
+
pending.push(continuation.resolution.value);
|
|
18843
|
+
}
|
|
18844
|
+
const adoption = promiseAdoptions.get(current);
|
|
18845
|
+
const bridge = adoption === void 0 ? void 0 : promiseAdoptionBridges.get(adoption);
|
|
18846
|
+
if (bridge !== void 0) pending.push(bridge.source);
|
|
18847
|
+
}
|
|
18848
|
+
return false;
|
|
18849
|
+
}
|
|
18231
18850
|
function createDumpFile(snapshot) {
|
|
18232
18851
|
const state = {
|
|
18233
18852
|
trustedRunReplay: inMemoryRunSnapshots.has(snapshot),
|
|
@@ -18491,7 +19110,7 @@ function collectContainerStats(value, stats, ancestors, guestValues, trustedRunR
|
|
|
18491
19110
|
ancestors.add(value);
|
|
18492
19111
|
const guestEntries = [];
|
|
18493
19112
|
const replayPromise = isSandboxPromise(value) ? value : isPromiseResolvingFunction(value) ? promiseResolvingFunctions.get(value)?.promise : void 0;
|
|
18494
|
-
const replayMetadata = trustedRunReplay && replayPromise !== void 0 &&
|
|
19113
|
+
const replayMetadata = trustedRunReplay && replayPromise !== void 0 && requiresPromiseReplay(replayPromise);
|
|
18495
19114
|
if (isSandboxDataView(value)) guestEntries.push(dataViewBuffer(value));
|
|
18496
19115
|
if (isNumericTypedArray(value)) guestEntries.push(typedArrayStorage(value).buffer);
|
|
18497
19116
|
const guest = isSandboxDataView(value) ? { kind: "dataview", state: captureDataViewState(value, (entry) => {
|
|
@@ -22605,6 +23224,8 @@ function getGeneratorMember(target, property, budget) {
|
|
|
22605
23224
|
});
|
|
22606
23225
|
}
|
|
22607
23226
|
function callGeneratorMethod(target, method, value, budget, context, async) {
|
|
23227
|
+
if (async && isSandboxGenerator(target) && target.async === true)
|
|
23228
|
+
return enqueueAsyncGeneratorRequest(target, method, value, budget, context);
|
|
22608
23229
|
const result = (async () => {
|
|
22609
23230
|
if (!isSandboxGenerator(target) || target.async === true !== async)
|
|
22610
23231
|
throw new TypeError(`${async ? "AsyncGenerator" : "Generator"}.${method} requires a matching generator receiver.`);
|
|
@@ -24023,6 +24644,7 @@ function createBuiltinBindings(options) {
|
|
|
24023
24644
|
if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
|
|
24024
24645
|
createGeneratorPrototypes(options.budget);
|
|
24025
24646
|
registerBuiltinIdentities(options.budget, bindings);
|
|
24647
|
+
mutableBuiltinBindings.set(bindings, new Set(Object.keys(bindings).filter((name) => name !== "Infinity" && name !== "NaN" && name !== "undefined")));
|
|
24026
24648
|
return bindings;
|
|
24027
24649
|
}
|
|
24028
24650
|
|
|
@@ -24085,7 +24707,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24085
24707
|
createRawJson(node.text);
|
|
24086
24708
|
return true;
|
|
24087
24709
|
}
|
|
24088
|
-
if (!["thenable-state", "thenable-resolver", "construction-environment", "capability-executor", "promise-aggregate", "aggregate-entry", "aggregate-handler", "intrinsic", "bound-function", "promise-resolver", "pending-promise", "promise-reaction", "promise-adoption", "adoption-resolver", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "guest-boxed", "guest-date", "guest-regex", "guest-promise", "array-iterator", "string-iterator", "async-disposable-stack", "async-cleanup", "async-cleanup-handler", "disposable-stack", "iterator-wrapper", "iterator-helper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
|
|
24710
|
+
if (!["async-generator-driver", "async-generator-handler", "async-function-driver", "async-function-handler", "thenable-state", "thenable-resolver", "construction-environment", "capability-executor", "promise-aggregate", "aggregate-entry", "aggregate-handler", "intrinsic", "bound-function", "promise-resolver", "pending-promise", "promise-reaction", "promise-adoption", "adoption-resolver", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "guest-boxed", "guest-date", "guest-regex", "guest-promise", "array-iterator", "string-iterator", "async-disposable-stack", "async-cleanup", "async-cleanup-handler", "disposable-stack", "iterator-wrapper", "iterator-helper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
|
|
24089
24711
|
const reference = (value, kinds) => {
|
|
24090
24712
|
const ref = record3(value);
|
|
24091
24713
|
fields(ref, ["kind", "id"]);
|
|
@@ -24096,10 +24718,15 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24096
24718
|
};
|
|
24097
24719
|
const callable = (value) => {
|
|
24098
24720
|
if (absent(value)) return;
|
|
24099
|
-
const target = reference(value, ["async-cleanup-handler", "thenable-resolver", "aggregate-handler", "capability-executor", "intrinsic", "bound-function", "promise-resolver", "guest-function", "guest-class"]);
|
|
24721
|
+
const target = reference(value, ["async-generator-handler", "async-function-handler", "async-cleanup-handler", "thenable-resolver", "aggregate-handler", "capability-executor", "intrinsic", "bound-function", "promise-resolver", "guest-function", "guest-class"]);
|
|
24100
24722
|
if (target.kind === "intrinsic" && intrinsicCatalogue().get(String(target.id)) !== true)
|
|
24101
24723
|
throw new TypeError("Guest accessor reference is not callable.");
|
|
24102
24724
|
};
|
|
24725
|
+
if ((node.kind === "pending-promise" || node.kind === "guest-promise") && Object.hasOwn(node, "generatorOwner")) {
|
|
24726
|
+
const owner = reference(node.generatorOwner, ["async-generator-driver"]);
|
|
24727
|
+
if (!array(owner.requests).some((value) => reference(record3(record3(value).capability).promise) === node))
|
|
24728
|
+
throw new TypeError("Invalid async generator request ownership.");
|
|
24729
|
+
}
|
|
24103
24730
|
const privateIdentity = (value, expected) => {
|
|
24104
24731
|
const identity = reference(value, ["object"]);
|
|
24105
24732
|
fields(identity, ["kind", "entries"]);
|
|
@@ -24272,7 +24899,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24272
24899
|
throw new TypeError("Invalid promise resolver action.");
|
|
24273
24900
|
state(node.state);
|
|
24274
24901
|
} else if (node.kind === "pending-promise" || node.kind === "promise-reaction") {
|
|
24275
|
-
fields(node, node.kind === "pending-promise" ? ["kind", "reactions", "state"] : ["kind", "source", "onFulfilled", "onRejected", "reactions", "state"], node.kind === "pending-promise" ? ["adoption", "thenable", "producers"] : ["capability", "aggregate", "producers"]);
|
|
24902
|
+
fields(node, node.kind === "pending-promise" ? ["kind", "reactions", "state"] : ["kind", "source", "onFulfilled", "onRejected", "reactions", "state"], node.kind === "pending-promise" ? ["adoption", "thenable", "producers", "generatorOwner"] : ["capability", "aggregate", "producers"]);
|
|
24276
24903
|
if (node.kind === "pending-promise" && Object.hasOwn(node, "thenable")) {
|
|
24277
24904
|
const continuation = reference(node.thenable, ["thenable-state"]);
|
|
24278
24905
|
if (Object.hasOwn(node, "adoption") || continuation.completed !== false || reference(continuation.owner) !== node)
|
|
@@ -24299,7 +24926,10 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24299
24926
|
} else if (handler.kind === "async-cleanup-handler") {
|
|
24300
24927
|
const cleanup = reference(handler.cleanup, ["async-cleanup"]);
|
|
24301
24928
|
owner = reference(record3(cleanup.capability).promise);
|
|
24302
|
-
}
|
|
24929
|
+
} else if (handler.kind === "async-function-handler") {
|
|
24930
|
+
const driver = reference(handler.driver, ["async-function-driver"]);
|
|
24931
|
+
owner = reference(record3(driver.capability).promise);
|
|
24932
|
+
} else if (handler.kind === "async-generator-handler") owner = reference(handler.owner);
|
|
24303
24933
|
if (owner !== void 0 && owner !== aggregate) throw new TypeError("Invalid promise aggregate handler ownership.");
|
|
24304
24934
|
}
|
|
24305
24935
|
}
|
|
@@ -24328,7 +24958,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24328
24958
|
}
|
|
24329
24959
|
state(node.state);
|
|
24330
24960
|
} else if (node.kind === "guest-promise") {
|
|
24331
|
-
fields(node, ["kind", "status", "value", "state"], ["reactions", "producers"]);
|
|
24961
|
+
fields(node, ["kind", "status", "value", "state"], ["reactions", "producers", "generatorOwner"]);
|
|
24332
24962
|
if (Object.hasOwn(node, "reactions")) {
|
|
24333
24963
|
if (!Array.isArray(node.reactions)) throw new TypeError("Invalid promise reactions.");
|
|
24334
24964
|
const reactions = /* @__PURE__ */ new Set();
|
|
@@ -24402,7 +25032,8 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24402
25032
|
if (resources.length > maxArrayLength) throw new TypeError("Too many async resources.");
|
|
24403
25033
|
for (const rawResource of resources) {
|
|
24404
25034
|
const resource = record3(rawResource);
|
|
24405
|
-
fields(resource, ["method", "receiver", "args", "syncFallback"]);
|
|
25035
|
+
fields(resource, ["method", "receiver", "args", "syncFallback"], ["synchronous"]);
|
|
25036
|
+
if (resource.synchronous !== void 0 && (resource.synchronous !== true || resource.syncFallback || absent(resource.method))) throw new TypeError("Invalid synchronous resource.");
|
|
24406
25037
|
const args = array(resource.args);
|
|
24407
25038
|
if (typeof resource.syncFallback !== "boolean" || args.length > 1) throw new TypeError("Invalid async resource.");
|
|
24408
25039
|
if (absent(resource.method)) {
|
|
@@ -24426,6 +25057,55 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24426
25057
|
throw new TypeError("Invalid async cleanup resolver ownership.");
|
|
24427
25058
|
}
|
|
24428
25059
|
}
|
|
25060
|
+
} else if (node.kind === "async-generator-driver") {
|
|
25061
|
+
fields(node, ["kind", "generator", "requests", "phase", "suspension", "awaitKind", "generation"]);
|
|
25062
|
+
const generator = reference(node.generator, ["guest-generator"]);
|
|
25063
|
+
if (generator.async !== true || generator.asyncFunction !== void 0 || reference(generator.driver) !== node || !["idle", "waiting"].includes(String(node.phase)) || !["await", "yield"].includes(String(node.suspension)) || !["body", "return"].includes(String(node.awaitKind))) throw new TypeError("Invalid async generator driver.");
|
|
25064
|
+
integer(node.generation);
|
|
25065
|
+
if (!Array.isArray(node.requests) || node.phase === "idle" !== (node.requests.length === 0)) throw new TypeError("Invalid async generator request queue.");
|
|
25066
|
+
if (node.phase === "waiting" && (node.awaitKind === "body" ? generator.state !== "suspended" || generator.awaitPhase === void 0 || node.suspension !== "await" : generator.state !== "done")) throw new TypeError("Invalid async generator wait position.");
|
|
25067
|
+
const owners = /* @__PURE__ */ new Set();
|
|
25068
|
+
for (const value of node.requests) {
|
|
25069
|
+
const request = record3(value);
|
|
25070
|
+
fields(request, ["method", "value", "capability"]);
|
|
25071
|
+
if (!["next", "return", "throw"].includes(String(request.method))) throw new TypeError("Invalid async generator request operation.");
|
|
25072
|
+
const capability = record3(request.capability);
|
|
25073
|
+
fields(capability, ["promise", "resolve", "reject"]);
|
|
25074
|
+
const owner = reference(capability.promise, ["pending-promise", "guest-promise"]);
|
|
25075
|
+
if (owners.has(owner)) throw new TypeError("Duplicate async generator request owner.");
|
|
25076
|
+
if (reference(owner.generatorOwner, ["async-generator-driver"]) !== node) throw new TypeError("Invalid async generator request ownership.");
|
|
25077
|
+
owners.add(owner);
|
|
25078
|
+
for (const key of ["resolve", "reject"]) {
|
|
25079
|
+
const resolver = reference(capability[key], ["promise-resolver"]);
|
|
25080
|
+
if (reference(resolver.promise) !== owner || resolver.action !== void 0 && resolver.action !== (key === "resolve" ? "fulfilled" : "rejected"))
|
|
25081
|
+
throw new TypeError("Invalid async generator resolver ownership.");
|
|
25082
|
+
}
|
|
25083
|
+
}
|
|
25084
|
+
} else if (node.kind === "async-generator-handler") {
|
|
25085
|
+
fields(node, ["kind", "driver", "owner", "action", "generation", "state"]);
|
|
25086
|
+
const driver = reference(node.driver, ["async-generator-driver"]);
|
|
25087
|
+
const owner = reference(node.owner, ["pending-promise", "guest-promise"]);
|
|
25088
|
+
if (!["fulfilled", "rejected"].includes(String(node.action)) || integer(node.generation) > integer(driver.generation)) throw new TypeError("Invalid async generator handler.");
|
|
25089
|
+
if (driver.phase === "waiting" && node.generation === driver.generation && reference(record3(record3(driver.requests[0]).capability).promise) !== owner) throw new TypeError("Invalid async generator active handler owner.");
|
|
25090
|
+
state(node.state);
|
|
25091
|
+
} else if (node.kind === "async-function-driver") {
|
|
25092
|
+
fields(node, ["kind", "generator", "capability", "phase", "generation"]);
|
|
25093
|
+
const generator = reference(node.generator, ["guest-generator"]);
|
|
25094
|
+
if (generator.asyncFunction !== true || !["waiting", "done"].includes(String(node.phase))) throw new TypeError("Invalid async function frame.");
|
|
25095
|
+
integer(node.generation);
|
|
25096
|
+
const capability = record3(node.capability);
|
|
25097
|
+
fields(capability, ["promise", "resolve", "reject"]);
|
|
25098
|
+
const owner = reference(capability.promise, ["pending-promise", "guest-promise"]);
|
|
25099
|
+
for (const key of ["resolve", "reject"]) {
|
|
25100
|
+
const resolver = reference(capability[key], ["promise-resolver"]);
|
|
25101
|
+
if (reference(resolver.promise) !== owner || resolver.action !== void 0 && resolver.action !== (key === "resolve" ? "fulfilled" : "rejected"))
|
|
25102
|
+
throw new TypeError("Invalid async function resolver ownership.");
|
|
25103
|
+
}
|
|
25104
|
+
} else if (node.kind === "async-function-handler") {
|
|
25105
|
+
fields(node, ["kind", "driver", "action", "generation", "state"]);
|
|
25106
|
+
const driver = reference(node.driver, ["async-function-driver"]);
|
|
25107
|
+
if (node.action !== "fulfilled" && node.action !== "rejected" || integer(node.generation) > integer(driver.generation)) throw new TypeError("Invalid async function handler.");
|
|
25108
|
+
state(node.state);
|
|
24429
25109
|
} else if (node.kind === "async-cleanup-handler") {
|
|
24430
25110
|
fields(node, ["kind", "cleanup", "action", "generation", "state"]);
|
|
24431
25111
|
const cleanup = reference(node.cleanup, ["async-cleanup"]);
|
|
@@ -24567,7 +25247,10 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24567
25247
|
}
|
|
24568
25248
|
state(node.state);
|
|
24569
25249
|
} else if (node.kind === "guest-generator") {
|
|
24570
|
-
fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates", "objectState"]);
|
|
25250
|
+
fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates", "objectState", "asyncFunction", "driver", "awaitPhase"]);
|
|
25251
|
+
if (node.asyncFunction !== void 0 && (node.asyncFunction !== true || node.async !== false)) throw new TypeError("Invalid async function suspension frame.");
|
|
25252
|
+
if (node.driver !== void 0 && (node.async !== true || reference(reference(node.driver, ["async-generator-driver"]).generator) !== node)) throw new TypeError("Invalid async generator frame owner.");
|
|
25253
|
+
if (node.awaitPhase !== void 0 && (node.driver === void 0 || node.state !== "suspended" || !["await", "yield", "return", "resume-return"].includes(String(node.awaitPhase)))) throw new TypeError("Invalid async generator await phase.");
|
|
24571
25254
|
if (Object.hasOwn(node, "objectState")) state(node.objectState);
|
|
24572
25255
|
if (!["start", "running", "suspended", "done"].includes(String(node.state)) || typeof node.async !== "boolean" || integer(node.astNodeId) < 1)
|
|
24573
25256
|
throw new TypeError("Invalid generator state.");
|
|
@@ -24602,8 +25285,24 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24602
25285
|
if (Object.hasOwn(expression, "referenceKey") && typeof expression.referenceKey !== "string") reference(expression.referenceKey, ["symbol"]);
|
|
24603
25286
|
} else if (expression.kind === "for-of-array" || expression.kind === "for-of-iterator" || expression.kind === "array-pattern" || expression.kind === "yield-delegate") {
|
|
24604
25287
|
if (expression.kind === "yield-delegate") {
|
|
24605
|
-
fields(expression, ["kind", "async", "value", "current", "iterator"]);
|
|
25288
|
+
fields(expression, ["kind", "async", "value", "current", "iterator"], ["phase", "awaitState", "completion"]);
|
|
24606
25289
|
if (typeof expression.async !== "boolean") throw new TypeError("Invalid delegated yield protocol.");
|
|
25290
|
+
if (expression.phase !== void 0) {
|
|
25291
|
+
if (!["await", "close"].includes(String(expression.phase)) || expression.async !== true || node.awaitPhase !== "await" || node.yieldNodeId !== Number(id))
|
|
25292
|
+
throw new TypeError("Invalid delegated iterator wait position.");
|
|
25293
|
+
const completion = record3(expression.completion);
|
|
25294
|
+
fields(completion, ["type", "value"]);
|
|
25295
|
+
if (!["normal", "return", "throw"].includes(String(completion.type)) || expression.phase === "close" && completion.type !== "throw")
|
|
25296
|
+
throw new TypeError("Invalid delegated iterator completion.");
|
|
25297
|
+
const awaiting = record3(expression.awaitState);
|
|
25298
|
+
if (awaiting.kind === "result") fields(awaiting, ["kind"]);
|
|
25299
|
+
else if (awaiting.kind === "value") {
|
|
25300
|
+
fields(awaiting, ["kind", "done", "closeOnReject"]);
|
|
25301
|
+
if (typeof awaiting.done !== "boolean" || typeof awaiting.closeOnReject !== "boolean" || awaiting.closeOnReject !== (expression.phase === "await" && completion.type !== "return" && !awaiting.done))
|
|
25302
|
+
throw new TypeError("Invalid delegated async-from-sync continuation.");
|
|
25303
|
+
} else throw new TypeError("Invalid delegated iterator await kind.");
|
|
25304
|
+
} else if (expression.awaitState !== void 0 || expression.completion !== void 0)
|
|
25305
|
+
throw new TypeError("Unexpected delegated iterator continuation fields.");
|
|
24607
25306
|
} else if (expression.kind === "array-pattern") {
|
|
24608
25307
|
fields(expression, ["kind", "phase", "index", "done", "current", "iterator"], ["referenceObject", "referenceKey", "privateName"]);
|
|
24609
25308
|
if (expression.privateName !== void 0 && (typeof expression.privateName !== "string" || !Object.hasOwn(expression, "referenceObject"))) throw new TypeError("Invalid private pattern reference.");
|
|
@@ -24617,8 +25316,26 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24617
25316
|
"index",
|
|
24618
25317
|
"scope",
|
|
24619
25318
|
...expression.kind === "for-of-array" ? ["values"] : ["value", "iterator", "async"]
|
|
24620
|
-
]);
|
|
24621
|
-
if (!["left", "body"].includes(String(expression.phase))) throw new TypeError("Invalid for-of phase.");
|
|
25319
|
+
], ["awaitState", "closeCompletion"]);
|
|
25320
|
+
if (!["left", "body", "next", "close"].includes(String(expression.phase))) throw new TypeError("Invalid for-of phase.");
|
|
25321
|
+
if (expression.phase === "next" || expression.phase === "close") {
|
|
25322
|
+
if (expression.kind !== "for-of-iterator" || expression.async !== true) throw new TypeError("Invalid async iterator suspension.");
|
|
25323
|
+
const awaiting = record3(expression.awaitState);
|
|
25324
|
+
if (awaiting.kind === "result") fields(awaiting, ["kind"]);
|
|
25325
|
+
else if (awaiting.kind === "value") {
|
|
25326
|
+
fields(awaiting, ["kind", "done", "closeOnReject"]);
|
|
25327
|
+
if (typeof awaiting.done !== "boolean" || typeof awaiting.closeOnReject !== "boolean" || awaiting.closeOnReject !== (expression.phase === "next" && !awaiting.done))
|
|
25328
|
+
throw new TypeError("Invalid async-from-sync continuation.");
|
|
25329
|
+
} else throw new TypeError("Invalid iterator await kind.");
|
|
25330
|
+
} else if (Object.hasOwn(expression, "awaitState")) throw new TypeError("Unexpected iterator await state.");
|
|
25331
|
+
if (expression.phase === "close") {
|
|
25332
|
+
const completion = record3(expression.closeCompletion);
|
|
25333
|
+
fields(completion, ["kind", "hasValue", "value"], ["span", "stackFrames", "label"]);
|
|
25334
|
+
if (!["normal", "return", "throw", "break", "continue"].includes(String(completion.kind)) || typeof completion.hasValue !== "boolean")
|
|
25335
|
+
throw new TypeError("Invalid iterator close completion.");
|
|
25336
|
+
if (completion.label !== void 0 && typeof completion.label !== "string") throw new TypeError("Invalid iterator close label.");
|
|
25337
|
+
if (completion.stackFrames !== void 0 && array(completion.stackFrames).some((frame) => typeof frame !== "string")) throw new TypeError("Invalid iterator close stack.");
|
|
25338
|
+
} else if (Object.hasOwn(expression, "closeCompletion")) throw new TypeError("Unexpected iterator close completion.");
|
|
24622
25339
|
reference(expression.scope, ["scope-frame"]);
|
|
24623
25340
|
}
|
|
24624
25341
|
if (expression.kind !== "yield-delegate") integer(expression.index);
|
|
@@ -24633,6 +25350,8 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24633
25350
|
iterator = record3(iterator.inner);
|
|
24634
25351
|
protocol = true;
|
|
24635
25352
|
}
|
|
25353
|
+
if ((expression.kind === "for-of-iterator" && (expression.phase === "next" || expression.phase === "close") || expression.kind === "yield-delegate" && expression.phase !== void 0) && record3(expression.awaitState).kind !== (depth === 1 ? "value" : "result"))
|
|
25354
|
+
throw new TypeError("Iterator await state does not match its adapter.");
|
|
24636
25355
|
if (iterator.kind === "guest") {
|
|
24637
25356
|
fields(iterator, ["kind", "value", "next", "async"]);
|
|
24638
25357
|
if (typeof iterator.async !== "boolean") throw new TypeError("Invalid iterator protocol.");
|
|
@@ -24673,7 +25392,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24673
25392
|
reference(expression.scope, ["scope-frame"]);
|
|
24674
25393
|
} else if (expression.kind === "for") {
|
|
24675
25394
|
fields(expression, ["kind", "phase", "loopScope", "activeScope"]);
|
|
24676
|
-
if (!["init", "test", "body", "update"].includes(String(expression.phase))) throw new TypeError("Invalid for-loop phase.");
|
|
25395
|
+
if (!["init", "test", "body", "update", "dispose"].includes(String(expression.phase))) throw new TypeError("Invalid for-loop phase.");
|
|
24677
25396
|
reference(expression.loopScope, ["scope-frame"]);
|
|
24678
25397
|
reference(expression.activeScope, ["scope-frame"]);
|
|
24679
25398
|
} else if (expression.kind === "identifier-assignment") {
|
|
@@ -24736,7 +25455,8 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24736
25455
|
if (Object.hasOwn(environment, "construction")) reference(environment.construction, ["construction-environment"]);
|
|
24737
25456
|
}
|
|
24738
25457
|
} else {
|
|
24739
|
-
fields(node, ["kind", "parent", "importMeta", "functionBoundary", "chargeData", "bindings", "cells"], ["restoredBindings", "privateNames"]);
|
|
25458
|
+
fields(node, ["kind", "parent", "importMeta", "functionBoundary", "chargeData", "bindings", "cells"], ["restoredBindings", "privateNames", "resourceState"]);
|
|
25459
|
+
if (node.resourceState !== void 0) reference(node.resourceState, ["object"]);
|
|
24740
25460
|
if (node.privateNames !== void 0) {
|
|
24741
25461
|
const names2 = /* @__PURE__ */ new Set();
|
|
24742
25462
|
for (const raw2 of array(node.privateNames)) {
|
|
@@ -24810,6 +25530,11 @@ function privateAssignmentName(value) {
|
|
|
24810
25530
|
const property = node.property;
|
|
24811
25531
|
return property.type === "PrivateIdentifier" ? String(property.name) : void 0;
|
|
24812
25532
|
}
|
|
25533
|
+
function asyncResourceDeclaration(value) {
|
|
25534
|
+
if (value === null || typeof value !== "object") return false;
|
|
25535
|
+
const node = value;
|
|
25536
|
+
return node.type === "VariableDeclaration" && node.disposal === "async";
|
|
25537
|
+
}
|
|
24813
25538
|
function validateGuestFunctionAst(record4, origin) {
|
|
24814
25539
|
if (record4.kind === "guest-class") {
|
|
24815
25540
|
if (origin === null || typeof origin !== "object" || !["ClassDeclaration", "ClassExpression"].includes(String(origin.type)))
|
|
@@ -24833,7 +25558,8 @@ function validateGuestFunctionAst(record4, origin) {
|
|
|
24833
25558
|
throw new TypeError("Unknown guest function AST identity");
|
|
24834
25559
|
if (record4.kind !== "guest-generator") return;
|
|
24835
25560
|
const functionNode = origin;
|
|
24836
|
-
|
|
25561
|
+
const representedAsync = record4.asyncFunction === true || record4.async === true && record4.driver !== void 0;
|
|
25562
|
+
if (record4.asyncFunction === true ? functionNode.async !== true || functionNode.generator === true || record4.async !== false : functionNode.generator !== true || functionNode.async === true !== record4.async)
|
|
24837
25563
|
throw new TypeError("Invalid generator AST identity");
|
|
24838
25564
|
let yieldBlocks;
|
|
24839
25565
|
let yieldFinalizers;
|
|
@@ -24848,10 +25574,29 @@ function validateGuestFunctionAst(record4, origin) {
|
|
|
24848
25574
|
if (["ArrowFunctionExpression", "FunctionExpression", "FunctionDeclaration"].includes(String(node.type))) continue;
|
|
24849
25575
|
let blocks = frame.blocks;
|
|
24850
25576
|
if (node.type === "BlockStatement" && typeof node.nodeId === "number") blocks = /* @__PURE__ */ new Set([...blocks, node.nodeId]);
|
|
24851
|
-
|
|
25577
|
+
const cases = node.type === "SwitchStatement" ? node.cases : void 0;
|
|
25578
|
+
const resourceBoundary = representedAsync && (node.type === "BlockStatement" && Array.isArray(node.body) && node.body.some(asyncResourceDeclaration) || node.type === "ForOfStatement" && asyncResourceDeclaration(node.left) || node.type === "ForStatement" && asyncResourceDeclaration(node.init) || cases !== void 0 && cases.some((entry) => entry.consequent.some(asyncResourceDeclaration)));
|
|
25579
|
+
const iteratorBoundary = representedAsync && node.type === "ForOfStatement" && node.await === true && ["next", "close"].includes(record4.expressionStates?.[String(node.nodeId)]?.phase ?? "");
|
|
25580
|
+
const delegateBoundary = representedAsync && node.type === "YieldExpression" && node.delegate === true && ["await", "close"].includes(record4.expressionStates?.[String(node.nodeId)]?.phase ?? "");
|
|
25581
|
+
if ((node.type === "YieldExpression" || representedAsync && node.type === "AwaitExpression" || record4.awaitPhase === "return" && node.type === "ReturnStatement" || resourceBoundary || iteratorBoundary) && node.nodeId === record4.yieldNodeId) {
|
|
25582
|
+
if (record4.awaitPhase !== void 0) {
|
|
25583
|
+
const valid = record4.awaitPhase === "await" ? node.type === "AwaitExpression" || resourceBoundary || iteratorBoundary || delegateBoundary : record4.awaitPhase === "return" ? node.type === "ReturnStatement" : node.type === "YieldExpression" && (record4.awaitPhase === "resume-return" || node.delegate !== true);
|
|
25584
|
+
if (!valid) throw new TypeError("Invalid async generator await source position.");
|
|
25585
|
+
}
|
|
24852
25586
|
yieldBlocks = blocks;
|
|
24853
25587
|
yieldFinalizers = frame.finalizers;
|
|
24854
25588
|
yieldExpressions = node.delegate === true && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "yield-delegate", async: record4.async === true }]]) : frame.expressions;
|
|
25589
|
+
if (resourceBoundary && typeof node.nodeId === "number") {
|
|
25590
|
+
if (node.type === "ForOfStatement") yieldExpressions = new Map([...frame.expressions, [node.nodeId, { kind: "for-of", phase: "body", async: node.await === true }]]);
|
|
25591
|
+
if (node.type === "ForStatement") yieldExpressions = new Map([...frame.expressions, [node.nodeId, { kind: "for", phase: "dispose" }]]);
|
|
25592
|
+
if (cases !== void 0) {
|
|
25593
|
+
const progress = record4.expressionStates?.[String(node.nodeId)];
|
|
25594
|
+
if (progress === void 0 || progress.phase !== "body" || progress.index < 0 || progress.index >= cases.length || progress.statementIndex < 0 || progress.statementIndex >= cases[progress.index].consequent.length) throw new TypeError("Invalid switch disposal position.");
|
|
25595
|
+
yieldExpressions = new Map([...frame.expressions, [node.nodeId, { kind: "switch", phase: "body", index: progress.index, statementIndex: progress.statementIndex }]]);
|
|
25596
|
+
}
|
|
25597
|
+
}
|
|
25598
|
+
if (iteratorBoundary && typeof node.nodeId === "number")
|
|
25599
|
+
yieldExpressions = new Map([...frame.expressions, [node.nodeId, { kind: "for-of", phase: record4.expressionStates[String(node.nodeId)].phase, async: true }]]);
|
|
24855
25600
|
}
|
|
24856
25601
|
for (const [key, value] of Object.entries(node)) {
|
|
24857
25602
|
if (node.type === "SwitchStatement" && key === "cases" && typeof node.nodeId === "number" && Array.isArray(value)) {
|
|
@@ -26132,6 +26877,91 @@ function bigIntOperation(operator, left, right, budget) {
|
|
|
26132
26877
|
}
|
|
26133
26878
|
}
|
|
26134
26879
|
|
|
26880
|
+
// packages/safe-js/src/interp/resource-management.ts
|
|
26881
|
+
function resourceSuspension(context, node) {
|
|
26882
|
+
return context.asyncFunction || context.asyncGeneratorFrame !== void 0 ? {
|
|
26883
|
+
awaitResource: (value) => suspendAsyncFunctionValue(value, node, context),
|
|
26884
|
+
resumeResource: context.generatorResume?.completed !== true && context.generatorResume?.yieldNodeId === node.nodeId
|
|
26885
|
+
} : {};
|
|
26886
|
+
}
|
|
26887
|
+
async function registerScopeResource(scope, value, hint, budget, context) {
|
|
26888
|
+
if (hint === "sync" && (value === null || value === void 0)) return;
|
|
26889
|
+
const state = scope.resourceState ??= { resources: [] };
|
|
26890
|
+
if (value === null || value === void 0) {
|
|
26891
|
+
state.resources.push({ method: void 0, receiver: void 0, args: [], syncFallback: false });
|
|
26892
|
+
createDataCheckpoint(budget, context)(state, 0, true);
|
|
26893
|
+
return;
|
|
26894
|
+
}
|
|
26895
|
+
if (typeof value !== "object") throw new TypeError("Disposable resource must be an object.");
|
|
26896
|
+
const read = async (key) => {
|
|
26897
|
+
if (context?.getProperty !== void 0) return context.getProperty(value, key);
|
|
26898
|
+
const descriptor = getSandboxPropertyDescriptor(value, key, budget);
|
|
26899
|
+
return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
|
|
26900
|
+
};
|
|
26901
|
+
let method = await read(hint === "async" ? wellKnownSymbols.asyncDispose : wellKnownSymbols.dispose);
|
|
26902
|
+
let syncFallback = false;
|
|
26903
|
+
if (hint === "async" && (method === void 0 || method === null)) {
|
|
26904
|
+
method = await read(wellKnownSymbols.dispose);
|
|
26905
|
+
syncFallback = true;
|
|
26906
|
+
}
|
|
26907
|
+
if (!isSandboxClosure(method)) throw new TypeError("Disposer must be callable.");
|
|
26908
|
+
state.resources.push({ method, receiver: value, args: [], syncFallback, ...hint === "sync" ? { synchronous: true } : {} });
|
|
26909
|
+
createDataCheckpoint(budget, context)(state, 0, true);
|
|
26910
|
+
}
|
|
26911
|
+
async function evaluateResourceScope(scope, budget, context, body) {
|
|
26912
|
+
let completion;
|
|
26913
|
+
try {
|
|
26914
|
+
completion = scope.resourceState?.completion ?? await body();
|
|
26915
|
+
} catch (error) {
|
|
26916
|
+
if (scope.resourceState === void 0 || isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
|
|
26917
|
+
completion = createThrowCompletion(error, budget, context?.stack ?? []);
|
|
26918
|
+
}
|
|
26919
|
+
const state = scope.resourceState;
|
|
26920
|
+
if (state === void 0 || state.resources.length === 0 && state.cleanup === void 0) return completion;
|
|
26921
|
+
if (completion.kind === "error") return completion;
|
|
26922
|
+
state.completion = { ...completion, ...completion.stackFrames === void 0 ? { stackFrames: void 0 } : { stackFrames: [...completion.stackFrames] } };
|
|
26923
|
+
const release = retainValues(budget, () => [state]);
|
|
26924
|
+
try {
|
|
26925
|
+
if (state.cleanup === void 0) {
|
|
26926
|
+
const capability = createPendingPromiseCapability(budget, context);
|
|
26927
|
+
const cleanup2 = {
|
|
26928
|
+
resources: state.resources,
|
|
26929
|
+
capability: { promise: capability.promise, resolve: capability.resolve, reject: capability.reject },
|
|
26930
|
+
phase: "running",
|
|
26931
|
+
failed: completion.kind === "throw",
|
|
26932
|
+
failure: completion.kind === "throw" ? completion.value : void 0,
|
|
26933
|
+
needsAwait: false,
|
|
26934
|
+
hasAwaited: false,
|
|
26935
|
+
generation: 0
|
|
26936
|
+
};
|
|
26937
|
+
state.resources = [];
|
|
26938
|
+
state.cleanup = cleanup2;
|
|
26939
|
+
asyncCleanupStates.set(cleanup2, cleanup2);
|
|
26940
|
+
await advanceAsyncCleanup(cleanup2, budget, context);
|
|
26941
|
+
}
|
|
26942
|
+
const cleanup = state.cleanup;
|
|
26943
|
+
try {
|
|
26944
|
+
if (context?.awaitResource !== void 0) {
|
|
26945
|
+
if (cleanup.phase !== "done" || context.resumeResource) await context.awaitResource(cleanup.capability.promise);
|
|
26946
|
+
else observeSandboxPromise(cleanup.capability.promise, true);
|
|
26947
|
+
} else {
|
|
26948
|
+
const settled = awaitSandboxValue(cleanup.capability.promise, context?.signal, budget, context);
|
|
26949
|
+
if (cleanup.phase === "done") await settled;
|
|
26950
|
+
else {
|
|
26951
|
+
context?.onSuspend?.();
|
|
26952
|
+
await suspendJob(settled);
|
|
26953
|
+
}
|
|
26954
|
+
}
|
|
26955
|
+
} catch (error) {
|
|
26956
|
+
if (cleanup.phase !== "done" || isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
|
|
26957
|
+
}
|
|
26958
|
+
return cleanup.failed ? { kind: "throw", hasValue: true, value: cleanup.failure } : completion;
|
|
26959
|
+
} finally {
|
|
26960
|
+
if (state.cleanup?.phase === "done") scope.resourceState = void 0;
|
|
26961
|
+
release();
|
|
26962
|
+
}
|
|
26963
|
+
}
|
|
26964
|
+
|
|
26135
26965
|
// packages/safe-js/src/interp/resume-target.ts
|
|
26136
26966
|
function containsResumeTarget(node, targetNodeIds) {
|
|
26137
26967
|
if (targetNodeIds === void 0 ? node.type === "YieldExpression" : node.nodeId !== void 0 && targetNodeIds.has(node.nodeId)) {
|
|
@@ -26292,9 +27122,10 @@ async function interpret(node, options = {}) {
|
|
|
26292
27122
|
asyncGenerator: options.asyncGenerator,
|
|
26293
27123
|
resumeTarget: { nodeId: options.snapshot?.resumeNodeId }
|
|
26294
27124
|
};
|
|
27125
|
+
const execute = () => node.type === "VariableDeclaration" && node.disposal !== void 0 ? evaluateResourceScope(scope, budget, { ...createCoercionContext(context), onSuspend: context.onSuspend, signal: context.signal }, () => evaluateNode(node, context)) : evaluateNode(node, context);
|
|
26295
27126
|
const evaluation = await withCancellationSignal(
|
|
26296
27127
|
options.signal,
|
|
26297
|
-
() => options.nested ? runAsyncPrefix(
|
|
27128
|
+
() => options.nested ? runAsyncPrefix(execute) : jobs.run(execute)
|
|
26298
27129
|
);
|
|
26299
27130
|
if (!options.nested) await jobs.drain();
|
|
26300
27131
|
const snapshot = scope.snapshot();
|
|
@@ -27119,6 +27950,7 @@ async function evaluateVariableDeclaration(node, context) {
|
|
|
27119
27950
|
};
|
|
27120
27951
|
const release = retainValues(context.budget, () => [value.value]);
|
|
27121
27952
|
try {
|
|
27953
|
+
if (node.disposal !== void 0) await registerScopeResource(context.scope, value.value, node.disposal, context.budget, createCoercionContext(context));
|
|
27122
27954
|
const binding = await bindPattern(
|
|
27123
27955
|
declarator.id,
|
|
27124
27956
|
value.value,
|
|
@@ -27208,24 +28040,26 @@ async function evaluateBlockStatement(node, context) {
|
|
|
27208
28040
|
const blockContext = createBlockContext(node, context);
|
|
27209
28041
|
const resumeIndex = findResumeStatementIndex(node, blockContext);
|
|
27210
28042
|
const generatorResumeIndex = findGeneratorResumeStatementIndex(node, blockContext);
|
|
27211
|
-
|
|
27212
|
-
|
|
27213
|
-
|
|
27214
|
-
|
|
27215
|
-
|
|
27216
|
-
|
|
27217
|
-
|
|
27218
|
-
|
|
27219
|
-
|
|
27220
|
-
|
|
27221
|
-
|
|
28043
|
+
return evaluateResourceScope(blockContext.scope, context.budget, { ...createCoercionContext(blockContext), ...resourceSuspension(blockContext, node), onSuspend: blockContext.onSuspend, signal: blockContext.signal }, async () => {
|
|
28044
|
+
for (let index = 0; index < node.body.length; index += 1) {
|
|
28045
|
+
const statement = node.body[index];
|
|
28046
|
+
if (generatorResumeIndex !== void 0 && index < generatorResumeIndex) {
|
|
28047
|
+
continue;
|
|
28048
|
+
}
|
|
28049
|
+
if (resumeIndex !== void 0 && index < resumeIndex && statement.type !== "VariableDeclaration") {
|
|
28050
|
+
continue;
|
|
28051
|
+
}
|
|
28052
|
+
const result = await evaluateNode(statement, blockContext);
|
|
28053
|
+
if (result.kind !== "normal") {
|
|
28054
|
+
return result;
|
|
28055
|
+
}
|
|
27222
28056
|
}
|
|
27223
|
-
|
|
27224
|
-
|
|
27225
|
-
|
|
27226
|
-
|
|
27227
|
-
|
|
27228
|
-
};
|
|
28057
|
+
return {
|
|
28058
|
+
kind: "normal",
|
|
28059
|
+
hasValue: false,
|
|
28060
|
+
value: void 0
|
|
28061
|
+
};
|
|
28062
|
+
});
|
|
27229
28063
|
}
|
|
27230
28064
|
function findGeneratorResumeStatementIndex(node, context) {
|
|
27231
28065
|
if (context.generatorResume === void 0) {
|
|
@@ -27334,44 +28168,46 @@ async function evaluateSwitchStatement(node, context) {
|
|
|
27334
28168
|
);
|
|
27335
28169
|
const release = retainValues(context.budget, () => [progress.value]);
|
|
27336
28170
|
try {
|
|
27337
|
-
|
|
27338
|
-
|
|
27339
|
-
|
|
27340
|
-
|
|
27341
|
-
|
|
27342
|
-
|
|
27343
|
-
|
|
27344
|
-
|
|
27345
|
-
|
|
27346
|
-
|
|
27347
|
-
|
|
28171
|
+
return await evaluateResourceScope(progress.scope, context.budget, { ...createCoercionContext(switchContext), ...resourceSuspension(switchContext, node), onSuspend: switchContext.onSuspend, signal: switchContext.signal }, async () => {
|
|
28172
|
+
const defaultIndex = node.cases.findIndex((entry) => entry.test === void 0);
|
|
28173
|
+
let startIndex = saved?.phase === "body" ? saved.index : void 0;
|
|
28174
|
+
for (let index = progress.index; startIndex === void 0 && index < node.cases.length; index += 1) {
|
|
28175
|
+
const switchCase = node.cases[index];
|
|
28176
|
+
if (switchCase.test === void 0) {
|
|
28177
|
+
continue;
|
|
28178
|
+
}
|
|
28179
|
+
progress.index = index;
|
|
28180
|
+
const test = await evaluateNode(switchCase.test, switchContext);
|
|
28181
|
+
if (test.kind !== "normal") {
|
|
28182
|
+
return test;
|
|
28183
|
+
}
|
|
28184
|
+
if (discriminant.value === test.value) {
|
|
28185
|
+
startIndex = index;
|
|
28186
|
+
break;
|
|
28187
|
+
}
|
|
27348
28188
|
}
|
|
27349
|
-
|
|
27350
|
-
|
|
27351
|
-
|
|
28189
|
+
startIndex ??= defaultIndex < 0 ? void 0 : defaultIndex;
|
|
28190
|
+
if (startIndex === void 0) {
|
|
28191
|
+
return normalEmptyResult();
|
|
27352
28192
|
}
|
|
27353
|
-
|
|
27354
|
-
|
|
27355
|
-
|
|
27356
|
-
|
|
27357
|
-
|
|
27358
|
-
|
|
27359
|
-
|
|
27360
|
-
|
|
27361
|
-
|
|
27362
|
-
|
|
27363
|
-
|
|
27364
|
-
|
|
27365
|
-
|
|
27366
|
-
|
|
27367
|
-
return normalEmptyResult();
|
|
27368
|
-
}
|
|
27369
|
-
if (result.kind !== "normal") {
|
|
27370
|
-
return result;
|
|
28193
|
+
for (let caseIndex = startIndex; caseIndex < node.cases.length; caseIndex += 1) {
|
|
28194
|
+
progress.phase = "body";
|
|
28195
|
+
progress.index = caseIndex;
|
|
28196
|
+
const statements = node.cases[caseIndex].consequent;
|
|
28197
|
+
for (let statementIndex = saved?.phase === "body" && caseIndex === saved.index ? saved.statementIndex : 0; statementIndex < statements.length; statementIndex++) {
|
|
28198
|
+
progress.statementIndex = statementIndex;
|
|
28199
|
+
const statement = statements[statementIndex];
|
|
28200
|
+
const result = await evaluateNode(statement, switchContext);
|
|
28201
|
+
if (result.kind === "break" && result.label === void 0) {
|
|
28202
|
+
return normalEmptyResult();
|
|
28203
|
+
}
|
|
28204
|
+
if (result.kind !== "normal") {
|
|
28205
|
+
return result;
|
|
28206
|
+
}
|
|
27371
28207
|
}
|
|
27372
28208
|
}
|
|
27373
|
-
|
|
27374
|
-
|
|
28209
|
+
return normalEmptyResult();
|
|
28210
|
+
});
|
|
27375
28211
|
} finally {
|
|
27376
28212
|
release();
|
|
27377
28213
|
}
|
|
@@ -27440,7 +28276,7 @@ async function evaluateForOfStatement(node, context) {
|
|
|
27440
28276
|
}
|
|
27441
28277
|
const iterationContext = createLoopIterationContext(phaseContext("body"), scope);
|
|
27442
28278
|
emitLoopIterationBreakpoint(node, iterationContext);
|
|
27443
|
-
const result = await evaluateNode(node.body, iterationContext);
|
|
28279
|
+
const result = await evaluateResourceScope(scope, context.budget, { ...createCoercionContext(iterationContext), ...resourceSuspension(iterationContext, node), onSuspend: iterationContext.onSuspend, signal: iterationContext.signal }, () => evaluateNode(node.body, iterationContext));
|
|
27444
28280
|
if (isMatchingBreak(result, loopLabels(node))) {
|
|
27445
28281
|
context.activeLoopIterations.delete(node.nodeId ?? -1);
|
|
27446
28282
|
return {
|
|
@@ -27467,12 +28303,43 @@ async function evaluateForOfStatement(node, context) {
|
|
|
27467
28303
|
async function evaluateForOfIterator(node, value, context, restoredEntry) {
|
|
27468
28304
|
const saved = context.generatorResume === void 0 || node.nodeId === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(node.nodeId);
|
|
27469
28305
|
if (saved !== void 0 && saved.kind !== "for-of-iterator") throw new TypeError("Invalid iterator continuation.");
|
|
27470
|
-
let resumeCurrent = saved !== void 0;
|
|
28306
|
+
let resumeCurrent = saved !== void 0 && saved.phase !== "next";
|
|
28307
|
+
let resumeNext = saved?.phase === "next";
|
|
28308
|
+
let index = saved?.index ?? consumeRestoredLoopIterationIndex(node, context);
|
|
27471
28309
|
const iterator = saved === void 0 ? await acquireSandboxIterator(value, context.budget, createCoercionContext(context), node.await, context.signal) : "kind" in saved.iterator ? await restoreSandboxIterator(saved.iterator, context.budget, createCoercionContext(context), context.signal) : saved.iterator;
|
|
27472
28310
|
if (iterator === void 0) {
|
|
27473
28311
|
throw new TypeError(`${String(value)} is not a supported iterable`);
|
|
27474
28312
|
}
|
|
27475
28313
|
const nextIteration = async () => {
|
|
28314
|
+
if ((context.asyncFunction || context.asyncGeneratorFrame !== void 0) && node.await && iterator.resumeAwait !== void 0 && node.nodeId !== void 0) {
|
|
28315
|
+
iterator.awaitValue = (awaited, awaitState) => suspendAsyncFunctionValue(awaited, node, {
|
|
28316
|
+
...context,
|
|
28317
|
+
generatorExpressionStates: new Map([
|
|
28318
|
+
...context.generatorExpressionStates ?? [],
|
|
28319
|
+
[node.nodeId, {
|
|
28320
|
+
kind: "for-of-iterator",
|
|
28321
|
+
phase: "next",
|
|
28322
|
+
awaitState,
|
|
28323
|
+
async: true,
|
|
28324
|
+
value,
|
|
28325
|
+
current: void 0,
|
|
28326
|
+
index,
|
|
28327
|
+
scope: context.scope,
|
|
28328
|
+
iterator
|
|
28329
|
+
}]
|
|
28330
|
+
])
|
|
28331
|
+
}, void 0, createCoercionContext(context));
|
|
28332
|
+
try {
|
|
28333
|
+
if (resumeNext) {
|
|
28334
|
+
resumeNext = false;
|
|
28335
|
+
if (saved?.awaitState === void 0) throw new TypeError("Missing iterator await continuation.");
|
|
28336
|
+
return await iterator.resumeAwait(saved.awaitState, () => iterator.awaitValue(void 0, saved.awaitState));
|
|
28337
|
+
}
|
|
28338
|
+
return await iterator.next();
|
|
28339
|
+
} finally {
|
|
28340
|
+
delete iterator.awaitValue;
|
|
28341
|
+
}
|
|
28342
|
+
}
|
|
27476
28343
|
const pending = Promise.resolve(iterator.next());
|
|
27477
28344
|
if (!node.await) return pending;
|
|
27478
28345
|
context.onSuspend?.();
|
|
@@ -27484,9 +28351,50 @@ async function evaluateForOfIterator(node, value, context, restoredEntry) {
|
|
|
27484
28351
|
}
|
|
27485
28352
|
};
|
|
27486
28353
|
const releaseIterator = retainValues(context.budget, () => [value, iterator.retainedValue]);
|
|
28354
|
+
const closeLoopIterator = async (completion) => {
|
|
28355
|
+
const preserveThrow = completion.kind === "throw";
|
|
28356
|
+
if (!context.asyncFunction && context.asyncGeneratorFrame === void 0 || !node.await || iterator.resumeAwait === void 0 || node.nodeId === void 0 || completion.kind === "error") {
|
|
28357
|
+
await closeIterator(iterator, preserveThrow);
|
|
28358
|
+
return;
|
|
28359
|
+
}
|
|
28360
|
+
const { node: ignoredNode, stackFrames, ...metadata } = completion;
|
|
28361
|
+
const closeCompletion = { ...metadata, ...stackFrames === void 0 ? {} : { stackFrames: [...stackFrames] } };
|
|
28362
|
+
iterator.awaitValue = (awaited, awaitState) => suspendAsyncFunctionValue(awaited, node, {
|
|
28363
|
+
...context,
|
|
28364
|
+
generatorExpressionStates: new Map([
|
|
28365
|
+
...context.generatorExpressionStates ?? [],
|
|
28366
|
+
[node.nodeId, {
|
|
28367
|
+
kind: "for-of-iterator",
|
|
28368
|
+
phase: "close",
|
|
28369
|
+
awaitState,
|
|
28370
|
+
closeCompletion,
|
|
28371
|
+
async: true,
|
|
28372
|
+
value,
|
|
28373
|
+
current: void 0,
|
|
28374
|
+
index,
|
|
28375
|
+
scope: context.scope,
|
|
28376
|
+
iterator
|
|
28377
|
+
}]
|
|
28378
|
+
])
|
|
28379
|
+
}, void 0, createCoercionContext(context));
|
|
28380
|
+
try {
|
|
28381
|
+
if (saved?.phase === "close" && context.generatorResume?.completed !== true) {
|
|
28382
|
+
if (saved.awaitState === void 0) throw new TypeError("Missing iterator close continuation.");
|
|
28383
|
+
await iterator.resumeAwait(saved.awaitState, () => iterator.awaitValue(void 0, saved.awaitState));
|
|
28384
|
+
} else await closeIterator(iterator, preserveThrow);
|
|
28385
|
+
} catch (error) {
|
|
28386
|
+
if (!preserveThrow || isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
|
|
28387
|
+
} finally {
|
|
28388
|
+
delete iterator.awaitValue;
|
|
28389
|
+
}
|
|
28390
|
+
};
|
|
27487
28391
|
try {
|
|
28392
|
+
if (saved?.phase === "close") {
|
|
28393
|
+
if (saved.closeCompletion === void 0) throw new TypeError("Missing iterator close completion.");
|
|
28394
|
+
await closeLoopIterator(saved.closeCompletion);
|
|
28395
|
+
return saved.closeCompletion;
|
|
28396
|
+
}
|
|
27488
28397
|
const nodeId = node.nodeId ?? -1;
|
|
27489
|
-
let index = saved?.index ?? consumeRestoredLoopIterationIndex(node, context);
|
|
27490
28398
|
for (let skipped = 0; saved === void 0 && skipped < index; skipped += 1) {
|
|
27491
28399
|
const skippedIteration = await nextIteration();
|
|
27492
28400
|
if (typeof skippedIteration !== "object" || skippedIteration === null) {
|
|
@@ -27533,19 +28441,19 @@ async function evaluateForOfIterator(node, value, context, restoredEntry) {
|
|
|
27533
28441
|
binding = resuming && saved.phase === "body" ? { ok: true } : await bindIterationVariable(node.left, nextValue, scope, phaseContext("left"));
|
|
27534
28442
|
} catch (error) {
|
|
27535
28443
|
if (isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
|
|
27536
|
-
await
|
|
28444
|
+
await closeLoopIterator(createThrowCompletion(error, context.budget, context.callStack));
|
|
27537
28445
|
throw error;
|
|
27538
28446
|
}
|
|
27539
28447
|
if (!binding.ok) {
|
|
27540
|
-
await
|
|
28448
|
+
await closeLoopIterator(binding.result);
|
|
27541
28449
|
return binding.result;
|
|
27542
28450
|
}
|
|
27543
28451
|
const iterationContext = createLoopIterationContext(phaseContext("body"), scope);
|
|
27544
28452
|
emitLoopIterationBreakpoint(node, iterationContext);
|
|
27545
|
-
const result = await evaluateNode(node.body, iterationContext);
|
|
28453
|
+
const result = await evaluateResourceScope(scope, context.budget, { ...createCoercionContext(iterationContext), ...resourceSuspension(iterationContext, node), onSuspend: iterationContext.onSuspend, signal: iterationContext.signal }, () => evaluateNode(node.body, iterationContext));
|
|
27546
28454
|
if (isMatchingBreak(result, loopLabels(node))) {
|
|
27547
28455
|
context.activeLoopIterations.delete(nodeId);
|
|
27548
|
-
await
|
|
28456
|
+
await closeLoopIterator(normalEmptyResult());
|
|
27549
28457
|
return normalEmptyResult();
|
|
27550
28458
|
}
|
|
27551
28459
|
if (isMatchingContinue(result, loopLabels(node))) {
|
|
@@ -27554,7 +28462,7 @@ async function evaluateForOfIterator(node, value, context, restoredEntry) {
|
|
|
27554
28462
|
}
|
|
27555
28463
|
if (result.kind !== "normal") {
|
|
27556
28464
|
context.activeLoopIterations.delete(nodeId);
|
|
27557
|
-
await
|
|
28465
|
+
await closeLoopIterator(result);
|
|
27558
28466
|
return result;
|
|
27559
28467
|
}
|
|
27560
28468
|
index += 1;
|
|
@@ -27692,55 +28600,57 @@ async function evaluateForStatement(node, context) {
|
|
|
27692
28600
|
])
|
|
27693
28601
|
}
|
|
27694
28602
|
});
|
|
27695
|
-
|
|
27696
|
-
|
|
27697
|
-
|
|
27698
|
-
|
|
27699
|
-
|
|
27700
|
-
}
|
|
27701
|
-
while (true) {
|
|
27702
|
-
context.budget.visitNode();
|
|
27703
|
-
context.stats.nodeVisits += 1;
|
|
27704
|
-
if (node.test !== void 0 && resumePhase !== "body" && resumePhase !== "update") {
|
|
27705
|
-
const test = await evaluateNode(node.test, phaseContext("test", loopScope));
|
|
27706
|
-
if (test.kind !== "normal") {
|
|
27707
|
-
return test;
|
|
27708
|
-
}
|
|
27709
|
-
if (!isTruthy(test.value)) {
|
|
27710
|
-
return {
|
|
27711
|
-
kind: "normal",
|
|
27712
|
-
hasValue: false,
|
|
27713
|
-
value: void 0
|
|
27714
|
-
};
|
|
28603
|
+
return evaluateResourceScope(loopScope, context.budget, { ...createCoercionContext(loopContext), ...resourceSuspension(phaseContext("dispose", loopScope), node), onSuspend: loopContext.onSuspend, signal: loopContext.signal }, async () => {
|
|
28604
|
+
if (node.init !== void 0 && (resumePhase === void 0 || resumePhase === "init")) {
|
|
28605
|
+
const init = await evaluateNode(node.init, phaseContext("init", loopScope));
|
|
28606
|
+
if (init.kind !== "normal") {
|
|
28607
|
+
return init;
|
|
27715
28608
|
}
|
|
27716
28609
|
}
|
|
27717
|
-
|
|
27718
|
-
|
|
27719
|
-
|
|
27720
|
-
|
|
27721
|
-
|
|
27722
|
-
|
|
27723
|
-
|
|
27724
|
-
|
|
27725
|
-
|
|
27726
|
-
|
|
27727
|
-
|
|
28610
|
+
while (true) {
|
|
28611
|
+
context.budget.visitNode();
|
|
28612
|
+
context.stats.nodeVisits += 1;
|
|
28613
|
+
if (node.test !== void 0 && resumePhase !== "body" && resumePhase !== "update") {
|
|
28614
|
+
const test = await evaluateNode(node.test, phaseContext("test", loopScope));
|
|
28615
|
+
if (test.kind !== "normal") {
|
|
28616
|
+
return test;
|
|
28617
|
+
}
|
|
28618
|
+
if (!isTruthy(test.value)) {
|
|
28619
|
+
return {
|
|
28620
|
+
kind: "normal",
|
|
28621
|
+
hasValue: false,
|
|
28622
|
+
value: void 0
|
|
28623
|
+
};
|
|
28624
|
+
}
|
|
27728
28625
|
}
|
|
27729
|
-
|
|
27730
|
-
|
|
28626
|
+
const iterationScope = resumePhase === "body" || resumePhase === "update" ? restored.activeScope : loopBindingNames.length === 0 ? loopScope : loopScope.iterationChild(loopBindingNames);
|
|
28627
|
+
if (resumePhase !== "update") {
|
|
28628
|
+
const iterationContext = createLoopIterationContext(phaseContext("body", iterationScope), iterationScope);
|
|
28629
|
+
emitLoopIterationBreakpoint(node, iterationContext);
|
|
28630
|
+
const result = await evaluateNode(node.body, iterationContext);
|
|
28631
|
+
if (isMatchingBreak(result, loopLabels(node))) {
|
|
28632
|
+
return {
|
|
28633
|
+
kind: "normal",
|
|
28634
|
+
hasValue: false,
|
|
28635
|
+
value: void 0
|
|
28636
|
+
};
|
|
28637
|
+
}
|
|
28638
|
+
if (result.kind !== "normal" && !isMatchingContinue(result, loopLabels(node))) {
|
|
28639
|
+
return result;
|
|
28640
|
+
}
|
|
27731
28641
|
}
|
|
27732
|
-
|
|
27733
|
-
|
|
27734
|
-
|
|
27735
|
-
|
|
27736
|
-
|
|
27737
|
-
|
|
27738
|
-
|
|
28642
|
+
const updateScope = resumePhase === "update" ? restored.activeScope : loopBindingNames.length === 0 ? iterationScope : iterationScope.iterationChild(loopBindingNames);
|
|
28643
|
+
const updateContext = phaseContext("update", updateScope);
|
|
28644
|
+
if (node.update !== void 0) {
|
|
28645
|
+
const update = await evaluateNode(node.update, updateContext);
|
|
28646
|
+
if (update.kind !== "normal") {
|
|
28647
|
+
return update;
|
|
28648
|
+
}
|
|
27739
28649
|
}
|
|
28650
|
+
loopScope.copyInitializedBindingsFrom(updateScope, loopBindingNames);
|
|
28651
|
+
resumePhase = void 0;
|
|
27740
28652
|
}
|
|
27741
|
-
|
|
27742
|
-
resumePhase = void 0;
|
|
27743
|
-
}
|
|
28653
|
+
});
|
|
27744
28654
|
}
|
|
27745
28655
|
async function evaluateWhileStatement(node, context) {
|
|
27746
28656
|
let resumeBody = context.generatorResume !== void 0 && context.generatorResume.completed !== true && containsResumeTarget(node.body, /* @__PURE__ */ new Set([context.generatorResume.yieldNodeId]));
|
|
@@ -27865,6 +28775,7 @@ async function bindIterationVariable(left, value, scope, context) {
|
|
|
27865
28775
|
[left.nodeId, { kind: "declaration", index: 0 }]
|
|
27866
28776
|
]) };
|
|
27867
28777
|
}
|
|
28778
|
+
if (left.disposal !== void 0) await registerScopeResource(scope, value, left.disposal, context.budget, createCoercionContext({ ...context, scope }));
|
|
27868
28779
|
return bindPattern(declarator.id, value, { kind: left.kind }, scope, createPatternContext(context, scope));
|
|
27869
28780
|
}
|
|
27870
28781
|
async function evaluateExpressionStatement(node, context) {
|
|
@@ -27896,14 +28807,14 @@ async function evaluateReturnStatement(node, context) {
|
|
|
27896
28807
|
value: void 0
|
|
27897
28808
|
};
|
|
27898
28809
|
}
|
|
27899
|
-
const argument = await evaluateNode(node.argument, context);
|
|
28810
|
+
const argument = context.asyncGeneratorFrame !== void 0 && context.generatorResume?.completed !== true && context.generatorResume?.yieldNodeId === node.nodeId ? { kind: "normal", hasValue: true, value: void 0 } : await evaluateNode(node.argument, context);
|
|
27900
28811
|
if (argument.kind !== "normal") {
|
|
27901
28812
|
return argument;
|
|
27902
28813
|
}
|
|
27903
28814
|
return {
|
|
27904
28815
|
kind: "return",
|
|
27905
28816
|
hasValue: argument.hasValue,
|
|
27906
|
-
value: context.asyncGenerator ? await suspendJob(awaitSandboxValue(argument.value, context.signal, context.budget, createCoercionContext(context))) : argument.value
|
|
28817
|
+
value: context.asyncGeneratorFrame !== void 0 ? await suspendAsyncFunctionValue(argument.value, node, context, void 0, createCoercionContext(context), "return") : context.asyncGenerator ? await suspendJob(awaitSandboxValue(argument.value, context.signal, context.budget, createCoercionContext(context))) : argument.value
|
|
27907
28818
|
};
|
|
27908
28819
|
}
|
|
27909
28820
|
async function evaluateYieldExpression(node, context) {
|
|
@@ -27927,7 +28838,25 @@ async function evaluateYieldExpression(node, context) {
|
|
|
27927
28838
|
return generatorCompletionResult(completion);
|
|
27928
28839
|
}
|
|
27929
28840
|
async function yieldGeneratorValue(value, node, context) {
|
|
27930
|
-
|
|
28841
|
+
const frame = context.asyncGeneratorFrame;
|
|
28842
|
+
const origin = frame === void 0 ? void 0 : getGeneratorOrigin(frame);
|
|
28843
|
+
const resuming = context.generatorResume?.completed !== true && context.generatorResume?.yieldNodeId === node.nodeId;
|
|
28844
|
+
if (frame !== void 0 && resuming && origin?.awaitPhase === "resume-return") {
|
|
28845
|
+
try {
|
|
28846
|
+
return { type: "return", value: await suspendAsyncFunctionValue(void 0, node, context, void 0, createCoercionContext(context), "resume-return") };
|
|
28847
|
+
} catch (error) {
|
|
28848
|
+
return { type: "throw", value: error };
|
|
28849
|
+
}
|
|
28850
|
+
}
|
|
28851
|
+
if (frame !== void 0 && !node.delegate && (!resuming || origin?.awaitPhase === "yield"))
|
|
28852
|
+
value = await suspendAsyncFunctionValue(value, node, context, void 0, createCoercionContext(context), "yield");
|
|
28853
|
+
else if (frame === void 0 && context.asyncGenerator && !node.delegate)
|
|
28854
|
+
value = await suspendJob(awaitSandboxValue(value, context.signal, context.budget, createCoercionContext(context)));
|
|
28855
|
+
if (frame !== void 0) {
|
|
28856
|
+
const driver = asyncGeneratorDrivers.get(frame);
|
|
28857
|
+
if (driver === void 0) throw new TypeError("Missing async generator yield owner.");
|
|
28858
|
+
driver.suspension = "yield";
|
|
28859
|
+
}
|
|
27931
28860
|
context.captureGeneratorScope?.(context.scope, context.generatorBlockScopes, context.finallyCompletions, context.generatorExpressionStates);
|
|
27932
28861
|
const completionPromise = context.generatorYield(allocateProducedSandboxValue(value, context.budget), node.nodeId);
|
|
27933
28862
|
emitResumeBreakpoint(context, {
|
|
@@ -27935,10 +28864,10 @@ async function yieldGeneratorValue(value, node, context) {
|
|
|
27935
28864
|
nodeId: node.nodeId,
|
|
27936
28865
|
span: node.span
|
|
27937
28866
|
});
|
|
27938
|
-
const completion = await (context.asyncGenerator ? suspendJob(completionPromise) : completionPromise);
|
|
28867
|
+
const completion = await (context.asyncGenerator && frame === void 0 ? suspendJob(completionPromise) : completionPromise);
|
|
27939
28868
|
if (context.asyncGenerator && completion.type === "return") {
|
|
27940
28869
|
try {
|
|
27941
|
-
return { type: "return", value: await suspendJob(awaitSandboxValue(completion.value, context.signal, context.budget, createCoercionContext(context))) };
|
|
28870
|
+
return { type: "return", value: frame === void 0 ? await suspendJob(awaitSandboxValue(completion.value, context.signal, context.budget, createCoercionContext(context))) : await suspendAsyncFunctionValue(completion.value, node, context, void 0, createCoercionContext(context), "resume-return") };
|
|
27942
28871
|
} catch (error) {
|
|
27943
28872
|
return { type: "throw", value: error };
|
|
27944
28873
|
}
|
|
@@ -27968,41 +28897,69 @@ async function evaluateYieldDelegate(node, context) {
|
|
|
27968
28897
|
async: context.asyncGenerator === true,
|
|
27969
28898
|
value: argument.value,
|
|
27970
28899
|
current: saved?.current,
|
|
27971
|
-
iterator
|
|
28900
|
+
iterator,
|
|
28901
|
+
...saved?.phase === void 0 ? {} : { phase: saved.phase, awaitState: saved.awaitState, completion: saved.completion }
|
|
27972
28902
|
};
|
|
27973
28903
|
if (node.nodeId !== void 0) context = {
|
|
27974
28904
|
...context,
|
|
27975
28905
|
generatorExpressionStates: new Map([...context.generatorExpressionStates ?? [], [node.nodeId, state]])
|
|
27976
28906
|
};
|
|
28907
|
+
if (context.asyncGeneratorFrame !== void 0 && iterator.resumeAwait !== void 0)
|
|
28908
|
+
iterator.awaitValue = (value, awaitState) => {
|
|
28909
|
+
state.awaitState = awaitState;
|
|
28910
|
+
return suspendAsyncFunctionValue(value, node, context, void 0, createCoercionContext(context));
|
|
28911
|
+
};
|
|
27977
28912
|
const releaseIterator = retainValues(context.budget, () => [
|
|
27978
28913
|
argument.value,
|
|
27979
28914
|
iterator.retainedValue,
|
|
27980
28915
|
state.current
|
|
27981
28916
|
]);
|
|
27982
28917
|
try {
|
|
27983
|
-
let completion = {
|
|
28918
|
+
let completion = saved?.completion ?? {
|
|
27984
28919
|
type: "normal",
|
|
27985
28920
|
value: void 0
|
|
27986
28921
|
};
|
|
27987
28922
|
const replay = saved === void 0 ? context.generatorResume?.sent ?? [] : [];
|
|
27988
28923
|
let replayIndex = 0;
|
|
27989
|
-
|
|
28924
|
+
let resumeOperation = saved?.phase !== void 0;
|
|
28925
|
+
if (saved !== void 0 && !resumeOperation) {
|
|
27990
28926
|
completion = await yieldGeneratorValue(saved.current, node, context);
|
|
27991
28927
|
if (context.generatorResume !== void 0) context.generatorResume.completed = true;
|
|
27992
28928
|
context.generatorResume = void 0;
|
|
27993
28929
|
}
|
|
27994
28930
|
while (true) {
|
|
27995
28931
|
const method = completion.type === "normal" ? "next" : completion.type;
|
|
27996
|
-
|
|
27997
|
-
if (
|
|
27998
|
-
|
|
27999
|
-
|
|
28000
|
-
throw new TypeError("
|
|
28932
|
+
let result;
|
|
28933
|
+
if (resumeOperation) {
|
|
28934
|
+
resumeOperation = false;
|
|
28935
|
+
if (iterator.resumeAwait === void 0 || iterator.awaitValue === void 0 || saved?.awaitState === void 0)
|
|
28936
|
+
throw new TypeError("Missing delegated iterator await continuation.");
|
|
28937
|
+
result = await iterator.resumeAwait(saved.awaitState, () => iterator.awaitValue(void 0, saved.awaitState));
|
|
28938
|
+
if (saved.phase === "close") throw new TypeError("Delegated iterator does not provide a throw method.");
|
|
28939
|
+
context.generatorResume = void 0;
|
|
28940
|
+
} else {
|
|
28941
|
+
const iteratorMethod = iterator.getOperation === void 0 ? iterator[method] : await iterator.getOperation(method);
|
|
28942
|
+
if (iteratorMethod === void 0) {
|
|
28943
|
+
if (completion.type === "throw") {
|
|
28944
|
+
if (iterator.awaitValue !== void 0) {
|
|
28945
|
+
state.phase = "close";
|
|
28946
|
+
state.completion = completion;
|
|
28947
|
+
}
|
|
28948
|
+
await closeIterator(iterator, false, context.asyncGeneratorFrame === void 0 ? suspendJob : async (pending) => await suspendAsyncFunctionValue(createSandboxPromise(pending), node, context, void 0, createCoercionContext(context)));
|
|
28949
|
+
throw new TypeError("Delegated iterator does not provide a throw method.");
|
|
28950
|
+
}
|
|
28951
|
+
return generatorCompletionResult(completion);
|
|
28001
28952
|
}
|
|
28002
|
-
|
|
28953
|
+
if (iterator.awaitValue !== void 0) {
|
|
28954
|
+
state.phase = "await";
|
|
28955
|
+
state.completion = completion;
|
|
28956
|
+
}
|
|
28957
|
+
const pendingResult = Promise.resolve(iteratorMethod(completion.value));
|
|
28958
|
+
result = context.asyncGeneratorFrame !== void 0 && iterator.awaitValue === void 0 ? await suspendAsyncFunctionValue(createSandboxPromise(pendingResult), node, context, void 0, createCoercionContext(context)) : await (context.asyncGenerator && iterator.awaitValue === void 0 ? suspendJob(pendingResult) : pendingResult);
|
|
28003
28959
|
}
|
|
28004
|
-
|
|
28005
|
-
|
|
28960
|
+
delete state.phase;
|
|
28961
|
+
delete state.awaitState;
|
|
28962
|
+
delete state.completion;
|
|
28006
28963
|
if (typeof result !== "object" && typeof result !== "function" || result === null) {
|
|
28007
28964
|
throw new TypeError("Iterator result must be an object.");
|
|
28008
28965
|
}
|
|
@@ -28028,6 +28985,7 @@ async function evaluateYieldDelegate(node, context) {
|
|
|
28028
28985
|
context.generatorResume = void 0;
|
|
28029
28986
|
}
|
|
28030
28987
|
} finally {
|
|
28988
|
+
delete iterator.awaitValue;
|
|
28031
28989
|
releaseIterator();
|
|
28032
28990
|
}
|
|
28033
28991
|
}
|
|
@@ -30287,21 +31245,23 @@ async function evaluateBlockCompletion(node, context, evaluateNode2) {
|
|
|
30287
31245
|
}
|
|
30288
31246
|
};
|
|
30289
31247
|
if (restoredScope === void 0) predeclareBlockBindings2(node, blockContext.scope);
|
|
30290
|
-
|
|
30291
|
-
|
|
30292
|
-
|
|
30293
|
-
|
|
30294
|
-
|
|
30295
|
-
|
|
30296
|
-
|
|
30297
|
-
|
|
30298
|
-
|
|
30299
|
-
|
|
30300
|
-
|
|
30301
|
-
|
|
31248
|
+
return evaluateResourceScope(scope, context.budget, { ...resourceSuspension(blockContext, node), stack: context.callStack, thisValue: void 0, getProperty: context.getProperty, onSuspend: context.onSuspend, signal: context.signal }, async () => {
|
|
31249
|
+
let result = {
|
|
31250
|
+
kind: "normal",
|
|
31251
|
+
hasValue: false,
|
|
31252
|
+
value: void 0
|
|
31253
|
+
};
|
|
31254
|
+
const resume = context.generatorResume;
|
|
31255
|
+
const resumeIndex = resume === void 0 || resume.completed === true ? -1 : node.body.findIndex((statement) => containsResumeTarget(statement, /* @__PURE__ */ new Set([resume.yieldNodeId])));
|
|
31256
|
+
for (let index = Math.max(0, resumeIndex); index < node.body.length; index++) {
|
|
31257
|
+
const statement = node.body[index];
|
|
31258
|
+
result = await evaluateNode2(statement, blockContext);
|
|
31259
|
+
if (result.kind !== "normal") {
|
|
31260
|
+
return result;
|
|
31261
|
+
}
|
|
30302
31262
|
}
|
|
30303
|
-
|
|
30304
|
-
|
|
31263
|
+
return result;
|
|
31264
|
+
});
|
|
30305
31265
|
}
|
|
30306
31266
|
function predeclareBlockBindings2(node, scope) {
|
|
30307
31267
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -30524,6 +31484,12 @@ async function advanceAsyncCleanup(cleanup, budget, context) {
|
|
|
30524
31484
|
try {
|
|
30525
31485
|
while ((current = cleanup.resources.pop()) !== void 0) {
|
|
30526
31486
|
budget.visitNode();
|
|
31487
|
+
if (current.synchronous && cleanup.needsAwait && !cleanup.hasAwaited) {
|
|
31488
|
+
cleanup.resources.push(current);
|
|
31489
|
+
cleanup.needsAwait = false;
|
|
31490
|
+
await wait(void 0, false);
|
|
31491
|
+
return;
|
|
31492
|
+
}
|
|
30527
31493
|
if (current.method === void 0) {
|
|
30528
31494
|
cleanup.needsAwait = true;
|
|
30529
31495
|
continue;
|
|
@@ -30534,13 +31500,14 @@ async function advanceAsyncCleanup(cleanup, budget, context) {
|
|
|
30534
31500
|
} catch (error) {
|
|
30535
31501
|
if (isFatalSandboxError(error)) throw error;
|
|
30536
31502
|
const value = createThrowCompletion(error, budget, context?.stack ?? []).value;
|
|
30537
|
-
if (current.syncFallback) {
|
|
31503
|
+
if (current.syncFallback && !current.synchronous) {
|
|
30538
31504
|
await wait(value, true);
|
|
30539
31505
|
return;
|
|
30540
31506
|
}
|
|
30541
31507
|
recordCleanupFailure(cleanup, value, budget, context);
|
|
30542
31508
|
continue;
|
|
30543
31509
|
}
|
|
31510
|
+
if (current.synchronous) continue;
|
|
30544
31511
|
await wait(current.syncFallback ? void 0 : result, false);
|
|
30545
31512
|
return;
|
|
30546
31513
|
}
|
|
@@ -31164,6 +32131,7 @@ function measureSandboxData(values, options = {}) {
|
|
|
31164
32131
|
return;
|
|
31165
32132
|
}
|
|
31166
32133
|
if (isSandboxGenerator(value)) {
|
|
32134
|
+
visit(asyncGeneratorDrivers.get(value), depth + 1);
|
|
31167
32135
|
const descriptors2 = Object.getOwnPropertyDescriptors(getGeneratorProperties(value));
|
|
31168
32136
|
for (const key of Reflect.ownKeys(descriptors2)) {
|
|
31169
32137
|
const descriptor = descriptors2[key];
|
|
@@ -31178,6 +32146,7 @@ function measureSandboxData(values, options = {}) {
|
|
|
31178
32146
|
return;
|
|
31179
32147
|
}
|
|
31180
32148
|
if (isSandboxPromise(value)) {
|
|
32149
|
+
visit(asyncGeneratorRequestOwners.get(value), depth + 1);
|
|
31181
32150
|
const settlement = promiseStates.get(value);
|
|
31182
32151
|
if (settlement !== void 0 && settlement.status !== "pending") visit(settlement.value, depth + 1);
|
|
31183
32152
|
const continuation = promiseContinuations.get(value);
|
|
@@ -46216,4 +47185,4 @@ export {
|
|
|
46216
47185
|
FileSnapshotBackend,
|
|
46217
47186
|
run
|
|
46218
47187
|
};
|
|
46219
|
-
//# sourceMappingURL=chunk-
|
|
47188
|
+
//# sourceMappingURL=chunk-KHHM7HUO.js.map
|