diff --git a/lib/net.js b/lib/net.js index 0cd5bb18ef..1f4910192f 100644 --- a/lib/net.js +++ b/lib/net.js @@ -853,7 +853,7 @@ Server.prototype._rejectPending = function() { // Accept and close the waiting clients one at a time. // Single threaded programming ftw. while (true) { - peerInfo = accept(this.fd); + var peerInfo = accept(this.fd); if (!peerInfo) return; close(peerInfo.fd); diff --git a/test/fixtures/print-chars-from-buffer.js b/test/fixtures/print-chars-from-buffer.js index 9f15b15e41..e742e6e36f 100644 --- a/test/fixtures/print-chars-from-buffer.js +++ b/test/fixtures/print-chars-from-buffer.js @@ -1,10 +1,9 @@ var common = require('../common'); var assert = require('assert');; -Buffer = require('buffer').Buffer; var n = parseInt(process.argv[2]); -b = new Buffer(n); +var b = new Buffer(n); for (var i = 0; i < n; i++) { b[i] = 100; } diff --git a/test/message/2100bytes.js b/test/message/2100bytes.js index f4da1a3e57..59fe3c1523 100644 --- a/test/message/2100bytes.js +++ b/test/message/2100bytes.js @@ -1,7 +1,7 @@ -common = require('../common'); -assert = common.assert; +var common = require('../common'); +var assert = require('assert'); +var util = require('util'); -util = require('util'); console.log([ '_______________________________________________50', '______________________________________________100', diff --git a/test/message/hello_world.js b/test/message/hello_world.js index 6f60c4cc0e..996e08d51a 100644 --- a/test/message/hello_world.js +++ b/test/message/hello_world.js @@ -1,4 +1,4 @@ -common = require('../common'); -assert = common.assert; +var common = require('../common'); +var assert = require('assert'); console.log('hello world'); diff --git a/test/pummel/test-keep-alive.js b/test/pummel/test-keep-alive.js index 178fc8736c..d39ddc24c8 100644 --- a/test/pummel/test-keep-alive.js +++ b/test/pummel/test-keep-alive.js @@ -1,11 +1,11 @@ // This test requires the program 'ab' var common = require('../common'); var assert = require('assert');; -http = require('http'); -exec = require('child_process').exec; +var http = require('http'); +var exec = require('child_process').exec; -body = 'hello world\n'; -server = http.createServer(function(req, res) { +var body = 'hello world\n'; +var server = http.createServer(function(req, res) { res.writeHead(200, { 'Content-Length': body.length, 'Content-Type': 'text/plain' diff --git a/test/pummel/test-net-many-clients.js b/test/pummel/test-net-many-clients.js index ab42762f7f..b59808e2e8 100644 --- a/test/pummel/test-net-many-clients.js +++ b/test/pummel/test-net-many-clients.js @@ -1,6 +1,7 @@ var common = require('../common'); var assert = require('assert');; -net = require('net'); +var net = require('net'); + // settings var bytes = 1024 * 40; var concurrency = 100; diff --git a/test/pummel/test-net-pause.js b/test/pummel/test-net-pause.js index 057da9f85a..de101d0ba2 100644 --- a/test/pummel/test-net-pause.js +++ b/test/pummel/test-net-pause.js @@ -1,10 +1,11 @@ var common = require('../common'); var assert = common.assert; var net = require('net'); + var N = 200; var recv = '', chars_recved = 0; -server = net.createServer(function(connection) { +var server = net.createServer(function(connection) { function write(j) { if (j >= N) { connection.end(); @@ -17,8 +18,9 @@ server = net.createServer(function(connection) { } write(0); }); + server.on('listening', function() { - client = net.createConnection(common.PORT); + var client = net.createConnection(common.PORT); client.setEncoding('ascii'); client.addListener('data', function(d) { common.print(d); diff --git a/test/pummel/test-net-pingpong-delay.js b/test/pummel/test-net-pingpong-delay.js index cac8418385..a30a6942e4 100644 --- a/test/pummel/test-net-pingpong-delay.js +++ b/test/pummel/test-net-pingpong-delay.js @@ -1,6 +1,6 @@ var common = require('../common'); var assert = require('assert');; -net = require('net'); +var net = require('net'); var tests_run = 0; diff --git a/test/pummel/test-net-pingpong.js b/test/pummel/test-net-pingpong.js index d6b828ab67..f2d8903d26 100644 --- a/test/pummel/test-net-pingpong.js +++ b/test/pummel/test-net-pingpong.js @@ -1,6 +1,6 @@ var common = require('../common'); var assert = require('assert');; -net = require('net'); +var net = require('net'); var tests_run = 0; diff --git a/test/pummel/test-net-throttle.js b/test/pummel/test-net-throttle.js index 11799cb7ac..02005d0e9a 100644 --- a/test/pummel/test-net-throttle.js +++ b/test/pummel/test-net-throttle.js @@ -1,11 +1,10 @@ var common = require('../common'); var assert = require('assert');; -net = require('net'); -N = 160 * 1024; // 30kb +var net = require('net'); - -chars_recved = 0; -npauses = 0; +var N = 160 * 1024; // 30kb +var chars_recved = 0; +var npauses = 0; console.log('build big string'); var body = ''; @@ -15,15 +14,16 @@ for (var i = 0; i < N; i++) { console.log('start server on port ' + common.PORT); -server = net.createServer(function(connection) { +var server = net.createServer(function(connection) { connection.addListener('connect', function() { assert.equal(false, connection.write(body)); connection.end(); }); }); + server.listen(common.PORT, function() { var paused = false; - client = net.createConnection(common.PORT); + var client = net.createConnection(common.PORT); client.setEncoding('ascii'); client.addListener('data', function(d) { chars_recved += d.length; @@ -33,7 +33,7 @@ server.listen(common.PORT, function() { npauses += 1; paused = true; console.log('pause'); - x = chars_recved; + var x = chars_recved; setTimeout(function() { assert.equal(chars_recved, x); client.resume(); diff --git a/test/pummel/test-net-timeout.js b/test/pummel/test-net-timeout.js index 0b58256b3f..68650f178e 100644 --- a/test/pummel/test-net-timeout.js +++ b/test/pummel/test-net-timeout.js @@ -1,10 +1,11 @@ var common = require('../common'); var assert = require('assert');; -net = require('net'); -exchanges = 0; -starttime = null; -timeouttime = null; -timeout = 1000; +var net = require('net'); + +var exchanges = 0; +var starttime = null; +var timeouttime = null; +var timeout = 1000; var echo_server = net.createServer(function(socket) { socket.setTimeout(timeout); diff --git a/test/pummel/test-timers.js b/test/pummel/test-timers.js index 0afe5a609d..3cc8777e2a 100644 --- a/test/pummel/test-timers.js +++ b/test/pummel/test-timers.js @@ -1,8 +1,6 @@ var common = require('../common'); var assert = require('assert'); -assert = require('assert'); - var WINDOW = 200; // why is does this need to be so big? var interval_count = 0; @@ -79,8 +77,8 @@ setInterval(function(param1, param2){ }, 1000, 'param1', 'param2'); // setInterval(cb, 0) should be called multiple times. -count4 = 0; -interval4 = setInterval(function() { +var count4 = 0; +var interval4 = setInterval(function() { if (++count4 > 10) clearInterval(interval4); }, 0); @@ -92,12 +90,12 @@ function t () { expectedTimeouts--; } -w = setTimeout(t, 200), -x = setTimeout(t, 200), -y = setTimeout(t, 200); +var w = setTimeout(t, 200); +var x = setTimeout(t, 200); +var y = setTimeout(t, 200); -clearTimeout(y), -z = setTimeout(t, 200); +clearTimeout(y); +var z = setTimeout(t, 200); clearTimeout(y); diff --git a/test/simple/test-http-exceptions.js b/test/simple/test-http-exceptions.js index 48e95cd991..4e711d7ff8 100644 --- a/test/simple/test-http-exceptions.js +++ b/test/simple/test-http-exceptions.js @@ -2,7 +2,7 @@ var common = require('../common'); var assert = require('assert');; var http = require('http'); -server = http.createServer(function (req, res) { +var server = http.createServer(function (req, res) { intentionally_not_defined(); res.writeHead(200, {"Content-Type": "text/plain"}); res.write("Thank you, come again."); @@ -17,7 +17,7 @@ server.listen(common.PORT, function () { } }); -exception_count = 0; +var exception_count = 0; process.addListener("uncaughtException", function (err) { console.log("Caught an exception: " + err); diff --git a/test/simple/test-http-expect-continue.js b/test/simple/test-http-expect-continue.js index 6ccaadc241..5b64cee8de 100644 --- a/test/simple/test-http-expect-continue.js +++ b/test/simple/test-http-expect-continue.js @@ -1,5 +1,5 @@ var common = require("../common"); -var assert = common.assert; +var assert = require('assert'); var http = require("http"); var outstanding_reqs = 0; @@ -31,12 +31,12 @@ server.listen(common.PORT); server.addListener("listening", function() { var client = http.createClient(common.PORT); - req = client.request("POST", "/world", { + var req = client.request("POST", "/world", { "Expect": "100-continue", }); common.debug("Client sending request..."); outstanding_reqs++; - body = ""; + var body = ""; req.addListener('continue', function () { common.debug("Client got 100 Continue..."); got_continue = true; diff --git a/test/simple/test-http-keep-alive-close-on-header.js b/test/simple/test-http-keep-alive-close-on-header.js index 7d55469031..03538b5047 100644 --- a/test/simple/test-http-keep-alive-close-on-header.js +++ b/test/simple/test-http-keep-alive-close-on-header.js @@ -1,20 +1,18 @@ var common = require('../common'); var assert = require('assert'); - -assert = require("assert"); var http = require('http'); var util = require('util'); -body = "hello world\n"; -headers = {'connection':'keep-alive'} +var body = "hello world\n"; +var headers = {'connection':'keep-alive'} -server = http.createServer(function (req, res) { +var server = http.createServer(function (req, res) { res.writeHead(200, {"Content-Length": body.length, "Connection":"close"}); res.write(body); res.end(); }); -connectCount = 0; +var connectCount = 0; server.listen(common.PORT, function () { var client = http.createClient(common.PORT); diff --git a/test/simple/test-http-keep-alive.js b/test/simple/test-http-keep-alive.js index 032f1cdba7..b44f4d41b9 100644 --- a/test/simple/test-http-keep-alive.js +++ b/test/simple/test-http-keep-alive.js @@ -1,20 +1,18 @@ var common = require('../common'); var assert = require('assert'); - -assert = require("assert"); var http = require('http'); var util = require('util'); -body = "hello world\n"; -headers = {'connection':'keep-alive'} +var body = "hello world\n"; +var headers = {'connection':'keep-alive'} -server = http.createServer(function (req, res) { +var server = http.createServer(function (req, res) { res.writeHead(200, {"Content-Length": body.length}); res.write(body); res.end(); }); -connectCount = 0; +var connectCount = 0; server.listen(common.PORT, function () { var client = http.createClient(common.PORT); diff --git a/test/simple/test-http-server.js b/test/simple/test-http-server.js index 2919c9630c..1a1525b4fc 100644 --- a/test/simple/test-http-server.js +++ b/test/simple/test-http-server.js @@ -2,8 +2,8 @@ var common = require('../common'); var assert = require('assert'); var net = require('net'); var http = require('http'); -url = require("url"); -qs = require("querystring"); +var url = require("url"); +var qs = require("querystring"); var request_number = 0; var requests_sent = 0; diff --git a/test/simple/test-http-upgrade-server2.js b/test/simple/test-http-upgrade-server2.js index a5129a4800..d80768ca37 100644 --- a/test/simple/test-http-upgrade-server2.js +++ b/test/simple/test-http-upgrade-server2.js @@ -1,10 +1,9 @@ var common = require('../common'); var assert = require('assert'); - var http = require('http'); var net = require('net'); -server = http.createServer(function (req, res) { +var server = http.createServer(function (req, res) { common.error('got req'); throw new Error("This shouldn't happen."); }); @@ -16,7 +15,7 @@ server.addListener('upgrade', function (req, socket, upgradeHead) { throw new Error('upgrade error'); }); -gotError = false; +var gotError = false; process.addListener('uncaughtException', function (e) { common.error('got "clientError" event'); diff --git a/test/simple/test-http-write-empty-string.js b/test/simple/test-http-write-empty-string.js index 1e4a1698db..5378d81777 100644 --- a/test/simple/test-http-write-empty-string.js +++ b/test/simple/test-http-write-empty-string.js @@ -2,9 +2,8 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); -assert = require('assert'); -server = http.createServer(function (request, response) { +var server = http.createServer(function (request, response) { console.log('responding to ' + request.url); response.writeHead(200, {'Content-Type': 'text/plain'}); diff --git a/test/simple/test-http.js b/test/simple/test-http.js index a60398a017..824f722e1e 100644 --- a/test/simple/test-http.js +++ b/test/simple/test-http.js @@ -1,7 +1,7 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); -url = require("url"); +var url = require("url"); function p (x) { common.error(common.inspect(x)); diff --git a/test/simple/test-listen-fd.js b/test/simple/test-listen-fd.js index 3323e2db26..d7bc1b7829 100644 --- a/test/simple/test-listen-fd.js +++ b/test/simple/test-listen-fd.js @@ -4,7 +4,7 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); -netBinding = process.binding('net'); +var netBinding = process.binding('net'); // Create an server and set it listening on a socket bound to common.PORT var gotRequest = false; diff --git a/test/simple/test-net-binary.js b/test/simple/test-net-binary.js index 476ab4ef33..7b5abf5fd1 100644 --- a/test/simple/test-net-binary.js +++ b/test/simple/test-net-binary.js @@ -2,10 +2,10 @@ var common = require('../common'); var assert = require('assert'); var net = require('net'); -binaryString = ""; +var binaryString = ""; for (var i = 255; i >= 0; i--) { var s = "'\\" + i.toString(8) + "'"; - S = eval(s); + var S = eval(s); common.error( s + " " + JSON.stringify(S) diff --git a/test/simple/test-net-server-max-connections.js b/test/simple/test-net-server-max-connections.js index 301c12a91a..2b1bc295f5 100644 --- a/test/simple/test-net-server-max-connections.js +++ b/test/simple/test-net-server-max-connections.js @@ -8,12 +8,12 @@ var net = require('net'); // TODO: test that the server can accept more connections after it reaches // its maximum and some are closed. -N = 200; -count = 0; -closes = 0; -waits = []; +var N = 200; +var count = 0; +var closes = 0; +var waits = []; -server = net.createServer(function (connection) { +var server = net.createServer(function (connection) { console.error("connect %d", count++); connection.write("hello"); waits.push(function () { connection.end(); }); diff --git a/test/simple/test-pipe-head.js b/test/simple/test-pipe-head.js index 51d7659983..3a79e9bb0f 100644 --- a/test/simple/test-pipe-head.js +++ b/test/simple/test-pipe-head.js @@ -1,19 +1,18 @@ var common = require('../common'); var assert = require('assert'); +var exec = require('child_process').exec; +var join = require('path').join; -exec = require('child_process').exec; -join = require('path').join; +var nodePath = process.argv[0]; +var script = join(common.fixturesDir, 'print-10-lines.js'); -nodePath = process.argv[0]; -script = join(common.fixturesDir, 'print-10-lines.js'); +var cmd = nodePath + ' ' + script + ' | head -2'; -cmd = nodePath + ' ' + script + ' | head -2'; - -finished = false; +var finished = false; exec(cmd, function (err, stdout, stderr) { if (err) throw err; - lines = stdout.split('\n'); + var lines = stdout.split('\n'); assert.equal(3, lines.length); finished = true; }); diff --git a/test/simple/test-pump-file2tcp-noexist.js b/test/simple/test-pump-file2tcp-noexist.js index 1cf2c6ab55..b2f608e4a9 100644 --- a/test/simple/test-pump-file2tcp-noexist.js +++ b/test/simple/test-pump-file2tcp-noexist.js @@ -4,12 +4,12 @@ var net = require('net'); var fs = require('fs'); var util = require('util'); var path = require('path'); -fn = path.join(common.fixturesDir, 'does_not_exist.txt'); +var fn = path.join(common.fixturesDir, 'does_not_exist.txt'); var got_error = false; var conn_closed = false; -server = net.createServer(function (stream) { +var server = net.createServer(function (stream) { common.error('pump!'); util.pump(fs.createReadStream(fn), stream, function (err) { common.error("util.pump's callback fired"); @@ -25,7 +25,7 @@ server = net.createServer(function (stream) { }); server.listen(common.PORT, function () { - conn = net.createConnection(common.PORT); + var conn = net.createConnection(common.PORT); conn.setEncoding('utf8'); conn.addListener("data", function (chunk) { common.error('recv data! nchars = ' + chunk.length); @@ -43,7 +43,6 @@ server.listen(common.PORT, function () { }); var buffer = ''; -count = 0; process.addListener('exit', function () { assert.equal(true, got_error); diff --git a/test/simple/test-pump-file2tcp.js b/test/simple/test-pump-file2tcp.js index 07572ae348..9622b861cc 100644 --- a/test/simple/test-pump-file2tcp.js +++ b/test/simple/test-pump-file2tcp.js @@ -4,11 +4,11 @@ var net = require('net'); var fs = require('fs'); var util = require('util'); var path = require('path'); -fn = path.join(common.fixturesDir, 'elipses.txt'); +var fn = path.join(common.fixturesDir, 'elipses.txt'); -expected = fs.readFileSync(fn, 'utf8'); +var expected = fs.readFileSync(fn, 'utf8'); -server = net.createServer(function (stream) { +var server = net.createServer(function (stream) { common.error('pump!'); util.pump(fs.createReadStream(fn), stream, function () { common.error('server stream close'); @@ -18,7 +18,7 @@ server = net.createServer(function (stream) { }); server.listen(common.PORT, function () { - conn = net.createConnection(common.PORT); + var conn = net.createConnection(common.PORT); conn.setEncoding('utf8'); conn.addListener("data", function (chunk) { common.error('recv data! nchars = ' + chunk.length); @@ -34,7 +34,7 @@ server.listen(common.PORT, function () { }); var buffer = ''; -count = 0; +var count = 0; server.addListener('listening', function () { }); diff --git a/test/simple/test-signal-handler.js b/test/simple/test-signal-handler.js index c3fa6b6868..3c450524d0 100644 --- a/test/simple/test-signal-handler.js +++ b/test/simple/test-signal-handler.js @@ -19,7 +19,7 @@ process.addListener('SIGUSR1', function () { }, 5); }); -i = 0; +var i = 0; setInterval(function () { console.log("running process..." + ++i); diff --git a/test/simple/test-stdin-from-file.js b/test/simple/test-stdin-from-file.js index 8fa0c248a8..ae97290bc7 100644 --- a/test/simple/test-stdin-from-file.js +++ b/test/simple/test-stdin-from-file.js @@ -1,17 +1,16 @@ var common = require('../common'); var assert = require('assert'); - -join = require('path').join; -childProccess = require('child_process'); +var join = require('path').join; +var childProccess = require('child_process'); var fs = require('fs'); -stdoutScript = join(common.fixturesDir, 'echo.js'); -tmpFile = join(common.fixturesDir, 'stdin.txt'); +var stdoutScript = join(common.fixturesDir, 'echo.js'); +var tmpFile = join(common.fixturesDir, 'stdin.txt'); -cmd = process.argv[0] + ' ' + stdoutScript + ' < ' + tmpFile; +var cmd = process.argv[0] + ' ' + stdoutScript + ' < ' + tmpFile; -string = "abc\nümlaut.\nsomething else\n" - + "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n"; +var string = "abc\nümlaut.\nsomething else\n" + + "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n"; console.log(cmd + "\n\n"); diff --git a/test/simple/test-stdout-to-file.js b/test/simple/test-stdout-to-file.js index 4ba1c7c1da..d5f7deadb0 100644 --- a/test/simple/test-stdout-to-file.js +++ b/test/simple/test-stdout-to-file.js @@ -1,11 +1,12 @@ var common = require('../common'); var assert = require('assert'); var path = require('path'); -childProccess = require('child_process'); +var childProccess = require('child_process'); var fs = require('fs'); -scriptString = path.join(common.fixturesDir, 'print-chars.js'); -scriptBuffer = path.join(common.fixturesDir, 'print-chars-from-buffer.js'); -tmpFile = path.join(common.fixturesDir, 'stdout.txt'); + +var scriptString = path.join(common.fixturesDir, 'print-chars.js'); +var scriptBuffer = path.join(common.fixturesDir, 'print-chars-from-buffer.js'); +var tmpFile = path.join(common.fixturesDir, 'stdout.txt'); function test (size, useBuffer, cb) { var cmd = process.argv[0] @@ -39,7 +40,7 @@ function test (size, useBuffer, cb) { }); } -finished = false; +var finished = false; test(1024*1024, false, function () { console.log("Done printing with string"); test(1024*1024, true, function () { diff --git a/test/simple/test-string-decoder.js b/test/simple/test-string-decoder.js index 3fb0811594..f49d589167 100644 --- a/test/simple/test-string-decoder.js +++ b/test/simple/test-string-decoder.js @@ -1,13 +1,11 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); +var StringDecoder = require('string_decoder').StringDecoder; +var decoder = new StringDecoder('utf8'); -Buffer = require('buffer').Buffer; -StringDecoder = require('string_decoder').StringDecoder; -decoder = new StringDecoder('utf8'); - -buffer = new Buffer('$'); +var buffer = new Buffer('$'); assert.deepEqual('$', decoder.write(buffer)); buffer = new Buffer('¢'); @@ -20,7 +18,7 @@ assert.deepEqual('', decoder.write(buffer.slice(1, 2))); assert.deepEqual('€', decoder.write(buffer.slice(2, 3))); buffer = new Buffer([0xF0, 0xA4, 0xAD, 0xA2]); -s = ''; +var s = ''; s += decoder.write(buffer.slice(0, 1)); s += decoder.write(buffer.slice(1, 2)); s += decoder.write(buffer.slice(2, 3)); @@ -34,10 +32,10 @@ assert.ok(s.length > 0); // U+12E4 -> E1 8B A4 // U+0030 -> 30 // U+3045 -> E3 81 85 -expected = '\u02e4\u0064\u12e4\u0030\u3045'; -buffer = new Buffer([0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, - 0x30, 0xE3, 0x81, 0x85]); -charLengths = [0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5]; +var expected = '\u02e4\u0064\u12e4\u0030\u3045'; +var buffer = new Buffer([0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, + 0x30, 0xE3, 0x81, 0x85]); +var charLengths = [0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5]; // Split the buffer into 3 segments // |----|------|-------|