Browse Source

Remove onEvent compatibility

v0.7.4-release
Ryan 16 years ago
parent
commit
ed926da691
  1. 10
      src/events.js
  2. 8
      src/http.js
  3. 14
      test/mjsunit/test-http-client-race.js
  4. 14
      test/mjsunit/test-http-proxy.js
  5. 16
      test/mjsunit/test-http-server.js
  6. 8
      test/mjsunit/test-http.js
  7. 8
      test/mjsunit/test-process-buffering.js
  8. 6
      test/mjsunit/test-process-kill.js
  9. 10
      test/mjsunit/test-process-simple.js
  10. 8
      test/mjsunit/test-process-spawn-loop.js
  11. 24
      test/mjsunit/test-reconnecting-socket.js
  12. 24
      test/mjsunit/test-tcp-pingpong.js

10
src/events.js

@ -21,14 +21,12 @@ emitter.listeners = function (type, listener) {
* See events.cc * See events.cc
*/ */
emitter.emit = function (type, args) { emitter.emit = function (type, args) {
if (this["on" + type] instanceof Function) {
this["on" + type].apply(this, args);
}
if (!this._events) return; if (!this._events) return;
if (!this._events.hasOwnProperty(type)) return; if (!this._events.hasOwnProperty(type)) return;
for (var i = 0; i < this._events[type].length; i++) { var listeners = this._events[type];
var listener = this._events[type][i]; var length = listeners.length;
listener.apply(this, args); for (var i = 0; i < length; i++) {
listeners[i].apply(this, args);
} }
}; };

8
src/http.js

@ -544,12 +544,12 @@ node.http.cat = function (url, encoding, callback) {
var status = res.statusCode == 200 ? 0 : -1; var status = res.statusCode == 200 ? 0 : -1;
res.setBodyEncoding(encoding); res.setBodyEncoding(encoding);
var content = ""; var content = "";
res.onBody = function (chunk) { res.addListener("Body", function (chunk) {
content += chunk; content += chunk;
}; });
res.onBodyComplete = function () { res.addListener("BodyComplete", function () {
callback(status, content); callback(status, content);
}; });
}); });
}; };

14
test/mjsunit/test-http-client-race.js

@ -23,17 +23,17 @@ var body2 = "";
client.get("/1").finish(function (res1) { client.get("/1").finish(function (res1) {
res1.setBodyEncoding("utf8"); res1.setBodyEncoding("utf8");
res1.onBody = function (chunk) { body1 += chunk; }; res1.addListener("Body", function (chunk) {
body1 += chunk;
});
res1.onBodyComplete = function () { res1.addListener("BodyComplete", function () {
client.get("/2").finish(function (res2) { client.get("/2").finish(function (res2) {
res2.setBodyEncoding("utf8"); res2.setBodyEncoding("utf8");
res2.onBody = function (chunk) { body2 += chunk; }; res2.addListener("Body", function (chunk) { body2 += chunk; });
res2.onBodyComplete = function () { res2.addListener("BodyComplete", function () { server.close(); });
server.close();
};
}); });
}; });
}); });
function onExit () { function onExit () {

14
test/mjsunit/test-http-proxy.js

@ -18,13 +18,13 @@ var proxy = node.http.createServer(function (req, res) {
var proxy_req = proxy_client.get(req.uri.path); var proxy_req = proxy_client.get(req.uri.path);
proxy_req.finish(function(proxy_res) { proxy_req.finish(function(proxy_res) {
res.sendHeader(proxy_res.statusCode, proxy_res.headers); res.sendHeader(proxy_res.statusCode, proxy_res.headers);
proxy_res.onBody = function(chunk) { proxy_res.addListener("Body", function(chunk) {
res.sendBody(chunk); res.sendBody(chunk);
}; });
proxy_res.onBodyComplete = function() { proxy_res.addListener("BodyComplete", function() {
res.finish(); res.finish();
// node.debug("proxy res"); // node.debug("proxy res");
}; });
}); });
}); });
// node.debug("listen proxy") // node.debug("listen proxy")
@ -40,12 +40,12 @@ function onLoad () {
// node.debug("got res"); // node.debug("got res");
assertEquals(200, res.statusCode); assertEquals(200, res.statusCode);
res.setBodyEncoding("utf8"); res.setBodyEncoding("utf8");
res.onBody = function (chunk) { body += chunk; }; res.addListener("Body", function (chunk) { body += chunk; });
res.onBodyComplete = function () { res.addListener("BodyComplete", function () {
proxy.close(); proxy.close();
backend.close(); backend.close();
// node.debug("closed both"); // node.debug("closed both");
}; });
}); });
} }

16
test/mjsunit/test-http-server.js

