Title: [235841] trunk/Source
Revision
235841
Author
[email protected]
Date
2018-09-09 22:20:52 -0700 (Sun, 09 Sep 2018)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (235840 => 235841)


--- trunk/Source/WTF/ChangeLog	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WTF/ChangeLog	2018-09-10 05:20:52 UTC (rev 235841)
@@ -1,3 +1,17 @@
+2018-09-09  Fujii Hironori  <[email protected]>
+
+        Add specialized template declarations of HashTraits and DefaultHash to detect misuse
+        https://bugs.webkit.org/show_bug.cgi?id=189044
+
+        Reviewed by Yusuke Suzuki.
+
+        * 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.
+
 2018-09-07  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r235784.

Modified: trunk/Source/WTF/wtf/BitVector.h (235840 => 235841)


--- trunk/Source/WTF/wtf/BitVector.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WTF/wtf/BitVector.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -482,7 +482,6 @@
     typedef BitVectorHash Hash;
 };
 
-template<typename T> struct HashTraits;
 template<> struct HashTraits<BitVector> : public CustomHashTraits<BitVector> { };
 
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/IndexSparseSet.h (235840 => 235841)


--- trunk/Source/WTF/wtf/IndexSparseSet.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WTF/wtf/IndexSparseSet.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -26,7 +26,6 @@
 #ifndef IndexSparseSet_h
 #define IndexSparseSet_h
 
-#include <wtf/HashTraits.h>
 #include <wtf/Vector.h>
 
 namespace WTF {

Modified: trunk/Source/WTF/wtf/LoggingHashMap.h (235840 => 235841)


--- trunk/Source/WTF/wtf/LoggingHashMap.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WTF/wtf/LoggingHashMap.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -28,7 +28,6 @@
 #include <wtf/DataLog.h>
 #include <wtf/HashMap.h>
 #include <wtf/LoggingHashID.h>
-#include <wtf/LoggingHashTraits.h>
 
 namespace WTF {
 

Modified: trunk/Source/WTF/wtf/MetaAllocatorPtr.h (235840 => 235841)


--- trunk/Source/WTF/wtf/MetaAllocatorPtr.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WTF/wtf/MetaAllocatorPtr.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -114,7 +114,6 @@
     typedef MetaAllocatorPtrHash<tag> Hash;
 };
 
-template<typename T> struct HashTraits;
 template<PtrTag tag> struct HashTraits<MetaAllocatorPtr<tag>> : public CustomHashTraits<MetaAllocatorPtr<tag>> { };
 
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/StackShot.h (235840 => 235841)


--- trunk/Source/WTF/wtf/StackShot.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WTF/wtf/StackShot.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include <wtf/Assertions.h>
+#include <wtf/HashTraits.h>
 #include <wtf/UniqueArray.h>
 
 namespace WTF {
@@ -123,7 +124,6 @@
     typedef StackShotHash Hash;
 };
 
-template<typename T> struct HashTraits;
 template<> struct HashTraits<StackShot> : SimpleClassHashTraits<StackShot> { };
 
 } // namespace WTF

Modified: trunk/Source/WebCore/ChangeLog (235840 => 235841)


--- trunk/Source/WebCore/ChangeLog	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/ChangeLog	2018-09-10 05:20:52 UTC (rev 235841)
@@ -1,5 +1,43 @@
 2018-09-09  Fujii Hironori  <[email protected]>
 
+        Add specialized template declarations of HashTraits and DefaultHash to detect misuse
+        https://bugs.webkit.org/show_bug.cgi?id=189044
+
+        Reviewed by Yusuke Suzuki.
+
+        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>.
+
+2018-09-09  Fujii Hironori  <[email protected]>
+
         [Win][Clang] Add FloatRect(const RECT&) constructor
         https://bugs.webkit.org/show_bug.cgi?id=189398
 

Modified: trunk/Source/WebCore/Modules/webdatabase/SQLResultSetRowList.h (235840 => 235841)


--- trunk/Source/WebCore/Modules/webdatabase/SQLResultSetRowList.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLResultSetRowList.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -30,7 +30,6 @@
 
 #include "ExceptionOr.h"
 #include "SQLValue.h"
-#include <wtf/HashTraits.h>
 
 namespace WebCore {
 

Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp (235840 => 235841)


--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp	2018-09-10 05:20:52 UTC (rev 235841)
@@ -81,7 +81,6 @@
 #include <_javascript_Core/TypedArrays.h>
 #include <_javascript_Core/WasmModule.h>
 #include <limits>
-#include <wtf/HashTraits.h>
 #include <wtf/MainThread.h>
 #include <wtf/RunLoop.h>
 #include <wtf/Vector.h>

Modified: trunk/Source/WebCore/page/DebugPageOverlays.cpp (235840 => 235841)


--- trunk/Source/WebCore/page/DebugPageOverlays.cpp	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/page/DebugPageOverlays.cpp	2018-09-10 05:20:52 UTC (rev 235841)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "DebugPageOverlays.h"
 
+#include "ColorHash.h"
 #include "ElementIterator.h"
 #include "FrameView.h"
 #include "GraphicsContext.h"

Modified: trunk/Source/WebCore/platform/URL.h (235840 => 235841)


--- trunk/Source/WebCore/platform/URL.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/platform/URL.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -424,11 +424,6 @@
 } // namespace WebCore
 
 namespace WTF {
-
-// URLHash is the default hash for String
-template<typename T> struct DefaultHash;
-template<> struct DefaultHash<WebCore::URL> {
-    typedef WebCore::URLHash Hash;
-};
-
+template<> struct DefaultHash<WebCore::URL>;
+template<> struct HashTraits<WebCore::URL>;
 } // namespace WTF

