delinting

This commit is contained in:
Adam Powers
2020-11-07 16:13:14 -08:00
parent 9fa0c9cfd2
commit beb189e6cb

View File

@@ -6,41 +6,56 @@ let savedOnRuntimeInitialized;
// starts nethack
function nethackStart(cb, inputModule = {}) {
if(typeof cb !== "string" && typeof cb !== "function") throw new TypeError("expected first argument to be 'Function' or 'String' representing global callback function name");
if(typeof inputModule !== "object") throw new TypeError("expected second argument to be object");
if (typeof cb !== "string" && typeof cb !== "function") {
throw new TypeError("expected first argument to be 'Function' or 'String' representing global callback function name");
}
if (typeof inputModule !== "object") {
throw new TypeError("expected second argument to be object");
}
let cbName;
if(typeof cb === "function") {
if (typeof cb === "function") {
cbName = cb.name;
if (cbName === "") cbName = "__anonymousNetHackCallback";
if (globalThis[cbName] === undefined) globalThis[cbName] = cb;
else if (globalThis[cbName] !== cb) throw new Error (`'globalThis["${cbName}"]' is not the same as specified callback`);
if (cbName === "") {
cbName = "__anonymousNetHackCallback";
}
if (globalThis[cbName] === undefined) {
globalThis[cbName] = cb;
} else if (globalThis[cbName] !== cb) {
throw new Error(`'globalThis["${cbName}"]' is not the same as specified callback`);
}
}
/* global globalThis */
userCallback = globalThis[cbName];
if(typeof userCallback !== "function") throw new TypeError(`expected 'globalThis["${cbName}"]' to be a function`);
if (typeof userCallback !== "function") {
throw new TypeError(`expected 'globalThis["${cbName}"]' to be a function`);
}
// if(userCallback.constructor.name !== "AsyncFunction") throw new TypeError(`expected 'globalThis["${cbName}"]' to be an async function`);
// Emscripten Module config
Module = inputModule;
savedOnRuntimeInitialized = Module.onRuntimeInitialized;
Module.onRuntimeInitialized = function (... args) {
Module.onRuntimeInitialized = function(... args) {
// after the WASM is loaded, add the shim graphics callback function
Module.ccall(
"shim_graphics_set_callback", // C function name
null, // return type
["string"], // arg types
[cbName], // arg values
{async: true} // options
{async: true}, // options
);
// if the user had their own onRuntimeInitialized(), call it now
if (savedOnRuntimeInitialized) savedOnRuntimeInitialized(... args);
if (savedOnRuntimeInitialized) {
savedOnRuntimeInitialized(... args);
}
};
// load and run the module
var factory = require(path.join(__dirname, "../build/nethack.js"));
let factory = require(path.join(__dirname, "../build/nethack.js"));
factory(Module);
}