Skip to content

Commit

Permalink
Depreciate onLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Aug 26, 2009
1 parent 79f1210 commit 31265be
Show file tree
Hide file tree
Showing 26 changed files with 383 additions and 429 deletions.
8 changes: 7 additions & 1 deletion src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ node.Module.prototype.load = function (callback) {
self.onExit = self.target.__onExit;

self.waitChildrenLoad(function () {
if (self.onLoad) self.onLoad();
if (self.onLoad) {
node.stdio.writeError( "(node) onLoad is depreciated it will be "
+ "removed in the future. Don't want it to "
+ "leave? Discuss on mailing list.\n"
);
self.onLoad();
}
self.loaded = true;
loadPromise.emitSuccess([self.target]);
});
Expand Down
14 changes: 6 additions & 8 deletions test/mjsunit/test-encode-utf8.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
include("mjsunit.js");

function onLoad () {
var a = [116,101,115,116,32,206,163,207,131,207,128,206,177,32,226,161,140,226,160, 129,226,160,167,226,160,145];
var s = node.encodeUtf8(a);
assertEquals("test Σσπα ⡌⠁⠧⠑", s);
var a = [116,101,115,116,32,206,163,207,131,207,128,206,177,32,226,161,140,226,160, 129,226,160,167,226,160,145];
var s = node.encodeUtf8(a);
assertEquals("test Σσπα ⡌⠁⠧⠑", s);

a = [104, 101, 108, 108, 111];
s = node.encodeUtf8(a);
assertEquals("hello", s);
}
a = [104, 101, 108, 108, 111];
s = node.encodeUtf8(a);
assertEquals("hello", s);
32 changes: 15 additions & 17 deletions test/mjsunit/test-event-emitter-add-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ var e = new node.EventEmitter();
var events_new_listener_emited = [];
var times_hello_emited = 0;

function onLoad () {
e.addListener("newListener", function (event, listener) {
puts("newListener: " + event);
events_new_listener_emited.push(event);
});

e.addListener("hello", function (a, b) {
puts("hello");
times_hello_emited += 1
assertEquals("a", a);
assertEquals("b", b);
});

puts("start");

e.emit("hello", ["a", "b"]);
}
e.addListener("newListener", function (event, listener) {
puts("newListener: " + event);
events_new_listener_emited.push(event);
});

e.addListener("hello", function (a, b) {
puts("hello");
times_hello_emited += 1
assertEquals("a", a);
assertEquals("b", b);
});

puts("start");

e.emit("hello", ["a", "b"]);

function onExit () {
assertArrayEquals(["hello"], events_new_listener_emited);
Expand Down
28 changes: 13 additions & 15 deletions test/mjsunit/test-file-cat-noexist.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
include("mjsunit.js");
var got_error = false;

function onLoad () {
var dirname = node.path.dirname(__filename);
var fixtures = node.path.join(dirname, "fixtures");
var filename = node.path.join(fixtures, "does_not_exist.txt");
var promise = node.fs.cat(filename, "raw");

promise.addCallback(function (content) {
node.debug("cat returned some content: " + content);
node.debug("this shouldn't happen as the file doesn't exist...");
assertTrue(false);
});
var dirname = node.path.dirname(__filename);
var fixtures = node.path.join(dirname, "fixtures");
var filename = node.path.join(fixtures, "does_not_exist.txt");
var promise = node.fs.cat(filename, "raw");

promise.addErrback(function () {
got_error = true;
});
}
promise.addCallback(function (content) {
node.debug("cat returned some content: " + content);
node.debug("this shouldn't happen as the file doesn't exist...");
assertTrue(false);
});

promise.addErrback(function () {
got_error = true;
});

function onExit () {
assertTrue(got_error);
Expand Down
24 changes: 11 additions & 13 deletions test/mjsunit/test-http-cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ server.listen(PORT);
var got_good_server_content = false;
var bad_server_got_error = false;

function onLoad () {
node.http.cat("http://localhost:"+PORT+"/", "utf8").addCallback(function (content) {
puts("got response");
got_good_server_content = true;
assertEquals(body, content);
server.close();
});

node.http.cat("http://localhost:12312/", "utf8").addErrback(function () {
puts("got error (this should happen)");
bad_server_got_error = true;
});
}
node.http.cat("http://localhost:"+PORT+"/", "utf8").addCallback(function (content) {
puts("got response");
got_good_server_content = true;
assertEquals(body, content);
server.close();
});

node.http.cat("http://localhost:12312/", "utf8").addErrback(function () {
puts("got error (this should happen)");
bad_server_got_error = true;
});

function onExit () {
assertTrue(got_good_server_content);
Expand Down
36 changes: 17 additions & 19 deletions test/mjsunit/test-http-client-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,24 @@ var server = node.http.createServer(function(req, res) {
});
server.listen(PORT);

function onLoad () {
var client = node.http.createClient(PORT);
var req = client.post('/');

req.sendBody('1\n');
req.sendBody('2\n');
req.sendBody('3\n');

puts("client finished sending request");
req.finish(function(res) {
res.setBodyEncoding("utf8");
res.addListener('body', function(chunk) {
puts(chunk);
});
res.addListener('complete', function() {
client_res_complete = true;
server.close();
});
var client = node.http.createClient(PORT);
var req = client.post('/');

req.sendBody('1\n');
req.sendBody('2\n');
req.sendBody('3\n');

puts("client finished sending request");
req.finish(function(res) {
res.setBodyEncoding("utf8");
res.addListener('body', function(chunk) {
puts(chunk);
});
}
res.addListener('complete', function() {
client_res_complete = true;
server.close();
});
});

function onExit () {
assertEquals("1\n2\n3\n", sent_body);
Expand Down
28 changes: 13 additions & 15 deletions test/mjsunit/test-http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,20 @@ proxy.listen(PROXY_PORT);

var body = "";

function onLoad () {
var client = node.http.createClient(PROXY_PORT);
var req = client.get("/test");
// node.debug("client req")
req.finish(function (res) {
// node.debug("got res");
assertEquals(200, res.statusCode);
res.setBodyEncoding("utf8");
res.addListener("body", function (chunk) { body += chunk; });
res.addListener("complete", function () {
proxy.close();
backend.close();
// node.debug("closed both");
});
var client = node.http.createClient(PROXY_PORT);
var req = client.get("/test");
// node.debug("client req")
req.finish(function (res) {
// node.debug("got res");
assertEquals(200, res.statusCode);
res.setBodyEncoding("utf8");
res.addListener("body", function (chunk) { body += chunk; });
res.addListener("complete", function () {
proxy.close();
backend.close();
// node.debug("closed both");
});
}
});

function onExit () {
assertEquals(body, "hello world\n");
Expand Down
101 changes: 49 additions & 52 deletions test/mjsunit/test-http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,57 @@ var requests_sent = 0;
var server_response = "";
var client_got_eof = false;

function onLoad() {

node.http.createServer(function (req, res) {
res.id = request_number;
req.id = request_number++;

if (req.id == 0) {
assertEquals("GET", req.method);
assertEquals("/hello", req.uri.path);
}

if (req.id == 1) {
assertEquals("POST", req.method);
assertEquals("/quit", req.uri.path);
this.close();
//puts("server closed");
}

setTimeout(function () {
res.sendHeader(200, {"Content-Type": "text/plain"});
res.sendBody(req.uri.path);
res.finish();
}, 1);

}).listen(port);

var c = node.tcp.createConnection(port);
node.http.createServer(function (req, res) {
res.id = request_number;
req.id = request_number++;

if (req.id == 0) {
assertEquals("GET", req.method);
assertEquals("/hello", req.uri.path);
}

if (req.id == 1) {
assertEquals("POST", req.method);
assertEquals("/quit", req.uri.path);
this.close();
//puts("server closed");
}

setTimeout(function () {
res.sendHeader(200, {"Content-Type": "text/plain"});
res.sendBody(req.uri.path);
res.finish();
}, 1);

}).listen(port);

var c = node.tcp.createConnection(port);

c.setEncoding("utf8");

c.addListener("connect", function () {
c.send( "GET /hello HTTP/1.1\r\n\r\n" );
requests_sent += 1;
});

c.addListener("receive", function (chunk) {
server_response += chunk;

if (requests_sent == 1) {
c.send("POST /quit HTTP/1.1\r\n\r\n");
c.close();
assertEquals(c.readyState, "readOnly");
requests_sent += 1;
}
});

c.setEncoding("utf8");
c.addListener("eof", function () {
client_got_eof = true;
});

c.addListener("connect", function () {
c.send( "GET /hello HTTP/1.1\r\n\r\n" );
requests_sent += 1;
});

c.addListener("receive", function (chunk) {
server_response += chunk;

if (requests_sent == 1) {
c.send("POST /quit HTTP/1.1\r\n\r\n");
c.close();
assertEquals(c.readyState, "readOnly");
requests_sent += 1;
}
});

c.addListener("eof", function () {
client_got_eof = true;
});

c.addListener("close", function () {
assertEquals(c.readyState, "closed");
});
}
c.addListener("close", function () {
assertEquals(c.readyState, "closed");
});

function onExit () {
assertEquals(2, request_number);
Expand Down
Loading

0 comments on commit 31265be

Please sign in to comment.