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
+2 -27
View File
@@ -41,13 +41,7 @@ export async function executeJSScript(script, scripts = [], workerScript) {
throw makeRuntimeRejectMsg(script.filename +
" did not have a main function, cannot run it.");
}
console.log("loadedModule:");
console.log(loadedModule);
let constructedModule = await ConstructModule(loadedModule, ns);
constructedModule = await constructedModule();
console.log("constructedModule: ");
console.log(constructedModule);
return constructedModule.main();
return loadedModule.main(ns);
} finally {
// Revoke the generated URLs
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
// 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('');
});
// If we successfully transformed the code, create a blob url for it and
// push that URL onto the top of the stack.
urlStack.push(URL.createObjectURL(makeScriptBlob(transformedCode)));