NETSCRIPT: Don't make dynamicLoadedFns entries for free functions. (#1617)

This commit is contained in:
Yichi Zhang 2024-08-23 21:23:41 -07:00 committed by GitHub
parent 2141032432
commit 028e779602
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

@ -343,6 +343,7 @@ function netscriptDelay(ctx: NetscriptContext, time: number): Promise<void> {
/** Adds to dynamic ram cost when calling new ns functions from a script */ /** Adds to dynamic ram cost when calling new ns functions from a script */
function updateDynamicRam(ctx: NetscriptContext, ramCost: number): void { function updateDynamicRam(ctx: NetscriptContext, ramCost: number): void {
if (ramCost === 0) return;
const ws = ctx.workerScript; const ws = ctx.workerScript;
const fnName = ctx.function; const fnName = ctx.function;
if (ws.dynamicLoadedFns[fnName]) return; if (ws.dynamicLoadedFns[fnName]) return;

@ -103,7 +103,9 @@ describe("Netscript RAM Calculation/Generation Tests", function () {
throw new Error(`Invalid function specified: [${fnPath.toString()}]`); throw new Error(`Invalid function specified: [${fnPath.toString()}]`);
} }
expect(workerScript.dynamicLoadedFns).toHaveProperty(fnName); if (expectedRamCost !== 0) {
expect(workerScript.dynamicLoadedFns).toHaveProperty(fnName);
}
expect(workerScript.dynamicRamUsage).toBeCloseTo(Math.min(expectedRamCost + baseCost, maxCost), 5); expect(workerScript.dynamicRamUsage).toBeCloseTo(Math.min(expectedRamCost + baseCost, maxCost), 5);
expect(workerScript.dynamicRamUsage).toBeCloseTo(scriptRef.ramUsage - extraLayerCost, 5); expect(workerScript.dynamicRamUsage).toBeCloseTo(scriptRef.ramUsage - extraLayerCost, 5);
} }