Browse Source

lib: turn on strict mode

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: https://github.com/node-forward/node/pull/64
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
archived-io.js-v0.12
Ben Noordhuis 10 years ago
parent
commit
21130c7d6f
  1. 2
      lib/_debug_agent.js
  2. 2
      lib/_debugger.js
  3. 2
      lib/_http_agent.js
  4. 2
      lib/_http_client.js
  5. 2
      lib/_http_common.js
  6. 2
      lib/_http_incoming.js
  7. 2
      lib/_http_outgoing.js
  8. 2
      lib/_http_server.js
  9. 2
      lib/_linklist.js
  10. 2
      lib/_stream_duplex.js
  11. 2
      lib/_stream_passthrough.js
  12. 2
      lib/_stream_readable.js
  13. 2
      lib/_stream_transform.js
  14. 2
      lib/_stream_writable.js
  15. 2
      lib/_tls_common.js
  16. 6
      lib/_tls_legacy.js
  17. 2
      lib/_tls_wrap.js
  18. 2
      lib/assert.js
  19. 2
      lib/buffer.js
  20. 2
      lib/child_process.js
  21. 4
      lib/cluster.js
  22. 6
      lib/console.js
  23. 2
      lib/constants.js
  24. 6
      lib/crypto.js
  25. 2
      lib/dgram.js
  26. 2
      lib/dns.js
  27. 2
      lib/domain.js
  28. 2
      lib/events.js
  29. 2
      lib/freelist.js
  30. 2
      lib/fs.js
  31. 2
      lib/http.js
  32. 2
      lib/https.js
  33. 2
      lib/module.js
  34. 3
      lib/net.js
  35. 2
      lib/os.js
  36. 1
      lib/path.js
  37. 2
      lib/querystring.js
  38. 2
      lib/readline.js
  39. 2
      lib/repl.js
  40. 2
      lib/smalloc.js
  41. 2
      lib/stream.js
  42. 2
      lib/string_decoder.js
  43. 2
      lib/sys.js
  44. 2
      lib/timers.js
  45. 2
      lib/tls.js
  46. 2
      lib/tracing.js
  47. 2
      lib/tty.js
  48. 2
      lib/url.js
  49. 2
      lib/util.js
  50. 2
      lib/vm.js
  51. 2
      lib/zlib.js
  52. 3
      src/node.js

2
lib/_debug_agent.js

@ -1,3 +1,5 @@
'use strict';
var assert = require('assert');
var net = require('net');
var util = require('util');

2
lib/_debugger.js

@ -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'),

2
lib/_http_agent.js

@ -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;

2
lib/_http_client.js

@ -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');

2
lib/_http_common.js

@ -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;

2
lib/_http_incoming.js

@ -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');

2
lib/_http_outgoing.js

@ -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');

2
lib/_http_server.js

@ -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;

2
lib/_linklist.js

@ -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;

2
lib/_stream_duplex.js

@ -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');

2
lib/_stream_passthrough.js

@ -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');

2
lib/_stream_readable.js

@ -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;

2
lib/_stream_transform.js

@ -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');

2
lib/_stream_writable.js

@ -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;

2
lib/_tls_common.js

@ -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');

6
lib/_tls_legacy.js

@ -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');
@ -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);

2
lib/_tls_wrap.js

@ -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');

2
lib/assert.js

@ -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;

2
lib/buffer.js

@ -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');

2
lib/child_process.js

@ -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');

4
lib/cluster.js

@ -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');
@ -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)) {

6
lib/console.js

@ -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) {
@ -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);
};

2
lib/constants.js

@ -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
lib/crypto.js

@ -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 {
@ -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);

2
lib/dgram.js

@ -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');

2
lib/dns.js

@ -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');

2
lib/domain.js

@ -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;

2
lib/events.js

@ -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');

2
lib/freelist.js

@ -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;

2
lib/fs.js

@ -25,6 +25,8 @@
//
// var mode = 438; /* mode=0666 */
'use strict';
var util = require('util');
var pathModule = require('path');

2
lib/http.js

@ -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;

2
lib/https.js

@ -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');

2
lib/module.js

@ -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;

3
lib/net.js

@ -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');
@ -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);

2
lib/os.js

@ -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';

1
lib/path.js

@ -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');

2
lib/querystring.js

@ -21,6 +21,8 @@
// Query String Utilities
'use strict';
var QueryString = exports;
var util = require('util');

2
lib/readline.js

@ -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');

2
lib/repl.js

@ -40,6 +40,8 @@
* repl.start("node > ").context.foo = "stdin is fun";
*/
'use strict';
var util = require('util');
var inherits = require('util').inherits;
var Stream = require('stream');

2
lib/smalloc.js

@ -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 smalloc = process.binding('smalloc');
var kMaxLength = smalloc.kMaxLength;
var util = require('util');

2
lib/stream.js

@ -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 = Stream;
var EE = require('events').EventEmitter;

2
lib/string_decoder.js

@ -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 assertEncoding(encoding) {
if (encoding && !Buffer.isEncoding(encoding)) {
throw new Error('Unknown encoding: ' + encoding);

2
lib/sys.js

@ -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';
// the sys module was renamed to 'util'.
// this shim remains to keep old programs working.
module.exports = require('util');

2
lib/timers.js

@ -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 Timer = process.binding('timer_wrap').Timer;
var L = require('_linklist');
var assert = require('assert').ok;

2
lib/tls.js

@ -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 url = require('url');
var util = require('util');

2
lib/tracing.js

@ -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');
var v8binding, process;

2
lib/tty.js

@ -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 inherits = require('util').inherits;
var net = require('net');
var TTY = process.binding('tty_wrap').TTY;

2
lib/url.js

@ -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 punycode = require('punycode');
var util = require('util');

2
lib/util.js

@ -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 formatRegExp = /%[sdj%]/g;
exports.format = function(f) {
if (!isString(f)) {

2
lib/vm.js

@ -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('contextify');
var Script = binding.ContextifyScript;
var util = require('util');

2
lib/zlib.js

@ -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 Transform = require('_stream_transform');
var binding = process.binding('zlib');

3
src/node.js

@ -24,6 +24,9 @@
// This file is invoked by node::Load in src/node.cc, and responsible for
// bootstrapping the node.js core. Special caution is given to the performance
// of the startup process, so many dependencies are invoked lazily.
'use strict';
(function(process) {
this.global = this;

Loading…
Cancel
Save