Index: third_party/WebKit/Source/wtf/SizeAssertions.h |
diff --git a/third_party/WebKit/Source/wtf/SizeAssertions.h b/third_party/WebKit/Source/wtf/SizeAssertions.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..176d980fb60b5f691bdac9f83cdf52421c72ea25 |
--- /dev/null |
+++ b/third_party/WebKit/Source/wtf/SizeAssertions.h |
@@ -0,0 +1,34 @@ |
+#ifndef WTF_SizeAssertions_h |
+#define WTF_SizeAssertions_h |
+ |
+#include "wtf/CPU.h" |
+ |
+namespace WTF { |
+ |
+// Expected32BitSize and Expected64BitSize are in bytes. Use a template instead |
+// of a plain static assert so that failure messages give the expected number. |
+template<class T, int Expected32BitSize, int Expected64BitSize> struct assert_size { |
+ template<int ActualSize, int ExpectedSize> class assertSizeEqual { |
+ static_assert(ActualSize == ExpectedSize, |
+ "Object size doesn't match expected value, think before making it bigger :-)"); |
+ }; |
+#if CPU(32BIT) |
+ assertSizeEqual<sizeof(T), Expected32BitSize> tmp; |
+#else |
+ assertSizeEqual<sizeof(T), Expected64BitSize> tmp; |
+#endif |
+ enum { Dummy = 1 }; |
+}; |
+ |
+} // namespace WTF |
+ |
+// Some objects have additional members when asserts are enabled, so only check |
+// sizes when they are disabled. |
+#if ENABLE(ASSERT) |
esprehn
2016/08/11 09:47:40
The bots and CQ always enable asserts, so this mea
|
+#define ASSERT_SIZE(className, expected32BitSize, expected64BitSize) |
+#else |
+#define ASSERT_SIZE(className, expected32BitSize, expected64BitSize) \ |
+ static_assert(WTF::assert_size<className, expected32BitSize, expected64BitSize>::Dummy, ""); |
+#endif |
+ |
+#endif // WTF_SizeAssertions_h |