Bug 1276669 - Part 9: Forbid transmutation of dynamic atoms. r=erahm, a=ritu
authorNathan Froyd <froydnj@mozilla.com>
Thu, 26 Jan 2017 15:43:38 -0500
changeset 378110 2159ed149364daaadd4da371c00c4809cd5c3490
parent 378109 712c0d0da7dce945cab161b7dcfa6e6ceec87ea3
child 378111 8ee370bffd15ed59c401285dac62e7f24d4f15ef
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm, ritu
bugs1276669
milestone53.0a2
Bug 1276669 - Part 9: Forbid transmutation of dynamic atoms. r=erahm, a=ritu We can do this now that we've shuffled static atom initialization around appropriately.
xpcom/ds/nsAtomTable.cpp
--- a/xpcom/ds/nsAtomTable.cpp
+++ b/xpcom/ds/nsAtomTable.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/HashFunctions.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/DebugOnly.h"
+#include "mozilla/Sprintf.h"
 #include "mozilla/Unused.h"
 
 #include "nsAtomTable.h"
 #include "nsStaticAtom.h"
 #include "nsString.h"
 #include "nsCRT.h"
 #include "PLDHashTable.h"
 #include "prenv.h"
@@ -613,21 +614,30 @@ RegisterStaticAtoms(const nsStaticAtom* 
 
     uint32_t hash;
     AtomTableEntry* he =
       GetAtomHashEntry(static_cast<char16_t*>(stringBuffer->Data()),
                        stringLen, &hash);
 
     nsIAtom* atom = he->mAtom;
     if (atom) {
+      // Disallow creating a dynamic atom, and then later, while the
+      // dynamic atom is still alive, registering that same atom as a
+      // static atom.  It causes subtle bugs, and we're programming in
+      // C++ here, not Smalltalk.
       if (!atom->IsStaticAtom()) {
-        // A rare case: we're creating a StaticAtom but there is already a
-        // DynamicAtom of the same name. Transmute the DynamicAtom into a
-        // StaticAtom.
-        static_cast<DynamicAtom*>(atom)->TransmuteToStatic(stringBuffer);
+        nsAutoCString name;
+        atom->ToUTF8String(name);
+
+        static char sCrashReason[1024];
+        SprintfLiteral(sCrashReason,
+                       "static atom registration for %s should be pushed back",
+                       name.get());
+        MOZ_CRASH_ANNOTATE(sCrashReason);
+        MOZ_REALLY_CRASH();
       }
     } else {
       atom = new StaticAtom(stringBuffer, stringLen, hash);
       he->mAtom = atom;
     }
     *atomp = atom;
 
     if (!gStaticAtomTableSealed) {