Comment 0 for bug 767966

Revision history for this message
Nils Maier (testnutzer123) wrote :

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