Bug 654399. Try to make sure we always hand out the same exact string buffer each time location.hash is gotten. r=roc
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 20 May 2011 16:21:27 -0400
changeset 69833 f68807492b2b348f5c7945104c26a2bdbeb4b8cd
parent 69832 bd9646fd621c6450317a578d85d58ff5132884ff
child 69834 7dcb9b3fa354e2e32a809f1803e7249e300d8f51
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersroc
bugs654399
milestone6.0a1
Bug 654399. Try to make sure we always hand out the same exact string buffer each time location.hash is gotten. r=roc
dom/base/nsGlobalWindow.h
dom/base/nsLocation.cpp
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -1135,16 +1135,17 @@ protected:
   nsresult SetHrefWithContext(JSContext* cx, const nsAString& aHref,
                               PRBool aReplace);
 
   nsresult GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL);
   nsresult GetSourceDocument(JSContext* cx, nsIDocument** aDocument);
 
   nsresult CheckURL(nsIURI *url, nsIDocShellLoadInfo** aLoadInfo);
 
+  nsString mCachedHash;
   nsWeakPtr mDocShell;
 };
 
 /* factory function */
 nsresult
 NS_NewScriptGlobalObject(PRBool aIsChrome, PRBool aIsModalContentWindow,
                          nsIScriptGlobalObject **aResult);
 
--- a/dom/base/nsLocation.cpp
+++ b/dom/base/nsLocation.cpp
@@ -400,16 +400,25 @@ nsLocation::GetHash(nsAString& aHash)
         rv = NS_OK;
       }
     }
 
     if (NS_SUCCEEDED(rv) && !unicodeRef.IsEmpty()) {
       aHash.Assign(PRUnichar('#'));
       aHash.Append(unicodeRef);
     }
+
+    if (aHash == mCachedHash) {
+      // Work around ShareThis stupidly polling location.hash every
+      // 5ms all the time by handing out the same exact string buffer
+      // we handed out last time.
+      aHash = mCachedHash;
+    } else {
+      mCachedHash = aHash;
+    }
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsLocation::SetHash(const nsAString& aHash)
 {