root-layout-stuff
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 153 cd96178a2e472dc6cd10443a56a3cedf9e8e1140
permissions -rw-r--r--
State as of now

diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -61,6 +61,7 @@
 #include "nsTextFragment.h"
 
 struct nsNativeKeyEvent; // Don't include nsINativeKeyBindings.h here: it will force strange compilation error!
+#include "nsGkAtoms.h"
 
 class nsIDOMScriptObjectFactory;
 class nsIXPConnect;
@@ -1300,6 +1301,8 @@ private:
     JSRuntime* sJSScriptRuntime;
 
     nsCOMArray<nsIRunnable> sBlockedScriptRunners;
+
+    nsGkAtoms sGKAtoms;
   };
 
   static LayoutRoots *sLayoutRoots;
diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -284,6 +284,8 @@ nsContentUtils::LayoutRoots::Init()
   if (!InitializeEventTable())
     return NS_ERROR_FAILURE;
 
+  sGKAtoms.RootAtoms();
+
   if (!sEventListenerManagersHash.ops) {
     static PLDHashTableOps hash_table_ops =
     {
diff --git a/content/base/src/nsGkAtoms.cpp b/content/base/src/nsGkAtoms.cpp
--- a/content/base/src/nsGkAtoms.cpp
+++ b/content/base/src/nsGkAtoms.cpp
@@ -49,14 +49,19 @@
 #include "nsGkAtomList.h"
 #undef GK_ATOM
 
-static const nsStaticAtom GkAtoms_info[] = {
-#define GK_ATOM(name_, value_) { value_, &nsGkAtoms::name_ },
+void nsGkAtoms::RootAtoms()
+{
+  nsStaticAtom GkAtoms_info[] = {
+#define GK_ATOM(name_, value_) { value_, &name_##root },
 #include "nsGkAtomList.h"
 #undef GK_ATOM
-};
+  };
 
-void nsGkAtoms::AddRefAtoms()
-{
+  // This sets our members
   NS_RegisterStaticAtoms(GkAtoms_info, NS_ARRAY_LENGTH(GkAtoms_info));
+
+  // Copy members to statics
+#define GK_ATOM(name_, value_) name_ = name_##root;
+#include "nsGkAtomList.h"
+#undef GK_ATOM
 }
-
diff --git a/content/base/src/nsGkAtoms.h b/content/base/src/nsGkAtoms.h
--- a/content/base/src/nsGkAtoms.h
+++ b/content/base/src/nsGkAtoms.h
@@ -48,8 +48,9 @@
 
 class nsGkAtoms {
 public:
-
-  static void AddRefAtoms();
+  // A single instance of nsGkAtoms is maintained by the nsContentUtils root:
+  // this instance sets the static variable for general use
+  void RootAtoms();
 
   /* Declare all atoms
 
@@ -61,6 +62,10 @@ public:
 #define GK_ATOM(_name, _value) static nsIAtom* _name;
 #include "nsGkAtomList.h"
 #undef GK_ATOM
+
+#define GK_ATOM(_name, _value) nsIAtom* _name##root;
+#include "nsGkAtomList.h"
+#undef GK_ATOM
 };
 
 #endif /* nsGkAtoms_h___ */
diff --git a/content/xslt/src/xslt/txStylesheetCompileHandlers.cpp b/content/xslt/src/xslt/txStylesheetCompileHandlers.cpp
--- a/content/xslt/src/xslt/txStylesheetCompileHandlers.cpp
+++ b/content/xslt/src/xslt/txStylesheetCompileHandlers.cpp
@@ -3014,13 +3014,15 @@ txHandlerTable::find(PRInt32 aNamespaceI
     return handler;
 }
 
+// XXXbsmedberg: NO ROOTING-UNTIL-SHUTDOWN!
 #define INIT_HANDLER(_name)                                          \
     gTx##_name##Handler =                                            \
         new txHandlerTable(gTx##_name##TableData.mTextHandler,       \
                            &gTx##_name##TableData.mLREHandler,       \
                            &gTx##_name##TableData.mOtherHandler);    \
     if (!gTx##_name##Handler)                                        \
-        return PR_FALSE
+        return PR_FALSE;                                             \
+    NS_RootUntilShutdown(gTx##_name##Handler);
 
 #define INIT_HANDLER_WITH_ELEMENT_HANDLERS(_name)                    \
     INIT_HANDLER(_name);                                             \
diff --git a/layout/build/nsLayoutStatics.cpp b/layout/build/nsLayoutStatics.cpp
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -62,7 +62,6 @@
 #include "nsGenericElement.h"  // for nsDOMEventRTTearoff
 #include "nsStyledElement.h"
 #include "nsGlobalWindow.h"
-#include "nsGkAtoms.h"
 #include "nsImageFrame.h"
 #include "nsLayoutStylesheetCache.h"
 #include "nsNodeInfo.h"
@@ -138,7 +137,6 @@ nsLayoutStatics::Initialize()
   nsCSSKeywords::AddRefTable();
   nsCSSProps::AddRefTable();
   nsColorNames::AddRefTable();
-  nsGkAtoms::AddRefAtoms();
 
   nsDOMScriptObjectFactory::Startup();
   rv = nsContentUtils::Init();