Browse Source

Snakecase events .

v0.7.4-release
Ryan 16 years ago
parent
commit
d428eff023
  1. 4
      src/events.cc
  2. 14
      src/events.js
  3. 14
      src/http.cc
  4. 60
      src/http.js
  5. 14
      src/net.cc
  6. 6
      src/node.js
  7. 4
      src/process.cc
  8. 2
      src/timer.cc
  9. 2
      test/mjsunit/test-file-open.js
  10. 8
      test/mjsunit/test-http-client-race.js
  11. 8
      test/mjsunit/test-http-proxy.js
  12. 8
      test/mjsunit/test-http-server.js
  13. 6
      test/mjsunit/test-http.js
  14. 4
      test/mjsunit/test-process-buffering.js
  15. 6
      test/mjsunit/test-process-kill.js
  16. 6
      test/mjsunit/test-process-simple.js
  17. 4
      test/mjsunit/test-process-spawn-loop.js
  18. 12
      test/mjsunit/test-reconnecting-socket.js
  19. 12
      test/mjsunit/test-tcp-pingpong.js

4
src/events.cc

@ -94,7 +94,7 @@ Promise::Create (void)
bool
Promise::EmitSuccess (int argc, v8::Handle<v8::Value> argv[])
{
bool r = Emit("Success", argc, argv);
bool r = Emit("success", argc, argv);
Detach();
ev_ref(EV_DEFAULT_UC);
@ -105,7 +105,7 @@ Promise::EmitSuccess (int argc, v8::Handle<v8::Value> argv[])
bool
Promise::EmitError (int argc, v8::Handle<v8::Value> argv[])
{
bool r = Emit("Error", argc, argv);
bool r = Emit("error", argc, argv);
Detach();
ev_ref(EV_DEFAULT_UC);

14
src/events.js

@ -17,12 +17,12 @@ emitter.listeners = function (type, listener) {
return this._events[type];
};
/* This function is called often from C++.
* See events.cc
*/
// This function is called often from C++.
// See events.cc
emitter.emit = function (type, args) {
if (!this._events) return;
if (!this._events.hasOwnProperty(type)) return;
var listeners = this._events[type];
var length = listeners.length;
@ -39,21 +39,21 @@ emitter.emit = function (type, args) {
var promise = node.Promise.prototype;
promise.addCallback = function (listener) {
this.addListener("Success", listener);
this.addListener("success", listener);
return this;
};
promise.addErrback = function (listener) {
this.addListener("Error", listener);
this.addListener("error", listener);
return this;
};
promise.emitSuccess = function (args) {
this.emit("Success", args);
this.emit("success", args);
};
promise.emitError = function (args) {
this.emit("Error", args);
this.emit("error", args);
};
})(); // end anonymous namespace

14
src/http.cc

@ -87,7 +87,7 @@ int
HTTPConnection::on_message_begin (http_parser *parser)
{
HTTPConnection *connection = static_cast<HTTPConnection*> (parser->data);
connection->Emit("MessageBegin", 0, NULL);
connection->Emit("message_begin", 0, NULL);
return 0;
}
@ -95,7 +95,7 @@ int
HTTPConnection::on_message_complete (http_parser *parser)
{
HTTPConnection *connection = static_cast<HTTPConnection*> (parser->data);
connection->Emit("MessageComplete", 0, NULL);
connection->Emit("message_complete", 0, NULL);
return 0;
}
@ -105,7 +105,7 @@ HTTPConnection::on_uri (http_parser *parser, const char *buf, size_t len)
HandleScope scope;
HTTPConnection *connection = static_cast<HTTPConnection*>(parser->data);
Local<Value> argv[1] = { String::New(buf, len) };
connection->Emit("URI", 1, argv);
connection->Emit("uri", 1, argv);
return 0;
}
@ -115,7 +115,7 @@ HTTPConnection::on_header_field (http_parser *parser, const char *buf, size_t le
HandleScope scope;
HTTPConnection *connection = static_cast<HTTPConnection*>(parser->data);
Local<Value> argv[1] = { String::New(buf, len) };
connection->Emit("HeaderField", 1, argv);
connection->Emit("header_field", 1, argv);
return 0;
}
@ -125,7 +125,7 @@ HTTPConnection::on_header_value (http_parser *parser, const char *buf, size_t le
HandleScope scope;
HTTPConnection *connection = static_cast<HTTPConnection*>(parser->data);
Local<Value> argv[1] = { String::New(buf, len) };
connection->Emit("HeaderValue", 1, argv);
connection->Emit("header_value", 1, argv);
return 0;
}
@ -183,7 +183,7 @@ HTTPConnection::on_headers_complete (http_parser *parser)
Local<Value> argv[1] = { message_info };
connection->Emit("HeadersComplete", 1, argv);
connection->Emit("headers_complete", 1, argv);
return 0;
}
@ -216,7 +216,7 @@ HTTPConnection::on_body (http_parser *parser, const char *buf, size_t len)
argv[0] = array;
}
connection->Emit("Body", 1, argv);
connection->Emit("body", 1, argv);
return 0;
}

