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
*/
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);
}
};

8
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);
};
});
});
};

14
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 () {

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);
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");
};
});
});
}

16
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);
}

8
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);
}

8
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;
};
});
}

6
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();
}

10
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");

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 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 () {

24
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);
}

24
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);

Loading…
Cancel
Save