Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare strings with strict equality operators #2582

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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(',');
Expand Down
12 changes: 6 additions & 6 deletions benchmark/http_simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/http_simple_auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
};

Expand All @@ -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;
Expand Down Expand Up @@ -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 = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
6 changes: 3 additions & 3 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ 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;
handle.send = handle.send6;
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');
Expand Down
10 changes: 5 additions & 5 deletions lib/punycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -930,7 +930,7 @@ function emitKeypressEvents(stream) {
}

function onNewListener(event) {
if (event == 'keypress') {
if (event === 'keypress') {
stream.on('data', onData);
stream.removeListener('newListener', onNewListener);
}
Expand Down
4 changes: 2 additions & 2 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -869,7 +869,7 @@
NativeModule._cache = {};

NativeModule.require = function(id) {
if (id == 'native_module') {
if (id === 'native_module') {
return NativeModule;
}

Expand Down
2 changes: 1 addition & 1 deletion test/disabled/test-sendfd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-uncaught-exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-worker-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-worker-kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-readfile-unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-utimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-upgrade-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-net-pipe-connect-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (common.isWindows) {
try {
fs.unlinkSync(emptyTxt);
} catch (e) {
if (e.code != 'ENOENT')
if (e.code !== 'ENOENT')
throw e;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-net-server-try-ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ server2.on('error', function(e) {
server2errors++;
console.error('server2 error');

if (e.code == 'EADDRINUSE') {
if (e.code === 'EADDRINUSE') {
server2eaddrinuse = true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-process-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/pummel/test-dtrace-jsstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down