Browse Source

Lint

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
5a05992155
  1. 38
      lib/_debugger.js
  2. 28
      lib/fs.js
  3. 1
      lib/os.js
  4. 78
      lib/path.js
  5. 2
      lib/readline.js
  6. 4
      lib/repl.js
  7. 8
      lib/tls.js
  8. 6
      src/node.js

38
lib/_debugger.js

@ -86,7 +86,7 @@ Protocol.prototype.execute = function(d) {
break; break;
default: default:
throw new Error("Unknown state"); throw new Error('Unknown state');
break; break;
} }
}; };
@ -121,13 +121,13 @@ function Client() {
}); });
protocol.onResponse = this._onResponse.bind(this); protocol.onResponse = this._onResponse.bind(this);
}; }
inherits(Client, net.Stream); inherits(Client, net.Stream);
exports.Client = Client; exports.Client = Client;
Client.prototype._addHandle = function(desc) { Client.prototype._addHandle = function(desc) {
if (typeof desc != 'object' || !desc.handle) throw new Error("bad type"); if (typeof desc != 'object' || !desc.handle) throw new Error('bad type');
this.handles[desc.handle] = desc; this.handles[desc.handle] = desc;
if (desc.type == 'script') { if (desc.type == 'script') {
@ -292,8 +292,8 @@ Client.prototype.step = function(action, count, cb) {
var helpMessage = "Commands: run, kill, print, step, next, " + var helpMessage = 'Commands: run, kill, print, step, next, ' +
"continue, scripts, backtrace, version, quit"; 'continue, scripts, backtrace, version, quit';
function SourceUnderline(sourceText, position) { function SourceUnderline(sourceText, position) {
if (!sourceText) return; if (!sourceText) return;
@ -425,7 +425,7 @@ Interface.prototype.pause = function() {
Interface.prototype.resume = function() { Interface.prototype.resume = function() {
if (!this.paused) return false if (!this.paused) return false;
this.paused = false; this.paused = false;
this.stdin.resume(); this.stdin.resume();
this.term.resume(); this.term.resume();
@ -486,7 +486,7 @@ Interface.prototype.handleCommand = function(cmd) {
self._lastCommand = null; self._lastCommand = null;
term.prompt(); term.prompt();
} else { } else {
console.log("restarting..."); console.log('restarting...');
self.killChild(); self.killChild();
// XXX need to wait a little bit for the restart to work? // XXX need to wait a little bit for the restart to work?
setTimeout(function() { setTimeout(function() {
@ -605,7 +605,7 @@ Interface.prototype.handleCommand = function(cmd) {
} }
var i = cmd.indexOf(' '); var i = cmd.indexOf(' ');
if (i < 0) { if (i < 0) {
console.log("print [expression]"); console.log('print [expression]');
term.prompt(); term.prompt();
} else { } else {
cmd = cmd.slice(i); cmd = cmd.slice(i);
@ -639,7 +639,7 @@ Interface.prototype.yesNoQuestion = function(prompt, cb) {
} else if (/^n(o)?$/i.test(answer)) { } else if (/^n(o)?$/i.test(answer)) {
cb(false); cb(false);
} else { } else {
console.log("Please answer y or n."); console.log('Please answer y or n.');
self.restartQuestion(cb); self.restartQuestion(cb);
} }
}); });
@ -647,18 +647,18 @@ Interface.prototype.yesNoQuestion = function(prompt, cb) {
Interface.prototype.restartQuestion = function(cb) { Interface.prototype.restartQuestion = function(cb) {
this.yesNoQuestion("The program being debugged has been started already.\n" + this.yesNoQuestion('The program being debugged has been started already.\n' +
"Start it from the beginning? (y or n) ", cb); 'Start it from the beginning? (y or n) ', cb);
}; };
Interface.prototype.killQuestion = function(cb) { Interface.prototype.killQuestion = function(cb) {
this.yesNoQuestion("Kill the program being debugged? (y or n) ", cb); this.yesNoQuestion('Kill the program being debugged? (y or n) ', cb);
}; };
Interface.prototype.quitQuestion = function(cb) { Interface.prototype.quitQuestion = function(cb) {
this.yesNoQuestion("A debugging session is active. Quit anyway? (y or n) ", this.yesNoQuestion('A debugging session is active. Quit anyway? (y or n) ',
cb); cb);
}; };
@ -689,12 +689,12 @@ Interface.prototype.trySpawn = function(cb) {
this.pause(); this.pause();
setTimeout(function() { setTimeout(function() {
process.stdout.write("connecting..."); process.stdout.write('connecting...');
var client = self.client = new Client(); var client = self.client = new Client();
client.connect(exports.port); client.connect(exports.port);
client.once('ready', function() { client.once('ready', function() {
process.stdout.write("ok\r\n"); process.stdout.write('ok\r\n');
// since we did debug-brk, we're hitting a break point immediately // since we did debug-brk, we're hitting a break point immediately
// continue before anything else. // continue before anything else.
@ -704,14 +704,14 @@ Interface.prototype.trySpawn = function(cb) {
}); });
client.on('close', function() { client.on('close', function() {
console.log("\nprogram terminated"); console.log('\nprogram terminated');
self.client = null; self.client = null;
self.killChild(); self.killChild();
if (!self.quitting) self.term.prompt(); if (!self.quitting) self.term.prompt();
}); });
client.on('unhandledResponse', function(res) { client.on('unhandledResponse', function(res) {
console.log("\r\nunhandled res:"); console.log('\r\nunhandled res:');
console.log(res); console.log(res);
self.term.prompt(); self.term.prompt();
}); });
@ -736,7 +736,9 @@ Interface.prototype.printScripts = function(displayNatives) {
for (var id in client.scripts) { for (var id in client.scripts) {
var script = client.scripts[id]; var script = client.scripts[id];
if (typeof script == 'object' && script.name) { if (typeof script == 'object' && script.name) {
if (displayNatives || script.name == client.currentScript || !script.isNative) { if (displayNatives ||
script.name == client.currentScript ||
!script.isNative) {
text += script.name == client.currentScript ? '* ' : ' '; text += script.name == client.currentScript ? '* ' : ' ';
var n = require('path').split(script.name); var n = require('path').split(script.name);
text += n[n.length - 1] + '\n'; text += n[n.length - 1] + '\n';

28
lib/fs.js

@ -529,10 +529,14 @@ if (isWindows) {
var seenLinks = {}, var seenLinks = {},
knownHard = {}; knownHard = {};
var pos = 0, // current character position in p // current character position in p
current = "", // the partial path so far, including a trailing slash if any var pos = 0;
base = "", // the partial path without a trailing slash // the partial path so far, including a trailing slash if any
previous = ""; // the partial path scanned in the previous round, with slash var current = '';
// the partial path without a trailing slash
var base = '';
// the partial path scanned in the previous round, with slash
var previous = '';
// walk down the path, swapping out linked pathparts for their real // walk down the path, swapping out linked pathparts for their real
// values // values
@ -566,7 +570,7 @@ if (isWindows) {
// resolve the link, then start over // resolve the link, then start over
p = path.resolve(previous, seenLinks[id], p.slice(pos)); p = path.resolve(previous, seenLinks[id], p.slice(pos));
pos = 0; pos = 0;
previous = base = current = ""; previous = base = current = '';
} }
return p; return p;
@ -581,10 +585,14 @@ if (isWindows) {
var seenLinks = {}, var seenLinks = {},
knownHard = {}; knownHard = {};
var pos = 0, // current character position in p // current character position in p
current = "", // the partial path so far, including a trailing slash if any var pos = 0;
base = "", // the partial path without a trailing slash // the partial path so far, including a trailing slash if any
previous = ""; // the partial path scanned in the previous round, with slash var current = '';
// the partial path without a trailing slash
var base = '';
// the partial path scanned in the previous round, with slash
var previous = '';
// walk down the path, swapping out linked pathparts for their real // walk down the path, swapping out linked pathparts for their real
// values // values
@ -641,7 +649,7 @@ if (isWindows) {
// resolve the link, then start over // resolve the link, then start over
p = path.resolve(previous, target, p.slice(pos)); p = path.resolve(previous, target, p.slice(pos));
pos = 0; pos = 0;
previous = base = current = ""; previous = base = current = '';
return process.nextTick(LOOP); return process.nextTick(LOOP);
} }

1
lib/os.js

@ -9,3 +9,4 @@ exports.cpus = binding.getCPUs;
exports.type = binding.getOSType; exports.type = binding.getOSType;
exports.release = binding.getOSRelease; exports.release = binding.getOSRelease;
exports.isWindows = binding.isWindows; exports.isWindows = binding.isWindows;

78
lib/path.js

@ -2,9 +2,10 @@
var isWindows = process.platform === 'win32'; var isWindows = process.platform === 'win32';
// resolves . and .. elements in a path array with directory names // resolves . and .. elements in a path array with directory names there
// there must be no slashes, empty elements, or device names (c:\) in the array // must be no slashes, empty elements, or device names (c:\) in the array
// (so also no leading and trailing slashes - it does not distinguish relative and absolute paths) // (so also no leading and trailing slashes - it does not distinguish
// relative and absolute paths)
function normalizeArray(parts, allowAboveRoot) { function normalizeArray(parts, allowAboveRoot) {
// if the path tries to go above the root, `up` ends up > 0 // if the path tries to go above the root, `up` ends up > 0
var up = 0; var up = 0;
@ -38,18 +39,20 @@ if (isWindows) {
// windows version // windows version
var splitPathRe = /^(.+(?:[\\\/](?!$)|:)|[\\\/])?((?:.+?)?(\.[^.]*)?)$/; var splitPathRe = /^(.+(?:[\\\/](?!$)|:)|[\\\/])?((?:.+?)?(\.[^.]*)?)$/;
// Regex to split a windows path into three parts: [*, device, slash, tail] // Regex to split a windows path into three parts: [*, device, slash,
// windows-only // tail] windows-only
var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?([\\\/])?(.*?)$/; var splitDeviceRe =
/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?([\\\/])?(.*?)$/;
// path.resolve([from ...], to) // path.resolve([from ...], to)
// windows version // windows version
exports.resolve = function() { exports.resolve = function() {
// Prepend cwd to provided paths // Prepend cwd to provided paths
var paths = [process.cwd()].concat(Array.prototype.slice.call(arguments, 0)); var paths = [process.cwd()].concat(
Array.prototype.slice.call(arguments, 0));
var resolvedDevice = "", var resolvedDevice = '',
resolvedTail = "", resolvedTail = '',
resolvedAbsolute = false; resolvedAbsolute = false;
for (var i = paths.length; i >= 0; i--) { for (var i = paths.length; i >= 0; i--) {
@ -66,7 +69,9 @@ if (isWindows) {
isAbsolute = !!result[2] || isUnc, // UNC paths are always absolute isAbsolute = !!result[2] || isUnc, // UNC paths are always absolute
tail = result[3]; tail = result[3];
if (device && resolvedDevice && device.toLowerCase() !== resolvedDevice.toLowerCase()) { if (device &&
resolvedDevice &&
device.toLowerCase() !== resolvedDevice.toLowerCase()) {
// This path points to another device so it is not applicable // This path points to another device so it is not applicable
continue; continue;
} }
@ -92,7 +97,7 @@ if (isWindows) {
// Windows stores the current directories for 'other' drives // Windows stores the current directories for 'other' drives
// as hidden environment variables like =C:=c:\windows (literally) // as hidden environment variables like =C:=c:\windows (literally)
// var deviceCwd = os.getCwdForDrive(resolvedDevice); // var deviceCwd = os.getCwdForDrive(resolvedDevice);
var deviceCwd = ""; var deviceCwd = '';
// If there is no cwd set for the drive, it is at root // If there is no cwd set for the drive, it is at root
resolvedTail = deviceCwd + '\\' + resolvedTail; resolvedTail = deviceCwd + '\\' + resolvedTail;
@ -102,17 +107,23 @@ if (isWindows) {
// Replace slashes (in UNC share name) by backslashes // Replace slashes (in UNC share name) by backslashes
resolvedDevice = resolvedDevice.replace(/\//g, '\\'); resolvedDevice = resolvedDevice.replace(/\//g, '\\');
// At this point the path should be resolved to a full absolute path, but // At this point the path should be resolved to a full absolute path,
// handle relative paths to be safe (might happen when process.cwd() fails) // but handle relative paths to be safe (might happen when process.cwd()
// fails)
// Normalize the tail path // Normalize the tail path
resolvedTail = normalizeArray(resolvedTail.split(/[\\\/]+/).filter(function(p) {
return !!p;
}), !resolvedAbsolute).join('\\');
return (resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail) || '.'; function f(p) {
return !!p;
} }
resolvedTail = normalizeArray(resolvedTail.split(/[\\\/]+/).filter(f),
!resolvedAbsolute).join('\\');
return (resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail) ||
'.';
};
// windows version // windows version
exports.normalize = function(path) { exports.normalize = function(path) {
var result = splitDeviceRe.exec(path), var result = splitDeviceRe.exec(path),
@ -128,21 +139,23 @@ if (isWindows) {
}), !isAbsolute).join('\\'); }), !isAbsolute).join('\\');
if (!tail && !isAbsolute) { if (!tail && !isAbsolute) {
tail = '.' tail = '.';
} }
if (tail && trailingSlash) { if (tail && trailingSlash) {
tail += '\\' tail += '\\';
} }
return device + (isAbsolute ? '\\' : '') + tail; return device + (isAbsolute ? '\\' : '') + tail;
} };
// windows version // windows version
exports.join = function() { exports.join = function() {
var paths = Array.prototype.slice.call(arguments, 0).filter(function(p) { function f(p) {
return p && typeof p === 'string'; return p && typeof p === 'string';
}), }
joined = paths.join('\\');
var paths = Array.prototype.slice.call(arguments, 0).filter(f);
var joined = paths.join('\\');
// Make sure that the joined path doesn't start with two slashes // Make sure that the joined path doesn't start with two slashes
// - it will be mistaken for an unc path by normalize() - // - it will be mistaken for an unc path by normalize() -
@ -152,7 +165,7 @@ if (isWindows) {
} }
return exports.normalize(joined); return exports.normalize(joined);
} };
} else /* posix */ { } else /* posix */ {
@ -165,9 +178,10 @@ if (isWindows) {
// posix version // posix version
exports.resolve = function() { exports.resolve = function() {
// Prepend cwd to provided paths // Prepend cwd to provided paths
var paths = [process.cwd()].concat(Array.prototype.slice.call(arguments, 0)); var paths = [process.cwd()].concat(
Array.prototype.slice.call(arguments, 0));
var resolvedPath = "", var resolvedPath = '',
resolvedAbsolute = false; resolvedAbsolute = false;
for (var i = paths.length; i >= 0 && !resolvedAbsolute; i--) { for (var i = paths.length; i >= 0 && !resolvedAbsolute; i--) {
@ -189,7 +203,7 @@ if (isWindows) {
}), !resolvedAbsolute).join('/'); }), !resolvedAbsolute).join('/');
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
} };
// path.normalize(path) // path.normalize(path)
// posix version // posix version
@ -203,23 +217,23 @@ if (isWindows) {
}), !isAbsolute).join('/'); }), !isAbsolute).join('/');
if (!path && !isAbsolute) { if (!path && !isAbsolute) {
path = '.' path = '.';
} }
if (path && trailingSlash) { if (path && trailingSlash) {
path += '/'; path += '/';
} }
return (isAbsolute ? '/' : '') + path; return (isAbsolute ? '/' : '') + path;
} };
// posix version // posix version
exports.join = function() { exports.join = function() {
var paths = Array.prototype.slice.call(arguments, 0); var paths = Array.prototype.slice.call(arguments, 0);
return exports.normalize(paths.filter(function(p, index) { return exports.normalize(paths.filter(function(p, index) {
return p && typeof p === 'string' return p && typeof p === 'string';
}).join('/')); }).join('/'));
} };
} }
@ -227,7 +241,7 @@ exports.dirname = function(path) {
var dir = splitPathRe.exec(path)[1] || ''; var dir = splitPathRe.exec(path)[1] || '';
if (!dir) { if (!dir) {
// No dirname // No dirname
return '.' return '.';
} else if (dir.length === 1 || } else if (dir.length === 1 ||
(isWindows && dir.length <= 3 && dir.charAt(1) === ':')) { (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {
// It is just a slash or a drive letter with a slash // It is just a slash or a drive letter with a slash

2
lib/readline.js

@ -109,7 +109,7 @@ Interface.prototype._onLine = function(line) {
var cb = this._questionCallback; var cb = this._questionCallback;
this._questionCallback = null; this._questionCallback = null;
this.setPrompt(this._oldPrompt); this.setPrompt(this._oldPrompt);
cb(line) cb(line);
} else { } else {
this.emit('line', line); this.emit('line', line);
} }

4
lib/repl.js

@ -128,7 +128,9 @@ function REPLServer(prompt, stream) {
try { try {
// First we attempt to eval as expression with parens. // First we attempt to eval as expression with parens.
// This catches '{a : 1}' properly. // This catches '{a : 1}' properly.
ret = vm.runInContext('(' + self.bufferedCommand + ')', context, 'repl'); ret = vm.runInContext('(' + self.bufferedCommand + ')',
context,
'repl');
if (typeof ret !== 'function') success = true; if (typeof ret !== 'function') success = true;
} catch (e) { } catch (e) {
success = false; success = false;

8
lib/tls.js

@ -17,8 +17,7 @@ if (process.env.NODE_DEBUG && /tls/.test(process.env.NODE_DEBUG)) {
var Connection = null; var Connection = null;
try { try {
Connection = process.binding('crypto').Connection; Connection = process.binding('crypto').Connection;
} } catch (e) {
catch (e) {
throw new Error('node.js not compiled with openssl crypto support.'); throw new Error('node.js not compiled with openssl crypto support.');
} }
@ -82,8 +81,8 @@ CryptoStream.prototype.setTimeout = function(n) {
}; };
// EG '/C=US/ST=CA/L=SF/O=Joyent/OU=Node.js/CN=ca1/emailAddress=ry@clouds.org'
function parseCertString(s) { function parseCertString(s) {
// EG '/C=US/ST=CA/L=SF/O=Joyent/OU=Node.js/CN=ca1/emailAddress=ry@tinyclouds.org'
var out = {}; var out = {};
var parts = s.split('/'); var parts = s.split('/');
// Note: can always skip the first one. // Note: can always skip the first one.
@ -380,8 +379,7 @@ exports.createSecurePair = function(credentials,
/** /* Attempt to cycle OpenSSLs buffers in various directions.
* Attempt to cycle OpenSSLs buffers in various directions.
* *
* An SSL Connection can be viewed as four separate piplines, * An SSL Connection can be viewed as four separate piplines,
* interacting with one has no connection to the behavoir of * interacting with one has no connection to the behavoir of

6
src/node.js

@ -132,7 +132,11 @@
var path = requireNative('path'); var path = requireNative('path');
var modulePaths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')]; var modulePaths = [path.resolve(process.execPath,
'..',
'..',
'lib',
'node')];
if (process.env['HOME']) { if (process.env['HOME']) {
modulePaths.unshift(path.resolve(process.env['HOME'], '.node_libraries')); modulePaths.unshift(path.resolve(process.env['HOME'], '.node_libraries'));

Loading…
Cancel
Save