Browse Source

Fix global leaks

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
92789b16e5
  1. 2
      lib/net.js
  2. 3
      test/fixtures/print-chars-from-buffer.js
  3. 6
      test/message/2100bytes.js
  4. 4
      test/message/hello_world.js
  5. 8
      test/pummel/test-keep-alive.js
  6. 3
      test/pummel/test-net-many-clients.js
  7. 6
      test/pummel/test-net-pause.js
  8. 2
      test/pummel/test-net-pingpong-delay.js
  9. 2
      test/pummel/test-net-pingpong.js
  10. 16
      test/pummel/test-net-throttle.js
  11. 11
      test/pummel/test-net-timeout.js
  12. 16
      test/pummel/test-timers.js
  13. 4
      test/simple/test-http-exceptions.js
  14. 6
      test/simple/test-http-expect-continue.js
  15. 10
      test/simple/test-http-keep-alive-close-on-header.js
  16. 10
      test/simple/test-http-keep-alive.js
  17. 4
      test/simple/test-http-server.js
  18. 5
      test/simple/test-http-upgrade-server2.js
  19. 3
      test/simple/test-http-write-empty-string.js
  20. 2
      test/simple/test-http.js
  21. 2
      test/simple/test-listen-fd.js
  22. 4
      test/simple/test-net-binary.js
  23. 10
      test/simple/test-net-server-max-connections.js
  24. 15
      test/simple/test-pipe-head.js
  25. 7
      test/simple/test-pump-file2tcp-noexist.js
  26. 10
      test/simple/test-pump-file2tcp.js
  27. 2
      test/simple/test-signal-handler.js
  28. 15
      test/simple/test-stdin-from-file.js
  29. 11
      test/simple/test-stdout-to-file.js
  30. 18
      test/simple/test-string-decoder.js

2
lib/net.js

