From 96a4d4c3678746729e246c8921ca76218db0d342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Zanolli?= Date: Sun, 27 Sep 2015 19:48:19 -0300 Subject: [PATCH 1/2] Small JSHint fixes --- loader.js | 105 +++++++++++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/loader.js b/loader.js index 52f89f6f..df77e42b 100644 --- a/loader.js +++ b/loader.js @@ -26,25 +26,23 @@ var Module = null; } function img(src) { - var img = new Image(); - img.src = src; - return img; + var _img = new Image(); + _img.src = src; + return _img; } // yea, this is a hack - if (/archive\.org$/.test(document.location.hostname)) { - var images = { ia: img("/images/ialogo.png"), - mame: img("/images/mame.png"), - mess: img("/images/mess.png"), - dosbox: img("/images/dosbox.png") - }; - } else { - images = { ia: img("other_logos/ia-logo-150x150.png"), - mame: img("other_logos/mame.png"), - mess: img("other_logos/mess.png"), - dosbox: img("other_logos/dosbox.png") - }; - } + var images = (/archive\.org$/.test(document.location.hostname)) ? + { ia: img("/images/ialogo.png"), + mame: img("/images/mame.png"), + mess: img("/images/mess.png"), + dosbox: img("/images/dosbox.png") + } : { + ia: img("other_logos/ia-logo-150x150.png"), + mame: img("other_logos/mame.png"), + mess: img("other_logos/mess.png"), + dosbox: img("other_logos/dosbox.png") + }; function updateLogo() { if (emulator_logo) { @@ -57,7 +55,7 @@ var Module = null; if (!audio_ctx) { return false; } - var sample = new audio_ctx; + var sample = new audio_ctx(); return sample.sampleRate.toString(); }()); @@ -97,7 +95,7 @@ var Module = null; modulecfg = JSON.parse(data); var mame = modulecfg && 'arcade' in modulecfg && - parseInt(modulecfg['arcade'], 10); + parseInt(modulecfg.arcade, 10); var get_files; if (module && module.indexOf("dosbox") === 0) { @@ -120,7 +118,7 @@ var Module = null; throw new Error("Unknown module type "+ module +"; cannot configure the emulator."); } - var nr = modulecfg['native_resolution']; + var nr = modulecfg.native_resolution; config_args = [cfgr.emulatorJS(get_js_url(modulecfg.js_filename)), cfgr.locateAdditionalEmulatorJS(locateAdditionalJS), cfgr.fileSystemKey(game), @@ -181,8 +179,9 @@ var Module = null; // first get the urls var urls = [], files = []; var len = metadata.documentElement.childNodes.length, i; + var node; for (i = 0; i < len; i++) { - var node = metadata.documentElement.childNodes[i]; + node = metadata.documentElement.childNodes[i]; var m = node.nodeName.match(/^dosbox_drive_[a-zA-Z]$/); if (m) { urls.push(node); @@ -190,12 +189,12 @@ var Module = null; } // and a count, then fetch them in - var len = urls.length; + len = urls.length; for (i = 0; i < len; i++) { - var node = urls[i], - drive = node.nodeName.split('_')[2], - title = 'Game File ('+ (i+1) +' of '+ (game ? len+1 : len) +')', - url = get_zip_url(node.textContent); + node = urls[i], + drive = node.nodeName.split('_')[2], + title = 'Game File ('+ (i+1) +' of '+ (game ? len+1 : len) +')', + url = get_zip_url(node.textContent); files.push(cfgr.mountZip(drive, cfgr.fetchFile(title, url))); } @@ -211,7 +210,7 @@ var Module = null; function get_mess_files(cfgr, metadata, modulecfg) { var files = [], - bios_files = modulecfg['bios_filenames']; + bios_files = modulecfg.bios_filenames; bios_files.forEach(function (fname, i) { if (fname) { var title = "Bios File ("+ (i+1) +" of "+ bios_files.length +")"; @@ -223,7 +222,7 @@ var Module = null; files.push(cfgr.mountFile('/'+ get_game_name(game), cfgr.fetchFile("Game File", get_zip_url(game)))); - files.push(cfgr.mountFile('/'+ modulecfg['driver'] + '.cfg', + files.push(cfgr.mountFile('/'+ modulecfg.driver + '.cfg', cfgr.fetchOptionalFile("CFG File", get_other_emulator_config_url(module)))); return files; @@ -231,7 +230,7 @@ var Module = null; function get_mame_files(cfgr, metadata, modulecfg) { var files = [], - bios_files = modulecfg['bios_filenames']; + bios_files = modulecfg.bios_filenames; bios_files.forEach(function (fname, i) { if (fname) { var title = "Bios File ("+ (i+1) +" of "+ bios_files.length +")"; @@ -243,7 +242,7 @@ var Module = null; files.push(cfgr.mountFile('/'+ get_game_name(game), cfgr.fetchFile("Game File", get_zip_url(game)))); - files.push(cfgr.mountFile('/'+ modulecfg['driver'] + '.cfg', + files.push(cfgr.mountFile('/'+ modulecfg.driver + '.cfg', cfgr.fetchOptionalFile("CFG File", get_other_emulator_config_url(module)))); return files; @@ -299,9 +298,9 @@ var Module = null; /** * BaseLoader */ - function BaseLoader() { + var BaseLoader = function() { return Array.prototype.reduce.call(arguments, extend); - } + }; BaseLoader.canvas = function (id) { var elem = id instanceof Element ? id : document.getElementById(id); @@ -365,11 +364,11 @@ var Module = null; return { title: title, data: data }; }; - function DosBoxLoader() { + var DosBoxLoader = function() { var config = Array.prototype.reduce.call(arguments, extend); config.emulator_arguments = build_dosbox_arguments(config.emulatorStart, config.files); return config; - } + }; DosBoxLoader.__proto__ = BaseLoader; DosBoxLoader.startExe = function (path) { @@ -404,14 +403,15 @@ var Module = null; /** * JSMAMELoader */ - function JSMAMELoader() { + var JSMAMELoader = function() { var config = Array.prototype.reduce.call(arguments, extend); config.emulator_arguments = build_mame_arguments(config.muted, config.mess_driver, config.nativeResolution, config.sample_rate, config.extra_mess_args); config.needs_jsmess_webaudio = true; return config; - } + }; + JSMAMELoader.__proto__ = BaseLoader; JSMAMELoader.driver = function (driver) { @@ -871,7 +871,7 @@ var Module = null; resolve(); } }; - }; + } var resizeCanvas = function (canvas, scale, resolution, aspectRatio) { if (scale && resolution) { @@ -1021,7 +1021,7 @@ var Module = null; } else if ('onwebkitfullscreenchange' in document) { document.addEventListener('webkitfullscreenchange', fullScreenChangeHandler); } - }; + } this.requestFullScreen = function () { Module.requestFullScreen(1, 0); @@ -1054,14 +1054,14 @@ var Module = null; } }); } - }; + } /** * misc */ function BFSOpenZip(loadedData) { return new BrowserFS.FileSystem.ZipFS(loadedData); - }; + } // This is such a hack. We're not calling the BrowserFS api // "correctly", so we have to synthesize these flags ourselves @@ -1119,7 +1119,7 @@ var Module = null; fs.readFileSync(dosboxConfPath, null, flag_r), null, flag_w, 0x1a4); } - }; + } function extend(a, b) { if (a === null) @@ -1170,7 +1170,7 @@ var Module = null; gain_node = context.createGain(); gain_node.gain.value = 1.0; gain_node.connect(context.destination); - }; + } function set_mastervolume ( // even though it's 'attenuation' the value is negative, so... @@ -1193,7 +1193,7 @@ var Module = null; gain_web_audio = +1; gain_node.gain.value = gain_web_audio; - }; + } function update_audio_stream ( pBuffer, // pointer into emscripten heap. int16 samples @@ -1236,7 +1236,7 @@ var Module = null; pending_buffers.push(buffer); tick(); - }; + } function tick () { // Note: this is the time the web audio mixer has mixed up to, @@ -1261,20 +1261,20 @@ var Module = null; // chunk of prebuffered audio. At that point it seems like // JSMESS never catches up and our sound glitches forever. - var insert_point = (buffer_insert_point === null) - ? now - : buffer_insert_point; + var insert_point = (buffer_insert_point === null) ? + now : + buffer_insert_point; if (pending_buffers.length) { - for (var i = 0, l = pending_buffers.length; i < l; i++) { - var buffer = pending_buffers[i]; + for (var _i = 0, _l = pending_buffers.length; _i < _l; _i++) { + var _buffer = pending_buffers[_i]; var source_node = context.createBufferSource(); - source_node.buffer = buffer; + source_node.buffer = _buffer; source_node.connect(gain_node); source_node.start(insert_point); - insert_point += buffer.duration; + insert_point += _buffer.duration; } pending_buffers.length = 0; @@ -1283,10 +1283,11 @@ var Module = null; if (buffer_insert_point <= now) buffer_insert_point = now; } - }; + } + function get_context() { return context; - }; + } return { set_mastervolume: set_mastervolume, From c94104cba2b7b00c13cada7f3c7f0dbb20e3aabf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Zanolli?= Date: Sun, 27 Sep 2015 20:46:25 -0300 Subject: [PATCH 2/2] Changes after getting feedback --- loader.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/loader.js b/loader.js index df77e42b..00912d45 100644 --- a/loader.js +++ b/loader.js @@ -32,17 +32,18 @@ var Module = null; } // yea, this is a hack - var images = (/archive\.org$/.test(document.location.hostname)) ? - { ia: img("/images/ialogo.png"), - mame: img("/images/mame.png"), - mess: img("/images/mess.png"), - dosbox: img("/images/dosbox.png") - } : { - ia: img("other_logos/ia-logo-150x150.png"), - mame: img("other_logos/mame.png"), - mess: img("other_logos/mess.png"), - dosbox: img("other_logos/dosbox.png") - }; + var images = (/archive\.org$/.test(document.location.hostname)) ? { + ia: img("/images/ialogo.png"), + mame: img("/images/mame.png"), + mess: img("/images/mess.png"), + dosbox: img("/images/dosbox.png") + } + : { + ia: img("other_logos/ia-logo-150x150.png"), + mame: img("other_logos/mame.png"), + mess: img("other_logos/mess.png"), + dosbox: img("other_logos/dosbox.png") + }; function updateLogo() { if (emulator_logo) { @@ -190,9 +191,10 @@ var Module = null; // and a count, then fetch them in len = urls.length; + var node; for (i = 0; i < len; i++) { - node = urls[i], - drive = node.nodeName.split('_')[2], + node = urls[i]; + var drive = node.nodeName.split('_')[2], title = 'Game File ('+ (i+1) +' of '+ (game ? len+1 : len) +')', url = get_zip_url(node.textContent); files.push(cfgr.mountZip(drive, cfgr.fetchFile(title, url))); @@ -298,9 +300,9 @@ var Module = null; /** * BaseLoader */ - var BaseLoader = function() { + function BaseLoader() { return Array.prototype.reduce.call(arguments, extend); - }; + } BaseLoader.canvas = function (id) { var elem = id instanceof Element ? id : document.getElementById(id); @@ -403,14 +405,14 @@ var Module = null; /** * JSMAMELoader */ - var JSMAMELoader = function() { + function JSMAMELoader() { var config = Array.prototype.reduce.call(arguments, extend); config.emulator_arguments = build_mame_arguments(config.muted, config.mess_driver, config.nativeResolution, config.sample_rate, config.extra_mess_args); config.needs_jsmess_webaudio = true; return config; - }; + } JSMAMELoader.__proto__ = BaseLoader; @@ -1261,9 +1263,9 @@ var Module = null; // chunk of prebuffered audio. At that point it seems like // JSMESS never catches up and our sound glitches forever. - var insert_point = (buffer_insert_point === null) ? - now : - buffer_insert_point; + var insert_point = (buffer_insert_point === null) + ? now + : buffer_insert_point; if (pending_buffers.length) { for (var _i = 0, _l = pending_buffers.length; _i < _l; _i++) {