Bug 1382435 - Create Symbols from Symbol.for() with a different hash from the atom used to create them; r=jandem
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 19 Jul 2017 18:30:55 -0400
changeset 369993 fd9640f4e73397e57ac213e2d355f371aac312c9
parent 369992 4de026113ad0c1a66ae4e8b98bf74c8b38554c91
child 369994 da3b6b55ed0ba18e6efa6198c22af3ef8c90b5b3
push id32209
push userarchaeopteryx@coole-files.de
push dateFri, 21 Jul 2017 12:15:28 +0000
treeherdermozilla-central@874cdf9f9c9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1382435
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1382435 - Create Symbols from Symbol.for() with a different hash from the atom used to create them; r=jandem
js/src/vm/Symbol.cpp
--- a/js/src/vm/Symbol.cpp
+++ b/js/src/vm/Symbol.cpp
@@ -71,17 +71,20 @@ Symbol::for_(JSContext* cx, HandleString
     if (p) {
         cx->markAtom(*p);
         return *p;
     }
 
     Symbol* sym;
     {
         AutoAtomsCompartment ac(cx, lock);
-        sym = newInternal(cx, SymbolCode::InSymbolRegistry, atom->hash(), atom, lock);
+        // Rehash the hash of the atom to give the corresponding symbol a hash
+        // that is different than the hash of the corresponding atom.
+        HashNumber hash = mozilla::HashGeneric(atom->hash());
+        sym = newInternal(cx, SymbolCode::InSymbolRegistry, hash, atom, lock);
         if (!sym)
             return nullptr;
 
         // p is still valid here because we have held the lock since the
         // lookupForAdd call, and newInternal can't GC.
         if (!registry.add(p, sym)) {
             // SystemAllocPolicy does not report OOM.
             ReportOutOfMemory(cx);