From 73e7a5aeda5d68823eabab8771f5b7080874b039 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Thu, 27 Aug 2015 22:41:16 +0530 Subject: [PATCH 1/4] lib: compare strings with strict equality operator This patch makes sure that the strings are compared with strict equality operator. --- lib/_debugger.js | 16 ++++++++-------- lib/assert.js | 2 +- lib/dgram.js | 6 +++--- lib/punycode.js | 10 +++++----- lib/readline.js | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/_debugger.js b/lib/_debugger.js index 9f8fa26f2189c3..3539af7ec21f35 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -186,7 +186,7 @@ Client.prototype._addScript = function(desc) { this.scripts[desc.id] = desc; if (desc.name) { desc.isNative = (desc.name.replace('.js', '') in natives) || - desc.name == 'node.js'; + desc.name === 'node.js'; } }; @@ -211,25 +211,25 @@ Client.prototype._onResponse = function(res) { var self = this; var handled = false; - if (res.headers.Type == 'connect') { + if (res.headers.Type === 'connect') { // Request a list of scripts for our own storage. self.reqScripts(); self.emit('ready'); handled = true; - } else if (res.body && res.body.event == 'break') { + } else if (res.body && res.body.event === 'break') { this.emit('break', res.body); handled = true; - } else if (res.body && res.body.event == 'exception') { + } else if (res.body && res.body.event === 'exception') { this.emit('exception', res.body); handled = true; - } else if (res.body && res.body.event == 'afterCompile') { + } else if (res.body && res.body.event === 'afterCompile') { this._addHandle(res.body.body.script); handled = true; - } else if (res.body && res.body.event == 'scriptCollected') { + } else if (res.body && res.body.event === 'scriptCollected') { // ??? this._removeScript(res.body.body.script); handled = true; @@ -528,9 +528,9 @@ Client.prototype.mirrorObject = function(handle, depth, cb) { var mirror, waiting = 1; - if (handle.className == 'Array') { + if (handle.className === 'Array') { mirror = []; - } else if (handle.className == 'Date') { + } else if (handle.className === 'Date') { mirror = new Date(handle.value); } else { mirror = {}; diff --git a/lib/assert.js b/lib/assert.js index ea142ed01f8f6e..ddd3a92c902279 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -164,7 +164,7 @@ function _deepEqual(actual, expected, strict) { actual.lastIndex === expected.lastIndex && actual.ignoreCase === expected.ignoreCase; - // 7.4. Other pairs that do not both pass typeof value == 'object', + // 7.4. Other pairs that do not both pass typeof value === 'object', // equivalence is determined by ==. } else if ((actual === null || typeof actual !== 'object') && (expected === null || typeof expected !== 'object')) { diff --git a/lib/dgram.js b/lib/dgram.js index b7bb7d3d703eb1..548bc3fde5d2dd 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -39,13 +39,13 @@ function lookup6(address, callback) { function newHandle(type) { - if (type == 'udp4') { + if (type === 'udp4') { var handle = new UDP(); handle.lookup = lookup4; return handle; } - if (type == 'udp6') { + if (type === 'udp6') { var handle = new UDP(); handle.lookup = lookup6; handle.bind = handle.bind6; @@ -53,7 +53,7 @@ function newHandle(type) { return handle; } - if (type == 'unix_dgram') + if (type === 'unix_dgram') throw new Error('unix_dgram sockets are not supported any more.'); throw new Error('Bad socket type specified. Valid types are: udp4, udp6'); diff --git a/lib/punycode.js b/lib/punycode.js index 51aa75132937d5..4873615a1a03a7 100644 --- a/lib/punycode.js +++ b/lib/punycode.js @@ -2,11 +2,11 @@ ;(function(root) { /** Detect free variables */ - var freeExports = typeof exports == 'object' && exports && + var freeExports = typeof exports === 'object' && exports && !exports.nodeType && exports; - var freeModule = typeof module == 'object' && module && + var freeModule = typeof module === 'object' && module && !module.nodeType && module; - var freeGlobal = typeof global == 'object' && global; + var freeGlobal = typeof global === 'object' && global; if ( freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || @@ -508,8 +508,8 @@ // Some AMD build optimizers, like r.js, check for specific condition patterns // like the following: if ( - typeof define == 'function' && - typeof define.amd == 'object' && + typeof define === 'function' && + typeof define.amd === 'object' && define.amd ) { define('punycode', function() { diff --git a/lib/readline.js b/lib/readline.js index 6164bcc85fb8ff..82c83b3d7782e6 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -664,7 +664,7 @@ Interface.prototype._ttyWrite = function(s, key) { key = key || {}; // Ignore escape key - Fixes #2876 - if (key.name == 'escape') return; + if (key.name === 'escape') return; if (key.ctrl && key.shift) { /* Control and shift pressed */ @@ -745,7 +745,7 @@ Interface.prototype._ttyWrite = function(s, key) { break; case 'z': - if (process.platform == 'win32') break; + if (process.platform === 'win32') break; if (this.listenerCount('SIGTSTP') > 0) { this.emit('SIGTSTP'); } else { @@ -930,7 +930,7 @@ function emitKeypressEvents(stream) { } function onNewListener(event) { - if (event == 'keypress') { + if (event === 'keypress') { stream.on('data', onData); stream.removeListener('newListener', onNewListener); } From cf922dfec68c40bf0807ca7347d709164c0a7652 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Thu, 27 Aug 2015 22:43:28 +0530 Subject: [PATCH 2/4] src: compare strings with strict equality operator This patch makes sure that the strings are compared with strict equality operator. --- src/node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node.js b/src/node.js index bd91fb888ae046..730cc1821ac404 100644 --- a/src/node.js +++ b/src/node.js @@ -58,7 +58,7 @@ NativeModule.require('_third_party_main'); }); - } else if (process.argv[1] == 'debug') { + } else if (process.argv[1] === 'debug') { // Start the debugger agent var d = NativeModule.require('_debugger'); d.start(); @@ -869,7 +869,7 @@ NativeModule._cache = {}; NativeModule.require = function(id) { - if (id == 'native_module') { + if (id === 'native_module') { return NativeModule; } From 3cc64855c74034d86065163b2cda6ec2d9b38619 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Thu, 27 Aug 2015 22:43:49 +0530 Subject: [PATCH 3/4] test: compare strings with strict equality operators This patch makes sure that the strings are compared with strict equality operators. --- test/disabled/test-sendfd.js | 2 +- test/internet/test-dns.js | 2 +- test/parallel/test-cluster-uncaught-exception.js | 2 +- test/parallel/test-cluster-worker-exit.js | 2 +- test/parallel/test-cluster-worker-kill.js | 2 +- test/parallel/test-fs-readfile-unlink.js | 2 +- test/parallel/test-fs-utimes.js | 2 +- test/parallel/test-http-upgrade-server.js | 2 +- test/parallel/test-net-pipe-connect-errors.js | 2 +- test/parallel/test-net-server-try-ports.js | 2 +- test/parallel/test-os.js | 2 +- test/parallel/test-process-env.js | 2 +- test/pummel/test-dtrace-jsstack.js | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/disabled/test-sendfd.js b/test/disabled/test-sendfd.js index 4eefbeab549685..363dc22192d898 100644 --- a/test/disabled/test-sendfd.js +++ b/test/disabled/test-sendfd.js @@ -46,7 +46,7 @@ var SOCK_PATH = path.join(__dirname, path.basename(__filename, '.js') + '.sock'); var logChild = function(d) { - if (typeof d == 'object') { + if (typeof d === 'object') { d = d.toString(); } diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index 796fd26c0a2e72..56d6094ec81ea2 100644 --- a/test/internet/test-dns.js +++ b/test/internet/test-dns.js @@ -709,7 +709,7 @@ req.oncomplete = function(err, domains) { console.log('nodejs.org = ', domains); assert.ok(Array.isArray(domains)); assert.ok(domains.length >= 1); - assert.ok(typeof domains[0] == 'string'); + assert.ok(typeof domains[0] === 'string'); getaddrinfoCallbackCalled = true; }; diff --git a/test/parallel/test-cluster-uncaught-exception.js b/test/parallel/test-cluster-uncaught-exception.js index ec42773ef55856..75043e13a8e9fe 100644 --- a/test/parallel/test-cluster-uncaught-exception.js +++ b/test/parallel/test-cluster-uncaught-exception.js @@ -10,7 +10,7 @@ var fork = require('child_process').fork; var MAGIC_EXIT_CODE = 42; -var isTestRunner = process.argv[2] != 'child'; +var isTestRunner = process.argv[2] !== 'child'; if (isTestRunner) { var exitCode = -1; diff --git a/test/parallel/test-cluster-worker-exit.js b/test/parallel/test-cluster-worker-exit.js index 3607a992a33dff..a0e2cce993ca66 100644 --- a/test/parallel/test-cluster-worker-exit.js +++ b/test/parallel/test-cluster-worker-exit.js @@ -88,7 +88,7 @@ if (cluster.isWorker) { checkResults(expected_results, results); } catch (exc) { console.error('FAIL: ' + exc.message); - if (exc.name != 'AssertionError') { + if (exc.name !== 'AssertionError') { console.trace(exc); } diff --git a/test/parallel/test-cluster-worker-kill.js b/test/parallel/test-cluster-worker-kill.js index e12b466610171a..64534caa57abf0 100644 --- a/test/parallel/test-cluster-worker-kill.js +++ b/test/parallel/test-cluster-worker-kill.js @@ -88,7 +88,7 @@ if (cluster.isWorker) { checkResults(expected_results, results); } catch (exc) { console.error('FAIL: ' + exc.message); - if (exc.name != 'AssertionError') { + if (exc.name !== 'AssertionError') { console.trace(exc); } diff --git a/test/parallel/test-fs-readfile-unlink.js b/test/parallel/test-fs-readfile-unlink.js index 15491b71c433ed..643506bd48ed87 100644 --- a/test/parallel/test-fs-readfile-unlink.js +++ b/test/parallel/test-fs-readfile-unlink.js @@ -13,7 +13,7 @@ try { fs.mkdirSync(dirName); } catch (e) { // Ignore if the directory already exists. - if (e.code != 'EEXIST') throw e; + if (e.code !== 'EEXIST') throw e; } fs.writeFileSync(fileName, buf); diff --git a/test/parallel/test-fs-utimes.js b/test/parallel/test-fs-utimes.js index 292636b1b69108..cf75d955def836 100644 --- a/test/parallel/test-fs-utimes.js +++ b/test/parallel/test-fs-utimes.js @@ -8,7 +8,7 @@ var tests_ok = 0; var tests_run = 0; function stat_resource(resource) { - if (typeof resource == 'string') { + if (typeof resource === 'string') { return fs.statSync(resource); } else { // ensure mtime has been written to disk diff --git a/test/parallel/test-http-upgrade-server.js b/test/parallel/test-http-upgrade-server.js index 9b34fe42eb05b9..b9a893bb6c2572 100644 --- a/test/parallel/test-http-upgrade-server.js +++ b/test/parallel/test-http-upgrade-server.js @@ -39,7 +39,7 @@ function testServer() { socket.on('data', function(d) { var data = d.toString('utf8'); - if (data == 'kill') { + if (data === 'kill') { socket.end(); } else { socket.write(data, 'utf8'); diff --git a/test/parallel/test-net-pipe-connect-errors.js b/test/parallel/test-net-pipe-connect-errors.js index e2ec1debf12617..9f6c7668c5a6fd 100644 --- a/test/parallel/test-net-pipe-connect-errors.js +++ b/test/parallel/test-net-pipe-connect-errors.js @@ -27,7 +27,7 @@ if (common.isWindows) { try { fs.unlinkSync(emptyTxt); } catch (e) { - if (e.code != 'ENOENT') + if (e.code !== 'ENOENT') throw e; } } diff --git a/test/parallel/test-net-server-try-ports.js b/test/parallel/test-net-server-try-ports.js index 742062abf62690..61b74a8723f038 100644 --- a/test/parallel/test-net-server-try-ports.js +++ b/test/parallel/test-net-server-try-ports.js @@ -26,7 +26,7 @@ server2.on('error', function(e) { server2errors++; console.error('server2 error'); - if (e.code == 'EADDRINUSE') { + if (e.code === 'EADDRINUSE') { server2eaddrinuse = true; } diff --git a/test/parallel/test-os.js b/test/parallel/test-os.js index f7fe4634c40dca..d4ca70919dcc0c 100644 --- a/test/parallel/test-os.js +++ b/test/parallel/test-os.js @@ -71,7 +71,7 @@ var arch = os.arch(); console.log('arch = ', arch); assert.ok(arch.length > 0); -if (process.platform != 'sunos') { +if (process.platform !== 'sunos') { // not implemeneted yet assert.ok(os.loadavg().length > 0); assert.ok(os.freemem() > 0); diff --git a/test/parallel/test-process-env.js b/test/parallel/test-process-env.js index 7e927d09bae668..a9dd183514d7c3 100644 --- a/test/parallel/test-process-env.js +++ b/test/parallel/test-process-env.js @@ -25,7 +25,7 @@ assert.equal(5, date.getHours()); // changes in environment should be visible to child processes -if (process.argv[2] == 'you-are-the-child') { +if (process.argv[2] === 'you-are-the-child') { // failed assertion results in process exiting with status code 1 assert.equal(false, 'NODE_PROCESS_ENV_DELETED' in process.env); assert.equal(42, process.env.NODE_PROCESS_ENV); diff --git a/test/pummel/test-dtrace-jsstack.js b/test/pummel/test-dtrace-jsstack.js index 67194a3dd77f53..b2c7cdd551aab0 100644 --- a/test/pummel/test-dtrace-jsstack.js +++ b/test/pummel/test-dtrace-jsstack.js @@ -4,7 +4,7 @@ var assert = require('assert'); var os = require('os'); var util = require('util'); -if (os.type() != 'SunOS') { +if (os.type() !== 'SunOS') { console.log('1..0 # Skipped: no DTRACE support'); return; } From 301e14fcb10ec0576e4bc9ffa9a0e450f055bf34 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Thu, 27 Aug 2015 22:46:40 +0530 Subject: [PATCH 4/4] benchmark: compare strings with strict equality operators This patch makes sure that the strings are compared with strict equality operators. --- benchmark/common.js | 12 ++++++------ benchmark/http_simple.js | 12 ++++++------ benchmark/http_simple_auto.js | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/benchmark/common.js b/benchmark/common.js index 158354004cd6bb..ecd88e46524670 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -60,7 +60,7 @@ function runBenchmarks() { if (test.match(/^[\._]/)) return process.nextTick(runBenchmarks); - if (outputFormat == 'default') + if (outputFormat === 'default') console.error(type + '/' + test); test = path.resolve(dir, test); @@ -160,7 +160,7 @@ Benchmark.prototype._run = function() { }, [[main]]); // output csv heading - if (outputFormat == 'csv') + if (outputFormat === 'csv') console.log('filename,' + Object.keys(options).join(',') + ',result'); var node = process.execPath; @@ -229,9 +229,9 @@ Benchmark.prototype.end = function(operations) { Benchmark.prototype.report = function(value) { var heading = this.getHeading(); - if (outputFormat == 'default') + if (outputFormat === 'default') console.log('%s: %s', heading, value.toFixed(5)); - else if (outputFormat == 'csv') + else if (outputFormat === 'csv') console.log('%s,%s', heading, value.toFixed(5)); process.exit(0); @@ -240,11 +240,11 @@ Benchmark.prototype.report = function(value) { Benchmark.prototype.getHeading = function() { var conf = this.config; - if (outputFormat == 'default') { + if (outputFormat === 'default') { return this._name + ' ' + Object.keys(conf).map(function(key) { return key + '=' + conf[key]; }).join(' '); - } else if (outputFormat == 'csv') { + } else if (outputFormat === 'csv') { return this._name + ',' + Object.keys(conf).map(function(key) { return conf[key]; }).join(','); diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js index 36800f2c9dba5a..915d34d0148b73 100644 --- a/benchmark/http_simple.js +++ b/benchmark/http_simple.js @@ -36,7 +36,7 @@ var server = module.exports = http.createServer(function (req, res) { var n_chunks = parseInt(commands[3], 10); var status = 200; - if (command == 'bytes') { + if (command === 'bytes') { var n = ~~arg; if (n <= 0) throw new Error('bytes called with n <= 0') @@ -45,7 +45,7 @@ var server = module.exports = http.createServer(function (req, res) { } body = storedBytes[n]; - } else if (command == 'buffer') { + } else if (command === 'buffer') { var n = ~~arg; if (n <= 0) throw new Error('buffer called with n <= 0'); @@ -57,7 +57,7 @@ var server = module.exports = http.createServer(function (req, res) { } body = storedBuffer[n]; - } else if (command == 'unicode') { + } else if (command === 'unicode') { var n = ~~arg; if (n <= 0) throw new Error('unicode called with n <= 0'); @@ -66,14 +66,14 @@ var server = module.exports = http.createServer(function (req, res) { } body = storedUnicode[n]; - } else if (command == 'quit') { + } else if (command === 'quit') { res.connection.server.close(); body = 'quitting'; - } else if (command == 'fixed') { + } else if (command === 'fixed') { body = fixed; - } else if (command == 'echo') { + } else if (command === 'echo') { res.writeHead(200, { 'Content-Type': 'text/plain', 'Transfer-Encoding': 'chunked' }); req.pipe(res); diff --git a/benchmark/http_simple_auto.js b/benchmark/http_simple_auto.js index f72cc01e60aa46..5d67d89dc91198 100644 --- a/benchmark/http_simple_auto.js +++ b/benchmark/http_simple_auto.js @@ -109,7 +109,7 @@ server.listen(port, function () { }); function dump_mm_stats() { - if (typeof gc != 'function') return; + if (typeof gc !== 'function') return; var before = process.memoryUsage(); for (var i = 0; i < 10; ++i) gc();