Changed NSJS to take in nsEnv as an argument to main

This commit is contained in:
danielyxie 2018-05-13 01:06:44 -05:00
parent bf5b3c371e
commit 02ce03d2d6
3 changed files with 6 additions and 83 deletions

30
dist/engine.bundle.js vendored

@ -63615,7 +63615,6 @@ function isnan (val) {
__webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "makeScriptBlob", function() { return makeScriptBlob; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "makeScriptBlob", function() { return makeScriptBlob; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "executeJSScript", function() { return executeJSScript; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "executeJSScript", function() { return executeJSScript; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConstructModule", function() { return ConstructModule; });
/* harmony import */ var _NetscriptJSPreamble_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./NetscriptJSPreamble.js */ 128); /* harmony import */ var _NetscriptJSPreamble_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./NetscriptJSPreamble.js */ 128);
/* harmony import */ var _NetscriptEvaluator_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./NetscriptEvaluator.js */ 7); /* harmony import */ var _NetscriptEvaluator_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./NetscriptEvaluator.js */ 7);
@ -63661,13 +63660,7 @@ async function executeJSScript(script, scripts = [], workerScript) {
throw Object(_NetscriptEvaluator_js__WEBPACK_IMPORTED_MODULE_1__["makeRuntimeRejectMsg"])(script.filename + throw Object(_NetscriptEvaluator_js__WEBPACK_IMPORTED_MODULE_1__["makeRuntimeRejectMsg"])(script.filename +
" did not have a main function, cannot run it."); " did not have a main function, cannot run it.");
} }
console.log("loadedModule:"); return loadedModule.main(ns);
console.log(loadedModule);
let constructedModule = await ConstructModule(loadedModule, ns);
constructedModule = await constructedModule();
console.log("constructedModule: ");
console.log(constructedModule);
return constructedModule.main();
} finally { } finally {
// Revoke the generated URLs // Revoke the generated URLs
if (urlStack != null) { if (urlStack != null) {
@ -63676,26 +63669,6 @@ async function executeJSScript(script, scripts = [], workerScript) {
}; };
} }
function ConstructModule(module, ns) {
function mod() {
/*
for (var fn in ns) {
let fooName = fn.toString();
var evalStatement = "var " + fooName + " = ns[\"" + fooName + "\"];"
console.log(evalStatement);
eval(evalStatement);
console.log(ns[fooName]);
console.log("Setting " + fooName + " in ConstructModule()");
console.log(fooName);
console.log(" ");
}*/
var newModule = Object.create(module);
newModule.tprint = ns.tprint;
return newModule;
}
return mod;
}
// Gets a stack of blob urls, the top/right-most element being // Gets a stack of blob urls, the top/right-most element being
// the blob url for the named script on the named server. // the blob url for the named script on the named server.
// //
@ -63739,6 +63712,7 @@ function _getScriptUrls(script, scripts, seen) {
return [prefix, urls[urls.length - 1], suffix].join(''); return [prefix, urls[urls.length - 1], suffix].join('');
}); });
// If we successfully transformed the code, create a blob url for it and // If we successfully transformed the code, create a blob url for it and
// push that URL onto the top of the stack. // push that URL onto the top of the stack.
urlStack.push(URL.createObjectURL(makeScriptBlob(transformedCode))); urlStack.push(URL.createObjectURL(makeScriptBlob(transformedCode)));

30
dist/tests.bundle.js vendored