60
src/http.js

@ -128,8 +128,8 @@ function send (output, data, encoding) {
*/
node.http.createServer = function (requestListener, options) {
var server = new node.http.LowLevelServer();
server.addListener("Connection", connectionListener);
server.addListener("Request", requestListener);
server.addListener("connection", connectionListener);
server.addListener("request", requestListener);
//server.setOptions(options);
return server;
};
@ -179,7 +179,7 @@ function connectionListener (connection) {
connection.responses = [];
// is this really needed?
connection.addListener("EOF", function () {
connection.addListener("eof", function () {
if (connection.responses.length == 0) {
connection.close();
} else {
@ -189,16 +189,16 @@ function connectionListener (connection) {
var req, res;
connection.addListener("MessageBegin", function () {
connection.addListener("message_begin", function () {
req = new node.http.createServerRequest(connection);
res = new node.http.ServerResponse(connection);
});
connection.addListener("URI", function (data) {
connection.addListener("uri", function (data) {
req.uri += data;
});
connection.addListener("HeaderField", function (data) {
connection.addListener("header_field", function (data) {
if (req.headers.length > 0 && req.last_was_value == false)
req.headers[req.headers.length-1][0] += data;
else
@ -206,7 +206,7 @@ function connectionListener (connection) {
req.last_was_value = false;
});
connection.addListener("HeaderValue", function (data) {
connection.addListener("header_value", function (data) {
var last_pair = req.headers[req.headers.length-1];
if (last_pair.length == 1)
last_pair[1] = data;
@ -215,22 +215,22 @@ function connectionListener (connection) {
req.last_was_value = true;
});
connection.addListener("HeadersComplete", function (info) {
connection.addListener("headers_complete", function (info) {
req.httpVersion = info.httpVersion;
req.method = info.method;
req.uri = node.http.parseUri(req.uri); // TODO parse the URI lazily?
res.should_keep_alive = info.should_keep_alive;
connection.server.emit("Request", [req, res]);
connection.server.emit("request", [req, res]);
});
connection.addListener("Body", function (chunk) {
req.emit("Body", [chunk]);
connection.addListener("body", function (chunk) {
req.emit("body", [chunk]);
});
connection.addListener("MessageComplete", function () {
req.emit("BodyComplete");
connection.addListener("message_complete", function () {
req.emit("complete");
});
};
@ -365,19 +365,19 @@ node.http.createClient = function (port, host) {
client.reconnect = function () { return client.connect(port, host) };
client.addListener("Connect", function () {
client.addListener("connect", function () {
//node.debug("HTTP CLIENT onConnect. readyState = " + client.readyState);
//node.debug("client.requests[0].uri = '" + client.requests[0].uri + "'");
client.flush(client.requests[0]);
});
client.addListener("EOF", function () {
client.addListener("eof", function () {
client.close();
});
client.addListener("Disconnect", function (had_error) {
client.addListener("disconnect", function (had_error) {
if (had_error) {
client.emit("Error");
client.emit("error");
return;
}
@ -391,12 +391,12 @@ node.http.createClient = function (port, host) {
var req, res;
client.addListener("MessageBegin", function () {
client.addListener("message_begin", function () {
req = client.requests.shift();
res = createClientResponse(client);
});
client.addListener("HeaderField", function (data) {
client.addListener("header_field", function (data) {
if (res.headers.length > 0 && res.last_was_value == false)
res.headers[res.headers.length-1][0] += data;
else
@ -404,7 +404,7 @@ node.http.createClient = function (port, host) {
res.last_was_value = false;
});
client.addListener("HeaderValue", function (data) {
client.addListener("header_value", function (data) {
var last_pair = res.headers[res.headers.length-1];
if (last_pair.length == 1) {
last_pair[1] = data;
@ -414,20 +414,20 @@ node.http.createClient = function (port, host) {
res.last_was_value = true;
});
client.addListener("HeadersComplete", function (info) {
client.addListener("headers_complete", function (info) {
res.statusCode = info.statusCode;
res.httpVersion = info.httpVersion;
req.emit("Response", [res]);
req.emit("response", [res]);
});
client.addListener("Body", function (chunk) {
res.emit("Body", [chunk]);
client.addListener("body", function (chunk) {
res.emit("body", [chunk]);
});
client.addListener("MessageComplete", function () {
client.addListener("message_complete", function () {
client.close();
res.emit("BodyComplete");
res.emit("complete");
});
return client;
@ -526,7 +526,7 @@ function createClientRequest (connection, method, uri, header_lines) {
req.finished = false;
req.finish = function (responseListener) {
req.addListener("Response", responseListener);
req.addListener("response", responseListener);
if (chunked_encoding)
send(req.output, "0\r\n\r\n"); // last chunk
@ -544,7 +544,7 @@ node.http.cat = function (url, encoding) {
var client = node.http.createClient(uri.port || 80, uri.host);
var req = client.get(uri.path || "/");
client.addListener("Error", function () {
client.addListener("error", function () {
promise.emitError();
});
@ -556,8 +556,8 @@ node.http.cat = function (url, encoding) {
return;
}
res.setBodyEncoding(encoding);
res.addListener("Body", function (chunk) { content += chunk; });
res.addListener("BodyComplete", function () {
res.addListener("body", function (chunk) { content += chunk; });
res.addListener("complete", function () {
promise.emitSuccess([content]);
});
});

14
src/net.cc

@ -448,7 +448,7 @@ Connection::OnReceive (const void *buf, size_t len)
argv[0] = Local<Value>::New(Null());
}
Emit("Receive", argc, argv);
Emit("receive", argc, argv);
}
void
@ -459,7 +459,7 @@ Connection::OnDisconnect ()
Handle<Value> argv[1];
argv[0] = socket_.errorno == 0 ? False() : True();
Emit("Disconnect", 1, argv);
Emit("disconnect", 1, argv);
}
#define DEFINE_SIMPLE_CALLBACK(name, type) \
@ -469,10 +469,10 @@ void name () \
Emit (type, 0, NULL); \
}
DEFINE_SIMPLE_CALLBACK(Connection::OnConnect, "Connect")
DEFINE_SIMPLE_CALLBACK(Connection::OnDrain, "Drain")
DEFINE_SIMPLE_CALLBACK(Connection::OnTimeout, "Timeout")
DEFINE_SIMPLE_CALLBACK(Connection::OnEOF, "EOF")
DEFINE_SIMPLE_CALLBACK(Connection::OnConnect, "connect")
DEFINE_SIMPLE_CALLBACK(Connection::OnDrain, "drain")
DEFINE_SIMPLE_CALLBACK(Connection::OnTimeout, "timeout")
DEFINE_SIMPLE_CALLBACK(Connection::OnEOF, "eof")
Persistent<FunctionTemplate> Server::constructor_template;
@ -576,7 +576,7 @@ Server::OnConnection (struct sockaddr *addr, socklen_t len)
Handle<Value> argv[1] = { js_connection };
Emit("Connection", 1, argv);
Emit("connection", 1, argv);
return connection;
}

6
src/node.js

@ -1,6 +1,6 @@
node.tcp.createServer = function (on_connection, options) {
var server = new node.tcp.Server();
server.addListener("Connection", on_connection);
server.addListener("connection", on_connection);
//server.setOptions(options);
return server;
};
@ -9,14 +9,14 @@ node.tcp.createServer = function (on_connection, options) {
function setTimeout (callback, after) {
var timer = new node.Timer();
timer.addListener("Timeout", callback);
timer.addListener("timeout", callback);
timer.start(after, 0);
return timer;
}
function setInterval (callback, repeat) {
var timer = new node.Timer();
timer.addListener("Timeout", callback);
timer.addListener("timeout", callback);
timer.start(repeat, repeat);
return timer;
}

4
src/process.cc

@ -357,7 +357,7 @@ Process::OnOutput (EV_P_ ev_io *watcher, int revents)
argv[0] = String::New((const char*)buf, r);
}
process->Emit(is_stdout ? "Output" : "Error", 1, argv);
process->Emit(is_stdout ? "output" : "error", 1, argv);
if (r == 0) {
ev_io_stop(EV_DEFAULT_UC_ watcher);
@ -480,7 +480,7 @@ Process::MaybeShutdown (void)
if (STDOUT_CLOSED && STDERR_CLOSED && got_chld_) {
HandleScope scope;
Handle<Value> argv[1] = { Integer::New(exit_code_) };
Emit("Exit", 1, argv);
Emit("exit", 1, argv);
Shutdown();
Detach();
}

2
src/timer.cc

@ -61,7 +61,7 @@ Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents)
assert(revents == EV_TIMEOUT);
timer->Emit("Timeout", 0, NULL);
timer->Emit("timeout", 0, NULL);
/* XXX i'm a bit worried if this is the correct test?
* it's rather crutial for memory leaks the conditional here test to see

2
test/mjsunit/test-file-open.js

@ -10,7 +10,7 @@ function onLoad () {
var x = node.path.join(fixtures, "x.txt");
file = new node.fs.File;
file.addListener("Error", function () { got_error = true });
file.addListener("error", function () { got_error = true });
file.open(x, "r").addCallback(function () {
opened = true

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

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

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

@ -18,10 +18,10 @@ 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.addListener("Body", function(chunk) {
proxy_res.addListener("body", function(chunk) {
res.sendBody(chunk);
});
proxy_res.addListener("BodyComplete", function() {
proxy_res.addListener("complete", function() {
res.finish();
// node.debug("proxy res");
});
@ -40,8 +40,8 @@ function onLoad () {
// node.debug("got res");
assertEquals(200, res.statusCode);
res.setBodyEncoding("utf8");
res.addListener("Body", function (chunk) { body += chunk; });
res.addListener("BodyComplete", function () {
res.addListener("body", function (chunk) { body += chunk; });
res.addListener("complete", function () {
proxy.close();
backend.close();
// node.debug("closed both");

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

@ -35,12 +35,12 @@ function onLoad() {
var c = new node.tcp.Connection();
c.setEncoding("utf8");
c.addListener("Connect", function () {
c.addListener("connect", function () {
c.send( "GET /hello HTTP/1.1\r\n\r\n" );
requests_sent += 1;
});
c.addListener("Receive", function (chunk) {
c.addListener("receive", function (chunk) {
server_response += chunk;
if (requests_sent == 1) {
@ -51,11 +51,11 @@ function onLoad() {
}
});
c.addListener("EOF", function () {
c.addListener("eof", function () {
client_got_eof = true;
});
c.addListener("Disconnect", function () {
c.addListener("disconnect", function () {
assertEquals(c.readyState, "closed");
});

6
test/mjsunit/test-http.js

@ -19,7 +19,7 @@ function onLoad () {
this.close();
}
req.addListener("BodyComplete", function () {
req.addListener("complete", function () {
res.sendHeader(200, [["Content-Type", "text/plain"]]);
res.sendBody("The path was " + req.uri.path);
res.finish();
@ -35,7 +35,7 @@ function onLoad () {
assertEquals(200, res.statusCode);
responses_recvd += 1;
res.setBodyEncoding("utf8");
res.addListener("Body", function (chunk) { body0 += chunk; });
res.addListener("body", function (chunk) { body0 += chunk; });
node.debug("Got /hello response");
});
@ -45,7 +45,7 @@ function onLoad () {
assertEquals(200, res.statusCode);
responses_recvd += 1;
res.setBodyEncoding("utf8");
res.addListener("Body", function (chunk) { body1 += chunk; });
res.addListener("body", function (chunk) { body1 += chunk; });
node.debug("Got /world response");
});
}, 1);

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

@ -5,10 +5,10 @@ var pwd_called = false;
function pwd (callback) {
var output = "";
var process = new node.Process("pwd");
process.addListener("Output", function (s) {
process.addListener("output", function (s) {
if (s) output += s;
});
process.addListener("Exit", 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.addListener("Output", function (chunk) { assertEquals(null, chunk); });
cat.addListener("Error", function (chunk) { assertEquals(null, chunk); });
cat.addListener("Exit", 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();
}

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

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

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

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

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

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

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

@ -19,7 +19,7 @@ function pingPongTest (port, host, on_complete) {
socket.setEncoding("utf8");
socket.timeout = 0;
socket.addListener("Receive", function (data) {
socket.addListener("receive", function (data) {
assertEquals("open", socket.readyState);
assertTrue(count <= N);
if (/PING/.exec(data)) {
@ -27,12 +27,12 @@ function pingPongTest (port, host, on_complete) {
}
});
socket.addListener("EOF", function () {
socket.addListener("eof", function () {
assertEquals("writeOnly", socket.readyState);
socket.close();
});
socket.addListener("Disconnect", function (had_error) {
socket.addListener("disconnect", function (had_error) {
assertFalse(had_error);
assertEquals("closed", socket.readyState);
socket.server.close();
@ -45,12 +45,12 @@ function pingPongTest (port, host, on_complete) {
client.setEncoding("utf8");
client.addListener("Connect", function () {
client.addListener("connect", function () {
assertEquals("open", client.readyState);
client.send("PING");
});
client.addListener("Receive", function (data) {
client.addListener("receive", function (data) {
assertEquals("PONG", data);
count += 1;
@ -70,7 +70,7 @@ function pingPongTest (port, host, on_complete) {
}
});
client.addListener("Disconnect", function () {
client.addListener("disconnect", function () {
assertEquals(N+1, count);
assertTrue(sent_final_ping);
if (on_complete) on_complete();

Loading…
Cancel
Save