Skip to content

Commit

Permalink
lib: turn on strict mode
Browse files Browse the repository at this point in the history
Turn on strict mode for the files in the lib/ directory.  It helps
catch bugs and can have a positive effect on performance.

PR-URL: node-forward/node#64
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
  • Loading branch information
bnoordhuis committed Nov 22, 2014
1 parent 963f5e8 commit 21130c7
Show file tree
Hide file tree
Showing 52 changed files with 110 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/_debug_agent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var assert = require('assert');
var net = require('net');
var util = require('util');
Expand Down
2 changes: 2 additions & 0 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var util = require('util'),
path = require('path'),
net = require('net'),
Expand Down
2 changes: 2 additions & 0 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var net = require('net');
var util = require('util');
var EventEmitter = require('events').EventEmitter;
Expand Down
2 changes: 2 additions & 0 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var util = require('util');
var net = require('net');
var url = require('url');
Expand Down
2 changes: 2 additions & 0 deletions lib/_http_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var FreeList = require('freelist').FreeList;
var HTTPParser = process.binding('http_parser').HTTPParser;

Expand Down
2 changes: 2 additions & 0 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var util = require('util');
var Stream = require('stream');

Expand Down
2 changes: 2 additions & 0 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var assert = require('assert').ok;
var Stream = require('stream');
var timers = require('timers');
Expand Down
2 changes: 2 additions & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var util = require('util');
var net = require('net');
var EventEmitter = require('events').EventEmitter;
Expand Down
2 changes: 2 additions & 0 deletions lib/_linklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

