refactor(domain): charge resource allowances through one Budget owner (#11293)

This commit is contained in:
morluto authored and GitHub committed 2026-11-15 23:47:20 +08:00
1 parent c931ba43ab
commit 3d67404132
11 files changed
+215 -96

No files matched your search

+3 -6
View File
@@ -1,3 +1,4 @@
import { Budget } from "../domain/budget.js";
import {
noRuntimeOverrideSentence,
selectedCdpCommandTimeoutMs,
@@ -19,7 +20,7 @@ export const cdpScriptSourceDeadlineOmissionReason = (
export class CdpScriptSourceBudget {
readonly #deadline: ProviderStartupDeadline;
readonly commandTimeoutMs: number;
#retainedBytes = 0;
readonly #retained = new Budget(WEB_RUNTIME_LIMITS.sourceBytes);
constructor(
signal?: AbortSignal,
@@ -39,11 +40,7 @@ export class CdpScriptSourceBudget {
/** Admit exact UTF-8 source bytes before building or retaining its artifact. */
admit(text: string): boolean {
const bytes = Buffer.byteLength(text, "utf8");
if (bytes > WEB_RUNTIME_LIMITS.sourceBytes - this.#retainedBytes)
return false;
this.#retainedBytes += bytes;
return true;
return this.#retained.tryCharge(Buffer.byteLength(text, "utf8"));
}
dispose(): void {