Skip to content

Commit

Permalink
Fix bugs caused by Map#set(k,v) returning undefined instead of v
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Westerlund committed Apr 24, 2013
1 parent ba505a9 commit a977269
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion lib/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ function channel(name) {
return cache.get(cid);
}
const chan = new Channel(name);
return cache.set(chan.id, chan);
cache.set(chan.id, chan);
return chan;
}

/** For joining channels
Expand Down
7 changes: 5 additions & 2 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,11 @@ function matchPred(pred, handler) {

function matchType(type, handler) {
const handlers = this.handlers;
const arr = handlers.has(type) ? handlers.get(type) :
handlers.set(type, []);
let arr = handlers.get(type);
if (!arr) {
arr = [];
handlers.set(type, arr);
}
arr.push(handler);
return this.ignore.bind(this, type, handler);
}
Expand Down
19 changes: 11 additions & 8 deletions lib/person.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Person.prototype.toString = function() {
+ this.user : "") + "@" + this.host : "")
}

property(Person.prototype, "id", function() { return id(this.nick) })
property(Person.prototype, "id", function() { return id(this.nick) });

/** Make a Person object
* @throws {Error} if no matching signature was found
Expand All @@ -55,13 +55,16 @@ property(Person.prototype, "id", function() { return id(this.nick) })
* @return {Person}
*/
function person(nick, user, host) {
if (arguments.length === 0 || arguments.length > 3)
throw new Error("No matching signature")
const pid = id(nick)
if (personCache.has(pid))
return personCache.get(pid)
const p = new Person(nick, user || null, host || null)
return personCache.set(p.id, p)
if (arguments.length === 0 || arguments.length > 3) {
throw new Error("No matching signature");
}
const pid = id(nick);
if (personCache.has(pid)) {
return personCache.get(pid);
}
const p = new Person(nick, user || null, host || null);
personCache.set(p.id, p);
return p;
}

/** Send a {@link Message} to a {@link Person}.
Expand Down
3 changes: 2 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ function server(name, port) {
return serverCache.get(sid);
}
const server = new Server(name, port ? port : DEFAULT_PORT);
return serverCache.set(server.id, server);
serverCache.set(server.id, server);
return server;
}

exports.Server = Server;
Expand Down

0 comments on commit a977269

Please sign in to comment.