From f5ca421554facaf72cb51fedbe5ce8e205a2df75 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 29 May 2014 21:46:04 -0400 Subject: [PATCH] Bug 1017946 - Kill usage of hasOwnProperty global. r=aleth --- chat/modules/imXPCOMUtils.jsm | 6 -- chat/protocols/twitter/twitter.js | 2 +- im/content/conversation.xml | 64 ++++++++----------- mail/components/im/content/imconversation.xml | 48 ++++++-------- 4 files changed, 45 insertions(+), 75 deletions(-) diff --git a/chat/modules/imXPCOMUtils.jsm b/chat/modules/imXPCOMUtils.jsm index ee53a6bf58..c9405114c9 100644 --- a/chat/modules/imXPCOMUtils.jsm +++ b/chat/modules/imXPCOMUtils.jsm @@ -7,7 +7,6 @@ const EXPORTED_SYMBOLS = [ "setTimeout", "clearTimeout", "executeSoon", - "hasOwnProperty", "nsSimpleEnumerator", "EmptyEnumerator", "ClassInfo", @@ -162,11 +161,6 @@ function executeSoon(aFunction) Services.tm.mainThread.dispatch(aFunction, Ci.nsIEventTarget.DISPATCH_NORMAL); } -// Similar to Object.hasOwnProperty, but doesn't fail if the object -// has a hasOwnProperty property set. -function hasOwnProperty(aObject, aPropertyName) - Object.prototype.hasOwnProperty.call(aObject, aPropertyName) - /* Common nsIClassInfo and QueryInterface implementation * shared by all generic objects implemented in this file. */ function ClassInfo(aInterfaces, aDescription = "JS Proto Object") diff --git a/chat/protocols/twitter/twitter.js b/chat/protocols/twitter/twitter.js index 2722835689..984e5d9caf 100644 --- a/chat/protocols/twitter/twitter.js +++ b/chat/protocols/twitter/twitter.js @@ -1040,7 +1040,7 @@ Account.prototype = { let tooltipInfo = []; for (let field in kFields) { - if (hasOwnProperty(userInfo, field) && userInfo[field]) { + if (userInfo.hasOwnProperty(field) && userInfo[field]) { let value = userInfo[field]; if (kFields[field]) value = kFields[field](value); diff --git a/im/content/conversation.xml b/im/content/conversation.xml index 4347807a80..fac1d4cb93 100644 --- a/im/content/conversation.xml +++ b/im/content/conversation.xml @@ -112,10 +112,10 @@ { if (chatBuddy.activeTimer) clearTimeout(chatBuddy.activeTimer); - } + }); } this._forgetConv(); @@ -218,8 +218,8 @@ if (!aMsg.system && conv.isChat) { let name = aMsg.who; - aMsg.color = this._hasBuddy(name) ? - this._activateBuddy(this.buddies[name], aMsg.time) : + aMsg.color = this.buddies.has(name) ? + this._activateBuddy(this.buddies.get(name), aMsg.time) : this._getColorStyle(this._computeColor(name)); } @@ -564,7 +564,7 @@ const suffix = ": "; if (pos > suffix.length && text.substring(pos - suffix.length, pos) == suffix) { - let completions = Object.keys(this.buddies); + let completions = [b for (b of this.buddies.keys())]; // Check if the preceding words are a sequence of nick completions. let preceding = text.substring(0, pos - suffix.length).split(", "); if (preceding.every(function(n) completions.indexOf(n) != -1)) { @@ -653,7 +653,7 @@ firstWordSuffix = ": "; - completions = Object.keys(this.buddies); + completions = [b for (b of this.buddies.keys())]; // Add recently parted nicks. const kIncludeNickTimespan = 300000; @@ -738,8 +738,8 @@ if (this._conv.isChat && !completingCommand) { // If there are active nicks, prefer those. let activeCompletions = this._completions.filter(function(c) - this._hasBuddy(c) && - !this.buddies[c].hasAttribute("inactive"), this); + this.buddies.has(c) && + !this.buddies.get(c).hasAttribute("inactive"), this); if (activeCompletions.length == 1) preferredNick = true; if (activeCompletions.length) { @@ -753,7 +753,7 @@ // If one of the completions is the sender of the last ping, // take it, if it was less than an hour ago. - if (this._lastPing && this._hasBuddy(this._lastPing) && + if (this._lastPing && this.buddies.has(this._lastPing) && this._completions.indexOf(this._lastPing) != -1 && (Date.now() / 1000 - this._lastPingTime) < 3600) { preferredNick = true; @@ -1068,7 +1068,7 @@ let secondNick = false; let pos = text.indexOf(":"); if (pos != -1) { - let completions = Object.keys(this.buddies); + let completions = [b for (b of this.buddies.keys())]; // Check if the preceding words are a sequence of nicks. let preceding = text.substring(0, pos).split(", "); if (preceding.every(function(n) completions.indexOf(n) != -1)) @@ -1199,17 +1199,6 @@ - - - - - - - - @@ -1255,7 +1244,7 @@ var name = aBuddy.name; if (!name) throw "The empty string isn't a valid nick."; - if (this._hasBuddy(name)) + if (this.buddies.has(name)) throw "Adding chat buddy " + name + " twice?!"; this.trackNick(name); @@ -1278,7 +1267,7 @@ delete this.partedBuddies[name]; } - this.buddies[name] = item; + this.buddies.set(name, item); if (aShouldAppendDirectly) { this.nicklistElt.appendChild(item); this._nicks.push(name.toLowerCase()); @@ -1293,7 +1282,7 @@ + capitalized list of nicks use [b for (b of this.buddies.keys())]. --> [] @@ -1340,25 +1329,25 @@ if (!aOldName) { // If aOldName is null, we are changing the flags of the buddy - var item = this.buddies[name]; + let item = this.buddies.get(name); item.chatBuddy = aBuddy; this.setBuddyAttributes(item); return; } // Is aOldName is not null, then we are renaming the buddy - if (!this._hasBuddy(aOldName)) + if (!this.buddies.has(aOldName)) throw "Updating a chat buddy that does not exist: " + aOldName; - if (this._hasBuddy(name)) + if (this.buddies.has(name)) throw "Updating a chat buddy to an already existing one: " + name; this.trackNick(name); - var item = this.buddies[aOldName]; + let item = this.buddies.get(aOldName); item.chatBuddy = aBuddy; - delete this.buddies[aOldName]; - this.buddies[name] = item; + this.buddies.delete(aOldName); + this.buddies.set(name, item); item.setAttribute("label", name); // Move this item to the right position if its name changed @@ -1373,9 +1362,9 @@ @@ -1408,9 +1397,8 @@ if (!("_showNickRegExp" in this)) { if (!("_showNickList" in this)) { this._showNickList = {}; - Object.keys(this.buddies).forEach(function(n) { + for (let n of this.buddies.keys()) this._showNickList[n.replace(this._nickEscape, "\\$&")] = true; - }, this); } // The reverse sort ensures that if we have "foo" and "foobar", @@ -1447,8 +1435,8 @@ let nick = nickNode.data; let elt = aNode.ownerDocument.createElement("span"); elt.setAttribute("class", "ib-nick"); - if (this._hasBuddy(nick)) { - let buddy = this.buddies[nick]; + if (this.buddies.has(nick)) { + let buddy = this.buddies.get(nick); if (!buddy.colorStyle) this._setBuddyColor(buddy); elt.setAttribute("style", buddy.colorStyle); @@ -1749,7 +1737,7 @@ this.getElt("participantCount").setAttribute("id", id); // Populate the nicklist - this.buddies = {}; + this.buddies = new Map(); this.partedBuddies = {}; this._nicks = []; this.nicklistElt = this.getElt("nicklist"); diff --git a/mail/components/im/content/imconversation.xml b/mail/components/im/content/imconversation.xml index 6fb5751c63..7ab3f3b19c 100644 --- a/mail/components/im/content/imconversation.xml +++ b/mail/components/im/content/imconversation.xml @@ -148,8 +148,8 @@ if (!aMsg.system && conv.isChat) { let name = aMsg.who; let color; - if (this._hasBuddy(name)) { - let buddy = this.buddies[name]; + if (this.buddies.has(name)) { + let buddy = this.buddies.get(name); color = buddy.color; buddy.removeAttribute("inactive"); this._activeBuddies[name] = true; @@ -457,7 +457,7 @@ else firstWordSuffix = ": "; - completions = Object.keys(this.buddies); + completions = [b for (b of this.buddies.keys())]; let outgoingNick = this._conv.nick; completions = completions.filter(function(c) c != outgoingNick); } @@ -477,8 +477,8 @@ // If only one of the possible completions is an active nick, take it. let activeNick = null; for each (let c in completions) { - if (this._hasBuddy(c) && - !this.buddies[c].hasAttribute("inactive")) { + if (this.buddies.has(c) && + !this.buddies.get(c).hasAttribute("inactive")) { if (!activeNick) activeNick = c; else { @@ -787,8 +787,7 @@ @@ -848,17 +847,6 @@ - - - - - - - - @@ -874,7 +862,7 @@ @@ -1136,7 +1124,7 @@ while (nicklist.hasChildNodes()) nicklist.lastChild.remove(); // Populate the nicklist - this.buddies = {}; + this.buddies = new Map(); let nicks = fixIterator(this.conv.getParticipants()); for (let n in nicks) this.addBuddy(n);