Modified: trunk/Source/WebCore/platform/URLHash.h (235840 => 235841)


--- trunk/Source/WebCore/platform/URLHash.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/platform/URLHash.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -50,8 +50,13 @@
 
 namespace WTF {
 
-    template<> struct HashTraits<WebCore::URL> : SimpleClassHashTraits<WebCore::URL> { };
+// URLHash is the default hash for String
+template<> struct DefaultHash<WebCore::URL> {
+    using Hash = WebCore::URLHash;
+};
 
+template<> struct HashTraits<WebCore::URL> : SimpleClassHashTraits<WebCore::URL> { };
+
 } // namespace WTF
 
 #endif // URLHash_h

Modified: trunk/Source/WebCore/platform/graphics/Color.h (235840 => 235841)


--- trunk/Source/WebCore/platform/graphics/Color.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/platform/graphics/Color.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -470,3 +470,8 @@
 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, ColorSpace);
 
 } // namespace WebCore
+
+namespace WTF {
+template<> struct DefaultHash<WebCore::Color>;
+template<> struct HashTraits<WebCore::Color>;
+}

Modified: trunk/Source/WebCore/platform/graphics/FloatSize.h (235840 => 235841)


--- trunk/Source/WebCore/platform/graphics/FloatSize.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/platform/graphics/FloatSize.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -256,3 +256,7 @@
 
 } // namespace WebCore
 
+namespace WTF {
+template<> struct DefaultHash<WebCore::FloatSize>;
+template<> struct HashTraits<WebCore::FloatSize>;
+}

Modified: trunk/Source/WebCore/platform/graphics/IntPoint.h (235840 => 235841)


--- trunk/Source/WebCore/platform/graphics/IntPoint.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/platform/graphics/IntPoint.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -215,3 +215,7 @@
 
 } // namespace WebCore
 
+namespace WTF {
+template<> struct DefaultHash<WebCore::IntPoint>;
+template<> struct HashTraits<WebCore::IntPoint>;
+}

Modified: trunk/Source/WebCore/platform/graphics/IntSize.h (235840 => 235841)


--- trunk/Source/WebCore/platform/graphics/IntSize.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/platform/graphics/IntSize.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include <algorithm>
+#include <wtf/Forward.h>
 
 #if PLATFORM(MAC) && defined __OBJC__
 #import <Foundation/NSGeometry.h>
@@ -219,3 +220,7 @@
 
 } // namespace WebCore
 
+namespace WTF {
+template<> struct DefaultHash<WebCore::IntSize>;
+template<> struct HashTraits<WebCore::IntSize>;
+}

Modified: trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h (235840 => 235841)


--- trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -27,6 +27,7 @@
 
 #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
 
+#include "IntSizeHash.h"
 #include "OrientationNotifier.h"
 #include "RealtimeMediaSource.h"
 #include <wtf/text/StringHash.h>

Modified: trunk/Source/WebCore/platform/network/ProtectionSpace.h (235840 => 235841)


--- trunk/Source/WebCore/platform/network/ProtectionSpace.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/platform/network/ProtectionSpace.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -48,4 +48,9 @@
 
 } // namespace WebCore
 
+namespace WTF {
+template<> struct DefaultHash<WebCore::ProtectionSpace>;
+template<> struct HashTraits<WebCore::ProtectionSpace>;
+}
+
 #endif

Modified: trunk/Source/WebCore/platform/network/ProtectionSpaceHash.h (235840 => 235841)


--- trunk/Source/WebCore/platform/network/ProtectionSpaceHash.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebCore/platform/network/ProtectionSpaceHash.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -59,9 +59,8 @@
 
     template<> struct HashTraits<WebCore::ProtectionSpace> : SimpleClassHashTraits<WebCore::ProtectionSpace> { };
 
-    template<typename T> struct DefaultHash;
     template<> struct DefaultHash<WebCore::ProtectionSpace> {
-        typedef WebCore::ProtectionSpaceHash Hash;
+        using Hash = WebCore::ProtectionSpaceHash;
     };
 
 } // namespace WTF

Modified: trunk/Source/WebKit/ChangeLog (235840 => 235841)


--- trunk/Source/WebKit/ChangeLog	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebKit/ChangeLog	2018-09-10 05:20:52 UTC (rev 235841)
@@ -1,5 +1,14 @@
 2018-09-09  Fujii Hironori  <[email protected]>
 
+        Add specialized template declarations of HashTraits and DefaultHash to detect misuse
+        https://bugs.webkit.org/show_bug.cgi?id=189044
+
+        Reviewed by Yusuke Suzuki.
+
+        * WebProcess/WebPage/WebPage.h: Added #include <WebCore/IntPointHash.h> to instantiate HashMap<std::pair<IntSize, double>, IntPoint>.
+
+2018-09-09  Fujii Hironori  <[email protected]>
+
         [MSVC] X86Assembler.h(108): error C2666: 'WebCore::operator -': 7 overloads have similar conversions
         https://bugs.webkit.org/show_bug.cgi?id=189467
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (235840 => 235841)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-09-10 05:12:44 UTC (rev 235840)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-09-10 05:20:52 UTC (rev 235841)
@@ -92,6 +92,7 @@
 #if PLATFORM(IOS)
 #include "GestureTypes.h"
 #include "WebPageMessages.h"
+#include <WebCore/IntPointHash.h>
 #include <WebCore/ViewportConfiguration.h>
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to