@ -63656,7 +63656,6 @@ module.exports = function flag(obj, key, value) {
__webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "makeScriptBlob", function() { return makeScriptBlob; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "makeScriptBlob", function() { return makeScriptBlob; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "executeJSScript", function() { return executeJSScript; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "executeJSScript", function() { return executeJSScript; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConstructModule", function() { return ConstructModule; });
/* harmony import */ var _NetscriptJSPreamble_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./NetscriptJSPreamble.js */ 128); /* harmony import */ var _NetscriptJSPreamble_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./NetscriptJSPreamble.js */ 128);
/* harmony import */ var _NetscriptEvaluator_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./NetscriptEvaluator.js */ 7); /* harmony import */ var _NetscriptEvaluator_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./NetscriptEvaluator.js */ 7);
@ -63702,13 +63701,7 @@ async function executeJSScript(script, scripts = [], workerScript) {
throw Object(_NetscriptEvaluator_js__WEBPACK_IMPORTED_MODULE_1__["makeRuntimeRejectMsg"])(script.filename + throw Object(_NetscriptEvaluator_js__WEBPACK_IMPORTED_MODULE_1__["makeRuntimeRejectMsg"])(script.filename +
" did not have a main function, cannot run it."); " did not have a main function, cannot run it.");
} }
console.log("loadedModule:"); return loadedModule.main(ns);
console.log(loadedModule);
let constructedModule = await ConstructModule(loadedModule, ns);
constructedModule = await constructedModule();
console.log("constructedModule: ");
console.log(constructedModule);
return constructedModule.main();
} finally { } finally {
// Revoke the generated URLs // Revoke the generated URLs
if (urlStack != null) { if (urlStack != null) {
@ -63717,26 +63710,6 @@ async function executeJSScript(script, scripts = [], workerScript) {
}; };
} }
function ConstructModule(module, ns) {
function mod() {
/*
for (var fn in ns) {
let fooName = fn.toString();
var evalStatement = "var " + fooName + " = ns[\"" + fooName + "\"];"
console.log(evalStatement);
eval(evalStatement);
console.log(ns[fooName]);
console.log("Setting " + fooName + " in ConstructModule()");
console.log(fooName);
console.log(" ");
}*/
var newModule = Object.create(module);
newModule.tprint = ns.tprint;
return newModule;
}
return mod;
}
// Gets a stack of blob urls, the top/right-most element being // Gets a stack of blob urls, the top/right-most element being
// the blob url for the named script on the named server. // the blob url for the named script on the named server.
// //
@ -63780,6 +63753,7 @@ function _getScriptUrls(script, scripts, seen) {
return [prefix, urls[urls.length - 1], suffix].join(''); return [prefix, urls[urls.length - 1], suffix].join('');
}); });
// If we successfully transformed the code, create a blob url for it and // If we successfully transformed the code, create a blob url for it and
// push that URL onto the top of the stack. // push that URL onto the top of the stack.
urlStack.push(URL.createObjectURL(makeScriptBlob(transformedCode))); urlStack.push(URL.createObjectURL(makeScriptBlob(transformedCode)));

@ -41,13 +41,7 @@ export async function executeJSScript(script, scripts = [], workerScript) {
throw makeRuntimeRejectMsg(script.filename + throw makeRuntimeRejectMsg(script.filename +
" did not have a main function, cannot run it."); " did not have a main function, cannot run it.");
} }
console.log("loadedModule:"); return loadedModule.main(ns);
console.log(loadedModule);
let constructedModule = await ConstructModule(loadedModule, ns);
constructedModule = await constructedModule();
console.log("constructedModule: ");
console.log(constructedModule);
return constructedModule.main();
} finally { } finally {
// Revoke the generated URLs // Revoke the generated URLs
if (urlStack != null) { if (urlStack != null) {
@ -56,26 +50,6 @@ export async function executeJSScript(script, scripts = [], workerScript) {
}; };
} }
export function ConstructModule(module, ns) {
function mod() {
/*
for (var fn in ns) {
let fooName = fn.toString();
var evalStatement = "var " + fooName + " = ns[\"" + fooName + "\"];"
console.log(evalStatement);
eval(evalStatement);
console.log(ns[fooName]);
console.log("Setting " + fooName + " in ConstructModule()");
console.log(fooName);
console.log(" ");
}*/
var newModule = Object.create(module);
newModule.tprint = ns.tprint;
return newModule;
}
return mod;
}
// Gets a stack of blob urls, the top/right-most element being // Gets a stack of blob urls, the top/right-most element being
// the blob url for the named script on the named server. // the blob url for the named script on the named server.
// //
@ -119,6 +93,7 @@ function _getScriptUrls(script, scripts, seen) {
return [prefix, urls[urls.length - 1], suffix].join(''); return [prefix, urls[urls.length - 1], suffix].join('');
}); });
// If we successfully transformed the code, create a blob url for it and // If we successfully transformed the code, create a blob url for it and
// push that URL onto the top of the stack. // push that URL onto the top of the stack.
urlStack.push(URL.createObjectURL(makeScriptBlob(transformedCode))); urlStack.push(URL.createObjectURL(makeScriptBlob(transformedCode)));