Merge pull request #1872 from danielyxie/dev

doc fix
This commit is contained in:
hydroflame 2021-12-13 15:00:33 -05:00 committed by GitHub
commit dfdb940aa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 12 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,6 +1,7 @@
import { isString } from "./utils/helpers/isString";
import { GetServer } from "./Server/AllServers";
import { WorkerScript } from "./Netscript/WorkerScript";
import { BlobsMap } from "./NetscriptJSEvaluator";
export function netscriptDelay(time: number, workerScript: WorkerScript): Promise<void> {
return new Promise(function (resolve) {
@ -18,6 +19,10 @@ export function makeRuntimeRejectMsg(workerScript: WorkerScript, msg: string): s
throw new Error(`WorkerScript constructed with invalid server ip: ${workerScript.hostname}`);
}
for (const url in BlobsMap) {
msg = msg.replace(new RegExp(url, "g"), BlobsMap[url]);
}
return "|DELIMITER|" + server.hostname + "|DELIMITER|" + workerScript.name + "|DELIMITER|" + msg;
}

@ -1056,12 +1056,16 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
}
if (scriptname && scriptname.constructor === Array) {
// Recursively call scp on all elements of array
let res = false;
await scriptname.forEach(async function (script) {
if (await NetscriptFunctions(workerScript).scp(script, hostname1, hostname2)) {
res = true;
const scripts: Array<string> = scriptname;
if (scripts.length === 0) {
throw makeRuntimeErrorMsg("scp", "No scripts to copy");
}
});
let res = true;
await Promise.all(scripts.map(async function(script) {
if (!await NetscriptFunctions(workerScript).scp(script, hostname1, hostname2)) {
res = false;
}
}));
return Promise.resolve(res);
}

@ -3,6 +3,8 @@ import { ScriptUrl } from "./Script/ScriptUrl";
import { WorkerScript } from "./Netscript/WorkerScript";
import { Script } from "./Script/Script";
export const BlobsMap: { [key: string]: string } = {};
// Makes a blob that contains the code of a given script.
function makeScriptBlob(code: string): Blob {
return new Blob([code], { type: "text/javascript" });
@ -19,7 +21,10 @@ export async function compile(script: Script, scripts: Script[]): Promise<void>
// by placing it inside an eval call.
await script.updateRamUsage(scripts);
const uurls = _getScriptUrls(script, scripts, []);
if (script.url) URL.revokeObjectURL(script.url); // remove the old reference.
if (script.url) {
URL.revokeObjectURL(script.url); // remove the old reference.
delete BlobsMap[script.url];
}
if (script.dependencies.length > 0) script.dependencies.forEach((dep) => URL.revokeObjectURL(dep.url));
script.url = uurls[uurls.length - 1].url;
script.module = new Promise((resolve) => resolve(eval("import(uurls[uurls.length - 1].url)")));
@ -133,7 +138,9 @@ function _getScriptUrls(script: Script, scripts: Script[], seen: Script[]): Scri
// If we successfully transformed the code, create a blob url for it and
// push that URL onto the top of the stack.
urlStack.push(new ScriptUrl(script.filename, URL.createObjectURL(makeScriptBlob(transformedCode))));
const su = new ScriptUrl(script.filename, URL.createObjectURL(makeScriptBlob(transformedCode)));
urlStack.push(su);
BlobsMap[su.url] = su.filename;
return urlStack;
} catch (err) {
// If there is an error, we need to clean up the URLs.

@ -140,7 +140,8 @@ function startNetscript2Script(workerScript: WorkerScript): Promise<WorkerScript
workerScript.errorMessage = e;
throw workerScript;
}
throw e; // Don't know what to do with it, let's rethrow.
workerScript.errorMessage = makeRuntimeRejectMsg(workerScript, e);
throw workerScript; // Don't know what to do with it, let's rethrow.
});
}

@ -324,8 +324,8 @@ export function SidebarRoot(props: IProps): React.ReactElement {
// }
}
document.addEventListener("keypress", handleShortcuts);
return () => document.removeEventListener("keypress", handleShortcuts);
document.addEventListener("keydown", handleShortcuts);
return () => document.removeEventListener("keydown", handleShortcuts);
}, []);
const classes = useStyles();