Add specialized template declarations of HashTraits and DefaultHash to detect misuse
authorHironori.Fujii@sony.com <Hironori.Fujii@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Sep 2018 05:20:52 +0000 (05:20 +0000)
committerHironori.Fujii@sony.com <Hironori.Fujii@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Sep 2018 05:20:52 +0000 (05:20 +0000)
commit09dbf5c70d544e9e7a328175716ab6109a298b46
tree84107dcfc47b06ec84fc4f166308d8a14cb8eabe
parent3337ddf7981adbe79367510acf6fd39ffcc8b14f
Add specialized template declarations of HashTraits and DefaultHash to detect misuse
https://bugs.webkit.org/show_bug.cgi?id=189044

Reviewed by Yusuke Suzuki.

Source/WebCore:

Some classes have a separate header for specializations of
WTF::HashTraits and WTF::DefaultHash to reduce the number of
header files included. For example, ColorHash.h and Color.h.

If someone is mistakenly using HashSet or HashMap without
including the specialization header, unexpected template
instantiation can cause subtle bugs. For example, MSVC linker
would silently produce an broken executable (Bug 188893).

By applying this change, I found three misuse cases in
DebugPageOverlays.cpp, AVVideoCaptureSource.h and WebPage.h. As
far as I analyzed, I concluded that these misuses don't introduce
any bugs at the moment, and they are not testable (Bug 189044 Comment 9),
except the MSVC issue (Bug 188893).

No new tests (Covered by existing tests).

* Modules/webdatabase/SQLResultSetRowList.h: Removed unused #include <wtf/HashTraits.h>.
* bindings/js/SerializedScriptValue.cpp: Ditto.
* page/DebugPageOverlays.cpp: Added #include "ColorHash.h" to instantiate HashMap<String, Color>.
* platform/URLHash.h: Added DefaultHash<URL> specialization definition.
* platform/URL.h: Added specialized template declarations.
* platform/graphics/Color.h: Ditto.
* platform/graphics/FloatSize.h: Ditto.
* platform/graphics/IntPoint.h: Ditto.
* platform/graphics/IntSize.h: Ditto.
* platform/network/ProtectionSpace.h: Ditto.
* platform/network/ProtectionSpaceHash.h: Removed unnecessary DefaultHash declaration.
* platform/mediastream/mac/AVVideoCaptureSource.h:
Added #include "IntSizeHash.h" to instantiate HashMap<String, IntSize>.

Source/WebKit:

* WebProcess/WebPage/WebPage.h: Added #include <WebCore/IntPointHash.h> to instantiate HashMap<std::pair<IntSize, double>, IntPoint>.

Source/WTF:

* wtf/BitVector.h: Removed unnecessary HashTraits declaration.
* wtf/MetaAllocatorPtr.h: Ditto.
* wtf/IndexSparseSet.h: Removed unused #include <wtf/HashTraits.h>.
* wtf/LoggingHashMap.h: Removed unused #include <wtf/LoggingHashTraits.h>.
* wtf/StackShot.h: Added #include <wtf/HashTraits.h> because this header uses SimpleClassHashTraits.
Removed unnecessary HashTraits declaration.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235841 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/BitVector.h
Source/WTF/wtf/IndexSparseSet.h
Source/WTF/wtf/LoggingHashMap.h
Source/WTF/wtf/MetaAllocatorPtr.h
Source/WTF/wtf/StackShot.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/webdatabase/SQLResultSetRowList.h
Source/WebCore/bindings/js/SerializedScriptValue.cpp
Source/WebCore/page/DebugPageOverlays.cpp
Source/WebCore/platform/URL.h
Source/WebCore/platform/URLHash.h
Source/WebCore/platform/graphics/Color.h
Source/WebCore/platform/graphics/FloatSize.h
Source/WebCore/platform/graphics/IntPoint.h
Source/WebCore/platform/graphics/IntSize.h
Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h
Source/WebCore/platform/network/ProtectionSpace.h
Source/WebCore/platform/network/ProtectionSpaceHash.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/WebPage.h