Bug 1295343 - Fix a strict aliasing warning in js::WeakMap. The resulting code will additionally fail to compile if you instantiate it with an invalid key type.

--HG--
extra : rebase_source : 5466eec299bbbae550e8fdca32e44c45ef45b695
This commit is contained in:
Steve Fink 2016-08-05 20:52:18 -07:00
parent 021a12c86f
commit cfe23d1b52

View File

@ -179,8 +179,10 @@ class WeakMap : public HashMap<Key, Value, HashPolicy, RuntimeAllocPolicy>,
{
MOZ_ASSERT(marked);
gc::Cell* l = origKey.asCell();
Ptr p = Base::lookup(reinterpret_cast<Lookup&>(l));
// If this cast fails, then you're instantiating the WeakMap with a
// Lookup that can't be constructed from a Cell*. The WeakKeyTable
// mechanism is indexed with a GCCellPtr, so that won't work.
Ptr p = Base::lookup(static_cast<Lookup>(origKey.asCell()));
MOZ_ASSERT(p.found());
Key key(p->key());