NETSCRIPT: A minorly breaking change around script launch, and refactoring. (#1213)

This commit is contained in:
David Walker
2024-04-23 17:21:05 -07:00
committed by GitHub
parent 7a1fce6f64
commit 384d1c1a2b
24 changed files with 48 additions and 66 deletions
+4 -2
View File
@@ -57,10 +57,12 @@ async function startNetscript2Script(workerScript: WorkerScript): Promise<void>
const loadedModule = await compile(script, scripts);
if (!loadedModule) throw `${script.filename} cannot be run because the script module won't load`;
const mainFunc = loadedModule.main;
// TODO unplanned: Better error for "unexpected reserved word" when using await in non-async function?
if (typeof loadedModule.main !== "function")
if (typeof mainFunc !== "function")
throw `${script.filename} cannot be run because it does not have a main function.`;
await loadedModule.main(ns);
// Explicitly called from a variable so that we don't bind "this".
await mainFunc(ns);
}
async function startNetscript1Script(workerScript: WorkerScript): Promise<void> {