diff options
author | Ryan <ry@tinyclouds.org> | 2009-06-27 20:40:43 +0200 |
---|---|---|
committer | Ryan <ry@tinyclouds.org> | 2009-06-28 19:08:26 +0200 |
commit | ed926da691b223c23e62f8e5cdf28152038ee2b9 (patch) | |
tree | 0c3406e2c9b577c8c9e526a78fbe23c89374ef21 | |
parent | 80bf451e6eed071b083a0058d8a77cc2edfc5336 (diff) | |
download | nodejs-ed926da691b223c23e62f8e5cdf28152038ee2b9.tar.gz nodejs-ed926da691b223c23e62f8e5cdf28152038ee2b9.tar.bz2 nodejs-ed926da691b223c23e62f8e5cdf28152038ee2b9.zip |
Remove onEvent compatibility
-rw-r--r-- | src/events.js | 10 | ||||
-rw-r--r-- | src/http.js | 8 | ||||
-rw-r--r-- | test/mjsunit/test-http-client-race.js | 14 | ||||
-rw-r--r-- | test/mjsunit/test-http-proxy.js | 14 | ||||
-rw-r--r-- | test/mjsunit/test-http-server.js | 16 | ||||
-rw-r--r-- | test/mjsunit/test-http.js | 8 | ||||
-rw-r--r-- | test/mjsunit/test-process-buffering.js | 8 | ||||
-rw-r--r-- | test/mjsunit/test-process-kill.js | 6 | ||||
-rw-r--r-- | test/mjsunit/test-process-simple.js | 10 | ||||
-rw-r--r-- | test/mjsunit/test-process-spawn-loop.js | 8 | ||||
-rw-r--r-- | test/mjsunit/test-reconnecting-socket.js | 24 | ||||
-rw-r--r-- | test/mjsunit/test-tcp-pingpong.js | 24 |
12 files changed, 74 insertions, 76 deletions
diff --git a/src/events.js b/src/events.js index f63641c23..3489d5982 100644 --- a/src/events.js +++ b/src/events.js @@ -21,14 +21,12 @@ emitter.listeners = function (type, listener) { * See events.cc */ emitter.emit = function (type, args) { - if (this["on" + type] instanceof Function) { - this["on" + type].apply(this, args); - } if (!this._events) return; if (!this._events.hasOwnProperty(type)) return; - for (var i = 0; i < this._events[type].length; i++) { - var listener = this._events[type][i]; - listener.apply(this, args); + var listeners = this._events[type]; + var length = listeners.length; + for (var i = 0; i < length; i++) { + listeners[i].apply(this, args); } }; diff --git a/src/http.js b/src/http.js index a9c8ff691..3b734ac1e 100644 --- a/src/http.js +++ b/src/http.js @@ -544,12 +544,12 @@ node.http.cat = function (url, encoding, callback) { var status = res.statusCode == 200 ? 0 : -1; res.setBodyEncoding(encoding); var content = ""; - res.onBody = function (chunk) { + res.addListener("Body", function (chunk) { content += chunk; - }; - res.onBodyComplete = function () { + }); + res.addListener("BodyComplete", function () { callback(status, content); - }; + }); }); }; diff --git a/test/mjsunit/test-http-client-race.js b/test/mjsunit/test-http-client-race.js index 875f53f99..0958065d0 100644 --- a/test/mjsunit/test-http-client-race.js +++ b/test/mjsunit/test-http-client-race.js @@ -23,17 +23,17 @@ var body2 = ""; client.get("/1").finish(function (res1) { 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) { res2.setBodyEncoding("utf8"); - res2.onBody = function (chunk) { body2 += chunk; }; - res2.onBodyComplete = function () { - server.close(); - }; + res2.addListener("Body", function (chunk) { body2 += chunk; }); + res2.addListener("BodyComplete", function () { server.close(); }); }); - }; + }); }); function onExit () { diff --git a/test/mjsunit/test-http-proxy.js b/test/mjsunit/test-http-proxy.js index 5a3e88f7a..2a3621dad 100644 --- a/test/mjsunit/test-http-proxy.js +++ b/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); proxy_req.finish(function(proxy_res) { res.sendHeader(proxy_res.statusCode, proxy_res.headers); - proxy_res.onBody = function(chunk) { + proxy_res.addListener("Body", function(chunk) { res.sendBody(chunk); - }; - proxy_res.onBodyComplete = function() { + }); + proxy_res.addListener("BodyComplete", function() { res.finish(); // node.debug("proxy res"); - }; + }); }); }); // node.debug("listen proxy") @@ -40,12 +40,12 @@ function onLoad () { // node.debug("got res"); assertEquals(200, res.statusCode); res.setBodyEncoding("utf8"); - res.onBody = function (chunk) { body += chunk; }; - res.onBodyComplete = function () { + res.addListener("Body", function (chunk) { body += chunk; }); + res.addListener("BodyComplete", function () { proxy.close(); backend.close(); // node.debug("closed both"); - }; + }); }); } diff --git a/test/mjsunit/test-http-server.js b/test/mjsunit/test-http-server.js index 689e1d05c..47a10e2eb 100644 --- a/test/mjsunit/test-http-server.js +++ b/test/mjsunit/test-http-server.js @@ -35,12 +35,12 @@ function onLoad() { var c = new node.tcp.Connection(); c.setEncoding("utf8"); - c.onConnect = function () { + c.addListener("Connect", function () { c.send( "GET /hello HTTP/1.1\r\n\r\n" ); requests_sent += 1; - }; + }); - c.onReceive = function (chunk) { + c.addListener("Receive", function (chunk) { server_response += chunk; if (requests_sent == 1) { @@ -49,15 +49,15 @@ function onLoad() { assertEquals(c.readyState, "readOnly"); requests_sent += 1; } - }; + }); - c.onEOF = function () { + c.addListener("EOF", function () { client_got_eof = true; - }; + }); - c.onDisconnect = function () { + c.addListener("Disconnect", function () { assertEquals(c.readyState, "closed"); - }; + }); c.connect(port); } diff --git a/test/mjsunit/test-http.js b/test/mjsunit/test-http.js index 2dea8aaa5..1a9491dd6 100644 --- a/test/mjsunit/test-http.js +++ b/test/mjsunit/test-http.js @@ -19,12 +19,12 @@ function onLoad () { this.close(); } - req.onBodyComplete = function () { + req.addListener("BodyComplete", function () { res.sendHeader(200, [["Content-Type", "text/plain"]]); res.sendBody("The path was " + req.uri.path); res.finish(); responses_sent += 1; - }; + }); //assertEquals("127.0.0.1", res.connection.remoteAddress); }).listen(PORT); @@ -35,7 +35,7 @@ function onLoad () { assertEquals(200, res.statusCode); responses_recvd += 1; res.setBodyEncoding("utf8"); - res.onBody = function (chunk) { body0 += chunk; }; + res.addListener("Body", function (chunk) { body0 += chunk; }); }); setTimeout(function () { @@ -44,7 +44,7 @@ function onLoad () { assertEquals(200, res.statusCode); responses_recvd += 1; res.setBodyEncoding("utf8"); - res.onBody = function (chunk) { body1 += chunk; }; + res.addListener("Body", function (chunk) { body1 += chunk; }); }); }, 1); } diff --git a/test/mjsunit/test-process-buffering.js b/test/mjsunit/test-process-buffering.js index 74dfca5a3..e65cc379a 100644 --- a/test/mjsunit/test-process-buffering.js +++ b/test/mjsunit/test-process-buffering.js @@ -5,14 +5,14 @@ var pwd_called = false; function pwd (callback) { var output = ""; var process = new node.Process("pwd"); - process.onOutput = function (s) { + process.addListener("Output", function (s) { if (s) output += s; - }; - process.onExit = function(c) { + }); + process.addListener("Exit", function(c) { assertEquals(0, c); callback(output); pwd_called = true; - }; + }); } diff --git a/test/mjsunit/test-process-kill.js b/test/mjsunit/test-process-kill.js index 90753fc89..1d4bb30ae 100644 --- a/test/mjsunit/test-process-kill.js +++ b/test/mjsunit/test-process-kill.js @@ -5,9 +5,9 @@ var exit_status = -1; function onLoad () { var cat = new node.Process("cat"); - cat.onOutput = function (chunk) { assertEquals(null, chunk); }; - cat.onError = function (chunk) { assertEquals(null, chunk); }; - cat.onExit = function (status) { exit_status = status; }; + cat.addListener("Output", function (chunk) { assertEquals(null, chunk); }); + cat.addListener("Error", function (chunk) { assertEquals(null, chunk); }); + cat.addListener("Exit", function (status) { exit_status = status; }); cat.kill(); } diff --git a/test/mjsunit/test-process-simple.js b/test/mjsunit/test-process-simple.js index f3a761abd..091f71d07 100644 --- a/test/mjsunit/test-process-simple.js +++ b/test/mjsunit/test-process-simple.js @@ -5,16 +5,16 @@ var cat = new node.Process("cat"); var response = ""; var exit_status = -1; -cat.onOutput = function (chunk) { +cat.addListener("Output", function (chunk) { if (chunk) { response += chunk; if (response === "hello world") cat.close(); } -}; -cat.onError = function (chunk) { +}); +cat.addListener("Error", function (chunk) { assertEquals(null, chunk); -}; -cat.onExit = function (status) { exit_status = status; }; +}); +cat.addListener("Exit", function (status) { exit_status = status; }); function onLoad () { cat.write("hello"); diff --git a/test/mjsunit/test-process-spawn-loop.js b/test/mjsunit/test-process-spawn-loop.js index 48ed973e6..af1b9b45f 100644 --- a/test/mjsunit/test-process-spawn-loop.js +++ b/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 output = ""; - p.onOutput = function(chunk) { + p.addListener("Output", function(chunk) { if (chunk) output += chunk; - }; + }); - p.onExit = function () { + p.addListener("Exit", function () { //puts(output); if (i < N) spawn(i+1); else finished = true; - }; + }); } function onLoad () { diff --git a/test/mjsunit/test-reconnecting-socket.js b/test/mjsunit/test-reconnecting-socket.js index dbbee0b47..99c0dd401 100644 --- a/test/mjsunit/test-reconnecting-socket.js +++ b/test/mjsunit/test-reconnecting-socket.js @@ -8,39 +8,39 @@ var client_recv_count = 0; function onLoad () { var server = node.tcp.createServer(function (socket) { - socket.onConnect = function () { + socket.addListener("Connect", function () { socket.send("hello\r\n"); - }; + }); - socket.onEOF = function () { + socket.addListener("EOF", function () { socket.close(); - }; + }); - socket.onDisconnect = function (had_error) { + socket.addListener("Disconnect", function (had_error) { //puts("server had_error: " + JSON.stringify(had_error)); assertFalse(had_error); - }; + }); }); server.listen(port); var client = new node.tcp.Connection(); client.setEncoding("UTF8"); - client.onConnect = function () { - }; + client.addListener("Connect", function () { + }); - client.onReceive = function (chunk) { + client.addListener("Receive", function (chunk) { client_recv_count += 1; assertEquals("hello\r\n", chunk); client.fullClose(); - }; + }); - client.onDisconnect = function (had_error) { + client.addListener("Disconnect", function (had_error) { assertFalse(had_error); if (disconnect_count++ < N) client.connect(port); // reconnect else server.close(); - }; + }); client.connect(port); } diff --git a/test/mjsunit/test-tcp-pingpong.js b/test/mjsunit/test-tcp-pingpong.js index c827512e3..81bf1f2f1 100644 --- a/test/mjsunit/test-tcp-pingpong.js +++ b/test/mjsunit/test-tcp-pingpong.js @@ -19,24 +19,24 @@ function pingPongTest (port, host, on_complete) { socket.setEncoding("utf8"); socket.timeout = 0; - socket.onReceive = function (data) { + socket.addListener("Receive", function (data) { assertEquals("open", socket.readyState); assertTrue(count <= N); if (/PING/.exec(data)) { socket.send("PONG"); } - }; + }); - socket.onEOF = function () { + socket.addListener("EOF", function () { assertEquals("writeOnly", socket.readyState); socket.close(); - }; + }); - socket.onDisconnect = function (had_error) { + socket.addListener("Disconnect", function (had_error) { assertFalse(had_error); assertEquals("closed", socket.readyState); socket.server.close(); - }; + }); }); server.listen(port, host); @@ -45,12 +45,12 @@ function pingPongTest (port, host, on_complete) { client.setEncoding("utf8"); - client.onConnect = function () { + client.addListener("Connect", function () { assertEquals("open", client.readyState); client.send("PING"); - }; + }); - client.onReceive = function (data) { + client.addListener("Receive", function (data) { assertEquals("PONG", data); count += 1; @@ -68,14 +68,14 @@ function pingPongTest (port, host, on_complete) { client.send("PING"); client.close(); } - }; + }); - client.onDisconnect = function () { + client.addListener("Disconnect", function () { assertEquals(N+1, count); assertTrue(sent_final_ping); if (on_complete) on_complete(); tests_run += 1; - }; + }); assertEquals("closed", client.readyState); client.connect(port, host); |