234
this._settleFinishedRuns();
235
if (this._runs.size === 0) { return 'quiesce'; }
237
>
const next = this._clock.peekNext();
238
>
if (next === undefined) { return 'park'; }
239
>
240
>
// Per-run trace-depth check: reject any run whose limit this event
241
>
// would exceed, before executing.
242
const traceDepth = next.trace?.depth ?? 0;
243
let depthOverflow = false;
244
for (const run of [...this._runs.keys()]) {
246
>
if (limit !== undefined && traceDepth > limit) {
247
this._settleRun(run, this._buildDepthOverflow(run, traceDepth));
248
depthOverflow = true;
249
}
251
>
if (depthOverflow) { return 'progress'; }
252
>
253
>
this._executeOne(next);
254
>
return 'progress';
255
}
256
257
private _executeOne(event: VirtualEvent): void {
259
>
TraceContext.instance.runAsHandler(
260
>
event.trace ?? ROOT_TRACE,
261
>
() => {
262
>
const e = this._clock.runNext();
263
>
if (e) {
264
>
this._history.push(e);
265
>
this._executedTotal++;
266
>
}
267
>
},
268
>
{
269
>
// Route the trace-reset through the same host primitive
270
>
// the embedding uses, so there is no race between this
271
>
// timer and the embedding's next hop.
272
>
afterMicrotaskClosure: cb => nextMacrotask(this._realApi, cb),
273
>
},
274
>
);
275
>
} catch (e) {
276
const err = e instanceof Error ? e : new Error(String(e));
277
// We can't tell which run "owned" the throwing event. Reject all