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

Side by Side Diff: third_party/WebKit/Source/wtf/Assertions.h

Issue 2534873004: Avoid unchecked casts in UA shadow DOM. (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGUseElement.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 return !(a == b); \ 263 return !(a == b); \
264 } \ 264 } \
265 inline bool operator!=(const thisType& a, const thisType* b) { \ 265 inline bool operator!=(const thisType& a, const thisType* b) { \
266 return !(a == b); \ 266 return !(a == b); \
267 } \ 267 } \
268 inline bool operator!=(const thisType* a, const thisType& b) { \ 268 inline bool operator!=(const thisType* a, const thisType& b) { \
269 return !(a == b); \ 269 return !(a == b); \
270 } 270 }
271 271
272 // DEFINE_TYPE_CASTS 272 // DEFINE_TYPE_CASTS
273 // Provide static_cast<> wrappers with SECURITY_DCHECK for bad casts. 273 //
274 #define DEFINE_TYPE_CASTS(thisType, argumentType, argumentName, \ 274 // toType() functions are static_cast<> wrappers with SECURITY_DCHECK. It's
275 pointerPredicate, referencePredicate) \ 275 // helpful to find bad casts.
276 inline thisType* to##thisType(argumentType* argumentName) { \ 276 //
277 SECURITY_DCHECK(!argumentName || (pointerPredicate)); \ 277 // toTypeOrDie() has a runtime type check, and it crashes if the specified
278 return static_cast<thisType*>(argumentName); \ 278 // object is not an instance of the destination type. It is used if
279 } \ 279 // * it's hard to prevent from passing unexpected objects,
280 inline const thisType* to##thisType(const argumentType* argumentName) { \ 280 // * proceeding with the following code doesn't make sense, and
281 SECURITY_DCHECK(!argumentName || (pointerPredicate)); \ 281 // * cost of runtime type check is acceptable.
282 return static_cast<const thisType*>(argumentName); \ 282 #define DEFINE_TYPE_CASTS(thisType, argumentType, argument, pointerPredicate, \
283 } \ 283 referencePredicate) \
284 inline thisType& to##thisType(argumentType& argumentName) { \ 284 inline thisType* to##thisType(argumentType* argument) { \
285 SECURITY_DCHECK(referencePredicate); \ 285 SECURITY_DCHECK(!argument || (pointerPredicate)); \
286 return static_cast<thisType&>(argumentName); \ 286 return static_cast<thisType*>(argument); \
287 } \ 287 } \
288 inline const thisType& to##thisType(const argumentType& argumentName) { \ 288 inline const thisType* to##thisType(const argumentType* argument) { \
289 SECURITY_DCHECK(referencePredicate); \ 289 SECURITY_DCHECK(!argument || (pointerPredicate)); \
290 return static_cast<const thisType&>(argumentName); \ 290 return static_cast<const thisType*>(argument); \
291 } \ 291 } \
292 void to##thisType(const thisType*); \ 292 inline thisType& to##thisType(argumentType& argument) { \
293 void to##thisType(const thisType&) 293 SECURITY_DCHECK(referencePredicate); \
294 return static_cast<thisType&>(argument); \
295 } \
296 inline const thisType& to##thisType(const argumentType& argument) { \
297 SECURITY_DCHECK(referencePredicate); \
298 return static_cast<const thisType&>(argument); \
299 } \
300 void to##thisType(const thisType*); \
301 void to##thisType(const thisType&); \
302 inline thisType* to##thisType##OrDie(argumentType* argument) { \
303 CHECK(!argument || (pointerPredicate)); \
304 return static_cast<thisType*>(argument); \
305 } \
306 inline const thisType* to##thisType##OrDie(const argumentType* argument) { \
307 CHECK(!argument || (pointerPredicate)); \
308 return static_cast<const thisType*>(argument); \
309 } \
310 inline thisType& to##thisType##OrDie(argumentType& argument) { \
311 CHECK(referencePredicate); \
312 return static_cast<thisType&>(argument); \
313 } \
314 inline const thisType& to##thisType##OrDie(const argumentType& argument) { \
315 CHECK(referencePredicate); \
316 return static_cast<const thisType&>(argument); \
317 } \
318 void to##thisType##OrDie(const thisType*); \
319 void to##thisType##OrDie(const thisType&)
294 320
295 #endif // WTF_Assertions_h 321 #endif // WTF_Assertions_h
OLDNEW
« 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