Merge pull request #3038 from Ornedan/fix-atexit-leak

Fix #3037: wrap user-supplied atExit function so that we can't accide…
This commit is contained in:
hydroflame 2022-03-01 10:51:49 -05:00 committed by GitHub
commit 3d6d729b33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2279,7 +2279,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
if (typeof f !== "function") { if (typeof f !== "function") {
throw makeRuntimeErrorMsg("atExit", "argument should be function"); throw makeRuntimeErrorMsg("atExit", "argument should be function");
} }
workerScript.atExit = f; workerScript.atExit = () => { f(); }; // Wrap the user function to prevent WorkerScript leaking as 'this'
}, },
mv: function (host: string, source: string, destination: string): void { mv: function (host: string, source: string, destination: string): void {
updateDynamicRam("mv", getRamCost(Player, "mv")); updateDynamicRam("mv", getRamCost(Player, "mv"));