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

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

Issue 1807853003: Deprecate some macros in wtf/Assertions.h in favor of base/logging.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 months 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
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 22 matching lines...) Expand all
33 Note, this file uses many GCC extensions, but it should be compatible with 33 Note, this file uses many GCC extensions, but it should be compatible with
34 C, Objective C, C++, and Objective C++. 34 C, Objective C, C++, and Objective C++.
35 35
36 For non-debug builds, everything is disabled by default, except for the 36 For non-debug builds, everything is disabled by default, except for the
37 RELEASE_ASSERT family of macros. 37 RELEASE_ASSERT family of macros.
38 38
39 Defining any of the symbols explicitly prevents this from having any effect. 39 Defining any of the symbols explicitly prevents this from having any effect.
40 40
41 */ 41 */
42 42
43 #include "base/logging.h"
43 #include "wtf/Compiler.h" 44 #include "wtf/Compiler.h"
44 #include "wtf/Noncopyable.h" 45 #include "wtf/Noncopyable.h"
45 #include "wtf/WTFExport.h" 46 #include "wtf/WTFExport.h"
46 #include "wtf/build_config.h" 47 #include "wtf/build_config.h"
47 #include <stdarg.h> 48 #include <stdarg.h>
48 49
49 // Users must test "#if ENABLE(ASSERT)", which helps ensure that code 50 // Users must test "#if ENABLE(ASSERT)", which helps ensure that code
50 // testing this macro has included this header. 51 // testing this macro has included this header.
51 #ifndef ENABLE_ASSERT 52 #ifndef ENABLE_ASSERT
52 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 53 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 (WTFReportBacktrace(), (*(int*)0xfbadbeef = 0), IMMEDIATE_CRASH()) 130 (WTFReportBacktrace(), (*(int*)0xfbadbeef = 0), IMMEDIATE_CRASH())
130 #endif 131 #endif
131 #endif 132 #endif
132 133
133 #if COMPILER(CLANG) 134 #if COMPILER(CLANG)
134 #define NO_RETURN_DUE_TO_CRASH NO_RETURN 135 #define NO_RETURN_DUE_TO_CRASH NO_RETURN
135 #else 136 #else
136 #define NO_RETURN_DUE_TO_CRASH 137 #define NO_RETURN_DUE_TO_CRASH
137 #endif 138 #endif
138 139
139 /* ASSERT, ASSERT_NOT_REACHED, ASSERT_UNUSED 140 // ASSERT, ASSERT_NOT_REACHED, ASSERT_UNUSED
140 141 // These macros are compiled out of release builds.
141 These macros are compiled out of release builds. 142 // Expressions inside them are evaluated in debug builds only.
142 Expressions inside them are evaluated in debug builds only. 143 // They are deprecated. We should use:
143 */ 144 // - DCHECK() for ASSERT()
145 // - NOTREACHED() for ASSERT_NOT_REACHED()
146 // - DCHECK() and ALLOW_UNUSED_LOCAL() for ASSERT_UNUSED().
144 #if OS(WIN) 147 #if OS(WIN)
145 /* FIXME: Change to use something other than ASSERT to avoid this conflict with the underlying platform */ 148 /* FIXME: Change to use something other than ASSERT to avoid this conflict with the underlying platform */
146 #undef ASSERT 149 #undef ASSERT
147 #endif 150 #endif
148 151
149 #if ENABLE(ASSERT) 152 #if ENABLE(ASSERT)
150 153
151 #define ASSERT(assertion) \ 154 #define ASSERT(assertion) \
152 (!(assertion) ? \ 155 (!(assertion) ? \
153 (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #ass ertion), \ 156 (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #ass ertion), \
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 #endif 208 #endif
206 209
207 // Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure 210 // Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure
208 // that code testing this macro has included this header. 211 // that code testing this macro has included this header.
209 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT) 212 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT)
210 #define ENABLE_SECURITY_ASSERT 1 213 #define ENABLE_SECURITY_ASSERT 1
211 #else 214 #else
212 #define ENABLE_SECURITY_ASSERT 0 215 #define ENABLE_SECURITY_ASSERT 0
213 #endif 216 #endif
214 217
215 /* ASSERT_WITH_MESSAGE */ 218 // ASSERT_WITH_MESSAGE
216 219 // This is deprecated. We should use DCHECK() << "message".
217 #if ASSERT_MSG_DISABLED 220 #if ASSERT_MSG_DISABLED
218 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0) 221 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0)
219 #else 222 #else
220 #define ASSERT_WITH_MESSAGE(assertion, ...) do \ 223 #define ASSERT_WITH_MESSAGE(assertion, ...) do \
221 if (!(assertion)) { \ 224 if (!(assertion)) { \
222 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC TION, #assertion, __VA_ARGS__); \ 225 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC TION, #assertion, __VA_ARGS__); \
223 CRASH(); \ 226 CRASH(); \
224 } \ 227 } \
225 while (0) 228 while (0)
226 #endif 229 #endif
227 230
228 /* ASSERT_WITH_MESSAGE_UNUSED */ 231 // ASSERT_WITH_MESSAGE_UNUSED
229 232 // This is deprecated. We should use DCHECK() << "message" and
233 // ALLOW_UNUSED_LOCAL().
230 #if ASSERT_MSG_DISABLED 234 #if ASSERT_MSG_DISABLED
231 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) ((void)variable) 235 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) ((void)variable)
232 #else 236 #else
233 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) do \ 237 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) do \
234 if (!(assertion)) { \ 238 if (!(assertion)) { \
235 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC TION, #assertion, __VA_ARGS__); \ 239 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC TION, #assertion, __VA_ARGS__); \
236 CRASH(); \ 240 CRASH(); \
237 } \ 241 } \
238 while (0) 242 while (0)
239 #endif 243 #endif
240 244
241 /* ASSERT_ARG */ 245 /* ASSERT_ARG */
242 246
243 #if ASSERT_ARG_DISABLED 247 #if ASSERT_ARG_DISABLED
244 248
245 #define ASSERT_ARG(argName, assertion) ((void)0) 249 #define ASSERT_ARG(argName, assertion) ((void)0)
246 250
247 #else 251 #else
248 252
249 #define ASSERT_ARG(argName, assertion) do \ 253 #define ASSERT_ARG(argName, assertion) do \
250 if (!(assertion)) { \ 254 if (!(assertion)) { \
251 WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTIO N, #argName, #assertion); \ 255 WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTIO N, #argName, #assertion); \
252 CRASH(); \ 256 CRASH(); \
253 } \ 257 } \
254 while (0) 258 while (0)
255 259
256 #endif 260 #endif
257 261
258 /* FATAL */ 262 // FATAL
259 263 // This is deprecated. We should use DLOG(FATAL) << ...
260 #if FATAL_DISABLED 264 #if FATAL_DISABLED
261 #define FATAL(...) ((void)0) 265 #define FATAL(...) ((void)0)
262 #else 266 #else
263 #define FATAL(...) do { \ 267 #define FATAL(...) do { \
264 WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \ 268 WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \
265 CRASH(); \ 269 CRASH(); \
266 } while (0) 270 } while (0)
267 #endif 271 #endif
268 272
269 /* WTF_LOG_ERROR */ 273 // WTF_LOG_ERROR
270 274 // This is deprecated. We should use DLOG(ERROR) << ...
271 #if ERROR_DISABLED 275 #if ERROR_DISABLED
272 #define WTF_LOG_ERROR(...) ((void)0) 276 #define WTF_LOG_ERROR(...) ((void)0)
273 #else 277 #else
274 #define WTF_LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTIO N, __VA_ARGS__) 278 #define WTF_LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTIO N, __VA_ARGS__)
275 #endif 279 #endif
276 280
277 /* WTF_LOG */ 281 // WTF_LOG
278 282 // This is deprecated. Should be replaced with DVLOG(verboselevel), which works
283 // only in debug build, or VLOG(verboselevel), which works in release build too.
279 #if LOG_DISABLED 284 #if LOG_DISABLED
280 #define WTF_LOG(channel, ...) ((void)0) 285 #define WTF_LOG(channel, ...) ((void)0)
281 #else 286 #else
282 #define WTF_LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_P REFIX, channel), __VA_ARGS__) 287 #define WTF_LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_P REFIX, channel), __VA_ARGS__)
283 #define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREF IX_LEVEL_2(prefix, channel) 288 #define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREF IX_LEVEL_2(prefix, channel)
284 #define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel 289 #define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel
285 #endif 290 #endif
286 291
287 /* RELEASE_ASSERT 292 /* RELEASE_ASSERT
288 293
289 Use in places where failure of an assertion indicates a definite security 294 Use in places where failure of an assertion indicates a definite security
290 vulnerability from which execution must not continue even in a release build. 295 vulnerability from which execution must not continue even in a release build.
291 Please sure to file bugs for these failures using the security template: 296 Please sure to file bugs for these failures using the security template:
292 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug 297 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug
293 */ 298 */
294 299 // RELEASE_ASSERT* are deprecated. We should use:
300 // - CHECK() for RELEASE_ASSERT()
301 // - CHECK() << message for RELEASE_ASSERT_WITH_MESSAGE()
302 // - RELEASE_NOTREACHED() for RELEASE_ASSERT_NOT_REACHED().
295 #if ENABLE(ASSERT) 303 #if ENABLE(ASSERT)
296 #define RELEASE_ASSERT(assertion) ASSERT(assertion) 304 #define RELEASE_ASSERT(assertion) ASSERT(assertion)
297 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio n, __VA_ARGS__) 305 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio n, __VA_ARGS__)
298 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED() 306 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED()
299 #else 307 #else
300 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0) 308 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0)
301 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion) 309 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion)
302 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH() 310 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH()
303 #endif 311 #endif
312 // TODO(tkent): Move this to base/logging.h?
313 #define RELEASE_NOTREACHED() LOG(FATAL)
304 314
305 /* DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES */ 315 /* DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES */
306 316
307 // Allow equality comparisons of Objects by reference or pointer, interchangeabl y. 317 // Allow equality comparisons of Objects by reference or pointer, interchangeabl y.
308 // This can be only used on types whose equality makes no other sense than point er equality. 318 // This can be only used on types whose equality makes no other sense than point er equality.
309 #define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \ 319 #define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \
310 inline bool operator==(const thisType& a, const thisType& b) { return &a == &b; } \ 320 inline bool operator==(const thisType& a, const thisType& b) { return &a == &b; } \
311 inline bool operator==(const thisType& a, const thisType* b) { return &a == b; } \ 321 inline bool operator==(const thisType& a, const thisType* b) { return &a == b; } \
312 inline bool operator==(const thisType* a, const thisType& b) { return a == & b; } \ 322 inline bool operator==(const thisType* a, const thisType& b) { return a == & b; } \
313 inline bool operator!=(const thisType& a, const thisType& b) { return !(a == b); } \ 323 inline bool operator!=(const thisType& a, const thisType& b) { return !(a == b); } \
(...skipping 27 matching lines...) Expand all
341 } \ 351 } \
342 inline const thisType& to##thisType(const argumentType& argumentName) \ 352 inline const thisType& to##thisType(const argumentType& argumentName) \
343 { \ 353 { \
344 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ 354 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \
345 return static_cast<const thisType&>(argumentName); \ 355 return static_cast<const thisType&>(argumentName); \
346 } \ 356 } \
347 void to##thisType(const thisType*); \ 357 void to##thisType(const thisType*); \
348 void to##thisType(const thisType&) 358 void to##thisType(const thisType&)
349 359
350 #endif /* WTF_Assertions_h */ 360 #endif /* WTF_Assertions_h */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698