Bug 1229195: explicitly link 'content' to the frame script global scope to prevent out-of-scope errors. r=Standard8
authorMike de Boer <mdeboer@mozilla.com>
Tue, 09 Feb 2016 15:16:22 +0100
changeset 329843 0c51994fbafe65be49c253ed58390f1ef4de691c
parent 329842 683c1c3ca8321e064f7bcd2f690557ef6562bffb
child 329844 dc2c6c1a4fe3ed7413ce361e1dcf2c556d1384b0
child 329888 38fc64906bbedfd8d69136b6df43b1c347f037c4
push id10617
push userdtownsend@mozilla.com
push dateTue, 09 Feb 2016 16:30:19 +0000
reviewersStandard8
bugs1229195
milestone47.0a1
Bug 1229195: explicitly link 'content' to the frame script global scope to prevent out-of-scope errors. r=Standard8
browser/base/content/social-content.js
--- a/browser/base/content/social-content.js
+++ b/browser/base/content/social-content.js
@@ -6,32 +6,37 @@
 /* This content script should work in any browser or iframe and should not
  * depend on the frame being contained in tabbrowser. */
 
 var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
+// Tie `content` to this frame scripts' global scope explicitly. If we don't, then
+// `content` might be out of eval's scope and GC'ed before this script is done.
+// See bug 1229195 for empirical proof.
+var gContent = content;
+
 // social frames are always treated as app tabs
 docShell.isAppTab = true;
 
 var gDOMContentLoaded = false;
 addEventListener("DOMContentLoaded", function() {
   gDOMContentLoaded = true;
   sendAsyncMessage("DOMContentLoaded");
 });
 var gDOMTitleChangedByUs = false;
 addEventListener("DOMTitleChanged", function(e) {
   if (!gDOMTitleChangedByUs) {
     sendAsyncMessage("DOMTitleChanged", {
       title: e.target.title
     });
-    gDOMTitleChangedByUs = false;
   }
+  gDOMTitleChangedByUs = false;
 });
 
 // Error handling class used to listen for network errors in the social frames
 // and replace them with a social-specific error page
 SocialErrorListener = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMEventListener,
                                          Ci.nsIWebProgressListener,
                                          Ci.nsISupportsWeakReference,