@ -35,12 +35,12 @@ function onLoad() {
var c = new node.tcp.Connection(); var c = new node.tcp.Connection();
c.setEncoding("utf8"); c.setEncoding("utf8");
c.onConnect = function () { c.addListener("Connect", function () {
c.send( "GET /hello HTTP/1.1\r\n\r\n" ); c.send( "GET /hello HTTP/1.1\r\n\r\n" );
requests_sent += 1; requests_sent += 1;
}; });
c.onReceive = function (chunk) { c.addListener("Receive", function (chunk) {
server_response += chunk; server_response += chunk;
if (requests_sent == 1) { if (requests_sent == 1) {
@ -49,15 +49,15 @@ function onLoad() {
assertEquals(c.readyState, "readOnly"); assertEquals(c.readyState, "readOnly");
requests_sent += 1; requests_sent += 1;
} }
}; });
c.onEOF = function () { c.addListener("EOF", function () {
client_got_eof = true; client_got_eof = true;
}; });
c.onDisconnect = function () { c.addListener("Disconnect", function () {
assertEquals(c.readyState, "closed"); assertEquals(c.readyState, "closed");
}; });
c.connect(port); c.connect(port);
} }

8
test/mjsunit/test-http.js

@ -19,12 +19,12 @@ function onLoad () {
this.close(); this.close();
} }
req.onBodyComplete = function () { req.addListener("BodyComplete", function () {
res.sendHeader(200, [["Content-Type", "text/plain"]]); res.sendHeader(200, [["Content-Type", "text/plain"]]);
res.sendBody("The path was " + req.uri.path); res.sendBody("The path was " + req.uri.path);
res.finish(); res.finish();
responses_sent += 1; responses_sent += 1;
}; });
//assertEquals("127.0.0.1", res.connection.remoteAddress); //assertEquals("127.0.0.1", res.connection.remoteAddress);
}).listen(PORT); }).listen(PORT);
@ -35,7 +35,7 @@ function onLoad () {
assertEquals(200, res.statusCode); assertEquals(200, res.statusCode);
responses_recvd += 1; responses_recvd += 1;
res.setBodyEncoding("utf8"); res.setBodyEncoding("utf8");
res.onBody = function (chunk) { body0 += chunk; }; res.addListener("Body", function (chunk) { body0 += chunk; });
}); });
setTimeout(function () { setTimeout(function () {
@ -44,7 +44,7 @@ function onLoad () {
assertEquals(200, res.statusCode); assertEquals(200, res.statusCode);
responses_recvd += 1; responses_recvd += 1;
res.setBodyEncoding("utf8"); res.setBodyEncoding("utf8");
res.onBody = function (chunk) { body1 += chunk; }; res.addListener("Body", function (chunk) { body1 += chunk; });
}); });
}, 1); }, 1);
} }

8
test/mjsunit/test-process-buffering.js

@ -5,14 +5,14 @@ var pwd_called = false;
function pwd (callback) { function pwd (callback) {
var output = ""; var output = "";
var process = new node.Process("pwd"); var process = new node.Process("pwd");
process.onOutput = function (s) { process.addListener("Output", function (s) {
if (s) output += s; if (s) output += s;
}; });
process.onExit = function(c) { process.addListener("Exit", function(c) {
assertEquals(0, c); assertEquals(0, c);
callback(output); callback(output);
pwd_called = true; pwd_called = true;
}; });
} }

6
test/mjsunit/test-process-kill.js

@ -5,9 +5,9 @@ var exit_status = -1;
function onLoad () { function onLoad () {
var cat = new node.Process("cat"); var cat = new node.Process("cat");
cat.onOutput = function (chunk) { assertEquals(null, chunk); }; cat.addListener("Output", function (chunk) { assertEquals(null, chunk); });
cat.onError = function (chunk) { assertEquals(null, chunk); }; cat.addListener("Error", function (chunk) { assertEquals(null, chunk); });
cat.onExit = function (status) { exit_status = status; }; cat.addListener("Exit", function (status) { exit_status = status; });
cat.kill(); cat.kill();
} }

10
test/mjsunit/test-process-simple.js

