@poe-platform/safe-js 0.1.426 → 0.1.427
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-MYKH5PM4.js → chunk-74YCEXKO.js} +2 -2
- package/dist/safe-js/chunks/{chunk-V3XJABDF.js → chunk-GZSWJFFP.js} +1322 -372
- package/dist/safe-js/chunks/chunk-GZSWJFFP.js.map +7 -0
- package/dist/safe-js/cli.js +2 -2
- package/dist/safe-js/core.js +1 -1
- package/dist/safe-js/index.js +2 -2
- package/dist/safe-js/interp/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 +3 -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-74YCEXKO.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
|
}
|
|
@@ -9336,6 +9374,485 @@ function restoreRegexProperties(value, data, decode) {
|
|
|
9336
9374
|
// packages/safe-js/src/snapshot/validation.ts
|
|
9337
9375
|
import { types as types10 } from "node:util";
|
|
9338
9376
|
|
|
9377
|
+
// packages/safe-js/src/interp/promise-continuations.ts
|
|
9378
|
+
var thenableContinuations = /* @__PURE__ */ new WeakMap();
|
|
9379
|
+
var thenableStates = /* @__PURE__ */ new WeakMap();
|
|
9380
|
+
var thenableResolvers = /* @__PURE__ */ new WeakMap();
|
|
9381
|
+
var promiseCapabilityExecutors = /* @__PURE__ */ new WeakMap();
|
|
9382
|
+
var promiseAggregateHandlers = /* @__PURE__ */ new WeakMap();
|
|
9383
|
+
var promiseAggregateStates = /* @__PURE__ */ new WeakMap();
|
|
9384
|
+
var promiseAggregateEntries = /* @__PURE__ */ new WeakMap();
|
|
9385
|
+
var promiseAdoptions = /* @__PURE__ */ new WeakMap();
|
|
9386
|
+
var promiseAdoptionBridges = /* @__PURE__ */ new WeakMap();
|
|
9387
|
+
var promiseAdoptionResolvers = /* @__PURE__ */ new WeakMap();
|
|
9388
|
+
var promiseContinuations = /* @__PURE__ */ new WeakMap();
|
|
9389
|
+
var promiseReactionResults = /* @__PURE__ */ new WeakMap();
|
|
9390
|
+
var promiseProducers = /* @__PURE__ */ new WeakMap();
|
|
9391
|
+
function linkPromiseAggregateProducer(producer, aggregate) {
|
|
9392
|
+
const continuation = promiseContinuations.get(producer);
|
|
9393
|
+
if (continuation?.kind !== "reaction") return;
|
|
9394
|
+
continuation.aggregate = aggregate;
|
|
9395
|
+
let producers = promiseProducers.get(aggregate);
|
|
9396
|
+
if (producers === void 0) promiseProducers.set(aggregate, producers = /* @__PURE__ */ new Set());
|
|
9397
|
+
producers.add(producer);
|
|
9398
|
+
}
|
|
9399
|
+
function trackPromiseContinuation(promise, continuation) {
|
|
9400
|
+
promiseContinuations.set(promise, continuation);
|
|
9401
|
+
if (continuation.kind === "reaction") {
|
|
9402
|
+
let results = promiseReactionResults.get(continuation.source);
|
|
9403
|
+
if (results === void 0) promiseReactionResults.set(continuation.source, results = /* @__PURE__ */ new Set());
|
|
9404
|
+
results.add(promise);
|
|
9405
|
+
if (continuation.capability !== void 0) {
|
|
9406
|
+
let producers = promiseProducers.get(continuation.capability.promise);
|
|
9407
|
+
if (producers === void 0) promiseProducers.set(continuation.capability.promise, producers = /* @__PURE__ */ new Set());
|
|
9408
|
+
producers.add(promise);
|
|
9409
|
+
}
|
|
9410
|
+
}
|
|
9411
|
+
const release = () => {
|
|
9412
|
+
promiseContinuations.delete(promise);
|
|
9413
|
+
if (continuation.kind === "capability") delete continuation.resolution;
|
|
9414
|
+
else {
|
|
9415
|
+
const results = promiseReactionResults.get(continuation.source);
|
|
9416
|
+
results?.delete(promise);
|
|
9417
|
+
if (results?.size === 0) promiseReactionResults.delete(continuation.source);
|
|
9418
|
+
if (continuation.capability !== void 0) {
|
|
9419
|
+
const producers = promiseProducers.get(continuation.capability.promise);
|
|
9420
|
+
producers?.delete(promise);
|
|
9421
|
+
if (producers?.size === 0) promiseProducers.delete(continuation.capability.promise);
|
|
9422
|
+
}
|
|
9423
|
+
if (continuation.aggregate !== void 0) {
|
|
9424
|
+
const producers = promiseProducers.get(continuation.aggregate);
|
|
9425
|
+
producers?.delete(promise);
|
|
9426
|
+
if (producers?.size === 0) promiseProducers.delete(continuation.aggregate);
|
|
9427
|
+
}
|
|
9428
|
+
}
|
|
9429
|
+
};
|
|
9430
|
+
promise.promise.then(release, release);
|
|
9431
|
+
}
|
|
9432
|
+
|
|
9433
|
+
// packages/safe-js/src/interp/jobs.ts
|
|
9434
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
9435
|
+
var activeJob = new AsyncLocalStorage3();
|
|
9436
|
+
var SandboxJobQueue = class {
|
|
9437
|
+
running = false;
|
|
9438
|
+
pending = [];
|
|
9439
|
+
ready = [];
|
|
9440
|
+
idle = [];
|
|
9441
|
+
generation = 0;
|
|
9442
|
+
bind(task) {
|
|
9443
|
+
return activeJob.run({ queue: this, ownsExecution: false }, task);
|
|
9444
|
+
}
|
|
9445
|
+
acquire(job) {
|
|
9446
|
+
return new Promise((resolve) => {
|
|
9447
|
+
this.pending.push(() => {
|
|
9448
|
+
this.running = true;
|
|
9449
|
+
this.generation += 1;
|
|
9450
|
+
job.ownsExecution = true;
|
|
9451
|
+
resolve();
|
|
9452
|
+
});
|
|
9453
|
+
this.advance();
|
|
9454
|
+
});
|
|
9455
|
+
}
|
|
9456
|
+
release(job) {
|
|
9457
|
+
job.prefixParent = void 0;
|
|
9458
|
+
if (!job.ownsExecution) return;
|
|
9459
|
+
job.ownsExecution = false;
|
|
9460
|
+
this.running = false;
|
|
9461
|
+
this.advance();
|
|
9462
|
+
}
|
|
9463
|
+
async run(task) {
|
|
9464
|
+
const job = { queue: this, ownsExecution: false };
|
|
9465
|
+
await this.acquire(job);
|
|
9466
|
+
return activeJob.run(job, async () => {
|
|
9467
|
+
try {
|
|
9468
|
+
return await task();
|
|
9469
|
+
} finally {
|
|
9470
|
+
this.release(job);
|
|
9471
|
+
}
|
|
9472
|
+
});
|
|
9473
|
+
}
|
|
9474
|
+
async drain() {
|
|
9475
|
+
let idleTurns = 0;
|
|
9476
|
+
while (idleTurns < 20) {
|
|
9477
|
+
const generation = this.generation;
|
|
9478
|
+
if (this.running) await new Promise((resolve) => this.idle.push(resolve));
|
|
9479
|
+
await Promise.resolve();
|
|
9480
|
+
idleTurns = generation === this.generation ? idleTurns + 1 : 0;
|
|
9481
|
+
}
|
|
9482
|
+
}
|
|
9483
|
+
advance() {
|
|
9484
|
+
if (this.running) return;
|
|
9485
|
+
if (this.ready.length === 0 && this.pending.length > 0) {
|
|
9486
|
+
const empty = this.ready;
|
|
9487
|
+
this.ready = this.pending.reverse();
|
|
9488
|
+
this.pending = empty;
|
|
9489
|
+
}
|
|
9490
|
+
const next = this.ready.pop();
|
|
9491
|
+
if (next !== void 0) {
|
|
9492
|
+
next();
|
|
9493
|
+
} else {
|
|
9494
|
+
for (const resolve of this.idle.splice(0)) resolve();
|
|
9495
|
+
}
|
|
9496
|
+
}
|
|
9497
|
+
};
|
|
9498
|
+
function runPromiseJob(task) {
|
|
9499
|
+
const job = activeJob.getStore();
|
|
9500
|
+
return job === void 0 ? Promise.resolve().then(task) : job.queue.run(task);
|
|
9501
|
+
}
|
|
9502
|
+
function createResumableJobContext() {
|
|
9503
|
+
let frame;
|
|
9504
|
+
return { run: (task) => {
|
|
9505
|
+
const parent = activeJob.getStore();
|
|
9506
|
+
if (parent === void 0) return task();
|
|
9507
|
+
frame ??= { queue: parent.queue, ownsExecution: false };
|
|
9508
|
+
for (let ancestor = parent; ancestor !== void 0; ancestor = ancestor.prefixParent) {
|
|
9509
|
+
if (ancestor === frame) return activeJob.run(frame, task);
|
|
9510
|
+
}
|
|
9511
|
+
frame.queue = parent.queue;
|
|
9512
|
+
frame.prefixParent = parent;
|
|
9513
|
+
return activeJob.run(frame, task);
|
|
9514
|
+
}, release: () => {
|
|
9515
|
+
if (frame !== void 0) frame.queue.release(frame);
|
|
9516
|
+
} };
|
|
9517
|
+
}
|
|
9518
|
+
function runAsyncPrefix(task) {
|
|
9519
|
+
const parent = activeJob.getStore();
|
|
9520
|
+
if (parent === void 0) return task();
|
|
9521
|
+
let owner = parent;
|
|
9522
|
+
while (owner !== void 0 && !owner.ownsExecution) owner = owner.prefixParent;
|
|
9523
|
+
if (owner === void 0) return parent.queue.run(task);
|
|
9524
|
+
const job = { queue: parent.queue, ownsExecution: false, prefixParent: parent };
|
|
9525
|
+
return activeJob.run(job, async () => {
|
|
9526
|
+
try {
|
|
9527
|
+
return await task();
|
|
9528
|
+
} finally {
|
|
9529
|
+
job.queue.release(job);
|
|
9530
|
+
}
|
|
9531
|
+
});
|
|
9532
|
+
}
|
|
9533
|
+
async function suspendJob(pending) {
|
|
9534
|
+
const job = activeJob.getStore();
|
|
9535
|
+
if (job === void 0) return pending;
|
|
9536
|
+
job.queue.release(job);
|
|
9537
|
+
try {
|
|
9538
|
+
return await pending;
|
|
9539
|
+
} finally {
|
|
9540
|
+
await job.queue.acquire(job);
|
|
9541
|
+
}
|
|
9542
|
+
}
|
|
9543
|
+
|
|
9544
|
+
// packages/safe-js/src/interp/async-function-driver.ts
|
|
9545
|
+
var asyncFunctionDrivers = /* @__PURE__ */ new WeakMap();
|
|
9546
|
+
var asyncFunctionHandlers = /* @__PURE__ */ new WeakMap();
|
|
9547
|
+
var asyncFunctionSignals = /* @__PURE__ */ new WeakMap();
|
|
9548
|
+
var abortReleases = /* @__PURE__ */ new WeakMap();
|
|
9549
|
+
function bindAsyncFunctionSignal(driver, signal, budget, context) {
|
|
9550
|
+
abortReleases.get(driver)?.();
|
|
9551
|
+
if (signal === void 0) asyncFunctionSignals.delete(driver);
|
|
9552
|
+
else asyncFunctionSignals.set(driver, signal);
|
|
9553
|
+
if (driver.phase !== "waiting") return;
|
|
9554
|
+
const generation = driver.generation;
|
|
9555
|
+
let notify;
|
|
9556
|
+
const aborted = new Promise((resolve) => {
|
|
9557
|
+
notify = resolve;
|
|
9558
|
+
});
|
|
9559
|
+
let active = true;
|
|
9560
|
+
const abort = () => notify(signal?.reason ?? new DOMException("The operation was aborted.", "AbortError"));
|
|
9561
|
+
const release = () => {
|
|
9562
|
+
active = false;
|
|
9563
|
+
signal?.removeEventListener("abort", abort);
|
|
9564
|
+
detachFatal?.();
|
|
9565
|
+
if (abortReleases.get(driver) === release) abortReleases.delete(driver);
|
|
9566
|
+
};
|
|
9567
|
+
abortReleases.set(driver, release);
|
|
9568
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
9569
|
+
const detachFatal = onFatalPromiseRejection(notify);
|
|
9570
|
+
void aborted.then((reason) => runPromiseJob(async () => {
|
|
9571
|
+
if (!active || driver.phase !== "waiting" || driver.generation !== generation) return;
|
|
9572
|
+
if (isFatalSandboxError(reason)) {
|
|
9573
|
+
release();
|
|
9574
|
+
driver.phase = "running";
|
|
9575
|
+
await withFatalPromiseCleanup(async () => {
|
|
9576
|
+
if (driver.generator?.state !== "done") await driver.generator?.channel.throw(reason);
|
|
9577
|
+
});
|
|
9578
|
+
throw reason;
|
|
9579
|
+
}
|
|
9580
|
+
const handler = createAsyncFunctionHandler(driver, "rejected", generation, budget, context);
|
|
9581
|
+
await handler.call([createThrowCompletion(reason, budget, context?.stack ?? []).value], context);
|
|
9582
|
+
})).catch((error) => {
|
|
9583
|
+
release();
|
|
9584
|
+
driver.phase = "done";
|
|
9585
|
+
if (driver.generator !== void 0) driver.generator.state = "done";
|
|
9586
|
+
const reject = pendingPromiseRejectors.get(driver.capability.promise);
|
|
9587
|
+
if (reject === void 0) throw new TypeError("Missing async function rejection capability.");
|
|
9588
|
+
reject(error);
|
|
9589
|
+
});
|
|
9590
|
+
if (signal?.aborted) abort();
|
|
9591
|
+
}
|
|
9592
|
+
function startAsyncFunction(initialize, budget, context, signal) {
|
|
9593
|
+
let completePrefix;
|
|
9594
|
+
let failPrefix;
|
|
9595
|
+
const prefix = new Promise((resolve, reject) => {
|
|
9596
|
+
completePrefix = resolve;
|
|
9597
|
+
failPrefix = reject;
|
|
9598
|
+
});
|
|
9599
|
+
void prefix.catch(() => void 0);
|
|
9600
|
+
const capability = createPendingPromiseCapability(budget, context, prefix);
|
|
9601
|
+
const driver = { capability: { promise: capability.promise, resolve: capability.resolve, reject: capability.reject }, phase: "running", generation: 0 };
|
|
9602
|
+
asyncFunctionDrivers.set(driver, driver);
|
|
9603
|
+
bindAsyncFunctionSignal(driver, signal, budget, context);
|
|
9604
|
+
void runAsyncPrefix(async () => {
|
|
9605
|
+
try {
|
|
9606
|
+
driver.generator = await initialize(completePrefix);
|
|
9607
|
+
await advanceAsyncFunction(driver, "fulfilled", void 0, budget, context);
|
|
9608
|
+
} catch (error) {
|
|
9609
|
+
driver.phase = "done";
|
|
9610
|
+
if (isFatalSandboxError(error)) throw error;
|
|
9611
|
+
await capability.reject.call([createThrowCompletion(error, budget, context?.stack ?? []).value], context);
|
|
9612
|
+
}
|
|
9613
|
+
}).then(completePrefix, (error) => {
|
|
9614
|
+
capability.rejectNative(error);
|
|
9615
|
+
failPrefix(error);
|
|
9616
|
+
});
|
|
9617
|
+
return capability.promise;
|
|
9618
|
+
}
|
|
9619
|
+
function createAsyncFunctionHandler(driver, action, generation, budget, context) {
|
|
9620
|
+
const handler = createSandboxClosure({
|
|
9621
|
+
guest: true,
|
|
9622
|
+
sandbox: true,
|
|
9623
|
+
name: "",
|
|
9624
|
+
length: 1,
|
|
9625
|
+
retainedValues: () => [driver],
|
|
9626
|
+
call: async ([value]) => {
|
|
9627
|
+
if (driver.phase !== "waiting" || driver.generation !== generation) return void 0;
|
|
9628
|
+
abortReleases.get(driver)?.();
|
|
9629
|
+
driver.phase = "running";
|
|
9630
|
+
if (driver.generator?.state === "done") {
|
|
9631
|
+
driver.phase = "done";
|
|
9632
|
+
const settle = (action === "fulfilled" ? pendingPromiseFulfillers : pendingPromiseRejectors).get(driver.capability.promise);
|
|
9633
|
+
if (settle === void 0) throw new TypeError("Missing async function settlement capability.");
|
|
9634
|
+
settle(value);
|
|
9635
|
+
return void 0;
|
|
9636
|
+
}
|
|
9637
|
+
await advanceAsyncFunction(driver, action, value, budget, context);
|
|
9638
|
+
return void 0;
|
|
9639
|
+
}
|
|
9640
|
+
});
|
|
9641
|
+
asyncFunctionHandlers.set(handler, { driver, action, generation });
|
|
9642
|
+
return handler;
|
|
9643
|
+
}
|
|
9644
|
+
async function advanceAsyncFunction(driver, action, value, budget, context) {
|
|
9645
|
+
const release = retainValues(budget, () => [driver]);
|
|
9646
|
+
try {
|
|
9647
|
+
const generator = driver.generator;
|
|
9648
|
+
if (generator === void 0) throw new TypeError("Missing async function frame.");
|
|
9649
|
+
generator.state = "running";
|
|
9650
|
+
const result = await generator.channel[action === "fulfilled" ? "next" : "throw"](value);
|
|
9651
|
+
if (result.done) {
|
|
9652
|
+
generator.state = "done";
|
|
9653
|
+
if (!requiresPromiseResolution(result.value, budget)) {
|
|
9654
|
+
driver.phase = "done";
|
|
9655
|
+
await driver.capability.resolve.call([result.value], context);
|
|
9656
|
+
return;
|
|
9657
|
+
}
|
|
9658
|
+
} else {
|
|
9659
|
+
generator.state = "suspended";
|
|
9660
|
+
}
|
|
9661
|
+
const prepared = result.value;
|
|
9662
|
+
let awaited;
|
|
9663
|
+
if (!result.done && isSandboxPromise(prepared)) awaited = prepared;
|
|
9664
|
+
else {
|
|
9665
|
+
const wrapper = promiseReplayContext.exit(() => createPendingPromiseCapability(budget, context));
|
|
9666
|
+
await wrapper.resolve.call([prepared], context);
|
|
9667
|
+
awaited = wrapper.promise;
|
|
9668
|
+
}
|
|
9669
|
+
driver.phase = "waiting";
|
|
9670
|
+
driver.generation++;
|
|
9671
|
+
bindAsyncFunctionSignal(driver, asyncFunctionSignals.get(driver), budget, context);
|
|
9672
|
+
const reaction = promiseReplayContext.exit(() => createPendingPromiseCapability(budget, context));
|
|
9673
|
+
attachPendingPromiseReaction(
|
|
9674
|
+
awaited,
|
|
9675
|
+
reaction,
|
|
9676
|
+
createAsyncFunctionHandler(driver, "fulfilled", driver.generation, budget, context),
|
|
9677
|
+
createAsyncFunctionHandler(driver, "rejected", driver.generation, budget, context),
|
|
9678
|
+
budget,
|
|
9679
|
+
context
|
|
9680
|
+
);
|
|
9681
|
+
linkPromiseAggregateProducer(reaction.promise, driver.capability.promise);
|
|
9682
|
+
} catch (error) {
|
|
9683
|
+
abortReleases.get(driver)?.();
|
|
9684
|
+
driver.phase = "done";
|
|
9685
|
+
if (driver.generator !== void 0) driver.generator.state = "done";
|
|
9686
|
+
if (isFatalSandboxError(error)) throw error;
|
|
9687
|
+
await driver.capability.reject.call([createThrowCompletion(error, budget, context?.stack ?? []).value], context);
|
|
9688
|
+
} finally {
|
|
9689
|
+
release();
|
|
9690
|
+
}
|
|
9691
|
+
}
|
|
9692
|
+
|
|
9693
|
+
// packages/safe-js/src/interp/async-generator-driver.ts
|
|
9694
|
+
var asyncGeneratorDrivers = /* @__PURE__ */ new WeakMap();
|
|
9695
|
+
var asyncGeneratorRequestOwners = /* @__PURE__ */ new WeakMap();
|
|
9696
|
+
var asyncGeneratorHandlers = /* @__PURE__ */ new WeakMap();
|
|
9697
|
+
var generatorSignals = /* @__PURE__ */ new WeakMap();
|
|
9698
|
+
var interruptReleases = /* @__PURE__ */ new WeakMap();
|
|
9699
|
+
function bindAsyncGeneratorSignal(generator, signal, budget, context) {
|
|
9700
|
+
if (signal === void 0) generatorSignals.delete(generator);
|
|
9701
|
+
else generatorSignals.set(generator, signal);
|
|
9702
|
+
const driver = asyncGeneratorDrivers.get(generator);
|
|
9703
|
+
if (driver === void 0) return;
|
|
9704
|
+
interruptReleases.get(driver)?.();
|
|
9705
|
+
if (driver.phase !== "waiting") return;
|
|
9706
|
+
const generation = driver.generation;
|
|
9707
|
+
let notify;
|
|
9708
|
+
const interrupted = new Promise((resolve) => {
|
|
9709
|
+
notify = resolve;
|
|
9710
|
+
});
|
|
9711
|
+
let active = true;
|
|
9712
|
+
const abort = () => notify(signal?.reason ?? new DOMException("The operation was aborted.", "AbortError"));
|
|
9713
|
+
const release = () => {
|
|
9714
|
+
active = false;
|
|
9715
|
+
signal?.removeEventListener("abort", abort);
|
|
9716
|
+
detachFatal?.();
|
|
9717
|
+
if (interruptReleases.get(driver) === release) interruptReleases.delete(driver);
|
|
9718
|
+
};
|
|
9719
|
+
interruptReleases.set(driver, release);
|
|
9720
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
9721
|
+
const detachFatal = onFatalPromiseRejection(notify);
|
|
9722
|
+
void interrupted.then((reason) => runPromiseJob(async () => {
|
|
9723
|
+
if (!active || driver.phase !== "waiting" || driver.generation !== generation) return;
|
|
9724
|
+
if (isFatalSandboxError(reason)) {
|
|
9725
|
+
release();
|
|
9726
|
+
driver.phase = "running";
|
|
9727
|
+
await withFatalPromiseCleanup(async () => {
|
|
9728
|
+
if (generator.state !== "done") await generator.channel.throw(reason, false);
|
|
9729
|
+
});
|
|
9730
|
+
throw reason;
|
|
9731
|
+
}
|
|
9732
|
+
const handler = createAsyncGeneratorHandler(driver, "rejected", generation, budget, context);
|
|
9733
|
+
await handler.call([createThrowCompletion(reason, budget, context?.stack ?? []).value], context);
|
|
9734
|
+
})).catch((error) => rejectGeneratorQueue(driver, error));
|
|
9735
|
+
if (signal?.aborted) abort();
|
|
9736
|
+
}
|
|
9737
|
+
function enqueueAsyncGeneratorRequest(generator, method, value, budget, context) {
|
|
9738
|
+
let driver = asyncGeneratorDrivers.get(generator);
|
|
9739
|
+
if (driver === void 0) {
|
|
9740
|
+
driver = { generator, requests: [], phase: "idle", suspension: "yield", awaitKind: "body", generation: 0 };
|
|
9741
|
+
asyncGeneratorDrivers.set(generator, driver);
|
|
9742
|
+
asyncGeneratorDrivers.set(driver, driver);
|
|
9743
|
+
}
|
|
9744
|
+
const startsRequest = driver.phase === "idle";
|
|
9745
|
+
let completePrefix;
|
|
9746
|
+
const prefix = startsRequest ? new Promise((resolve) => {
|
|
9747
|
+
completePrefix = resolve;
|
|
9748
|
+
}) : void 0;
|
|
9749
|
+
const capability = createPendingPromiseCapability(budget, context, prefix);
|
|
9750
|
+
driver.requests.push({ method, value, capability: { promise: capability.promise, resolve: capability.resolve, reject: capability.reject } });
|
|
9751
|
+
asyncGeneratorRequestOwners.set(capability.promise, driver);
|
|
9752
|
+
if (startsRequest) {
|
|
9753
|
+
driver.phase = "running";
|
|
9754
|
+
const active = driver;
|
|
9755
|
+
void runAsyncPrefix(() => advanceAsyncGenerator(active, method, value, budget, context)).then(
|
|
9756
|
+
() => completePrefix?.(),
|
|
9757
|
+
(error) => {
|
|
9758
|
+
rejectGeneratorQueue(active, error);
|
|
9759
|
+
completePrefix?.();
|
|
9760
|
+
}
|
|
9761
|
+
);
|
|
9762
|
+
}
|
|
9763
|
+
return capability.promise;
|
|
9764
|
+
}
|
|
9765
|
+
function rejectGeneratorQueue(driver, error) {
|
|
9766
|
+
interruptReleases.get(driver)?.();
|
|
9767
|
+
driver.generator.state = "done";
|
|
9768
|
+
driver.phase = "idle";
|
|
9769
|
+
for (const request of driver.requests.splice(0)) {
|
|
9770
|
+
asyncGeneratorRequestOwners.delete(request.capability.promise);
|
|
9771
|
+
pendingPromiseRejectors.get(request.capability.promise)?.(error);
|
|
9772
|
+
}
|
|
9773
|
+
}
|
|
9774
|
+
function createAsyncGeneratorHandler(driver, action, generation, budget, context, owner = driver.requests[0]?.capability.promise) {
|
|
9775
|
+
if (owner === void 0) throw new TypeError("Missing async generator handler owner.");
|
|
9776
|
+
const handler = createSandboxClosure({
|
|
9777
|
+
guest: true,
|
|
9778
|
+
sandbox: true,
|
|
9779
|
+
name: "",
|
|
9780
|
+
length: 1,
|
|
9781
|
+
retainedValues: () => [driver, owner],
|
|
9782
|
+
call: async ([value]) => {
|
|
9783
|
+
if (driver.phase !== "waiting" || driver.generation !== generation) return void 0;
|
|
9784
|
+
interruptReleases.get(driver)?.();
|
|
9785
|
+
driver.phase = "running";
|
|
9786
|
+
if (driver.awaitKind === "return") await settleGeneratorRequest(driver, action, value, true, budget, context);
|
|
9787
|
+
else await advanceAsyncGenerator(driver, action === "fulfilled" ? "next" : "throw", value, budget, context, false);
|
|
9788
|
+
return void 0;
|
|
9789
|
+
}
|
|
9790
|
+
});
|
|
9791
|
+
asyncGeneratorHandlers.set(handler, { driver, owner, action, generation });
|
|
9792
|
+
return handler;
|
|
9793
|
+
}
|
|
9794
|
+
async function settleGeneratorRequest(driver, action, value, done, budget, context) {
|
|
9795
|
+
const request = driver.requests[0];
|
|
9796
|
+
if (request === void 0) throw new TypeError("Missing async generator request.");
|
|
9797
|
+
if (action === "fulfilled") await request.capability.resolve.call([allocateProducedSandboxValue({ value, done }, budget)], context);
|
|
9798
|
+
else await request.capability.reject.call([value], context);
|
|
9799
|
+
driver.requests.shift();
|
|
9800
|
+
asyncGeneratorRequestOwners.delete(request.capability.promise);
|
|
9801
|
+
const next = driver.requests[0];
|
|
9802
|
+
if (next === void 0) driver.phase = "idle";
|
|
9803
|
+
else await advanceAsyncGenerator(driver, next.method, next.value, budget, context);
|
|
9804
|
+
}
|
|
9805
|
+
async function awaitGeneratorRequest(driver, value, kind, budget, context) {
|
|
9806
|
+
let awaited;
|
|
9807
|
+
if (kind === "body" && isSandboxPromise(value)) awaited = value;
|
|
9808
|
+
else {
|
|
9809
|
+
const wrapper = promiseReplayContext.exit(() => createPendingPromiseCapability(budget, context));
|
|
9810
|
+
await wrapper.resolve.call([value], context);
|
|
9811
|
+
awaited = wrapper.promise;
|
|
9812
|
+
}
|
|
9813
|
+
driver.phase = "waiting";
|
|
9814
|
+
driver.awaitKind = kind;
|
|
9815
|
+
driver.generation++;
|
|
9816
|
+
const reaction = promiseReplayContext.exit(() => createPendingPromiseCapability(budget, context));
|
|
9817
|
+
attachPendingPromiseReaction(
|
|
9818
|
+
awaited,
|
|
9819
|
+
reaction,
|
|
9820
|
+
createAsyncGeneratorHandler(driver, "fulfilled", driver.generation, budget, context),
|
|
9821
|
+
createAsyncGeneratorHandler(driver, "rejected", driver.generation, budget, context),
|
|
9822
|
+
budget,
|
|
9823
|
+
context
|
|
9824
|
+
);
|
|
9825
|
+
const request = driver.requests[0];
|
|
9826
|
+
if (request === void 0) throw new TypeError("Missing async generator await owner.");
|
|
9827
|
+
linkPromiseAggregateProducer(reaction.promise, request.capability.promise);
|
|
9828
|
+
bindAsyncGeneratorSignal(driver.generator, generatorSignals.get(driver.generator), budget, context);
|
|
9829
|
+
}
|
|
9830
|
+
async function advanceAsyncGenerator(driver, method, value, budget, context, record4 = true) {
|
|
9831
|
+
const release = retainValues(budget, () => [driver]);
|
|
9832
|
+
const generator = driver.generator;
|
|
9833
|
+
try {
|
|
9834
|
+
driver.phase = "running";
|
|
9835
|
+
const initial = generator.state;
|
|
9836
|
+
generator.state = "running";
|
|
9837
|
+
const result = await generator.channel[method](value, record4);
|
|
9838
|
+
generator.state = result.done ? "done" : "suspended";
|
|
9839
|
+
const produced = result.value;
|
|
9840
|
+
if (!result.done && driver.suspension === "await") await awaitGeneratorRequest(driver, produced, "body", budget, context);
|
|
9841
|
+
else if (result.done && (requiresPromiseResolution(produced, budget) || method === "return" && (initial === "start" || initial === "done")))
|
|
9842
|
+
await awaitGeneratorRequest(driver, produced, "return", budget, context);
|
|
9843
|
+
else await settleGeneratorRequest(driver, "fulfilled", produced, result.done === true, budget, context);
|
|
9844
|
+
} catch (error) {
|
|
9845
|
+
generator.state = "done";
|
|
9846
|
+
if (isFatalSandboxError(error)) {
|
|
9847
|
+
rejectGeneratorQueue(driver, error);
|
|
9848
|
+
throw error;
|
|
9849
|
+
}
|
|
9850
|
+
await settleGeneratorRequest(driver, "rejected", createThrowCompletion(error, budget, context?.stack ?? []).value, true, budget, context);
|
|
9851
|
+
} finally {
|
|
9852
|
+
release();
|
|
9853
|
+
}
|
|
9854
|
+
}
|
|
9855
|
+
|
|
9339
9856
|
// packages/safe-js/src/interp/running-state.ts
|
|
9340
9857
|
var runningObjects = /* @__PURE__ */ new WeakSet();
|
|
9341
9858
|
var lockedCollections = /* @__PURE__ */ new WeakSet();
|
|
@@ -9457,8 +9974,8 @@ function getRegExpIteratorMember(property, budget) {
|
|
|
9457
9974
|
}
|
|
9458
9975
|
|
|
9459
9976
|
// packages/safe-js/src/interp/cancel.ts
|
|
9460
|
-
import { AsyncLocalStorage as
|
|
9461
|
-
var activeCancellation = new
|
|
9977
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
9978
|
+
var activeCancellation = new AsyncLocalStorage4();
|
|
9462
9979
|
var sandboxPromises = /* @__PURE__ */ new WeakSet();
|
|
9463
9980
|
var cancelableOutcomes = /* @__PURE__ */ new WeakMap();
|
|
9464
9981
|
function withCancellationSignal(signal, task) {
|
|
@@ -9643,101 +10160,6 @@ function isPromiseLike(value) {
|
|
|
9643
10160
|
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
9644
10161
|
}
|
|
9645
10162
|
|
|
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
10163
|
// packages/safe-js/src/interp/iteration.ts
|
|
9742
10164
|
function mapIteratorSnapshot(snapshot, map) {
|
|
9743
10165
|
if (snapshot.kind === "unsupported") throw new TypeError("Host-owned iterator cannot be portably snapshotted.");
|
|
@@ -9808,15 +10230,25 @@ async function getSandboxIteratorFromMethod(value, factory, budget, context, asy
|
|
|
9808
10230
|
return guestIterator(iterator, next, asyncProtocol, budget, context, signal);
|
|
9809
10231
|
}
|
|
9810
10232
|
function guestIterator(iterator, next, asyncProtocol, budget, context, signal) {
|
|
10233
|
+
const resumeAwait = async (state, value) => {
|
|
10234
|
+
if (state.kind !== "result") throw new TypeError("Invalid async iterator await state.");
|
|
10235
|
+
const result = await value();
|
|
10236
|
+
if (typeof result !== "object" && typeof result !== "function" || result === null)
|
|
10237
|
+
throw new TypeError("Iterator result must be an object.");
|
|
10238
|
+
return result;
|
|
10239
|
+
};
|
|
9811
10240
|
const invoke = async (operation, args) => {
|
|
9812
10241
|
if (!isSandboxClosure(operation)) throw new TypeError("Iterator operation must be callable.");
|
|
9813
10242
|
const returned = await invokeBuiltinClosure(operation, args, budget, context, iterator);
|
|
10243
|
+
if (asyncProtocol && wrapper.awaitValue !== void 0)
|
|
10244
|
+
return resumeAwait({ kind: "result" }, () => wrapper.awaitValue(returned, { kind: "result" }));
|
|
9814
10245
|
const result = asyncProtocol ? await awaitSandboxValue(returned, signal, budget, context) : returned;
|
|
9815
10246
|
if (typeof result !== "object" && typeof result !== "function" || result === null)
|
|
9816
10247
|
throw new TypeError("Iterator result must be an object.");
|
|
9817
10248
|
return result;
|
|
9818
10249
|
};
|
|
9819
|
-
|
|
10250
|
+
const wrapper = {
|
|
10251
|
+
resumeAwait,
|
|
9820
10252
|
...asyncProtocol ? { asyncProtocol: true } : {},
|
|
9821
10253
|
asynchronous: true,
|
|
9822
10254
|
retainedValue: [iterator, next],
|
|
@@ -9830,6 +10262,7 @@ function guestIterator(iterator, next, asyncProtocol, budget, context, signal) {
|
|
|
9830
10262
|
value: await context.getProperty(result, property)
|
|
9831
10263
|
})
|
|
9832
10264
|
};
|
|
10265
|
+
return wrapper;
|
|
9833
10266
|
}
|
|
9834
10267
|
async function readIteratorResult(iterator, result, property) {
|
|
9835
10268
|
return iterator.readResultProperty === void 0 ? { value: result[property] } : iterator.readResultProperty(result, property);
|
|
@@ -9888,6 +10321,16 @@ function nativeAsyncIterator(value, method, signal) {
|
|
|
9888
10321
|
};
|
|
9889
10322
|
}
|
|
9890
10323
|
function asyncFromSyncIterator(iterator, budget, signal, context) {
|
|
10324
|
+
const resumeAwait = async (state, value) => {
|
|
10325
|
+
if (state.kind !== "value") throw new TypeError("Invalid async-from-sync await state.");
|
|
10326
|
+
try {
|
|
10327
|
+
return { done: state.done, value: await value() };
|
|
10328
|
+
} catch (error) {
|
|
10329
|
+
if (isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
|
|
10330
|
+
if (state.closeOnReject) await closeIterator(iterator, true);
|
|
10331
|
+
throw error;
|
|
10332
|
+
}
|
|
10333
|
+
};
|
|
9891
10334
|
const invoke = async (method, args) => {
|
|
9892
10335
|
const operation = iterator.getOperation === void 0 ? iterator[method] : await iterator.getOperation(method);
|
|
9893
10336
|
if (operation === void 0) {
|
|
@@ -9904,6 +10347,10 @@ function asyncFromSyncIterator(iterator, budget, signal, context) {
|
|
|
9904
10347
|
}
|
|
9905
10348
|
const done = Boolean((await readIteratorResult(iterator, result, "done")).value);
|
|
9906
10349
|
const resultValue = (await readIteratorResult(iterator, result, "value")).value;
|
|
10350
|
+
if (wrapper.awaitValue !== void 0) {
|
|
10351
|
+
const state = { kind: "value", done, closeOnReject: !done && method !== "return" };
|
|
10352
|
+
return resumeAwait(state, () => wrapper.awaitValue(resultValue, state));
|
|
10353
|
+
}
|
|
9907
10354
|
try {
|
|
9908
10355
|
return { done, value: await awaitSandboxValue(resultValue, signal, budget, context) };
|
|
9909
10356
|
} catch (error) {
|
|
@@ -9912,7 +10359,8 @@ function asyncFromSyncIterator(iterator, budget, signal, context) {
|
|
|
9912
10359
|
throw error;
|
|
9913
10360
|
}
|
|
9914
10361
|
};
|
|
9915
|
-
|
|
10362
|
+
const wrapper = {
|
|
10363
|
+
resumeAwait,
|
|
9916
10364
|
asyncProtocol: true,
|
|
9917
10365
|
snapshotIndex: iterator.snapshotIndex,
|
|
9918
10366
|
snapshot: () => ({ kind: "async-from-sync", inner: iterator.snapshot?.() ?? { kind: "unsupported" } }),
|
|
@@ -9923,13 +10371,14 @@ function asyncFromSyncIterator(iterator, budget, signal, context) {
|
|
|
9923
10371
|
return: (...args) => invoke("return", args),
|
|
9924
10372
|
throw: (...args) => invoke("throw", args)
|
|
9925
10373
|
};
|
|
10374
|
+
return wrapper;
|
|
9926
10375
|
}
|
|
9927
|
-
async function closeIterator(iterator, preserveThrow = false) {
|
|
10376
|
+
async function closeIterator(iterator, preserveThrow = false, awaitResult = suspendJob) {
|
|
9928
10377
|
try {
|
|
9929
10378
|
const close = iterator.getOperation === void 0 ? iterator.return : await iterator.getOperation("return");
|
|
9930
10379
|
if (close === void 0) return;
|
|
9931
10380
|
const returned = close();
|
|
9932
|
-
const result = iterator.asyncProtocol ? await
|
|
10381
|
+
const result = iterator.asyncProtocol ? iterator.awaitValue === void 0 ? await awaitResult(Promise.resolve(returned)) : await returned : iterator.generator || iterator.asynchronous ? await returned : returned;
|
|
9933
10382
|
if (typeof result !== "object" && typeof result !== "function" || result === null) {
|
|
9934
10383
|
throw new TypeError("Iterator return result must be an object.");
|
|
9935
10384
|
}
|
|
@@ -10072,7 +10521,6 @@ function collectionIterator(collection, value) {
|
|
|
10072
10521
|
adapter.snapshot = () => ({ kind: "builtin", value, index: adapter.snapshotIndex() });
|
|
10073
10522
|
return adapter;
|
|
10074
10523
|
}
|
|
10075
|
-
var asyncGeneratorRequests = /* @__PURE__ */ new WeakMap();
|
|
10076
10524
|
function guestProtocolAdapter(value, budget, context, asyncProtocol, signal) {
|
|
10077
10525
|
const bridge = {
|
|
10078
10526
|
...context,
|
|
@@ -10128,13 +10576,8 @@ function generatorObjectIterator(generator, budget, context) {
|
|
|
10128
10576
|
function generatorIterator(generator, budget, context) {
|
|
10129
10577
|
const invoke = async (method, value) => {
|
|
10130
10578
|
const leaveRunning = enterRunningState(generator);
|
|
10131
|
-
const initialState = generator.state;
|
|
10132
10579
|
generator.state = "running";
|
|
10133
10580
|
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
10581
|
const result = await generator.channel[method](value);
|
|
10139
10582
|
generator.state = result.done ? "done" : "suspended";
|
|
10140
10583
|
return result;
|
|
@@ -10147,13 +10590,7 @@ function generatorIterator(generator, budget, context) {
|
|
|
10147
10590
|
};
|
|
10148
10591
|
const request = (method, value) => {
|
|
10149
10592
|
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;
|
|
10593
|
+
return enqueueAsyncGeneratorRequest(generator, method, value, budget ?? new Budget(), context).promise;
|
|
10157
10594
|
};
|
|
10158
10595
|
return {
|
|
10159
10596
|
generator: true,
|
|
@@ -10194,67 +10631,13 @@ function syncIterator(iterator) {
|
|
|
10194
10631
|
var promiseResolvingFunctions = /* @__PURE__ */ new WeakMap();
|
|
10195
10632
|
var promiseResolverActions = /* @__PURE__ */ new WeakMap();
|
|
10196
10633
|
|
|
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
10634
|
// packages/safe-js/src/interp/promise.ts
|
|
10254
10635
|
var promiseConstructors = /* @__PURE__ */ new WeakSet();
|
|
10255
10636
|
var intrinsicPromiseThenMethods = /* @__PURE__ */ new WeakSet();
|
|
10256
10637
|
var intrinsicPromiseConstructors = /* @__PURE__ */ new WeakMap();
|
|
10257
10638
|
var promisePrototypes2 = /* @__PURE__ */ new WeakMap();
|
|
10639
|
+
var pendingPromiseRejectors = /* @__PURE__ */ new WeakMap();
|
|
10640
|
+
var pendingPromiseFulfillers = /* @__PURE__ */ new WeakMap();
|
|
10258
10641
|
function isSandboxPromiseConstructor(value) {
|
|
10259
10642
|
return isSandboxClosure(value) && promiseConstructors.has(value);
|
|
10260
10643
|
}
|
|
@@ -10268,6 +10651,8 @@ function createPendingPromiseCapability(budget, context, synchronousPrefix) {
|
|
|
10268
10651
|
fulfill = resolve;
|
|
10269
10652
|
reject = rejectPromise;
|
|
10270
10653
|
}), { span: context?.span, synchronousPrefix });
|
|
10654
|
+
pendingPromiseRejectors.set(promise, reject);
|
|
10655
|
+
pendingPromiseFulfillers.set(promise, fulfill);
|
|
10271
10656
|
const resolverState = { promise, settled: false };
|
|
10272
10657
|
const continuation = { kind: "capability", state: resolverState };
|
|
10273
10658
|
trackPromiseContinuation(promise, continuation);
|
|
@@ -10321,6 +10706,11 @@ function attachPendingPromiseReaction(source, capability, onFulfilled, onRejecte
|
|
|
10321
10706
|
continuation.phase = "running";
|
|
10322
10707
|
try {
|
|
10323
10708
|
consumeSettledHostCall(source);
|
|
10709
|
+
const asyncContinuation = isSandboxClosure(handler) ? asyncFunctionHandlers.get(handler) : void 0;
|
|
10710
|
+
if (isSandboxClosure(handler) && asyncContinuation?.driver.generator?.state === "done") {
|
|
10711
|
+
capability.fulfill(handler.call([value], context));
|
|
10712
|
+
return;
|
|
10713
|
+
}
|
|
10324
10714
|
capability.fulfill(reactionCapability === void 0 ? runPromiseReaction(handler, value, status, budget, capability.promise, context) : runCapabilityReaction(handler, value, status, reactionCapability, budget, context));
|
|
10325
10715
|
} catch (error) {
|
|
10326
10716
|
capability.rejectNative(error);
|
|
@@ -10328,6 +10718,21 @@ function attachPendingPromiseReaction(source, capability, onFulfilled, onRejecte
|
|
|
10328
10718
|
};
|
|
10329
10719
|
source.promise.then((value) => react(onFulfilled, value, "fulfilled"), (reason) => react(onRejected, reason, "rejected"));
|
|
10330
10720
|
trackPromiseContinuation(capability.promise, continuation);
|
|
10721
|
+
const asyncHandler = isSandboxClosure(onRejected) ? asyncFunctionHandlers.get(onRejected) : void 0;
|
|
10722
|
+
const generatorHandler = isSandboxClosure(onRejected) ? asyncGeneratorHandlers.get(onRejected) : void 0;
|
|
10723
|
+
if (generatorHandler !== void 0) {
|
|
10724
|
+
observeSandboxPromise(capability.promise, true);
|
|
10725
|
+
void capability.promise.promise.catch((error) => rejectGeneratorQueue(generatorHandler.driver, error));
|
|
10726
|
+
}
|
|
10727
|
+
if (asyncHandler !== void 0) {
|
|
10728
|
+
observeSandboxPromise(capability.promise, true);
|
|
10729
|
+
void capability.promise.promise.catch((error) => {
|
|
10730
|
+
asyncHandler.driver.phase = "done";
|
|
10731
|
+
const reject = pendingPromiseRejectors.get(asyncHandler.driver.capability.promise);
|
|
10732
|
+
if (reject === void 0) throw new TypeError("Missing async function rejection capability.");
|
|
10733
|
+
reject(error);
|
|
10734
|
+
});
|
|
10735
|
+
}
|
|
10331
10736
|
}
|
|
10332
10737
|
function createPromiseGlobals(options) {
|
|
10333
10738
|
promisePrototypes2.delete(options.budget);
|
|
@@ -11398,6 +11803,7 @@ var Scope = class _Scope {
|
|
|
11398
11803
|
parent;
|
|
11399
11804
|
importMeta;
|
|
11400
11805
|
options;
|
|
11806
|
+
resourceState;
|
|
11401
11807
|
privateNames;
|
|
11402
11808
|
#bindings = /* @__PURE__ */ new Map();
|
|
11403
11809
|
#restoredBindings;
|
|
@@ -11466,6 +11872,7 @@ var Scope = class _Scope {
|
|
|
11466
11872
|
}
|
|
11467
11873
|
retainedValues() {
|
|
11468
11874
|
const values = this.parent?.retainedValues() ?? [];
|
|
11875
|
+
if (this.resourceState !== void 0) values.push(this.resourceState);
|
|
11469
11876
|
if (this.options.chargeData !== false) {
|
|
11470
11877
|
if (this.importMeta !== void 0) values.push(this.importMeta);
|
|
11471
11878
|
if (this.privateNames !== void 0) values.push(...this.privateNames.values());
|
|
@@ -11596,6 +12003,7 @@ var Scope = class _Scope {
|
|
|
11596
12003
|
chargeData: this.options.chargeData !== false,
|
|
11597
12004
|
bindings,
|
|
11598
12005
|
cells,
|
|
12006
|
+
...this.resourceState === void 0 ? {} : { resourceState: this.resourceState },
|
|
11599
12007
|
...this.privateNames === void 0 ? {} : { privateNames: [...this.privateNames] },
|
|
11600
12008
|
...this.parent === void 0 ? { restoredBindings: [...this.#restoredBindings] } : {}
|
|
11601
12009
|
};
|
|
@@ -11623,6 +12031,7 @@ var Scope = class _Scope {
|
|
|
11623
12031
|
const restored = new Map(frame.restoredBindings ?? []);
|
|
11624
12032
|
if (restored.size !== (frame.restoredBindings?.length ?? 0)) throw new TypeError("Duplicate restored binding.");
|
|
11625
12033
|
this.importMeta = frame.importMeta;
|
|
12034
|
+
this.resourceState = frame.resourceState;
|
|
11626
12035
|
if (frame.privateNames !== void 0) this.privateNames = new Map(frame.privateNames);
|
|
11627
12036
|
for (const [name, binding] of bindings) this.#bindings.set(name, binding);
|
|
11628
12037
|
if (this.parent === void 0)
|
|
@@ -11781,27 +12190,34 @@ function createGeneratorChannel(body) {
|
|
|
11781
12190
|
let state = "unstarted";
|
|
11782
12191
|
let signal = deferred();
|
|
11783
12192
|
let resume;
|
|
11784
|
-
const
|
|
12193
|
+
const resumeJob = createResumableJobContext();
|
|
11785
12194
|
const sent = [];
|
|
11786
12195
|
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 });
|
|
12196
|
+
function startBody() {
|
|
12197
|
+
let bodyPromise;
|
|
12198
|
+
try {
|
|
12199
|
+
bodyPromise = body(yieldValue);
|
|
12200
|
+
} catch (error) {
|
|
12201
|
+
bodyPromise = Promise.reject(error);
|
|
11802
12202
|
}
|
|
11803
|
-
|
|
11804
|
-
|
|
12203
|
+
void bodyPromise.then(
|
|
12204
|
+
(value) => {
|
|
12205
|
+
if (state === "done") {
|
|
12206
|
+
return;
|
|
12207
|
+
}
|
|
12208
|
+
state = "done";
|
|
12209
|
+
signal.resolve({ type: "complete", value });
|
|
12210
|
+
},
|
|
12211
|
+
(error) => {
|
|
12212
|
+
if (state === "done") {
|
|
12213
|
+
return;
|
|
12214
|
+
}
|
|
12215
|
+
state = "done";
|
|
12216
|
+
signal.resolve({ type: "error", error });
|
|
12217
|
+
}
|
|
12218
|
+
);
|
|
12219
|
+
void bodyPromise.catch(() => void 0);
|
|
12220
|
+
}
|
|
11805
12221
|
async function yieldValue(value, nodeId) {
|
|
11806
12222
|
resume = deferred();
|
|
11807
12223
|
yieldNodeId = nodeId;
|
|
@@ -11809,7 +12225,7 @@ function createGeneratorChannel(body) {
|
|
|
11809
12225
|
signal.resolve({ type: "yield", value });
|
|
11810
12226
|
return resume.promise;
|
|
11811
12227
|
}
|
|
11812
|
-
async function deliver(completion) {
|
|
12228
|
+
async function deliver(completion, record4) {
|
|
11813
12229
|
const leaveRunning = enterRunningState(channelIdentity);
|
|
11814
12230
|
try {
|
|
11815
12231
|
if (state === "done") {
|
|
@@ -11831,11 +12247,11 @@ function createGeneratorChannel(body) {
|
|
|
11831
12247
|
throw completion.value;
|
|
11832
12248
|
}
|
|
11833
12249
|
state = "running";
|
|
11834
|
-
sent.push(completion);
|
|
11835
|
-
|
|
12250
|
+
if (record4) sent.push(completion);
|
|
12251
|
+
startBody();
|
|
11836
12252
|
} else {
|
|
11837
12253
|
state = "running";
|
|
11838
|
-
sent.push(completion);
|
|
12254
|
+
if (record4) sent.push(completion);
|
|
11839
12255
|
signal = deferred();
|
|
11840
12256
|
const pendingResume = resume;
|
|
11841
12257
|
resume = void 0;
|
|
@@ -11851,13 +12267,14 @@ function createGeneratorChannel(body) {
|
|
|
11851
12267
|
return { value: settled.value, done: true };
|
|
11852
12268
|
} finally {
|
|
11853
12269
|
leaveRunning();
|
|
12270
|
+
resumeJob.release();
|
|
11854
12271
|
}
|
|
11855
12272
|
}
|
|
11856
12273
|
const channelIdentity = {};
|
|
11857
12274
|
return {
|
|
11858
|
-
next: (value) => deliver({ type: "normal", value }),
|
|
11859
|
-
return: (value) => deliver({ type: "return", value }),
|
|
11860
|
-
throw: (error) => deliver({ type: "throw", value: error }),
|
|
12275
|
+
next: (value, record4 = true) => resumeJob.run(() => deliver({ type: "normal", value }, record4)),
|
|
12276
|
+
return: (value, record4 = true) => resumeJob.run(() => deliver({ type: "return", value }, record4)),
|
|
12277
|
+
throw: (error, record4 = true) => resumeJob.run(() => deliver({ type: "throw", value: error }, record4)),
|
|
11861
12278
|
snapshot: () => ({
|
|
11862
12279
|
...yieldNodeId === void 0 ? {} : { yieldNodeId },
|
|
11863
12280
|
sent: sent.map((completion) => ({ ...completion }))
|
|
@@ -12313,18 +12730,56 @@ function createInterpretedClosure(node, context, evaluateNode2, homeObject, init
|
|
|
12313
12730
|
};
|
|
12314
12731
|
if (!node.async)
|
|
12315
12732
|
return executeClosure(node, args, callContext?.thisValue, invocationContext, evaluateNode2);
|
|
12316
|
-
return
|
|
12317
|
-
|
|
12318
|
-
|
|
12319
|
-
|
|
12320
|
-
|
|
12321
|
-
|
|
12322
|
-
|
|
12323
|
-
|
|
12324
|
-
|
|
12325
|
-
|
|
12326
|
-
|
|
12327
|
-
|
|
12733
|
+
return startAsyncFunction(async (onSuspend) => {
|
|
12734
|
+
const parent = invocationContext.compilation;
|
|
12735
|
+
const operation = context.budget.acquireCompileOwner(false, parent?.owner);
|
|
12736
|
+
const compilation = new CompileScope(operation.owner, parent);
|
|
12737
|
+
const executionContext = { ...invocationContext, compilation, onSuspend };
|
|
12738
|
+
let scope;
|
|
12739
|
+
try {
|
|
12740
|
+
scope = await createClosureScope(node, args, callContext?.thisValue, executionContext, evaluateNode2);
|
|
12741
|
+
} catch (error) {
|
|
12742
|
+
compilation.dispose();
|
|
12743
|
+
operation.release();
|
|
12744
|
+
throw error;
|
|
12745
|
+
}
|
|
12746
|
+
const channel = createGeneratorChannel(async (generatorYield) => {
|
|
12747
|
+
try {
|
|
12748
|
+
const result = await evaluateNode2(node.body, {
|
|
12749
|
+
...executionContext,
|
|
12750
|
+
scope,
|
|
12751
|
+
asyncFunction: true,
|
|
12752
|
+
asyncGenerator: false,
|
|
12753
|
+
asyncGeneratorFrame: void 0,
|
|
12754
|
+
functionBody: node.body.type === "BlockStatement" ? node.body : void 0,
|
|
12755
|
+
generatorBlockScopes: /* @__PURE__ */ new Map(),
|
|
12756
|
+
generatorExpressionStates: /* @__PURE__ */ new Map(),
|
|
12757
|
+
captureGeneratorScope: (current, blocks, completions, expressions) => {
|
|
12758
|
+
origin.suspendedScope = current;
|
|
12759
|
+
origin.blockScopes = blocks;
|
|
12760
|
+
origin.finallyCompletions = completions;
|
|
12761
|
+
origin.expressionStates = expressions;
|
|
12762
|
+
},
|
|
12763
|
+
generatorYield: (value2, nodeId) => {
|
|
12764
|
+
generator.state = "suspended";
|
|
12765
|
+
return generatorYield(value2, nodeId);
|
|
12766
|
+
}
|
|
12767
|
+
});
|
|
12768
|
+
const value = "hasValue" in result && result.hasValue ? result.value : void 0;
|
|
12769
|
+
reconcileCompiledValues(context.budget, [...scope.retainedValues(), value], compilation, parent, [value]);
|
|
12770
|
+
if (result.kind === "error") throw result.error;
|
|
12771
|
+
if (result.kind === "throw") throw result.value;
|
|
12772
|
+
return value;
|
|
12773
|
+
} finally {
|
|
12774
|
+
compilation.dispose();
|
|
12775
|
+
operation.release();
|
|
12776
|
+
}
|
|
12777
|
+
});
|
|
12778
|
+
const generator = createSandboxGenerator(channel);
|
|
12779
|
+
const origin = registerGeneratorOrigin(generator, node, scope, invocationContext);
|
|
12780
|
+
origin.asyncFunction = true;
|
|
12781
|
+
return generator;
|
|
12782
|
+
}, context.budget, callContext, context.signal);
|
|
12328
12783
|
}
|
|
12329
12784
|
});
|
|
12330
12785
|
registerClosureOrigin(closure, node, context);
|
|
@@ -12391,8 +12846,11 @@ function createGeneratorClosure(node, context, evaluateNode2, initializePrototyp
|
|
|
12391
12846
|
const execute = async () => {
|
|
12392
12847
|
const result = await evaluateNode2(node.body, {
|
|
12393
12848
|
...closureContext,
|
|
12849
|
+
asyncFunction: false,
|
|
12394
12850
|
functionBody: node.body,
|
|
12395
12851
|
asyncGenerator: node.async,
|
|
12852
|
+
asyncGeneratorFrame: node.async ? generator : void 0,
|
|
12853
|
+
onSuspend: void 0,
|
|
12396
12854
|
generatorBlockScopes: /* @__PURE__ */ new Map(),
|
|
12397
12855
|
generatorExpressionStates: /* @__PURE__ */ new Map(),
|
|
12398
12856
|
captureGeneratorScope: (suspendedScope, blocks, completions, expressions) => {
|
|
@@ -12414,11 +12872,12 @@ function createGeneratorClosure(node, context, evaluateNode2, initializePrototyp
|
|
|
12414
12872
|
throw result.value;
|
|
12415
12873
|
}
|
|
12416
12874
|
const value = result.hasValue ? result.value : void 0;
|
|
12417
|
-
return
|
|
12875
|
+
return value;
|
|
12418
12876
|
};
|
|
12419
|
-
return
|
|
12877
|
+
return execute();
|
|
12420
12878
|
});
|
|
12421
12879
|
const generator = createSandboxGenerator(channel, { async: node.async });
|
|
12880
|
+
if (node.async) bindAsyncGeneratorSignal(generator, context.signal, context.budget);
|
|
12422
12881
|
if (prototype !== void 0) setSandboxPrototype(generator, prototype, context.budget);
|
|
12423
12882
|
const origin = registerGeneratorOrigin(generator, node, scope, closureContext);
|
|
12424
12883
|
return generator;
|
|
@@ -12441,11 +12900,17 @@ function isConstructResult(value) {
|
|
|
12441
12900
|
return typeof value === "object" && value !== null;
|
|
12442
12901
|
}
|
|
12443
12902
|
async function evaluateAwaitExpression(node, context, evaluateNode2) {
|
|
12903
|
+
if ((context.asyncFunction || context.asyncGeneratorFrame !== void 0) && context.generatorResume?.completed !== true && context.generatorResume?.yieldNodeId === node.nodeId) {
|
|
12904
|
+
return { kind: "normal", hasValue: true, value: await suspendAsyncFunctionValue(void 0, node, context) };
|
|
12905
|
+
}
|
|
12444
12906
|
const replayState = context.captureReplayState?.();
|
|
12445
12907
|
const argument = await evaluateNode2(node.argument, context);
|
|
12446
12908
|
if (argument.kind !== "normal") {
|
|
12447
12909
|
return argument;
|
|
12448
12910
|
}
|
|
12911
|
+
if (context.asyncFunction || context.asyncGeneratorFrame !== void 0) {
|
|
12912
|
+
return { kind: "normal", hasValue: true, value: await suspendAsyncFunctionValue(argument.value, node, context, replayState, createCoercionContext(context)) };
|
|
12913
|
+
}
|
|
12449
12914
|
context.onSuspend?.();
|
|
12450
12915
|
emitResumeBreakpoint(context, {
|
|
12451
12916
|
kind: "await",
|
|
@@ -12465,6 +12930,51 @@ async function evaluateAwaitExpression(node, context, evaluateNode2) {
|
|
|
12465
12930
|
leaveAwait();
|
|
12466
12931
|
}
|
|
12467
12932
|
}
|
|
12933
|
+
async function suspendAsyncFunctionValue(value, node, context, replayState = context.captureReplayState?.(), callContext, phase = "await") {
|
|
12934
|
+
if (context.generatorYield === void 0 || node.nodeId === void 0) throw new TypeError("Missing async function suspension identity.");
|
|
12935
|
+
let awaited;
|
|
12936
|
+
if (isSandboxPromise(value)) {
|
|
12937
|
+
const prepared = prepareAwaitedPromise(value, context.budget, callContext);
|
|
12938
|
+
awaited = prepared instanceof Promise ? await prepared : prepared;
|
|
12939
|
+
} else {
|
|
12940
|
+
const wrapper = promiseReplayContext.exit(() => createPendingPromiseCapability(context.budget, callContext));
|
|
12941
|
+
const prefix = wrapper.resolve.call([value], callContext);
|
|
12942
|
+
if (prefix instanceof Promise) await prefix;
|
|
12943
|
+
awaited = wrapper.promise;
|
|
12944
|
+
}
|
|
12945
|
+
if (context.signal?.aborted) {
|
|
12946
|
+
observeSandboxPromise(awaited, true);
|
|
12947
|
+
await awaitWithSignal(awaited.promise, context.signal);
|
|
12948
|
+
}
|
|
12949
|
+
context.captureGeneratorScope?.(context.scope, context.generatorBlockScopes, context.finallyCompletions, context.generatorExpressionStates);
|
|
12950
|
+
context.onSuspend?.();
|
|
12951
|
+
const otelSpan = getBoundOtelSpan(value);
|
|
12952
|
+
emitResumeBreakpoint(context, {
|
|
12953
|
+
kind: "await",
|
|
12954
|
+
nodeId: node.nodeId,
|
|
12955
|
+
span: node.span,
|
|
12956
|
+
replayState,
|
|
12957
|
+
...otelSpan === void 0 ? {} : { otelSpan }
|
|
12958
|
+
});
|
|
12959
|
+
const leaveAwait = context.budget.enterAwait();
|
|
12960
|
+
const generator = context.asyncGeneratorFrame;
|
|
12961
|
+
const origin = generator === void 0 ? void 0 : getGeneratorOrigin(generator);
|
|
12962
|
+
if (generator !== void 0) {
|
|
12963
|
+
const driver = asyncGeneratorDrivers.get(generator);
|
|
12964
|
+
if (driver === void 0 || origin === void 0) throw new TypeError("Missing async generator suspension owner.");
|
|
12965
|
+
driver.suspension = "await";
|
|
12966
|
+
origin.awaitPhase = phase;
|
|
12967
|
+
}
|
|
12968
|
+
try {
|
|
12969
|
+
const completion = await context.generatorYield(awaited, node.nodeId);
|
|
12970
|
+
if (context.generatorResume !== void 0) context.generatorResume.completed = true;
|
|
12971
|
+
if (completion.type === "throw") throw completion.value;
|
|
12972
|
+
return completion.value;
|
|
12973
|
+
} finally {
|
|
12974
|
+
if (origin !== void 0) origin.awaitPhase = void 0;
|
|
12975
|
+
leaveAwait();
|
|
12976
|
+
}
|
|
12977
|
+
}
|
|
12468
12978
|
async function executeClosure(node, args, thisValue, context, evaluateNode2) {
|
|
12469
12979
|
const parent = context.compilation;
|
|
12470
12980
|
const operation = context.budget.acquireCompileOwner(false, parent?.owner);
|
|
@@ -12475,6 +12985,8 @@ async function executeClosure(node, args, thisValue, context, evaluateNode2) {
|
|
|
12475
12985
|
const result = await evaluateNode2(node.body, {
|
|
12476
12986
|
...context,
|
|
12477
12987
|
asyncGenerator: false,
|
|
12988
|
+
asyncFunction: false,
|
|
12989
|
+
asyncGeneratorFrame: void 0,
|
|
12478
12990
|
functionBody: node.body.type === "BlockStatement" ? node.body : void 0,
|
|
12479
12991
|
scope
|
|
12480
12992
|
});
|
|
@@ -17486,10 +17998,56 @@ function captureAsyncResources(resources, encode) {
|
|
|
17486
17998
|
method: encode(resource.method),
|
|
17487
17999
|
receiver: encode(resource.receiver),
|
|
17488
18000
|
args: resource.args.map(encode),
|
|
17489
|
-
syncFallback: resource.syncFallback
|
|
18001
|
+
syncFallback: resource.syncFallback,
|
|
18002
|
+
...resource.synchronous === void 0 ? {} : { synchronous: resource.synchronous }
|
|
17490
18003
|
}));
|
|
17491
18004
|
}
|
|
17492
18005
|
function captureGuestHeapNode(value, encode) {
|
|
18006
|
+
const generatorDriver = asyncGeneratorDrivers.get(value);
|
|
18007
|
+
if (generatorDriver === value) {
|
|
18008
|
+
if (generatorDriver.phase === "running") throw new SnapshotNotReadyError("Cannot snapshot an active async generator request.");
|
|
18009
|
+
return {
|
|
18010
|
+
kind: "async-generator-driver",
|
|
18011
|
+
generator: encode(generatorDriver.generator),
|
|
18012
|
+
phase: generatorDriver.phase,
|
|
18013
|
+
suspension: generatorDriver.suspension,
|
|
18014
|
+
awaitKind: generatorDriver.awaitKind,
|
|
18015
|
+
generation: generatorDriver.generation,
|
|
18016
|
+
requests: generatorDriver.requests.map((request) => ({
|
|
18017
|
+
method: request.method,
|
|
18018
|
+
value: encode(request.value),
|
|
18019
|
+
capability: { promise: encode(request.capability.promise), resolve: encode(request.capability.resolve), reject: encode(request.capability.reject) }
|
|
18020
|
+
}))
|
|
18021
|
+
};
|
|
18022
|
+
}
|
|
18023
|
+
const generatorHandler = isSandboxClosure(value) ? asyncGeneratorHandlers.get(value) : void 0;
|
|
18024
|
+
if (generatorHandler !== void 0) return {
|
|
18025
|
+
kind: "async-generator-handler",
|
|
18026
|
+
driver: encode(generatorHandler.driver),
|
|
18027
|
+
owner: encode(generatorHandler.owner),
|
|
18028
|
+
action: generatorHandler.action,
|
|
18029
|
+
generation: generatorHandler.generation,
|
|
18030
|
+
state: captureObjectState(value, encode)
|
|
18031
|
+
};
|
|
18032
|
+
const driver = asyncFunctionDrivers.get(value);
|
|
18033
|
+
if (driver !== void 0) {
|
|
18034
|
+
if (driver.phase === "running" || driver.generator === void 0) throw new SnapshotNotReadyError("Cannot snapshot an active async function.");
|
|
18035
|
+
return {
|
|
18036
|
+
kind: "async-function-driver",
|
|
18037
|
+
generator: encode(driver.generator),
|
|
18038
|
+
phase: driver.phase,
|
|
18039
|
+
generation: driver.generation,
|
|
18040
|
+
capability: { promise: encode(driver.capability.promise), resolve: encode(driver.capability.resolve), reject: encode(driver.capability.reject) }
|
|
18041
|
+
};
|
|
18042
|
+
}
|
|
18043
|
+
const asyncHandler = isSandboxClosure(value) ? asyncFunctionHandlers.get(value) : void 0;
|
|
18044
|
+
if (asyncHandler !== void 0) return {
|
|
18045
|
+
kind: "async-function-handler",
|
|
18046
|
+
driver: encode(asyncHandler.driver),
|
|
18047
|
+
action: asyncHandler.action,
|
|
18048
|
+
generation: asyncHandler.generation,
|
|
18049
|
+
state: captureObjectState(value, encode)
|
|
18050
|
+
};
|
|
17493
18051
|
const asyncStack = asyncDisposableStackStates.get(value);
|
|
17494
18052
|
if (asyncStack !== void 0) return {
|
|
17495
18053
|
kind: "async-disposable-stack",
|
|
@@ -17609,6 +18167,8 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17609
18167
|
return { kind: "promise-resolver", promise: encode(resolver.promise), state: captureObjectState(value, encode) };
|
|
17610
18168
|
}
|
|
17611
18169
|
if (isSandboxPromise(value)) {
|
|
18170
|
+
const generatorOwner = asyncGeneratorRequestOwners.get(value);
|
|
18171
|
+
const ownerState = generatorOwner === void 0 ? {} : { generatorOwner: encode(generatorOwner) };
|
|
17612
18172
|
const producerState = promiseProducers.has(value) ? { producers: [...promiseProducers.get(value)].map(encode) } : {};
|
|
17613
18173
|
const settlement = promiseStates.get(value);
|
|
17614
18174
|
if (settlement !== void 0 && settlement.status !== "pending")
|
|
@@ -17616,6 +18176,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17616
18176
|
kind: "guest-promise",
|
|
17617
18177
|
status: settlement.status,
|
|
17618
18178
|
value: encode(settlement.value),
|
|
18179
|
+
...ownerState,
|
|
17619
18180
|
...producerState,
|
|
17620
18181
|
...promiseReactionResults.has(value) ? { reactions: [...promiseReactionResults.get(value)].map(encode) } : {},
|
|
17621
18182
|
state: captureObjectState(value, encode)
|
|
@@ -17623,6 +18184,8 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17623
18184
|
const continuation = promiseContinuations.get(value);
|
|
17624
18185
|
if (unrepresentedPromiseContinuations.has(value))
|
|
17625
18186
|
throw new TypeError("Cannot serialize host reference: unrepresented promise continuation.");
|
|
18187
|
+
if (continuation?.kind === "reaction" && continuation.phase === "running")
|
|
18188
|
+
throw new SnapshotNotReadyError("Cannot snapshot an active promise reaction.");
|
|
17626
18189
|
if (continuation?.kind === "capability") {
|
|
17627
18190
|
const thenable2 = thenableContinuations.get(value);
|
|
17628
18191
|
if (continuation.state.settled && thenable2 !== void 0 && !thenable2.completed && thenable2.owner === value)
|
|
@@ -17630,6 +18193,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17630
18193
|
kind: "pending-promise",
|
|
17631
18194
|
thenable: encode(thenable2),
|
|
17632
18195
|
...producerState,
|
|
18196
|
+
...ownerState,
|
|
17633
18197
|
reactions: [...promiseReactionResults.get(value) ?? []].map(encode),
|
|
17634
18198
|
state: captureObjectState(value, encode)
|
|
17635
18199
|
};
|
|
@@ -17639,6 +18203,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17639
18203
|
return {
|
|
17640
18204
|
kind: "pending-promise",
|
|
17641
18205
|
...continuation.state.settled ? { adoption: encode(adoption) } : {},
|
|
18206
|
+
...ownerState,
|
|
17642
18207
|
...producerState,
|
|
17643
18208
|
reactions: [...promiseReactionResults.get(value) ?? []].map(encode),
|
|
17644
18209
|
state: captureObjectState(value, encode)
|
|
@@ -17787,6 +18352,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17787
18352
|
functionBoundary: frame.functionBoundary,
|
|
17788
18353
|
chargeData: frame.chargeData,
|
|
17789
18354
|
bindings: frame.bindings,
|
|
18355
|
+
...frame.resourceState === void 0 ? {} : { resourceState: encode(frame.resourceState) },
|
|
17790
18356
|
...frame.privateNames === void 0 ? {} : { privateNames: frame.privateNames.map(([name, identity]) => [name, encode(identity)]) },
|
|
17791
18357
|
cells: frame.cells.map((cell) => cell.initialized ? { ...cell, value: encode(cell.value) } : cell),
|
|
17792
18358
|
...frame.restoredBindings === void 0 ? {} : {
|
|
@@ -17803,6 +18369,9 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17803
18369
|
state: value.state,
|
|
17804
18370
|
astNodeId: origin2.node.nodeId,
|
|
17805
18371
|
async: value.async === true,
|
|
18372
|
+
...origin2.asyncFunction ? { asyncFunction: true } : {},
|
|
18373
|
+
...generatorDriver === void 0 ? {} : { driver: encode(generatorDriver) },
|
|
18374
|
+
...origin2.awaitPhase === void 0 ? {} : { awaitPhase: origin2.awaitPhase },
|
|
17806
18375
|
objectState: captureObjectState(value, encode),
|
|
17807
18376
|
scope: encode(origin2.scope),
|
|
17808
18377
|
closureScope: encode(origin2.closureScope),
|
|
@@ -17826,9 +18395,13 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17826
18395
|
expressionStates: Object.fromEntries([...origin2.expressionStates].map(([id, expression]) => [
|
|
17827
18396
|
String(id),
|
|
17828
18397
|
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
|
-
|
|
18398
|
+
kind: expression.kind,
|
|
18399
|
+
async: expression.async,
|
|
17830
18400
|
value: encode(expression.value),
|
|
17831
18401
|
current: encode(expression.current),
|
|
18402
|
+
...expression.phase === void 0 ? {} : { phase: expression.phase },
|
|
18403
|
+
...expression.awaitState === void 0 ? {} : { awaitState: expression.awaitState },
|
|
18404
|
+
...expression.completion === void 0 ? {} : { completion: { ...expression.completion, value: encode(expression.completion.value) } },
|
|
17832
18405
|
iterator: mapIteratorSnapshot("kind" in expression.iterator ? expression.iterator : expression.iterator.snapshot?.() ?? { kind: "unsupported" }, encode)
|
|
17833
18406
|
} : expression.kind === "pattern-source" ? { kind: "pattern-source", value: encode(expression.value) } : expression.kind === "object-pattern" ? {
|
|
17834
18407
|
kind: "object-pattern",
|
|
@@ -17849,10 +18422,15 @@ function captureGuestHeapNode(value, encode) {
|
|
|
17849
18422
|
iterator: mapIteratorSnapshot("kind" in expression.iterator ? expression.iterator : expression.iterator.snapshot?.() ?? { kind: "unsupported" }, encode),
|
|
17850
18423
|
...Object.hasOwn(expression, "referenceObject") ? { referenceObject: encode(expression.referenceObject), referenceKey: encode(expression.referenceKey) } : {}
|
|
17851
18424
|
} : expression.kind === "for-of-array" ? { ...expression, values: encode(expression.values), current: encode(expression.current), scope: encode(expression.scope) } : expression.kind === "for-of-iterator" ? {
|
|
17852
|
-
|
|
18425
|
+
kind: expression.kind,
|
|
18426
|
+
phase: expression.phase,
|
|
18427
|
+
async: expression.async,
|
|
18428
|
+
index: expression.index,
|
|
18429
|
+
...expression.awaitState === void 0 ? {} : { awaitState: expression.awaitState },
|
|
17853
18430
|
value: encode(expression.value),
|
|
17854
18431
|
current: encode(expression.current),
|
|
17855
18432
|
scope: encode(expression.scope),
|
|
18433
|
+
...expression.closeCompletion === void 0 ? {} : { closeCompletion: { ...expression.closeCompletion, value: encode(expression.closeCompletion.value) } },
|
|
17856
18434
|
iterator: mapIteratorSnapshot("kind" in expression.iterator ? expression.iterator : expression.iterator.snapshot?.() ?? { kind: "unsupported" }, encode)
|
|
17857
18435
|
} : 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
18436
|
kind: "member-assignment",
|
|
@@ -18228,6 +18806,29 @@ function serializeSafeJSSnapshot(snapshot) {
|
|
|
18228
18806
|
}
|
|
18229
18807
|
return JSON.stringify(createDumpFile(snapshot), null, 2);
|
|
18230
18808
|
}
|
|
18809
|
+
function requiresPromiseReplay(promise) {
|
|
18810
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18811
|
+
const pending = [promise];
|
|
18812
|
+
while (pending.length > 0) {
|
|
18813
|
+
const current = pending.pop();
|
|
18814
|
+
if (seen.has(current)) continue;
|
|
18815
|
+
seen.add(current);
|
|
18816
|
+
const continuation = promiseContinuations.get(current);
|
|
18817
|
+
if (promiseStates.get(current)?.status === "pending" && (unrepresentedPromiseContinuations.has(current) || continuation === void 0)) return true;
|
|
18818
|
+
pending.push(...promiseProducers.get(current) ?? [], ...promiseReactionResults.get(current) ?? []);
|
|
18819
|
+
if (continuation?.kind === "reaction") {
|
|
18820
|
+
pending.push(continuation.source);
|
|
18821
|
+
if (continuation.aggregate !== void 0) pending.push(continuation.aggregate);
|
|
18822
|
+
if (continuation.capability !== void 0) pending.push(continuation.capability.promise);
|
|
18823
|
+
} else if (continuation?.resolution !== void 0 && isSandboxPromise(continuation.resolution.value)) {
|
|
18824
|
+
pending.push(continuation.resolution.value);
|
|
18825
|
+
}
|
|
18826
|
+
const adoption = promiseAdoptions.get(current);
|
|
18827
|
+
const bridge = adoption === void 0 ? void 0 : promiseAdoptionBridges.get(adoption);
|
|
18828
|
+
if (bridge !== void 0) pending.push(bridge.source);
|
|
18829
|
+
}
|
|
18830
|
+
return false;
|
|
18831
|
+
}
|
|
18231
18832
|
function createDumpFile(snapshot) {
|
|
18232
18833
|
const state = {
|
|
18233
18834
|
trustedRunReplay: inMemoryRunSnapshots.has(snapshot),
|
|
@@ -18491,7 +19092,7 @@ function collectContainerStats(value, stats, ancestors, guestValues, trustedRunR
|
|
|
18491
19092
|
ancestors.add(value);
|
|
18492
19093
|
const guestEntries = [];
|
|
18493
19094
|
const replayPromise = isSandboxPromise(value) ? value : isPromiseResolvingFunction(value) ? promiseResolvingFunctions.get(value)?.promise : void 0;
|
|
18494
|
-
const replayMetadata = trustedRunReplay && replayPromise !== void 0 &&
|
|
19095
|
+
const replayMetadata = trustedRunReplay && replayPromise !== void 0 && requiresPromiseReplay(replayPromise);
|
|
18495
19096
|
if (isSandboxDataView(value)) guestEntries.push(dataViewBuffer(value));
|
|
18496
19097
|
if (isNumericTypedArray(value)) guestEntries.push(typedArrayStorage(value).buffer);
|
|
18497
19098
|
const guest = isSandboxDataView(value) ? { kind: "dataview", state: captureDataViewState(value, (entry) => {
|
|
@@ -22605,6 +23206,8 @@ function getGeneratorMember(target, property, budget) {
|
|
|
22605
23206
|
});
|
|
22606
23207
|
}
|
|
22607
23208
|
function callGeneratorMethod(target, method, value, budget, context, async) {
|
|
23209
|
+
if (async && isSandboxGenerator(target) && target.async === true)
|
|
23210
|
+
return enqueueAsyncGeneratorRequest(target, method, value, budget, context);
|
|
22608
23211
|
const result = (async () => {
|
|
22609
23212
|
if (!isSandboxGenerator(target) || target.async === true !== async)
|
|
22610
23213
|
throw new TypeError(`${async ? "AsyncGenerator" : "Generator"}.${method} requires a matching generator receiver.`);
|
|
@@ -24085,7 +24688,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24085
24688
|
createRawJson(node.text);
|
|
24086
24689
|
return true;
|
|
24087
24690
|
}
|
|
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;
|
|
24691
|
+
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
24692
|
const reference = (value, kinds) => {
|
|
24090
24693
|
const ref = record3(value);
|
|
24091
24694
|
fields(ref, ["kind", "id"]);
|
|
@@ -24096,10 +24699,15 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24096
24699
|
};
|
|
24097
24700
|
const callable = (value) => {
|
|
24098
24701
|
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"]);
|
|
24702
|
+
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
24703
|
if (target.kind === "intrinsic" && intrinsicCatalogue().get(String(target.id)) !== true)
|
|
24101
24704
|
throw new TypeError("Guest accessor reference is not callable.");
|
|
24102
24705
|
};
|
|
24706
|
+
if ((node.kind === "pending-promise" || node.kind === "guest-promise") && Object.hasOwn(node, "generatorOwner")) {
|
|
24707
|
+
const owner = reference(node.generatorOwner, ["async-generator-driver"]);
|
|
24708
|
+
if (!array(owner.requests).some((value) => reference(record3(record3(value).capability).promise) === node))
|
|
24709
|
+
throw new TypeError("Invalid async generator request ownership.");
|
|
24710
|
+
}
|
|
24103
24711
|
const privateIdentity = (value, expected) => {
|
|
24104
24712
|
const identity = reference(value, ["object"]);
|
|
24105
24713
|
fields(identity, ["kind", "entries"]);
|
|
@@ -24272,7 +24880,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24272
24880
|
throw new TypeError("Invalid promise resolver action.");
|
|
24273
24881
|
state(node.state);
|
|
24274
24882
|
} 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"]);
|
|
24883
|
+
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
24884
|
if (node.kind === "pending-promise" && Object.hasOwn(node, "thenable")) {
|
|
24277
24885
|
const continuation = reference(node.thenable, ["thenable-state"]);
|
|
24278
24886
|
if (Object.hasOwn(node, "adoption") || continuation.completed !== false || reference(continuation.owner) !== node)
|
|
@@ -24299,7 +24907,10 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24299
24907
|
} else if (handler.kind === "async-cleanup-handler") {
|
|
24300
24908
|
const cleanup = reference(handler.cleanup, ["async-cleanup"]);
|
|
24301
24909
|
owner = reference(record3(cleanup.capability).promise);
|
|
24302
|
-
}
|
|
24910
|
+
} else if (handler.kind === "async-function-handler") {
|
|
24911
|
+
const driver = reference(handler.driver, ["async-function-driver"]);
|
|
24912
|
+
owner = reference(record3(driver.capability).promise);
|
|
24913
|
+
} else if (handler.kind === "async-generator-handler") owner = reference(handler.owner);
|
|
24303
24914
|
if (owner !== void 0 && owner !== aggregate) throw new TypeError("Invalid promise aggregate handler ownership.");
|
|
24304
24915
|
}
|
|
24305
24916
|
}
|
|
@@ -24328,7 +24939,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24328
24939
|
}
|
|
24329
24940
|
state(node.state);
|
|
24330
24941
|
} else if (node.kind === "guest-promise") {
|
|
24331
|
-
fields(node, ["kind", "status", "value", "state"], ["reactions", "producers"]);
|
|
24942
|
+
fields(node, ["kind", "status", "value", "state"], ["reactions", "producers", "generatorOwner"]);
|
|
24332
24943
|
if (Object.hasOwn(node, "reactions")) {
|
|
24333
24944
|
if (!Array.isArray(node.reactions)) throw new TypeError("Invalid promise reactions.");
|
|
24334
24945
|
const reactions = /* @__PURE__ */ new Set();
|
|
@@ -24402,7 +25013,8 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24402
25013
|
if (resources.length > maxArrayLength) throw new TypeError("Too many async resources.");
|
|
24403
25014
|
for (const rawResource of resources) {
|
|
24404
25015
|
const resource = record3(rawResource);
|
|
24405
|
-
fields(resource, ["method", "receiver", "args", "syncFallback"]);
|
|
25016
|
+
fields(resource, ["method", "receiver", "args", "syncFallback"], ["synchronous"]);
|
|
25017
|
+
if (resource.synchronous !== void 0 && (resource.synchronous !== true || resource.syncFallback || absent(resource.method))) throw new TypeError("Invalid synchronous resource.");
|
|
24406
25018
|
const args = array(resource.args);
|
|
24407
25019
|
if (typeof resource.syncFallback !== "boolean" || args.length > 1) throw new TypeError("Invalid async resource.");
|
|
24408
25020
|
if (absent(resource.method)) {
|
|
@@ -24426,6 +25038,55 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24426
25038
|
throw new TypeError("Invalid async cleanup resolver ownership.");
|
|
24427
25039
|
}
|
|
24428
25040
|
}
|
|
25041
|
+
} else if (node.kind === "async-generator-driver") {
|
|
25042
|
+
fields(node, ["kind", "generator", "requests", "phase", "suspension", "awaitKind", "generation"]);
|
|
25043
|
+
const generator = reference(node.generator, ["guest-generator"]);
|
|
25044
|
+
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.");
|
|
25045
|
+
integer(node.generation);
|
|
25046
|
+
if (!Array.isArray(node.requests) || node.phase === "idle" !== (node.requests.length === 0)) throw new TypeError("Invalid async generator request queue.");
|
|
25047
|
+
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.");
|
|
25048
|
+
const owners = /* @__PURE__ */ new Set();
|
|
25049
|
+
for (const value of node.requests) {
|
|
25050
|
+
const request = record3(value);
|
|
25051
|
+
fields(request, ["method", "value", "capability"]);
|
|
25052
|
+
if (!["next", "return", "throw"].includes(String(request.method))) throw new TypeError("Invalid async generator request operation.");
|
|
25053
|
+
const capability = record3(request.capability);
|
|
25054
|
+
fields(capability, ["promise", "resolve", "reject"]);
|
|
25055
|
+
const owner = reference(capability.promise, ["pending-promise", "guest-promise"]);
|
|
25056
|
+
if (owners.has(owner)) throw new TypeError("Duplicate async generator request owner.");
|
|
25057
|
+
if (reference(owner.generatorOwner, ["async-generator-driver"]) !== node) throw new TypeError("Invalid async generator request ownership.");
|
|
25058
|
+
owners.add(owner);
|
|
25059
|
+
for (const key of ["resolve", "reject"]) {
|
|
25060
|
+
const resolver = reference(capability[key], ["promise-resolver"]);
|
|
25061
|
+
if (reference(resolver.promise) !== owner || resolver.action !== void 0 && resolver.action !== (key === "resolve" ? "fulfilled" : "rejected"))
|
|
25062
|
+
throw new TypeError("Invalid async generator resolver ownership.");
|
|
25063
|
+
}
|
|
25064
|
+
}
|
|
25065
|
+
} else if (node.kind === "async-generator-handler") {
|
|
25066
|
+
fields(node, ["kind", "driver", "owner", "action", "generation", "state"]);
|
|
25067
|
+
const driver = reference(node.driver, ["async-generator-driver"]);
|
|
25068
|
+
const owner = reference(node.owner, ["pending-promise", "guest-promise"]);
|
|
25069
|
+
if (!["fulfilled", "rejected"].includes(String(node.action)) || integer(node.generation) > integer(driver.generation)) throw new TypeError("Invalid async generator handler.");
|
|
25070
|
+
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.");
|
|
25071
|
+
state(node.state);
|
|
25072
|
+
} else if (node.kind === "async-function-driver") {
|
|
25073
|
+
fields(node, ["kind", "generator", "capability", "phase", "generation"]);
|
|
25074
|
+
const generator = reference(node.generator, ["guest-generator"]);
|
|
25075
|
+
if (generator.asyncFunction !== true || !["waiting", "done"].includes(String(node.phase))) throw new TypeError("Invalid async function frame.");
|
|
25076
|
+
integer(node.generation);
|
|
25077
|
+
const capability = record3(node.capability);
|
|
25078
|
+
fields(capability, ["promise", "resolve", "reject"]);
|
|
25079
|
+
const owner = reference(capability.promise, ["pending-promise", "guest-promise"]);
|
|
25080
|
+
for (const key of ["resolve", "reject"]) {
|
|
25081
|
+
const resolver = reference(capability[key], ["promise-resolver"]);
|
|
25082
|
+
if (reference(resolver.promise) !== owner || resolver.action !== void 0 && resolver.action !== (key === "resolve" ? "fulfilled" : "rejected"))
|
|
25083
|
+
throw new TypeError("Invalid async function resolver ownership.");
|
|
25084
|
+
}
|
|
25085
|
+
} else if (node.kind === "async-function-handler") {
|
|
25086
|
+
fields(node, ["kind", "driver", "action", "generation", "state"]);
|
|
25087
|
+
const driver = reference(node.driver, ["async-function-driver"]);
|
|
25088
|
+
if (node.action !== "fulfilled" && node.action !== "rejected" || integer(node.generation) > integer(driver.generation)) throw new TypeError("Invalid async function handler.");
|
|
25089
|
+
state(node.state);
|
|
24429
25090
|
} else if (node.kind === "async-cleanup-handler") {
|
|
24430
25091
|
fields(node, ["kind", "cleanup", "action", "generation", "state"]);
|
|
24431
25092
|
const cleanup = reference(node.cleanup, ["async-cleanup"]);
|
|
@@ -24567,7 +25228,10 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24567
25228
|
}
|
|
24568
25229
|
state(node.state);
|
|
24569
25230
|
} else if (node.kind === "guest-generator") {
|
|
24570
|
-
fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates", "objectState"]);
|
|
25231
|
+
fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates", "objectState", "asyncFunction", "driver", "awaitPhase"]);
|
|
25232
|
+
if (node.asyncFunction !== void 0 && (node.asyncFunction !== true || node.async !== false)) throw new TypeError("Invalid async function suspension frame.");
|
|
25233
|
+
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.");
|
|
25234
|
+
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
25235
|
if (Object.hasOwn(node, "objectState")) state(node.objectState);
|
|
24572
25236
|
if (!["start", "running", "suspended", "done"].includes(String(node.state)) || typeof node.async !== "boolean" || integer(node.astNodeId) < 1)
|
|
24573
25237
|
throw new TypeError("Invalid generator state.");
|
|
@@ -24602,8 +25266,24 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24602
25266
|
if (Object.hasOwn(expression, "referenceKey") && typeof expression.referenceKey !== "string") reference(expression.referenceKey, ["symbol"]);
|
|
24603
25267
|
} else if (expression.kind === "for-of-array" || expression.kind === "for-of-iterator" || expression.kind === "array-pattern" || expression.kind === "yield-delegate") {
|
|
24604
25268
|
if (expression.kind === "yield-delegate") {
|
|
24605
|
-
fields(expression, ["kind", "async", "value", "current", "iterator"]);
|
|
25269
|
+
fields(expression, ["kind", "async", "value", "current", "iterator"], ["phase", "awaitState", "completion"]);
|
|
24606
25270
|
if (typeof expression.async !== "boolean") throw new TypeError("Invalid delegated yield protocol.");
|
|
25271
|
+
if (expression.phase !== void 0) {
|
|
25272
|
+
if (!["await", "close"].includes(String(expression.phase)) || expression.async !== true || node.awaitPhase !== "await" || node.yieldNodeId !== Number(id))
|
|
25273
|
+
throw new TypeError("Invalid delegated iterator wait position.");
|
|
25274
|
+
const completion = record3(expression.completion);
|
|
25275
|
+
fields(completion, ["type", "value"]);
|
|
25276
|
+
if (!["normal", "return", "throw"].includes(String(completion.type)) || expression.phase === "close" && completion.type !== "throw")
|
|
25277
|
+
throw new TypeError("Invalid delegated iterator completion.");
|
|
25278
|
+
const awaiting = record3(expression.awaitState);
|
|
25279
|
+
if (awaiting.kind === "result") fields(awaiting, ["kind"]);
|
|
25280
|
+
else if (awaiting.kind === "value") {
|
|
25281
|
+
fields(awaiting, ["kind", "done", "closeOnReject"]);
|
|
25282
|
+
if (typeof awaiting.done !== "boolean" || typeof awaiting.closeOnReject !== "boolean" || awaiting.closeOnReject !== (expression.phase === "await" && completion.type !== "return" && !awaiting.done))
|
|
25283
|
+
throw new TypeError("Invalid delegated async-from-sync continuation.");
|
|
25284
|
+
} else throw new TypeError("Invalid delegated iterator await kind.");
|
|
25285
|
+
} else if (expression.awaitState !== void 0 || expression.completion !== void 0)
|
|
25286
|
+
throw new TypeError("Unexpected delegated iterator continuation fields.");
|
|
24607
25287
|
} else if (expression.kind === "array-pattern") {
|
|
24608
25288
|
fields(expression, ["kind", "phase", "index", "done", "current", "iterator"], ["referenceObject", "referenceKey", "privateName"]);
|
|
24609
25289
|
if (expression.privateName !== void 0 && (typeof expression.privateName !== "string" || !Object.hasOwn(expression, "referenceObject"))) throw new TypeError("Invalid private pattern reference.");
|
|
@@ -24617,8 +25297,26 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24617
25297
|
"index",
|
|
24618
25298
|
"scope",
|
|
24619
25299
|
...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.");
|
|
25300
|
+
], ["awaitState", "closeCompletion"]);
|
|
25301
|
+
if (!["left", "body", "next", "close"].includes(String(expression.phase))) throw new TypeError("Invalid for-of phase.");
|
|
25302
|
+
if (expression.phase === "next" || expression.phase === "close") {
|
|
25303
|
+
if (expression.kind !== "for-of-iterator" || expression.async !== true) throw new TypeError("Invalid async iterator suspension.");
|
|
25304
|
+
const awaiting = record3(expression.awaitState);
|
|
25305
|
+
if (awaiting.kind === "result") fields(awaiting, ["kind"]);
|
|
25306
|
+
else if (awaiting.kind === "value") {
|
|
25307
|
+
fields(awaiting, ["kind", "done", "closeOnReject"]);
|
|
25308
|
+
if (typeof awaiting.done !== "boolean" || typeof awaiting.closeOnReject !== "boolean" || awaiting.closeOnReject !== (expression.phase === "next" && !awaiting.done))
|
|
25309
|
+
throw new TypeError("Invalid async-from-sync continuation.");
|
|
25310
|
+
} else throw new TypeError("Invalid iterator await kind.");
|
|
25311
|
+
} else if (Object.hasOwn(expression, "awaitState")) throw new TypeError("Unexpected iterator await state.");
|
|
25312
|
+
if (expression.phase === "close") {
|
|
25313
|
+
const completion = record3(expression.closeCompletion);
|
|
25314
|
+
fields(completion, ["kind", "hasValue", "value"], ["span", "stackFrames", "label"]);
|
|
25315
|
+
if (!["normal", "return", "throw", "break", "continue"].includes(String(completion.kind)) || typeof completion.hasValue !== "boolean")
|
|
25316
|
+
throw new TypeError("Invalid iterator close completion.");
|
|
25317
|
+
if (completion.label !== void 0 && typeof completion.label !== "string") throw new TypeError("Invalid iterator close label.");
|
|
25318
|
+
if (completion.stackFrames !== void 0 && array(completion.stackFrames).some((frame) => typeof frame !== "string")) throw new TypeError("Invalid iterator close stack.");
|
|
25319
|
+
} else if (Object.hasOwn(expression, "closeCompletion")) throw new TypeError("Unexpected iterator close completion.");
|
|
24622
25320
|
reference(expression.scope, ["scope-frame"]);
|
|
24623
25321
|
}
|
|
24624
25322
|
if (expression.kind !== "yield-delegate") integer(expression.index);
|
|
@@ -24633,6 +25331,8 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24633
25331
|
iterator = record3(iterator.inner);
|
|
24634
25332
|
protocol = true;
|
|
24635
25333
|
}
|
|
25334
|
+
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"))
|
|
25335
|
+
throw new TypeError("Iterator await state does not match its adapter.");
|
|
24636
25336
|
if (iterator.kind === "guest") {
|
|
24637
25337
|
fields(iterator, ["kind", "value", "next", "async"]);
|
|
24638
25338
|
if (typeof iterator.async !== "boolean") throw new TypeError("Invalid iterator protocol.");
|
|
@@ -24673,7 +25373,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24673
25373
|
reference(expression.scope, ["scope-frame"]);
|
|
24674
25374
|
} else if (expression.kind === "for") {
|
|
24675
25375
|
fields(expression, ["kind", "phase", "loopScope", "activeScope"]);
|
|
24676
|
-
if (!["init", "test", "body", "update"].includes(String(expression.phase))) throw new TypeError("Invalid for-loop phase.");
|
|
25376
|
+
if (!["init", "test", "body", "update", "dispose"].includes(String(expression.phase))) throw new TypeError("Invalid for-loop phase.");
|
|
24677
25377
|
reference(expression.loopScope, ["scope-frame"]);
|
|
24678
25378
|
reference(expression.activeScope, ["scope-frame"]);
|
|
24679
25379
|
} else if (expression.kind === "identifier-assignment") {
|
|
@@ -24736,7 +25436,8 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24736
25436
|
if (Object.hasOwn(environment, "construction")) reference(environment.construction, ["construction-environment"]);
|
|
24737
25437
|
}
|
|
24738
25438
|
} else {
|
|
24739
|
-
fields(node, ["kind", "parent", "importMeta", "functionBoundary", "chargeData", "bindings", "cells"], ["restoredBindings", "privateNames"]);
|
|
25439
|
+
fields(node, ["kind", "parent", "importMeta", "functionBoundary", "chargeData", "bindings", "cells"], ["restoredBindings", "privateNames", "resourceState"]);
|
|
25440
|
+
if (node.resourceState !== void 0) reference(node.resourceState, ["object"]);
|
|
24740
25441
|
if (node.privateNames !== void 0) {
|
|
24741
25442
|
const names2 = /* @__PURE__ */ new Set();
|
|
24742
25443
|
for (const raw2 of array(node.privateNames)) {
|
|
@@ -24810,6 +25511,11 @@ function privateAssignmentName(value) {
|
|
|
24810
25511
|
const property = node.property;
|
|
24811
25512
|
return property.type === "PrivateIdentifier" ? String(property.name) : void 0;
|
|
24812
25513
|
}
|
|
25514
|
+
function asyncResourceDeclaration(value) {
|
|
25515
|
+
if (value === null || typeof value !== "object") return false;
|
|
25516
|
+
const node = value;
|
|
25517
|
+
return node.type === "VariableDeclaration" && node.disposal === "async";
|
|
25518
|
+
}
|
|
24813
25519
|
function validateGuestFunctionAst(record4, origin) {
|
|
24814
25520
|
if (record4.kind === "guest-class") {
|
|
24815
25521
|
if (origin === null || typeof origin !== "object" || !["ClassDeclaration", "ClassExpression"].includes(String(origin.type)))
|
|
@@ -24833,7 +25539,8 @@ function validateGuestFunctionAst(record4, origin) {
|
|
|
24833
25539
|
throw new TypeError("Unknown guest function AST identity");
|
|
24834
25540
|
if (record4.kind !== "guest-generator") return;
|
|
24835
25541
|
const functionNode = origin;
|
|
24836
|
-
|
|
25542
|
+
const representedAsync = record4.asyncFunction === true || record4.async === true && record4.driver !== void 0;
|
|
25543
|
+
if (record4.asyncFunction === true ? functionNode.async !== true || functionNode.generator === true || record4.async !== false : functionNode.generator !== true || functionNode.async === true !== record4.async)
|
|
24837
25544
|
throw new TypeError("Invalid generator AST identity");
|
|
24838
25545
|
let yieldBlocks;
|
|
24839
25546
|
let yieldFinalizers;
|
|
@@ -24848,10 +25555,29 @@ function validateGuestFunctionAst(record4, origin) {
|
|
|
24848
25555
|
if (["ArrowFunctionExpression", "FunctionExpression", "FunctionDeclaration"].includes(String(node.type))) continue;
|
|
24849
25556
|
let blocks = frame.blocks;
|
|
24850
25557
|
if (node.type === "BlockStatement" && typeof node.nodeId === "number") blocks = /* @__PURE__ */ new Set([...blocks, node.nodeId]);
|
|
24851
|
-
|
|
25558
|
+
const cases = node.type === "SwitchStatement" ? node.cases : void 0;
|
|
25559
|
+
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)));
|
|
25560
|
+
const iteratorBoundary = representedAsync && node.type === "ForOfStatement" && node.await === true && ["next", "close"].includes(record4.expressionStates?.[String(node.nodeId)]?.phase ?? "");
|
|
25561
|
+
const delegateBoundary = representedAsync && node.type === "YieldExpression" && node.delegate === true && ["await", "close"].includes(record4.expressionStates?.[String(node.nodeId)]?.phase ?? "");
|
|
25562
|
+
if ((node.type === "YieldExpression" || representedAsync && node.type === "AwaitExpression" || record4.awaitPhase === "return" && node.type === "ReturnStatement" || resourceBoundary || iteratorBoundary) && node.nodeId === record4.yieldNodeId) {
|
|
25563
|
+
if (record4.awaitPhase !== void 0) {
|
|
25564
|
+
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);
|
|
25565
|
+
if (!valid) throw new TypeError("Invalid async generator await source position.");
|
|
25566
|
+
}
|
|
24852
25567
|
yieldBlocks = blocks;
|
|
24853
25568
|
yieldFinalizers = frame.finalizers;
|
|
24854
25569
|
yieldExpressions = node.delegate === true && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "yield-delegate", async: record4.async === true }]]) : frame.expressions;
|
|
25570
|
+
if (resourceBoundary && typeof node.nodeId === "number") {
|
|
25571
|
+
if (node.type === "ForOfStatement") yieldExpressions = new Map([...frame.expressions, [node.nodeId, { kind: "for-of", phase: "body", async: node.await === true }]]);
|
|
25572
|
+
if (node.type === "ForStatement") yieldExpressions = new Map([...frame.expressions, [node.nodeId, { kind: "for", phase: "dispose" }]]);
|
|
25573
|
+
if (cases !== void 0) {
|
|
25574
|
+
const progress = record4.expressionStates?.[String(node.nodeId)];
|
|
25575
|
+
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.");
|
|
25576
|
+
yieldExpressions = new Map([...frame.expressions, [node.nodeId, { kind: "switch", phase: "body", index: progress.index, statementIndex: progress.statementIndex }]]);
|
|
25577
|
+
}
|
|
25578
|
+
}
|
|
25579
|
+
if (iteratorBoundary && typeof node.nodeId === "number")
|
|
25580
|
+
yieldExpressions = new Map([...frame.expressions, [node.nodeId, { kind: "for-of", phase: record4.expressionStates[String(node.nodeId)].phase, async: true }]]);
|
|
24855
25581
|
}
|
|
24856
25582
|
for (const [key, value] of Object.entries(node)) {
|
|
24857
25583
|
if (node.type === "SwitchStatement" && key === "cases" && typeof node.nodeId === "number" && Array.isArray(value)) {
|
|
@@ -26132,6 +26858,91 @@ function bigIntOperation(operator, left, right, budget) {
|
|
|
26132
26858
|
}
|
|
26133
26859
|
}
|
|
26134
26860
|
|
|
26861
|
+
// packages/safe-js/src/interp/resource-management.ts
|
|
26862
|
+
function resourceSuspension(context, node) {
|
|
26863
|
+
return context.asyncFunction || context.asyncGeneratorFrame !== void 0 ? {
|
|
26864
|
+
awaitResource: (value) => suspendAsyncFunctionValue(value, node, context),
|
|
26865
|
+
resumeResource: context.generatorResume?.completed !== true && context.generatorResume?.yieldNodeId === node.nodeId
|
|
26866
|
+
} : {};
|
|
26867
|
+
}
|
|
26868
|
+
async function registerScopeResource(scope, value, hint, budget, context) {
|
|
26869
|
+
if (hint === "sync" && (value === null || value === void 0)) return;
|
|
26870
|
+
const state = scope.resourceState ??= { resources: [] };
|
|
26871
|
+
if (value === null || value === void 0) {
|
|
26872
|
+
state.resources.push({ method: void 0, receiver: void 0, args: [], syncFallback: false });
|
|
26873
|
+
createDataCheckpoint(budget, context)(state, 0, true);
|
|
26874
|
+
return;
|
|
26875
|
+
}
|
|
26876
|
+
if (typeof value !== "object") throw new TypeError("Disposable resource must be an object.");
|
|
26877
|
+
const read = async (key) => {
|
|
26878
|
+
if (context?.getProperty !== void 0) return context.getProperty(value, key);
|
|
26879
|
+
const descriptor = getSandboxPropertyDescriptor(value, key, budget);
|
|
26880
|
+
return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
|
|
26881
|
+
};
|
|
26882
|
+
let method = await read(hint === "async" ? wellKnownSymbols.asyncDispose : wellKnownSymbols.dispose);
|
|
26883
|
+
let syncFallback = false;
|
|
26884
|
+
if (hint === "async" && (method === void 0 || method === null)) {
|
|
26885
|
+
method = await read(wellKnownSymbols.dispose);
|
|
26886
|
+
syncFallback = true;
|
|
26887
|
+
}
|
|
26888
|
+
if (!isSandboxClosure(method)) throw new TypeError("Disposer must be callable.");
|
|
26889
|
+
state.resources.push({ method, receiver: value, args: [], syncFallback, ...hint === "sync" ? { synchronous: true } : {} });
|
|
26890
|
+
createDataCheckpoint(budget, context)(state, 0, true);
|
|
26891
|
+
}
|
|
26892
|
+
async function evaluateResourceScope(scope, budget, context, body) {
|
|
26893
|
+
let completion;
|
|
26894
|
+
try {
|
|
26895
|
+
completion = scope.resourceState?.completion ?? await body();
|
|
26896
|
+
} catch (error) {
|
|
26897
|
+
if (scope.resourceState === void 0 || isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
|
|
26898
|
+
completion = createThrowCompletion(error, budget, context?.stack ?? []);
|
|
26899
|
+
}
|
|
26900
|
+
const state = scope.resourceState;
|
|
26901
|
+
if (state === void 0 || state.resources.length === 0 && state.cleanup === void 0) return completion;
|
|
26902
|
+
if (completion.kind === "error") return completion;
|
|
26903
|
+
state.completion = { ...completion, ...completion.stackFrames === void 0 ? { stackFrames: void 0 } : { stackFrames: [...completion.stackFrames] } };
|
|
26904
|
+
const release = retainValues(budget, () => [state]);
|
|
26905
|
+
try {
|
|
26906
|
+
if (state.cleanup === void 0) {
|
|
26907
|
+
const capability = createPendingPromiseCapability(budget, context);
|
|
26908
|
+
const cleanup2 = {
|
|
26909
|
+
resources: state.resources,
|
|
26910
|
+
capability: { promise: capability.promise, resolve: capability.resolve, reject: capability.reject },
|
|
26911
|
+
phase: "running",
|
|
26912
|
+
failed: completion.kind === "throw",
|
|
26913
|
+
failure: completion.kind === "throw" ? completion.value : void 0,
|
|
26914
|
+
needsAwait: false,
|
|
26915
|
+
hasAwaited: false,
|
|
26916
|
+
generation: 0
|
|
26917
|
+
};
|
|
26918
|
+
state.resources = [];
|
|
26919
|
+
state.cleanup = cleanup2;
|
|
26920
|
+
asyncCleanupStates.set(cleanup2, cleanup2);
|
|
26921
|
+
await advanceAsyncCleanup(cleanup2, budget, context);
|
|
26922
|
+
}
|
|
26923
|
+
const cleanup = state.cleanup;
|
|
26924
|
+
try {
|
|
26925
|
+
if (context?.awaitResource !== void 0) {
|
|
26926
|
+
if (cleanup.phase !== "done" || context.resumeResource) await context.awaitResource(cleanup.capability.promise);
|
|
26927
|
+
else observeSandboxPromise(cleanup.capability.promise, true);
|
|
26928
|
+
} else {
|
|
26929
|
+
const settled = awaitSandboxValue(cleanup.capability.promise, context?.signal, budget, context);
|
|
26930
|
+
if (cleanup.phase === "done") await settled;
|
|
26931
|
+
else {
|
|
26932
|
+
context?.onSuspend?.();
|
|
26933
|
+
await suspendJob(settled);
|
|
26934
|
+
}
|
|
26935
|
+
}
|
|
26936
|
+
} catch (error) {
|
|
26937
|
+
if (cleanup.phase !== "done" || isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
|
|
26938
|
+
}
|
|
26939
|
+
return cleanup.failed ? { kind: "throw", hasValue: true, value: cleanup.failure } : completion;
|
|
26940
|
+
} finally {
|
|
26941
|
+
if (state.cleanup?.phase === "done") scope.resourceState = void 0;
|
|
26942
|
+
release();
|
|
26943
|
+
}
|
|
26944
|
+
}
|
|
26945
|
+
|
|
26135
26946
|
// packages/safe-js/src/interp/resume-target.ts
|
|
26136
26947
|
function containsResumeTarget(node, targetNodeIds) {
|
|
26137
26948
|
if (targetNodeIds === void 0 ? node.type === "YieldExpression" : node.nodeId !== void 0 && targetNodeIds.has(node.nodeId)) {
|
|
@@ -26292,9 +27103,10 @@ async function interpret(node, options = {}) {
|
|
|
26292
27103
|
asyncGenerator: options.asyncGenerator,
|
|
26293
27104
|
resumeTarget: { nodeId: options.snapshot?.resumeNodeId }
|
|
26294
27105
|
};
|
|
27106
|
+
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
27107
|
const evaluation = await withCancellationSignal(
|
|
26296
27108
|
options.signal,
|
|
26297
|
-
() => options.nested ? runAsyncPrefix(
|
|
27109
|
+
() => options.nested ? runAsyncPrefix(execute) : jobs.run(execute)
|
|
26298
27110
|
);
|
|
26299
27111
|
if (!options.nested) await jobs.drain();
|
|
26300
27112
|
const snapshot = scope.snapshot();
|
|
@@ -27119,6 +27931,7 @@ async function evaluateVariableDeclaration(node, context) {
|
|
|
27119
27931
|
};
|
|
27120
27932
|
const release = retainValues(context.budget, () => [value.value]);
|
|
27121
27933
|
try {
|
|
27934
|
+
if (node.disposal !== void 0) await registerScopeResource(context.scope, value.value, node.disposal, context.budget, createCoercionContext(context));
|
|
27122
27935
|
const binding = await bindPattern(
|
|
27123
27936
|
declarator.id,
|
|
27124
27937
|
value.value,
|
|
@@ -27208,24 +28021,26 @@ async function evaluateBlockStatement(node, context) {
|
|
|
27208
28021
|
const blockContext = createBlockContext(node, context);
|
|
27209
28022
|
const resumeIndex = findResumeStatementIndex(node, blockContext);
|
|
27210
28023
|
const generatorResumeIndex = findGeneratorResumeStatementIndex(node, blockContext);
|
|
27211
|
-
|
|
27212
|
-
|
|
27213
|
-
|
|
27214
|
-
|
|
27215
|
-
|
|
27216
|
-
|
|
27217
|
-
|
|
27218
|
-
|
|
27219
|
-
|
|
27220
|
-
|
|
27221
|
-
|
|
28024
|
+
return evaluateResourceScope(blockContext.scope, context.budget, { ...createCoercionContext(blockContext), ...resourceSuspension(blockContext, node), onSuspend: blockContext.onSuspend, signal: blockContext.signal }, async () => {
|
|
28025
|
+
for (let index = 0; index < node.body.length; index += 1) {
|
|
28026
|
+
const statement = node.body[index];
|
|
28027
|
+
if (generatorResumeIndex !== void 0 && index < generatorResumeIndex) {
|
|
28028
|
+
continue;
|
|
28029
|
+
}
|
|
28030
|
+
if (resumeIndex !== void 0 && index < resumeIndex && statement.type !== "VariableDeclaration") {
|
|
28031
|
+
continue;
|
|
28032
|
+
}
|
|
28033
|
+
const result = await evaluateNode(statement, blockContext);
|
|
28034
|
+
if (result.kind !== "normal") {
|
|
28035
|
+
return result;
|
|
28036
|
+
}
|
|
27222
28037
|
}
|
|
27223
|
-
|
|
27224
|
-
|
|
27225
|
-
|
|
27226
|
-
|
|
27227
|
-
|
|
27228
|
-
};
|
|
28038
|
+
return {
|
|
28039
|
+
kind: "normal",
|
|
28040
|
+
hasValue: false,
|
|
28041
|
+
value: void 0
|
|
28042
|
+
};
|
|
28043
|
+
});
|
|
27229
28044
|
}
|
|
27230
28045
|
function findGeneratorResumeStatementIndex(node, context) {
|
|
27231
28046
|
if (context.generatorResume === void 0) {
|
|
@@ -27334,44 +28149,46 @@ async function evaluateSwitchStatement(node, context) {
|
|
|
27334
28149
|
);
|
|
27335
28150
|
const release = retainValues(context.budget, () => [progress.value]);
|
|
27336
28151
|
try {
|
|
27337
|
-
|
|
27338
|
-
|
|
27339
|
-
|
|
27340
|
-
|
|
27341
|
-
|
|
27342
|
-
|
|
27343
|
-
|
|
27344
|
-
|
|
27345
|
-
|
|
27346
|
-
|
|
27347
|
-
|
|
28152
|
+
return await evaluateResourceScope(progress.scope, context.budget, { ...createCoercionContext(switchContext), ...resourceSuspension(switchContext, node), onSuspend: switchContext.onSuspend, signal: switchContext.signal }, async () => {
|
|
28153
|
+
const defaultIndex = node.cases.findIndex((entry) => entry.test === void 0);
|
|
28154
|
+
let startIndex = saved?.phase === "body" ? saved.index : void 0;
|
|
28155
|
+
for (let index = progress.index; startIndex === void 0 && index < node.cases.length; index += 1) {
|
|
28156
|
+
const switchCase = node.cases[index];
|
|
28157
|
+
if (switchCase.test === void 0) {
|
|
28158
|
+
continue;
|
|
28159
|
+
}
|
|
28160
|
+
progress.index = index;
|
|
28161
|
+
const test = await evaluateNode(switchCase.test, switchContext);
|
|
28162
|
+
if (test.kind !== "normal") {
|
|
28163
|
+
return test;
|
|
28164
|
+
}
|
|
28165
|
+
if (discriminant.value === test.value) {
|
|
28166
|
+
startIndex = index;
|
|
28167
|
+
break;
|
|
28168
|
+
}
|
|
27348
28169
|
}
|
|
27349
|
-
|
|
27350
|
-
|
|
27351
|
-
|
|
28170
|
+
startIndex ??= defaultIndex < 0 ? void 0 : defaultIndex;
|
|
28171
|
+
if (startIndex === void 0) {
|
|
28172
|
+
return normalEmptyResult();
|
|
27352
28173
|
}
|
|
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;
|
|
28174
|
+
for (let caseIndex = startIndex; caseIndex < node.cases.length; caseIndex += 1) {
|
|
28175
|
+
progress.phase = "body";
|
|
28176
|
+
progress.index = caseIndex;
|
|
28177
|
+
const statements = node.cases[caseIndex].consequent;
|
|
28178
|
+
for (let statementIndex = saved?.phase === "body" && caseIndex === saved.index ? saved.statementIndex : 0; statementIndex < statements.length; statementIndex++) {
|
|
28179
|
+
progress.statementIndex = statementIndex;
|
|
28180
|
+
const statement = statements[statementIndex];
|
|
28181
|
+
const result = await evaluateNode(statement, switchContext);
|
|
28182
|
+
if (result.kind === "break" && result.label === void 0) {
|
|
28183
|
+
return normalEmptyResult();
|
|
28184
|
+
}
|
|
28185
|
+
if (result.kind !== "normal") {
|
|
28186
|
+
return result;
|
|
28187
|
+
}
|
|
27371
28188
|
}
|
|
27372
28189
|
}
|
|
27373
|
-
|
|
27374
|
-
|
|
28190
|
+
return normalEmptyResult();
|
|
28191
|
+
});
|
|
27375
28192
|
} finally {
|
|
27376
28193
|
release();
|
|
27377
28194
|
}
|
|
@@ -27440,7 +28257,7 @@ async function evaluateForOfStatement(node, context) {
|
|
|
27440
28257
|
}
|
|
27441
28258
|
const iterationContext = createLoopIterationContext(phaseContext("body"), scope);
|
|
27442
28259
|
emitLoopIterationBreakpoint(node, iterationContext);
|
|
27443
|
-
const result = await evaluateNode(node.body, iterationContext);
|
|
28260
|
+
const result = await evaluateResourceScope(scope, context.budget, { ...createCoercionContext(iterationContext), ...resourceSuspension(iterationContext, node), onSuspend: iterationContext.onSuspend, signal: iterationContext.signal }, () => evaluateNode(node.body, iterationContext));
|
|
27444
28261
|
if (isMatchingBreak(result, loopLabels(node))) {
|
|
27445
28262
|
context.activeLoopIterations.delete(node.nodeId ?? -1);
|
|
27446
28263
|
return {
|
|
@@ -27467,12 +28284,43 @@ async function evaluateForOfStatement(node, context) {
|
|
|
27467
28284
|
async function evaluateForOfIterator(node, value, context, restoredEntry) {
|
|
27468
28285
|
const saved = context.generatorResume === void 0 || node.nodeId === void 0 ? void 0 : context.restoredGeneratorExpressionStates?.get(node.nodeId);
|
|
27469
28286
|
if (saved !== void 0 && saved.kind !== "for-of-iterator") throw new TypeError("Invalid iterator continuation.");
|
|
27470
|
-
let resumeCurrent = saved !== void 0;
|
|
28287
|
+
let resumeCurrent = saved !== void 0 && saved.phase !== "next";
|
|
28288
|
+
let resumeNext = saved?.phase === "next";
|
|
28289
|
+
let index = saved?.index ?? consumeRestoredLoopIterationIndex(node, context);
|
|
27471
28290
|
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
28291
|
if (iterator === void 0) {
|
|
27473
28292
|
throw new TypeError(`${String(value)} is not a supported iterable`);
|
|
27474
28293
|
}
|
|
27475
28294
|
const nextIteration = async () => {
|
|
28295
|
+
if ((context.asyncFunction || context.asyncGeneratorFrame !== void 0) && node.await && iterator.resumeAwait !== void 0 && node.nodeId !== void 0) {
|
|
28296
|
+
iterator.awaitValue = (awaited, awaitState) => suspendAsyncFunctionValue(awaited, node, {
|
|
28297
|
+
...context,
|
|
28298
|
+
generatorExpressionStates: new Map([
|
|
28299
|
+
...context.generatorExpressionStates ?? [],
|
|
28300
|
+
[node.nodeId, {
|
|
28301
|
+
kind: "for-of-iterator",
|
|
28302
|
+
phase: "next",
|
|
28303
|
+
awaitState,
|
|
28304
|
+
async: true,
|
|
28305
|
+
value,
|
|
28306
|
+
current: void 0,
|
|
28307
|
+
index,
|
|
28308
|
+
scope: context.scope,
|
|
28309
|
+
iterator
|
|
28310
|
+
}]
|
|
28311
|
+
])
|
|
28312
|
+
}, void 0, createCoercionContext(context));
|
|
28313
|
+
try {
|
|
28314
|
+
if (resumeNext) {
|
|
28315
|
+
resumeNext = false;
|
|
28316
|
+
if (saved?.awaitState === void 0) throw new TypeError("Missing iterator await continuation.");
|
|
28317
|
+
return await iterator.resumeAwait(saved.awaitState, () => iterator.awaitValue(void 0, saved.awaitState));
|
|
28318
|
+
}
|
|
28319
|
+
return await iterator.next();
|
|
28320
|
+
} finally {
|
|
28321
|
+
delete iterator.awaitValue;
|
|
28322
|
+
}
|
|
28323
|
+
}
|
|
27476
28324
|
const pending = Promise.resolve(iterator.next());
|
|
27477
28325
|
if (!node.await) return pending;
|
|
27478
28326
|
context.onSuspend?.();
|
|
@@ -27484,9 +28332,50 @@ async function evaluateForOfIterator(node, value, context, restoredEntry) {
|
|
|
27484
28332
|
}
|
|
27485
28333
|
};
|
|
27486
28334
|
const releaseIterator = retainValues(context.budget, () => [value, iterator.retainedValue]);
|
|
28335
|
+
const closeLoopIterator = async (completion) => {
|
|
28336
|
+
const preserveThrow = completion.kind === "throw";
|
|
28337
|
+
if (!context.asyncFunction && context.asyncGeneratorFrame === void 0 || !node.await || iterator.resumeAwait === void 0 || node.nodeId === void 0 || completion.kind === "error") {
|
|
28338
|
+
await closeIterator(iterator, preserveThrow);
|
|
28339
|
+
return;
|
|
28340
|
+
}
|
|
28341
|
+
const { node: ignoredNode, stackFrames, ...metadata } = completion;
|
|
28342
|
+
const closeCompletion = { ...metadata, ...stackFrames === void 0 ? {} : { stackFrames: [...stackFrames] } };
|
|
28343
|
+
iterator.awaitValue = (awaited, awaitState) => suspendAsyncFunctionValue(awaited, node, {
|
|
28344
|
+
...context,
|
|
28345
|
+
generatorExpressionStates: new Map([
|
|
28346
|
+
...context.generatorExpressionStates ?? [],
|
|
28347
|
+
[node.nodeId, {
|
|
28348
|
+
kind: "for-of-iterator",
|
|
28349
|
+
phase: "close",
|
|
28350
|
+
awaitState,
|
|
28351
|
+
closeCompletion,
|
|
28352
|
+
async: true,
|
|
28353
|
+
value,
|
|
28354
|
+
current: void 0,
|
|
28355
|
+
index,
|
|
28356
|
+
scope: context.scope,
|
|
28357
|
+
iterator
|
|
28358
|
+
}]
|
|
28359
|
+
])
|
|
28360
|
+
}, void 0, createCoercionContext(context));
|
|
28361
|
+
try {
|
|
28362
|
+
if (saved?.phase === "close" && context.generatorResume?.completed !== true) {
|
|
28363
|
+
if (saved.awaitState === void 0) throw new TypeError("Missing iterator close continuation.");
|
|
28364
|
+
await iterator.resumeAwait(saved.awaitState, () => iterator.awaitValue(void 0, saved.awaitState));
|
|
28365
|
+
} else await closeIterator(iterator, preserveThrow);
|
|
28366
|
+
} catch (error) {
|
|
28367
|
+
if (!preserveThrow || isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
|
|
28368
|
+
} finally {
|
|
28369
|
+
delete iterator.awaitValue;
|
|
28370
|
+
}
|
|
28371
|
+
};
|
|
27487
28372
|
try {
|
|
28373
|
+
if (saved?.phase === "close") {
|
|
28374
|
+
if (saved.closeCompletion === void 0) throw new TypeError("Missing iterator close completion.");
|
|
28375
|
+
await closeLoopIterator(saved.closeCompletion);
|
|
28376
|
+
return saved.closeCompletion;
|
|
28377
|
+
}
|
|
27488
28378
|
const nodeId = node.nodeId ?? -1;
|
|
27489
|
-
let index = saved?.index ?? consumeRestoredLoopIterationIndex(node, context);
|
|
27490
28379
|
for (let skipped = 0; saved === void 0 && skipped < index; skipped += 1) {
|
|
27491
28380
|
const skippedIteration = await nextIteration();
|
|
27492
28381
|
if (typeof skippedIteration !== "object" || skippedIteration === null) {
|
|
@@ -27533,19 +28422,19 @@ async function evaluateForOfIterator(node, value, context, restoredEntry) {
|
|
|
27533
28422
|
binding = resuming && saved.phase === "body" ? { ok: true } : await bindIterationVariable(node.left, nextValue, scope, phaseContext("left"));
|
|
27534
28423
|
} catch (error) {
|
|
27535
28424
|
if (isFatalSandboxError(error) || error instanceof HostCallResumabilityError) throw error;
|
|
27536
|
-
await
|
|
28425
|
+
await closeLoopIterator(createThrowCompletion(error, context.budget, context.callStack));
|
|
27537
28426
|
throw error;
|
|
27538
28427
|
}
|
|
27539
28428
|
if (!binding.ok) {
|
|
27540
|
-
await
|
|
28429
|
+
await closeLoopIterator(binding.result);
|
|
27541
28430
|
return binding.result;
|
|
27542
28431
|
}
|
|
27543
28432
|
const iterationContext = createLoopIterationContext(phaseContext("body"), scope);
|
|
27544
28433
|
emitLoopIterationBreakpoint(node, iterationContext);
|
|
27545
|
-
const result = await evaluateNode(node.body, iterationContext);
|
|
28434
|
+
const result = await evaluateResourceScope(scope, context.budget, { ...createCoercionContext(iterationContext), ...resourceSuspension(iterationContext, node), onSuspend: iterationContext.onSuspend, signal: iterationContext.signal }, () => evaluateNode(node.body, iterationContext));
|
|
27546
28435
|
if (isMatchingBreak(result, loopLabels(node))) {
|
|
27547
28436
|
context.activeLoopIterations.delete(nodeId);
|
|
27548
|
-
await
|
|
28437
|
+
await closeLoopIterator(normalEmptyResult());
|
|
27549
28438
|
return normalEmptyResult();
|
|
27550
28439
|
}
|
|
27551
28440
|
if (isMatchingContinue(result, loopLabels(node))) {
|
|
@@ -27554,7 +28443,7 @@ async function evaluateForOfIterator(node, value, context, restoredEntry) {
|
|
|
27554
28443
|
}
|
|
27555
28444
|
if (result.kind !== "normal") {
|
|
27556
28445
|
context.activeLoopIterations.delete(nodeId);
|
|
27557
|
-
await
|
|
28446
|
+
await closeLoopIterator(result);
|
|
27558
28447
|
return result;
|
|
27559
28448
|
}
|
|
27560
28449
|
index += 1;
|
|
@@ -27692,55 +28581,57 @@ async function evaluateForStatement(node, context) {
|
|
|
27692
28581
|
])
|
|
27693
28582
|
}
|
|
27694
28583
|
});
|
|
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
|
-
};
|
|
28584
|
+
return evaluateResourceScope(loopScope, context.budget, { ...createCoercionContext(loopContext), ...resourceSuspension(phaseContext("dispose", loopScope), node), onSuspend: loopContext.onSuspend, signal: loopContext.signal }, async () => {
|
|
28585
|
+
if (node.init !== void 0 && (resumePhase === void 0 || resumePhase === "init")) {
|
|
28586
|
+
const init = await evaluateNode(node.init, phaseContext("init", loopScope));
|
|
28587
|
+
if (init.kind !== "normal") {
|
|
28588
|
+
return init;
|
|
27715
28589
|
}
|
|
27716
28590
|
}
|
|
27717
|
-
|
|
27718
|
-
|
|
27719
|
-
|
|
27720
|
-
|
|
27721
|
-
|
|
27722
|
-
|
|
27723
|
-
|
|
27724
|
-
|
|
27725
|
-
|
|
27726
|
-
|
|
27727
|
-
|
|
28591
|
+
while (true) {
|
|
28592
|
+
context.budget.visitNode();
|
|
28593
|
+
context.stats.nodeVisits += 1;
|
|
28594
|
+
if (node.test !== void 0 && resumePhase !== "body" && resumePhase !== "update") {
|
|
28595
|
+
const test = await evaluateNode(node.test, phaseContext("test", loopScope));
|
|
28596
|
+
if (test.kind !== "normal") {
|
|
28597
|
+
return test;
|
|
28598
|
+
}
|
|
28599
|
+
if (!isTruthy(test.value)) {
|
|
28600
|
+
return {
|
|
28601
|
+
kind: "normal",
|
|
28602
|
+
hasValue: false,
|
|
28603
|
+
value: void 0
|
|
28604
|
+
};
|
|
28605
|
+
}
|
|
27728
28606
|
}
|
|
27729
|
-
|
|
27730
|
-
|
|
28607
|
+
const iterationScope = resumePhase === "body" || resumePhase === "update" ? restored.activeScope : loopBindingNames.length === 0 ? loopScope : loopScope.iterationChild(loopBindingNames);
|
|
28608
|
+
if (resumePhase !== "update") {
|
|
28609
|
+
const iterationContext = createLoopIterationContext(phaseContext("body", iterationScope), iterationScope);
|
|
28610
|
+
emitLoopIterationBreakpoint(node, iterationContext);
|
|
28611
|
+
const result = await evaluateNode(node.body, iterationContext);
|
|
28612
|
+
if (isMatchingBreak(result, loopLabels(node))) {
|
|
28613
|
+
return {
|
|
28614
|
+
kind: "normal",
|
|
28615
|
+
hasValue: false,
|
|
28616
|
+
value: void 0
|
|
28617
|
+
};
|
|
28618
|
+
}
|
|
28619
|
+
if (result.kind !== "normal" && !isMatchingContinue(result, loopLabels(node))) {
|
|
28620
|
+
return result;
|
|
28621
|
+
}
|
|
27731
28622
|
}
|
|
27732
|
-
|
|
27733
|
-
|
|
27734
|
-
|
|
27735
|
-
|
|
27736
|
-
|
|
27737
|
-
|
|
27738
|
-
|
|
28623
|
+
const updateScope = resumePhase === "update" ? restored.activeScope : loopBindingNames.length === 0 ? iterationScope : iterationScope.iterationChild(loopBindingNames);
|
|
28624
|
+
const updateContext = phaseContext("update", updateScope);
|
|
28625
|
+
if (node.update !== void 0) {
|
|
28626
|
+
const update = await evaluateNode(node.update, updateContext);
|
|
28627
|
+
if (update.kind !== "normal") {
|
|
28628
|
+
return update;
|
|
28629
|
+
}
|
|
27739
28630
|
}
|
|
28631
|
+
loopScope.copyInitializedBindingsFrom(updateScope, loopBindingNames);
|
|
28632
|
+
resumePhase = void 0;
|
|
27740
28633
|
}
|
|
27741
|
-
|
|
27742
|
-
resumePhase = void 0;
|
|
27743
|
-
}
|
|
28634
|
+
});
|
|
27744
28635
|
}
|
|
27745
28636
|
async function evaluateWhileStatement(node, context) {
|
|
27746
28637
|
let resumeBody = context.generatorResume !== void 0 && context.generatorResume.completed !== true && containsResumeTarget(node.body, /* @__PURE__ */ new Set([context.generatorResume.yieldNodeId]));
|
|
@@ -27865,6 +28756,7 @@ async function bindIterationVariable(left, value, scope, context) {
|
|
|
27865
28756
|
[left.nodeId, { kind: "declaration", index: 0 }]
|
|
27866
28757
|
]) };
|
|
27867
28758
|
}
|
|
28759
|
+
if (left.disposal !== void 0) await registerScopeResource(scope, value, left.disposal, context.budget, createCoercionContext({ ...context, scope }));
|
|
27868
28760
|
return bindPattern(declarator.id, value, { kind: left.kind }, scope, createPatternContext(context, scope));
|
|
27869
28761
|
}
|
|
27870
28762
|
async function evaluateExpressionStatement(node, context) {
|
|
@@ -27896,14 +28788,14 @@ async function evaluateReturnStatement(node, context) {
|
|
|
27896
28788
|
value: void 0
|
|
27897
28789
|
};
|
|
27898
28790
|
}
|
|
27899
|
-
const argument = await evaluateNode(node.argument, context);
|
|
28791
|
+
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
28792
|
if (argument.kind !== "normal") {
|
|
27901
28793
|
return argument;
|
|
27902
28794
|
}
|
|
27903
28795
|
return {
|
|
27904
28796
|
kind: "return",
|
|
27905
28797
|
hasValue: argument.hasValue,
|
|
27906
|
-
value: context.asyncGenerator ? await suspendJob(awaitSandboxValue(argument.value, context.signal, context.budget, createCoercionContext(context))) : argument.value
|
|
28798
|
+
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
28799
|
};
|
|
27908
28800
|
}
|
|
27909
28801
|
async function evaluateYieldExpression(node, context) {
|
|
@@ -27927,7 +28819,25 @@ async function evaluateYieldExpression(node, context) {
|
|
|
27927
28819
|
return generatorCompletionResult(completion);
|
|
27928
28820
|
}
|
|
27929
28821
|
async function yieldGeneratorValue(value, node, context) {
|
|
27930
|
-
|
|
28822
|
+
const frame = context.asyncGeneratorFrame;
|
|
28823
|
+
const origin = frame === void 0 ? void 0 : getGeneratorOrigin(frame);
|
|
28824
|
+
const resuming = context.generatorResume?.completed !== true && context.generatorResume?.yieldNodeId === node.nodeId;
|
|
28825
|
+
if (frame !== void 0 && resuming && origin?.awaitPhase === "resume-return") {
|
|
28826
|
+
try {
|
|
28827
|
+
return { type: "return", value: await suspendAsyncFunctionValue(void 0, node, context, void 0, createCoercionContext(context), "resume-return") };
|
|
28828
|
+
} catch (error) {
|
|
28829
|
+
return { type: "throw", value: error };
|
|
28830
|
+
}
|
|
28831
|
+
}
|
|
28832
|
+
if (frame !== void 0 && !node.delegate && (!resuming || origin?.awaitPhase === "yield"))
|
|
28833
|
+
value = await suspendAsyncFunctionValue(value, node, context, void 0, createCoercionContext(context), "yield");
|
|
28834
|
+
else if (frame === void 0 && context.asyncGenerator && !node.delegate)
|
|
28835
|
+
value = await suspendJob(awaitSandboxValue(value, context.signal, context.budget, createCoercionContext(context)));
|
|
28836
|
+
if (frame !== void 0) {
|
|
28837
|
+
const driver = asyncGeneratorDrivers.get(frame);
|
|
28838
|
+
if (driver === void 0) throw new TypeError("Missing async generator yield owner.");
|
|
28839
|
+
driver.suspension = "yield";
|
|
28840
|
+
}
|
|
27931
28841
|
context.captureGeneratorScope?.(context.scope, context.generatorBlockScopes, context.finallyCompletions, context.generatorExpressionStates);
|
|
27932
28842
|
const completionPromise = context.generatorYield(allocateProducedSandboxValue(value, context.budget), node.nodeId);
|
|
27933
28843
|
emitResumeBreakpoint(context, {
|
|
@@ -27935,10 +28845,10 @@ async function yieldGeneratorValue(value, node, context) {
|
|
|
27935
28845
|
nodeId: node.nodeId,
|
|
27936
28846
|
span: node.span
|
|
27937
28847
|
});
|
|
27938
|
-
const completion = await (context.asyncGenerator ? suspendJob(completionPromise) : completionPromise);
|
|
28848
|
+
const completion = await (context.asyncGenerator && frame === void 0 ? suspendJob(completionPromise) : completionPromise);
|
|
27939
28849
|
if (context.asyncGenerator && completion.type === "return") {
|
|
27940
28850
|
try {
|
|
27941
|
-
return { type: "return", value: await suspendJob(awaitSandboxValue(completion.value, context.signal, context.budget, createCoercionContext(context))) };
|
|
28851
|
+
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
28852
|
} catch (error) {
|
|
27943
28853
|
return { type: "throw", value: error };
|
|
27944
28854
|
}
|
|
@@ -27968,41 +28878,69 @@ async function evaluateYieldDelegate(node, context) {
|
|
|
27968
28878
|
async: context.asyncGenerator === true,
|
|
27969
28879
|
value: argument.value,
|
|
27970
28880
|
current: saved?.current,
|
|
27971
|
-
iterator
|
|
28881
|
+
iterator,
|
|
28882
|
+
...saved?.phase === void 0 ? {} : { phase: saved.phase, awaitState: saved.awaitState, completion: saved.completion }
|
|
27972
28883
|
};
|
|
27973
28884
|
if (node.nodeId !== void 0) context = {
|
|
27974
28885
|
...context,
|
|
27975
28886
|
generatorExpressionStates: new Map([...context.generatorExpressionStates ?? [], [node.nodeId, state]])
|
|
27976
28887
|
};
|
|
28888
|
+
if (context.asyncGeneratorFrame !== void 0 && iterator.resumeAwait !== void 0)
|
|
28889
|
+
iterator.awaitValue = (value, awaitState) => {
|
|
28890
|
+
state.awaitState = awaitState;
|
|
28891
|
+
return suspendAsyncFunctionValue(value, node, context, void 0, createCoercionContext(context));
|
|
28892
|
+
};
|
|
27977
28893
|
const releaseIterator = retainValues(context.budget, () => [
|
|
27978
28894
|
argument.value,
|
|
27979
28895
|
iterator.retainedValue,
|
|
27980
28896
|
state.current
|
|
27981
28897
|
]);
|
|
27982
28898
|
try {
|
|
27983
|
-
let completion = {
|
|
28899
|
+
let completion = saved?.completion ?? {
|
|
27984
28900
|
type: "normal",
|
|
27985
28901
|
value: void 0
|
|
27986
28902
|
};
|
|
27987
28903
|
const replay = saved === void 0 ? context.generatorResume?.sent ?? [] : [];
|
|
27988
28904
|
let replayIndex = 0;
|
|
27989
|
-
|
|
28905
|
+
let resumeOperation = saved?.phase !== void 0;
|
|
28906
|
+
if (saved !== void 0 && !resumeOperation) {
|
|
27990
28907
|
completion = await yieldGeneratorValue(saved.current, node, context);
|
|
27991
28908
|
if (context.generatorResume !== void 0) context.generatorResume.completed = true;
|
|
27992
28909
|
context.generatorResume = void 0;
|
|
27993
28910
|
}
|
|
27994
28911
|
while (true) {
|
|
27995
28912
|
const method = completion.type === "normal" ? "next" : completion.type;
|
|
27996
|
-
|
|
27997
|
-
if (
|
|
27998
|
-
|
|
27999
|
-
|
|
28000
|
-
throw new TypeError("
|
|
28913
|
+
let result;
|
|
28914
|
+
if (resumeOperation) {
|
|
28915
|
+
resumeOperation = false;
|
|
28916
|
+
if (iterator.resumeAwait === void 0 || iterator.awaitValue === void 0 || saved?.awaitState === void 0)
|
|
28917
|
+
throw new TypeError("Missing delegated iterator await continuation.");
|
|
28918
|
+
result = await iterator.resumeAwait(saved.awaitState, () => iterator.awaitValue(void 0, saved.awaitState));
|
|
28919
|
+
if (saved.phase === "close") throw new TypeError("Delegated iterator does not provide a throw method.");
|
|
28920
|
+
context.generatorResume = void 0;
|
|
28921
|
+
} else {
|
|
28922
|
+
const iteratorMethod = iterator.getOperation === void 0 ? iterator[method] : await iterator.getOperation(method);
|
|
28923
|
+
if (iteratorMethod === void 0) {
|
|
28924
|
+
if (completion.type === "throw") {
|
|
28925
|
+
if (iterator.awaitValue !== void 0) {
|
|
28926
|
+
state.phase = "close";
|
|
28927
|
+
state.completion = completion;
|
|
28928
|
+
}
|
|
28929
|
+
await closeIterator(iterator, false, context.asyncGeneratorFrame === void 0 ? suspendJob : async (pending) => await suspendAsyncFunctionValue(createSandboxPromise(pending), node, context, void 0, createCoercionContext(context)));
|
|
28930
|
+
throw new TypeError("Delegated iterator does not provide a throw method.");
|
|
28931
|
+
}
|
|
28932
|
+
return generatorCompletionResult(completion);
|
|
28001
28933
|
}
|
|
28002
|
-
|
|
28934
|
+
if (iterator.awaitValue !== void 0) {
|
|
28935
|
+
state.phase = "await";
|
|
28936
|
+
state.completion = completion;
|
|
28937
|
+
}
|
|
28938
|
+
const pendingResult = Promise.resolve(iteratorMethod(completion.value));
|
|
28939
|
+
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
28940
|
}
|
|
28004
|
-
|
|
28005
|
-
|
|
28941
|
+
delete state.phase;
|
|
28942
|
+
delete state.awaitState;
|
|
28943
|
+
delete state.completion;
|
|
28006
28944
|
if (typeof result !== "object" && typeof result !== "function" || result === null) {
|
|
28007
28945
|
throw new TypeError("Iterator result must be an object.");
|
|
28008
28946
|
}
|
|
@@ -28028,6 +28966,7 @@ async function evaluateYieldDelegate(node, context) {
|
|
|
28028
28966
|
context.generatorResume = void 0;
|
|
28029
28967
|
}
|
|
28030
28968
|
} finally {
|
|
28969
|
+
delete iterator.awaitValue;
|
|
28031
28970
|
releaseIterator();
|
|
28032
28971
|
}
|
|
28033
28972
|
}
|
|
@@ -30287,21 +31226,23 @@ async function evaluateBlockCompletion(node, context, evaluateNode2) {
|
|
|
30287
31226
|
}
|
|
30288
31227
|
};
|
|
30289
31228
|
if (restoredScope === void 0) predeclareBlockBindings2(node, blockContext.scope);
|
|
30290
|
-
|
|
30291
|
-
|
|
30292
|
-
|
|
30293
|
-
|
|
30294
|
-
|
|
30295
|
-
|
|
30296
|
-
|
|
30297
|
-
|
|
30298
|
-
|
|
30299
|
-
|
|
30300
|
-
|
|
30301
|
-
|
|
31229
|
+
return evaluateResourceScope(scope, context.budget, { ...resourceSuspension(blockContext, node), stack: context.callStack, thisValue: void 0, getProperty: context.getProperty, onSuspend: context.onSuspend, signal: context.signal }, async () => {
|
|
31230
|
+
let result = {
|
|
31231
|
+
kind: "normal",
|
|
31232
|
+
hasValue: false,
|
|
31233
|
+
value: void 0
|
|
31234
|
+
};
|
|
31235
|
+
const resume = context.generatorResume;
|
|
31236
|
+
const resumeIndex = resume === void 0 || resume.completed === true ? -1 : node.body.findIndex((statement) => containsResumeTarget(statement, /* @__PURE__ */ new Set([resume.yieldNodeId])));
|
|
31237
|
+
for (let index = Math.max(0, resumeIndex); index < node.body.length; index++) {
|
|
31238
|
+
const statement = node.body[index];
|
|
31239
|
+
result = await evaluateNode2(statement, blockContext);
|
|
31240
|
+
if (result.kind !== "normal") {
|
|
31241
|
+
return result;
|
|
31242
|
+
}
|
|
30302
31243
|
}
|
|
30303
|
-
|
|
30304
|
-
|
|
31244
|
+
return result;
|
|
31245
|
+
});
|
|
30305
31246
|
}
|
|
30306
31247
|
function predeclareBlockBindings2(node, scope) {
|
|
30307
31248
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -30524,6 +31465,12 @@ async function advanceAsyncCleanup(cleanup, budget, context) {
|
|
|
30524
31465
|
try {
|
|
30525
31466
|
while ((current = cleanup.resources.pop()) !== void 0) {
|
|
30526
31467
|
budget.visitNode();
|
|
31468
|
+
if (current.synchronous && cleanup.needsAwait && !cleanup.hasAwaited) {
|
|
31469
|
+
cleanup.resources.push(current);
|
|
31470
|
+
cleanup.needsAwait = false;
|
|
31471
|
+
await wait(void 0, false);
|
|
31472
|
+
return;
|
|
31473
|
+
}
|
|
30527
31474
|
if (current.method === void 0) {
|
|
30528
31475
|
cleanup.needsAwait = true;
|
|
30529
31476
|
continue;
|
|
@@ -30534,13 +31481,14 @@ async function advanceAsyncCleanup(cleanup, budget, context) {
|
|
|
30534
31481
|
} catch (error) {
|
|
30535
31482
|
if (isFatalSandboxError(error)) throw error;
|
|
30536
31483
|
const value = createThrowCompletion(error, budget, context?.stack ?? []).value;
|
|
30537
|
-
if (current.syncFallback) {
|
|
31484
|
+
if (current.syncFallback && !current.synchronous) {
|
|
30538
31485
|
await wait(value, true);
|
|
30539
31486
|
return;
|
|
30540
31487
|
}
|
|
30541
31488
|
recordCleanupFailure(cleanup, value, budget, context);
|
|
30542
31489
|
continue;
|
|
30543
31490
|
}
|
|
31491
|
+
if (current.synchronous) continue;
|
|
30544
31492
|
await wait(current.syncFallback ? void 0 : result, false);
|
|
30545
31493
|
return;
|
|
30546
31494
|
}
|
|
@@ -31164,6 +32112,7 @@ function measureSandboxData(values, options = {}) {
|
|
|
31164
32112
|
return;
|
|
31165
32113
|
}
|
|
31166
32114
|
if (isSandboxGenerator(value)) {
|
|
32115
|
+
visit(asyncGeneratorDrivers.get(value), depth + 1);
|
|
31167
32116
|
const descriptors2 = Object.getOwnPropertyDescriptors(getGeneratorProperties(value));
|
|
31168
32117
|
for (const key of Reflect.ownKeys(descriptors2)) {
|
|
31169
32118
|
const descriptor = descriptors2[key];
|
|
@@ -31178,6 +32127,7 @@ function measureSandboxData(values, options = {}) {
|
|
|
31178
32127
|
return;
|
|
31179
32128
|
}
|
|
31180
32129
|
if (isSandboxPromise(value)) {
|
|
32130
|
+
visit(asyncGeneratorRequestOwners.get(value), depth + 1);
|
|
31181
32131
|
const settlement = promiseStates.get(value);
|
|
31182
32132
|
if (settlement !== void 0 && settlement.status !== "pending") visit(settlement.value, depth + 1);
|
|
31183
32133
|
const continuation = promiseContinuations.get(value);
|
|
@@ -46216,4 +47166,4 @@ export {
|
|
|
46216
47166
|
FileSnapshotBackend,
|
|
46217
47167
|
run
|
|
46218
47168
|
};
|
|
46219
|
-
//# sourceMappingURL=chunk-
|
|
47169
|
+
//# sourceMappingURL=chunk-GZSWJFFP.js.map
|