OLD | NEW |
---|---|
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 Loading... | |
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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 #define BACKTRACE() ((void)0) | 207 #define BACKTRACE() ((void)0) |
207 | 208 |
208 #else | 209 #else |
209 | 210 |
210 #define BACKTRACE() do { \ | 211 #define BACKTRACE() do { \ |
211 WTFReportBacktrace(); \ | 212 WTFReportBacktrace(); \ |
212 } while (false) | 213 } while (false) |
213 | 214 |
214 #endif | 215 #endif |
215 | 216 |
216 /* ASSERT, ASSERT_NOT_REACHED, ASSERT_UNUSED | 217 // ASSERT, ASSERT_NOT_REACHED, ASSERT_UNUSED |
217 | 218 // These macros are compiled out of release builds. |
218 These macros are compiled out of release builds. | 219 // Expressions inside them are evaluated in debug builds only. |
219 Expressions inside them are evaluated in debug builds only. | 220 // They are deprecated. We should use: |
220 */ | 221 // - DCHECK() for ASSERT() |
222 // - NOTREACHED() for ASSERT_NOT_REACHED() | |
223 // - DCHECK() and ALLOW_UNUSED_LOCAL() for ASSERT_UNUSED(). | |
221 #if OS(WIN) | 224 #if OS(WIN) |
222 /* FIXME: Change to use something other than ASSERT to avoid this conflict with the underlying platform */ | 225 /* FIXME: Change to use something other than ASSERT to avoid this conflict with the underlying platform */ |
223 #undef ASSERT | 226 #undef ASSERT |
224 #endif | 227 #endif |
225 | 228 |
226 #if ENABLE(ASSERT) | 229 #if ENABLE(ASSERT) |
227 | 230 |
228 #define ASSERT(assertion) \ | 231 #define ASSERT(assertion) \ |
229 (!(assertion) ? \ | 232 (!(assertion) ? \ |
230 (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #ass ertion), \ | 233 (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #ass ertion), \ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 #endif | 285 #endif |
283 | 286 |
284 // Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure | 287 // Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure |
285 // that code testing this macro has included this header. | 288 // that code testing this macro has included this header. |
286 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT) | 289 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT) |
287 #define ENABLE_SECURITY_ASSERT 1 | 290 #define ENABLE_SECURITY_ASSERT 1 |
288 #else | 291 #else |
289 #define ENABLE_SECURITY_ASSERT 0 | 292 #define ENABLE_SECURITY_ASSERT 0 |
290 #endif | 293 #endif |
291 | 294 |
292 /* ASSERT_WITH_MESSAGE */ | 295 // ASSERT_WITH_MESSAGE |
293 | 296 // This is deprecated. We should use DCHECK() << "message". |
294 #if ASSERT_MSG_DISABLED | 297 #if ASSERT_MSG_DISABLED |
295 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0) | 298 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0) |
296 #else | 299 #else |
297 #define ASSERT_WITH_MESSAGE(assertion, ...) do \ | 300 #define ASSERT_WITH_MESSAGE(assertion, ...) do \ |
298 if (!(assertion)) { \ | 301 if (!(assertion)) { \ |
299 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC TION, #assertion, __VA_ARGS__); \ | 302 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC TION, #assertion, __VA_ARGS__); \ |
300 CRASH(); \ | 303 CRASH(); \ |
301 } \ | 304 } \ |
302 while (0) | 305 while (0) |
303 #endif | 306 #endif |
304 | 307 |
305 /* ASSERT_WITH_MESSAGE_UNUSED */ | 308 // ASSERT_WITH_MESSAGE_UNUSED |
306 | 309 // This is deprecated. We should use DCHECK() << "message" and |
310 // ALLOW_UNUSED_LOCAL(). | |
esprehn
2016/03/18 04:58:30
Why do you need to use ALLOW_UNUSED_LOCAL ?
tkent
2016/03/18 05:19:20
to avoid "unused variable" warning in release buil
| |
307 #if ASSERT_MSG_DISABLED | 311 #if ASSERT_MSG_DISABLED |
308 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) ((void)variable) | 312 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) ((void)variable) |
309 #else | 313 #else |
310 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) do \ | 314 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) do \ |
311 if (!(assertion)) { \ | 315 if (!(assertion)) { \ |
312 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC TION, #assertion, __VA_ARGS__); \ | 316 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC TION, #assertion, __VA_ARGS__); \ |
313 CRASH(); \ | 317 CRASH(); \ |
314 } \ | 318 } \ |
315 while (0) | 319 while (0) |
316 #endif | 320 #endif |
317 | 321 |
318 /* ASSERT_ARG */ | 322 /* ASSERT_ARG */ |
319 | 323 |
320 #if ASSERT_ARG_DISABLED | 324 #if ASSERT_ARG_DISABLED |
321 | 325 |
322 #define ASSERT_ARG(argName, assertion) ((void)0) | 326 #define ASSERT_ARG(argName, assertion) ((void)0) |
323 | 327 |
324 #else | 328 #else |
325 | 329 |
326 #define ASSERT_ARG(argName, assertion) do \ | 330 #define ASSERT_ARG(argName, assertion) do \ |
327 if (!(assertion)) { \ | 331 if (!(assertion)) { \ |
328 WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTIO N, #argName, #assertion); \ | 332 WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTIO N, #argName, #assertion); \ |
329 CRASH(); \ | 333 CRASH(); \ |
330 } \ | 334 } \ |
331 while (0) | 335 while (0) |
332 | 336 |
333 #endif | 337 #endif |
334 | 338 |
335 /* FATAL */ | 339 // FATAL |
336 | 340 // This is deprecated. We should use DLOG(FATAL) << ... |
337 #if FATAL_DISABLED | 341 #if FATAL_DISABLED |
338 #define FATAL(...) ((void)0) | 342 #define FATAL(...) ((void)0) |
339 #else | 343 #else |
340 #define FATAL(...) do { \ | 344 #define FATAL(...) do { \ |
341 WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \ | 345 WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \ |
342 CRASH(); \ | 346 CRASH(); \ |
343 } while (0) | 347 } while (0) |
344 #endif | 348 #endif |
345 | 349 |
346 /* WTF_LOG_ERROR */ | 350 // WTF_LOG_ERROR |
347 | 351 // This is deprecated. We should use DLOG(ERROR) << ... |
348 #if ERROR_DISABLED | 352 #if ERROR_DISABLED |
349 #define WTF_LOG_ERROR(...) ((void)0) | 353 #define WTF_LOG_ERROR(...) ((void)0) |
350 #else | 354 #else |
351 #define WTF_LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTIO N, __VA_ARGS__) | 355 #define WTF_LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTIO N, __VA_ARGS__) |
352 #endif | 356 #endif |
353 | 357 |
354 /* WTF_LOG */ | 358 // WTF_LOG |
355 | 359 // This is deprecated. Should be replaced with DVLOG(verboselevel), which works |
360 // only in debug build, or VLOG(verboselevel), which works in release build too. | |
356 #if LOG_DISABLED | 361 #if LOG_DISABLED |
357 #define WTF_LOG(channel, ...) ((void)0) | 362 #define WTF_LOG(channel, ...) ((void)0) |
358 #else | 363 #else |
359 #define WTF_LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_P REFIX, channel), __VA_ARGS__) | 364 #define WTF_LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_P REFIX, channel), __VA_ARGS__) |
360 #define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREF IX_LEVEL_2(prefix, channel) | 365 #define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREF IX_LEVEL_2(prefix, channel) |
361 #define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel | 366 #define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel |
362 #endif | 367 #endif |
363 | 368 |
364 /* UNREACHABLE_FOR_PLATFORM */ | 369 /* UNREACHABLE_FOR_PLATFORM */ |
365 | 370 |
(...skipping 11 matching lines...) Expand all Loading... | |
377 #define UNREACHABLE_FOR_PLATFORM() ASSERT_NOT_REACHED() | 382 #define UNREACHABLE_FOR_PLATFORM() ASSERT_NOT_REACHED() |
378 #endif | 383 #endif |
379 | 384 |
380 /* RELEASE_ASSERT | 385 /* RELEASE_ASSERT |
381 | 386 |
382 Use in places where failure of an assertion indicates a definite security | 387 Use in places where failure of an assertion indicates a definite security |
383 vulnerability from which execution must not continue even in a release build. | 388 vulnerability from which execution must not continue even in a release build. |
384 Please sure to file bugs for these failures using the security template: | 389 Please sure to file bugs for these failures using the security template: |
385 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug | 390 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug |
386 */ | 391 */ |
387 | 392 // RELEASE_ASSERT* are deprecated. We should use: |
393 // - CHECK() for RELEASE_ASSERT() | |
394 // - CHECK() << message for RELEASE_ASSERT_WITH_MESSAGE() | |
395 // - LOG(FATAL) for RELEASE_ASSERT_NOT_REACHED(). | |
esprehn
2016/03/18 04:58:31
LOG(FATAL) is less clear, we should add a release
tkent
2016/03/18 05:19:20
ok, I added RELEASE_NOTREACHED() here.
| |
388 #if ENABLE(ASSERT) | 396 #if ENABLE(ASSERT) |
389 #define RELEASE_ASSERT(assertion) ASSERT(assertion) | 397 #define RELEASE_ASSERT(assertion) ASSERT(assertion) |
390 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio n, __VA_ARGS__) | 398 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio n, __VA_ARGS__) |
391 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED() | 399 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED() |
392 #else | 400 #else |
393 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0) | 401 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0) |
394 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion) | 402 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion) |
395 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH() | 403 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH() |
396 #endif | 404 #endif |
397 | 405 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 } \ | 442 } \ |
435 inline const thisType& to##thisType(const argumentType& argumentName) \ | 443 inline const thisType& to##thisType(const argumentType& argumentName) \ |
436 { \ | 444 { \ |
437 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ | 445 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ |
438 return static_cast<const thisType&>(argumentName); \ | 446 return static_cast<const thisType&>(argumentName); \ |
439 } \ | 447 } \ |
440 void to##thisType(const thisType*); \ | 448 void to##thisType(const thisType*); \ |
441 void to##thisType(const thisType&) | 449 void to##thisType(const thisType&) |
442 | 450 |
443 #endif /* WTF_Assertions_h */ | 451 #endif /* WTF_Assertions_h */ |
OLD | NEW |