From 19d63b4710443082e1e7c92d35c81df6541a1285 Mon Sep 17 00:00:00 2001 From: Jeff Parsons Date: Sun, 18 Dec 2016 15:05:41 -0800 Subject: [PATCH 01/12] I'm Dreaming of White Spaces --- modules/pcx86/lib/keyboard.js | 4 ++-- modules/shared/es6/component.js | 2 +- modules/shared/es6/netlib.js | 22 +++++++++++----------- modules/shared/es6/proclib.js | 2 +- modules/shared/es6/strlib.js | 4 ++-- modules/shared/es6/usrlib.js | 2 +- modules/shared/es6/weblib.js | 14 +++++++------- modules/shared/lib/component.js | 2 +- modules/shared/lib/sockets.js | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/modules/pcx86/lib/keyboard.js b/modules/pcx86/lib/keyboard.js index 2e228bb44b..ee312e2b98 100644 --- a/modules/pcx86/lib/keyboard.js +++ b/modules/pcx86/lib/keyboard.js @@ -1043,7 +1043,7 @@ Keyboard.prototype.setBinding = function(sHTMLType, sBinding, control, sValue) kbd.addActiveKey(simCode); }; }(this, sBinding, Keyboard.SOFTCODES[sBinding]); - var fnUp = function (kbd, sKey, simCode) { + var fnUp = function(kbd, sKey, simCode) { return function onKeyboardBindingUp(event) { kbd.removeActiveKey(simCode); }; @@ -1655,7 +1655,7 @@ Keyboard.prototype.injectKeysFromBuffer = function(msDelay) this.addActiveKey(ch, true); } if (this.sInjectBuffer.length > 0) { - setTimeout(function (kbd) { + setTimeout(function(kbd) { return function onInjectKeyTimeout() { kbd.injectKeysFromBuffer(msDelay); }; diff --git a/modules/shared/es6/component.js b/modules/shared/es6/component.js index d395e5299a..74f1ad9be0 100644 --- a/modules/shared/es6/component.js +++ b/modules/shared/es6/component.js @@ -1027,7 +1027,7 @@ if (!Array.prototype.indexOf) { * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray */ if (!Array.isArray) { - Array.isArray = function (arg) { + Array.isArray = function(arg) { return Object.prototype.toString.call(arg) === '[object Array]'; }; } diff --git a/modules/shared/es6/netlib.js b/modules/shared/es6/netlib.js index 4cb2a89ef0..d369970573 100644 --- a/modules/shared/es6/netlib.js +++ b/modules/shared/es6/netlib.js @@ -156,7 +156,7 @@ class Net { var options = url.parse(sURL); options.method = "HEAD"; options.path = options.pathname; // TODO: Determine the necessity of aliasing this - var req = http.request(options, function (res) + var req = http.request(options, function(res) { var err = null; var stat = null; @@ -179,7 +179,7 @@ class Net { } done(err, stat); }); - req.on('error', function (err) + req.on('error', function(err) { done(err, null); }); @@ -211,9 +211,9 @@ class Net { */ var sFile = ""; var bufFile = null; - http.get(sURL, function (res) + http.get(sURL, function(res) { - res.on('data', function (data) + res.on('data', function(data) { if (sEncoding) { sFile += data; @@ -241,7 +241,7 @@ class Net { * bufFile = buf; */ bufFile = Buffer.concat([bufFile, data], bufFile.length + data.length); - }).on('end', function () + }).on('end', function() { /* * TODO: Decide what to do when res.statusCode is actually an error code (eg, 404), because @@ -252,7 +252,7 @@ class Net { } else { done(new Error(sEncoding ? sFile : bufFile), res.statusCode, null); } - }).on('error', function (err) + }).on('error', function(err) { done(err, res.statusCode, null); }); @@ -279,12 +279,12 @@ class Net { * Either the documentation isn't quite right for url.parse() or http.request() (the big brother * of http.get), or one of those "options" properties is aliased to the other, or...? */ - http.get(sURL, function (res) + http.get(sURL, function(res) { - res.on('data', function (data) + res.on('data', function(data) { file.write(data); - }).on('end', function () + }).on('end', function() { file.end(); /* @@ -295,7 +295,7 @@ class Net { * in such cases, the file content will likely just be an HTML error page. */ done(null, res.statusCode); - }).on('error', function (err) + }).on('error', function(err) { done(err, res.statusCode); }); @@ -329,7 +329,7 @@ class Net { var sBaseName = Str.getBaseName(sURL); var sFile = path.join(Net.sServerRoot, sURL); if (fAsync) { - fs.readFile(sFile, {encoding: "utf8"}, function (err, s) + fs.readFile(sFile, {encoding: "utf8"}, function(err, s) { /* * TODO: If err is set, is there an error code we should return (instead of -1)? diff --git a/modules/shared/es6/proclib.js b/modules/shared/es6/proclib.js index aca7c8b584..818a708a42 100644 --- a/modules/shared/es6/proclib.js +++ b/modules/shared/es6/proclib.js @@ -44,7 +44,7 @@ class Proc { * * @return {{argc:number, argv:{}}} */ - static getArgs = function () + static getArgs() { var argc = 0; var argv = {}; diff --git a/modules/shared/es6/strlib.js b/modules/shared/es6/strlib.js index 804d9301bf..82264f4e4d 100644 --- a/modules/shared/es6/strlib.js +++ b/modules/shared/es6/strlib.js @@ -450,7 +450,7 @@ class Str { */ static escapeHTML(sHTML) { - return sHTML.replace(/[&<>"']/g, function (m) + return sHTML.replace(/[&<>"']/g, function(m) { return Str.aHTMLEscapeMap[m]; }); @@ -494,7 +494,7 @@ class Str { k = k.replace(/([\\[\]*{}().+?])/g, "\\$1"); sMatch += (sMatch ? '|' : '') + k; } - return s.replace(new RegExp('(' + sMatch + ')', "g"), function (m) + return s.replace(new RegExp('(' + sMatch + ')', "g"), function(m) { return a[m]; }); diff --git a/modules/shared/es6/usrlib.js b/modules/shared/es6/usrlib.js index 1ea251fd1c..d3260b457a 100644 --- a/modules/shared/es6/usrlib.js +++ b/modules/shared/es6/usrlib.js @@ -56,7 +56,7 @@ class Usr { var right = a.length; var found = 0; if (fnCompare === undefined) { - fnCompare = function (a, b) + fnCompare = function(a, b) { return a > b ? 1 : a < b ? -1 : 0; }; diff --git a/modules/shared/es6/weblib.js b/modules/shared/es6/weblib.js index cc7f22fd78..c83cc951ea 100644 --- a/modules/shared/es6/weblib.js +++ b/modules/shared/es6/weblib.js @@ -174,7 +174,7 @@ class Web { return [sResource, nErrorCode]; } else if (fAsync && typeof resources == 'function') { - resources(sURL, function (sResource, nErrorCode) + resources(sURL, function(sResource, nErrorCode) { if (done) done(sURL, sResource, nErrorCode); }); @@ -190,7 +190,7 @@ class Web { var xmlHTTP = (window.XMLHttpRequest ? new window.XMLHttpRequest() : new window.ActiveXObject("Microsoft.XMLHTTP")); if (fAsync) { - xmlHTTP.onreadystatechange = function () + xmlHTTP.onreadystatechange = function() { if (xmlHTTP.readyState === 4) { /* @@ -679,7 +679,7 @@ class Web { var match; var pl = /\+/g; // RegExp for replacing addition symbol with a space var search = /([^&=]+)=?([^&]*)/g; - var decode = function (s) + var decode = function(s) { return decodeURIComponent(s.replace(pl, " ")); }; @@ -777,7 +777,7 @@ class Web { ms = msRepeat; } }; - e.onmousedown = function () + e.onmousedown = function() { // Web.log("onMouseDown()"); if (!fIgnoreMouseEvents) { @@ -787,7 +787,7 @@ class Web { } } }; - e.ontouchstart = function () + e.ontouchstart = function() { // Web.log("onTouchStart()"); if (!timer) { @@ -795,7 +795,7 @@ class Web { fnRepeat(); } }; - e.onmouseup = e.onmouseout = function () + e.onmouseup = e.onmouseout = function() { // Web.log("onMouseUp()/onMouseOut()"); if (timer) { @@ -803,7 +803,7 @@ class Web { timer = null; } }; - e.ontouchend = e.ontouchcancel = function () + e.ontouchend = e.ontouchcancel = function() { // Web.log("onTouchEnd()/onTouchCancel()"); if (timer) { diff --git a/modules/shared/lib/component.js b/modules/shared/lib/component.js index 07a03b6f42..92b0abe8e0 100644 --- a/modules/shared/lib/component.js +++ b/modules/shared/lib/component.js @@ -1081,7 +1081,7 @@ if (!Array.prototype.indexOf) { * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray */ if (!Array.isArray) { - Array.isArray = function (arg) { + Array.isArray = function(arg) { return Object.prototype.toString.call(arg) === '[object Array]'; }; } diff --git a/modules/shared/lib/sockets.js b/modules/shared/lib/sockets.js index da453401c6..06c16914be 100644 --- a/modules/shared/lib/sockets.js +++ b/modules/shared/lib/sockets.js @@ -34,6 +34,6 @@ var socket = io.connect(); // if we get an "info" emit from the socket server then console.log the data we receive -socket.on('info', function (data) { +socket.on('info', function(data) { console.log(data); }); From 15f3053b694def1ba3f344f30f83323abb8e9066 Mon Sep 17 00:00:00 2001 From: Jeff Parsons Date: Wed, 21 Dec 2016 16:07:11 -0800 Subject: [PATCH 02/12] Some notes on ES6 adoption and work-arounds --- modules/pdp11/README.md | 82 ++++++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 17 deletions(-) diff --git a/modules/pdp11/README.md b/modules/pdp11/README.md index 8a2703415f..19d96e4758 100644 --- a/modules/pdp11/README.md +++ b/modules/pdp11/README.md @@ -9,29 +9,77 @@ PDP-11 Machine Emulation Module (PDPjs) Overview --- -PDPjs, our [PDP-11 Machine](/devices/pdp11/machine/) emulation module, is adapted from -the [PDP-11/70 Emulator (v1.4)](http://skn.noip.me/pdp11/pdp11.html) written by -Paul Nankervis. +PDPjs, our [PDP-11 Machine](/devices/pdp11/machine/) emulation module, was written in 2016. It was adapted from +the [PDP-11/70 Emulator (v1.4)](http://skn.noip.me/pdp11/pdp11.html) written by Paul Nankervis. -PDPjs is currently comprised of the following non-shared components, as listed in -[package.json](../../package.json) (see the *pdp11Files* property): +PDPjs is currently comprised of the following PDP-11 components, as listed in [package.json](../../package.json) +(see the *pdp11Files* property): -* [defines.js](/modules/pdp11/lib/defines.js) -* [messages.js](/modules/pdp11/lib/messages.js) -* [panel.js](/modules/pdp11/lib/panel.js) * [bus.js](/modules/pdp11/lib/bus.js) -* [device.js](/modules/pdp11/lib/device.js) -* [memory.js](/modules/pdp11/lib/memory.js) +* [computer.js](/modules/pdp11/lib/computer.js) * [cpu.js](/modules/pdp11/lib/cpu.js) -* [cpustate.js](/modules/pdp11/lib/cpustate.js) * [cpuops.js](/modules/pdp11/lib/cpuops.js) -* [rom.js](/modules/pdp11/lib/rom.js) -* [ram.js](/modules/pdp11/lib/ram.js) +* [cpustate.js](/modules/pdp11/lib/cpustate.js) +* [debugger.js](/modules/pdp11/lib/debugger.js) +* [defines.js](/modules/pdp11/lib/defines.js) +* [device.js](/modules/pdp11/lib/device.js) +* [disk.js](/modules/pdp11/lib/disk.js) * [keyboard.js](/modules/pdp11/lib/keyboard.js) -* [serialport.js](/modules/pdp11/lib/serialport.js) +* [memory.js](/modules/pdp11/lib/memory.js) +* [messages.js](/modules/pdp11/lib/messages.js) +* [panel.js](/modules/pdp11/lib/panel.js) * [pc11.js](/modules/pdp11/lib/pc11.js) -* [disk.js](/modules/pdp11/lib/disk.js) +* [ram.js](/modules/pdp11/lib/ram.js) * [rk11.js](/modules/pdp11/lib/rk11.js) * [rl11.js](/modules/pdp11/lib/rl11.js) -* [debugger.js](/modules/pdp11/lib/debugger.js) -* [computer.js](/modules/pdp11/lib/computer.js) +* [rom.js](/modules/pdp11/lib/rom.js) +* [serialport.js](/modules/pdp11/lib/serialport.js) + +Since this module was written in 2016, it seemed appropriate to start adopting some of the more useful features of +[ECMAScript](http://www.ecma-international.org/ecma-262/6.0/index.html) 2015 (aka ES6), including: + +* Classes +* *const* and *let* +* Computed Properties +* Default Parameters +* Octal and Binary Constants +* Template Literals + - String Interpolation (i.e., ${*expr*}) +* New Built-in Methods + - String.repeat() +* *import* and *export* + +However, I've still configured the Closure Compiler to "transpile" to ECMAScript 5 (aka ES5), because some people +may still be using older browsers that don't support ES6 -- or at least the subset of ES6 features I'm currently +using. + +Eventually, I need to do some performance testing and determine whether the ES6 version performs any faster and/or +consumes fewer resources than the ES5 version. If it does, then I should either bite the bullet and generate ES6 code, +or generate both versions and use a loader that detects the browser's capabilities and loads the appropriate version. + +Caveats +------- + +With regard to *import* and *export* statements, the main reason I use them is to inform my development environment +(WebStorm) about each file's dependencies, thereby preventing inspection warnings. Ultimately, I plan to make PDPjs +run as a Node application, so explicitly declaring all imports and exports will be required, but for now, it's just +a web application, so strictly speaking, they're not required. + +When loading uncompiled PDPjs files into a web browser, the Node-based web server bundled with PCjs still relies on +the `