[Bug 767966] [NEW] globalmenu extension pollutes main window javascript scope

Launchpad Bug Tracker 767966 at bugs.launchpad.net
Thu Apr 21 11:11:50 UTC 2011


You have been subscribed to a public bug:

Binary package hint: firefox

The globalmenu extension overlays browser.xul and loads firefoxMenu.js, adding a lot of new variables/functions to the shared scope, at least:
nsIObserverService !
uIGlobalMenuLoader
uIGlobalMenuService
observer !
Observer() !
onLoad() !
onUnload() !
PlacesMenuUnityImpl()
HistoryMenuUnityImpl()
(! marks names with high chance of conflicts)

This is a problem as the regular browser code, all other extensions overlaying the browser window and this extension share the same scope, i.e. the same namespace.
If other extensions happen to define the same scope-global names, then conflicts will occur. Whoever loads last wins. Hence there is a high probability of heisenbugs (depending on the other extensions a user installs).
I'm a volunteer addons.mozilla.org editor, performing required code reviews an extension, this would be a definite show-stopper bug to any public listing.

You can either "hide" your stuff within a function, use some "namespace" variable, or a mixture of both, e.g.:
if (!com) var com =  {};
if (!com.canonical) com.canonical =  {};
(function()  {
  // local/"hidden" stuff
  function load()   {
    removeEventListener("load", load, false);
    ...
  }
  addEventListener("load", load, false);

  // globally visible
  this.Unity = { // |this| is com.canonical
    PlacesMenuUnityImpl: ...
  };
}).call(com.canonical);

(in the xul overlay you would then change all references to
PlacesMenuUnityImpl to com.canonical.Unity.PlacesMenuUnityImpl)

Also see:
https://developer.mozilla.org/en/XUL_School/JavaScript_Object_Management

** Affects: globalmenu-extension
     Importance: High
         Status: Triaged

** Affects: firefox (Ubuntu)
     Importance: High
         Status: Triaged

** Affects: firefox (Ubuntu Natty)
     Importance: High
         Status: Triaged

** Affects: firefox (Ubuntu Oneiric)
     Importance: Medium
         Status: Triaged

-- 
globalmenu extension pollutes main window javascript scope
https://bugs.launchpad.net/bugs/767966
You received this bug notification because you are a member of Mozilla Bugs, which is subscribed to firefox in Ubuntu.




More information about the Ubuntu-mozillateam-bugs mailing list