mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-21 16:52:55 +02:00
@@ -31,8 +31,6 @@ export async function executeJSScript(scripts = [], workerScript) {
|
||||
loadedModule = script.module;
|
||||
|
||||
let ns = workerScript.env.vars;
|
||||
//ns.threads = workerScript.threads;
|
||||
//ns.args = workerScript.args;
|
||||
|
||||
try {
|
||||
// TODO: putting await in a non-async function yields unhelpful
|
||||
@@ -75,7 +73,7 @@ export function _getScriptUrls(script, scripts, seen) {
|
||||
// import {foo} from "blob://<uuid>"
|
||||
//
|
||||
// Where the blob URL contains the script content.
|
||||
const transformedCode = script.code.replace(/((?:from|import)\s+(?:'|"))([^'"]+)('|";)/g,
|
||||
let transformedCode = script.code.replace(/((?:from|import)\s+(?:'|"))([^'"]+)('|";)/g,
|
||||
(unmodified, prefix, filename, suffix) => {
|
||||
const isAllowedImport = scripts.some(s => s.filename == filename);
|
||||
if (!isAllowedImport) return unmodified;
|
||||
@@ -92,6 +90,9 @@ export function _getScriptUrls(script, scripts, seen) {
|
||||
}
|
||||
);
|
||||
|
||||
// We automatically define a print function() in the NetscriptJS module so that
|
||||
// accidental calls to window.print() do not bring up the "print screen" dialog
|
||||
transformedCode += `\n\nfunction print() {throw new Error("Invalid call to window.print(). Did you mean to use Netscript's print()?");}`
|
||||
|
||||
// If we successfully transformed the code, create a blob url for it and
|
||||
// push that URL onto the top of the stack.
|
||||
|
||||
Reference in New Issue
Block a user