Bug 1445113 - Disallow duplicate static atoms. r=froydnj

This will allow us to work with direct pointers to static atoms that are
initialized at compile-time, rather than pointers to pointers to static atoms
that are initialized at runtime.

MozReview-Commit-ID: K04pEicuqu3

--HG--
extra : rebase_source : c5d895b34567c621f4591769390fc95a4c6ff405
This commit is contained in:
Nicholas Nethercote 2018-03-29 05:54:10 +11:00
parent 8c5d5f7c30
commit 380782f6b6

View File

@ -666,20 +666,17 @@ nsAtomTable::RegisterStaticAtoms(const nsStaticAtomSetup* aSetup,
AtomTableEntry* he = table.Add(key);
if (he->mAtom) {
// 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 (!he->mAtom->IsStatic()) {
nsAutoCString name;
he->mAtom->ToUTF8String(name);
MOZ_CRASH_UNSAFE_PRINTF(
"Static atom registration for %s should be pushed back", name.get());
}
// XXX: A duplicate static atom! Bug 1445113 will disallow this case.
*atomp = static_cast<nsStaticAtom*>(he->mAtom);
} else {
he->mAtom = *atomp = const_cast<nsStaticAtom*>(atom);
// There are two ways we could get here.
// - Register two static atoms with the same string.
// - Create a dynamic atom and then register a static atom with the same
// string while the dynamic atom is alive.
// Both cases can cause subtle bugs, and are disallowed. We're
// programming in C++ here, not Smalltalk.
nsAutoCString name;
he->mAtom->ToUTF8String(name);
MOZ_CRASH_UNSAFE_PRINTF("Atom for '%s' already exists", name.get());
}
he->mAtom = *atomp = const_cast<nsStaticAtom*>(atom);
}
}