function init(list) {
list._idleNext = list;
list._idlePrev = list;
Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// prototypally inherits from Readable, and then parasitically from
// Writable.

'use strict';

module.exports = Duplex;
var util = require('util');
var Readable = require('_stream_readable');
Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_passthrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
// basically just the most minimal sort of Transform stream.
// Every written chunk gets output as-is.

'use strict';

module.exports = PassThrough;

var Transform = require('_stream_transform');
Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

module.exports = Readable;
Readable.ReadableState = ReadableState;

Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
// would be consumed, and then the rest would wait (un-transformed) until
// the results of the previous transformed chunk were consumed.

'use strict';

module.exports = Transform;

var Duplex = require('_stream_duplex');
Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
// Implement an async ._write(chunk, cb), and it'll handle all
// the drain event emission and buffering.

'use strict';

module.exports = Writable;
Writable.WritableState = WritableState;

Expand Down
2 changes: 2 additions & 0 deletions lib/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var util = require('util');
var constants = require('constants');
var tls = require('tls');
Expand Down
6 changes: 4 additions & 2 deletions lib/_tls_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var assert = require('assert');
var events = require('events');
var stream = require('stream');
Expand Down Expand Up @@ -444,9 +446,9 @@ CryptoStream.prototype.destroySoon = function(err) {
// was written on this side was read from the other side.
var self = this;
var waiting = 1;
function finish() {
var finish = function() {
if (--waiting === 0) self.destroy();
}
};
this._opposite.once('end', finish);
if (!this._finished) {
this.once('finish', finish);
Expand Down
2 changes: 2 additions & 0 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var assert = require('assert');
var crypto = require('crypto');
var net = require('net');
Expand Down
2 changes: 2 additions & 0 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

// UTILITY
var util = require('util');
var pSlice = Array.prototype.slice;
Expand Down
2 changes: 2 additions & 0 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var buffer = process.binding('buffer');
var smalloc = process.binding('smalloc');
var util = require('util');
Expand Down
2 changes: 2 additions & 0 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var StringDecoder = require('string_decoder').StringDecoder;
var EventEmitter = require('events').EventEmitter;
var net = require('net');
Expand Down
4 changes: 2 additions & 2 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var EventEmitter = require('events').EventEmitter;
var assert = require('assert');
var dgram = require('dgram');
Expand Down Expand Up @@ -680,8 +682,6 @@ function sendHelper(proc, message, handle, cb) {
// to the callback but intercepts and redirects ACK messages.
function internal(worker, cb) {
return function(message, handle) {
'use strict';

if (message.cmd !== 'NODE_CLUSTER') return;
var fn = cb;
if (!util.isUndefined(message.ack)) {
Expand Down
6 changes: 4 additions & 2 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var util = require('util');

function Console(stdout, stderr) {
Expand Down Expand Up @@ -89,13 +91,13 @@ Console.prototype.timeEnd = function(label) {
};


Console.prototype.trace = function() {
Console.prototype.trace = function trace() {
// TODO probably can to do this better with V8's debug object once that is
// exposed.
var err = new Error;
err.name = 'Trace';
err.message = util.format.apply(this, arguments);
Error.captureStackTrace(err, arguments.callee);
Error.captureStackTrace(err, trace);
this.error(err.stack);
};

Expand Down
2 changes: 2 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

module.exports = process.binding('constants');
6 changes: 4 additions & 2 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// Note: In 0.8 and before, crypto functions all defaulted to using
// binary-encoded strings rather than buffers.

'use strict';

exports.DEFAULT_ENCODING = 'buffer';

try {
Expand Down Expand Up @@ -600,11 +602,11 @@ function pbkdf2(password, salt, iterations, keylen, digest, callback) {
// at this point, we need to handle encodings.
var encoding = exports.DEFAULT_ENCODING;
if (callback) {
function next(er, ret) {
var next = function(er, ret) {
if (ret)
ret = ret.toString(encoding);
callback(er, ret);
}
};
binding.PBKDF2(password, salt, iterations, keylen, digest, next);
} else {
var ret = binding.PBKDF2(password, salt, iterations, keylen, digest);
Expand Down
2 changes: 2 additions & 0 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var assert = require('assert');
var util = require('util');
var events = require('events');
Expand Down
2 changes: 2 additions & 0 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var net = require('net');
var util = require('util');

Expand Down
2 changes: 2 additions & 0 deletions lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var util = require('util');
var EventEmitter = require('events');
var inherits = util.inherits;
Expand Down
2 changes: 2 additions & 0 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var domain;
var util = require('util');

Expand Down
2 changes: 2 additions & 0 deletions lib/freelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

// This is a free list to avoid creating so many of the same object.
exports.FreeList = function(name, max, constructor) {
this.name = name;
Expand Down
2 changes: 2 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
//
// var mode = 438; /* mode=0666 */

'use strict';

var util = require('util');
var pathModule = require('path');

Expand Down
2 changes: 2 additions & 0 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var util = require('util');
var EventEmitter = require('events').EventEmitter;

Expand Down
2 changes: 2 additions & 0 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var tls = require('tls');
var url = require('url');
var http = require('http');
Expand Down
2 changes: 2 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var NativeModule = require('native_module');
var util = NativeModule.require('util');
var runInThisContext = require('vm').runInThisContext;
Expand Down
3 changes: 2 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var events = require('events');
var stream = require('stream');
var timers = require('timers');
Expand Down Expand Up @@ -612,7 +614,6 @@ Socket.prototype.__defineGetter__('localPort', function() {


Socket.prototype.write = function(chunk, encoding, cb) {
'use strict';
if (!util.isString(chunk) && !util.isBuffer(chunk))
throw new TypeError('invalid data');
return stream.Duplex.prototype.write.apply(this, arguments);
Expand Down
2 changes: 2 additions & 0 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var binding = process.binding('os');
var util = require('util');
var isWindows = process.platform === 'win32';
Expand Down
1 change: 1 addition & 0 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var isWindows = process.platform === 'win32';
var util = require('util');
Expand Down
2 changes: 2 additions & 0 deletions lib/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

// Query String Utilities

'use strict';

var QueryString = exports;
var util = require('util');

Expand Down
2 changes: 2 additions & 0 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
// * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
// * http://www.3waylabs.com/nw/WWW/products/wizcon/vt220.html

'use strict';

var kHistorySize = 30;

var util = require('util');
Expand Down
Loading

0 comments on commit 21130c7

Please sign in to comment.