Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1151)

Unified Diff: third_party/WebKit/Source/wtf/Assertions.h

Issue 2534873004: Avoid unchecked casts in UA shadow DOM. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGUseElement.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/Assertions.h
diff --git a/third_party/WebKit/Source/wtf/Assertions.h b/third_party/WebKit/Source/wtf/Assertions.h
index 28af93a08d25f87328a1a5c4eaa00b164651dfd6..4036571ed3032374465ef8e6ed929ae0edb35e62 100644
--- a/third_party/WebKit/Source/wtf/Assertions.h
+++ b/third_party/WebKit/Source/wtf/Assertions.h
@@ -270,26 +270,52 @@ class WTF_EXPORT ScopedLogger {
}
// DEFINE_TYPE_CASTS
-// Provide static_cast<> wrappers with SECURITY_DCHECK for bad casts.
-#define DEFINE_TYPE_CASTS(thisType, argumentType, argumentName, \
- pointerPredicate, referencePredicate) \
- inline thisType* to##thisType(argumentType* argumentName) { \
- SECURITY_DCHECK(!argumentName || (pointerPredicate)); \
- return static_cast<thisType*>(argumentName); \
- } \
- inline const thisType* to##thisType(const argumentType* argumentName) { \
- SECURITY_DCHECK(!argumentName || (pointerPredicate)); \
- return static_cast<const thisType*>(argumentName); \
- } \
- inline thisType& to##thisType(argumentType& argumentName) { \
- SECURITY_DCHECK(referencePredicate); \
- return static_cast<thisType&>(argumentName); \
- } \
- inline const thisType& to##thisType(const argumentType& argumentName) { \
- SECURITY_DCHECK(referencePredicate); \
- return static_cast<const thisType&>(argumentName); \
- } \
- void to##thisType(const thisType*); \
- void to##thisType(const thisType&)
+//
+// toType() functions are static_cast<> wrappers with SECURITY_DCHECK. It's
+// helpful to find bad casts.
+//
+// toTypeOrDie() has a runtime type check, and it crashes if the specified
+// object is not an instance of the destination type. It is used if
+// * it's hard to prevent from passing unexpected objects,
+// * proceeding with the following code doesn't make sense, and
+// * cost of runtime type check is acceptable.
+#define DEFINE_TYPE_CASTS(thisType, argumentType, argument, pointerPredicate, \
+ referencePredicate) \
+ inline thisType* to##thisType(argumentType* argument) { \
+ SECURITY_DCHECK(!argument || (pointerPredicate)); \
+ return static_cast<thisType*>(argument); \
+ } \
+ inline const thisType* to##thisType(const argumentType* argument) { \
+ SECURITY_DCHECK(!argument || (pointerPredicate)); \
+ return static_cast<const thisType*>(argument); \
+ } \
+ inline thisType& to##thisType(argumentType& argument) { \
+ SECURITY_DCHECK(referencePredicate); \
+ return static_cast<thisType&>(argument); \
+ } \
+ inline const thisType& to##thisType(const argumentType& argument) { \
+ SECURITY_DCHECK(referencePredicate); \
+ return static_cast<const thisType&>(argument); \
+ } \
+ void to##thisType(const thisType*); \
+ void to##thisType(const thisType&); \
+ inline thisType* to##thisType##OrDie(argumentType* argument) { \
+ CHECK(!argument || (pointerPredicate)); \
+ return static_cast<thisType*>(argument); \
+ } \
+ inline const thisType* to##thisType##OrDie(const argumentType* argument) { \
+ CHECK(!argument || (pointerPredicate)); \
+ return static_cast<const thisType*>(argument); \
+ } \
+ inline thisType& to##thisType##OrDie(argumentType& argument) { \
+ CHECK(referencePredicate); \
+ return static_cast<thisType&>(argument); \
+ } \
+ inline const thisType& to##thisType##OrDie(const argumentType& argument) { \
+ CHECK(referencePredicate); \
+ return static_cast<const thisType&>(argument); \
+ } \
+ void to##thisType##OrDie(const thisType*); \
+ void to##thisType##OrDie(const thisType&)
#endif // WTF_Assertions_h
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGUseElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698