From beb189e6cbb68e9b5f8c56aa60b9a3023653c0d8 Mon Sep 17 00:00:00 2001 From: Adam Powers Date: Sat, 7 Nov 2020 16:13:14 -0800 Subject: [PATCH] delinting --- sys/libnh/npm-package/src/nethackShim.js | 37 +++++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/sys/libnh/npm-package/src/nethackShim.js b/sys/libnh/npm-package/src/nethackShim.js index e7a802c30..23c58e021 100644 --- a/sys/libnh/npm-package/src/nethackShim.js +++ b/sys/libnh/npm-package/src/nethackShim.js @@ -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); } -- 2.50.1