Bug 693469 - Implement mozilla::ArrayLength and mozilla::ArrayEnd, and replace uses of NS_ARRAY_LENGTH whenever possible. (Exceptions: assigning to static initializers, use in static assertions, as template parameters, etc. These will go away when the relevant compilers have C++11 constexpr support.) r=cjones
authorJeff Walden <jwalden@mit.edu>
Mon, 10 Oct 2011 22:50:08 -0700
changeset 78817 b9b9d9f379db
parent 78816 38f53f45bbf4
child 78818 88b9a330ff8c
push id2697
push userjwalden@mit.edu
push date2011-10-16 01:24 +0000
treeherdermozilla-inbound@6ef8c395b2df [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs693469
milestone10.0a1
Bug 693469 - Implement mozilla::ArrayLength and mozilla::ArrayEnd, and replace uses of NS_ARRAY_LENGTH whenever possible. (Exceptions: assigning to static initializers, use in static assertions, as template parameters, etc. These will go away when the relevant compilers have C++11 constexpr support.) r=cjones
accessible/src/atk/nsAccessibleWrap.cpp
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsDocAccessible.cpp
accessible/src/base/nsRootAccessible.cpp
browser/components/migration/src/nsIEProfileMigrator.cpp
browser/components/migration/src/nsOperaProfileMigrator.cpp
browser/components/shell/src/nsGNOMEShellService.cpp
caps/src/nsNullPrincipal.cpp
caps/src/nsScriptSecurityManager.cpp
content/base/src/nsContentUtils.cpp
content/base/src/nsDocument.cpp
content/base/src/nsEventSource.cpp
content/base/src/nsGenericElement.cpp
content/base/src/nsGkAtoms.cpp
content/base/src/nsNodeInfo.cpp
content/base/src/nsTreeSanitizer.cpp
content/base/src/nsWebSocket.cpp
content/base/src/nsXMLHttpRequest.cpp
content/events/src/nsDOMDataTransfer.cpp
content/events/src/nsDOMEvent.cpp
content/html/content/src/nsFormSubmission.cpp
content/html/content/src/nsGenericHTMLElement.cpp
content/html/content/src/nsHTMLBRElement.cpp
content/html/content/src/nsHTMLBodyElement.cpp
content/html/content/src/nsHTMLDivElement.cpp
content/html/content/src/nsHTMLFontElement.cpp
content/html/content/src/nsHTMLFrameElement.cpp
content/html/content/src/nsHTMLHRElement.cpp
content/html/content/src/nsHTMLHeadingElement.cpp
content/html/content/src/nsHTMLIFrameElement.cpp
content/html/content/src/nsHTMLImageElement.cpp
content/html/content/src/nsHTMLInputElement.cpp
content/html/content/src/nsHTMLLIElement.cpp
content/html/content/src/nsHTMLMediaElement.cpp
content/html/content/src/nsHTMLOListElement.cpp
content/html/content/src/nsHTMLObjectElement.cpp
content/html/content/src/nsHTMLParagraphElement.cpp
content/html/content/src/nsHTMLPreElement.cpp
content/html/content/src/nsHTMLSelectElement.cpp
content/html/content/src/nsHTMLSharedElement.cpp
content/html/content/src/nsHTMLSharedObjectElement.cpp
content/html/content/src/nsHTMLTableCaptionElement.cpp
content/html/content/src/nsHTMLTableCellElement.cpp
content/html/content/src/nsHTMLTableColElement.cpp
content/html/content/src/nsHTMLTableElement.cpp
content/html/content/src/nsHTMLTableRowElement.cpp
content/html/content/src/nsHTMLTableSectionElement.cpp
content/html/content/src/nsHTMLTextAreaElement.cpp
content/html/content/src/nsHTMLVideoElement.cpp
content/html/document/src/nsHTMLContentSink.cpp
content/html/document/src/nsHTMLDocument.cpp
content/mathml/content/src/nsMathMLElement.cpp
content/svg/content/src/DOMSVGPathSeg.cpp
content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp
content/svg/content/src/SVGLength.cpp
content/svg/content/src/SVGNumberList.cpp
content/svg/content/src/SVGPointList.cpp
content/svg/content/src/SVGTransformListParser.cpp
content/svg/content/src/nsSVGAElement.cpp
content/svg/content/src/nsSVGAltGlyphElement.cpp
content/svg/content/src/nsSVGAngle.cpp
content/svg/content/src/nsSVGCircleElement.cpp
content/svg/content/src/nsSVGClipPathElement.cpp
content/svg/content/src/nsSVGDefsElement.cpp
content/svg/content/src/nsSVGElement.cpp
content/svg/content/src/nsSVGEllipseElement.cpp
content/svg/content/src/nsSVGFilterElement.cpp
content/svg/content/src/nsSVGFilters.cpp
content/svg/content/src/nsSVGForeignObjectElement.cpp
content/svg/content/src/nsSVGGElement.cpp
content/svg/content/src/nsSVGGradientElement.cpp
content/svg/content/src/nsSVGGraphicElement.cpp
content/svg/content/src/nsSVGImageElement.cpp
content/svg/content/src/nsSVGLength2.cpp
content/svg/content/src/nsSVGLineElement.cpp
content/svg/content/src/nsSVGMarkerElement.cpp
content/svg/content/src/nsSVGMaskElement.cpp
content/svg/content/src/nsSVGMpathElement.cpp
content/svg/content/src/nsSVGPathElement.cpp
content/svg/content/src/nsSVGPatternElement.cpp
content/svg/content/src/nsSVGPolyElement.cpp
content/svg/content/src/nsSVGRectElement.cpp
content/svg/content/src/nsSVGSVGElement.cpp
content/svg/content/src/nsSVGScriptElement.cpp
content/svg/content/src/nsSVGStopElement.cpp
content/svg/content/src/nsSVGSwitchElement.cpp
content/svg/content/src/nsSVGSymbolElement.cpp
content/svg/content/src/nsSVGTSpanElement.cpp
content/svg/content/src/nsSVGTextElement.cpp
content/svg/content/src/nsSVGTextPathElement.cpp
content/svg/content/src/nsSVGTextPositioningElement.cpp
content/svg/content/src/nsSVGUseElement.cpp
content/xbl/src/nsXBLContentSink.cpp
content/xbl/src/nsXBLPrototypeBinding.cpp
content/xbl/src/nsXBLPrototypeHandler.cpp
content/xbl/src/nsXBLService.cpp
content/xslt/src/xpath/txCoreFunctionCall.cpp
content/xslt/src/xslt/txEXSLTFunctions.cpp
content/xslt/src/xslt/txStylesheetCompileHandlers.cpp
content/xslt/src/xslt/txStylesheetCompiler.cpp
content/xul/document/src/nsXULDocument.cpp
content/xul/templates/src/nsRuleNetwork.cpp
content/xul/templates/src/nsXULContentBuilder.cpp
content/xul/templates/src/nsXULContentUtils.cpp
docshell/base/nsDocShell.cpp
dom/base/nsDOMClassInfo.cpp
dom/base/nsGlobalWindow.cpp
dom/plugins/base/nsNPAPIPlugin.cpp
dom/plugins/base/nsPluginsDirWin.cpp
dom/plugins/ipc/PluginInstanceChild.cpp
dom/plugins/ipc/PluginInstanceParent.cpp
dom/plugins/ipc/PluginModuleChild.cpp
dom/system/unix/nsDeviceMotionSystem.cpp
dom/workers/RuntimeService.cpp
editor/libeditor/html/nsEditProperty.cpp
editor/libeditor/html/nsHTMLDataTransfer.cpp
editor/libeditor/html/nsHTMLEditUtils.cpp
editor/libeditor/text/nsPlaintextDataTransfer.cpp
editor/txtsvc/src/nsTextServicesDocument.cpp
embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
extensions/auth/nsAuthGSSAPI.cpp
extensions/permissions/nsContentBlocker.cpp
gfx/layers/d3d10/ThebesLayerD3D10.cpp
gfx/layers/d3d9/ThebesLayerD3D9.cpp
gfx/layers/opengl/LayerManagerOGL.cpp
gfx/layers/opengl/ThebesLayerOGL.cpp
gfx/src/nsColor.cpp
gfx/tests/TestColorNames.cpp
gfx/tests/gfxTextRunPerfTest.cpp
gfx/thebes/GLContextProviderEGL.cpp
gfx/thebes/gfxAtoms.cpp
gfx/thebes/gfxCoreTextShaper.cpp
gfx/thebes/gfxDWriteFontList.cpp
gfx/thebes/gfxFT2FontList.cpp
gfx/thebes/gfxFontUtils.cpp
gfx/thebes/gfxFontconfigUtils.cpp
gfx/thebes/gfxGDIFontList.cpp
gfx/thebes/gfxPangoFonts.cpp
gfx/thebes/gfxWindowsPlatform.cpp
intl/locale/src/nsCharsetAliasImp.cpp
intl/locale/src/os2/nsOS2Charset.cpp
intl/locale/src/unix/nsUNIXCharset.cpp
intl/locale/src/windows/nsWin32Locale.cpp
intl/locale/src/windows/nsWinCharset.cpp
ipc/glue/IPCMessageUtils.h
ipc/testshell/TestShellParent.cpp
js/xpconnect/src/XPCConvert.cpp
js/xpconnect/src/dombindings.cpp
js/xpconnect/wrappers/AccessCheck.cpp
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsPresShell.cpp
layout/base/nsRefreshDriver.cpp
layout/generic/TextOverflow.cpp
layout/generic/nsFrame.cpp
layout/generic/nsImageFrame.cpp
layout/generic/nsTextFrameThebes.cpp
layout/inspector/src/inDOMView.cpp
layout/style/Declaration.cpp
layout/style/Loader.cpp
layout/style/nsCSSAnonBoxes.cpp
layout/style/nsCSSParser.cpp
layout/style/nsCSSPropertySet.h
layout/style/nsCSSProps.cpp
layout/style/nsCSSPseudoClasses.cpp
layout/style/nsCSSPseudoElements.cpp
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsCSSScanner.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsMediaFeatures.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleAnimation.cpp
layout/style/nsStyleSet.cpp
layout/style/nsStyleUtil.cpp
mfbt/Util.h
modules/libpr0n/decoders/icon/nsIconURI.cpp
modules/libpr0n/decoders/icon/win/nsIconChannel.cpp
modules/libpref/src/Preferences.cpp
netwerk/base/src/nsProtocolProxyService.cpp
netwerk/cache/nsCacheService.cpp
netwerk/cache/nsDiskCacheDeviceSQL.cpp
netwerk/dns/nsEffectiveTLDService.cpp
netwerk/streamconv/converters/nsDirIndexParser.cpp
parser/html/nsHtml5Atoms.cpp
parser/htmlparser/src/CNavDTD.cpp
parser/htmlparser/src/nsDTDUtils.h
parser/htmlparser/src/nsHTMLEntities.cpp
parser/htmlparser/src/nsHTMLTags.cpp
rdf/base/src/nsRDFContentSink.cpp
security/manager/ssl/src/nsNSSIOLayer.cpp
storage/src/SQLCollations.cpp
storage/src/mozStorageSQLFunctions.cpp
storage/test/storage_test_harness_tail.h
storage/test/test_asyncStatementExecution_transaction.cpp
storage/test/test_binding_params.cpp
storage/test/test_deadlock_detector.cpp
storage/test/test_mutex.cpp
toolkit/components/downloads/nsDownloadManager.cpp
toolkit/components/places/nsAnnotationService.cpp
toolkit/components/places/nsFaviconService.cpp
toolkit/components/places/nsNavBookmarks.cpp
toolkit/components/places/nsNavHistory.cpp
toolkit/components/places/tests/cpp/places_test_harness_tail.h
toolkit/components/remote/nsXRemoteService.cpp
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/profile/nsToolkitProfileService.cpp
toolkit/system/gnome/nsGSettingsService.cpp
toolkit/xre/MacLaunchHelper.mm
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsEmbedFunctions.cpp
uriloader/exthandler/nsExternalHelperAppService.cpp
widget/src/cocoa/GfxInfo.mm
widget/src/cocoa/TextInputHandler.mm
widget/src/cocoa/nsChildView.mm
widget/src/cocoa/nsPrintDialogX.mm
widget/src/gtk2/nsClipboard.cpp
widget/src/gtk2/nsFilePicker.cpp
widget/src/gtk2/nsGtkKeyUtils.cpp
widget/src/gtk2/nsNativeKeyBindings.cpp
widget/src/gtk2/nsPaperPS.cpp
widget/src/gtk2/nsPrintDialogGTK.cpp
widget/src/gtk2/nsWindow.cpp
widget/src/qt/nsClipboard.cpp
widget/src/qt/nsQtKeyUtils.cpp
widget/src/qt/nsWindow.cpp
widget/src/windows/GfxInfo.cpp
widget/src/windows/KeyboardLayout.cpp
widget/src/windows/TaskbarWindowPreview.cpp
widget/src/windows/nsDataObj.cpp
widget/src/windows/nsDeviceContextSpecWin.cpp
widget/src/windows/nsUXThemeData.cpp
widget/src/windows/nsWindow.cpp
widget/src/xpwidgets/GfxInfoBase.cpp
widget/src/xpwidgets/nsBaseWidget.cpp
widget/src/xpwidgets/nsClipboardPrivacyHandler.cpp
widget/src/xpwidgets/nsXPLookAndFeel.cpp
xpcom/base/MapsMemoryReporter.cpp
xpcom/base/nsCycleCollector.cpp
xpcom/base/nsStackWalk.cpp
xpcom/base/nsSystemInfo.cpp
xpcom/components/ManifestParser.cpp
xpcom/io/nsDirectoryService.cpp
xpcom/io/nsLocalFileUnix.cpp
xpcom/io/nsLocalFileWin.cpp
xpcom/tests/MoreTestingAtoms.cpp
xpcom/tests/TestAtoms.cpp
xpcom/tests/TestDeadlockDetector.cpp
xpcom/tests/TestHarness.h
xpcom/tests/TestObserverArray.cpp
xpcom/tests/TestTArray.cpp
xpcom/tests/TestUTF.cpp
xpcom/tests/TestingAtoms.cpp
xpcom/threads/nsProcessCommon.cpp
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -33,16 +33,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsAccessible.h"
 #include "nsAccessibleWrap.h"
 
 #include "nsAccUtils.h"
 #include "nsApplicationAccessibleWrap.h"
 #include "nsIAccessibleRelation.h"
 #include "nsRootAccessible.h"
 #include "nsDocAccessibleWrap.h"
@@ -64,16 +66,17 @@
 #include "nsMaiInterfaceHypertext.h"
 #include "nsMaiInterfaceHyperlinkImpl.h"
 #include "nsMaiInterfaceTable.h"
 #include "nsXPCOMStrings.h"
 #include "nsComponentManagerUtils.h"
 #include "nsMaiInterfaceDocument.h"
 #include "nsMaiInterfaceImage.h"
 
+using namespace mozilla;
 using namespace mozilla::a11y;
 
 nsAccessibleWrap::EAvailableAtkSignals nsAccessibleWrap::gAvailableAtkSignals =
   eUnknown;
 
 //defined in nsApplicationAccessibleWrap.cpp
 extern "C" GType g_atk_hyperlink_impl_type;
 
@@ -517,17 +520,17 @@ GetMaiAtkType(PRUint16 interfacesBits)
     static PRUint16 typeRegCount = 0;
     if (typeRegCount++ >= 4095) {
         return G_TYPE_INVALID;
     }
     type = g_type_register_static(MAI_TYPE_ATK_OBJECT,
                                   atkTypeName,
                                   &tinfo, GTypeFlags(0));
 
-    for (PRUint32 index = 0; index < NS_ARRAY_LENGTH(atk_if_infos); index++) {
+    for (PRUint32 index = 0; index < ArrayLength(atk_if_infos); index++) {
       if (interfacesBits & (1 << index)) {
         g_type_add_interface_static(type,
                                     GetAtkTypeForMai((MaiInterfaceType)index),
                                     &atk_if_infos[index]);
       }
     }
 
     return type;
@@ -958,17 +961,17 @@ refRelationSetCB(AtkObject *aAtkObj)
     nsIAccessibleRelation::RELATION_CONTROLLER_FOR,
     nsIAccessibleRelation::RELATION_EMBEDS,
     nsIAccessibleRelation::RELATION_FLOWS_TO,
     nsIAccessibleRelation::RELATION_FLOWS_FROM,
     nsIAccessibleRelation::RELATION_DESCRIBED_BY,
     nsIAccessibleRelation::RELATION_DESCRIPTION_FOR,
   };
 
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(relationTypes); i++) {
+  for (PRUint32 i = 0; i < ArrayLength(relationTypes); i++) {
     AtkRelationType atkType = static_cast<AtkRelationType>(relationTypes[i]);
     AtkRelation* atkRelation =
       atk_relation_set_get_relation_by_type(relation_set, atkType);
     if (atkRelation)
       atk_relation_set_remove(relation_set, atkRelation);
 
     Relation rel(accWrap->RelationByType(relationTypes[i]));
     nsTArray<AtkObject*> targets;
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 // NOTE: alphabetically ordered
 #include "nsAccessibilityService.h"
 #include "nsCoreUtils.h"
 #include "nsAccUtils.h"
 #include "nsApplicationAccessibleWrap.h"
 #include "nsARIAGridAccessibleWrap.h"
 #include "nsARIAMap.h"
 #include "FocusManager.h"
@@ -106,16 +108,17 @@
 #ifndef DISABLE_XFORMS_HOOKS
 #include "nsXFormsFormControlsAccessible.h"
 #include "nsXFormsWidgetsAccessible.h"
 #endif
 
 #include "mozilla/FunctionTimer.h"
 #include "mozilla/dom/Element.h"
 
+using namespace mozilla;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessibilityService
 ////////////////////////////////////////////////////////////////////////////////
 
 nsAccessibilityService *nsAccessibilityService::gAccessibilityService = nsnull;
 bool nsAccessibilityService::gIsShutdown = true;
@@ -649,17 +652,17 @@ nsAccessibilityService::GetAccessibleFor
 
   NS_IF_ADDREF(*aAccessible = GetAccessible(node));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessibilityService::GetStringRole(PRUint32 aRole, nsAString& aString)
 {
-  if ( aRole >= NS_ARRAY_LENGTH(kRoleNames)) {
+  if ( aRole >= ArrayLength(kRoleNames)) {
     aString.AssignLiteral("unknown");
     return NS_OK;
   }
 
   CopyUTF8toUTF16(kRoleNames[aRole], aString);
   return NS_OK;
 }
 
@@ -780,34 +783,34 @@ nsAccessibilityService::GetStringStates(
   return NS_OK;
 }
 
 // nsIAccessibleRetrieval::getStringEventType()
 NS_IMETHODIMP
 nsAccessibilityService::GetStringEventType(PRUint32 aEventType,
                                            nsAString& aString)
 {
-  NS_ASSERTION(nsIAccessibleEvent::EVENT_LAST_ENTRY == NS_ARRAY_LENGTH(kEventTypeNames),
+  NS_ASSERTION(nsIAccessibleEvent::EVENT_LAST_ENTRY == ArrayLength(kEventTypeNames),
                "nsIAccessibleEvent constants are out of sync to kEventTypeNames");
 
-  if (aEventType >= NS_ARRAY_LENGTH(kEventTypeNames)) {
+  if (aEventType >= ArrayLength(kEventTypeNames)) {
     aString.AssignLiteral("unknown");
     return NS_OK;
   }
 
   CopyUTF8toUTF16(kEventTypeNames[aEventType], aString);
   return NS_OK;
 }
 
 // nsIAccessibleRetrieval::getStringRelationType()
 NS_IMETHODIMP
 nsAccessibilityService::GetStringRelationType(PRUint32 aRelationType,
                                               nsAString& aString)
 {
-  if (aRelationType >= NS_ARRAY_LENGTH(kRelationTypeNames)) {
+  if (aRelationType >= ArrayLength(kRelationTypeNames)) {
     aString.AssignLiteral("unknown");
     return NS_OK;
   }
 
   CopyUTF8toUTF16(kRelationTypeNames[aRelationType], aString);
   return NS_OK;
 }
 
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -72,17 +72,17 @@
 #include "nsIURI.h"
 #include "nsIWebNavigation.h"
 #include "nsFocusManager.h"
 #include "mozilla/dom/Element.h"
 #ifdef MOZ_XUL
 #include "nsIXULDocument.h"
 #endif
 
-namespace dom = mozilla::dom;
+using namespace mozilla;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // Static member initialization
 
 static nsIAtom** kRelationAttrs[] =
 {
   &nsGkAtoms::aria_labelledby,
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -30,16 +30,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #define CreateEvent CreateEventA
 #include "nsIDOMDocument.h"
 
 #include "nsAccessibilityService.h"
 #include "nsApplicationAccessibleWrap.h"
 #include "nsAccUtils.h"
 #include "nsCoreUtils.h"
 #include "Relation.h"
@@ -78,17 +80,17 @@
 #include "nsFocusManager.h"
 
 #ifdef MOZ_XUL
 #include "nsXULTreeAccessible.h"
 #include "nsIXULDocument.h"
 #include "nsIXULWindow.h"
 #endif
 
-namespace dom = mozilla::dom;
+using namespace mozilla;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsISupports
 
 // Expanded version of NS_IMPL_ISUPPORTS_INHERITED2 
 // so we can QI directly to concrete nsRootAccessible
 NS_IMPL_QUERY_HEAD(nsRootAccessible)
@@ -250,17 +252,17 @@ nsresult nsRootAccessible::AddEventListe
   // nsIDOMEventTarget interface allows to register event listeners to
   // receive untrusted events (synthetic events generated by untrusted code).
   // For example, XBL bindings implementations for elements that are hosted in
   // non chrome document fire untrusted events.
   nsCOMPtr<nsIDOMEventTarget> nstarget(do_QueryInterface(mDocument));
 
   if (nstarget) {
     for (const char* const* e = docEvents,
-                   * const* e_end = docEvents + NS_ARRAY_LENGTH(docEvents);
+                   * const* e_end = ArrayEnd(docEvents);
          e < e_end; ++e) {
       nsresult rv = nstarget->AddEventListener(NS_ConvertASCIItoUTF16(*e),
                                                this, PR_TRUE, PR_TRUE, 2);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   if (!mCaretAccessible) {
@@ -270,17 +272,17 @@ nsresult nsRootAccessible::AddEventListe
   return nsDocAccessible::AddEventListeners();
 }
 
 nsresult nsRootAccessible::RemoveEventListeners()
 {
   nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mDocument));
   if (target) { 
     for (const char* const* e = docEvents,
-                   * const* e_end = docEvents + NS_ARRAY_LENGTH(docEvents);
+                   * const* e_end = ArrayEnd(docEvents);
          e < e_end; ++e) {
       nsresult rv = target->RemoveEventListener(NS_ConvertASCIItoUTF16(*e), this, PR_TRUE);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   // Do this before removing clearing caret accessible, so that it can use
   // shutdown the caret accessible's selection listener
--- a/browser/components/migration/src/nsIEProfileMigrator.cpp
+++ b/browser/components/migration/src/nsIEProfileMigrator.cpp
@@ -34,16 +34,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include <stdio.h>
 #include <string.h>
 #include <windows.h>
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsBrowserProfileMigratorUtils.h"
 #include "nsCOMPtr.h"
 #include "nsCRTGlue.h"
 #include "nsNetCID.h"
@@ -104,16 +106,18 @@
   NS_LITERAL_STRING("Software\\Microsoft\\Internet Explorer\\Main")
 #define REGISTRY_IE_TYPEDURL_KEY \
   NS_LITERAL_STRING("Software\\Microsoft\\Internet Explorer\\TypedURLs")
 #define REGISTRY_IE_TOOLBAR_KEY \
   NS_LITERAL_STRING("Software\\Microsoft\\Internet Explorer\\Toolbar")
 #define REGISTRY_IE_SEARCHURL_KEY \
   NS_LITERAL_STRING("Software\\Microsoft\\Internet Explorer\\SearchUrl")
 
+using namespace mozilla;
+
 const int sInitialCookieBufferSize = 1024; // but it can grow
 const int sUsernameLengthLimit     = 80;
 const int sHostnameLengthLimit     = 255;
 
 //***********************************************************************
 //*** Replacements for comsupp.lib calls used by pstorec.dll
 //***********************************************************************
 void  __stdcall _com_issue_error(HRESULT hr)
@@ -1668,17 +1672,17 @@ nsIEProfileMigrator::ParseFavoritesFolde
   return rv;
 }
 
 nsresult
 nsIEProfileMigrator::CopyPreferences(bool aReplace) 
 {
   bool            regKeyOpen = false;
   const regEntry  *entry,
-                  *endEntry = gRegEntries + NS_ARRAY_LENGTH(gRegEntries);
+                  *endEntry = ArrayEnd(gRegEntries);
                               
 
   nsCOMPtr<nsIPrefBranch> prefs;
 
   { // scope pserve why not
     nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID));
     if (pserve)
       pserve->GetBranch("", getter_AddRefs(prefs));
@@ -2163,17 +2167,17 @@ nsIEProfileMigrator::CopyProxyPreference
         { "https=",   6, PR_FALSE, "network.proxy.ssl",
           "network.proxy.ssl_port"    },
         { "socks=",   6, PR_FALSE, "network.proxy.socks",
           "network.proxy.socks_port"  },
       };
 
       PRInt32 startIndex = 0, count = 0;
       bool foundSpecificProxy = false;
-      for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(data); ++i) {
+      for (PRUint32 i = 0; i < ArrayLength(data); ++i) {
         PRInt32 offset = buf.Find(NS_ConvertASCIItoUTF16(data[i].prefix));
         if (offset >= 0) {
           foundSpecificProxy = PR_TRUE;
 
           data[i].proxyConfigured = PR_TRUE;
 
           startIndex = offset + data[i].prefixLength;
 
@@ -2186,17 +2190,17 @@ nsIEProfileMigrator::CopyProxyPreference
                        data[i].portPref, aPrefs);
         }
       }
 
       if (!foundSpecificProxy) {
         // No proxy config for any specific type was found, assume 
         // the ProxyServer value is of the form host:port and that 
         // it applies to all protocols.
-        for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(data); ++i)
+        for (PRUint32 i = 0; i < ArrayLength(data); ++i)
           SetProxyPref(buf, data[i].hostPref, data[i].portPref, aPrefs);
         aPrefs->SetBoolPref("network.proxy.share_proxy_settings", PR_TRUE);
       }
     }
 
   }
 
   return NS_OK;
--- a/browser/components/migration/src/nsOperaProfileMigrator.cpp
+++ b/browser/components/migration/src/nsOperaProfileMigrator.cpp
@@ -30,16 +30,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsBrowserProfileMigratorUtils.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsDocShellCID.h"
 #include "nsINavBookmarksService.h"
 #include "nsBrowserCompsCID.h"
 #include "nsIBrowserProfileMigrator.h"
@@ -63,16 +65,18 @@
 #include "nsISupportsPrimitives.h"
 #include "nsNetUtil.h"
 #include "nsOperaProfileMigrator.h"
 #include "nsToolkitCompsCID.h"
 #ifdef XP_WIN
 #include <windows.h>
 #endif
 
+using namespace mozilla;
+
 #define MIGRATION_BUNDLE "chrome://browser/locale/migration/migration.properties"
 
 #ifdef XP_WIN
 #define OPERA_PREFERENCES_FOLDER_NAME NS_LITERAL_STRING("Opera")
 #define OPERA_PREFERENCES_FILE_NAME NS_LITERAL_STRING("opera6.ini")
 #define OPERA_HISTORY_FILE_NAME NS_LITERAL_STRING("global.dat")
 #define OPERA_BOOKMARKS_FILE_NAME NS_LITERAL_STRING("opera6.adr")
 #elif defined(XP_MACOSX)
@@ -477,17 +481,17 @@ nsOperaProfileMigrator::CopyProxySetting
 
   PRInt32 networkProxyType = 0;
 
   const char* protocols[] = { "HTTP", "HTTPS", "FTP"  };
   const char* protocols_l[] = { "http", "https", "ftp" };
   char toggleBuf[15], serverBuf[20], serverPrefBuf[20], 
        serverPortPrefBuf[25];
   PRInt32 enabled;
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(protocols); ++i) {
+  for (PRUint32 i = 0; i < ArrayLength(protocols); ++i) {
     sprintf(toggleBuf, "Use %s", protocols[i]);
     GetInteger(aParser, "Proxy", toggleBuf, &enabled);
     if (enabled) {
       // Enable the "manual configuration" setting if we have at least
       // one protocol using a Proxy. 
       networkProxyType = 1;
     }
 
--- a/browser/components/shell/src/nsGNOMEShellService.cpp
+++ b/browser/components/shell/src/nsGNOMEShellService.cpp
@@ -29,16 +29,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsCOMPtr.h"
 #include "nsGNOMEShellService.h"
 #include "nsShellService.h"
 #include "nsIServiceManager.h"
 #include "nsILocalFile.h"
 #include "nsIProperties.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsIPrefService.h"
@@ -63,16 +65,18 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <limits.h>
 #include <stdlib.h>
 
+using namespace mozilla;
+
 struct ProtocolAssociation
 {
   const char *name;
   bool essential;
 };
 
 struct MimeTypeAssociation
 {
@@ -234,17 +238,17 @@ nsGNOMEShellService::IsDefaultBrowser(bo
 
   nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
   nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
 
   bool enabled;
   nsCAutoString handler;
   nsCOMPtr<nsIGIOMimeApp> gioApp;
 
-  for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appProtocols); ++i) {
+  for (unsigned int i = 0; i < ArrayLength(appProtocols); ++i) {
     if (!appProtocols[i].essential)
       continue;
 
     if (gconf) {
       handler.Truncate();
       gconf->GetAppForProtocol(nsDependentCString(appProtocols[i].name),
                                &enabled, handler);
 
@@ -290,17 +294,17 @@ nsGNOMEShellService::SetDefaultBrowser(b
       appKeyValue = tmp;
       g_free(tmp);
     } else {
       appKeyValue = mAppPath;
     }
 
     appKeyValue.AppendLiteral(" %s");
 
-    for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appProtocols); ++i) {
+    for (unsigned int i = 0; i < ArrayLength(appProtocols); ++i) {
       if (appProtocols[i].essential || aClaimAllTypes) {
         gconf->SetAppForProtocol(nsDependentCString(appProtocols[i].name),
                                  appKeyValue);
       }
     }
   }
 
   if (giovfs) {
@@ -323,26 +327,26 @@ nsGNOMEShellService::SetDefaultBrowser(b
     NS_ConvertUTF16toUTF8 id(brandShortName);
     nsCOMPtr<nsIGIOMimeApp> appInfo;
     rv = giovfs->CreateAppFromCommand(mAppPath,
                                       id,
                                       getter_AddRefs(appInfo));
     NS_ENSURE_SUCCESS(rv, rv);
 
     // set handler for the protocols
-    for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appProtocols); ++i) {
+    for (unsigned int i = 0; i < ArrayLength(appProtocols); ++i) {
       if (appProtocols[i].essential || aClaimAllTypes) {
         appInfo->SetAsDefaultForURIScheme(nsDependentCString(appProtocols[i].name));
       }
     }
 
     // set handler for .html and xhtml files and MIME types:
     if (aClaimAllTypes) {
       // Add mime types for html, xhtml extension and set app to just created appinfo.
-      for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appTypes); ++i) {
+      for (unsigned int i = 0; i < ArrayLength(appTypes); ++i) {
         appInfo->SetAsDefaultForMimeType(nsDependentCString(appTypes[i].mimeType));
         appInfo->SetAsDefaultForFileExtensions(nsDependentCString(appTypes[i].extensions));
       }
     }
   }
 
   return NS_OK;
 }
--- a/caps/src/nsNullPrincipal.cpp
+++ b/caps/src/nsNullPrincipal.cpp
@@ -37,27 +37,31 @@
  * ***** END LICENSE BLOCK ***** */
 
 /**
  * This is the principal that has no rights and can't be accessed by
  * anything other than itself and chrome; null principals are not
  * same-origin with anything but themselves.
  */
 
+#include "mozilla/Util.h"
+
 #include "nsNullPrincipal.h"
 #include "nsNullPrincipalURI.h"
 #include "nsMemory.h"
 #include "nsIUUIDGenerator.h"
 #include "nsID.h"
 #include "nsNetUtil.h"
 #include "nsIClassInfoImpl.h"
 #include "nsNetCID.h"
 #include "nsDOMError.h"
 #include "nsScriptSecurityManager.h"
 
+using namespace mozilla;
+
 NS_IMPL_CLASSINFO(nsNullPrincipal, NULL, nsIClassInfo::MAIN_THREAD_ONLY,
                   NS_NULLPRINCIPAL_CID)
 NS_IMPL_QUERY_INTERFACE2_CI(nsNullPrincipal,
                             nsIPrincipal,
                             nsISerializable)
 NS_IMPL_CI_INTERFACE_GETTER2(nsNullPrincipal,
                              nsIPrincipal,
                              nsISerializable)
@@ -106,17 +110,17 @@ nsNullPrincipal::Init()
   nsID id;
   rv = uuidgen->GenerateUUIDInPlace(&id);
   NS_ENSURE_SUCCESS(rv, rv);
 
   char chars[NSID_LENGTH];
   id.ToProvidedString(chars);
 
   PRUint32 suffixLen = NSID_LENGTH - 1;
-  PRUint32 prefixLen = NS_ARRAY_LENGTH(NS_NULLPRINCIPAL_PREFIX) - 1;
+  PRUint32 prefixLen = ArrayLength(NS_NULLPRINCIPAL_PREFIX) - 1;
 
   // Use an nsCString so we only do the allocation once here and then share
   // with nsJSPrincipals
   nsCString str;
   str.SetCapacity(prefixLen + suffixLen);
 
   str.Append(NS_NULLPRINCIPAL_PREFIX);
   str.Append(chars);
--- a/caps/src/nsScriptSecurityManager.cpp
+++ b/caps/src/nsScriptSecurityManager.cpp
@@ -35,16 +35,19 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "xpcprivate.h"
 #include "nsScriptSecurityManager.h"
 #include "nsIServiceManager.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIScriptContext.h"
 #include "nsIURL.h"
 #include "nsINestedURI.h"
 #include "nspr.h"
@@ -939,17 +942,17 @@ nsScriptSecurityManager::CheckPropertyAc
             subjectOriginUnicode.get(),
             className.get(),
             IDToString(cx, aProperty),
             objectOriginUnicode.get(),
             subjectDomainUnicode.get(),
             objectDomainUnicode.get()
         };
 
-        PRUint32 length = NS_ARRAY_LENGTH(formatStrings);
+        PRUint32 length = ArrayLength(formatStrings);
 
         // XXXbz Our localization system is stupid and can't handle not showing
         // some strings that get passed in.  Which means that we have to get
         // our length precisely right: it has to be exactly the number of
         // strings our format string wants.  This means we'll have to move
         // strings in the array as needed, sadly...
         if (nsAutoInPrincipalDomainOriginSetter::sInPrincipalDomainOrigin ||
             !objectPrincipal) {
@@ -961,17 +964,17 @@ nsScriptSecurityManager::CheckPropertyAc
             length -= 2;
             if (!subjectDomainUnicode.IsEmpty()) {
                 stringName.AppendLiteral("SubjectDomain");
                 length += 1;
             }
             if (!objectDomainUnicode.IsEmpty()) {
                 stringName.AppendLiteral("ObjectDomain");
                 length += 1;
-                if (length != NS_ARRAY_LENGTH(formatStrings)) {
+                if (length != ArrayLength(formatStrings)) {
                     // We have an object domain but not a subject domain.
                     // Scoot our string over one slot.  See the XXX comment
                     // above for why we need to do this.
                     formatStrings[length-1] = formatStrings[length];
                 }
             }
         }
         
@@ -1583,17 +1586,17 @@ nsScriptSecurityManager::CheckLoadURIWit
     NS_ENSURE_SUCCESS(rv, rv);
     if (!hasFlags) {
         nsXPIDLString message;
         NS_ConvertASCIItoUTF16 ucsTargetScheme(targetScheme);
         const PRUnichar* formatStrings[] = { ucsTargetScheme.get() };
         rv = sStrBundle->
             FormatStringFromName(NS_LITERAL_STRING("ProtocolFlagError").get(),
                                  formatStrings,
-                                 NS_ARRAY_LENGTH(formatStrings),
+                                 ArrayLength(formatStrings),
                                  getter_Copies(message));
         if (NS_SUCCEEDED(rv)) {
             nsCOMPtr<nsIConsoleService> console(
               do_GetService("@mozilla.org/consoleservice;1"));
             NS_ENSURE_TRUE(console, NS_ERROR_FAILURE);
 
             console->LogStringMessage(message.get());
 #ifdef DEBUG
@@ -1624,17 +1627,17 @@ nsScriptSecurityManager::ReportError(JSC
 
     // Localize the error message
     nsXPIDLString message;
     NS_ConvertASCIItoUTF16 ucsSourceSpec(sourceSpec);
     NS_ConvertASCIItoUTF16 ucsTargetSpec(targetSpec);
     const PRUnichar *formatStrings[] = { ucsSourceSpec.get(), ucsTargetSpec.get() };
     rv = sStrBundle->FormatStringFromName(PromiseFlatString(messageTag).get(),
                                           formatStrings,
-                                          NS_ARRAY_LENGTH(formatStrings),
+                                          ArrayLength(formatStrings),
                                           getter_Copies(message));
     NS_ENSURE_SUCCESS(rv, rv);
 
     // If a JS context was passed in, set a JS exception.
     // Otherwise, print the error message directly to the JS console
     // and to standard output
     if (cx)
     {
@@ -1703,17 +1706,17 @@ nsScriptSecurityManager::CheckLoadURIStr
     PRUint32 flags[] = {
         nsIURIFixup::FIXUP_FLAG_NONE,
         nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP,
         nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI,
         nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP |
         nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI
     };
 
-    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(flags); ++i) {
+    for (PRUint32 i = 0; i < ArrayLength(flags); ++i) {
         rv = fixup->CreateFixupURI(aTargetURIStr, flags[i],
                                    getter_AddRefs(target));
         NS_ENSURE_SUCCESS(rv, rv);
 
         rv = CheckLoadURIWithPrincipal(aPrincipal, target, aFlags);
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
@@ -2676,17 +2679,17 @@ nsScriptSecurityManager::FormatCapabilit
             newcaps += capstr;
         else
         {
             nsXPIDLString extensionCap;
             const PRUnichar* formatArgs[] = { rawcap.get() };
             rv = sStrBundle->FormatStringFromName(
                                 NS_LITERAL_STRING("ExtensionCapability").get(),
                                 formatArgs,
-                                NS_ARRAY_LENGTH(formatArgs),
+                                ArrayLength(formatArgs),
                                 getter_Copies(extensionCap));
             if (NS_SUCCEEDED(rv))
                 newcaps += extensionCap;
             else
                 newcaps += rawcap;
         }
 
         newcaps += NS_LITERAL_STRING("\n");
@@ -2765,17 +2768,17 @@ nsScriptSecurityManager::CheckConfirmDia
     NS_ConvertUTF8toUTF16 location(val);
     NS_ConvertASCIItoUTF16 capability(aCapability);
     FormatCapabilityString(capability);
     const PRUnichar *formatStrings[] = { location.get(), capability.get() };
 
     nsXPIDLString message;
     rv = sStrBundle->FormatStringFromName(NS_LITERAL_STRING("EnableCapabilityQuery").get(),
                                           formatStrings,
-                                          NS_ARRAY_LENGTH(formatStrings),
+                                          ArrayLength(formatStrings),
                                           getter_Copies(message));
     if (NS_FAILED(rv))
         return PR_FALSE;
 
     PRInt32 buttonPressed = 1; // If the user exits by clicking the close box, assume No (button 1)
     rv = prompter->ConfirmEx(title.get(), message.get(),
                              (nsIPrompt::BUTTON_DELAY_ENABLE) +
                              (nsIPrompt::BUTTON_POS_1_DEFAULT) +
@@ -2888,17 +2891,17 @@ nsScriptSecurityManager::EnableCapabilit
 
         NS_ConvertUTF8toUTF16 location(val);
         NS_ConvertUTF8toUTF16 cap(capability);
         const PRUnichar *formatStrings[] = { location.get(), cap.get() };
 
         nsXPIDLString message;
         rv = sStrBundle->FormatStringFromName(NS_LITERAL_STRING("EnableCapabilityDenied").get(),
                                               formatStrings,
-                                              NS_ARRAY_LENGTH(formatStrings),
+                                              ArrayLength(formatStrings),
                                               getter_Copies(message));
         if (NS_FAILED(rv))
             return rv;
 
         SetPendingException(cx, message.get());
 
         return NS_ERROR_FAILURE; // XXX better error code?
     }
@@ -3054,17 +3057,17 @@ nsScriptSecurityManager::CanCreateWrappe
             GetPrincipalDomainOrigin(subjectPrincipal, origin);
         }
         NS_ConvertUTF8toUTF16 originUnicode(origin);
         NS_ConvertUTF8toUTF16 className(objClassInfo.GetName());
         const PRUnichar* formatStrings[] = {
             className.get(),
             originUnicode.get()
         };
-        PRUint32 length = NS_ARRAY_LENGTH(formatStrings);
+        PRUint32 length = ArrayLength(formatStrings);
         if (originUnicode.IsEmpty()) {
             --length;
         } else {
             strName.AppendLiteral("ForOrigin");
         }
         nsXPIDLString errorMsg;
         // We need to keep our existing failure rv and not override it
         // with a likely success code from the following string bundle
@@ -3848,17 +3851,17 @@ nsScriptSecurityManager::InitPrincipals(
      * codebase principals are disabled. Don't use trustedCodebase except with unspoofable
      * URLs such as HTTPS URLs.
      */
 
     static const char idSuffix[] = ".id";
     for (PRUint32 c = 0; c < aPrefCount; c++)
     {
         PRInt32 prefNameLen = PL_strlen(aPrefNames[c]) - 
-            (NS_ARRAY_LENGTH(idSuffix) - 1);
+            (ArrayLength(idSuffix) - 1);
         if (PL_strcasecmp(aPrefNames[c] + prefNameLen, idSuffix) != 0)
             continue;
 
         nsAdoptingCString id = Preferences::GetCString(aPrefNames[c]);
         if (!id) {
             return NS_ERROR_FAILURE;
         }
 
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -36,16 +36,18 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* A namespace class for static layout utilities. */
 
+#include "mozilla/Util.h"
+
 #include "jsapi.h"
 #include "jsdbgapi.h"
 
 #include "nsJSUtils.h"
 #include "nsCOMPtr.h"
 #include "nsAString.h"
 #include "nsPrintfCString.h"
 #include "nsUnicharUtils.h"
@@ -530,29 +532,29 @@ nsContentUtils::InitializeEventTable() {
     nsnull
   };
 
   sAtomEventTable = new nsDataHashtable<nsISupportsHashKey, EventNameMapping>;
   sStringEventTable = new nsDataHashtable<nsStringHashKey, EventNameMapping>;
   sUserDefinedEvents = new nsCOMArray<nsIAtom>(64);
 
   if (!sAtomEventTable || !sStringEventTable || !sUserDefinedEvents ||
-      !sAtomEventTable->Init(int(NS_ARRAY_LENGTH(eventArray) / 0.75) + 1) ||
-      !sStringEventTable->Init(int(NS_ARRAY_LENGTH(eventArray) / 0.75) + 1)) {
+      !sAtomEventTable->Init(int(ArrayLength(eventArray) / 0.75) + 1) ||
+      !sStringEventTable->Init(int(ArrayLength(eventArray) / 0.75) + 1)) {
     delete sAtomEventTable;
     sAtomEventTable = nsnull;
     delete sStringEventTable;
     sStringEventTable = nsnull;
     delete sUserDefinedEvents;
     sUserDefinedEvents = nsnull;
     return PR_FALSE;
   }
 
   // Subtract one from the length because of the trailing null
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(eventArray) - 1; ++i) {
+  for (PRUint32 i = 0; i < ArrayLength(eventArray) - 1; ++i) {
     if (!sAtomEventTable->Put(eventArray[i].mAtom, eventArray[i]) ||
         !sStringEventTable->Put(Substring(nsDependentAtomString(eventArray[i].mAtom), 2),
                                 eventArray[i])) {
       delete sAtomEventTable;
       sAtomEventTable = nsnull;
       delete sStringEventTable;
       sStringEventTable = nsnull;
       return PR_FALSE;
@@ -573,17 +575,17 @@ nsContentUtils::InitializeTouchEventTabl
 #define TOUCH_EVENT(name_,  _id, _type, _struct)      \
       { nsGkAtoms::on##name_, _id, _type, _struct },
 #include "nsEventNameList.h"
 #undef TOUCH_EVENT
 #undef EVENT
       nsnull
     };
     // Subtract one from the length because of the trailing null
-    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(touchEventArray) - 1; ++i) {
+    for (PRUint32 i = 0; i < ArrayLength(touchEventArray) - 1; ++i) {
       if (!sAtomEventTable->Put(touchEventArray[i].mAtom, touchEventArray[i]) ||
           !sStringEventTable->Put(Substring(nsDependentAtomString(touchEventArray[i].mAtom), 2),
                                   touchEventArray[i])) {
         delete sAtomEventTable;
         sAtomEventTable = nsnull;
         delete sStringEventTable;
         sStringEventTable = nsnull;
         return;
@@ -4153,17 +4155,17 @@ nsContentUtils::GetTopLevelWidget(nsIWid
 /* static */
 const nsDependentString
 nsContentUtils::GetLocalizedEllipsis()
 {
   static PRUnichar sBuf[4] = { 0, 0, 0, 0 };
   if (!sBuf[0]) {
     nsAdoptingString tmp = Preferences::GetLocalizedString("intl.ellipsis");
     PRUint32 len = NS_MIN(PRUint32(tmp.Length()),
-                          PRUint32(NS_ARRAY_LENGTH(sBuf) - 1));
+                          PRUint32(ArrayLength(sBuf) - 1));
     CopyUnicodeTo(tmp, 0, sBuf, len);
     if (!sBuf[0])
       sBuf[0] = PRUnichar(0x2026);
   }
   return nsDependentString(sBuf);
 }
 
 //static
@@ -5154,17 +5156,17 @@ nsContentUtils::CanAccessNativeAnon()
   }
 
   // XXX HACK EWW! Allow chrome://global/ access to these things, even
   // if they've been cloned into less privileged contexts.
   static const char prefix[] = "chrome://global/";
   const char *filename;
   if (fp && JS_IsScriptFrame(cx, fp) &&
       (filename = JS_GetScriptFilename(cx, JS_GetFrameScript(cx, fp))) &&
-      !strncmp(filename, prefix, NS_ARRAY_LENGTH(prefix) - 1)) {
+      !strncmp(filename, prefix, ArrayLength(prefix) - 1)) {
     return PR_TRUE;
   }
 
   // Before we throw, check for UniversalXPConnect.
   nsresult rv = sSecurityManager->IsCapabilityEnabled("UniversalXPConnect", &privileged);
   if (NS_SUCCEEDED(rv) && privileged) {
     return PR_TRUE;
   }
@@ -5672,32 +5674,32 @@ nsContentUtils::FindInternalContentViewe
       *aLoaderType = TYPE_UNKNOWN;
     }
     return docFactory.forget();
   }
 
 #ifdef MOZ_MEDIA
 #ifdef MOZ_OGG
   if (nsHTMLMediaElement::IsOggEnabled()) {
-    for (unsigned int i = 0; i < NS_ARRAY_LENGTH(nsHTMLMediaElement::gOggTypes); ++i) {
+    for (unsigned int i = 0; i < ArrayLength(nsHTMLMediaElement::gOggTypes); ++i) {
       const char* type = nsHTMLMediaElement::gOggTypes[i];
       if (!strcmp(aType, type)) {
         docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
         if (docFactory && aLoaderType) {
           *aLoaderType = TYPE_CONTENT;
         }
         return docFactory.forget();
       }
     }
   }
 #endif
 
 #ifdef MOZ_WEBM
   if (nsHTMLMediaElement::IsWebMEnabled()) {
-    for (unsigned int i = 0; i < NS_ARRAY_LENGTH(nsHTMLMediaElement::gWebMTypes); ++i) {
+    for (unsigned int i = 0; i < ArrayLength(nsHTMLMediaElement::gWebMTypes); ++i) {
       const char* type = nsHTMLMediaElement::gWebMTypes[i];
       if (!strcmp(aType, type)) {
         docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
         if (docFactory && aLoaderType) {
           *aLoaderType = TYPE_CONTENT;
         }
         return docFactory.forget();
       }
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -42,16 +42,18 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 /*
  * Base class for all our document implementations.
  */
 
+#include "mozilla/Util.h"
+
 #ifdef MOZ_LOGGING
 // so we can get logging even in release builds
 #define FORCE_PR_LOG 1
 #endif
 #include "prlog.h"
 #include "plstr.h"
 #include "prprf.h"
 
@@ -1794,17 +1796,17 @@ static const char* kNSURIs[] = {
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument)
   if (NS_UNLIKELY(cb.WantDebugInfo())) {
     char name[512];
     PRUint32 nsid = tmp->GetDefaultNamespaceID();
     nsCAutoString uri;
     if (tmp->mDocumentURI)
       tmp->mDocumentURI->GetSpec(uri);
-    if (nsid < NS_ARRAY_LENGTH(kNSURIs)) {
+    if (nsid < ArrayLength(kNSURIs)) {
       PR_snprintf(name, sizeof(name), "nsDocument%s %s", kNSURIs[nsid],
                   uri.get());
     }
     else {
       PR_snprintf(name, sizeof(name), "nsDocument %s", uri.get());
     }
     cb.DescribeRefCountedNode(tmp->mRefCnt.get(), sizeof(nsDocument), name);
   }
--- a/content/base/src/nsEventSource.cpp
+++ b/content/base/src/nsEventSource.cpp
@@ -32,16 +32,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsEventSource.h"
 #include "nsNetUtil.h"
 #include "nsMimeTypes.h"
 #include "nsDOMMessageEvent.h"
 #include "nsIJSContextStack.h"
 #include "nsIPromptFactory.h"
 #include "nsIWindowWatcher.h"
 #include "nsPresContext.h"
@@ -1091,21 +1093,21 @@ nsEventSource::ConsoleError()
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ConvertUTF8toUTF16 specUTF16(targetSpec);
   const PRUnichar *formatStrings[] = { specUTF16.get() };
 
   if (mReadyState == nsIEventSource::CONNECTING) {
     rv = PrintErrorOnConsole("chrome://global/locale/appstrings.properties",
                              NS_LITERAL_STRING("connectionFailure").get(),
-                             formatStrings, NS_ARRAY_LENGTH(formatStrings));
+                             formatStrings, ArrayLength(formatStrings));
   } else {
     rv = PrintErrorOnConsole("chrome://global/locale/appstrings.properties",
                              NS_LITERAL_STRING("netInterrupt").get(),
-                             formatStrings, NS_ARRAY_LENGTH(formatStrings));
+                             formatStrings, ArrayLength(formatStrings));
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
 nsEventSource::DispatchFailConnection()
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -38,16 +38,18 @@
  * ***** END LICENSE BLOCK ***** */
 
 /*
  * Base class for all element classes; this provides an implementation
  * of DOM Core's nsIDOMElement, implements nsIContent, provides
  * utility methods for subclasses, and so forth.
  */
 
+#include "mozilla/Util.h"
+
 #include "nsGenericElement.h"
 
 #include "nsDOMAttribute.h"
 #include "nsDOMAttributeMap.h"
 #include "nsIAtom.h"
 #include "nsINodeInfo.h"
 #include "nsIDocument.h"
 #include "nsIDOMNodeList.h"
@@ -146,18 +148,18 @@
 #include "prprf.h"
 
 #include "nsSVGFeatures.h"
 #include "nsDOMMemoryReporter.h"
 #include "nsWrapperCacheInlines.h"
 
 #include "xpcpublic.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
-namespace css = mozilla::css;
 
 NS_DEFINE_IID(kThisPtrOffsetsSID, NS_THISPTROFFSETS_SID);
 
 PRInt32 nsIContent::sTabFocusModel = eTabFocus_any;
 bool nsIContent::sTabFocusModelAppliesToXUL = false;
 PRUint32 nsMutationGuard::sMutationCount = 0;
 
 nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
@@ -4318,17 +4320,17 @@ static const char* kNSURIs[] = {
   " (XML Events)"
 };
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGenericElement)
   if (NS_UNLIKELY(cb.WantDebugInfo())) {
     char name[72];
     PRUint32 nsid = tmp->GetNameSpaceID();
     nsAtomCString localName(tmp->NodeInfo()->NameAtom());
-    if (nsid < NS_ARRAY_LENGTH(kNSURIs)) {
+    if (nsid < ArrayLength(kNSURIs)) {
       PR_snprintf(name, sizeof(name), "nsGenericElement%s %s", kNSURIs[nsid],
                   localName.get());
     }
     else {
       PR_snprintf(name, sizeof(name), "nsGenericElement %s", localName.get());
     }
     cb.DescribeRefCountedNode(tmp->mRefCnt.get(), sizeof(nsGenericElement),
                               name);
--- a/content/base/src/nsGkAtoms.cpp
+++ b/content/base/src/nsGkAtoms.cpp
@@ -36,19 +36,23 @@
  * ***** END LICENSE BLOCK ***** */
 
 /*
  * This class wraps up the creation (and destruction) of the standard
  * set of atoms used by gklayout; the atoms are created when gklayout
  * is loaded and they are destroyed when gklayout is unloaded.
  */
 
+#include "mozilla/Util.h"
+
 #include "nsGkAtoms.h"
 #include "nsStaticAtom.h"
 
+using namespace mozilla;
+
 // define storage for all atoms
 #define GK_ATOM(name_, value_) nsIAtom* nsGkAtoms::name_;
 #include "nsGkAtomList.h"
 #undef GK_ATOM
 
 #define GK_ATOM(name_, value_) NS_STATIC_ATOM_BUFFER(name_##_buffer, value_)
 #include "nsGkAtomList.h"
 #undef GK_ATOM
@@ -56,11 +60,11 @@
 static const nsStaticAtom GkAtoms_info[] = {
 #define GK_ATOM(name_, value_) NS_STATIC_ATOM(name_##_buffer, &nsGkAtoms::name_),
 #include "nsGkAtomList.h"
 #undef GK_ATOM
 };
 
 void nsGkAtoms::AddRefAtoms()
 {
-  NS_RegisterStaticAtoms(GkAtoms_info, NS_ARRAY_LENGTH(GkAtoms_info));
+  NS_RegisterStaticAtoms(GkAtoms_info, ArrayLength(GkAtoms_info));
 }
 
--- a/content/base/src/nsNodeInfo.cpp
+++ b/content/base/src/nsNodeInfo.cpp
@@ -36,16 +36,18 @@
  * ***** END LICENSE BLOCK ***** */
 
 /*
  * Class that represents a prefix/namespace/localName triple; a single
  * nodeinfo is shared by all elements in a document that have that
  * prefix, namespace, and localName.
  */
 
+#include "mozilla/Util.h"
+
 #include "nscore.h"
 #include "nsNodeInfo.h"
 #include "nsNodeInfoManager.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsIAtom.h"
 #include "nsDOMString.h"
 #include "nsCRT.h"
@@ -53,16 +55,18 @@
 #include "nsReadableUtils.h"
 #include "nsAutoPtr.h"
 #include NEW_H
 #include "nsFixedSizeAllocator.h"
 #include "prprf.h"
 #include "nsIDocument.h"
 #include "nsGkAtoms.h"
 
+using namespace mozilla;
+
 static const size_t kNodeInfoPoolSizes[] = {
   sizeof(nsNodeInfo)
 };
 
 static const PRInt32 kNodeInfoPoolInitialSize = 
   (NS_SIZE_IN_HEAP(sizeof(nsNodeInfo))) * 64;
 
 // static
@@ -187,17 +191,17 @@ static const char* kNSURIs[] = {
   " (XUL)"
 };
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsNodeInfo)
   if (NS_UNLIKELY(cb.WantDebugInfo())) {
     char name[72];
     PRUint32 nsid = tmp->NamespaceID();
     nsAtomCString localName(tmp->NameAtom());
-    if (nsid < NS_ARRAY_LENGTH(kNSURIs)) {
+    if (nsid < ArrayLength(kNSURIs)) {
       PR_snprintf(name, sizeof(name), "nsNodeInfo%s %s", kNSURIs[nsid],
                   localName.get());
     }
     else {
       PR_snprintf(name, sizeof(name), "nsNodeInfo %s", localName.get());
     }
 
     cb.DescribeRefCountedNode(tmp->mRefCnt.get(), sizeof(nsNodeInfo), name);
--- a/content/base/src/nsTreeSanitizer.cpp
+++ b/content/base/src/nsTreeSanitizer.cpp
@@ -33,32 +33,36 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsTreeSanitizer.h"
 #include "nsCSSParser.h"
 #include "nsCSSProperty.h"
 #include "mozilla/css/Declaration.h"
 #include "mozilla/css/StyleRule.h"
 #include "mozilla/css/Rule.h"
 #include "nsUnicharInputStream.h"
 #include "nsCSSStyleSheet.h"
 #include "nsIDOMCSSRule.h"
 #include "nsAttrName.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsNetUtil.h"
 #include "nsComponentManagerUtils.h"
 #include "nsNullPrincipal.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
+
 //
 // Thanks to Mark Pilgrim and Sam Ruby for the initial whitelist
 //
 nsIAtom** const kElementsHTML[] = {
   &nsGkAtoms::a,
   &nsGkAtoms::abbr,
   &nsGkAtoms::acronym,
   &nsGkAtoms::address,
@@ -1448,47 +1452,47 @@ nsTreeSanitizer::Sanitize(nsIContent* aF
 }
 
 void
 nsTreeSanitizer::InitializeStatics()
 {
   NS_PRECONDITION(!sElementsHTML, "Initializing a second time.");
 
   sElementsHTML = new nsTHashtable<nsISupportsHashKey> ();
-  sElementsHTML->Init(NS_ARRAY_LENGTH(kElementsHTML));
+  sElementsHTML->Init(ArrayLength(kElementsHTML));
   for (PRUint32 i = 0; kElementsHTML[i]; i++) {
     sElementsHTML->PutEntry(*kElementsHTML[i]);
   }
 
   sAttributesHTML = new nsTHashtable<nsISupportsHashKey> ();
-  sAttributesHTML->Init(NS_ARRAY_LENGTH(kAttributesHTML));
+  sAttributesHTML->Init(ArrayLength(kAttributesHTML));
   for (PRUint32 i = 0; kAttributesHTML[i]; i++) {
     sAttributesHTML->PutEntry(*kAttributesHTML[i]);
   }
 
   sElementsSVG = new nsTHashtable<nsISupportsHashKey> ();
-  sElementsSVG->Init(NS_ARRAY_LENGTH(kElementsSVG));
+  sElementsSVG->Init(ArrayLength(kElementsSVG));
   for (PRUint32 i = 0; kElementsSVG[i]; i++) {
     sElementsSVG->PutEntry(*kElementsSVG[i]);
   }
 
   sAttributesSVG = new nsTHashtable<nsISupportsHashKey> ();
-  sAttributesSVG->Init(NS_ARRAY_LENGTH(kAttributesSVG));
+  sAttributesSVG->Init(ArrayLength(kAttributesSVG));
   for (PRUint32 i = 0; kAttributesSVG[i]; i++) {
     sAttributesSVG->PutEntry(*kAttributesSVG[i]);
   }
 
   sElementsMathML = new nsTHashtable<nsISupportsHashKey> ();
-  sElementsMathML->Init(NS_ARRAY_LENGTH(kElementsMathML));
+  sElementsMathML->Init(ArrayLength(kElementsMathML));
   for (PRUint32 i = 0; kElementsMathML[i]; i++) {
     sElementsMathML->PutEntry(*kElementsMathML[i]);
   }
 
   sAttributesMathML = new nsTHashtable<nsISupportsHashKey> ();
-  sAttributesMathML->Init(NS_ARRAY_LENGTH(kAttributesMathML));
+  sAttributesMathML->Init(ArrayLength(kAttributesMathML));
   for (PRUint32 i = 0; kAttributesMathML[i]; i++) {
     sAttributesMathML->PutEntry(*kAttributesMathML[i]);
   }
 
   nsCOMPtr<nsIPrincipal> principal =
       do_CreateInstance(NS_NULLPRINCIPAL_CONTRACTID);
   principal.forget(&sNullPrincipal);
 }
--- a/content/base/src/nsWebSocket.cpp
+++ b/content/base/src/nsWebSocket.cpp
@@ -33,16 +33,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsWebSocket.h"
 
 #include "nsIScriptGlobalObject.h"
 #include "nsIDOMWindow.h"
 #include "nsIDocument.h"
 #include "nsXPCOM.h"
 #include "nsIXPConnect.h"
 #include "nsContentUtils.h"
@@ -413,21 +415,21 @@ nsWebSocketEstablishedConnection::Consol
     NS_WARNING("Failed to get targetSpec");
   } else {
     NS_ConvertUTF8toUTF16 specUTF16(targetSpec);
     const PRUnichar *formatStrings[] = { specUTF16.get() };
     
     if (mStatus < CONN_CONNECTED_AND_READY) {
       PrintErrorOnConsole("chrome://global/locale/appstrings.properties",
                           NS_LITERAL_STRING("connectionFailure").get(),
-                          formatStrings, NS_ARRAY_LENGTH(formatStrings));
+                          formatStrings, ArrayLength(formatStrings));
     } else {
       PrintErrorOnConsole("chrome://global/locale/appstrings.properties",
                           NS_LITERAL_STRING("netInterrupt").get(),
-                          formatStrings, NS_ARRAY_LENGTH(formatStrings));
+                          formatStrings, ArrayLength(formatStrings));
     }
   }
   /// todo some specific errors - like for message too large
   return rv;
 }
 
 
 nsresult
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -30,16 +30,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsXMLHttpRequest.h"
 #include "nsISimpleEnumerator.h"
 #include "nsIXPConnect.h"
 #include "nsICharsetConverterManager.h"
 #include "nsLayoutCID.h"
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
 #include "nsIURI.h"
@@ -96,16 +98,18 @@
 #include "nsChannelPolicy.h"
 #include "nsIContentSecurityPolicy.h"
 #include "nsAsyncRedirectVerifyHelper.h"
 #include "jstypedarray.h"
 #include "nsStringBuffer.h"
 #include "nsDOMFile.h"
 #include "nsIFileChannel.h"
 
+using namespace mozilla;
+
 #define LOAD_STR "load"
 #define ERROR_STR "error"
 #define ABORT_STR "abort"
 #define LOADSTART_STR "loadstart"
 #define PROGRESS_STR "progress"
 #define UPLOADPROGRESS_STR "uploadprogress"
 #define READYSTATE_STR "readystatechange"
 #define LOADEND_STR "loadend"
@@ -1265,17 +1269,17 @@ nsXMLHttpRequest::GetResponseHeader(cons
     }
 
     const char *kCrossOriginSafeHeaders[] = {
       "cache-control", "content-language", "content-type", "expires",
       "last-modified", "pragma"
     };
     bool safeHeader = false;
     PRUint32 i;
-    for (i = 0; i < NS_ARRAY_LENGTH(kCrossOriginSafeHeaders); ++i) {
+    for (i = 0; i < ArrayLength(kCrossOriginSafeHeaders); ++i) {
       if (header.LowerCaseEqualsASCII(kCrossOriginSafeHeaders[i])) {
         safeHeader = PR_TRUE;
         break;
       }
     }
 
     if (!safeHeader) {
       nsCAutoString headerVal;
@@ -2644,17 +2648,17 @@ nsXMLHttpRequest::SetRequestHeader(const
     const char *kInvalidHeaders[] = {
       "accept-charset", "accept-encoding", "access-control-request-headers",
       "access-control-request-method", "connection", "content-length",
       "cookie", "cookie2", "content-transfer-encoding", "date", "expect",
       "host", "keep-alive", "origin", "referer", "te", "trailer",
       "transfer-encoding", "upgrade", "user-agent", "via"
     };
     PRUint32 i;
-    for (i = 0; i < NS_ARRAY_LENGTH(kInvalidHeaders); ++i) {
+    for (i = 0; i < ArrayLength(kInvalidHeaders); ++i) {
       if (header.LowerCaseEqualsASCII(kInvalidHeaders[i])) {
         NS_WARNING("refusing to set request header");
         return NS_OK;
       }
     }
     if (StringBeginsWith(header, NS_LITERAL_CSTRING("proxy-"),
                          nsCaseInsensitiveCStringComparator()) ||
         StringBeginsWith(header, NS_LITERAL_CSTRING("sec-"),
@@ -2666,17 +2670,17 @@ nsXMLHttpRequest::SetRequestHeader(const
     // Check for dangerous cross-site headers
     bool safeHeader = IsSystemXHR();
     if (!safeHeader) {
       // Content-Type isn't always safe, but we'll deal with it in Send()
       const char *kCrossOriginSafeHeaders[] = {
         "accept", "accept-language", "content-language", "content-type",
         "last-event-id"
       };
-      for (i = 0; i < NS_ARRAY_LENGTH(kCrossOriginSafeHeaders); ++i) {
+      for (i = 0; i < ArrayLength(kCrossOriginSafeHeaders); ++i) {
         if (header.LowerCaseEqualsASCII(kCrossOriginSafeHeaders[i])) {
           safeHeader = true;
           break;
         }
       }
     }
 
     if (!safeHeader) {
--- a/content/events/src/nsDOMDataTransfer.cpp
+++ b/content/events/src/nsDOMDataTransfer.cpp
@@ -30,16 +30,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsDOMDataTransfer.h"
 
 #include "prlog.h"
 #include "nsString.h"
 #include "nsIServiceManager.h"
 #include "nsIVariant.h"
 #include "nsISupportsPrimitives.h"
 #include "nsDOMClassInfoID.h"
@@ -49,16 +51,18 @@
 #include "nsDOMError.h"
 #include "nsIDragService.h"
 #include "nsIScriptableRegion.h"
 #include "nsContentUtils.h"
 #include "nsIContent.h"
 #include "nsCRT.h"
 #include "nsIScriptObjectPrincipal.h"
 
+using namespace mozilla;
+
 NS_IMPL_CYCLE_COLLECTION_2(nsDOMDataTransfer, mDragTarget, mDragImage)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMDataTransfer)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMDataTransfer)
 
 DOMCI_DATA(DataTransfer, nsDOMDataTransfer)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMDataTransfer)
@@ -173,17 +177,17 @@ nsDOMDataTransfer::SetEffectAllowed(cons
     return NS_OK;
   }
 
   PR_STATIC_ASSERT(nsIDragService::DRAGDROP_ACTION_NONE == 0);
   PR_STATIC_ASSERT(nsIDragService::DRAGDROP_ACTION_COPY == 1);
   PR_STATIC_ASSERT(nsIDragService::DRAGDROP_ACTION_MOVE == 2);
   PR_STATIC_ASSERT(nsIDragService::DRAGDROP_ACTION_LINK == 4);
 
-  for (PRUint32 e = 0; e < NS_ARRAY_LENGTH(sEffects); e++) {
+  for (PRUint32 e = 0; e < ArrayLength(sEffects); e++) {
     if (aEffectAllowed.EqualsASCII(sEffects[e])) {
       mEffectAllowed = e;
       break;
     }
   }
 
   return NS_OK;
 }
@@ -855,17 +859,17 @@ nsDOMDataTransfer::CacheExternalFormats(
   // there isn't a way to get a list of the formats that might be available on
   // all platforms, so just check for the types that can actually be imported
   // XXXndeakin there are some other formats but those are platform specific.
   const char* formats[] = { kFileMime, kHTMLMime, kURLMime, kURLDataMime, kUnicodeMime };
 
   PRUint32 count;
   dragSession->GetNumDropItems(&count);
   for (PRUint32 c = 0; c < count; c++) {
-    for (PRUint32 f = 0; f < NS_ARRAY_LENGTH(formats); f++) {
+    for (PRUint32 f = 0; f < ArrayLength(formats); f++) {
       // IsDataFlavorSupported doesn't take an index as an argument and just
       // checks if any of the items support a particular flavor, even though
       // the GetData method does take an index. Here, we just assume that
       // every item being dragged has the same set of flavors.
       bool supported;
       dragSession->IsDataFlavorSupported(formats[f], &supported);
       // if the format is supported, add an item to the array with null as
       // the data. When retrieved, GetRealData will read the data.
--- a/content/events/src/nsDOMEvent.cpp
+++ b/content/events/src/nsDOMEvent.cpp
@@ -33,16 +33,20 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "base/basictypes.h"
+
+/* This must occur *after* base/basictypes.h to avoid typedefs conflicts. */
+#include "mozilla/Util.h"
+
 #include "IPC/IPCMessageUtils.h"
 #include "nsCOMPtr.h"
 #include "nsDOMEvent.h"
 #include "nsEventStateManager.h"
 #include "nsIFrame.h"
 #include "nsIContent.h"
 #include "nsIPresShell.h"
 #include "nsIDocument.h"
@@ -437,17 +441,17 @@ ReportUseOfDeprecatedMethod(nsEvent* aEv
 {
   nsCOMPtr<nsIDocument> doc(GetDocumentForReport(aEvent));
 
   nsAutoString type;
   aDOMEvent->GetType(type);
   const PRUnichar *strings[] = { type.get() };
   nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
                                   aWarning,
-                                  strings, NS_ARRAY_LENGTH(strings),
+                                  strings, ArrayLength(strings),
                                   nsnull,
                                   EmptyString(), 0, 0,
                                   nsIScriptError::warningFlag,
                                   "DOM Events", doc);
 }
 
 NS_IMETHODIMP
 nsDOMEvent::PreventBubble()
--- a/content/html/content/src/nsFormSubmission.cpp
+++ b/content/html/content/src/nsFormSubmission.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsFormSubmission.h"
 
 #include "nsCOMPtr.h"
 #include "nsIForm.h"
 #include "nsILinkHandler.h"
 #include "nsIDocument.h"
 #include "nsGkAtoms.h"
 #include "nsIHTMLDocument.h"
@@ -66,16 +68,18 @@
 #include "nsIMIMEService.h"
 #include "nsIConsoleService.h"
 #include "nsIScriptError.h"
 #include "nsIStringBundle.h"
 #include "nsCExternalHandlerService.h"
 #include "nsIFileStreams.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
+
 static void
 SendJSWarning(nsIDocument* aDocument,
               const char* aWarningName,
               const PRUnichar** aWarningArgs, PRUint32 aWarningArgsLen)
 {
   nsContentUtils::ReportToConsole(nsContentUtils::eFORMS_PROPERTIES,
                                   aWarningName,
                                   aWarningArgs, aWarningArgsLen,
@@ -262,17 +266,17 @@ HandleMailtoSubject(nsCString& aPath) {
     if (NS_FAILED(rv))
       return;
     const PRUnichar *formatStrings[] = { brandName.get() };
     nsXPIDLString subjectStr;
     rv = nsContentUtils::FormatLocalizedString(
                                            nsContentUtils::eFORMS_PROPERTIES,
                                            "DefaultFormSubject",
                                            formatStrings,
-                                           NS_ARRAY_LENGTH(formatStrings),
+                                           ArrayLength(formatStrings),
                                            subjectStr);
     if (NS_FAILED(rv))
       return;
     aPath.AppendLiteral("subject=");
     nsCString subjectStrEscaped;
     aPath.Append(NS_EscapeURL(NS_ConvertUTF16toUTF8(subjectStr), esc_Query,
                               subjectStrEscaped));
   }
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -32,16 +32,19 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nscore.h"
 #include "nsGenericHTMLElement.h"
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
 #include "nsIContentViewer.h"
 #include "mozilla/css/StyleRule.h"
 #include "nsIDocument.h"
 #include "nsIDocumentEncoder.h"
@@ -1441,17 +1444,17 @@ nsGenericHTMLElement::ParseAttribute(PRI
 
 bool
 nsGenericHTMLElement::IsAttributeMapped(const nsIAtom* aAttribute) const
 {
   static const MappedAttributeEntry* const map[] = {
     sCommonAttributeMap
   };
   
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 nsMapRuleToAttributesFunc
 nsGenericHTMLElement::GetAttributeMappingFunction() const
 {
   return &MapCommonAttributesInto;
 }
 
@@ -2162,17 +2165,17 @@ nsGenericHTMLElement::MapScrollingAttrib
   if (!(aData->mSIDs & NS_STYLE_INHERIT_BIT(Display)))
     return;
 
   // scrolling
   nsCSSValue* overflowValues[2] = {
     aData->ValueForOverflowX(),
     aData->ValueForOverflowY(),
   };
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(overflowValues); ++i) {
+  for (PRUint32 i = 0; i < ArrayLength(overflowValues); ++i) {
     if (overflowValues[i]->GetUnit() == eCSSUnit_Null) {
       const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::scrolling);
       if (value && value->Type() == nsAttrValue::eEnum) {
         PRInt32 mappedValue;
         switch (value->GetEnumValue()) {
           case NS_STYLE_FRAME_ON:
           case NS_STYLE_FRAME_SCROLL:
           case NS_STYLE_FRAME_YES:
--- a/content/html/content/src/nsHTMLBRElement.cpp
+++ b/content/html/content/src/nsHTMLBRElement.cpp
@@ -29,24 +29,29 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLBRElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsMappedAttributes.h"
 #include "nsRuleData.h"
 
+using namespace mozilla;
+
 class nsHTMLBRElement : public nsGenericHTMLElement,
                         public nsIDOMHTMLBRElement
 {
 public:
   nsHTMLBRElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLBRElement();
 
   // nsISupports
@@ -152,16 +157,16 @@ nsHTMLBRElement::IsAttributeMapped(const
     { nsnull }
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLBRElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLBodyElement.cpp
+++ b/content/html/content/src/nsHTMLBodyElement.cpp
@@ -31,16 +31,19 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nscore.h"
 #include "nsCOMPtr.h"
 #include "nsIDOMHTMLBodyElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
@@ -56,16 +59,18 @@
 #include "nsIDocShell.h"
 #include "nsIEditorDocShell.h"
 #include "nsCOMPtr.h"
 #include "nsRuleWalker.h"
 #include "jsapi.h"
 
 //----------------------------------------------------------------------
 
+using namespace mozilla;
+
 class nsHTMLBodyElement;
 
 class BodyRule: public nsIStyleRule {
 public:
   BodyRule(nsHTMLBodyElement* aPart);
   virtual ~BodyRule();
 
   NS_DECL_ISUPPORTS
@@ -463,17 +468,17 @@ nsHTMLBodyElement::IsAttributeMapped(con
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
     sBackgroundAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 already_AddRefed<nsIEditor>
 nsHTMLBodyElement::GetAssociatedEditor()
 {
   nsIEditor* editor = nsnull;
   if (NS_SUCCEEDED(GetEditorInternal(&editor)) && editor) {
     return editor;
--- a/content/html/content/src/nsHTMLDivElement.cpp
+++ b/content/html/content/src/nsHTMLDivElement.cpp
@@ -29,24 +29,29 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLDivElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsMappedAttributes.h"
 #include "nsDOMMemoryReporter.h"
 
+using namespace mozilla;
+
 class nsHTMLDivElement : public nsGenericHTMLElement,
                          public nsIDOMHTMLDivElement
 {
 public:
   nsHTMLDivElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLDivElement();
 
   // nsISupports
@@ -160,25 +165,25 @@ MapMarqueeAttributesIntoRule(const nsMap
 NS_IMETHODIMP_(bool)
 nsHTMLDivElement::IsAttributeMapped(const nsIAtom* aAttribute) const
 {
   if (mNodeInfo->Equals(nsGkAtoms::div)) {
     static const MappedAttributeEntry* const map[] = {
       sDivAlignAttributeMap,
       sCommonAttributeMap
     };
-    return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+    return FindAttributeDependence(aAttribute, map, ArrayLength(map));
   }
   if (mNodeInfo->Equals(nsGkAtoms::marquee)) {  
     static const MappedAttributeEntry* const map[] = {
       sImageMarginSizeAttributeMap,
       sBackgroundColorAttributeMap,
       sCommonAttributeMap
     };
-    return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+    return FindAttributeDependence(aAttribute, map, ArrayLength(map));
   }
 
   return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLDivElement::GetAttributeMappingFunction() const
 {
--- a/content/html/content/src/nsHTMLFontElement.cpp
+++ b/content/html/content/src/nsHTMLFontElement.cpp
@@ -29,27 +29,32 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsCOMPtr.h"
 #include "nsIDOMHTMLFontElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsMappedAttributes.h"
 #include "nsRuleData.h"
 #include "nsIDocument.h"
 
+using namespace mozilla;
+
 class nsHTMLFontElement : public nsGenericHTMLElement,
                           public nsIDOMHTMLFontElement
 {
 public:
   nsHTMLFontElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLFontElement();
 
   // nsISupports
@@ -271,17 +276,17 @@ nsHTMLFontElement::IsAttributeMapped(con
     { nsnull }
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 nsMapRuleToAttributesFunc
 nsHTMLFontElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLFrameElement.cpp
+++ b/content/html/content/src/nsHTMLFrameElement.cpp
@@ -29,23 +29,27 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLFrameElement.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsDOMError.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 class nsHTMLFrameElement : public nsGenericHTMLFrameElement,
                            public nsIDOMHTMLFrameElement
 {
 public:
   nsHTMLFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
                      mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
@@ -170,16 +174,16 @@ MapAttributesIntoRule(const nsMappedAttr
 NS_IMETHODIMP_(bool)
 nsHTMLFrameElement::IsAttributeMapped(const nsIAtom* aAttribute) const
 {
   static const MappedAttributeEntry* const map[] = {
     sScrollingAttributeMap,
     sCommonAttributeMap,
   };
   
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLFrameElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLHRElement.cpp
+++ b/content/html/content/src/nsHTMLHRElement.cpp
@@ -30,27 +30,31 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsGenericHTMLElement.h"
 #include "nsIDOMHTMLHRElement.h"
 
 #include "nsIDOMEventTarget.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsMappedAttributes.h"
 #include "nsRuleData.h"
 #include "nsCSSProps.h"
 
+using namespace mozilla;
+
 class nsHTMLHRElement : public nsGenericHTMLElement,
                         public nsIDOMHTMLHRElement
 {
 public:
   nsHTMLHRElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLHRElement();
 
   // nsISupports
@@ -325,17 +329,17 @@ nsHTMLHRElement::IsAttributeMapped(const
     { nsnull },
   };
   
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 nsMapRuleToAttributesFunc
 nsHTMLHRElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLHeadingElement.cpp
+++ b/content/html/content/src/nsHTMLHeadingElement.cpp
@@ -29,25 +29,30 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLHeadingElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsMappedAttributes.h"
 #include "nsRuleData.h"
 #include "mozAutoDocUpdate.h"
 
+using namespace mozilla;
+
 class nsHTMLHeadingElement : public nsGenericHTMLElement,
                              public nsIDOMHTMLHeadingElement
 {
 public:
   nsHTMLHeadingElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLHeadingElement();
 
   // nsISupports
@@ -134,17 +139,17 @@ MapAttributesIntoRule(const nsMappedAttr
 NS_IMETHODIMP_(bool)
 nsHTMLHeadingElement::IsAttributeMapped(const nsIAtom* aAttribute) const
 {
   static const MappedAttributeEntry* const map[] = {
     sDivAlignAttributeMap,
     sCommonAttributeMap
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 nsMapRuleToAttributesFunc
 nsHTMLHeadingElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLIFrameElement.cpp
+++ b/content/html/content/src/nsHTMLIFrameElement.cpp
@@ -29,28 +29,32 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLIFrameElement.h"
 #include "nsGenericHTMLElement.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMGetSVGDocument.h"
 #include "nsIDOMSVGDocument.h"
 #include "nsGkAtoms.h"
 #include "nsIDocument.h"
 #include "nsMappedAttributes.h"
 #include "nsDOMError.h"
 #include "nsRuleData.h"
 #include "nsStyleConsts.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 class nsHTMLIFrameElement : public nsGenericHTMLFrameElement
                           , public nsIDOMHTMLIFrameElement
                           , public nsIDOMGetSVGDocument
 {
 public:
   nsHTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
@@ -253,17 +257,17 @@ nsHTMLIFrameElement::IsAttributeMapped(c
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sScrollingAttributeMap,
     sImageAlignAttributeMap,
     sCommonAttributeMap,
   };
   
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 
 nsMapRuleToAttributesFunc
 nsHTMLIFrameElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
--- a/content/html/content/src/nsHTMLImageElement.cpp
+++ b/content/html/content/src/nsHTMLImageElement.cpp
@@ -29,16 +29,19 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLImageElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsImageLoadingContent.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsMappedAttributes.h"
@@ -395,17 +398,17 @@ nsHTMLImageElement::IsAttributeMapped(co
 {
   static const MappedAttributeEntry* const map[] = {
     sCommonAttributeMap,
     sImageMarginSizeAttributeMap,
     sImageBorderAttributeMap,
     sImageAlignAttributeMap
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 nsMapRuleToAttributesFunc
 nsHTMLImageElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -32,16 +32,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsHTMLInputElement.h"
 
 #include "nsIDOMHTMLInputElement.h"
 #include "nsITextControlElement.h"
 #include "nsIDOMNSEditableElement.h"
 #include "nsIRadioVisitor.h"
 #include "nsIPhonetic.h"
 
@@ -2602,17 +2604,17 @@ nsHTMLInputElement::IsAttributeMapped(co
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
     sImageMarginSizeAttributeMap,
     sImageBorderAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLInputElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
 
--- a/content/html/content/src/nsHTMLLIElement.cpp
+++ b/content/html/content/src/nsHTMLLIElement.cpp
@@ -29,24 +29,29 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLLIElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsMappedAttributes.h"
 #include "nsRuleData.h"
 
+using namespace mozilla;
+
 class nsHTMLLIElement : public nsGenericHTMLElement,
                         public nsIDOMHTMLLIElement
 {
 public:
   nsHTMLLIElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLLIElement();
 
   // nsISupports
@@ -173,17 +178,17 @@ nsHTMLLIElement::IsAttributeMapped(const
     { nsnull },
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 
 nsMapRuleToAttributesFunc
 nsHTMLLIElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLMediaElement.h"
 #include "nsIDOMHTMLSourceElement.h"
 #include "nsHTMLMediaElement.h"
 #include "nsTimeRanges.h"
 #include "nsGenericHTMLElement.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsGkAtoms.h"
@@ -1531,17 +1533,17 @@ static bool IsRawEnabled()
 {
   return Preferences::GetBool("media.raw.enabled");
 }
 
 static bool IsRawType(const nsACString& aType)
 {
   if (!IsRawEnabled())
     return false;
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gRawTypes); ++i) {
+  for (PRUint32 i = 0; i < ArrayLength(gRawTypes); ++i) {
     if (aType.EqualsASCII(gRawTypes[i]))
       return true;
   }
   return false;
 }
 #endif
 #ifdef MOZ_OGG
 // See http://www.rfc-editor.org/rfc/rfc5334.txt for the definitions
@@ -1564,17 +1566,17 @@ nsHTMLMediaElement::IsOggEnabled()
   return Preferences::GetBool("media.ogg.enabled");
 }
 
 bool
 nsHTMLMediaElement::IsOggType(const nsACString& aType)
 {
   if (!IsOggEnabled())
     return false;
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gOggTypes); ++i) {
+  for (PRUint32 i = 0; i < ArrayLength(gOggTypes); ++i) {
     if (aType.EqualsASCII(gOggTypes[i]))
       return true;
   }
   return false;
 }
 #endif
 
 #ifdef MOZ_WAVE
@@ -1599,17 +1601,17 @@ nsHTMLMediaElement::IsWaveEnabled()
   return Preferences::GetBool("media.wave.enabled");
 }
 
 bool
 nsHTMLMediaElement::IsWaveType(const nsACString& aType)
 {
   if (!IsWaveEnabled())
     return false;
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gWaveTypes); ++i) {
+  for (PRUint32 i = 0; i < ArrayLength(gWaveTypes); ++i) {
     if (aType.EqualsASCII(gWaveTypes[i]))
       return true;
   }
   return false;
 }
 #endif
 
 #ifdef MOZ_WEBM
@@ -1631,17 +1633,17 @@ nsHTMLMediaElement::IsWebMEnabled()
   return Preferences::GetBool("media.webm.enabled");
 }
 
 bool
 nsHTMLMediaElement::IsWebMType(const nsACString& aType)
 {
   if (!IsWebMEnabled())
     return false;
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gWebMTypes); ++i) {
+  for (PRUint32 i = 0; i < ArrayLength(gWebMTypes); ++i) {
     if (aType.EqualsASCII(gWebMTypes[i]))
       return true;
   }
   return false;
 }
 #endif
 
 /* static */
--- a/content/html/content/src/nsHTMLOListElement.cpp
+++ b/content/html/content/src/nsHTMLOListElement.cpp
@@ -29,26 +29,31 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLOListElement.h"
 #include "nsIDOMHTMLDListElement.h"
 #include "nsIDOMHTMLUListElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsMappedAttributes.h"
 #include "nsRuleData.h"
 
+using namespace mozilla;
+
 class nsHTMLSharedListElement : public nsGenericHTMLElement,
                                 public nsIDOMHTMLOListElement,
                                 public nsIDOMHTMLDListElement,
                                 public nsIDOMHTMLUListElement
 {
 public:
   nsHTMLSharedListElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLSharedListElement();
@@ -225,17 +230,17 @@ nsHTMLSharedListElement::IsAttributeMapp
       { nsnull }
     };
 
     static const MappedAttributeEntry* const map[] = {
       attributes,
       sCommonAttributeMap,
     };
 
-    return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+    return FindAttributeDependence(aAttribute, map, ArrayLength(map));
   }
 
   return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLSharedListElement::GetAttributeMappingFunction() const
 {
--- a/content/html/content/src/nsHTMLObjectElement.cpp
+++ b/content/html/content/src/nsHTMLObjectElement.cpp
@@ -31,31 +31,34 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsAutoPtr.h"
 #include "nsGenericHTMLElement.h"
 #include "nsObjectLoadingContent.h"
 #include "nsGkAtoms.h"
 #include "nsDOMError.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMSVGDocument.h"
 #include "nsIDOMGetSVGDocument.h"
 #include "nsIDOMHTMLObjectElement.h"
 #include "nsFormSubmission.h"
 #include "nsIObjectFrame.h"
 #include "nsNPAPIPluginInstance.h"
 #include "nsIConstraintValidation.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 class nsHTMLObjectElement : public nsGenericHTMLFormElement
                           , public nsObjectLoadingContent
                           , public nsIDOMHTMLObjectElement
                           , public nsIConstraintValidation
                           , public nsIDOMGetSVGDocument
 {
@@ -484,17 +487,17 @@ nsHTMLObjectElement::IsAttributeMapped(c
 {
   static const MappedAttributeEntry* const map[] = {
     sCommonAttributeMap,
     sImageMarginSizeAttributeMap,
     sImageBorderAttributeMap,
     sImageAlignAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 nsMapRuleToAttributesFunc
 nsHTMLObjectElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLParagraphElement.cpp
+++ b/content/html/content/src/nsHTMLParagraphElement.cpp
@@ -29,27 +29,31 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLParagraphElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsMappedAttributes.h"
 #include "nsRuleData.h"
 
+using namespace mozilla;
+
 // XXX missing nav attributes
 
-
 class nsHTMLParagraphElement : public nsGenericHTMLElement,
                                public nsIDOMHTMLParagraphElement
 {
 public:
   nsHTMLParagraphElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLParagraphElement();
 
   // nsISupports
@@ -137,17 +141,17 @@ MapAttributesIntoRule(const nsMappedAttr
 NS_IMETHODIMP_(bool)
 nsHTMLParagraphElement::IsAttributeMapped(const nsIAtom* aAttribute) const
 {
   static const MappedAttributeEntry* const map[] = {
     sDivAlignAttributeMap,
     sCommonAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 nsMapRuleToAttributesFunc
 nsHTMLParagraphElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLPreElement.cpp
+++ b/content/html/content/src/nsHTMLPreElement.cpp
@@ -29,24 +29,29 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLPreElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsMappedAttributes.h"
 #include "nsRuleData.h"
 
+using namespace mozilla;
+
 class nsHTMLPreElement : public nsGenericHTMLElement,
                          public nsIDOMHTMLPreElement
 {
 public:
   nsHTMLPreElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLPreElement();
 
   // nsISupports
@@ -183,16 +188,16 @@ nsHTMLPreElement::IsAttributeMapped(cons
     { nsnull },
   };
   
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLPreElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLSelectElement.cpp
+++ b/content/html/content/src/nsHTMLSelectElement.cpp
@@ -32,16 +32,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsHTMLSelectElement.h"
 
 #include "nsHTMLOptionElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsLayoutUtils.h"
@@ -66,16 +68,17 @@
 #include "nsDOMError.h"
 #include "nsServiceManagerUtils.h"
 #include "nsRuleData.h"
 #include "nsEventDispatcher.h"
 #include "mozilla/dom/Element.h"
 #include "mozAutoDocUpdate.h"
 #include "dombindings.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 NS_IMPL_ISUPPORTS1(nsSelectState, nsSelectState)
 NS_DEFINE_STATIC_IID_ACCESSOR(nsSelectState, NS_SELECT_STATE_IID)
 
 //----------------------------------------------------------------------
 //
 // nsSafeOptionListMutation
@@ -1518,17 +1521,17 @@ nsHTMLSelectElement::GetAttributeChangeH
 NS_IMETHODIMP_(bool)
 nsHTMLSelectElement::IsAttributeMapped(const nsIAtom* aAttribute) const
 {
   static const MappedAttributeEntry* const map[] = {
     sCommonAttributeMap,
     sImageAlignAttributeMap
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLSelectElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
 
--- a/content/html/content/src/nsHTMLSharedElement.cpp
+++ b/content/html/content/src/nsHTMLSharedElement.cpp
@@ -30,30 +30,33 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLParamElement.h"
 #include "nsIDOMHTMLBaseElement.h"
 #include "nsIDOMHTMLDirectoryElement.h"
 #include "nsIDOMHTMLQuoteElement.h"
 #include "nsIDOMHTMLHeadElement.h"
 #include "nsIDOMHTMLHtmlElement.h"
 #include "nsGenericHTMLElement.h"
 
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsRuleData.h"
 #include "nsMappedAttributes.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
 
 // XXX nav4 has type= start= (same as OL/UL)
 extern nsAttrValue::EnumTable kListTypeTable[];
 
 class nsHTMLSharedElement : public nsGenericHTMLElement,
                             public nsIDOMHTMLParamElement,
                             public nsIDOMHTMLBaseElement,
                             public nsIDOMHTMLDirectoryElement,
@@ -306,17 +309,17 @@ nsHTMLSharedElement::IsAttributeMapped(c
       { nsnull} 
     };
   
     static const MappedAttributeEntry* const map[] = {
       attributes,
       sCommonAttributeMap,
     };
 
-    return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+    return FindAttributeDependence(aAttribute, map, ArrayLength(map));
   }
 
   return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
 }
 
 static void
 SetBaseURIUsingFirstBaseWithHref(nsIDocument* aDocument, nsIContent* aMustMatch)
 {
--- a/content/html/content/src/nsHTMLSharedObjectElement.cpp
+++ b/content/html/content/src/nsHTMLSharedObjectElement.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsGenericHTMLElement.h"
 #include "nsObjectLoadingContent.h"
 #include "nsGkAtoms.h"
 #include "nsDOMError.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMHTMLAppletElement.h"
 #include "nsIDOMHTMLEmbedElement.h"
@@ -50,16 +52,17 @@
 
 // XXX this is to get around conflicts with windows.h defines
 // introduced through jni.h
 #ifdef XP_WIN
 #undef GetClassName
 #undef GetObject
 #endif
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 class nsHTMLSharedObjectElement : public nsGenericHTMLElement
                                 , public nsObjectLoadingContent
                                 , public nsIDOMHTMLAppletElement
                                 , public nsIDOMHTMLEmbedElement
                                 , public nsIDOMGetSVGDocument
 {
@@ -433,17 +436,17 @@ nsHTMLSharedObjectElement::IsAttributeMa
 {
   static const MappedAttributeEntry* const map[] = {
     sCommonAttributeMap,
     sImageMarginSizeAttributeMap,
     sImageBorderAttributeMap,
     sImageAlignAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 nsMapRuleToAttributesFunc
 nsHTMLSharedObjectElement::GetAttributeMappingFunction() const
 {
   if (mNodeInfo->Equals(nsGkAtoms::embed)) {
     return &EmbedMapAttributesIntoRule;
--- a/content/html/content/src/nsHTMLTableCaptionElement.cpp
+++ b/content/html/content/src/nsHTMLTableCaptionElement.cpp
@@ -29,24 +29,29 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLTableCaptionElem.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsMappedAttributes.h"
 #include "nsRuleData.h"
 
+using namespace mozilla;
+
 class nsHTMLTableCaptionElement :  public nsGenericHTMLElement,
                                    public nsIDOMHTMLTableCaptionElement
 {
 public:
   nsHTMLTableCaptionElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLTableCaptionElement();
 
   // nsISupports
@@ -156,17 +161,17 @@ nsHTMLTableCaptionElement::IsAttributeMa
     { nsnull }
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 
 nsMapRuleToAttributesFunc
 nsHTMLTableCaptionElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
--- a/content/html/content/src/nsHTMLTableCellElement.cpp
+++ b/content/html/content/src/nsHTMLTableCellElement.cpp
@@ -29,31 +29,36 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLTableCellElement.h"
 #include "nsIDOMHTMLTableRowElement.h"
 #include "nsHTMLTableElement.h"
 #include "nsIDOMHTMLCollection.h"
 #include "nsIDOMEventTarget.h"
 #include "nsMappedAttributes.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsRuleData.h"
 #include "nsRuleWalker.h"
 #include "nsIDocument.h"
 #include "celldata.h"
 
+using namespace mozilla;
+
 class nsHTMLTableCellElement : public nsGenericHTMLElement,
                                public nsIDOMHTMLTableCellElement
 {
 public:
   nsHTMLTableCellElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLTableCellElement();
 
   // nsISupports
@@ -422,16 +427,16 @@ nsHTMLTableCellElement::IsAttributeMappe
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
     sBackgroundAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLTableCellElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLTableColElement.cpp
+++ b/content/html/content/src/nsHTMLTableColElement.cpp
@@ -29,24 +29,29 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLTableColElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsMappedAttributes.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsRuleData.h"
 
+using namespace mozilla;
+
 // use the same protection as ancient code did 
 // http://lxr.mozilla.org/classic/source/lib/layout/laytable.c#46
 #define MAX_COLSPAN 1000
 
 class nsHTMLTableColElement : public nsGenericHTMLElement,
                               public nsIDOMHTMLTableColElement
 {
 public:
@@ -222,17 +227,17 @@ nsHTMLTableColElement::IsAttributeMapped
     { nsnull }
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 nsMapRuleToAttributesFunc
 nsHTMLTableColElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLTableElement.cpp
+++ b/content/html/content/src/nsHTMLTableElement.cpp
@@ -29,16 +29,19 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsHTMLTableElement.h"
 #include "nsIDOMHTMLTableCaptionElem.h"
 #include "nsIDOMHTMLTableSectionElem.h"
 #include "nsCOMPtr.h"
 #include "nsIDOMEventTarget.h"
 #include "nsDOMError.h"
 #include "nsContentList.h"
 #include "nsGenericHTMLElement.h"
@@ -51,16 +54,18 @@
 #include "nsIDocument.h"
 #include "nsContentUtils.h"
 #include "nsIDOMElement.h"
 #include "nsGenericHTMLElement.h"
 #include "nsIHTMLCollection.h"
 #include "nsHTMLStyleSheet.h"
 #include "dombindings.h"
 
+using namespace mozilla;
+
 /* ------------------------------ TableRowsCollection -------------------------------- */
 /**
  * This class provides a late-bound collection of rows in a table.
  * mParent is NOT ref-counted to avoid circular references
  */
 class TableRowsCollection : public nsIHTMLCollection,
                             public nsWrapperCache
 {
@@ -1151,17 +1156,17 @@ nsHTMLTableElement::IsAttributeMapped(co
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
     sBackgroundAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLTableElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
 
--- a/content/html/content/src/nsHTMLTableRowElement.cpp
+++ b/content/html/content/src/nsHTMLTableRowElement.cpp
@@ -29,31 +29,36 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLTableRowElement.h"
 #include "nsIDOMHTMLTableElement.h"
 #include "nsIDOMHTMLTableSectionElem.h"
 #include "nsIDOMHTMLTableCellElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsDOMError.h"
 #include "nsMappedAttributes.h"
 #include "nsGenericHTMLElement.h"
 #include "nsContentList.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsHTMLParts.h"
 #include "nsRuleData.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
+
 class nsHTMLTableRowElement : public nsGenericHTMLElement,
                               public nsIDOMHTMLTableRowElement
 {
 public:
   nsHTMLTableRowElement(already_AddRefed<nsINodeInfo> aNodeInfo);
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
@@ -452,17 +457,17 @@ nsHTMLTableRowElement::IsAttributeMapped
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
     sBackgroundAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLTableRowElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
 
--- a/content/html/content/src/nsHTMLTableSectionElement.cpp
+++ b/content/html/content/src/nsHTMLTableSectionElement.cpp
@@ -29,29 +29,34 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLTableSectionElem.h"
 #include "nsIDOMEventTarget.h"
 #include "nsMappedAttributes.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsHTMLParts.h"
 #include "nsStyleConsts.h"
 #include "nsContentList.h"
 #include "nsRuleData.h"
 #include "nsDOMError.h"
 #include "nsIDocument.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
+
 // you will see the phrases "rowgroup" and "section" used interchangably
 
 class nsHTMLTableSectionElement : public nsGenericHTMLElement,
                                   public nsIDOMHTMLTableSectionElement
 {
 public:
   nsHTMLTableSectionElement(already_AddRefed<nsINodeInfo> aNodeInfo);
 
@@ -316,17 +321,17 @@ nsHTMLTableSectionElement::IsAttributeMa
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap,
     sBackgroundAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 
 nsMapRuleToAttributesFunc
 nsHTMLTableSectionElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
--- a/content/html/content/src/nsHTMLTextAreaElement.cpp
+++ b/content/html/content/src/nsHTMLTextAreaElement.cpp
@@ -32,16 +32,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLTextAreaElement.h"
 #include "nsITextControlElement.h"
 #include "nsIDOMNSEditableElement.h"
 #include "nsIControllers.h"
 #include "nsFocusManager.h"
 #include "nsPIDOMWindow.h"
 #include "nsContentCID.h"
 #include "nsCOMPtr.h"
@@ -76,16 +78,17 @@
 #include "mozAutoDocUpdate.h"
 #include "nsISupportsPrimitives.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsIConstraintValidation.h"
 #include "nsHTMLFormElement.h"
 
 #include "nsTextEditorState.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 static NS_DEFINE_CID(kXULControllersCID,  NS_XULCONTROLLERS_CID);
 
 #define NS_NO_CONTENT_DISPATCH (1 << 0)
 
 class nsHTMLTextAreaElement : public nsGenericHTMLFormElement,
                               public nsIDOMHTMLTextAreaElement,
@@ -660,17 +663,17 @@ nsHTMLTextAreaElement::GetAttributeChang
 NS_IMETHODIMP_(bool)
 nsHTMLTextAreaElement::IsAttributeMapped(const nsIAtom* aAttribute) const
 {
   static const MappedAttributeEntry* const map[] = {
     sDivAlignAttributeMap,
     sCommonAttributeMap,
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLTextAreaElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
 
--- a/content/html/content/src/nsHTMLVideoElement.cpp
+++ b/content/html/content/src/nsHTMLVideoElement.cpp
@@ -30,16 +30,19 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIDOMHTMLVideoElement.h"
 #include "nsIDOMHTMLSourceElement.h"
 #include "nsHTMLVideoElement.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsSize.h"
 #include "nsIFrame.h"
 #include "nsIDocument.h"
@@ -59,16 +62,17 @@
 #include "jsapi.h"
 
 #include "nsITimer.h"
 
 #include "nsEventDispatcher.h"
 #include "nsIDOMProgressEvent.h"
 #include "nsMediaError.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Video)
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLVideoElement, nsHTMLMediaElement)
 NS_IMPL_RELEASE_INHERITED(nsHTMLVideoElement, nsHTMLMediaElement)
 
 DOMCI_NODE_DATA(HTMLVideoElement, nsHTMLVideoElement)
@@ -145,17 +149,17 @@ nsHTMLVideoElement::IsAttributeMapped(co
     { nsnull }
   };
 
   static const MappedAttributeEntry* const map[] = {
     attributes,
     sCommonAttributeMap
   };
 
-  return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
+  return FindAttributeDependence(aAttribute, map, ArrayLength(map));
 }
 
 nsMapRuleToAttributesFunc
 nsHTMLVideoElement::GetAttributeMappingFunction() const
 {
   return &MapAttributesIntoRule;
 }
 
--- a/content/html/document/src/nsHTMLContentSink.cpp
+++ b/content/html/document/src/nsHTMLContentSink.cpp
@@ -35,16 +35,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsContentSink.h"
 #include "nsCOMPtr.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsIHTMLContentSink.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIParser.h"
@@ -1474,43 +1476,43 @@ HTMLContentSink::~HTMLContentSink()
   if (mCurrentContext == mHeadContext) {
     mCurrentContext = nsnull;
   }
 
   delete mCurrentContext;
 
   delete mHeadContext;
 
-  for (i = 0; PRUint32(i) < NS_ARRAY_LENGTH(mNodeInfoCache); ++i) {
+  for (i = 0; PRUint32(i) < ArrayLength(mNodeInfoCache); ++i) {
     NS_IF_RELEASE(mNodeInfoCache[i]);
   }
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLContentSink)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLContentSink, nsContentSink)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mHTMLDocument)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRoot)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mBody)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFrameset)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mHead)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCurrentForm)
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(tmp->mNodeInfoCache); ++i) {
+  for (PRUint32 i = 0; i < ArrayLength(tmp->mNodeInfoCache); ++i) {
     NS_IF_RELEASE(tmp->mNodeInfoCache[i]);
   }
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLContentSink,
                                                   nsContentSink)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mHTMLDocument)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRoot)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mBody)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFrameset)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mHead)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentForm)
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(tmp->mNodeInfoCache); ++i) {
+  for (PRUint32 i = 0; i < ArrayLength(tmp->mNodeInfoCache); ++i) {
     NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mNodeInfoCache[i]");
     cb.NoteXPCOMChild(tmp->mNodeInfoCache[i]);
   }
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLContentSink)
   NS_INTERFACE_TABLE_BEGIN
     NS_INTERFACE_TABLE_ENTRY(HTMLContentSink, nsIContentSink)
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -32,16 +32,19 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsICharsetAlias.h"
 
 #include "nsCOMPtr.h"
 #include "nsXPIDLString.h"
 #include "nsPrintfCString.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsHTMLDocument.h"
@@ -3183,25 +3186,25 @@ ConvertToMidasInternalCommandInner(const
             const PRUnichar *end = inParam.EndReading();
             if (start != end && *start == '<' && *(end - 1) == '>') {
               ++start;
               --end;
             }
 
             NS_ConvertUTF16toUTF8 convertedParam(Substring(start, end));
             PRUint32 j;
-            for (j = 0; j < NS_ARRAY_LENGTH(gBlocks); ++j) {
+            for (j = 0; j < ArrayLength(gBlocks); ++j) {
               if (convertedParam.Equals(gBlocks[j],
                                         nsCaseInsensitiveCStringComparator())) {
                 outParam.Assign(gBlocks[j]);
                 break;
               }
             }
 
-            return j != NS_ARRAY_LENGTH(gBlocks);
+            return j != ArrayLength(gBlocks);
           }
           else {
             CopyUTF16toUTF8(inParam, outParam);
           }
         }
       }
     }
   } // end else for useNewParam (do convert existing param)
--- a/content/mathml/content/src/nsMathMLElement.cpp
+++ b/content/mathml/content/src/nsMathMLElement.cpp
@@ -33,30 +33,34 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsMathMLElement.h"
 #include "nsDOMClassInfoID.h" // for eDOMClassInfo_MathElement_id.
 #include "nsGkAtoms.h"
 #include "nsCRT.h"
 #include "nsRuleData.h"
 #include "nsCSSValue.h"
 #include "nsMappedAttributes.h"
 #include "nsStyleConsts.h"
 #include "nsIDocument.h"
 #include "nsEventStates.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "mozAutoDocUpdate.h"
 
+using namespace mozilla;
+
 //----------------------------------------------------------------------
 // nsISupports methods:
 
 DOMCI_NODE_DATA(MathMLElement, nsMathMLElement)
 
 NS_INTERFACE_TABLE_HEAD(nsMathMLElement)
   NS_NODE_OFFSET_AND_INTERFACE_TABLE_BEGIN(nsMathMLElement)
     NS_INTERFACE_TABLE_ENTRY(nsMathMLElement, nsIDOMNode)
@@ -172,21 +176,21 @@ nsMathMLElement::IsAttributeMapped(const
   };
   
   // We don't support mglyph (yet).
   nsIAtom* tag = Tag();
   if (tag == nsGkAtoms::ms_ || tag == nsGkAtoms::mi_ ||
       tag == nsGkAtoms::mn_ || tag == nsGkAtoms::mo_ ||
       tag == nsGkAtoms::mtext_ || tag == nsGkAtoms::mspace_)
     return FindAttributeDependence(aAttribute, tokenMap,
-                                   NS_ARRAY_LENGTH(tokenMap));
+                                   ArrayLength(tokenMap));
   if (tag == nsGkAtoms::mstyle_ ||
       tag == nsGkAtoms::math)
     return FindAttributeDependence(aAttribute, mstyleMap,
-                                   NS_ARRAY_LENGTH(mstyleMap));
+                                   ArrayLength(mstyleMap));
 
   if (tag == nsGkAtoms::maction_ ||
       tag == nsGkAtoms::maligngroup_ ||
       tag == nsGkAtoms::malignmark_ ||
       tag == nsGkAtoms::menclose_ ||
       tag == nsGkAtoms::merror_ ||
       tag == nsGkAtoms::mfenced_ ||
       tag == nsGkAtoms::mfrac_ ||
@@ -202,17 +206,17 @@ nsMathMLElement::IsAttributeMapped(const
       tag == nsGkAtoms::msup_ ||
       tag == nsGkAtoms::mtable_ ||
       tag == nsGkAtoms::mtd_ ||
       tag == nsGkAtoms::mtr_ ||
       tag == nsGkAtoms::munder_ ||
       tag == nsGkAtoms::munderover_ ||
       tag == nsGkAtoms::none) {
     return FindAttributeDependence(aAttribute, commonPresMap,
-                                   NS_ARRAY_LENGTH(commonPresMap));
+                                   ArrayLength(commonPresMap));
   }
 
   return PR_FALSE;
 }
 
 nsMapRuleToAttributesFunc
 nsMathMLElement::GetAttributeMappingFunction() const
 {
@@ -400,17 +404,17 @@ nsMathMLElement::MapMathMLAttributesInto
       if (!ParseNumericValue(str, *fontSize, 0) &&
           parseSizeKeywords) {
         static const char sizes[3][7] = { "small", "normal", "big" };
         static const PRInt32 values[NS_ARRAY_LENGTH(sizes)] = {
           NS_STYLE_FONT_SIZE_SMALL, NS_STYLE_FONT_SIZE_MEDIUM,
           NS_STYLE_FONT_SIZE_LARGE
         };
         str.CompressWhitespace();
-        for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(sizes); ++i) {
+        for (PRUint32 i = 0; i < ArrayLength(sizes); ++i) {
           if (str.EqualsASCII(sizes[i])) {
             fontSize->SetIntValue(values[i], eCSSUnit_Enumerated);
             break;
           }
         }
       }
     }
 
--- a/content/svg/content/src/DOMSVGPathSeg.cpp
+++ b/content/svg/content/src/DOMSVGPathSeg.cpp
@@ -29,16 +29,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "DOMSVGPathSeg.h"
 #include "DOMSVGPathSegList.h"
 #include "SVGPathSegUtils.h"
 #include "SVGAnimatedPathSegList.h"
 #include "nsSVGElement.h"
 #include "nsIDOMSVGPathSeg.h"
 #include "nsDOMError.h"
 
@@ -167,17 +169,17 @@ DOMSVGPathSeg::IndexIsValid()
 }
 #endif
 
 
 ////////////////////////////////////////////////////////////////////////
 // Implementation of DOMSVGPathSeg sub-classes below this point
 
 #define CHECK_ARG_COUNT_IN_SYNC(segType)                                      \
-          NS_ABORT_IF_FALSE(NS_ARRAY_LENGTH(mArgs) ==                         \
+          NS_ABORT_IF_FALSE(ArrayLength(mArgs) ==                         \
             SVGPathSegUtils::ArgCountForType(PRUint32(segType)) ||            \
             PRUint32(segType) == nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH,         \
             "Arg count/array size out of sync")
 
 #define IMPL_SVGPATHSEG_SUBCLASS_COMMON(segName, segType)                     \
   DOMSVGPathSeg##segName(const float *aArgs)                                  \
     : DOMSVGPathSeg()                                                         \
   {                                                                           \
--- a/content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp
+++ b/content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "SVGAnimatedPreserveAspectRatio.h"
 #include "nsWhitespaceTokenizer.h"
 #ifdef MOZ_SMIL
 #include "nsSMILValue.h"
 #include "SMILEnumType.h"
 #endif // MOZ_SMIL
 
 using namespace mozilla;
@@ -97,17 +99,17 @@ static const char *sAlignStrings[] =
   { "none", "xMinYMin", "xMidYMin", "xMaxYMin", "xMinYMid", "xMidYMid",
     "xMaxYMid", "xMinYMax", "xMidYMax", "xMaxYMax" };
 
 static const char *sMeetOrSliceStrings[] = { "meet", "slice" };
 
 static PRUint16
 GetAlignForString(const nsAString &aAlignString)
 {
-  for (PRUint32 i = 0 ; i < NS_ARRAY_LENGTH(sAlignStrings) ; i++) {
+  for (PRUint32 i = 0 ; i < ArrayLength(sAlignStrings) ; i++) {
     if (aAlignString.EqualsASCII(sAlignStrings[i])) {
       return (i + nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE);
     }
   }
 
   return nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_UNKNOWN;
 }
 
@@ -122,17 +124,17 @@ GetAlignString(nsAString& aAlignString, 
   aAlignString.AssignASCII(
     sAlignStrings[aAlign -
                   nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE]);
 }
 
 static PRUint16
 GetMeetOrSliceForString(const nsAString &aMeetOrSlice)
 {
-  for (PRUint32 i = 0 ; i < NS_ARRAY_LENGTH(sMeetOrSliceStrings) ; i++) {
+  for (PRUint32 i = 0 ; i < ArrayLength(sMeetOrSliceStrings) ; i++) {
     if (aMeetOrSlice.EqualsASCII(sMeetOrSliceStrings[i])) {
       return (i + nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET);
     }
   }
 
   return nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_UNKNOWN;
 }
 
--- a/content/svg/content/src/SVGLength.cpp
+++ b/content/svg/content/src/SVGLength.cpp
@@ -29,16 +29,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "SVGLength.h"
 #include "nsSVGElement.h"
 #include "nsSVGSVGElement.h"
 #include "nsString.h"
 #include "nsSVGUtils.h"
 #include "nsTextFormatter.h"
 #include "prdtoa.h"
 #include "nsMathUtils.h"
@@ -266,17 +268,17 @@ GetUnitString(nsAString& unit, PRUint16 
 static PRUint16
 GetUnitTypeForString(const char* unitStr)
 {
   if (!unitStr || *unitStr == '\0')
     return nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER;
 
   nsCOMPtr<nsIAtom> unitAtom = do_GetAtom(unitStr);
 
-  for (PRUint32 i = 1 ; i < NS_ARRAY_LENGTH(unitMap) ; i++) {
+  for (PRUint32 i = 1 ; i < ArrayLength(unitMap) ; i++) {
     if (unitMap[i] && *unitMap[i] == unitAtom) {
       return i;
     }
   }
   return nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN;
 }
 
 } // namespace mozilla
--- a/content/svg/content/src/SVGNumberList.cpp
+++ b/content/svg/content/src/SVGNumberList.cpp
@@ -29,16 +29,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "SVGNumberList.h"
 #include "SVGAnimatedNumberList.h"
 #include "nsSVGElement.h"
 #include "nsDOMError.h"
 #include "nsString.h"
 #include "nsSVGUtils.h"
 #include "string.h"
 #include "prdtoa.h"
@@ -63,17 +65,17 @@ void
 SVGNumberList::GetValueAsString(nsAString& aValue) const
 {
   aValue.Truncate();
   PRUnichar buf[24];
   PRUint32 last = mNumbers.Length() - 1;
   for (PRUint32 i = 0; i < mNumbers.Length(); ++i) {
     // Would like to use aValue.AppendPrintf("%f", mNumbers[i]), but it's not
     // possible to always avoid trailing zeros.
-    nsTextFormatter::snprintf(buf, NS_ARRAY_LENGTH(buf),
+    nsTextFormatter::snprintf(buf, ArrayLength(buf),
                               NS_LITERAL_STRING("%g").get(),
                               double(mNumbers[i]));
     // We ignore OOM, since it's not useful for us to return an error.
     aValue.Append(buf);
     if (i != last) {
       aValue.Append(' ');
     }
   }
--- a/content/svg/content/src/SVGPointList.cpp
+++ b/content/svg/content/src/SVGPointList.cpp
@@ -29,16 +29,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "SVGPointList.h"
 #include "SVGAnimatedPointList.h"
 #include "nsSVGElement.h"
 #include "nsDOMError.h"
 #include "nsString.h"
 #include "nsSVGUtils.h"
 #include "string.h"
 #include "prdtoa.h"
@@ -63,17 +65,17 @@ void
 SVGPointList::GetValueAsString(nsAString& aValue) const
 {
   aValue.Truncate();
   PRUnichar buf[50];
   PRUint32 last = mItems.Length() - 1;
   for (PRUint32 i = 0; i < mItems.Length(); ++i) {
     // Would like to use aValue.AppendPrintf("%f,%f", item.mX, item.mY),
     // but it's not possible to always avoid trailing zeros.
-    nsTextFormatter::snprintf(buf, NS_ARRAY_LENGTH(buf),
+    nsTextFormatter::snprintf(buf, ArrayLength(buf),
                               NS_LITERAL_STRING("%g,%g").get(),
                               double(mItems[i].mX), double(mItems[i].mY));
     // We ignore OOM, since it's not useful for us to return an error.
     aValue.Append(buf);
     if (i != last) {
       aValue.Append(' ');
     }
   }
--- a/content/svg/content/src/SVGTransformListParser.cpp
+++ b/content/svg/content/src/SVGTransformListParser.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "SVGTransformListParser.h"
 #include "SVGTransform.h"
 #include "prdtoa.h"
 #include "nsDOMError.h"
 #include "nsGkAtoms.h"
 #include "nsReadableUtils.h"
 #include "nsCRT.h"
 #include "nsContentUtils.h"
@@ -230,17 +232,17 @@ SVGTransformListParser::MatchNumberArgum
 nsresult
 SVGTransformListParser::MatchTranslate()
 {
   GetNextToken();
 
   float t[2];
   PRUint32 count;
 
-  ENSURE_MATCHED(MatchNumberArguments(t, NS_ARRAY_LENGTH(t), &count));
+  ENSURE_MATCHED(MatchNumberArguments(t, ArrayLength(t), &count));
 
   switch (count) {
     case 1:
       t[1] = 0.f;
       // fall-through
     case 2:
     {
       SVGTransform* transform = mTransforms.AppendElement();
@@ -259,17 +261,17 @@ SVGTransformListParser::MatchTranslate()
 nsresult
 SVGTransformListParser::MatchScale()
 {
   GetNextToken();
 
   float s[2];
   PRUint32 count;
 
-  ENSURE_MATCHED(MatchNumberArguments(s, NS_ARRAY_LENGTH(s), &count));
+  ENSURE_MATCHED(MatchNumberArguments(s, ArrayLength(s), &count));
 
   switch (count) {
     case 1:
       s[1] = s[0];
       // fall-through
     case 2:
     {
       SVGTransform* transform = mTransforms.AppendElement();
@@ -288,17 +290,17 @@ SVGTransformListParser::MatchScale()
 nsresult
 SVGTransformListParser::MatchRotate()
 {
   GetNextToken();
 
   float r[3];
   PRUint32 count;
 
-  ENSURE_MATCHED(MatchNumberArguments(r, NS_ARRAY_LENGTH(r), &count));
+  ENSURE_MATCHED(MatchNumberArguments(r, ArrayLength(r), &count));
 
   switch (count) {
     case 1:
       r[1] = r[2] = 0.f;
       // fall-through
     case 3:
     {
       SVGTransform* transform = mTransforms.AppendElement();
@@ -361,17 +363,17 @@ SVGTransformListParser::MatchSkewY()
 nsresult
 SVGTransformListParser::MatchMatrix()
 {
   GetNextToken();
 
   float m[6];
   PRUint32 count;
 
-  ENSURE_MATCHED(MatchNumberArguments(m, NS_ARRAY_LENGTH(m), &count));
+  ENSURE_MATCHED(MatchNumberArguments(m, ArrayLength(m), &count));
 
   if (count != 6) {
     return NS_ERROR_FAILURE;
   }
 
   SVGTransform* transform = mTransforms.AppendElement();
   NS_ENSURE_TRUE(transform, NS_ERROR_OUT_OF_MEMORY);
   transform->SetMatrix(gfxMatrix(m[0], m[1], m[2], m[3], m[4], m[5]));
--- a/content/svg/content/src/nsSVGAElement.cpp
+++ b/content/svg/content/src/nsSVGAElement.cpp
@@ -30,26 +30,30 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGAElement.h"
 #include "nsSVGGraphicElement.h"
 #include "nsIDOMSVGAElement.h"
 #include "nsIDOMSVGURIReference.h"
 #include "nsILink.h"
 #include "nsSVGString.h"
 #include "nsCOMPtr.h"
 #include "nsGkAtoms.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
+
 nsSVGElement::StringInfo nsSVGAElement::sStringInfo[2] =
 {
   { &nsGkAtoms::href, kNameSpaceID_XLink, PR_TRUE },
   { &nsGkAtoms::target, kNameSpaceID_None, PR_TRUE }
 };
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(A)
 
@@ -184,17 +188,17 @@ nsSVGAElement::IsAttributeMapped(const n
     sFontSpecificationMap,
     sGradientStopMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGAElementBase::IsAttributeMapped(name);
 }
 
 bool
 nsSVGAElement::IsFocusable(PRInt32 *aTabIndex, bool aWithMouse)
 {
   nsCOMPtr<nsIURI> uri;
   if (IsLink(getter_AddRefs(uri))) {
@@ -330,10 +334,10 @@ nsSVGAElement::UnsetAttr(PRInt32 aNameSp
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::StringAttributesInfo
 nsSVGAElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
--- a/content/svg/content/src/nsSVGAltGlyphElement.cpp
+++ b/content/svg/content/src/nsSVGAltGlyphElement.cpp
@@ -27,23 +27,27 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsGkAtoms.h"
 #include "nsIDOMSVGAltGlyphElement.h"
 #include "nsIDOMSVGURIReference.h"
 #include "nsSVGString.h"
 #include "nsSVGTextPositioningElement.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
+
 typedef nsSVGTextPositioningElement nsSVGAltGlyphElementBase;
 
 class nsSVGAltGlyphElement : public nsSVGAltGlyphElementBase, // = nsIDOMSVGTextPositioningElement
                              public nsIDOMSVGAltGlyphElement,
                              public nsIDOMSVGURIReference
 {
 protected:
   friend nsresult NS_NewSVGAltGlyphElement(nsIContent **aResult,
@@ -168,27 +172,27 @@ nsSVGAltGlyphElement::IsAttributeMapped(
   static const MappedAttributeEntry* const map[] = {
     sColorMap,
     sFillStrokeMap,
     sFontSpecificationMap,
     sGraphicsMap,
     sTextContentElementsMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGAltGlyphElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement overrides
 
 bool
 nsSVGAltGlyphElement::IsEventName(nsIAtom* aName)
 {
   return nsContentUtils::IsEventAttributeName(aName, EventNameType_SVGGraphic);
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGAltGlyphElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
--- a/content/svg/content/src/nsSVGAngle.cpp
+++ b/content/svg/content/src/nsSVGAngle.cpp
@@ -29,16 +29,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGAngle.h"
 #include "prdtoa.h"
 #include "nsTextFormatter.h"
 #include "nsSVGUtils.h"
 #include "nsSVGMarkerElement.h"
 #include "nsMathUtils.h"
 #include "nsContentUtils.h" // NS_ENSURE_FINITE
 #ifdef MOZ_SMIL
@@ -186,17 +188,17 @@ GetUnitString(nsAString& unit, PRUint16 
 static PRUint16
 GetUnitTypeForString(const char* unitStr)
 {
   if (!unitStr || *unitStr == '\0') 
     return nsIDOMSVGAngle::SVG_ANGLETYPE_UNSPECIFIED;
                    
   nsCOMPtr<nsIAtom> unitAtom = do_GetAtom(unitStr);
 
-  for (PRUint32 i = 0 ; i < NS_ARRAY_LENGTH(unitMap) ; i++) {
+  for (PRUint32 i = 0 ; i < ArrayLength(unitMap) ; i++) {
     if (unitMap[i] && *unitMap[i] == unitAtom) {
       return i;
     }
   }
 
   return nsIDOMSVGAngle::SVG_ANGLETYPE_UNKNOWN;
 }
 
--- a/content/svg/content/src/nsSVGCircleElement.cpp
+++ b/content/svg/content/src/nsSVGCircleElement.cpp
@@ -31,23 +31,27 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGPathGeometryElement.h"
 #include "nsIDOMSVGCircleElement.h"
 #include "nsSVGLength2.h"
 #include "nsGkAtoms.h"
 #include "nsSVGUtils.h"
 #include "gfxContext.h"
 
+using namespace mozilla;
+
 typedef nsSVGPathGeometryElement nsSVGCircleElementBase;
 
 class nsSVGCircleElement : public nsSVGCircleElementBase,
                            public nsIDOMSVGCircleElement
 {
 protected:
   friend nsresult NS_NewSVGCircleElement(nsIContent **aResult,
                                          already_AddRefed<nsINodeInfo> aNodeInfo);
@@ -137,17 +141,17 @@ NS_IMETHODIMP nsSVGCircleElement::GetR(n
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthAttributesInfo
 nsSVGCircleElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 //----------------------------------------------------------------------
 // nsSVGPathGeometryElement methods
 
 void
 nsSVGCircleElement::ConstructPath(gfxContext *aCtx)
 {
--- a/content/svg/content/src/nsSVGClipPathElement.cpp
+++ b/content/svg/content/src/nsSVGClipPathElement.cpp
@@ -29,19 +29,23 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGClipPathElement.h"
 #include "nsGkAtoms.h"
 
+using namespace mozilla;
+
 nsSVGElement::EnumInfo nsSVGClipPathElement::sEnumInfo[1] =
 {
   { &nsGkAtoms::clipPathUnits,
     sSVGUnitTypesMap,
     nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE
   }
 };
 
@@ -75,16 +79,16 @@ NS_IMETHODIMP nsSVGClipPathElement::GetC
 {
   return mEnumAttributes[CLIPPATHUNITS].ToDOMAnimatedEnum(aClipPathUnits, this);
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGClipPathElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGClipPathElement)
 
--- a/content/svg/content/src/nsSVGDefsElement.cpp
+++ b/content/svg/content/src/nsSVGDefsElement.cpp
@@ -31,19 +31,23 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGGraphicElement.h"
 #include "nsIDOMSVGDefsElement.h"
 
+using namespace mozilla;
+
 typedef nsSVGGraphicElement nsSVGDefsElementBase;
 
 class nsSVGDefsElement : public nsSVGDefsElementBase,
                          public nsIDOMSVGDefsElement
 {
 protected:
   friend nsresult NS_NewSVGDefsElement(nsIContent **aResult,
                                        already_AddRefed<nsINodeInfo> aNodeInfo);
@@ -117,11 +121,11 @@ nsSVGDefsElement::IsAttributeMapped(cons
     sFontSpecificationMap,
     sGradientStopMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGDefsElementBase::IsAttributeMapped(name);
 }
--- a/content/svg/content/src/nsSVGElement.cpp
+++ b/content/svg/content/src/nsSVGElement.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGElement.h"
 #include "nsSVGSVGElement.h"
 #include "nsSVGSwitchElement.h"
 #include "nsIDocument.h"
 #include "nsRange.h"
 #include "nsIDOMAttr.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIDOMMutationEvent.h"
@@ -2141,17 +2143,17 @@ nsSVGElement::ReportAttributeParseFailur
                                           nsIAtom* aAttribute,
                                           const nsAString& aValue)
 {
   const nsAFlatString& attributeValue = PromiseFlatString(aValue);
   const PRUnichar *strings[] = { aAttribute->GetUTF16String(),
                                  attributeValue.get() };
   return nsSVGUtils::ReportToConsole(aDocument,
                                      "AttributeParseWarning",
-                                     strings, NS_ARRAY_LENGTH(strings));
+                                     strings, ArrayLength(strings));
 }
 
 void
 nsSVGElement::RecompileScriptEventListeners()
 {
   PRInt32 i, count = mAttrsAndChildren.AttrCount();
   for (i = 0; i < count; ++i) {
     const nsAttrName *name = mAttrsAndChildren.AttrNameAt(i);
--- a/content/svg/content/src/nsSVGEllipseElement.cpp
+++ b/content/svg/content/src/nsSVGEllipseElement.cpp
@@ -32,23 +32,27 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGPathGeometryElement.h"
 #include "nsIDOMSVGEllipseElement.h"
 #include "nsSVGLength2.h"
 #include "nsGkAtoms.h"
 #include "nsSVGUtils.h"
 #include "gfxContext.h"
 
+using namespace mozilla;
+
 typedef nsSVGPathGeometryElement nsSVGEllipseElementBase;
 
 class nsSVGEllipseElement : public nsSVGEllipseElementBase,
                             public nsIDOMSVGEllipseElement
 {
 protected:
   friend nsresult NS_NewSVGEllipseElement(nsIContent **aResult,
                                           already_AddRefed<nsINodeInfo> aNodeInfo);
@@ -145,17 +149,17 @@ NS_IMETHODIMP nsSVGEllipseElement::GetRy
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthAttributesInfo
 nsSVGEllipseElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 //----------------------------------------------------------------------
 // nsSVGPathGeometryElement methods
 
 void
 nsSVGEllipseElement::ConstructPath(gfxContext *aCtx)
 {
--- a/content/svg/content/src/nsSVGFilterElement.cpp
+++ b/content/svg/content/src/nsSVGFilterElement.cpp
@@ -29,21 +29,25 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsGkAtoms.h"
 #include "nsCOMPtr.h"
 #include "nsSVGFilterElement.h"
 #include "nsSVGEffects.h"
 
+using namespace mozilla;
+
 nsSVGElement::LengthInfo nsSVGFilterElement::sLengthInfo[4] =
 {
   { &nsGkAtoms::x, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
   { &nsGkAtoms::y, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
   { &nsGkAtoms::width, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
   { &nsGkAtoms::height, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
 };
 
@@ -186,17 +190,17 @@ nsSVGFilterElement::IsAttributeMapped(co
     sFiltersMap,
     sFontSpecificationMap,
     sGradientStopMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGGraphicElementBase::IsAttributeMapped(name);
 }
 
 void
 nsSVGFilterElement::Invalidate()
 {
   nsTObserverArray<nsIMutationObserver*> *observers = GetMutationObservers();
 
@@ -213,31 +217,31 @@ nsSVGFilterElement::Invalidate()
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthAttributesInfo
 nsSVGFilterElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 nsSVGElement::IntegerPairAttributesInfo
 nsSVGFilterElement::GetIntegerPairInfo()
 {
   return IntegerPairAttributesInfo(mIntegerPairAttributes, sIntegerPairInfo,
-                                   NS_ARRAY_LENGTH(sIntegerPairInfo));
+                                   ArrayLength(sIntegerPairInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGFilterElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFilterElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
--- a/content/svg/content/src/nsSVGFilters.cpp
+++ b/content/svg/content/src/nsSVGFilters.cpp
@@ -29,16 +29,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGElement.h"
 #include "nsGkAtoms.h"
 #include "nsSVGNumber2.h"
 #include "nsSVGNumberPair.h"
 #include "nsSVGInteger.h"
 #include "nsSVGIntegerPair.h"
 #include "nsSVGBoolean.h"
 #include "nsIDOMSVGFilters.h"
@@ -288,28 +290,28 @@ NS_IMETHODIMP nsSVGFE::GetResult(nsIDOMS
 
 NS_IMETHODIMP_(bool)
 nsSVGFE::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sFiltersMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGFEBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthAttributesInfo
 nsSVGFE::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 inline static void DidAnimateAttr(Element *aFilterPrimitive)
 {
   // nsSVGLeafFrame doesn't implement AttributeChanged.
   nsIFrame* frame = aFilterPrimitive->GetPrimaryFrame();
   if (frame) {
     nsSVGEffects::InvalidateRenderingObservers(frame);
@@ -841,24 +843,24 @@ nsSVGFEGaussianBlurElement::ComputeChang
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberPairAttributesInfo
 nsSVGFEGaussianBlurElement::GetNumberPairInfo()
 {
   return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
-                                  NS_ARRAY_LENGTH(sNumberPairInfo));
+                                  ArrayLength(sNumberPairInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEGaussianBlurElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //---------------------Blend------------------------
 
 typedef nsSVGFE nsSVGFEBlendElementBase;
 
 class nsSVGFEBlendElement : public nsSVGFEBlendElementBase,
                             public nsIDOMSVGFEBlendElement
@@ -1043,24 +1045,24 @@ nsSVGFEBlendElement::GetSourceImageNames
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::EnumAttributesInfo
 nsSVGFEBlendElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEBlendElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //---------------------Color Matrix------------------------
 
 typedef nsSVGFE nsSVGFEColorMatrixElementBase;
 
 class nsSVGFEColorMatrixElement : public nsSVGFEColorMatrixElementBase,
                                   public nsIDOMSVGFEColorMatrixElement
@@ -1339,31 +1341,31 @@ nsSVGFEColorMatrixElement::Filter(nsSVGF
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::EnumAttributesInfo
 nsSVGFEColorMatrixElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEColorMatrixElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 nsSVGElement::NumberListAttributesInfo
 nsSVGFEColorMatrixElement::GetNumberListInfo()
 {
   return NumberListAttributesInfo(mNumberListAttributes, sNumberListInfo,
-                                  NS_ARRAY_LENGTH(sNumberListInfo));
+                                  ArrayLength(sNumberListInfo));
 }
 
 //---------------------Composite------------------------
 
 typedef nsSVGFE nsSVGFECompositeElementBase;
 
 class nsSVGFECompositeElement : public nsSVGFECompositeElementBase,
                                 public nsIDOMSVGFECompositeElement
@@ -1633,31 +1635,31 @@ nsSVGFECompositeElement::ComputeTargetBB
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberAttributesInfo
 nsSVGFECompositeElement::GetNumberInfo()
 {
   return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
-                              NS_ARRAY_LENGTH(sNumberInfo));
+                              ArrayLength(sNumberInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGFECompositeElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFECompositeElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //---------------------Component Transfer------------------------
 
 typedef nsSVGFE nsSVGFEComponentTransferElementBase;
 
 class nsSVGFEComponentTransferElement : public nsSVGFEComponentTransferElementBase,
                                         public nsIDOMSVGFEComponentTransferElement
@@ -1745,17 +1747,17 @@ nsSVGFEComponentTransferElement::GetIn1(
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEComponentTransferElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //--------------------------------------------
 
 #define NS_SVG_FE_COMPONENT_TRANSFER_FUNCTION_ELEMENT_CID \
     { 0xafab106d, 0xbc18, 0x4f7f, \
   { 0x9e, 0x29, 0xfe, 0xb4, 0xb0, 0x16, 0x5f, 0xf4 } }
 
@@ -2037,31 +2039,31 @@ nsSVGComponentTransferFunctionElement::G
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberListAttributesInfo
 nsSVGComponentTransferFunctionElement::GetNumberListInfo()
 {
   return NumberListAttributesInfo(mNumberListAttributes, sNumberListInfo,
-                                  NS_ARRAY_LENGTH(sNumberListInfo));
+                                  ArrayLength(sNumberListInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGComponentTransferFunctionElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGElement::NumberAttributesInfo
 nsSVGComponentTransferFunctionElement::GetNumberInfo()
 {
   return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
-                              NS_ARRAY_LENGTH(sNumberInfo));
+                              ArrayLength(sNumberInfo));
 }
 
 class nsSVGFEFuncRElement : public nsSVGComponentTransferFunctionElement,
                             public nsIDOMSVGFEFuncRElement
 {
   friend nsresult NS_NewSVGFEFuncRElement(nsIContent **aResult,
                                           already_AddRefed<nsINodeInfo> aNodeInfo);
 protected:
@@ -2388,17 +2390,17 @@ nsSVGFEMergeElement::GetSourceImageNames
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEMergeElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //---------------------Merge Node------------------------
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsSVGFEMergeNodeElement, NS_SVG_FE_MERGE_NODE_CID)
 
 nsSVGElement::StringInfo nsSVGFEMergeNodeElement::sStringInfo[1] =
 {
@@ -2442,17 +2444,17 @@ NS_IMETHODIMP nsSVGFEMergeNodeElement::G
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEMergeNodeElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //---------------------Offset------------------------
 
 typedef nsSVGFE nsSVGFEOffsetElementBase;
 
 class nsSVGFEOffsetElement : public nsSVGFEOffsetElementBase,
                              public nsIDOMSVGFEOffsetElement
@@ -2624,24 +2626,24 @@ nsSVGFEOffsetElement::ComputeNeededSourc
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberAttributesInfo
 nsSVGFEOffsetElement::GetNumberInfo()
 {
   return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
-                              NS_ARRAY_LENGTH(sNumberInfo));
+                              ArrayLength(sNumberInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEOffsetElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //---------------------Flood------------------------
 
 typedef nsSVGFE nsSVGFEFloodElementBase;
 
 class nsSVGFEFloodElement : public nsSVGFEFloodElementBase,
                             public nsIDOMSVGFEFloodElement
@@ -2761,28 +2763,28 @@ nsSVGFEFloodElement::ComputeTargetBBox(c
 
 NS_IMETHODIMP_(bool)
 nsSVGFEFloodElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sFEFloodMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGFEFloodElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEFloodElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //---------------------Tile------------------------
 
 typedef nsSVGFE nsSVGFETileElementBase;
 
 class nsSVGFETileElement : public nsSVGFETileElementBase,
                            public nsIDOMSVGFETileElement
@@ -2963,17 +2965,17 @@ nsSVGFETileElement::Filter(nsSVGFilterIn
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::StringAttributesInfo
 nsSVGFETileElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //---------------------Turbulence------------------------
 
 typedef nsSVGFE nsSVGFETurbulenceElementBase;
 
 class nsSVGFETurbulenceElement : public nsSVGFETurbulenceElementBase,
                                  public nsIDOMSVGFETurbulenceElement
@@ -3464,45 +3466,45 @@ nsSVGFETurbulenceElement::ComputeTargetB
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberAttributesInfo
 nsSVGFETurbulenceElement::GetNumberInfo()
 {
   return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
-                              NS_ARRAY_LENGTH(sNumberInfo));
+                              ArrayLength(sNumberInfo));
 }
 
 nsSVGElement::NumberPairAttributesInfo
 nsSVGFETurbulenceElement::GetNumberPairInfo()
 {
   return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
-                                 NS_ARRAY_LENGTH(sNumberPairInfo));
+                                 ArrayLength(sNumberPairInfo));
 }
 
 nsSVGElement::IntegerAttributesInfo
 nsSVGFETurbulenceElement::GetIntegerInfo()
 {
   return IntegerAttributesInfo(mIntegerAttributes, sIntegerInfo,
-                               NS_ARRAY_LENGTH(sIntegerInfo));
+                               ArrayLength(sIntegerInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGFETurbulenceElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFETurbulenceElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //---------------------Morphology------------------------
 
 typedef nsSVGFE nsSVGFEMorphologyElementBase;
 
 class nsSVGFEMorphologyElement : public nsSVGFEMorphologyElementBase,
                                  public nsIDOMSVGFEMorphologyElement
@@ -3799,31 +3801,31 @@ nsSVGFEMorphologyElement::Filter(nsSVGFi
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberPairAttributesInfo
 nsSVGFEMorphologyElement::GetNumberPairInfo()
 {
   return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
-                                  NS_ARRAY_LENGTH(sNumberPairInfo));
+                                  ArrayLength(sNumberPairInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGFEMorphologyElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEMorphologyElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //---------------------Convolve Matrix------------------------
 
 typedef nsSVGFE nsSVGFEConvolveMatrixElementBase;
 
 class nsSVGFEConvolveMatrixElement : public nsSVGFEConvolveMatrixElementBase,
                                      public nsIDOMSVGFEConvolveMatrixElement
@@ -4257,66 +4259,66 @@ nsSVGFEConvolveMatrixElement::Filter(nsS
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberAttributesInfo
 nsSVGFEConvolveMatrixElement::GetNumberInfo()
 {
   return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
-                              NS_ARRAY_LENGTH(sNumberInfo));
+                              ArrayLength(sNumberInfo));
 }
 
 nsSVGElement::NumberPairAttributesInfo
 nsSVGFEConvolveMatrixElement::GetNumberPairInfo()
 {
   return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
-                                  NS_ARRAY_LENGTH(sNumberPairInfo));
+                                  ArrayLength(sNumberPairInfo));
 }
 
 nsSVGElement::IntegerAttributesInfo
 nsSVGFEConvolveMatrixElement::GetIntegerInfo()
 {
   return IntegerAttributesInfo(mIntegerAttributes, sIntegerInfo,
-                               NS_ARRAY_LENGTH(sIntegerInfo));
+                               ArrayLength(sIntegerInfo));
 }
 
 nsSVGElement::IntegerPairAttributesInfo
 nsSVGFEConvolveMatrixElement::GetIntegerPairInfo()
 {
   return IntegerPairAttributesInfo(mIntegerPairAttributes, sIntegerPairInfo,
-                                   NS_ARRAY_LENGTH(sIntegerPairInfo));
+                                   ArrayLength(sIntegerPairInfo));
 }
 
 nsSVGElement::BooleanAttributesInfo
 nsSVGFEConvolveMatrixElement::GetBooleanInfo()
 {
   return BooleanAttributesInfo(mBooleanAttributes, sBooleanInfo,
-                               NS_ARRAY_LENGTH(sBooleanInfo));
+                               ArrayLength(sBooleanInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGFEConvolveMatrixElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEConvolveMatrixElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 nsSVGElement::NumberListAttributesInfo
 nsSVGFEConvolveMatrixElement::GetNumberListInfo()
 {
   return NumberListAttributesInfo(mNumberListAttributes, sNumberListInfo,
-                                  NS_ARRAY_LENGTH(sNumberListInfo));
+                                  ArrayLength(sNumberListInfo));
 }
 
 //---------------------DistantLight------------------------
 
 typedef nsSVGElement nsSVGFEDistantLightElementBase;
 
 class nsSVGFEDistantLightElement : public nsSVGFEDistantLightElementBase,
                                    public nsIDOMSVGFEDistantLightElement
@@ -4397,17 +4399,17 @@ nsSVGFEDistantLightElement::GetElevation
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberAttributesInfo
 nsSVGFEDistantLightElement::GetNumberInfo()
 {
   return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
-                              NS_ARRAY_LENGTH(sNumberInfo));
+                              ArrayLength(sNumberInfo));
 }
 
 //---------------------PointLight------------------------
 
 typedef nsSVGElement nsSVGFEPointLightElementBase;
 
 class nsSVGFEPointLightElement : public nsSVGFEPointLightElementBase,
                                  public nsIDOMSVGFEPointLightElement
@@ -4493,17 +4495,17 @@ nsSVGFEPointLightElement::GetZ(nsIDOMSVG
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberAttributesInfo
 nsSVGFEPointLightElement::GetNumberInfo()
 {
   return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
-                              NS_ARRAY_LENGTH(sNumberInfo));
+                              ArrayLength(sNumberInfo));
 }
 
 //---------------------SpotLight------------------------
 
 typedef nsSVGElement nsSVGFESpotLightElementBase;
 
 class nsSVGFESpotLightElement : public nsSVGFESpotLightElementBase,
                                 public nsIDOMSVGFESpotLightElement
@@ -4628,17 +4630,17 @@ nsSVGFESpotLightElement::GetLimitingCone
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberAttributesInfo
 nsSVGFESpotLightElement::GetNumberInfo()
 {
   return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
-                              NS_ARRAY_LENGTH(sNumberInfo));
+                              ArrayLength(sNumberInfo));
 }
 
 //------------------------------------------------------------
 
 typedef nsSVGFE nsSVGFELightingElementBase;
 
 class nsSVGFELightingElement : public nsSVGFELightingElementBase
 {
@@ -4727,17 +4729,17 @@ NS_INTERFACE_MAP_END_INHERITING(nsSVGFEL
 
 NS_IMETHODIMP_(bool)
 nsSVGFELightingElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sLightingEffectsMap
   };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGFELightingElementBase::IsAttributeMapped(name);
 }
 
 void
 nsSVGFELightingElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
 {
   aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
 }
@@ -4986,31 +4988,31 @@ nsSVGFELightingElement::Filter(nsSVGFilt
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberAttributesInfo
 nsSVGFELightingElement::GetNumberInfo()
 {
   return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
-                              NS_ARRAY_LENGTH(sNumberInfo));
+                              ArrayLength(sNumberInfo));
 }
 
 nsSVGElement::NumberPairAttributesInfo
 nsSVGFELightingElement::GetNumberPairInfo()
 {
   return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
-                                  NS_ARRAY_LENGTH(sNumberPairInfo));
+                                  ArrayLength(sNumberPairInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFELightingElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //---------------------DiffuseLighting------------------------
 
 typedef nsSVGFELightingElement nsSVGFEDiffuseLightingElementBase;
 
 class nsSVGFEDiffuseLightingElement : public nsSVGFEDiffuseLightingElementBase,
                                       public nsIDOMSVGFEDiffuseLightingElement
@@ -5455,17 +5457,17 @@ nsSVGFEImageElement::LoadSVGImage(bool a
 
 NS_IMETHODIMP_(bool)
 nsSVGFEImageElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sGraphicsMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGFEImageElementBase::IsAttributeMapped(name);
 }
 
 nsresult
 nsSVGFEImageElement::AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
                                   const nsAString* aValue, bool aNotify)
 {
   if (aNamespaceID == kNameSpaceID_XLink && aName == nsGkAtoms::href) {
@@ -5610,17 +5612,17 @@ nsSVGFEImageElement::GetPreserveAspectRa
 {
   return &mPreserveAspectRatio;
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEImageElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 void
 nsSVGFEImageElement::DidAnimateString(PRUint8 aAttrEnum)
 {
   if (aAttrEnum == HREF) {
     LoadSVGImage(PR_TRUE, PR_FALSE);
     return;
@@ -5945,24 +5947,24 @@ nsSVGFEDisplacementMapElement::ComputeCh
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::NumberAttributesInfo
 nsSVGFEDisplacementMapElement::GetNumberInfo()
 {
   return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
-                              NS_ARRAY_LENGTH(sNumberInfo));
+                              ArrayLength(sNumberInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGFEDisplacementMapElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGFEDisplacementMapElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
-}
+                              ArrayLength(sStringInfo));
+}
--- a/content/svg/content/src/nsSVGForeignObjectElement.cpp
+++ b/content/svg/content/src/nsSVGForeignObjectElement.cpp
@@ -31,19 +31,23 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsCOMPtr.h"
 #include "nsSVGForeignObjectElement.h"
 
+using namespace mozilla;
+
 nsSVGElement::LengthInfo nsSVGForeignObjectElement::sLengthInfo[4] =
 {
   { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
   { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
   { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
   { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
 };
 
@@ -131,21 +135,21 @@ nsSVGForeignObjectElement::IsAttributeMa
     sFontSpecificationMap,
     sGradientStopMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGForeignObjectElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthAttributesInfo
 nsSVGForeignObjectElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
--- a/content/svg/content/src/nsSVGGElement.cpp
+++ b/content/svg/content/src/nsSVGGElement.cpp
@@ -31,19 +31,23 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGGraphicElement.h"
 #include "nsIDOMSVGGElement.h"
 
+using namespace mozilla;
+
 typedef nsSVGGraphicElement nsSVGGElementBase;
 
 class nsSVGGElement : public nsSVGGElementBase,
                       public nsIDOMSVGGElement
 {
 protected:
   friend nsresult NS_NewSVGGElement(nsIContent **aResult,
                                     already_AddRefed<nsINodeInfo> aNodeInfo);
@@ -118,11 +122,11 @@ nsSVGGElement::IsAttributeMapped(const n
     sFontSpecificationMap,
     sGradientStopMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGGElementBase::IsAttributeMapped(name);
 }
--- a/content/svg/content/src/nsSVGGradientElement.cpp
+++ b/content/svg/content/src/nsSVGGradientElement.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "DOMSVGAnimatedTransformList.h"
 #include "nsIDOMSVGAnimatedEnum.h"
 #include "nsIDOMSVGURIReference.h"
 #include "nsIDOMSVGGradientElement.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsCOMPtr.h"
 #include "nsSVGStylableElement.h"
 #include "nsGkAtoms.h"
@@ -96,24 +98,24 @@ nsSVGGradientElement::nsSVGGradientEleme
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::EnumAttributesInfo
 nsSVGGradientElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGGradientElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //----------------------------------------------------------------------
 // nsIDOMSVGGradientElement methods
 
 /* readonly attribute nsIDOMSVGAnimatedEnumeration gradientUnits; */
 NS_IMETHODIMP nsSVGGradientElement::GetGradientUnits(nsIDOMSVGAnimatedEnumeration * *aGradientUnits)
 {
@@ -151,17 +153,17 @@ nsSVGGradientElement::GetHref(nsIDOMSVGA
 NS_IMETHODIMP_(bool)
 nsSVGGradientElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sColorMap,
     sGradientStopMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGGradientElementBase::IsAttributeMapped(name);
 }
 
 //---------------------Linear Gradients------------------------
 
 nsSVGElement::LengthInfo nsSVGLinearGradientElement::sLengthInfo[4] =
 {
   { &nsGkAtoms::x1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
@@ -240,17 +242,17 @@ nsSVGGradientElement::GetAnimatedTransfo
   }
   return mGradientTransform;
 }
 
 nsSVGElement::LengthAttributesInfo
 nsSVGLinearGradientElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 //-------------------------- Radial Gradients ----------------------------
 
 nsSVGElement::LengthInfo nsSVGRadialGradientElement::sLengthInfo[5] =
 {
   { &nsGkAtoms::cx, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
   { &nsGkAtoms::cy, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
@@ -325,10 +327,10 @@ NS_IMETHODIMP nsSVGRadialGradientElement
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthAttributesInfo
 nsSVGRadialGradientElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
--- a/content/svg/content/src/nsSVGGraphicElement.cpp
+++ b/content/svg/content/src/nsSVGGraphicElement.cpp
@@ -32,16 +32,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGGraphicElement.h"
 #include "nsSVGSVGElement.h"
 #include "DOMSVGAnimatedTransformList.h"
 #include "DOMSVGMatrix.h"
 #include "nsGkAtoms.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIFrame.h"
 #include "nsISVGChildFrame.h"
@@ -168,17 +170,17 @@ NS_IMETHODIMP_(bool)
 nsSVGGraphicElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sColorMap,
     sFillStrokeMap,
     sGraphicsMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGGraphicElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement overrides
 
 bool
 nsSVGGraphicElement::IsEventName(nsIAtom* aName)
--- a/content/svg/content/src/nsSVGImageElement.cpp
+++ b/content/svg/content/src/nsSVGImageElement.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGImageElement.h"
 #include "nsCOMPtr.h"
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 #include "imgIContainer.h"
 #include "imgIDecoderObserver.h"
 #include "gfxContext.h"
 #include "mozilla/Preferences.h"
@@ -229,17 +231,17 @@ nsSVGImageElement::IntrinsicState() cons
 
 NS_IMETHODIMP_(bool)
 nsSVGImageElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sViewportsMap,
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGImageElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGPathGeometryElement methods
 
 /* For the purposes of the update/invalidation logic pretend to
    be a rectangle. */
@@ -258,30 +260,30 @@ nsSVGImageElement::ConstructPath(gfxCont
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthAttributesInfo
 nsSVGImageElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 SVGAnimatedPreserveAspectRatio *
 nsSVGImageElement::GetPreserveAspectRatio()
 {
   return &mPreserveAspectRatio;
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGImageElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 void
 nsSVGImageElement::DidAnimateString(PRUint8 aAttrEnum)
 {
   if (aAttrEnum == HREF) {
     LoadSVGImage(PR_TRUE, PR_FALSE);
     return;
--- a/content/svg/content/src/nsSVGLength2.cpp
+++ b/content/svg/content/src/nsSVGLength2.cpp
@@ -31,29 +31,33 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGLength2.h"
 #include "prdtoa.h"
 #include "nsTextFormatter.h"
 #include "nsSVGSVGElement.h"
 #include "nsIFrame.h"
 #include "nsSVGIntegrationUtils.h"
 #include "nsSVGAttrTearoffTable.h"
 #include "nsContentUtils.h" // NS_ENSURE_FINITE
 #ifdef MOZ_SMIL
 #include "nsSMILValue.h"
 #include "nsSMILFloatType.h"
 #endif // MOZ_SMIL
 
+using namespace mozilla;
+
 NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGLength2::DOMBaseVal, mSVGElement)
 
 NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGLength2::DOMAnimVal, mSVGElement)
 
 NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGLength2::DOMAnimatedLength, mSVGElement)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGLength2::DOMBaseVal)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGLength2::DOMBaseVal)
@@ -135,17 +139,17 @@ GetUnitString(nsAString& unit, PRUint16 
 static PRUint16
 GetUnitTypeForString(const char* unitStr)
 {
   if (!unitStr || *unitStr == '\0') 
     return nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER;
                    
   nsCOMPtr<nsIAtom> unitAtom = do_GetAtom(unitStr);
 
-  for (PRUint32 i = 0 ; i < NS_ARRAY_LENGTH(unitMap) ; i++) {
+  for (PRUint32 i = 0 ; i < ArrayLength(unitMap) ; i++) {
     if (unitMap[i] && *unitMap[i] == unitAtom) {
       return i;
     }
   }
 
   return nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN;
 }
 
--- a/content/svg/content/src/nsSVGLineElement.cpp
+++ b/content/svg/content/src/nsSVGLineElement.cpp
@@ -32,22 +32,26 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGPathGeometryElement.h"
 #include "nsIDOMSVGLineElement.h"
 #include "nsSVGLength2.h"
 #include "nsGkAtoms.h"
 #include "gfxContext.h"
 
+using namespace mozilla;
+
 typedef nsSVGPathGeometryElement nsSVGLineElementBase;
 
 class nsSVGLineElement : public nsSVGLineElementBase,
                          public nsIDOMSVGLineElement
 {
 protected:
   friend nsresult NS_NewSVGLineElement(nsIContent **aResult,
                                        already_AddRefed<nsINodeInfo> aNodeInfo);
@@ -152,28 +156,28 @@ NS_IMETHODIMP nsSVGLineElement::GetY2(ns
 
 NS_IMETHODIMP_(bool)
 nsSVGLineElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sMarkersMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGLineElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthAttributesInfo
 nsSVGLineElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 //----------------------------------------------------------------------
 // nsSVGPathGeometryElement methods
 
 void
 nsSVGLineElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks) {
   float x1, y1, x2, y2;
--- a/content/svg/content/src/nsSVGMarkerElement.cpp
+++ b/content/svg/content/src/nsSVGMarkerElement.cpp
@@ -29,16 +29,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsGkAtoms.h"
 #include "nsCOMPtr.h"
 #include "SVGAnimatedPreserveAspectRatio.h"
 #include "nsDOMError.h"
 #include "nsSVGUtils.h"
 #include "nsSVGMarkerElement.h"
 #include "gfxMatrix.h"
 #include "nsContentUtils.h" // NS_ENSURE_FINITE
@@ -239,17 +241,17 @@ nsSVGMarkerElement::IsAttributeMapped(co
     sFontSpecificationMap,
     sGradientStopMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGMarkerElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 bool
 nsSVGMarkerElement::GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
@@ -303,31 +305,31 @@ nsSVGMarkerElement::SetParentCoordCtxPro
   mCoordCtx = aContext;
   mViewBoxToViewportTransform = nsnull;
 }
 
 nsSVGElement::LengthAttributesInfo
 nsSVGMarkerElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 nsSVGElement::AngleAttributesInfo
 nsSVGMarkerElement::GetAngleInfo()
 {
   return AngleAttributesInfo(mAngleAttributes, sAngleInfo,
-                             NS_ARRAY_LENGTH(sAngleInfo));
+                             ArrayLength(sAngleInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGMarkerElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGViewBox *
 nsSVGMarkerElement::GetViewBox()
 {
   return &mViewBox;
 }
 
--- a/content/svg/content/src/nsSVGMaskElement.cpp
+++ b/content/svg/content/src/nsSVGMaskElement.cpp
@@ -29,20 +29,24 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsCOMPtr.h"
 #include "nsGkAtoms.h"
 #include "nsSVGMaskElement.h"
 
+using namespace mozilla;
+
 //--------------------- Masks ------------------------
 
 nsSVGElement::LengthInfo nsSVGMaskElement::sLengthInfo[4] =
 {
   { &nsGkAtoms::x, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
   { &nsGkAtoms::y, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
   { &nsGkAtoms::width, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::X },
   { &nsGkAtoms::height, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
@@ -131,24 +135,24 @@ NS_IMETHODIMP nsSVGMaskElement::GetHeigh
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthAttributesInfo
 nsSVGMaskElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGMaskElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 //----------------------------------------------------------------------
 // nsIContent methods
 
 NS_IMETHODIMP_(bool)
 nsSVGMaskElement::IsAttributeMapped(const nsIAtom* name) const
 {
@@ -158,11 +162,11 @@ nsSVGMaskElement::IsAttributeMapped(cons
     sFontSpecificationMap,
     sGradientStopMap,
     sGraphicsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGMaskElementBase::IsAttributeMapped(name);
 }
--- a/content/svg/content/src/nsSVGMpathElement.cpp
+++ b/content/svg/content/src/nsSVGMpathElement.cpp
@@ -30,22 +30,25 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGMpathElement.h"
 #include "nsAutoPtr.h"
 #include "nsDebug.h"
 #include "nsSVGPathElement.h"
 #include "nsSVGAnimateMotionElement.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 nsSVGElement::StringInfo nsSVGMpathElement::sStringInfo[1] =
 {
   { &nsGkAtoms::href, kNameSpaceID_XLink, PR_FALSE }
 };
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(Mpath)
@@ -186,17 +189,17 @@ nsSVGMpathElement::UnsetAttr(PRInt32 aNa
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::StringAttributesInfo
 nsSVGMpathElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //----------------------------------------------------------------------
 // nsIMutationObserver methods
 
 void
 nsSVGMpathElement::AttributeChanged(nsIDocument* aDocument,
                                     Element* aElement,
--- a/content/svg/content/src/nsSVGPathElement.cpp
+++ b/content/svg/content/src/nsSVGPathElement.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsGkAtoms.h"
 #include "nsIDOMSVGPathSeg.h"
 #include "DOMSVGPathSeg.h"
 #include "DOMSVGPathSegList.h"
 #include "nsCOMPtr.h"
 #include "nsIFrame.h"
 #include "nsSVGPathDataParser.h"
 #include "nsSVGPathElement.h"
@@ -381,17 +383,17 @@ NS_IMETHODIMP nsSVGPathElement::GetAnima
 
 NS_IMETHODIMP_(bool)
 nsSVGPathElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sMarkersMap
   };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGPathElementBase::IsAttributeMapped(name);
 }
 
 already_AddRefed<gfxFlattenedPath>
 nsSVGPathElement::GetFlattenedPath(const gfxMatrix &aMatrix)
 {
   return mD.GetAnimValue().ToFlattenedPath(aMatrix);
 }
--- a/content/svg/content/src/nsSVGPatternElement.cpp
+++ b/content/svg/content/src/nsSVGPatternElement.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "DOMSVGAnimatedTransformList.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsCOMPtr.h"
 #include "nsGkAtoms.h"
 #include "nsSVGPatternElement.h"
 #include "nsIFrame.h"
 
 using namespace mozilla;
@@ -191,17 +193,17 @@ nsSVGPatternElement::IsAttributeMapped(c
     sFontSpecificationMap,
     sGradientStopMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGPatternElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 SVGAnimatedTransformList*
 nsSVGPatternElement::GetAnimatedTransformList()
@@ -211,24 +213,24 @@ nsSVGPatternElement::GetAnimatedTransfor
   }
   return mPatternTransform;
 }
 
 nsSVGElement::LengthAttributesInfo
 nsSVGPatternElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGPatternElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGViewBox *
 nsSVGPatternElement::GetViewBox()
 {
   return &mViewBox;
 }
 
@@ -237,11 +239,11 @@ nsSVGPatternElement::GetPreserveAspectRa
 {
   return &mPreserveAspectRatio;
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGPatternElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
--- a/content/svg/content/src/nsSVGPolyElement.cpp
+++ b/content/svg/content/src/nsSVGPolyElement.cpp
@@ -29,16 +29,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGPolyElement.h"
 #include "DOMSVGPointList.h"
 #include "gfxContext.h"
 #include "nsSVGUtils.h"
 
 using namespace mozilla;
 
 //----------------------------------------------------------------------
@@ -86,17 +88,17 @@ nsSVGPolyElement::GetAnimatedPoints(nsID
 
 NS_IMETHODIMP_(bool)
 nsSVGPolyElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sMarkersMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGPolyElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGPathGeometryElement methods
 
 bool
 nsSVGPolyElement::AttributeDefinesGeometry(const nsIAtom *aName)
--- a/content/svg/content/src/nsSVGRectElement.cpp
+++ b/content/svg/content/src/nsSVGRectElement.cpp
@@ -32,22 +32,26 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGPathGeometryElement.h"
 #include "nsIDOMSVGRectElement.h"
 #include "nsSVGLength2.h"
 #include "nsGkAtoms.h"
 #include "gfxContext.h"
 
+using namespace mozilla;
+
 typedef nsSVGPathGeometryElement nsSVGRectElementBase;
 
 class nsSVGRectElement : public nsSVGRectElementBase,
                          public nsIDOMSVGRectElement
 {
 protected:
   friend nsresult NS_NewSVGRectElement(nsIContent **aResult,
                                        already_AddRefed<nsINodeInfo> aNodeInfo);
@@ -158,17 +162,17 @@ NS_IMETHODIMP nsSVGRectElement::GetRy(ns
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthAttributesInfo
 nsSVGRectElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 //----------------------------------------------------------------------
 // nsSVGPathGeometryElement methods
 
 void
 nsSVGRectElement::ConstructPath(gfxContext *aCtx)
 {
--- a/content/svg/content/src/nsSVGSVGElement.cpp
+++ b/content/svg/content/src/nsSVGSVGElement.cpp
@@ -33,16 +33,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsGkAtoms.h"
 #include "DOMSVGNumber.h"
 #include "DOMSVGLength.h"
 #include "nsSVGAngle.h"
 #include "nsCOMPtr.h"
 #include "nsIPresShell.h"
 #include "nsContentUtils.h"
 #include "nsIDocument.h"
@@ -901,17 +903,17 @@ nsSVGSVGElement::IsAttributeMapped(const
     sGradientStopMap,
     sGraphicsMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGSVGElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsIContent methods:
 
 #ifdef MOZ_SMIL
 nsresult
@@ -1198,24 +1200,24 @@ nsSVGSVGElement::PrependLocalTransformTo
   // outer-<svg>, but inline in some other content:
   return GetViewBoxTransform() * aMatrix;
 }
 
 nsSVGElement::LengthAttributesInfo
 nsSVGSVGElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGSVGElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGViewBox *
 nsSVGSVGElement::GetViewBox()
 {
   return &mViewBox;
 }
 
--- a/content/svg/content/src/nsSVGScriptElement.cpp
+++ b/content/svg/content/src/nsSVGScriptElement.cpp
@@ -32,28 +32,31 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGElement.h"
 #include "nsGkAtoms.h"
 #include "nsIDOMSVGScriptElement.h"
 #include "nsIDOMSVGURIReference.h"
 #include "nsCOMPtr.h"
 #include "nsSVGString.h"
 #include "nsIDocument.h"
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 #include "nsScriptElement.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 typedef nsSVGElement nsSVGScriptElementBase;
 
 class nsSVGScriptElement : public nsSVGScriptElementBase,
                            public nsIDOMSVGScriptElement, 
                            public nsIDOMSVGURIReference,
                            public nsScriptElement
@@ -260,17 +263,17 @@ nsSVGScriptElement::DidChangeString(PRUi
     MaybeProcessScript();
   }
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGScriptElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //----------------------------------------------------------------------
 // nsIContent methods
 
 nsresult
 nsSVGScriptElement::DoneAddingChildren(bool aHaveNotified)
 {
--- a/content/svg/content/src/nsSVGStopElement.cpp
+++ b/content/svg/content/src/nsSVGStopElement.cpp
@@ -31,22 +31,26 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGStylableElement.h"
 #include "nsIDOMSVGStopElement.h"
 #include "nsSVGNumber2.h"
 #include "nsSVGUtils.h"
 #include "nsGenericHTMLElement.h"
 
+using namespace mozilla;
+
 typedef nsSVGStylableElement nsSVGStopElementBase;
 
 class nsSVGStopElement : public nsSVGStopElementBase,
                          public nsIDOMSVGStopElement
 {
 protected:
   friend nsresult NS_NewSVGStopElement(nsIContent **aResult,
                                        already_AddRefed<nsINodeInfo> aNodeInfo);
@@ -134,13 +138,13 @@ nsSVGStopElement::GetNumberInfo()
 
 NS_IMETHODIMP_(bool)
 nsSVGStopElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sGradientStopMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGStopElementBase::IsAttributeMapped(name);
 }
 
 
--- a/content/svg/content/src/nsSVGSwitchElement.cpp
+++ b/content/svg/content/src/nsSVGSwitchElement.cpp
@@ -29,16 +29,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGFeatures.h"
 #include "nsSVGSwitchElement.h"
 #include "nsIFrame.h"
 #include "nsISVGChildFrame.h"
 #include "nsSVGUtils.h"
 #include "mozilla/Preferences.h"
 
 using namespace mozilla;
@@ -145,17 +147,17 @@ nsSVGSwitchElement::IsAttributeMapped(co
     sFontSpecificationMap,
     sGradientStopMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGSwitchElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // Implementation Helpers:
 
 nsIContent *
 nsSVGSwitchElement::FindActiveChild() const
--- a/content/svg/content/src/nsSVGSymbolElement.cpp
+++ b/content/svg/content/src/nsSVGSymbolElement.cpp
@@ -29,16 +29,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsIDOMSVGSymbolElement.h"
 #include "nsSVGStylableElement.h"
 #include "nsSVGViewBox.h"
 #include "SVGAnimatedPreserveAspectRatio.h"
 #include "nsIDOMSVGFitToViewBox.h"
 #include "nsGkAtoms.h"
 
 using namespace mozilla;
@@ -142,17 +144,17 @@ nsSVGSymbolElement::IsAttributeMapped(co
     sGradientStopMap,
     sGraphicsMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
    };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGSymbolElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGViewBox *
 nsSVGSymbolElement::GetViewBox()
--- a/content/svg/content/src/nsSVGTSpanElement.cpp
+++ b/content/svg/content/src/nsSVGTSpanElement.cpp
@@ -31,22 +31,26 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsGkAtoms.h"
 #include "nsIDOMSVGTSpanElement.h"
 #include "nsSVGSVGElement.h"
 #include "nsSVGTextPositioningElement.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
+
 typedef nsSVGTextPositioningElement nsSVGTSpanElementBase;
 
 class nsSVGTSpanElement : public nsSVGTSpanElementBase, // = nsIDOMSVGTextPositioningElement
                           public nsIDOMSVGTSpanElement
 {
 protected:
   friend nsresult NS_NewSVGTSpanElement(nsIContent **aResult,
                                         already_AddRefed<nsINodeInfo> aNodeInfo);
@@ -129,17 +133,17 @@ nsSVGTSpanElement::IsAttributeMapped(con
   static const MappedAttributeEntry* const map[] = {
     sColorMap,
     sFillStrokeMap,
     sFontSpecificationMap,
     sGraphicsMap,
     sTextContentElementsMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGTSpanElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement overrides
 
 bool
 nsSVGTSpanElement::IsEventName(nsIAtom* aName)
--- a/content/svg/content/src/nsSVGTextElement.cpp
+++ b/content/svg/content/src/nsSVGTextElement.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGGraphicElement.h"
 #include "nsGkAtoms.h"
 #include "nsIDOMSVGTextElement.h"
 #include "nsCOMPtr.h"
 #include "nsSVGSVGElement.h"
 #include "nsSVGTextPositioningElement.h"
 #include "nsIFrame.h"
 #include "nsDOMError.h"
@@ -352,17 +354,17 @@ nsSVGTextElement::SelectSubString(PRUint
 NS_IMETHODIMP_(bool)
 nsSVGTextElement::IsAttributeMapped(const nsIAtom* name) const
 {
   static const MappedAttributeEntry* const map[] = {
     sTextContentElementsMap,
     sFontSpecificationMap
   };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGTextElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::LengthListInfo nsSVGTextElement::sLengthListInfo[4] =
 {
@@ -371,23 +373,23 @@ nsSVGElement::LengthListInfo nsSVGTextEl
   { &nsGkAtoms::dx, nsSVGUtils::X, PR_TRUE },
   { &nsGkAtoms::dy, nsSVGUtils::Y, PR_TRUE }
 };
 
 nsSVGElement::LengthListAttributesInfo
 nsSVGTextElement::GetLengthListInfo()
 {
   return LengthListAttributesInfo(mLengthListAttributes, sLengthListInfo,
-                                  NS_ARRAY_LENGTH(sLengthListInfo));
+                                  ArrayLength(sLengthListInfo));
 }
 
 nsSVGElement::NumberListInfo nsSVGTextElement::sNumberListInfo[1] =
 {
   { &nsGkAtoms::rotate }
 };
 
 nsSVGElement::NumberListAttributesInfo
 nsSVGTextElement::GetNumberListInfo()
 {
   return NumberListAttributesInfo(mNumberListAttributes, sNumberListInfo,
-                                  NS_ARRAY_LENGTH(sNumberListInfo));
+                                  ArrayLength(sNumberListInfo));
 }
 
--- a/content/svg/content/src/nsSVGTextPathElement.cpp
+++ b/content/svg/content/src/nsSVGTextPathElement.cpp
@@ -30,25 +30,29 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGStylableElement.h"
 #include "nsGkAtoms.h"
 #include "nsIDOMSVGTextPathElement.h"
 #include "nsIDOMSVGURIReference.h"
 #include "nsIFrame.h"
 #include "nsSVGTextPathElement.h"
 #include "nsDOMError.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
+
 nsSVGElement::LengthInfo nsSVGTextPathElement::sLengthInfo[1] =
 {
   { &nsGkAtoms::startOffset, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
 };
 
 nsSVGEnumMapping nsSVGTextPathElement::sMethodMap[] = {
   {&nsGkAtoms::align, nsIDOMSVGTextPathElement::TEXTPATH_METHODTYPE_ALIGN},
   {&nsGkAtoms::stretch, nsIDOMSVGTextPathElement::TEXTPATH_METHODTYPE_STRETCH},
@@ -146,41 +150,41 @@ nsSVGTextPathElement::IsAttributeMapped(
   static const MappedAttributeEntry* const map[] = {
     sColorMap,
     sFillStrokeMap,
     sFontSpecificationMap,
     sGraphicsMap,
     sTextContentElementsMap
   };
   
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGTextPathElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement overrides
 
 bool
 nsSVGTextPathElement::IsEventName(nsIAtom* aName)
 {
   return nsContentUtils::IsEventAttributeName(aName, EventNameType_SVGGraphic);
 }
 
 nsSVGElement::LengthAttributesInfo
 nsSVGTextPathElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 nsSVGElement::EnumAttributesInfo
 nsSVGTextPathElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
-                            NS_ARRAY_LENGTH(sEnumInfo));
+                            ArrayLength(sEnumInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGTextPathElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
--- a/content/svg/content/src/nsSVGTextPositioningElement.cpp
+++ b/content/svg/content/src/nsSVGTextPositioningElement.cpp
@@ -28,16 +28,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGTextPositioningElement.h"
 #include "SVGAnimatedLengthList.h"
 #include "DOMSVGAnimatedLengthList.h"
 #include "SVGLengthList.h"
 #include "DOMSVGAnimatedNumberList.h"
 
 using namespace mozilla;
 
@@ -49,30 +51,30 @@ nsSVGElement::LengthListInfo nsSVGTextPo
   { &nsGkAtoms::dx, nsSVGUtils::X, PR_TRUE },
   { &nsGkAtoms::dy, nsSVGUtils::Y, PR_TRUE }
 };
 
 nsSVGElement::LengthListAttributesInfo
 nsSVGTextPositioningElement::GetLengthListInfo()
 {
   return LengthListAttributesInfo(mLengthListAttributes, sLengthListInfo,
-                                  NS_ARRAY_LENGTH(sLengthListInfo));
+                                  ArrayLength(sLengthListInfo));
 }
 
 
 nsSVGElement::NumberListInfo nsSVGTextPositioningElement::sNumberListInfo[1] =
 {
   { &nsGkAtoms::rotate }
 };
 
 nsSVGElement::NumberListAttributesInfo
 nsSVGTextPositioningElement::GetNumberListInfo()
 {
   return NumberListAttributesInfo(mNumberListAttributes, sNumberListInfo,
-                                  NS_ARRAY_LENGTH(sNumberListInfo));
+                                  ArrayLength(sNumberListInfo));
 }
 
 //----------------------------------------------------------------------
 // nsIDOMSVGTextPositioningElement methods
 
 /* readonly attribute nsIDOMSVGAnimatedLengthList x; */
 NS_IMETHODIMP nsSVGTextPositioningElement::GetX(nsIDOMSVGAnimatedLengthList * *aX)
 {
--- a/content/svg/content/src/nsSVGUseElement.cpp
+++ b/content/svg/content/src/nsSVGUseElement.cpp
@@ -29,27 +29,30 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsSVGUseElement.h"
 #include "nsIDOMSVGGElement.h"
 #include "nsGkAtoms.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMSVGSVGElement.h"
 #include "nsIDOMSVGSymbolElement.h"
 #include "nsIDocument.h"
 #include "nsIPresShell.h"
 #include "mozilla/dom/Element.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 ////////////////////////////////////////////////////////////////////////
 // implementation
 
 nsSVGElement::LengthInfo nsSVGUseElement::sLengthInfo[4] =
 {
   { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
@@ -497,24 +500,24 @@ nsSVGUseElement::PrependLocalTransformTo
   const_cast<nsSVGUseElement*>(this)->GetAnimatedLengthValues(&x, &y, nsnull);
   return matrix.PreMultiply(gfxMatrix().Translate(gfxPoint(x, y)));
 }
 
 nsSVGElement::LengthAttributesInfo
 nsSVGUseElement::GetLengthInfo()
 {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
-                              NS_ARRAY_LENGTH(sLengthInfo));
+                              ArrayLength(sLengthInfo));
 }
 
 nsSVGElement::StringAttributesInfo
 nsSVGUseElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
-                              NS_ARRAY_LENGTH(sStringInfo));
+                              ArrayLength(sStringInfo));
 }
 
 //----------------------------------------------------------------------
 // nsIContent methods
 
 NS_IMETHODIMP_(bool)
 nsSVGUseElement::IsAttributeMapped(const nsIAtom* name) const
 {
@@ -524,12 +527,12 @@ nsSVGUseElement::IsAttributeMapped(const
     sFontSpecificationMap,
     sGradientStopMap,
     sLightingEffectsMap,
     sMarkersMap,
     sTextContentElementsMap,
     sViewportsMap
   };
 
-  return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
+  return FindAttributeDependence(name, map, ArrayLength(map)) ||
     nsSVGUseElementBase::IsAttributeMapped(name);
 }
 
--- a/content/xbl/src/nsXBLContentSink.cpp
+++ b/content/xbl/src/nsXBLContentSink.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsXBLContentSink.h"
 #include "nsIDocument.h"
 #include "nsBindingManager.h"
 #include "nsIDOMNode.h"
 #include "nsIParser.h"
 #include "nsGkAtoms.h"
 #include "nsINameSpaceManager.h"
 #include "nsHTMLTokens.h"
@@ -56,16 +58,17 @@
 #include "nsContentUtils.h"
 #include "nsIConsoleService.h"
 #include "nsIScriptError.h"
 #include "nsNodeInfoManager.h"
 #include "nsINodeInfo.h"
 #include "nsIPrincipal.h"
 #include "mozilla/dom/Element.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 nsresult
 NS_NewXBLContentSink(nsIXMLContentSink** aResult,
                      nsIDocument* aDoc,
                      nsIURI* aURI,
                      nsISupports* aContainer)
 {
@@ -241,17 +244,17 @@ nsXBLContentSink::ReportUnexpectedElemen
   mState = eXBL_Error;
   nsAutoString elementName;
   aElementName->ToString(elementName);
 
   const PRUnichar* params[] = { elementName.get() };
 
   return nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
                                          "UnexpectedElement",
-                                         params, NS_ARRAY_LENGTH(params),
+                                         params, ArrayLength(params),
                                          nsnull,
                                          EmptyString() /* source line */,
                                          aLineNumber, 0 /* column number */,
                                          nsIScriptError::errorFlag,
                                          "XBL Content Sink",
                                          mDocument);
 }
 
--- a/content/xbl/src/nsXBLPrototypeBinding.cpp
+++ b/content/xbl/src/nsXBLPrototypeBinding.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
 #include "nsIInputStream.h"
 #include "nsINameSpaceManager.h"
 #include "nsIURI.h"
 #include "nsIURL.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIChannel.h"
@@ -69,16 +71,18 @@
 #include "nsContentUtils.h"
 
 #include "nsIScriptContext.h"
 
 #include "nsIStyleRuleProcessor.h"
 #include "nsXBLResourceLoader.h"
 #include "mozilla/dom/Element.h"
 
+using namespace mozilla;
+
 // Helper Classes =====================================================================
 
 // nsXBLAttributeEntry and helpers.  This class is used to efficiently handle
 // attribute changes in anonymous content.
 
 class nsXBLAttributeEntry {
 public:
   nsIAtom* GetSrcAttribute() { return mSrcAttribute; }
@@ -167,17 +171,17 @@ public:
   {
     if (++gRefCnt == 1) {
       kPool = new nsFixedSizeAllocator();
       if (kPool) {
         static const size_t kBucketSizes[] = {
           sizeof(nsXBLInsertionPointEntry)
         };
         kPool->Init("XBL Insertion Point Entries", kBucketSizes,
-                    NS_ARRAY_LENGTH(kBucketSizes), aInitialSize);
+                    ArrayLength(kBucketSizes), aInitialSize);
       }
     }
   }
   static bool PoolInited()
   {
     return kPool != nsnull;
   }
   static void ReleasePool()
--- a/content/xbl/src/nsXBLPrototypeHandler.cpp
+++ b/content/xbl/src/nsXBLPrototypeHandler.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsCOMPtr.h"
 #include "nsXBLPrototypeHandler.h"
 #include "nsXBLPrototypeBinding.h"
 #include "nsContentUtils.h"
 #include "nsIContent.h"
 #include "nsIAtom.h"
 #include "nsIDOMKeyEvent.h"
 #include "nsIDOMMouseEvent.h"
@@ -985,17 +987,17 @@ nsXBLPrototypeHandler::ReportKeyConflict
     }
   } else if (aKeyElement) {
     doc = aKeyElement->GetOwnerDoc();
   }
 
   const PRUnichar* params[] = { aKey, aModifiers };
   nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
                                   aMessageName,
-                                  params, NS_ARRAY_LENGTH(params),
+                                  params, ArrayLength(params),
                                   nsnull, EmptyString(), mLineNumber, 0,
                                   nsIScriptError::warningFlag,
                                   "XBL Prototype Handler", doc);
 }
 
 bool
 nsXBLPrototypeHandler::ModifiersMatchMask(nsIDOMUIEvent* aEvent,
                                           bool aIgnoreShiftKey)
--- a/content/xbl/src/nsXBLService.cpp
+++ b/content/xbl/src/nsXBLService.cpp
@@ -34,16 +34,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsCOMPtr.h"
 #include "nsNetUtil.h"
 #include "nsXBLService.h"
 #include "nsXBLWindowKeyHandler.h"
 #include "nsIInputStream.h"
 #include "nsINameSpaceManager.h"
 #include "nsHashtable.h"
 #include "nsIURI.h"
@@ -130,17 +132,17 @@ IsAncestorBinding(nsIDocument* aDocument
         continue;
       }
       nsCAutoString spec;
       aChildBindingURI->GetSpec(spec);
       NS_ConvertUTF8toUTF16 bindingURI(spec);
       const PRUnichar* params[] = { bindingURI.get() };
       nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
                                       "TooDeepBindingRecursion",
-                                      params, NS_ARRAY_LENGTH(params),
+                                      params, ArrayLength(params),
                                       nsnull,
                                       EmptyString(), 0, 0,
                                       nsIScriptError::warningFlag,
                                       "XBL", aDocument);
       return PR_TRUE;
     }
   }
 
@@ -964,17 +966,17 @@ nsXBLService::GetBinding(nsIContent* aBo
             nsContentUtils::NameSpaceManager()->GetNameSpaceID(nameSpace);
 
           nsCOMPtr<nsIAtom> tagName = do_GetAtom(display);
           // Check the white list
           if (!CheckTagNameWhiteList(nameSpaceID, tagName)) {
             const PRUnichar* params[] = { display.get() };
             nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
                                             "InvalidExtendsBinding",
-                                            params, NS_ARRAY_LENGTH(params),
+                                            params, ArrayLength(params),
                                             nsnull,
                                             EmptyString(), 0, 0,
                                             nsIScriptError::errorFlag,
                                             "XBL", doc);
             NS_ASSERTION(!IsChromeOrResourceURI(aURI),
                          "Invalid extends value");
             return NS_ERROR_ILLEGAL_VALUE;
           }
@@ -999,17 +1001,17 @@ nsXBLService::GetBinding(nsIContent* aBo
           NS_ENSURE_SUCCESS(rv, rv);
           if (equal) {
             nsCAutoString spec;
             protoBinding->BindingURI()->GetSpec(spec);
             NS_ConvertUTF8toUTF16 protoSpec(spec);
             const PRUnichar* params[] = { protoSpec.get(), value.get() };
             nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
                                             "CircularExtendsBinding",
-                                            params, NS_ARRAY_LENGTH(params),
+                                            params, ArrayLength(params),
                                             nsnull,
                                             EmptyString(), 0, 0,
                                             nsIScriptError::warningFlag,
                                             "XBL", boundDocument);
             return NS_ERROR_ILLEGAL_VALUE;
           }
         }
 
--- a/content/xslt/src/xpath/txCoreFunctionCall.cpp
+++ b/content/xslt/src/xpath/txCoreFunctionCall.cpp
@@ -31,27 +31,31 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "txExpr.h"
 #include "nsAutoPtr.h"
 #include "txNodeSet.h"
 #include "nsGkAtoms.h"
 #include "txIXPathContext.h"
 #include "nsWhitespaceTokenizer.h"
 #include "txXPathTreeWalker.h"
 #include <math.h>
 #include "txStringUtils.h"
 #include "txXMLUtils.h"
 
+using namespace mozilla;
+
 struct txCoreFunctionDescriptor
 {
     PRInt8 mMinParams;
     PRInt8 mMaxParams;
     Expr::ResultType mReturnType;
     nsIAtom** mName;
 };
 
@@ -749,17 +753,17 @@ txCoreFunctionCall::isSensitiveTo(Contex
     return PR_TRUE;
 }
 
 // static
 bool
 txCoreFunctionCall::getTypeFromAtom(nsIAtom* aName, eType& aType)
 {
     PRUint32 i;
-    for (i = 0; i < NS_ARRAY_LENGTH(descriptTable); ++i) {
+    for (i = 0; i < ArrayLength(descriptTable); ++i) {
         if (aName == *descriptTable[i].mName) {
             aType = static_cast<eType>(i);
 
             return PR_TRUE;
         }
     }
 
     return PR_FALSE;
--- a/content/xslt/src/xslt/txEXSLTFunctions.cpp
+++ b/content/xslt/src/xslt/txEXSLTFunctions.cpp
@@ -32,16 +32,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsIAtom.h"
 #include "nsGkAtoms.h"
 #include "txExecutionState.h"
 #include "txExpr.h"
 #include "txIXPathContext.h"
 #include "txNodeSet.h"
 #include "txOutputFormat.h"
 #include "txRtfHandler.h"
@@ -49,16 +51,18 @@
 #include "nsPrintfCString.h"
 #include "nsComponentManagerUtils.h"
 #include "nsContentCID.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsIContent.h"
 #include "nsIDOMDocumentFragment.h"
 #include "txMozillaXMLOutput.h"
 
+using namespace mozilla;
+
 class txStylesheetCompilerState;
 
 // ------------------------------------------------------------------
 // Utility functions
 // ------------------------------------------------------------------
 
 static nsresult
 convertRtfToNode(txIEvalContext *aContext, txResultTreeFragment *aRtf)
@@ -740,34 +744,34 @@ txEXSLTFunctionCall::getNameAtom(nsIAtom
 
 extern nsresult
 TX_ConstructEXSLTFunction(nsIAtom *aName,
                           PRInt32 aNamespaceID,
                           txStylesheetCompilerState* aState,
                           FunctionCall **aResult)
 {
     PRUint32 i;
-    for (i = 0; i < NS_ARRAY_LENGTH(descriptTable); ++i) {
+    for (i = 0; i < ArrayLength(descriptTable); ++i) {
         txEXSLTFunctionDescriptor& desc = descriptTable[i];
         if (aName == *desc.mName && aNamespaceID == desc.mNamespaceID) {
             *aResult = new txEXSLTFunctionCall(
                 static_cast<txEXSLTFunctionCall::eType>(i));
 
             return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
         }
     }
 
     return NS_ERROR_XPATH_UNKNOWN_FUNCTION;
 }
 
 extern bool
 TX_InitEXSLTFunction()
 {
     PRUint32 i;
-    for (i = 0; i < NS_ARRAY_LENGTH(descriptTable); ++i) {
+    for (i = 0; i < ArrayLength(descriptTable); ++i) {
         txEXSLTFunctionDescriptor& desc = descriptTable[i];
         NS_ConvertASCIItoUTF16 namespaceURI(desc.mNamespaceURI);
         desc.mNamespaceID =
             txNamespaceManager::getNamespaceID(namespaceURI);
 
         if (desc.mNamespaceID == kNameSpaceID_Unknown) {
             return PR_FALSE;
         }
--- a/content/xslt/src/xslt/txStylesheetCompileHandlers.cpp
+++ b/content/xslt/src/xslt/txStylesheetCompileHandlers.cpp
@@ -31,30 +31,34 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "txStylesheetCompiler.h"
 #include "txStylesheetCompileHandlers.h"
 #include "nsWhitespaceTokenizer.h"
 #include "txInstructions.h"
 #include "nsGkAtoms.h"
 #include "txCore.h"
 #include "txStringUtils.h"
 #include "txStylesheet.h"
 #include "txToplevelItems.h"
 #include "txPatternParser.h"
 #include "txNamespaceMap.h"
 #include "txURIUtils.h"
 #include "txXSLTFunctions.h"
 
+using namespace mozilla;
+
 txHandlerTable* gTxIgnoreHandler = 0;
 txHandlerTable* gTxRootHandler = 0;
 txHandlerTable* gTxEmbedHandler = 0;
 txHandlerTable* gTxTopHandler = 0;
 txHandlerTable* gTxTemplateHandler = 0;
 txHandlerTable* gTxTextHandler = 0;
 txHandlerTable* gTxApplyTemplatesHandler = 0;
 txHandlerTable* gTxCallTemplateHandler = 0;
@@ -3026,17 +3030,17 @@ txHandlerTable::find(PRInt32 aNamespaceI
                            &gTx##_name##TableData.mOtherHandler);    \
     if (!gTx##_name##Handler)                                        \
         return PR_FALSE
 
 #define INIT_HANDLER_WITH_ELEMENT_HANDLERS(_name)                    \
     INIT_HANDLER(_name);                                             \
                                                                      \
     rv = gTx##_name##Handler->init(gTx##_name##ElementHandlers,      \
-                                   NS_ARRAY_LENGTH(gTx##_name##ElementHandlers)); \
+                                   ArrayLength(gTx##_name##ElementHandlers)); \
     if (NS_FAILED(rv))                                               \
         return PR_FALSE
 
 #define SHUTDOWN_HANDLER(_name)                                      \
     delete gTx##_name##Handler;                                      \
     gTx##_name##Handler = nsnull
 
 // static
--- a/content/xslt/src/xslt/txStylesheetCompiler.cpp
+++ b/content/xslt/src/xslt/txStylesheetCompiler.cpp
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "txStylesheetCompiler.h"
 #include "txStylesheetCompileHandlers.h"
 #include "nsGkAtoms.h"
 #include "txURIUtils.h"
 #include "nsWhitespaceTokenizer.h"
 #include "txStylesheet.h"
 #include "txInstructions.h"
 #include "txToplevelItems.h"
@@ -48,16 +50,18 @@
 #include "txLog.h"
 #include "txPatternParser.h"
 #include "txStringUtils.h"
 #include "txXSLTFunctions.h"
 #include "nsICategoryManager.h"
 #include "nsServiceManagerUtils.h"
 #include "nsTArray.h"
 
+using namespace mozilla;
+
 txStylesheetCompiler::txStylesheetCompiler(const nsAString& aStylesheetURI,
                                            txACompileObserver* aObserver)
     : txStylesheetCompilerState(aObserver)
 {
     mStatus = init(aStylesheetURI, nsnull, nsnull);
 }
 
 txStylesheetCompiler::txStylesheetCompiler(const nsAString& aStylesheetURI,
@@ -1016,26 +1020,26 @@ struct txXPCOMFunctionMapping
 static nsTArray<txXPCOMFunctionMapping> *sXPCOMFunctionMappings = nsnull;
 
 static nsresult
 findFunction(nsIAtom* aName, PRInt32 aNamespaceID,
              txStylesheetCompilerState* aState, FunctionCall** aResult)
 {
     if (kExtensionFunctions[0].mNamespaceID == kNameSpaceID_Unknown) {
         PRUint32 i;
-        for (i = 0; i < NS_ARRAY_LENGTH(kExtensionFunctions); ++i) {
+        for (i = 0; i < ArrayLength(kExtensionFunctions); ++i) {
             txFunctionFactoryMapping& mapping = kExtensionFunctions[i];
             NS_ConvertASCIItoUTF16 namespaceURI(mapping.mNamespaceURI);
             mapping.mNamespaceID =
                 txNamespaceManager::getNamespaceID(namespaceURI);
         }
     }
 
     PRUint32 i;
-    for (i = 0; i < NS_ARRAY_LENGTH(kExtensionFunctions); ++i) {
+    for (i = 0; i < ArrayLength(kExtensionFunctions); ++i) {
         const txFunctionFactoryMapping& mapping = kExtensionFunctions[i];
         if (mapping.mNamespaceID == aNamespaceID) {
             return mapping.mFactory(aName, aNamespaceID, aState, aResult);
         }
     }
 
     if (!sXPCOMFunctionMappings) {
         sXPCOMFunctionMappings = new nsTArray<txXPCOMFunctionMapping>;
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -53,16 +53,18 @@
      keep the element map in sync for HTML elements. Why don't we just
      do it for _all_ elements? Well, in the case of XUL elements,
      which may be lazily created during frame construction, the
      document observer methods will never be called because we'll be
      adding the XUL nodes into the content model "quietly".
 
 */
 
+#include "mozilla/Util.h"
+
 // Note the ALPHABETICAL ORDERING
 #include "nsXULDocument.h"
 
 #include "nsDOMError.h"
 #include "nsIBoxObject.h"
 #include "nsIChromeRegistry.h"
 #include "nsIView.h"
 #include "nsIViewManager.h"
@@ -3047,17 +3049,17 @@ nsXULDocument::ResumeWalk()
                 if (piProto->mTarget.EqualsLiteral("xml-stylesheet") ||
                     piProto->mTarget.EqualsLiteral("xul-overlay")) {
 
                     const PRUnichar* params[] = { piProto->mTarget.get() };
 
                     nsContentUtils::ReportToConsole(
                                         nsContentUtils::eXUL_PROPERTIES,
                                         "PINotInProlog",
-                                        params, NS_ARRAY_LENGTH(params),
+                                        params, ArrayLength(params),
                                         overlayURI,
                                         EmptyString(), /* source line */
                                         0, /* line number */
                                         0, /* column number */
                                         nsIScriptError::warningFlag,
                                         "XUL Document");
                 }
 
@@ -3344,17 +3346,17 @@ nsXULDocument::ReportMissingOverlay(nsIU
     
     nsCAutoString spec;
     aURI->GetSpec(spec);
 
     NS_ConvertUTF8toUTF16 utfSpec(spec);
     const PRUnichar* params[] = { utfSpec.get() };
     nsContentUtils::ReportToConsole(nsContentUtils::eXUL_PROPERTIES,
                                     "MissingOverlay",
-                                    params, NS_ARRAY_LENGTH(params),
+                                    params, ArrayLength(params),
                                     nsnull,
                                     EmptyString(), /* source line */
                                     0, /* line number */
                                     0, /* column number */
                                     nsIScriptError::warningFlag,
                                     "XUL Document", this);
 }
 
--- a/content/xul/templates/src/nsRuleNetwork.cpp
+++ b/content/xul/templates/src/nsRuleNetwork.cpp
@@ -45,16 +45,18 @@
 
   - Constrain() & Propagate() still feel like they are poorly named.
   - As do Instantiation and InstantiationSet.
   - Make InstantiationSet share and do copy-on-write.
   - Make things iterative, instead of recursive.
 
  */
 
+#include "mozilla/Util.h"
+
 #include "nscore.h"
 #include "nsCOMPtr.h"
 #include "nsCRT.h"
 #include "nsIComponentManager.h"
 #include "nsIContent.h"
 #include "plhash.h"
 #include "nsReadableUtils.h"
 
@@ -68,31 +70,33 @@ extern PRLogModuleInfo* gXULTemplateLog;
 
 #endif
 
 #include "nsRuleNetwork.h"
 #include "nsXULTemplateResultSetRDF.h"
 #include "nsRDFConMemberTestNode.h"
 #include "nsRDFPropertyTestNode.h"
 
+using namespace mozilla;
+
 bool MemoryElement::gPoolInited;
 nsFixedSizeAllocator MemoryElement::gPool;
 
 // static
 bool
 MemoryElement::Init()
 {
     if (!gPoolInited) {
         const size_t bucketsizes[] = {
             sizeof (nsRDFConMemberTestNode::Element),
             sizeof (nsRDFPropertyTestNode::Element)
         };
 
         if (NS_FAILED(gPool.Init("MemoryElement", bucketsizes,
-                                 NS_ARRAY_LENGTH(bucketsizes), 256)))
+                                 ArrayLength(bucketsizes), 256)))
             return PR_FALSE;
 
         gPoolInited = PR_TRUE;
     }
 
     return PR_TRUE;
 }
 
--- a/content/xul/templates/src/nsXULContentBuilder.cpp
+++ b/content/xul/templates/src/nsXULContentBuilder.cpp
@@ -35,16 +35,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsContentCID.h"
 #include "nsIDocument.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMXULDocument.h"
 #include "nsINodeInfo.h"
 #include "nsIServiceManager.h"
 #include "nsIXULDocument.h"
 
@@ -66,16 +68,17 @@
 #include "nsAttrName.h"
 #include "nsNodeUtils.h"
 #include "mozAutoDocUpdate.h"
 
 #include "jsapi.h"
 #include "pldhash.h"
 #include "rdf.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 //----------------------------------------------------------------------
 //
 // Return values for EnsureElementHasGenericChild()
 //
 #define NS_ELEMENT_GOT_CREATED NS_RDF_NO_VALUE
 #define NS_ELEMENT_WAS_THERE   NS_OK
@@ -641,17 +644,17 @@ nsXULContentBuilder::BuildContentFromTem
         else if (tag == nsGkAtoms::textnode &&
                  nameSpaceID == kNameSpaceID_XUL) {
             // <xul:text value="..."> is replaced by text of the
             // actual value of the 'rdf:resource' attribute for the
             // given node.
             // SynchronizeUsingTemplate contains code used to update textnodes,
             // so make sure to modify both when changing this
             PRUnichar attrbuf[128];
-            nsFixedString attrValue(attrbuf, NS_ARRAY_LENGTH(attrbuf), 0);
+            nsFixedString attrValue(attrbuf, ArrayLength(attrbuf), 0);
             tmplKid->GetAttr(kNameSpaceID_None, nsGkAtoms::value, attrValue);
             if (!attrValue.IsEmpty()) {
                 nsAutoString value;
                 rv = SubstituteText(aChild, attrValue, value);
                 if (NS_FAILED(rv)) return rv;
 
                 nsCOMPtr<nsIContent> content;
                 rv = NS_NewTextNode(getter_AddRefs(content),
@@ -780,17 +783,17 @@ nsXULContentBuilder::CopyAttributesToEle
         nsCOMPtr<nsIAtom> attribName = name->LocalName();
 
         // XXXndeakin ignore namespaces until bug 321182 is fixed
         if (attribName != nsGkAtoms::id && attribName != nsGkAtoms::uri) {
             // Create a buffer here, because there's a chance that an
             // attribute in the template is going to be an RDF URI, which is
             // usually longish.
             PRUnichar attrbuf[128];
-            nsFixedString attribValue(attrbuf, NS_ARRAY_LENGTH(attrbuf), 0);
+            nsFixedString attribValue(attrbuf, ArrayLength(attrbuf), 0);
             aTemplateNode->GetAttr(attribNameSpaceID, attribName, attribValue);
             if (!attribValue.IsEmpty()) {
                 nsAutoString value;
                 rv = SubstituteText(aResult, attribValue, value);
                 if (NS_FAILED(rv))
                     return rv;
 
                 // if the string is empty after substitutions, remove the
@@ -918,17 +921,17 @@ nsXULContentBuilder::SynchronizeUsingTem
         if (! realKid)
             break;
 
         // check for text nodes and update them accordingly.
         // This code is similar to that in BuildContentFromTemplate
         if (tmplKid->NodeInfo()->Equals(nsGkAtoms::textnode,
                                         kNameSpaceID_XUL)) {
             PRUnichar attrbuf[128];
-            nsFixedString attrValue(attrbuf, NS_ARRAY_LENGTH(attrbuf), 0);
+            nsFixedString attrValue(attrbuf, ArrayLength(attrbuf), 0);
             tmplKid->GetAttr(kNameSpaceID_None, nsGkAtoms::value, attrValue);
             if (!attrValue.IsEmpty()) {
                 nsAutoString value;
                 rv = SubstituteText(aResult, attrValue, value);
                 if (NS_FAILED(rv)) return rv;
                 realKid->SetText(value, PR_TRUE);
             }
         }
--- a/content/xul/templates/src/nsXULContentUtils.cpp
+++ b/content/xul/templates/src/nsXULContentUtils.cpp
@@ -52,16 +52,17 @@
 
 
 /*
 
   A package of routines shared by the XUL content code.
 
  */
 
+#include "mozilla/Util.h"
 
 #include "nsCOMPtr.h"
 #include "nsIContent.h"
 #include "nsINodeInfo.h"
 #include "nsIDocument.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMXULCommandDispatcher.h"
 #include "nsIDOMXULDocument.h"
@@ -86,16 +87,18 @@
 #include "nsIScriptableDateFormat.h"
 #include "nsICollation.h"
 #include "nsCollationCID.h"
 #include "nsILocale.h"
 #include "nsILocaleService.h"
 #include "nsIConsoleService.h"
 #include "nsEscape.h"
 
+using namespace mozilla;
+
 static NS_DEFINE_CID(kRDFServiceCID,        NS_RDFSERVICE_CID);
 
 //------------------------------------------------------------------------
 
 nsIRDFService* nsXULContentUtils::gRDF;
 nsIDateTimeFormat* nsXULContentUtils::gFormat;
 nsICollation *nsXULContentUtils::gCollation;
 
@@ -220,17 +223,17 @@ nsXULContentUtils::FindChildByTag(nsICon
 nsresult
 nsXULContentUtils::GetElementResource(nsIContent* aElement, nsIRDFResource** aResult)
 {
     // Perform a reverse mapping from an element in the content model
     // to an RDF resource.
     nsresult rv;
 
     PRUnichar buf[128];
-    nsFixedString id(buf, NS_ARRAY_LENGTH(buf), 0);
+    nsFixedString id(buf, ArrayLength(buf), 0);
 
     // Whoa.  Why the "id" attribute?  What if it's not even a XUL
     // element?  This is totally bogus!
     aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::id, id);
     if (id.IsEmpty())
         return NS_ERROR_FAILURE;
 
     // Since the element will store its ID attribute as a document-relative value,
@@ -411,17 +414,17 @@ nsXULContentUtils::GetResource(PRInt32 a
     // XXX should we allow nodes with no namespace???
     //NS_PRECONDITION(aNameSpaceID != kNameSpaceID_Unknown, "no namespace");
     //if (aNameSpaceID == kNameSpaceID_Unknown)
     //    return NS_ERROR_UNEXPECTED;
 
     nsresult rv;
 
     PRUnichar buf[256];
-    nsFixedString uri(buf, NS_ARRAY_LENGTH(buf), 0);
+    nsFixedString uri(buf, ArrayLength(buf), 0);
     if (aNameSpaceID != kNameSpaceID_Unknown && aNameSpaceID != kNameSpaceID_None) {
         rv = nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, uri);
         // XXX ignore failure; treat as "no namespace"
     }
 
     // XXX check to see if we need to insert a '/' or a '#'. Oy.
     if (!uri.IsEmpty()  && uri.Last() != '#' && uri.Last() != '/' && aAttribute.First() != '#')
         uri.Append(PRUnichar('#'));
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -36,16 +36,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #ifdef MOZ_LOGGING
 // so we can get logging even in release builds (but only for some things)
 #define FORCE_PR_LOG 1
 #endif
 
 #include "nsIBrowserDOMWindow.h"
 #include "nsIComponentManager.h"
 #include "nsIContent.h"
@@ -10621,17 +10623,17 @@ nsDocShell::ConfirmRepost(bool * aRepost
     rv = appBundle->GetStringFromName(NS_LITERAL_STRING("confirmRepostPrompt").get(),
                                       getter_Copies(msgString));
   }
   else {
     // Brand available - if the app has an override file with formatting, the app name will
     // be included. Without an override, the prompt will look like the generic version.
     const PRUnichar *formatStrings[] = { brandName.get() };
     rv = appBundle->FormatStringFromName(NS_LITERAL_STRING("confirmRepostPrompt").get(),
-                                         formatStrings, NS_ARRAY_LENGTH(formatStrings),
+                                         formatStrings, ArrayLength(formatStrings),
                                          getter_Copies(msgString));
   }
   if (NS_FAILED(rv)) return rv;
 
   rv = appBundle->GetStringFromName(NS_LITERAL_STRING("resendButton.label").get(),
                                     getter_Copies(button0Title));
   if (NS_FAILED(rv)) return rv;
 
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -33,16 +33,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 // JavaScript includes
 #include "jsapi.h"
 #include "jsprvtd.h"    // we are using private JS typedefs...
 #include "jscntxt.h"
 #include "jsdbgapi.h"
 #include "WrapperFactory.h"
 #include "AccessCheck.h"
 
@@ -2154,17 +2156,17 @@ nsDOMClassInfo::RegisterExternalClasses(
 #define DOM_CLASSINFO_MAP_CONDITIONAL_ENTRY(_if, _cond)                       \
       (_cond) ? &NS_GET_IID(_if) : nsnull,
 
 #define DOM_CLASSINFO_MAP_END                                                 \
       nsnull                                                                  \
     };                                                                        \
                                                                               \
     /* Compact the interface list */                                          \
-    size_t count = NS_ARRAY_LENGTH(interface_list);                           \
+    size_t count = ArrayLength(interface_list);                               \
     /* count is the number of array entries, which is one greater than the */ \
     /* number of interfaces due to the terminating null */                    \
     for (size_t i = 0; i < count - 1; ++i) {                                  \
       if (!interface_list[i]) {                                               \
         memmove(&interface_list[i], &interface_list[i+1],                     \
                 sizeof(nsIID*) * (count - i));                                \
         /* Make sure to examine the new pointer we ended up with at this */   \
         /* slot, since it may be null too */                                  \
@@ -4123,17 +4125,17 @@ nsDOMClassInfo::Init()
 
   DOM_CLASSINFO_MAP_BEGIN(CustomEvent, nsIDOMCustomEvent)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMCustomEvent)
     DOM_CLASSINFO_EVENT_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
 
 #ifdef NS_DEBUG
   {
-    PRUint32 i = NS_ARRAY_LENGTH(sClassInfoData);
+    PRUint32 i = ArrayLength(sClassInfoData);
 
     if (i != eDOMClassInfoIDCount) {
       NS_ERROR("The number of items in sClassInfoData doesn't match the "
                "number of nsIDOMClassInfo ID's, this is bad! Fix it!");
 
       return NS_ERROR_NOT_INITIALIZED;
     }
 
@@ -5257,29 +5259,29 @@ nsWindowSH::Enumerate(nsIXPConnectWrappe
 
   return NS_OK;
 }
 
 static const char*
 FindConstructorContractID(const nsDOMClassInfoData *aDOMClassInfoData)
 {
   PRUint32 i;
-  for (i = 0; i < NS_ARRAY_LENGTH(kConstructorMap); ++i) {
+  for (i = 0; i < ArrayLength(kConstructorMap); ++i) {
     if (&sClassInfoData[kConstructorMap[i].mDOMClassInfoID] ==
         aDOMClassInfoData) {
       return kConstructorMap[i].mContractID;
     }
   }
   return nsnull;
 }
 
 static nsDOMConstructorFunc
 FindConstructorFunc(const nsDOMClassInfoData *aDOMClassInfoData)
 {
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kConstructorFuncMap); ++i) {
+  for (PRUint32 i = 0; i < ArrayLength(kConstructorFuncMap); ++i) {
     if (&sClassInfoData[kConstructorFuncMap[i].mDOMClassInfoID] ==
         aDOMClassInfoData) {
       return kConstructorFuncMap[i].mConstructorFunc;
     }
   }
   return nsnull;
 }
 
@@ -6644,17 +6646,17 @@ nsWindowSH::NewResolve(nsIXPConnectWrapp
 
   // It is not worth calling GlobalResolve() if we are resolving
   // for assignment, since only read-write properties get dealt
   // with there.
   if (!(flags & JSRESOLVE_ASSIGNING)) {
     JSAutoRequest ar(cx);
 
     // Resolve special classes.
-    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(sOtherResolveFuncs); i++) {
+    for (PRUint32 i = 0; i < ArrayLength(sOtherResolveFuncs); i++) {
       if (!sOtherResolveFuncs[i](cx, obj, id, flags, objp)) {
         return NS_ERROR_FAILURE;
       }
       if (*objp) {
         return NS_OK;
       }
     }
 
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -44,16 +44,19 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "base/basictypes.h"
 
+/* This must occur *after* base/basictypes.h to avoid typedefs conflicts. */
+#include "mozilla/Util.h"
+
 // Local Includes
 #include "nsGlobalWindow.h"
 #include "nsScreen.h"
 #include "nsHistory.h"
 #include "nsPerformance.h"
 #include "nsDOMNavigationTiming.h"
 #include "nsBarProps.h"
 #include "nsDOMStorage.h"
@@ -4655,17 +4658,17 @@ nsGlobalWindow::MakeScriptDialogTitle(ns
               nsCAutoString prepath;
               fixedURI->GetPrePath(prepath);
 
               NS_ConvertUTF8toUTF16 ucsPrePath(prepath);
               const PRUnichar *formatStrings[] = { ucsPrePath.get() };
               nsXPIDLString tempString;
               nsContentUtils::FormatLocalizedString(nsContentUtils::eCOMMON_DIALOG_PROPERTIES,
                                                     "ScriptDlgHeading",
-                                                    formatStrings, NS_ARRAY_LENGTH(formatStrings),
+                                                    formatStrings, ArrayLength(formatStrings),
                                                     tempString);
               aOutTitle = tempString;
             }
           }
         }
       }
     }
     else { // failed to get subject principal
--- a/dom/plugins/base/nsNPAPIPlugin.cpp
+++ b/dom/plugins/base/nsNPAPIPlugin.cpp
@@ -37,16 +37,19 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifdef MOZ_WIDGET_QT
 #include <QX11Info>
 #endif
 
 #include "base/basictypes.h"
 
+/* This must occur *after* layers/PLayers.h to avoid typedefs conflicts. */
+#include "mozilla/Util.h"
+
 #include "prtypes.h"
 #include "prmem.h"
 #include "prenv.h"
 #include "prclist.h"
 
 #include "jscntxt.h"
 #include "jsfriendapi.h"
 
@@ -1617,17 +1620,17 @@ bool NP_CALLBACK
   if (!obj) {
     return false;
   }
 
   obj = JS_ObjectToInnerObject(cx, obj);
 
   // Root obj and the rval (below).
   jsval vec[] = { OBJECT_TO_JSVAL(obj), JSVAL_NULL };
-  js::AutoArrayRooter tvr(cx, NS_ARRAY_LENGTH(vec), vec);
+  js::AutoArrayRooter tvr(cx, ArrayLength(vec), vec);
   jsval *rval = &vec[1];
 
   if (result) {
     // Initialize the out param to void
     VOID_TO_NPVARIANT(*result);
   }
 
   if (!script || !script->UTF8Length || !script->UTF8Characters) {
--- a/dom/plugins/base/nsPluginsDirWin.cpp
+++ b/dom/plugins/base/nsPluginsDirWin.cpp
@@ -38,42 +38,46 @@
 /*
   nsPluginsDirWin.cpp
   
   Windows implementation of the nsPluginsDir/nsPluginsFile classes.
   
   by Alex Musil
  */
 
+#include "mozilla/Util.h"
+
 #include "nsPluginsDir.h"
 #include "prlink.h"
 #include "plstr.h"
 #include "prmem.h"
 #include "prprf.h"
 
 #include "windows.h"
 #include "winbase.h"
 
 #include "nsString.h"
 #include "nsILocalFile.h"
 #include "nsUnicharUtils.h"
 #include "nsSetDllDirectory.h"
 
+using namespace mozilla;
+
 /* Local helper functions */
 
 static char* GetKeyValue(void* verbuf, const WCHAR* key,
                          UINT language, UINT codepage)
 {
   WCHAR keybuf[64]; // plenty for the template below, with the longest key
                     // we use (currently "FileDescription")
   const WCHAR keyFormat[] = L"\\StringFileInfo\\%04X%04X\\%s";
   WCHAR *buf = NULL;
   UINT blen;
 
-  if (_snwprintf_s(keybuf, NS_ARRAY_LENGTH(keybuf), _TRUNCATE,
+  if (_snwprintf_s(keybuf, ArrayLength(keybuf), _TRUNCATE,
                    keyFormat, language, codepage, key) < 0)
   {
     NS_NOTREACHED("plugin info key too long for buffer!");
     return nsnull;
   }
 
   if (::VerQueryValueW(verbuf, keybuf, (void **)&buf, &blen) == 0 ||
       buf == nsnull || blen == 0)
--- a/dom/plugins/ipc/PluginInstanceChild.cpp
+++ b/dom/plugins/ipc/PluginInstanceChild.cpp
@@ -62,19 +62,21 @@
 #include "nsCrashOnException.h"
 extern const PRUnichar* kFlashFullscreenClass;
 using mozilla::gfx::SharedDIBSurface;
 #endif
 #include "gfxSharedImageSurface.h"
 #include "gfxUtils.h"
 #include "gfxAlphaRecovery.h"
 
+#include "mozilla/Util.h"
 #include "mozilla/ipc/SyncChannel.h"
 #include "mozilla/AutoRestore.h"
 
+using namespace mozilla;
 using mozilla::ipc::ProcessChild;
 using namespace mozilla::plugins;
 
 #ifdef MOZ_WIDGET_GTK2
 
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include <gdk/gdk.h>
@@ -1535,17 +1537,17 @@ PluginInstanceChild::TrackPopupHookProc(
       NS_ERROR("TrackPopupMenu stub isn't set! Badness!");
       return 0;
   }
 
   // Only change the parent when we know this is a context on the plugin
   // surface within the browser. Prevents resetting the parent on child ui
   // displayed by plugins that have working parent-child relationships.
   PRUnichar szClass[21];
-  bool haveClass = GetClassNameW(hWnd, szClass, NS_ARRAY_LENGTH(szClass));
+  bool haveClass = GetClassNameW(hWnd, szClass, ArrayLength(szClass));
   if (!haveClass || 
       (wcscmp(szClass, L"MozillaWindowClass") &&
        wcscmp(szClass, L"SWFlash_Placeholder"))) {
       // Unrecognized parent
       return sUser32TrackPopupMenuStub(hMenu, uFlags, x, y, nReserved,
                                        hWnd, prcRect);
   }
 
--- a/dom/plugins/ipc/PluginInstanceParent.cpp
+++ b/dom/plugins/ipc/PluginInstanceParent.cpp
@@ -33,17 +33,16 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "PluginInstanceParent.h"
-
 #include "BrowserStreamParent.h"
 #include "PluginBackgroundDestroyer.h"
 #include "PluginModuleParent.h"
 #include "PluginStreamParent.h"
 #include "StreamNotifyParent.h"
 #include "npfunctions.h"
 #include "nsAutoPtr.h"
 #include "mozilla/unused.h"
--- a/dom/plugins/ipc/PluginModuleChild.cpp
+++ b/dom/plugins/ipc/PluginModuleChild.cpp
@@ -39,16 +39,20 @@
 
 #ifdef MOZ_WIDGET_QT
 #include <QtCore/QTimer>
 #include "nsQAppInstance.h"
 #include "NestedLoopTimer.h"
 #endif
 
 #include "mozilla/plugins/PluginModuleChild.h"
+
+/* This must occur *after* plugins/PluginModuleChild.h to avoid typedefs conflicts. */
+#include "mozilla/Util.h"
+
 #include "mozilla/ipc/SyncChannel.h"
 
 #ifdef MOZ_WIDGET_GTK2
 #include <gtk/gtk.h>
 #endif
 
 #include "nsILocalFile.h"
 
@@ -76,16 +80,17 @@
 #include "mozilla/widget/AudioSession.h"
 #endif
 
 #ifdef MOZ_WIDGET_COCOA
 #include "PluginInterposeOSX.h"
 #include "PluginUtilsOSX.h"
 #endif
 
+using namespace mozilla;
 using namespace mozilla::plugins;
 using mozilla::dom::CrashReporterChild;
 using mozilla::dom::PCrashReporterChild;
 
 #if defined(XP_WIN)
 const PRUnichar * kFlashFullscreenClass = L"ShockwaveFlashFullScreen";
 const PRUnichar * kMozillaWindowClass = L"MozillaWindowClass";
 #endif
@@ -1898,17 +1903,17 @@ PMCGetWindowInfoHook(HWND hWnd, PWINDOWI
 
   if (!sGetWindowInfoPtrStub) {
      NS_ASSERTION(FALSE, "Something is horribly wrong in PMCGetWindowInfoHook!");
      return FALSE;
   }
 
   if (!sBrowserHwnd) {
       PRUnichar szClass[20];
-      if (GetClassNameW(hWnd, szClass, NS_ARRAY_LENGTH(szClass)) && 
+      if (GetClassNameW(hWnd, szClass, ArrayLength(szClass)) &&
           !wcscmp(szClass, kMozillaWindowClass)) {
           sBrowserHwnd = hWnd;
       }
   }
   // Oddity: flash does strange rect comparisons for mouse input destined for
   // it's internal settings window. Post removing sub widgets for tabs, touch
   // this up so they get the rect they expect.
   // XXX potentially tie this to a specific major version?
--- a/dom/system/unix/nsDeviceMotionSystem.cpp
+++ b/dom/system/unix/nsDeviceMotionSystem.cpp
@@ -31,19 +31,24 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include <unistd.h>
+
+#include "mozilla/Util.h"
+
 #include "nsDeviceMotionSystem.h"
 #include "nsIServiceManager.h"
 
+using namespace mozilla;
+
 typedef struct {
   const char* mPosition;
   const char* mCalibrate;
   nsAccelerometerSystemDriver mToken;
 } AccelerometerData;
 
 static const AccelerometerData gAccelerometers[] = {
   // MacBook
@@ -189,17 +194,17 @@ nsDeviceMotionSystem::UpdateHandler(nsIT
 
   self->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION, xf, yf, zf );
 }
 
 void nsDeviceMotionSystem::Startup()
 {
   // Accelerometers in Linux are used by reading a file (yay UNIX!), which is
   // in a slightly different location depending on the driver.
-  for (unsigned int i = 0; i < NS_ARRAY_LENGTH(gAccelerometers); i++) {
+  for (unsigned int i = 0; i < ArrayLength(gAccelerometers); i++) {
     if (!(mPositionFile = fopen(gAccelerometers[i].mPosition, "r")))
       continue;
 
     mType = gAccelerometers[i].mToken;
     if (gAccelerometers[i].mCalibrate) {
       mCalibrateFile = fopen(gAccelerometers[i].mCalibrate, "r");
       if (!mCalibrateFile) {
         fclose(mPositionFile);
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -32,16 +32,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "RuntimeService.h"
 
 #include "nsIDOMChromeWindow.h"
 #include "nsIDocument.h"
 #include "nsIEffectiveTLDService.h"
 #include "nsIObserverService.h"
 #include "nsIPlatformCharset.h"
 #include "nsIPrincipal.h"
@@ -62,16 +64,18 @@
 #include "nsXPCOMPrivate.h"
 #include "xpcpublic.h"
 
 #include "Events.h"
 #include "EventTarget.h"
 #include "Worker.h"
 #include "WorkerPrivate.h"
 
+using namespace mozilla;
+
 USING_WORKERS_NAMESPACE
 
 using mozilla::MutexAutoLock;
 using mozilla::MutexAutoUnlock;
 using mozilla::Preferences;
 using namespace mozilla::xpconnect::memory;
 
 // The size of the worker runtime heaps in bytes.
@@ -832,17 +836,17 @@ RuntimeService::Init()
     do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID, PR_FALSE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mObserved = true;
 
-  for (PRUint32 index = 0; index < NS_ARRAY_LENGTH(gPrefsToWatch); index++) {
+  for (PRUint32 index = 0; index < ArrayLength(gPrefsToWatch); index++) {
     if (NS_FAILED(Preferences::RegisterCallback(PrefCallback,
                                                 gPrefsToWatch[index], this))) {
       NS_WARNING("Failed to register pref callback?!");
     }
     PrefCallback(gPrefsToWatch[index], this);
   }
 
   // We assume atomic 32bit reads/writes. If this assumption doesn't hold on
@@ -947,17 +951,17 @@ RuntimeService::Cleanup()
     }
   }
 
   if (mWindowMap.IsInitialized()) {
     NS_ASSERTION(!mWindowMap.Count(), "All windows should have been released!");
   }
 
   if (mObserved) {
-    for (PRUint32 index = 0; index < NS_ARRAY_LENGTH(gPrefsToWatch); index++) {
+    for (PRUint32 index = 0; index < ArrayLength(gPrefsToWatch); index++) {
       Preferences::UnregisterCallback(PrefCallback, gPrefsToWatch[index], this);
     }
 
     nsCOMPtr<nsIObserverService> obs =
       do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
     NS_WARN_IF_FALSE(obs, "Failed to get observer service?!");
 
     if (obs) {
--- a/editor/libeditor/html/nsEditProperty.cpp
+++ b/editor/libeditor/html/nsEditProperty.cpp
@@ -32,20 +32,23 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsMemory.h"
 #include "nsStaticAtom.h"
 #include "nsEditProperty.h"
 
+using namespace mozilla;
 
 #define EDITOR_ATOM(name_, value_) nsIAtom* nsEditProperty::name_ = 0;
 #include "nsEditPropertyAtomList.h"
 #undef EDITOR_ATOM
 
 /* From the HTML 4.0 DTD, 
 
 INLINE:
@@ -77,10 +80,10 @@ nsEditProperty::RegisterAtoms()
 {
   // inline tags
   static const nsStaticAtom property_atoms[] = {
 #define EDITOR_ATOM(name_, value_) NS_STATIC_ATOM(name_##_buffer, &name_),
 #include "nsEditPropertyAtomList.h"
 #undef EDITOR_ATOM
   };
   
-  NS_RegisterStaticAtoms(property_atoms, NS_ARRAY_LENGTH(property_atoms));
+  NS_RegisterStaticAtoms(property_atoms, ArrayLength(property_atoms));
 }
--- a/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -31,16 +31,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
 
 #include "nsHTMLEditor.h"
 #include "nsHTMLEditRules.h"
 #include "nsTextEditUtils.h"
 #include "nsHTMLEditUtils.h"
 #include "nsWSRunObject.h"
 
 #include "nsIDOMNode.h"
@@ -1215,17 +1216,17 @@ nsHTMLEditor::ParseCFHTML(nsCString & aC
     if (startHTML == -1)
       return PR_FALSE;
   }
   if (endHTML == -1) {
     const char endFragmentMarker[] = "<!--EndFragment-->";
     endHTML = aCfhtml.Find(endFragmentMarker);
     if (endHTML == -1)
       return PR_FALSE;
-    endHTML += NS_ARRAY_LENGTH(endFragmentMarker) - 1;
+    endHTML += ArrayLength(endFragmentMarker) - 1;
   }
 
   // create context string
   nsCAutoString contextUTF8(Substring(aCfhtml, startHTML, startFragment - startHTML) +
                             NS_LITERAL_CSTRING("<!--" kInsertCookie "-->") +
                             Substring(aCfhtml, endFragment, endHTML - endFragment));
 
   // validate startFragment
@@ -1826,17 +1827,17 @@ bool nsHTMLEditor::HavePrivateHTMLFlavor
   // we have our own internal html format on clipboard.
   
   NS_ENSURE_TRUE(aClipboard, PR_FALSE);
   bool bHavePrivateHTMLFlavor = false;
   
   const char* flavArray[] = { kHTMLContext };
   
   if (NS_SUCCEEDED(aClipboard->HasDataMatchingFlavors(flavArray,
-    NS_ARRAY_LENGTH(flavArray), nsIClipboard::kGlobalClipboard,
+    ArrayLength(flavArray), nsIClipboard::kGlobalClipboard,
     &bHavePrivateHTMLFlavor )))
     return bHavePrivateHTMLFlavor;
     
   return PR_FALSE;
 }
 
 
 NS_IMETHODIMP nsHTMLEditor::Paste(PRInt32 aSelectionType)
@@ -1992,21 +1993,21 @@ NS_IMETHODIMP nsHTMLEditor::CanPaste(PRI
   nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool haveFlavors;
 
   // Use the flavors depending on the current editor mask
   if (IsPlaintextEditor())
     rv = clipboard->HasDataMatchingFlavors(textEditorFlavors,
-                                           NS_ARRAY_LENGTH(textEditorFlavors),
+                                           ArrayLength(textEditorFlavors),
                                            aSelectionType, &haveFlavors);
   else
     rv = clipboard->HasDataMatchingFlavors(textHtmlEditorFlavors,
-                                           NS_ARRAY_LENGTH(textHtmlEditorFlavors),
+                                           ArrayLength(textHtmlEditorFlavors),
                                            aSelectionType, &haveFlavors);
   
   NS_ENSURE_SUCCESS(rv, rv);
   
   *aCanPaste = haveFlavors;
   return NS_OK;
 }
 
@@ -2028,20 +2029,20 @@ NS_IMETHODIMP nsHTMLEditor::CanPasteTran
 
   // Peek in |aTransferable| to see if it contains a supported MIME type.
 
   // Use the flavors depending on the current editor mask
   const char ** flavors;
   unsigned length;
   if (IsPlaintextEditor()) {
     flavors = textEditorFlavors;
-    length = NS_ARRAY_LENGTH(textEditorFlavors);
+    length = ArrayLength(textEditorFlavors);
   } else {
     flavors = textHtmlEditorFlavors;
-    length = NS_ARRAY_LENGTH(textHtmlEditorFlavors);
+    length = ArrayLength(textHtmlEditorFlavors);
   }
 
   for (unsigned int i = 0; i < length; i++, flavors++) {
     nsCOMPtr<nsISupports> data;
     PRUint32 dataLen;
     nsresult rv = aTransferable->GetTransferData(*flavors,
                                                  getter_AddRefs(data),
                                                  &dataLen);
--- a/editor/libeditor/html/nsHTMLEditUtils.cpp
+++ b/editor/libeditor/html/nsHTMLEditUtils.cpp
@@ -30,30 +30,34 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsHTMLEditUtils.h"
 #include "nsTextEditUtils.h"
 
 #include "nsString.h"
 #include "nsUnicharUtils.h"
 #include "nsEditor.h"
 #include "nsEditProperty.h"
 #include "nsIAtom.h"
 #include "nsIDOMNode.h"
 #include "nsIContent.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMHTMLAnchorElement.h"
 #include "nsHTMLTags.h"
 
+using namespace mozilla;
+
 ///////////////////////////////////////////////////////////////////////////
 //                  
 bool 
 nsHTMLEditUtils::IsBig(nsIDOMNode *node)
 {
   return nsEditor::NodeIsType(node, nsEditProperty::big);
 }
 
@@ -765,17 +769,17 @@ nsHTMLEditUtils::CanContain(PRInt32 aPar
       eHTMLTag_form,
       eHTMLTag_iframe,
       eHTMLTag_input,
       eHTMLTag_select,
       eHTMLTag_textarea
     };
 
     PRUint32 j;
-    for (j = 0; j < NS_ARRAY_LENGTH(kButtonExcludeKids); ++j) {
+    for (j = 0; j < ArrayLength(kButtonExcludeKids); ++j) {
       if (kButtonExcludeKids[j] == aChild) {
         return PR_FALSE;
       }
     }
   }
 
   // Deprecated elements.
   if (aChild == eHTMLTag_bgsound) {
--- a/editor/libeditor/text/nsPlaintextDataTransfer.cpp
+++ b/editor/libeditor/text/nsPlaintextDataTransfer.cpp
@@ -30,16 +30,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
 
 #include "nsPlaintextEditor.h"
 
 #include "nsIDOMDocument.h"
 #include "nsIDocument.h"
 #include "nsIContent.h"
 #include "nsIFormControl.h"
 #include "nsIDOMEventTarget.h" 
@@ -65,16 +66,18 @@
 // Misc
 #include "nsEditorUtils.h"
 #include "nsContentCID.h"
 #include "nsISelectionPrivate.h"
 #include "nsFrameSelection.h"
 #include "nsEventDispatcher.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
+
 NS_IMETHODIMP nsPlaintextEditor::PrepareTransferable(nsITransferable **transferable)
 {
   // Create generic Transferable for getting the data
   nsresult rv = CallCreateInstance("@mozilla.org/widget/transferable;1", transferable);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Get the nsITransferable interface for getting the data from the clipboard
   if (transferable) {
@@ -478,17 +481,17 @@ NS_IMETHODIMP nsPlaintextEditor::CanPast
   nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
   NS_ENSURE_SUCCESS(rv, rv);
   
   // the flavors that we can deal with
   const char* textEditorFlavors[] = { kUnicodeMime };
 
   bool haveFlavors;
   rv = clipboard->HasDataMatchingFlavors(textEditorFlavors,
-                                         NS_ARRAY_LENGTH(textEditorFlavors),
+                                         ArrayLength(textEditorFlavors),
                                          aSelectionType, &haveFlavors);
   NS_ENSURE_SUCCESS(rv, rv);
   
   *aCanPaste = haveFlavors;
   return NS_OK;
 }
 
 
--- a/editor/txtsvc/src/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/src/nsTextServicesDocument.cpp
@@ -32,16 +32,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nscore.h"
 #include "nsLayoutCID.h"
 #include "nsIAtom.h"
 #include "nsStaticAtom.h"
 #include "nsString.h"
 #include "nsIEnumerator.h"
 #include "nsIContent.h"
 #include "nsIContentIterator.h"
@@ -59,16 +61,17 @@
 
 #include "nsLWBrkCIID.h"
 #include "nsIWordBreaker.h"
 #include "nsIServiceManager.h"
 
 #define LOCK_DOC(doc)
 #define UNLOCK_DOC(doc)
 
+using namespace mozilla;
 
 class OffsetEntry
 {
 public:
   OffsetEntry(nsIDOMNode *aNode, PRInt32 aOffset, PRInt32 aLength)
     : mNode(aNode), mNodeOffset(0), mStrOffset(aOffset), mLength(aLength),
       mIsInsertedText(PR_FALSE), mIsValid(PR_TRUE)
   {
@@ -128,17 +131,17 @@ void
 nsTextServicesDocument::RegisterAtoms()
 {
   static const nsStaticAtom ts_atoms[] = {
 #define TS_ATOM(name_, value_) NS_STATIC_ATOM(name_##_buffer, &name_),
 #include "nsTSAtomList.h"
 #undef TS_ATOM
   };
 
-  NS_RegisterStaticAtoms(ts_atoms, NS_ARRAY_LENGTH(ts_atoms));
+  NS_RegisterStaticAtoms(ts_atoms, ArrayLength(ts_atoms));
 }
 
 /* static */
 void
 nsTextServicesDocument::Shutdown()
 {
   NS_IF_RELEASE(sRangeHelper);
 }
--- a/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
+++ b/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
@@ -33,16 +33,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nspr.h"
 
 #include "nsIFileStreams.h"       // New Necko file streams
 
 #ifdef XP_OS2
 #include "nsILocalFileOS2.h"
 #endif
 
@@ -117,16 +119,18 @@
 #include "ftpCore.h"
 #include "nsITransport.h"
 #include "nsISocketTransport.h"
 #include "nsIStringBundle.h"
 #include "nsIProtocolHandler.h"
 
 #include "nsWebBrowserPersist.h"
 
+using namespace mozilla;
+
 // Buffer file writes in 32kb chunks
 #define BUFFERED_OUTPUT_SIZE (1024 * 32)
 
 #define NS_SUCCESS_DONT_FIXUP NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 1)
 
 // Information about a DOM document
 struct DocData
 {
@@ -3944,17 +3948,17 @@ static const char kSpecialXHTMLTags[][11
 static bool IsSpecialXHTMLTag(nsIDOMNode *aNode)
 {
     nsAutoString tmp;
     aNode->GetNamespaceURI(tmp);
     if (!tmp.EqualsLiteral("http://www.w3.org/1999/xhtml"))
         return PR_FALSE;
 
     aNode->GetLocalName(tmp);
-    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kSpecialXHTMLTags); i++) {
+    for (PRUint32 i = 0; i < ArrayLength(kSpecialXHTMLTags); i++) {
         if (tmp.EqualsASCII(kSpecialXHTMLTags[i]))
         {
             // XXX This element MAY have URI attributes, but
             //     we are not actually checking if they are present.
             //     That would slow us down further, and I am not so sure
             //     how important that would be.
             return PR_TRUE;
         }
--- a/extensions/auth/nsAuthGSSAPI.cpp
+++ b/extensions/auth/nsAuthGSSAPI.cpp
@@ -45,16 +45,18 @@
 // Described by IETF Internet draft: draft-brezak-kerberos-http-00.txt
 // (formerly draft-brezak-spnego-http-04.txt)
 //
 // Also described here:
 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsecure/html/http-sso-1.asp
 //
 //
 
+#include "mozilla/Util.h"
+
 #include "prlink.h"
 #include "nsCOMPtr.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIServiceManager.h"
 #include "nsNativeCharsetUtils.h"
 
 #include "nsAuthGSSAPI.h"
@@ -71,59 +73,61 @@ typedef KLStatus (*KLCacheHasValidTicket
     KLPrincipal *,
     char **);
 #endif
 
 #if defined(HAVE_RES_NINIT)
 #include <resolv.h>
 #endif
 
+using namespace mozilla;
+
 //-----------------------------------------------------------------------------
 
 // We define GSS_C_NT_HOSTBASED_SERVICE explicitly since it may be referenced
 // by by a different name depending on the implementation of gss but always
 // has the same value
 
 static gss_OID_desc gss_c_nt_hostbased_service = 
     { 10, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04" };
 
 static const char kNegotiateAuthGssLib[] =
     "network.negotiate-auth.gsslib";
 static const char kNegotiateAuthNativeImp[] = 
    "network.negotiate-auth.using-native-gsslib";
 
-static const char *gssFuncStr[] = {
-    "gss_display_status", 
-    "gss_init_sec_context", 
-    "gss_indicate_mechs",
-    "gss_release_oid_set",
-    "gss_delete_sec_context",
-    "gss_import_name",
-    "gss_release_buffer",
-    "gss_release_name",
-    "gss_wrap",
-    "gss_unwrap"
+static struct GSSFunction {
+    const char *str;
+    PRFuncPtr func;
+} gssFuncs[] = {
+    { "gss_display_status", NULL },
+    { "gss_init_sec_context", NULL },
+    { "gss_indicate_mechs", NULL },
+    { "gss_release_oid_set", NULL },
+    { "gss_delete_sec_context", NULL },
+    { "gss_import_name", NULL },
+    { "gss_release_buffer", NULL },
+    { "gss_release_name", NULL },
+    { "gss_wrap", NULL },
+    { "gss_unwrap", NULL }
 };
 
-#define gssFuncItems NS_ARRAY_LENGTH(gssFuncStr)
-
-static PRFuncPtr gssFunPtr[gssFuncItems]; 
 static bool      gssNativeImp = true;
 static PRLibrary* gssLibrary = nsnull;
 
-#define gss_display_status_ptr      ((gss_display_status_type)*gssFunPtr[0])
-#define gss_init_sec_context_ptr    ((gss_init_sec_context_type)*gssFunPtr[1])
-#define gss_indicate_mechs_ptr      ((gss_indicate_mechs_type)*gssFunPtr[2])
-#define gss_release_oid_set_ptr     ((gss_release_oid_set_type)*gssFunPtr[3])
-#define gss_delete_sec_context_ptr  ((gss_delete_sec_context_type)*gssFunPtr[4])
-#define gss_import_name_ptr         ((gss_import_name_type)*gssFunPtr[5])
-#define gss_release_buffer_ptr      ((gss_release_buffer_type)*gssFunPtr[6])
-#define gss_release_name_ptr        ((gss_release_name_type)*gssFunPtr[7])
-#define gss_wrap_ptr                ((gss_wrap_type)*gssFunPtr[8])
-#define gss_unwrap_ptr              ((gss_unwrap_type)*gssFunPtr[9])
+#define gss_display_status_ptr      ((gss_display_status_type)*gssFuncs[0].func)
+#define gss_init_sec_context_ptr    ((gss_init_sec_context_type)*gssFuncs[1].func)
+#define gss_indicate_mechs_ptr      ((gss_indicate_mechs_type)*gssFuncs[2].func)
+#define gss_release_oid_set_ptr     ((gss_release_oid_set_type)*gssFuncs[3].func)
+#define gss_delete_sec_context_ptr  ((gss_delete_sec_context_type)*gssFuncs[4].func)
+#define gss_import_name_ptr         ((gss_import_name_type)*gssFuncs[5].func)
+#define gss_release_buffer_ptr      ((gss_release_buffer_type)*gssFuncs[6].func)
+#define gss_release_name_ptr        ((gss_release_name_type)*gssFuncs[7].func)
+#define gss_wrap_ptr                ((gss_wrap_type)*gssFuncs[8].func)
+#define gss_unwrap_ptr              ((gss_unwrap_type)*gssFuncs[9].func)
 
 #ifdef XP_MACOSX
 static PRFuncPtr KLCacheHasValidTicketsPtr;
 #define KLCacheHasValidTickets_ptr \
         ((KLCacheHasValidTickets_type)*KLCacheHasValidTicketsPtr)
 #endif
 
 static nsresult
@@ -159,17 +163,17 @@ gssInit()
         };
         
         const char *const verLibNames[] = {
             "libgssapi_krb5.so.2", /* MIT - FC, Suse10, Debian */
             "libgssapi.so.4",      /* Heimdal - Suse10, MDK */
             "libgssapi.so.1"       /* Heimdal - Suse9, CITI - FC, MDK, Suse10*/
         };
 
-        for (size_t i = 0; i < NS_ARRAY_LENGTH(verLibNames) && !lib; ++i) {
+        for (size_t i = 0; i < ArrayLength(verLibNames) && !lib; ++i) {
             lib = PR_LoadLibrary(verLibNames[i]);
  
             /* The CITI libgssapi library calls exit() during
              * initialization if it's not correctly configured. Try to
              * ensure that we never use this library for our GSSAPI
              * support, as its just a wrapper library, anyway.
              * See Bugzilla #325433
              */
@@ -178,17 +182,17 @@ gssInit()
                                       "internal_krb5_gss_initialize") &&
                 PR_FindFunctionSymbol(lib, "gssd_pname_to_uid")) {
                 LOG(("CITI libgssapi found, which calls exit(). Skipping\n"));
                 PR_UnloadLibrary(lib);
                 lib = NULL;
             }
         }
 
-        for (size_t i = 0; i < NS_ARRAY_LENGTH(libNames) && !lib; ++i) {
+        for (size_t i = 0; i < ArrayLength(libNames) && !lib; ++i) {
             char *libName = PR_GetLibraryName(NULL, libNames[i]);
             if (libName) {
                 lib = PR_LoadLibrary(libName);
                 PR_FreeLibraryName(libName);
 
                 if (lib &&
                     PR_FindFunctionSymbol(lib, 
                                           "internal_krb5_gss_initialize") &&
@@ -204,20 +208,20 @@ gssInit()
     
     if (!lib) {
         LOG(("Fail to load gssapi library\n"));
         return NS_ERROR_FAILURE;
     }
 
     LOG(("Attempting to load gss functions\n"));
 
-    for (size_t i = 0; i < gssFuncItems; ++i) {
-        gssFunPtr[i] = PR_FindFunctionSymbol(lib, gssFuncStr[i]);
-        if (!gssFunPtr[i]) {
-            LOG(("Fail to load %s function from gssapi library\n", gssFuncStr[i]));
+    for (size_t i = 0; i < ArrayLength(gssFuncs); ++i) {
+        gssFuncs[i].func = PR_FindFunctionSymbol(lib, gssFuncs[i].str);
+        if (!gssFuncs[i].func) {
+            LOG(("Fail to load %s function from gssapi library\n", gssFuncs[i].str));
             PR_UnloadLibrary(lib);
             return NS_ERROR_FAILURE;
         }
     }
 #ifdef XP_MACOSX
     if (gssNativeImp &&
             !(KLCacheHasValidTicketsPtr =
                PR_FindFunctionSymbol(lib, "KLCacheHasValidTickets"))) {
--- a/extensions/permissions/nsContentBlocker.cpp
+++ b/extensions/permissions/nsContentBlocker.cpp
@@ -28,16 +28,17 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
 #include "nsContentBlocker.h"
 #include "nsIDocument.h"
 #include "nsIContent.h"
 #include "nsIURI.h"
 #include "nsIServiceManager.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
--- a/gfx/layers/d3d10/ThebesLayerD3D10.cpp
+++ b/gfx/layers/d3d10/ThebesLayerD3D10.cpp
@@ -31,16 +31,20 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/layers/PLayers.h"
+
+/* This must occur *after* layers/PLayers.h to avoid typedefs conflicts. */
+#include "mozilla/Util.h"
+
 #include "ThebesLayerD3D10.h"
 #include "gfxPlatform.h"
 
 #include "gfxWindowsPlatform.h"
 #ifdef CAIRO_HAS_D2D_SURFACE
 #include "gfxD2DSurface.h"
 #endif
 
@@ -359,17 +363,17 @@ ThebesLayerD3D10::DrawRegion(nsIntRegion
   }
 
   nsRefPtr<gfxASurface> destinationSurface;
   
   if (aMode == SURFACE_COMPONENT_ALPHA) {
     FillSurface(mD2DSurface, aRegion, visibleRect.TopLeft(), gfxRGBA(0.0, 0.0, 0.0, 1.0));
     FillSurface(mD2DSurfaceOnWhite, aRegion, visibleRect.TopLeft(), gfxRGBA(1.0, 1.0, 1.0, 1.0));
     gfxASurface* surfaces[2] = { mD2DSurface.get(), mD2DSurfaceOnWhite.get() };
-    destinationSurface = new gfxTeeSurface(surfaces, NS_ARRAY_LENGTH(surfaces));
+    destinationSurface = new gfxTeeSurface(surfaces, ArrayLength(surfaces));
     // Using this surface as a source will likely go horribly wrong, since
     // only the onBlack surface will really be used, so alpha information will
     // be incorrect.
     destinationSurface->SetAllowUseAsSource(PR_FALSE);
   } else {
     destinationSurface = mD2DSurface;
   }
 
--- a/gfx/layers/d3d9/ThebesLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ThebesLayerD3D9.cpp
@@ -31,16 +31,20 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/layers/PLayers.h"
+
+/* This must occur *after* layers/PLayers.h to avoid typedefs conflicts. */
+#include "mozilla/Util.h"
+
 #include "mozilla/layers/ShadowLayers.h"
 #include "ShadowBufferD3D9.h"
 
 #include "ThebesLayerD3D9.h"
 #include "gfxPlatform.h"
 
 #include "gfxWindowsPlatform.h"
 #include "gfxTeeSurface.h"
@@ -470,17 +474,17 @@ ThebesLayerD3D9::DrawRegion(nsIntRegion 
 
     case SURFACE_COMPONENT_ALPHA: {
       nsRefPtr<gfxWindowsSurface> onBlack = opaqueRenderer.Begin(this);
       nsRefPtr<gfxWindowsSurface> onWhite = opaqueRendererOnWhite.Begin(this);
       if (onBlack && onWhite) {
         FillSurface(onBlack, aRegion, bounds.TopLeft(), gfxRGBA(0.0, 0.0, 0.0, 1.0));
         FillSurface(onWhite, aRegion, bounds.TopLeft(), gfxRGBA(1.0, 1.0, 1.0, 1.0));
         gfxASurface* surfaces[2] = { onBlack.get(), onWhite.get() };
-        destinationSurface = new gfxTeeSurface(surfaces, NS_ARRAY_LENGTH(surfaces));
+        destinationSurface = new gfxTeeSurface(surfaces, ArrayLength(surfaces));
         // Using this surface as a source will likely go horribly wrong, since
         // only the onBlack surface will really be used, so alpha information will
         // be incorrect.
         destinationSurface->SetAllowUseAsSource(PR_FALSE);
       }
       break;
     }
   }
--- a/gfx/layers/opengl/LayerManagerOGL.cpp
+++ b/gfx/layers/opengl/LayerManagerOGL.cpp
@@ -34,16 +34,19 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/layers/PLayers.h"
 
+/* This must occur *after* layers/PLayers.h to avoid typedefs conflicts. */
+#include "mozilla/Util.h"
+
 #include "LayerManagerOGL.h"
 #include "ThebesLayerOGL.h"
 #include "ContainerLayerOGL.h"
 #include "ImageLayerOGL.h"
 #include "ColorLayerOGL.h"
 #include "CanvasLayerOGL.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Preferences.h"
@@ -253,17 +256,17 @@ LayerManagerOGL::Initialize(nsRefPtr<GLC
     LOCAL_GL_TEXTURE_2D,
 #ifndef USE_GLES2
     LOCAL_GL_TEXTURE_RECTANGLE_ARB
 #endif
   };
 
   mFBOTextureTarget = LOCAL_GL_NONE;
 
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(textureTargets); i++) {
+  for (PRUint32 i = 0; i < ArrayLength(textureTargets); i++) {
     GLenum target = textureTargets[i];
     mGLContext->fGenTextures(1, &mBackBufferTexture);
     mGLContext->fBindTexture(target, mBackBufferTexture);
     mGLContext->fTexParameteri(target,
                                LOCAL_GL_TEXTURE_MIN_FILTER,
                                LOCAL_GL_NEAREST);
     mGLContext->fTexParameteri(target,
                                LOCAL_GL_TEXTURE_MAG_FILTER,
@@ -1082,17 +1085,17 @@ LayerManagerOGL::ProgramType LayerManage
   gl::ColorLayerProgramType,
   gl::YCbCrLayerProgramType,
   gl::ComponentAlphaPass1ProgramType,
   gl::ComponentAlphaPass2ProgramType
 };
 
 #define FOR_EACH_LAYER_PROGRAM(vname)                       \
   for (size_t lpindex = 0;                                  \
-       lpindex < NS_ARRAY_LENGTH(sLayerProgramTypes);       \
+       lpindex < ArrayLength(sLayerProgramTypes);           \
        ++lpindex)                                           \
   {                                                         \
     LayerProgram *vname = static_cast<LayerProgram*>        \
       (mPrograms[sLayerProgramTypes[lpindex]]);             \
     do
 
 #define FOR_EACH_LAYER_PROGRAM_END              \
     while (0);                                  \
--- a/gfx/layers/opengl/ThebesLayerOGL.cpp
+++ b/gfx/layers/opengl/ThebesLayerOGL.cpp
@@ -32,16 +32,20 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/layers/PLayers.h"
+
+/* This must occur *after* layers/PLayers.h to avoid typedefs conflicts. */
+#include "mozilla/Util.h"
+
 #include "mozilla/layers/ShadowLayers.h"
 
 #include "ThebesLayerBuffer.h"
 #include "ThebesLayerOGL.h"
 #include "gfxUtils.h"
 #include "gfxTeeSurface.h"
 
 namespace mozilla {
@@ -628,17 +632,17 @@ BasicBufferOGL::BeginPaint(ContentType a
     nsIntRegion drawRegionCopy = result.mRegionToDraw;
     gfxASurface *onBlack = mTexImage->BeginUpdate(drawRegionCopy);
     gfxASurface *onWhite = mTexImageOnWhite->BeginUpdate(result.mRegionToDraw);
     NS_ASSERTION(result.mRegionToDraw == drawRegionCopy,
                  "BeginUpdate should always modify the draw region in the same way!");
     FillSurface(onBlack, result.mRegionToDraw, nsIntPoint(0,0), gfxRGBA(0.0, 0.0, 0.0, 1.0));
     FillSurface(onWhite, result.mRegionToDraw, nsIntPoint(0,0), gfxRGBA(1.0, 1.0, 1.0, 1.0));
     gfxASurface* surfaces[2] = { onBlack, onWhite };
-    nsRefPtr<gfxTeeSurface> surf = new gfxTeeSurface(surfaces, NS_ARRAY_LENGTH(surfaces));
+    nsRefPtr<gfxTeeSurface> surf = new gfxTeeSurface(surfaces, ArrayLength(surfaces));
 
     // XXX If the device offset is set on the individual surfaces instead of on
     // the tee surface, we render in the wrong place. Why?
     gfxPoint deviceOffset = onBlack->GetDeviceOffset();
     onBlack->SetDeviceOffset(gfxPoint(0, 0));
     onWhite->SetDeviceOffset(gfxPoint(0, 0));
     surf->SetDeviceOffset(deviceOffset);
 
--- a/gfx/src/nsColor.cpp
+++ b/gfx/src/nsColor.cpp
@@ -30,43 +30,47 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "plstr.h"
 #include "nsColor.h"
 #include "nsColorNames.h"
 #include "nsString.h"
 #include "nscore.h"
 #include "nsCoord.h"
 #include "nsCOMPtr.h"
 #include "nsIServiceManager.h"
 #include <math.h>
 #include "prprf.h"
 #include "nsStaticNameTable.h"
 
+using namespace mozilla;
+
 // define an array of all color names
 #define GFX_COLOR(_name, _value) #_name,
 static const char* const kColorNames[] = {
 #include "nsColorNameList.h"
 };
 #undef GFX_COLOR
 
 // define an array of all color name values
 #define GFX_COLOR(_name, _value) _value,
 static const nscolor kColors[] = {
 #include "nsColorNameList.h"
 };
 #undef GFX_COLOR
 
-#define eColorName_COUNT (NS_ARRAY_LENGTH(kColorNames))
+#define eColorName_COUNT (ArrayLength(kColorNames))
 #define eColorName_UNKNOWN (-1)
 
 static nsStaticCaseInsensitiveNameTable* gColorTable = nsnull;
 
 void nsColorNames::AddRefTable(void) 
 {
   NS_ASSERTION(!gColorTable, "pre existing array!");
   if (!gColorTable) {
--- a/gfx/tests/TestColorNames.cpp
+++ b/gfx/tests/TestColorNames.cpp
@@ -74,17 +74,17 @@ int main(int argc, char** argv)
 
   nscolor rgb;
   int rv = 0;
 
   // First make sure we can find all of the tags that are supposed to
   // be in the table. Futz with the case to make sure any case will
   // work
 
-  for (PRUint32 index = 0 ; index < NS_ARRAY_LENGTH(kColorNames); index++) {
+  for (PRUint32 index = 0 ; index < ArrayLength(kColorNames); index++) {
     // Lookup color by name and make sure it has the right id
     nsCString tagName(kColorNames[index]);
 
     // Check that color lookup by name gets the right rgb value
     if (!NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tagName), &rgb)) {
       fail("can't find '%s'", tagName.get());
       rv = 1;
     }
@@ -124,17 +124,17 @@ int main(int argc, char** argv)
     }
     if (hexrgb != rgb) {
       fail("rgb=%x hexrgb=%x", rgb, hexrgb);
       rv = 1;
     }
   }
 
   // Now make sure we don't find some garbage
-  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kJunkNames); i++) {
+  for (PRUint32 i = 0; i < ArrayLength(kJunkNames); i++) {
     nsCString tag(kJunkNames[i]);
     if (NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tag), &rgb)) {
       fail("found '%s'", kJunkNames[i] ? kJunkNames[i] : "(null)");
       rv = 1;
     }
   }
 
   if (rv == 0)
--- a/gfx/tests/gfxTextRunPerfTest.cpp
+++ b/gfx/tests/gfxTextRunPerfTest.cpp
@@ -30,16 +30,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsDependentString.h"
 
 #include "prinrval.h"
 
 #include "gfxContext.h"
@@ -51,16 +53,18 @@
 #if defined(XP_MACOSX)
 #include "gfxTestCocoaHelper.h"
 #endif
 
 #ifdef MOZ_WIDGET_GTK2
 #include "gtk/gtk.h"
 #endif
 
+using namespace mozilla;
+
 struct TestEntry {
   const char* mFamilies;
   const char* mString;
 };
 
 TestEntry testList[] = {
 #include "per-word-runs.h"
 { nsnull, nsnull } // terminator
@@ -156,17 +160,17 @@ main (int argc, char **argv) {
 
     nsRefPtr<gfxContext> context = MakeContext();
 
     // Start timing
     PRIntervalTime start = PR_IntervalNow();
 
     for (PRUint32 i = 0; i < iterations; ++i) {
         for (uint test = 0;
-             test < NS_ARRAY_LENGTH(testList) - 1;
+             test < ArrayLength(testList) - 1;
              test++)
         {
             RunTest(&testList[test], context);
         }
     }
 
     PRIntervalTime end = PR_IntervalNow();
     
--- a/gfx/thebes/GLContextProviderEGL.cpp
+++ b/gfx/thebes/GLContextProviderEGL.cpp
@@ -34,16 +34,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #if defined(XP_UNIX)
 
 #ifdef MOZ_WIDGET_GTK2
 #include <gdk/gdkx.h>
 // we're using default display for now
 #define GET_NATIVE_WINDOW(aWidget) (EGLNativeWindowType)GDK_WINDOW_XID((GdkWindow *) aWidget->GetNativeData(NS_NATIVE_WINDOW))
 #elif defined(MOZ_WIDGET_QT)
 #include <QtOpenGL/QGLContext>
@@ -1781,40 +1783,44 @@ static const EGLint kEGLConfigAttribsRGB
     LOCAL_EGL_RENDERABLE_TYPE, LOCAL_EGL_OPENGL_ES2_BIT,
     LOCAL_EGL_RED_SIZE,        8,
     LOCAL_EGL_GREEN_SIZE,      8,
     LOCAL_EGL_BLUE_SIZE,       8,
     LOCAL_EGL_ALPHA_SIZE,      8,
     LOCAL_EGL_NONE
 };
 
+// This struct is used only by CreateConfig below, but ISO C++98 forbids
+// instantiating a template dependent on a locally-defined type.  Boo-urns!
+struct EGLAttribs {
+    gfxASurface::gfxImageFormat mFormat;
+    const EGLint* mAttribs;
+};
+
 // Return true if a suitable EGLConfig was found and pass it out
 // through aConfig.  Return false otherwise.
 //
 // NB: It's entirely legal for the returned EGLConfig to be valid yet
 // have the value null.
 static bool
 CreateConfig(EGLConfig* aConfig)
 {
-    struct EGLAttribs {
-        gfxASurface::gfxImageFormat mFormat;
-        const EGLint* mAttribs;
-    } attribsToTry[] = {
+    EGLAttribs attribsToTry[] = {
 #ifdef MOZ_GFX_OPTIMIZE_MOBILE
         // Prefer r5g6b5 for potential savings in memory bandwidth.
         // This needs to be reevaluated for newer devices.
         { gfxASurface::ImageFormatRGB16_565, kEGLConfigAttribsRGB16 },
 #endif
         { gfxASurface::ImageFormatARGB32, kEGLConfigAttribsRGBA32 },
     };
 
     EGLConfig configs[64];
-    for (unsigned i = 0; i < NS_ARRAY_LENGTH(attribsToTry); ++i) {
+    for (unsigned i = 0; i < ArrayLength(attribsToTry); ++i) {
         const EGLAttribs& attribs = attribsToTry[i];
-        EGLint ncfg = NS_ARRAY_LENGTH(configs);
+        EGLint ncfg = ArrayLength(configs);
 
         if (!sEGLLibrary.fChooseConfig(EGL_DISPLAY(), attribs.mAttribs,
                                        configs, ncfg, &ncfg) ||
             ncfg < 1)
         {
             continue;
         }
 
--- a/gfx/thebes/gfxAtoms.cpp
+++ b/gfx/thebes/gfxAtoms.cpp
@@ -29,30 +29,34 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "gfxAtoms.h"
 #include "nsStaticAtom.h"
 #include "nsMemory.h"
 
+using namespace mozilla;
+
 #define GFX_ATOM(name_, value_) nsIAtom* gfxAtoms::name_ = 0;
 #include "gfxAtomList.h"
 #undef GFX_ATOM
 
 #define GFX_ATOM(name_, value_) NS_STATIC_ATOM_BUFFER(name_##_buffer, value_)
 #include "gfxAtomList.h"
 #undef GFX_ATOM
 
 static const nsStaticAtom atoms[] = {
 #define GFX_ATOM(name_, value_) NS_STATIC_ATOM(name_##_buffer, &gfxAtoms::name_),
 #include "gfxAtomList.h"
 #undef GFX_ATOM
 };
 
 void gfxAtoms::RegisterAtoms()
 {
-    NS_RegisterStaticAtoms(atoms, NS_ARRAY_LENGTH(atoms));
+    NS_RegisterStaticAtoms(atoms, ArrayLength(atoms));
 }
--- a/gfx/thebes/gfxCoreTextShaper.cpp
+++ b/gfx/thebes/gfxCoreTextShaper.cpp
@@ -33,16 +33,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "prtypes.h"
 #include "nsAlgorithm.h"
 #include "prmem.h"
 #include "nsString.h"
 #include "nsBidiUtils.h"
 
 #include "gfxTypes.h"
 
@@ -58,16 +60,18 @@
 #include "gfxFontUtils.h"
 
 #include "gfxQuartzSurface.h"
 #include "gfxMacPlatformFontList.h"
 #include "gfxUserFontSet.h"
 
 #include "nsUnicodeRange.h"
 
+using namespace mozilla;
+
 // standard font descriptors that we construct the first time they're needed
 CTFontDescriptorRef gfxCoreTextShaper::sDefaultFeaturesDescriptor = NULL;
 CTFontDescriptorRef gfxCoreTextShaper::sDisableLigaturesDescriptor = NULL;
 
 gfxCoreTextShaper::gfxCoreTextShaper(gfxMacFont *aFont)
     : gfxFontShaper(aFont)
 {
     // Create our CTFontRef
@@ -551,52 +555,52 @@ gfxCoreTextShaper::CreateDefaultFeatures
                            kCTFontFeatureSelectorIdentifierKey };
     CFTypeRef values[] = { swashesType,
                            lineInitialsOffSelector };
     CFDictionaryRef featureSettings[2];
     featureSettings[0] =
         ::CFDictionaryCreate(kCFAllocatorDefault,
                              (const void **) keys,
                              (const void **) values,
-                             NS_ARRAY_LENGTH(keys),
+                             ArrayLength(keys),
                              &kCFTypeDictionaryKeyCallBacks,
                              &kCFTypeDictionaryValueCallBacks);
     ::CFRelease(lineInitialsOffSelector);
 
     val = kLineFinalSwashesOffSelector;
     CFNumberRef lineFinalsOffSelector =
         ::CFNumberCreate(kCFAllocatorDefault,
                          kCFNumberSInt16Type,
                          &val);
     values[1] = lineFinalsOffSelector;
     featureSettings[1] =
         ::CFDictionaryCreate(kCFAllocatorDefault,
                              (const void **) keys,
                              (const void **) values,
-                             NS_ARRAY_LENGTH(keys),
+                             ArrayLength(keys),
                              &kCFTypeDictionaryKeyCallBacks,
                              &kCFTypeDictionaryValueCallBacks);
     ::CFRelease(lineFinalsOffSelector);
     ::CFRelease(swashesType);
 
     CFArrayRef featuresArray =
         ::CFArrayCreate(kCFAllocatorDefault,
                         (const void **) featureSettings,
-                        NS_ARRAY_LENGTH(featureSettings),
+                        ArrayLength(featureSettings),
                         &kCFTypeArrayCallBacks);
     ::CFRelease(featureSettings[0]);
     ::CFRelease(featureSettings[1]);
 
     const CFTypeRef attrKeys[]   = { kCTFontFeatureSettingsAttribute };
     const CFTypeRef attrValues[] = { featuresArray };
     CFDictionaryRef attributesDict =
         ::CFDictionaryCreate(kCFAllocatorDefault,
                              (const void **) attrKeys,
                              (const void **) attrValues,
-                             NS_ARRAY_LENGTH(attrKeys),
+                             ArrayLength(attrKeys),
                              &kCFTypeDictionaryKeyCallBacks,
                              &kCFTypeDictionaryValueCallBacks);
     ::CFRelease(featuresArray);
 
     sDefaultFeaturesDescriptor =
         ::CTFontDescriptorCreateWithAttributes(attributesDict);
     ::CFRelease(attributesDict);
 }
@@ -621,17 +625,17 @@ gfxCoreTextShaper::CreateCTFontWithDisab
         const CFTypeRef keys[]   = { kCTFontFeatureTypeIdentifierKey,
                                      kCTFontFeatureSelectorIdentifierKey };
         const CFTypeRef values[] = { ligaturesType,
                                      commonLigaturesOffSelector };
         CFDictionaryRef featureSettingDict =
             ::CFDictionaryCreate(kCFAllocatorDefault,
                                  (const void **) keys,
                                  (const void **) values,
-                                 NS_ARRAY_LENGTH(keys),
+                                 ArrayLength(keys),
                                  &kCFTypeDictionaryKeyCallBacks,
                                  &kCFTypeDictionaryValueCallBacks);
         ::CFRelease(ligaturesType);
         ::CFRelease(commonLigaturesOffSelector);
 
         CFArrayRef featuresArray =
             ::CFArrayCreate(kCFAllocatorDefault,
                             (const void **) &featureSettingDict,
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -29,16 +29,19 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG /* Allow logging in the release build */
 #endif /* MOZ_LOGGING */
 
 #include "gfxDWriteFontList.h"
 #include "gfxDWriteFonts.h"
 #include "nsUnicharUtils.h"
 #include "nsILocaleService.h"
@@ -1010,17 +1013,17 @@ gfxDWriteFontList::GetFontSubstitutes()
           L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes",
           0, KEY_READ, &hKey) != ERROR_SUCCESS)
     {
         return NS_ERROR_FAILURE;
     }
 
     for (i = 0, rv = ERROR_SUCCESS; rv != ERROR_NO_MORE_ITEMS; i++) {
         aliasName[0] = 0;
-        lenAlias = NS_ARRAY_LENGTH(aliasName);
+        lenAlias = ArrayLength(aliasName);
         actualName[0] = 0;
         lenActual = sizeof(actualName);
         rv = RegEnumValueW(hKey, i, aliasName, &lenAlias, NULL, &valueType, 
                 (LPBYTE)actualName, &lenActual);
 
         if (rv != ERROR_SUCCESS || valueType != REG_SZ || lenAlias == 0) {
             continue;
         }
@@ -1058,17 +1061,17 @@ static const FontSubstitution sDirectWri
     { L"Small Fonts", L"Arial" },
     { L"Roman", L"Times New Roman" },
     { L"Script", L"Mistral" }
 };
 
 void
 gfxDWriteFontList::GetDirectWriteSubstitutes()
 {
-    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(sDirectWriteSubs); ++i) {
+    for (PRUint32 i = 0; i < ArrayLength(sDirectWriteSubs); ++i) {
         const FontSubstitution& sub(sDirectWriteSubs[i]);
         nsAutoString substituteName((PRUnichar*)sub.aliasName);
         BuildKeyNameFromFontName(substituteName);
         if (nsnull != mFontFamilies.GetWeak(substituteName)) {
             // don't do the substitution if user actually has a usable font
             // with this name installed
             continue;
         }
--- a/gfx/thebes/gfxFT2FontList.cpp
+++ b/gfx/thebes/gfxFT2FontList.cpp
@@ -34,16 +34,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #if defined(MOZ_WIDGET_GTK2)
 #include "gfxPlatformGtk.h"
 #define gfxToolkitPlatform gfxPlatformGtk
 #elif defined(MOZ_WIDGET_QT)
 #include <qfontinfo.h>
 #include "gfxQtPlatform.h"
 #define gfxToolkitPlatform gfxQtPlatform
 #elif defined(XP_WIN)
@@ -85,16 +87,18 @@
 #include "mozilla/scache/StartupCache.h"
 #include <sys/stat.h>
 
 #ifdef XP_WIN
 #include "nsIWindowsRegKey.h"
 #include <windows.h>
 #endif
 
+using namespace mozilla;
+
 #ifdef PR_LOGGING
 static PRLogModuleInfo *gFontInfoLog = PR_NewLogModule("fontInfoLog");
 #endif /* PR_LOGGING */
 
 #undef LOG
 #define LOG(args) PR_LOG(gFontInfoLog, PR_LOG_DEBUG, args)
 #define LOG_ENABLED() PR_LOG_TEST(gFontInfoLog, PR_LOG_DEBUG)
 
@@ -923,17 +927,17 @@ gfxFT2FontList::FindFonts()
         }
         const char *ext = ent->d_name + namelen - 4;
         if (strcasecmp(ext, ".ttf") == 0 ||
             strcasecmp(ext, ".otf") == 0 ||
             strcasecmp(ext, ".ttc") == 0)
         {
             bool isStdFont = false;
             for (unsigned int i = 0;
-                 i < NS_ARRAY_LENGTH(sStandardFonts) && !isStdFont; i++)
+                 i < ArrayLength(sStandardFonts) && !isStdFont; i++)
             {
                 isStdFont = strcmp(sStandardFonts[i], ent->d_name) == 0;
             }
 
             nsCString s(root);
             s.Append('/');
             s.Append(ent->d_name, namelen);
 
--- a/gfx/thebes/gfxFontUtils.cpp
+++ b/gfx/thebes/gfxFontUtils.cpp
@@ -32,16 +32,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "gfxFontUtils.h"
 
 #include "nsServiceManagerUtils.h"
 
 #include "mozilla/Preferences.h"
 
 #include "nsIStreamBufferAccess.h"
 #include "nsIUUIDGenerator.h"
@@ -55,17 +57,17 @@
 #ifdef XP_MACOSX
 #include <CoreFoundation/CoreFoundation.h>
 #endif
 
 #define NO_RANGE_FOUND 126 // bit 126 in the font unicode ranges is required to be 0
 
 #define UNICODE_BMP_LIMIT 0x10000
 
-using namespace mozilla; // for the AutoSwap_* types
+using namespace mozilla;
 
 /* Unicode subrange table
  *   from: http://msdn.microsoft.com/en-us/library/dd374090
  *
  * Edit the text to extend the initial digit, then use something like:
  * perl -pi -e 's/^(\d+)\t([\dA-Fa-f]+)\s+-\s+([\dA-Fa-f]+)\s+\b([a-zA-Z0-9\(\)\- ]+)/    { \1, 0x\2, 0x\3, \"\4\" },/' < unicoderange.txt
  * to generate the below list.
  */
@@ -1296,17 +1298,17 @@ gfxFontUtils::RenameFont(const nsAString
     // new name table
     static const PRUint32 neededNameIDs[] = {NAME_ID_FAMILY, 
                                              NAME_ID_STYLE,
                                              NAME_ID_UNIQUE,
                                              NAME_ID_FULL,
                                              NAME_ID_POSTSCRIPT};
 
     // calculate new name table size
-    PRUint16 nameCount = NS_ARRAY_LENGTH(neededNameIDs);
+    PRUint16 nameCount = ArrayLength(neededNameIDs);
 
     // leave room for null-terminator
     PRUint16 nameStrLength = (aName.Length() + 1) * sizeof(PRUnichar); 
 
     // round name table size up to 4-byte multiple
     PRUint32 nameTableSize = (sizeof(NameHeader) +
                               sizeof(NameRecord) * nameCount +
                               nameStrLength +
--- a/gfx/thebes/gfxFontconfigUtils.cpp
+++ b/gfx/thebes/gfxFontconfigUtils.cpp
@@ -32,16 +32,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "gfxFontconfigUtils.h"
 #include "gfxFont.h"
 #include "gfxAtoms.h"
 
 #include <locale.h>
 #include <fontconfig/fontconfig.h>
 
 #include "nsServiceManagerUtils.h"
@@ -318,17 +320,17 @@ gfxFontconfigUtils::NewPattern(const nsT
 
             // fontconfig generic families are typically implemented with weak
             // aliases (so that the preferred font depends on language).
             // However, this would give them lower priority than subsequent
             // non-generic families in the list.  To ensure that subsequent
             // families do not have a higher priority, they are given weak
             // bindings.
             for (PRUint32 g = 0;
-                 g < NS_ARRAY_LENGTH(sFontconfigGenerics);
+                 g < ArrayLength(sFontconfigGenerics);
                  ++g) {
                 if (0 == FcStrCmpIgnoreCase(ToFcChar8(sFontconfigGenerics[g]),
                                             ToFcChar8(family.get()))) {
                     useWeakBinding = PR_TRUE;
                     break;
                 }
             }
         } else {
@@ -465,17 +467,17 @@ TryLangForGroup(const nsACString& aOSLan
 /* static */ void
 gfxFontconfigUtils::GetSampleLangForGroup(nsIAtom *aLangGroup,
                                           nsACString *aFcLang)
 {
     NS_PRECONDITION(aFcLang != nsnull, "aFcLang must not be NULL");
 
     const MozLangGroupData *langGroup = nsnull;
 
-    for (unsigned int i = 0; i < NS_ARRAY_LENGTH(MozLangGroups); ++i) {
+    for (unsigned int i = 0; i < ArrayLength(MozLangGroups); ++i) {
         if (aLangGroup == MozLangGroups[i].mozLangGroup) {
             langGroup = &MozLangGroups[i];
             break;
         }
     }
 
     if (!langGroup) {
         // Not a special mozilla language group.
--- a/gfx/thebes/gfxGDIFontList.cpp
+++ b/gfx/thebes/gfxGDIFontList.cpp
@@ -34,16 +34,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG /* Allow logging in the release build */
 #endif
 #include "prlog.h"
 
 #include "gfxGDIFontList.h"
 #include "gfxWindowsPlatform.h"
 #include "gfxUserFontSet.h"
@@ -619,17 +621,17 @@ gfxGDIFontList::GetFontSubstitutes()
           L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes",
           0, KEY_READ, &hKey) != ERROR_SUCCESS)
     {
         return NS_ERROR_FAILURE;
     }
 
     for (i = 0, rv = ERROR_SUCCESS; rv != ERROR_NO_MORE_ITEMS; i++) {
         aliasName[0] = 0;
-        lenAlias = NS_ARRAY_LENGTH(aliasName);
+        lenAlias = ArrayLength(aliasName);
         actualName[0] = 0;
         lenActual = sizeof(actualName);
         rv = RegEnumValueW(hKey, i, aliasName, &lenAlias, NULL, &valueType, 
                 (LPBYTE)actualName, &lenActual);
 
         if (rv != ERROR_SUCCESS || valueType != REG_SZ || lenAlias == 0) {
             continue;
         }
--- a/gfx/thebes/gfxPangoFonts.cpp
+++ b/gfx/thebes/gfxPangoFonts.cpp
@@ -37,16 +37,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #define PANGO_ENABLE_BACKEND
 #define PANGO_ENABLE_ENGINE
 
 #include "prtypes.h"
 #include "prlink.h"
 #include "gfxTypes.h"
 
 #include "nsTArray.h"
@@ -79,16 +81,18 @@
 #include <pango/pangofc-fontmap.h>
 
 #ifdef MOZ_WIDGET_GTK2
 #include <gdk/gdk.h>
 #endif
 
 #include <math.h>
 
+using namespace mozilla;
+
 #define FLOAT_PANGO_SCALE ((gfxFloat)PANGO_SCALE)
 
 #ifndef PANGO_VERSION_CHECK
 #define PANGO_VERSION_CHECK(x,y,z) 0
 #endif
 #ifndef PANGO_GLYPH_UNKNOWN_FLAG
 #define PANGO_GLYPH_UNKNOWN_FLAG ((PangoGlyph)0x10000000)
 #endif
@@ -305,19 +309,19 @@ gfxFcFontEntry::ShouldUseHarfBuzz(PRInt3
     hb_script_t script =
         aRunScript <= HB_SCRIPT_INHERITED ? HB_SCRIPT_LATIN
         : static_cast<hb_script_t>(aRunScript);
 
     // Prefer HarfBuzz if the font also has support for OpenType shaping of
     // this script.
     const FcChar8 otCapTemplate[] = "otlayout:XXXX";
     FcChar8 otCap[NS_ARRAY_LENGTH(otCapTemplate)];
-    memcpy(otCap, otCapTemplate, NS_ARRAY_LENGTH(otCapTemplate));
+    memcpy(otCap, otCapTemplate, ArrayLength(otCapTemplate));
     // Subtract 5, for 4 characters and NUL. 
-    const PRUint32 scriptOffset = NS_ARRAY_LENGTH(otCapTemplate) - 5;
+    const PRUint32 scriptOffset = ArrayLength(otCapTemplate) - 5;
 
     for (const hb_tag_t *scriptTags = hb_ot_tags_from_script(script);
          hb_tag_t scriptTag = *scriptTags;
          scriptTags++) {
         if (scriptTag == HB_TAG('D','F','L','T')) { // e.g. HB_SCRIPT_UNKNOWN
             continue;
         }
 
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -33,16 +33,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "gfxWindowsPlatform.h"
 
 #include "gfxImageSurface.h"
 #include "gfxWindowsSurface.h"
 #include "gfxTextRunWordCache.h"
 
 #include "nsUnicharUtils.h"
 
@@ -68,16 +70,17 @@
 #include "gfxDWriteCommon.h"
 #include <dwrite.h>
 #endif
 
 #include "gfxUserFontSet.h"
 
 #include <string>
 
+using namespace mozilla;
 using namespace mozilla::gfx;
 
 #ifdef CAIRO_HAS_D2D_SURFACE
 #include "gfxD2DSurface.h"
 
 #include <d3d10_1.h>
 #include <dxgi.h>
 
@@ -794,29 +797,29 @@ gfxWindowsPlatform::GetCleartypeParams(n
                        0, KEY_READ, &hKey);
 
     if (rv != ERROR_SUCCESS) {
         return;
     }
 
     // enumerate over subkeys
     for (i = 0, rv = ERROR_SUCCESS; rv != ERROR_NO_MORE_ITEMS; i++) {
-        size = NS_ARRAY_LENGTH(displayName);
+        size = ArrayLength(displayName);
         rv = RegEnumKeyExW(hKey, i, displayName, &size, NULL, NULL, NULL, NULL);
         if (rv != ERROR_SUCCESS) {
             continue;
         }
 
         ClearTypeParameterInfo ctinfo;
         ctinfo.displayName.Assign(displayName);
 
         DWORD subrv, value;
         bool foundData = false;
 
-        swprintf_s(subkeyName, NS_ARRAY_LENGTH(subkeyName),
+        swprintf_s(subkeyName, ArrayLength(subkeyName),
                    L"Software\\Microsoft\\Avalon.Graphics\\%s", displayName);
 
         // subkey for gamma, pixel structure
         subrv = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
                               subkeyName, 0, KEY_QUERY_VALUE, &subKey);
 
         if (subrv == ERROR_SUCCESS) {
             size = sizeof(value);
--- a/intl/locale/src/nsCharsetAliasImp.cpp
+++ b/intl/locale/src/nsCharsetAliasImp.cpp
@@ -30,28 +30,31 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
 
 #include "nsICharsetAlias.h"
 #include "pratom.h"
 
 // for NS_IMPL_IDS only
 #include "nsIPlatformCharset.h"
 
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsUConvPropertySearch.h"
 #include "nsCharsetAlias.h"
 
+using namespace mozilla;
+
 //--------------------------------------------------------------
 NS_IMPL_THREADSAFE_ISUPPORTS1(nsCharsetAlias2, nsICharsetAlias)
 
 //--------------------------------------------------------------
 nsCharsetAlias2::nsCharsetAlias2()
 {
 }
 //--------------------------------------------------------------
@@ -69,17 +72,17 @@ NS_IMETHODIMP nsCharsetAlias2::GetPrefer
                                             nsACString& oResult)
 {
    if (aAlias.IsEmpty()) return NS_ERROR_NULL_POINTER;
 
    nsCAutoString key(aAlias);
    ToLowerCase(key);
 
    nsresult rv = nsUConvPropertySearch::SearchPropertyValue(kAliases,
-      NS_ARRAY_LENGTH(kAliases), key, oResult);
+      ArrayLength(kAliases), key, oResult);
 
   return rv;
 }
 
 //--------------------------------------------------------------
 NS_IMETHODIMP
 nsCharsetAlias2::Equals(const nsACString& aCharset1,
                         const nsACString& aCharset2, bool* oResult)
--- a/intl/locale/src/os2/nsOS2Charset.cpp
+++ b/intl/locale/src/os2/nsOS2Charset.cpp
@@ -33,28 +33,33 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/Util.h"
+
 #include "nsIPlatformCharset.h"
 #include "nsUConvPropertySearch.h"
 #include "pratom.h"
 #define INCL_WIN
 #include <os2.h>
 #include "nsIOS2Locale.h"
 #include "nsCOMPtr.h"
 #include "nsReadableUtils.h"
 #include "nsLocaleCID.h"
 #include "nsIServiceManager.h"
 #include "nsPlatformCharset.h"
 
+using namespace mozilla;
+
 static const char* kOS2Charsets[][3] = {
 #include "os2charset.properties.h"
 };
 
 NS_IMPL_ISUPPORTS1(nsPlatformCharset, nsIPlatformCharset)
 
 nsPlatformCharset::nsPlatformCharset()
 {
@@ -71,17 +76,17 @@ nsPlatformCharset::~nsPlatformCharset()
 
 nsresult
 nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsACString& outCharset)
 {
   nsCAutoString key;
   LossyCopyUTF16toASCII(inANSICodePage, key);
 
   nsresult rv = nsUConvPropertySearch::SearchPropertyValue(kOS2Charsets,
-      NS_ARRAY_LENGTH(kOS2Charsets), key, outCharset);
+      ArrayLength(kOS2Charsets), key, outCharset);
   if (NS_FAILED(rv)) {
     outCharset.AssignLiteral("IBM850");
   }
   return rv;
 }
 
 NS_IMETHODIMP 
 nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
--- a/intl/locale/src/unix/nsUNIXCharset.cpp
+++ b/intl/locale/src/unix/nsUNIXCharset.cpp
@@ -31,16 +31,19 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include <locale.h>
+
+#include "mozilla/Util.h"
+
 #include "nsIPlatformCharset.h"
 #include "pratom.h"
 #include "nsUConvPropertySearch.h"
 #include "nsCOMPtr.h"
 #include "nsReadableUtils.h"
 #include "nsIComponentManager.h"
 #include "nsIServiceManager.h"
 #include "nsIUnicodeDecoder.h"
@@ -55,16 +58,18 @@
 #endif
 #if HAVE_LANGINFO_CODESET
 #include <langinfo.h>
 #endif
 #include "nsPlatformCharset.h"
 #include "prinit.h"
 #include "nsUnicharUtils.h"
 
+using namespace mozilla;
+
 static const char* kUnixCharsets[][3] = {
 #include "unixcharset.properties.h"
 };
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(nsPlatformCharset, nsIPlatformCharset)
 
 nsPlatformCharset::nsPlatformCharset()
 {
@@ -77,25 +82,25 @@ nsPlatformCharset::ConvertLocaleToCharse
     nsCAutoString platformLocaleKey;
     // note: NS_LITERAL_STRING("locale." OSTYPE ".") does not compile on AIX
     platformLocaleKey.AssignLiteral("locale.");
     platformLocaleKey.Append(OSTYPE);
     platformLocaleKey.AppendLiteral(".");
     platformLocaleKey.AppendWithConversion(locale);
 
     nsresult res = nsUConvPropertySearch::SearchPropertyValue(kUnixCharsets,
-        NS_ARRAY_LENGTH(kUnixCharsets), platformLocaleKey, oResult);
+        ArrayLength(kUnixCharsets), platformLocaleKey, oResult);
     if (NS_SUCCEEDED(res))  {
       return NS_OK;
     }
     nsCAutoString localeKey;
     localeKey.AssignLiteral("locale.all.");
     localeKey.AppendWithConversion(locale);
     res = nsUConvPropertySearch::SearchPropertyValue(kUnixCharsets,
-        NS_ARRAY_LENGTH(kUnixCharsets), localeKey, oResult);
+        ArrayLength(kUnixCharsets), localeKey, oResult);
     if (NS_SUCCEEDED(res))  {
       return NS_OK;
     }
    }
    NS_ERROR("unable to convert locale to charset using deprecated config");
    mCharset.AssignLiteral("ISO-8859-1");
    oResult.AssignLiteral("ISO-8859-1");
    return NS_SUCCESS_USING_FALLBACK_LOCALE;
--- a/intl/locale/src/windows/nsWin32Locale.cpp
+++ b/intl/locale/src/windows/nsWin32Locale.cpp
@@ -30,26 +30,30 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nscore.h"
 #include "nsString.h"
 #include "nsXPCOMStrings.h"
 #include "nsReadableUtils.h"
 #include "nsWin32Locale.h"
 #include "nsLocaleCID.h"
 #include "prprf.h"
 #include <windows.h>
 #include "nsCRT.h"
 
+using namespace mozilla;
+
 struct iso_pair 
 {
 	const char*	iso_code;
 	DWORD       win_code;
 };
 
 struct iso_map
 {
@@ -511,17 +515,17 @@ iso_map iso_list[] =
 		{ "CN", SUBLANG_CHINESE_SIMPLIFIED },
 		{ "HK", SUBLANG_CHINESE_HONGKONG },
 		{ "SG", SUBLANG_CHINESE_SINGAPORE },
 		{ "MO", SUBLANG_CHINESE_MACAU },
 		{ "",0}}
 	}
 };
 
-#define LENGTH_MAPPING_LIST		NS_ARRAY_LENGTH(iso_list)
+#define LENGTH_MAPPING_LIST		ArrayLength(iso_list)
 	
 //
 // This list maps ISO 2 digit country codes to Win32 country codes.
 // This list must be kept in alphabetic (by iso code) order and synchronized
 // with the list above.  This is only used in debug builds to check the consistentcy
 // of the internal tables.
 //
 #ifdef DEBUG
--- a/intl/locale/src/windows/nsWinCharset.cpp
+++ b/intl/locale/src/windows/nsWinCharset.cpp
@@ -30,28 +30,32 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "mozilla/Util.h"
+
 #include "nsIPlatformCharset.h"
 #include "nsUConvPropertySearch.h"
 #include "pratom.h"
 #include <windows.h>
 #include "nsWin32Locale.h"
 #include "nsCOMPtr.h"
 #include "nsReadableUtils.h"
 #include "nsLocaleCID.h"
 #include "nsServiceManagerUtils.h"
 #include "nsPlatformCharset.h"
 #include "nsEncoderDecoderUtils.h"
 
+using namespace mozilla;
+
 static const char* kWinCharsets[][3] = {
 #include "wincharset.properties.h"
 };
 
 NS_IMPL_ISUPPORTS1(nsPlatformCharset, nsIPlatformCharset)
 
 nsPlatformCharset::nsPlatformCharset()
 {
@@ -66,17 +70,17 @@ nsPlatformCharset::~nsPlatformCharset()
 
 nsresult
 nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsACString& outCharset)
 {
   nsCAutoString key;
   LossyCopyUTF16toASCII(inANSICodePage, key);
 
   nsresult rv = nsUConvPropertySearch::SearchPropertyValue(kWinCharsets,
-      NS_ARRAY_LENGTH(kWinCharsets), key, outCharset);
+      ArrayLength(kWinCharsets), key, outCharset);
   if (NS_FAILED(rv)) {
     outCharset.AssignLiteral("windows-1252");
     return NS_SUCCESS_USING_FALLBACK_LOCALE;
   }
   return rv;
 }
 
 NS_IMETHODIMP 
@@ -98,17 +102,17 @@ nsPlatformCharset::GetDefaultCharsetForL
   nsresult rv;
   oResult.Truncate();
 
   rv = nsWin32Locale::GetPlatformLocale(localeName, &localeAsLCID);
   if (NS_FAILED(rv)) { return rv; }
 
   PRUnichar acp_name[6];
   if (GetLocaleInfoW(localeAsLCID, LOCALE_IDEFAULTANSICODEPAGE, acp_name,
-                     NS_ARRAY_LENGTH(acp_name))==0) {
+                     ArrayLength(acp_name))==0) {
     return NS_ERROR_FAILURE; 
   }
   nsAutoString acp_key(NS_LITERAL_STRING("acp."));
   acp_key.Append(acp_name);
 
   return MapToCharset(acp_key, oResult);
 }
 
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -36,16 +36,18 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __IPC_GLUE_IPCMESSAGEUTILS_H__
 #define __IPC_GLUE_IPCMESSAGEUTILS_H__
 
 #include "chrome/common/ipc_message_utils.h"
 
+#include "mozilla/Util.h"
+
 #include "prtypes.h"
 #include "nsID.h"
 #include "nsMemory.h"
 #include "nsStringGlue.h"
 #include "nsTArray.h"
 #include "gfx3DMatrix.h"
 #include "gfxColor.h"
 #include "gfxMatrix.h"
@@ -731,43 +733,43 @@ struct ParamTraits<nsID>
 {
   typedef nsID paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     WriteParam(aMsg, aParam.m0);
     WriteParam(aMsg, aParam.m1);
     WriteParam(aMsg, aParam.m2);
-    for (unsigned int i = 0; i < NS_ARRAY_LENGTH(aParam.m3); i++) {
+    for (unsigned int i = 0; i < mozilla::ArrayLength(aParam.m3); i++) {
       WriteParam(aMsg, aParam.m3[i]);
     }
   }
 
   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   {
     if(!ReadParam(aMsg, aIter, &(aResult->m0)) ||
        !ReadParam(aMsg, aIter, &(aResult->m1)) ||
        !ReadParam(aMsg, aIter, &(aResult->m2)))
       return false;
 
-    for (unsigned int i = 0; i < NS_ARRAY_LENGTH(aResult->m3); i++)
+    for (unsigned int i = 0; i < mozilla::ArrayLength(aResult->m3); i++)
       if (!ReadParam(aMsg, aIter, &(aResult->m3[i])))
         return false;
 
     return true;
   }
 
   static void Log(const paramType& aParam, std::wstring* aLog)
   {
     aLog->append(L"{");
     aLog->append(StringPrintf(L"%8.8X-%4.4X-%4.4X-",
                               aParam.m0,
                               aParam.m1,
                               aParam.m2));
-    for (unsigned int i = 0; i < NS_ARRAY_LENGTH(aParam.m3); i++)
+    for (unsigned int i = 0; i < mozilla::ArrayLength(aParam.m3); i++)
       aLog->append(StringPrintf(L"%2.2X", aParam.m3[i]));
     aLog->append(L"}");
   }
 };
 
 } /* namespace IPC */
 
 #endif /* __IPC_GLUE_IPCMESSAGEUTILS_H__ */
--- a/ipc/testshell/TestShellParent.cpp
+++ b/ipc/testshell/TestShellParent.cpp
@@ -30,21 +30,26 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "TestShellParent.h"
+
+/* This must occur *after* TestShellParent.h to avoid typedefs conflicts. */
+#include "mozilla/Util.h"
+
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/jsipc/ContextWrapperParent.h"
 
 #include "nsAutoPtr.h"
 
+using namespace mozilla;
 using mozilla::ipc::TestShellParent;
 using mozilla::ipc::TestShellCommandParent;
 using mozilla::ipc::PTestShellCommandParent;