diff --git a/js/public/HashTable.h b/js/public/HashTable.h index c8ad21d95ba4..1a5e814ff826 100644 --- a/js/public/HashTable.h +++ b/js/public/HashTable.h @@ -17,6 +17,7 @@ #include "mozilla/ReentrancyGuard.h" #include "mozilla/TemplateLib.h" #include "mozilla/TypeTraits.h" +#include "mozilla/UniquePtr.h" #include "js/Utility.h" @@ -586,6 +587,25 @@ template struct DefaultHasher : PointerHasher::value> {}; +// Specialize hashing policy for mozilla::UniquePtr to proxy the UniquePtr's +// raw pointer to PointerHasher. +template +struct DefaultHasher> +{ + using Lookup = mozilla::UniquePtr; + using PtrHasher = PointerHasher::value>; + + static HashNumber hash(const Lookup& l) { + return PtrHasher::hash(l.get()); + } + static bool match(const mozilla::UniquePtr& k, const Lookup& l) { + return PtrHasher::match(k.get(), l.get()); + } + static void rekey(mozilla::UniquePtr& k, mozilla::UniquePtr&& newKey) { + k = mozilla::Move(newKey); + } +}; + // For doubles, we can xor the two uint32s. template <> struct DefaultHasher