Merge pull request #3400 from TheMas3212/fix/wrapper-doesnt-recurs

fix netscript function concurrency wrapper doesnt recurs
This commit is contained in:
hydroflame
2022-04-11 19:37:21 -04:00
committed by GitHub

View File

@ -116,11 +116,22 @@ function startNetscript2Script(player: IPlayer, workerScript: WorkerScript): Pro
};
}
for (const prop of Object.keys(workerScript.env.vars)) {
if (typeof workerScript.env.vars[prop] !== "function") continue;
workerScript.env.vars[prop] = wrap(prop, workerScript.env.vars[prop]);
function wrapObject(vars: any, ...tree: string[]): void {
for (const prop of Object.keys(vars)) {
switch (typeof vars[prop]) {
case "function": {
vars[prop] = wrap([...tree, prop].join("."), vars[prop]);
break;
}
case "object": {
if (Array.isArray(vars[prop])) continue;
wrapObject(vars[prop], ...tree, prop);
break;
}
}
}
}
workerScript.env.vars.stanek.charge = wrap("stanek.charge", workerScript.env.vars.stanek.charge);
wrapObject(workerScript.env.vars);
// Note: the environment that we pass to the JS script only needs to contain the functions visible
// to that script, which env.vars does at this point.