@ -5,16 +5,16 @@ var cat = new node.Process("cat");
var response = ""; var response = "";
var exit_status = -1; var exit_status = -1;
cat.onOutput = function (chunk) { cat.addListener("Output", function (chunk) {
if (chunk) { if (chunk) {
response += chunk; response += chunk;
if (response === "hello world") cat.close(); if (response === "hello world") cat.close();
} }
}; });
cat.onError = function (chunk) { cat.addListener("Error", function (chunk) {
assertEquals(null, chunk); assertEquals(null, chunk);
}; });
cat.onExit = function (status) { exit_status = status; }; cat.addListener("Exit", function (status) { exit_status = status; });
function onLoad () { function onLoad () {
cat.write("hello"); cat.write("hello");

8
test/mjsunit/test-process-spawn-loop.js

@ -7,17 +7,17 @@ function spawn (i) {
var p = new node.Process('python -c "print 500 * 1024 * \'C\'"'); var p = new node.Process('python -c "print 500 * 1024 * \'C\'"');
var output = ""; var output = "";
p.onOutput = function(chunk) { p.addListener("Output", function(chunk) {
if (chunk) output += chunk; if (chunk) output += chunk;
}; });
p.onExit = function () { p.addListener("Exit", function () {
//puts(output); //puts(output);
if (i < N) if (i < N)
spawn(i+1); spawn(i+1);
else else
finished = true; finished = true;
}; });
} }
function onLoad () { function onLoad () {

24
test/mjsunit/test-reconnecting-socket.js

@ -8,39 +8,39 @@ var client_recv_count = 0;
function onLoad () { function onLoad () {
var server = node.tcp.createServer(function (socket) { var server = node.tcp.createServer(function (socket) {
socket.onConnect = function () { socket.addListener("Connect", function () {
socket.send("hello\r\n"); socket.send("hello\r\n");
}; });
socket.onEOF = function () { socket.addListener("EOF", function () {
socket.close(); socket.close();
}; });
socket.onDisconnect = function (had_error) { socket.addListener("Disconnect", function (had_error) {
//puts("server had_error: " + JSON.stringify(had_error)); //puts("server had_error: " + JSON.stringify(had_error));
assertFalse(had_error); assertFalse(had_error);
}; });
}); });
server.listen(port); server.listen(port);
var client = new node.tcp.Connection(); var client = new node.tcp.Connection();
client.setEncoding("UTF8"); client.setEncoding("UTF8");
client.onConnect = function () { client.addListener("Connect", function () {
}; });
client.onReceive = function (chunk) { client.addListener("Receive", function (chunk) {
client_recv_count += 1; client_recv_count += 1;
assertEquals("hello\r\n", chunk); assertEquals("hello\r\n", chunk);
client.fullClose(); client.fullClose();
}; });
client.onDisconnect = function (had_error) { client.addListener("Disconnect", function (had_error) {
assertFalse(had_error); assertFalse(had_error);
if (disconnect_count++ < N) if (disconnect_count++ < N)
client.connect(port); // reconnect client.connect(port); // reconnect
else else
server.close(); server.close();
}; });
client.connect(port); client.connect(port);
} }

24
test/mjsunit/test-tcp-pingpong.js

@ -19,24 +19,24 @@ function pingPongTest (port, host, on_complete) {
socket.setEncoding("utf8"); socket.setEncoding("utf8");
socket.timeout = 0; socket.timeout = 0;
socket.onReceive = function (data) { socket.addListener("Receive", function (data) {
assertEquals("open", socket.readyState); assertEquals("open", socket.readyState);
assertTrue(count <= N); assertTrue(count <= N);
if (/PING/.exec(data)) { if (/PING/.exec(data)) {
socket.send("PONG"); socket.send("PONG");
} }
}; });
socket.onEOF = function () { socket.addListener("EOF", function () {
assertEquals("writeOnly", socket.readyState); assertEquals("writeOnly", socket.readyState);
socket.close(); socket.close();
}; });
socket.onDisconnect = function (had_error) { socket.addListener("Disconnect", function (had_error) {
assertFalse(had_error); assertFalse(had_error);
assertEquals("closed", socket.readyState); assertEquals("closed", socket.readyState);
socket.server.close(); socket.server.close();
}; });
}); });
server.listen(port, host); server.listen(port, host);
@ -45,12 +45,12 @@ function pingPongTest (port, host, on_complete) {
client.setEncoding("utf8"); client.setEncoding("utf8");
client.onConnect = function () { client.addListener("Connect", function () {
assertEquals("open", client.readyState); assertEquals("open", client.readyState);
client.send("PING"); client.send("PING");
}; });
client.onReceive = function (data) { client.addListener("Receive", function (data) {
assertEquals("PONG", data); assertEquals("PONG", data);
count += 1; count += 1;
@ -68,14 +68,14 @@ function pingPongTest (port, host, on_complete) {
client.send("PING"); client.send("PING");
client.close(); client.close();
} }
}; });
client.onDisconnect = function () { client.addListener("Disconnect", function () {
assertEquals(N+1, count); assertEquals(N+1, count);
assertTrue(sent_final_ping); assertTrue(sent_final_ping);
if (on_complete) on_complete(); if (on_complete) on_complete();
tests_run += 1; tests_run += 1;
}; });
assertEquals("closed", client.readyState); assertEquals("closed", client.readyState);
client.connect(port, host); client.connect(port, host);

Loading…
Cancel
Save