@ -853,7 +853,7 @@ Server.prototype._rejectPending = function() {
// Accept and close the waiting clients one at a time. // Accept and close the waiting clients one at a time.
// Single threaded programming ftw. // Single threaded programming ftw.
while (true) { while (true) {
peerInfo = accept(this.fd); var peerInfo = accept(this.fd);
if (!peerInfo) return; if (!peerInfo) return;
close(peerInfo.fd); close(peerInfo.fd);

3
test/fixtures/print-chars-from-buffer.js

@ -1,10 +1,9 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert');; var assert = require('assert');;
Buffer = require('buffer').Buffer;
var n = parseInt(process.argv[2]); var n = parseInt(process.argv[2]);
b = new Buffer(n); var b = new Buffer(n);
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
b[i] = 100; b[i] = 100;
} }

6
test/message/2100bytes.js

@ -1,7 +1,7 @@
common = require('../common'); var common = require('../common');
assert = common.assert; var assert = require('assert');
var util = require('util');
util = require('util');
console.log([ console.log([
'_______________________________________________50', '_______________________________________________50',
'______________________________________________100', '______________________________________________100',

4
test/message/hello_world.js

@ -1,4 +1,4 @@
common = require('../common'); var common = require('../common');
assert = common.assert; var assert = require('assert');
console.log('hello world'); console.log('hello world');

8
test/pummel/test-keep-alive.js

@ -1,11 +1,11 @@
// This test requires the program 'ab' // This test requires the program 'ab'
var common = require('../common'); var common = require('../common');
var assert = require('assert');; var assert = require('assert');;
http = require('http'); var http = require('http');
exec = require('child_process').exec; var exec = require('child_process').exec;
body = 'hello world\n'; var body = 'hello world\n';
server = http.createServer(function(req, res) { var server = http.createServer(function(req, res) {
res.writeHead(200, { res.writeHead(200, {
'Content-Length': body.length, 'Content-Length': body.length,
'Content-Type': 'text/plain' 'Content-Type': 'text/plain'

3
test/pummel/test-net-many-clients.js

@ -1,6 +1,7 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert');; var assert = require('assert');;
net = require('net'); var net = require('net');
// settings // settings
var bytes = 1024 * 40; var bytes = 1024 * 40;
var concurrency = 100; var concurrency = 100;

6
test/pummel/test-net-pause.js

@ -1,10 +1,11 @@
var common = require('../common'); var common = require('../common');
var assert = common.assert; var assert = common.assert;
var net = require('net'); var net = require('net');
var N = 200; var N = 200;
var recv = '', chars_recved = 0; var recv = '', chars_recved = 0;
server = net.createServer(function(connection) { var server = net.createServer(function(connection) {
function write(j) { function write(j) {
if (j >= N) { if (j >= N) {
connection.end(); connection.end();
@ -17,8 +18,9 @@ server = net.createServer(function(connection) {
} }
write(0); write(0);
}); });
server.on('listening', function() { server.on('listening', function() {
client = net.createConnection(common.PORT); var client = net.createConnection(common.PORT);
client.setEncoding('ascii'); client.setEncoding('ascii');
client.addListener('data', function(d) { client.addListener('data', function(d) {
common.print(d); common.print(d);

2
test/pummel/test-net-pingpong-delay.js

@ -1,6 +1,6 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert');; var assert = require('assert');;
net = require('net'); var net = require('net');
var tests_run = 0; var tests_run = 0;

2
test/pummel/test-net-pingpong.js

@ -1,6 +1,6 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert');; var assert = require('assert');;
net = require('net'); var net = require('net');
var tests_run = 0; var tests_run = 0;

16
test/pummel/test-net-throttle.js

@ -1,11 +1,10 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert');; var assert = require('assert');;
net = require('net'); var net = require('net');
N = 160 * 1024; // 30kb
var N = 160 * 1024; // 30kb
chars_recved = 0; var chars_recved = 0;
npauses = 0; var npauses = 0;
console.log('build big string'); console.log('build big string');
var body = ''; var body = '';
@ -15,15 +14,16 @@ for (var i = 0; i < N; i++) {
console.log('start server on port ' + common.PORT); console.log('start server on port ' + common.PORT);
server = net.createServer(function(connection) { var server = net.createServer(function(connection) {
connection.addListener('connect', function() { connection.addListener('connect', function() {
assert.equal(false, connection.write(body)); assert.equal(false, connection.write(body));
connection.end(); connection.end();
}); });
}); });
server.listen(common.PORT, function() { server.listen(common.PORT, function() {
var paused = false; var paused = false;
client = net.createConnection(common.PORT); var client = net.createConnection(common.PORT);
client.setEncoding('ascii'); client.setEncoding('ascii');
client.addListener('data', function(d) { client.addListener('data', function(d) {
chars_recved += d.length; chars_recved += d.length;
@ -33,7 +33,7 @@ server.listen(common.PORT, function() {
npauses += 1; npauses += 1;
paused = true; paused = true;
console.log('pause'); console.log('pause');
x = chars_recved; var x = chars_recved;
setTimeout(function() { setTimeout(function() {
assert.equal(chars_recved, x); assert.equal(chars_recved, x);
client.resume(); client.resume();

11
test/pummel/test-net-timeout.js

@ -1,10 +1,11 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert');; var assert = require('assert');;
net = require('net'); var net = require('net');
exchanges = 0;
starttime = null; var exchanges = 0;
timeouttime = null; var starttime = null;
timeout = 1000; var timeouttime = null;
var timeout = 1000;
var echo_server = net.createServer(function(socket) { var echo_server = net.createServer(function(socket) {
socket.setTimeout(timeout); socket.setTimeout(timeout);

16
test/pummel/test-timers.js

@ -1,8 +1,6 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
assert = require('assert');
var WINDOW = 200; // why is does this need to be so big? var WINDOW = 200; // why is does this need to be so big?
var interval_count = 0; var interval_count = 0;
@ -79,8 +77,8 @@ setInterval(function(param1, param2){
}, 1000, 'param1', 'param2'); }, 1000, 'param1', 'param2');
// setInterval(cb, 0) should be called multiple times. // setInterval(cb, 0) should be called multiple times.
count4 = 0; var count4 = 0;
interval4 = setInterval(function() { var interval4 = setInterval(function() {
if (++count4 > 10) clearInterval(interval4); if (++count4 > 10) clearInterval(interval4);
}, 0); }, 0);
@ -92,12 +90,12 @@ function t () {
expectedTimeouts--; expectedTimeouts--;
} }
w = setTimeout(t, 200), var w = setTimeout(t, 200);
x = setTimeout(t, 200), var x = setTimeout(t, 200);
y = setTimeout(t, 200); var y = setTimeout(t, 200);
clearTimeout(y), clearTimeout(y);
z = setTimeout(t, 200); var z = setTimeout(t, 200);
clearTimeout(y); clearTimeout(y);

4
test/simple/test-http-exceptions.js

@ -2,7 +2,7 @@ var common = require('../common');
var assert = require('assert');; var assert = require('assert');;
var http = require('http'); var http = require('http');
server = http.createServer(function (req, res) { var server = http.createServer(function (req, res) {
intentionally_not_defined(); intentionally_not_defined();
res.writeHead(200, {"Content-Type": "text/plain"}); res.writeHead(200, {"Content-Type": "text/plain"});
res.write("Thank you, come again."); 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) { process.addListener("uncaughtException", function (err) {
console.log("Caught an exception: " + err); console.log("Caught an exception: " + err);

6
test/simple/test-http-expect-continue.js

@ -1,5 +1,5 @@
var common = require("../common"); var common = require("../common");
var assert = common.assert; var assert = require('assert');
var http = require("http"); var http = require("http");
var outstanding_reqs = 0; var outstanding_reqs = 0;
@ -31,12 +31,12 @@ server.listen(common.PORT);
server.addListener("listening", function() { server.addListener("listening", function() {
var client = http.createClient(common.PORT); var client = http.createClient(common.PORT);
req = client.request("POST", "/world", { var req = client.request("POST", "/world", {
"Expect": "100-continue", "Expect": "100-continue",
}); });
common.debug("Client sending request..."); common.debug("Client sending request...");
outstanding_reqs++; outstanding_reqs++;
body = ""; var body = "";
req.addListener('continue', function () { req.addListener('continue', function () {
common.debug("Client got 100 Continue..."); common.debug("Client got 100 Continue...");
got_continue = true; got_continue = true;

10
test/simple/test-http-keep-alive-close-on-header.js

@ -1,20 +1,18 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
assert = require("assert");
var http = require('http'); var http = require('http');
var util = require('util'); var util = require('util');
body = "hello world\n"; var body = "hello world\n";
headers = {'connection':'keep-alive'} 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.writeHead(200, {"Content-Length": body.length, "Connection":"close"});
res.write(body); res.write(body);
res.end(); res.end();
}); });
connectCount = 0; var connectCount = 0;
server.listen(common.PORT, function () { server.listen(common.PORT, function () {
var client = http.createClient(common.PORT); var client = http.createClient(common.PORT);

10
test/simple/test-http-keep-alive.js

@ -1,20 +1,18 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
assert = require("assert");
var http = require('http'); var http = require('http');
var util = require('util'); var util = require('util');
body = "hello world\n"; var body = "hello world\n";
headers = {'connection':'keep-alive'} 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.writeHead(200, {"Content-Length": body.length});
res.write(body); res.write(body);
res.end(); res.end();
}); });
connectCount = 0; var connectCount = 0;
server.listen(common.PORT, function () { server.listen(common.PORT, function () {
var client = http.createClient(common.PORT); var client = http.createClient(common.PORT);

4
test/simple/test-http-server.js

@ -2,8 +2,8 @@ var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var net = require('net'); var net = require('net');
var http = require('http'); var http = require('http');
url = require("url"); var url = require("url");
qs = require("querystring"); var qs = require("querystring");
var request_number = 0; var request_number = 0;
var requests_sent = 0; var requests_sent = 0;

5
test/simple/test-http-upgrade-server2.js

@ -1,10 +1,9 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var http = require('http'); var http = require('http');
var net = require('net'); var net = require('net');
server = http.createServer(function (req, res) { var server = http.createServer(function (req, res) {
common.error('got req'); common.error('got req');
throw new Error("This shouldn't happen."); throw new Error("This shouldn't happen.");
}); });
@ -16,7 +15,7 @@ server.addListener('upgrade', function (req, socket, upgradeHead) {
throw new Error('upgrade error'); throw new Error('upgrade error');
}); });
gotError = false; var gotError = false;
process.addListener('uncaughtException', function (e) { process.addListener('uncaughtException', function (e) {
common.error('got "clientError" event'); common.error('got "clientError" event');

3
test/simple/test-http-write-empty-string.js

@ -2,9 +2,8 @@ var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var http = require('http'); 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); console.log('responding to ' + request.url);
response.writeHead(200, {'Content-Type': 'text/plain'}); response.writeHead(200, {'Content-Type': 'text/plain'});

2
test/simple/test-http.js

@ -1,7 +1,7 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var http = require('http'); var http = require('http');
url = require("url"); var url = require("url");
function p (x) { function p (x) {
common.error(common.inspect(x)); common.error(common.inspect(x));

2
test/simple/test-listen-fd.js

@ -4,7 +4,7 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var http = require('http'); 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 // Create an server and set it listening on a socket bound to common.PORT
var gotRequest = false; var gotRequest = false;

4
test/simple/test-net-binary.js

@ -2,10 +2,10 @@ var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var net = require('net'); var net = require('net');
binaryString = ""; var binaryString = "";
for (var i = 255; i >= 0; i--) { for (var i = 255; i >= 0; i--) {
var s = "'\\" + i.toString(8) + "'"; var s = "'\\" + i.toString(8) + "'";
S = eval(s); var S = eval(s);
common.error( s common.error( s
+ " " + " "
+ JSON.stringify(S) + JSON.stringify(S)

10
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 // TODO: test that the server can accept more connections after it reaches
// its maximum and some are closed. // its maximum and some are closed.
N = 200; var N = 200;
count = 0; var count = 0;
closes = 0; var closes = 0;
waits = []; var waits = [];
server = net.createServer(function (connection) { var server = net.createServer(function (connection) {
console.error("connect %d", count++); console.error("connect %d", count++);
connection.write("hello"); connection.write("hello");
waits.push(function () { connection.end(); }); waits.push(function () { connection.end(); });

15
test/simple/test-pipe-head.js

@ -1,19 +1,18 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var exec = require('child_process').exec;
var join = require('path').join;
exec = require('child_process').exec; var nodePath = process.argv[0];
join = require('path').join; var script = join(common.fixturesDir, 'print-10-lines.js');
nodePath = process.argv[0]; var cmd = nodePath + ' ' + script + ' | head -2';
script = join(common.fixturesDir, 'print-10-lines.js');
cmd = nodePath + ' ' + script + ' | head -2'; var finished = false;
finished = false;
exec(cmd, function (err, stdout, stderr) { exec(cmd, function (err, stdout, stderr) {
if (err) throw err; if (err) throw err;
lines = stdout.split('\n'); var lines = stdout.split('\n');
assert.equal(3, lines.length); assert.equal(3, lines.length);
finished = true; finished = true;
}); });

7
test/simple/test-pump-file2tcp-noexist.js

@ -4,12 +4,12 @@ var net = require('net');
var fs = require('fs'); var fs = require('fs');
var util = require('util'); var util = require('util');
var path = require('path'); 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 got_error = false;
var conn_closed = false; var conn_closed = false;
server = net.createServer(function (stream) { var server = net.createServer(function (stream) {
common.error('pump!'); common.error('pump!');
util.pump(fs.createReadStream(fn), stream, function (err) { util.pump(fs.createReadStream(fn), stream, function (err) {
common.error("util.pump's callback fired"); common.error("util.pump's callback fired");
@ -25,7 +25,7 @@ server = net.createServer(function (stream) {
}); });
server.listen(common.PORT, function () { server.listen(common.PORT, function () {
conn = net.createConnection(common.PORT); var conn = net.createConnection(common.PORT);
conn.setEncoding('utf8'); conn.setEncoding('utf8');
conn.addListener("data", function (chunk) { conn.addListener("data", function (chunk) {
common.error('recv data! nchars = ' + chunk.length); common.error('recv data! nchars = ' + chunk.length);
@ -43,7 +43,6 @@ server.listen(common.PORT, function () {
}); });
var buffer = ''; var buffer = '';
count = 0;
process.addListener('exit', function () { process.addListener('exit', function () {
assert.equal(true, got_error); assert.equal(true, got_error);

10
test/simple/test-pump-file2tcp.js

@ -4,11 +4,11 @@ var net = require('net');
var fs = require('fs'); var fs = require('fs');
var util = require('util'); var util = require('util');
var path = require('path'); 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!'); common.error('pump!');
util.pump(fs.createReadStream(fn), stream, function () { util.pump(fs.createReadStream(fn), stream, function () {
common.error('server stream close'); common.error('server stream close');
@ -18,7 +18,7 @@ server = net.createServer(function (stream) {
}); });
server.listen(common.PORT, function () { server.listen(common.PORT, function () {
conn = net.createConnection(common.PORT); var conn = net.createConnection(common.PORT);
conn.setEncoding('utf8'); conn.setEncoding('utf8');
conn.addListener("data", function (chunk) { conn.addListener("data", function (chunk) {
common.error('recv data! nchars = ' + chunk.length); common.error('recv data! nchars = ' + chunk.length);
@ -34,7 +34,7 @@ server.listen(common.PORT, function () {
}); });
var buffer = ''; var buffer = '';
count = 0; var count = 0;
server.addListener('listening', function () { server.addListener('listening', function () {
}); });

2
test/simple/test-signal-handler.js

@ -19,7 +19,7 @@ process.addListener('SIGUSR1', function () {
}, 5); }, 5);
}); });
i = 0; var i = 0;
setInterval(function () { setInterval(function () {
console.log("running process..." + ++i); console.log("running process..." + ++i);

15
test/simple/test-stdin-from-file.js

@ -1,17 +1,16 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var join = require('path').join;
join = require('path').join; var childProccess = require('child_process');
childProccess = require('child_process');
var fs = require('fs'); var fs = require('fs');
stdoutScript = join(common.fixturesDir, 'echo.js'); var stdoutScript = join(common.fixturesDir, 'echo.js');
tmpFile = join(common.fixturesDir, 'stdin.txt'); 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" var string = "abc\nümlaut.\nsomething else\n" +
+ "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n"; "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n";
console.log(cmd + "\n\n"); console.log(cmd + "\n\n");

11
test/simple/test-stdout-to-file.js

@ -1,11 +1,12 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var path = require('path'); var path = require('path');
childProccess = require('child_process'); var childProccess = require('child_process');
var fs = require('fs'); var fs = require('fs');
scriptString = path.join(common.fixturesDir, 'print-chars.js');
scriptBuffer = path.join(common.fixturesDir, 'print-chars-from-buffer.js'); var scriptString = path.join(common.fixturesDir, 'print-chars.js');
tmpFile = path.join(common.fixturesDir, 'stdout.txt'); var scriptBuffer = path.join(common.fixturesDir, 'print-chars-from-buffer.js');
var tmpFile = path.join(common.fixturesDir, 'stdout.txt');
function test (size, useBuffer, cb) { function test (size, useBuffer, cb) {
var cmd = process.argv[0] var cmd = process.argv[0]
@ -39,7 +40,7 @@ function test (size, useBuffer, cb) {
}); });
} }
finished = false; var finished = false;
test(1024*1024, false, function () { test(1024*1024, false, function () {
console.log("Done printing with string"); console.log("Done printing with string");
test(1024*1024, true, function () { test(1024*1024, true, function () {

18
test/simple/test-string-decoder.js

@ -1,13 +1,11 @@
var common = require('../common'); 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');
var buffer = new Buffer('$');
buffer = new Buffer('$');
assert.deepEqual('$', decoder.write(buffer)); assert.deepEqual('$', decoder.write(buffer));
buffer = new Buffer('¢'); buffer = new Buffer('¢');
@ -20,7 +18,7 @@ assert.deepEqual('', decoder.write(buffer.slice(1, 2)));
assert.deepEqual('€', decoder.write(buffer.slice(2, 3))); assert.deepEqual('€', decoder.write(buffer.slice(2, 3)));
buffer = new Buffer([0xF0, 0xA4, 0xAD, 0xA2]); buffer = new Buffer([0xF0, 0xA4, 0xAD, 0xA2]);
s = ''; var s = '';
s += decoder.write(buffer.slice(0, 1)); s += decoder.write(buffer.slice(0, 1));
s += decoder.write(buffer.slice(1, 2)); s += decoder.write(buffer.slice(1, 2));
s += decoder.write(buffer.slice(2, 3)); s += decoder.write(buffer.slice(2, 3));
@ -34,10 +32,10 @@ assert.ok(s.length > 0);
// U+12E4 -> E1 8B A4 // U+12E4 -> E1 8B A4
// U+0030 -> 30 // U+0030 -> 30
// U+3045 -> E3 81 85 // U+3045 -> E3 81 85
expected = '\u02e4\u0064\u12e4\u0030\u3045'; var expected = '\u02e4\u0064\u12e4\u0030\u3045';
buffer = new Buffer([0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, var buffer = new Buffer([0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4,
0x30, 0xE3, 0x81, 0x85]); 0x30, 0xE3, 0x81, 0x85]);
charLengths = [0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5]; var charLengths = [0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5];
// Split the buffer into 3 segments // Split the buffer into 3 segments
// |----|------|-------| // |----|------|-------|

Loading…
Cancel
Save