| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 emits a warning when %@ is used in the format string. Until <rdar://problem/
5195437> is resolved we can't include | 85 emits a warning when %@ is used in the format string. Until <rdar://problem/
5195437> is resolved we can't include |
| 86 the attribute when being used from Objective-C code in case it decides to use
%@. */ | 86 the attribute when being used from Objective-C code in case it decides to use
%@. */ |
| 87 #if COMPILER(GCC) && !defined(__OBJC__) | 87 #if COMPILER(GCC) && !defined(__OBJC__) |
| 88 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__
((__format__(printf, formatStringArgument, extraArguments))) | 88 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__
((__format__(printf, formatStringArgument, extraArguments))) |
| 89 #else | 89 #else |
| 90 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) | 90 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) |
| 91 #endif | 91 #endif |
| 92 | 92 |
| 93 /* These helper functions are always declared, but not necessarily always define
d if the corresponding function is disabled. */ | 93 /* These helper functions are always declared, but not necessarily always define
d if the corresponding function is disabled. */ |
| 94 | 94 |
| 95 typedef enum { WTFLogChannelOff, WTFLogChannelOn } WTFLogChannelState; | 95 typedef enum { WTFLogChannelOff, |
| 96 WTFLogChannelOn } WTFLogChannelState; |
| 96 | 97 |
| 97 typedef struct { | 98 typedef struct { |
| 98 WTFLogChannelState state; | 99 WTFLogChannelState state; |
| 99 } WTFLogChannel; | 100 } WTFLogChannel; |
| 100 | 101 |
| 101 WTF_EXPORT void WTFReportAssertionFailure(const char* file, int line, const char
* function, const char* assertion); | 102 WTF_EXPORT void WTFReportAssertionFailure(const char* file, int line, const char
* function, const char* assertion); |
| 102 WTF_EXPORT void WTFReportAssertionFailureWithMessage(const char* file, int line,
const char* function, const char* assertion, const char* format, ...) WTF_ATTRI
BUTE_PRINTF(5, 6); | 103 WTF_EXPORT void WTFReportAssertionFailureWithMessage(const char* file, int line,
const char* function, const char* assertion, const char* format, ...) WTF_ATTRI
BUTE_PRINTF(5, 6); |
| 103 WTF_EXPORT void WTFReportArgumentAssertionFailure(const char* file, int line, co
nst char* function, const char* argName, const char* assertion); | 104 WTF_EXPORT void WTFReportArgumentAssertionFailure(const char* file, int line, co
nst char* function, const char* argName, const char* assertion); |
| 104 WTF_EXPORT void WTFReportFatalError(const char* file, int line, const char* func
tion, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5); | 105 WTF_EXPORT void WTFReportFatalError(const char* file, int line, const char* func
tion, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5); |
| 105 WTF_EXPORT void WTFReportError(const char* file, int line, const char* function,
const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5); | 106 WTF_EXPORT void WTFReportError(const char* file, int line, const char* function,
const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5); |
| 106 WTF_EXPORT void WTFLog(WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PR
INTF(2, 3); | 107 WTF_EXPORT void WTFLog(WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PR
INTF(2, 3); |
| 107 WTF_EXPORT void WTFLogVerbose(const char* file, int line, const char* function,
WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6); | 108 WTF_EXPORT void WTFLogVerbose(const char* file, int line, const char* function,
WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6); |
| 108 WTF_EXPORT void WTFLogAlways(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2)
; | 109 WTF_EXPORT void WTFLogAlways(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2)
; |
| 109 | 110 |
| 110 WTF_EXPORT void WTFGetBacktrace(void** stack, int* size); | 111 WTF_EXPORT void WTFGetBacktrace(void** stack, int* size); |
| 111 WTF_EXPORT void WTFReportBacktrace(int framesToShow = 31); | 112 WTF_EXPORT void WTFReportBacktrace(int framesToShow = 31); |
| 112 WTF_EXPORT void WTFPrintBacktrace(void** stack, int size); | 113 WTF_EXPORT void WTFPrintBacktrace(void** stack, int size); |
| 113 | 114 |
| 114 namespace WTF { | 115 namespace WTF { |
| 115 | 116 |
| 116 class WTF_EXPORT FrameToNameScope { | 117 class WTF_EXPORT FrameToNameScope { |
| 117 public: | 118 public: |
| 118 explicit FrameToNameScope(void*); | 119 explicit FrameToNameScope(void*); |
| 119 ~FrameToNameScope(); | 120 ~FrameToNameScope(); |
| 120 const char* nullableName() { return m_name; } | 121 const char* nullableName() { return m_name; } |
| 121 | 122 |
| 122 private: | 123 private: |
| 123 const char* m_name; | 124 const char* m_name; |
| 124 char* m_cxaDemangled; | 125 char* m_cxaDemangled; |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 // ScopedLogger wraps log messages in parentheses, with indentation proportional | 128 // ScopedLogger wraps log messages in parentheses, with indentation proportional |
| 128 // to the number of instances. This makes it easy to see the flow of control in | 129 // to the number of instances. This makes it easy to see the flow of control in |
| 129 // the output, particularly when instrumenting recursive functions. | 130 // the output, particularly when instrumenting recursive functions. |
| 130 class WTF_EXPORT ScopedLogger { | 131 class WTF_EXPORT ScopedLogger { |
| 131 WTF_MAKE_NONCOPYABLE(ScopedLogger); | 132 WTF_MAKE_NONCOPYABLE(ScopedLogger); |
| 132 public: | |
| 133 // The first message is passed to the constructor. Additional messages for | |
| 134 // the same scope can be added with log(). If condition is false, produce no | |
| 135 // output and do not create a scope. | |
| 136 ScopedLogger(bool condition, const char* format, ...) WTF_ATTRIBUTE_PRINTF(3
, 4); | |
| 137 ~ScopedLogger(); | |
| 138 void log(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3); | |
| 139 | 133 |
| 140 private: | 134 public: |
| 141 friend class AssertionsTest; | 135 // The first message is passed to the constructor. Additional messages for |
| 142 using PrintFunctionPtr = void (*)(const char* format, va_list args); | 136 // the same scope can be added with log(). If condition is false, produce no |
| 143 static void setPrintFuncForTests(PrintFunctionPtr p) { m_printFunc = p; } //
Note: not thread safe. | 137 // output and do not create a scope. |
| 138 ScopedLogger(bool condition, const char* format, ...) WTF_ATTRIBUTE_PRINTF(3,
4); |
| 139 ~ScopedLogger(); |
| 140 void log(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3); |
| 144 | 141 |
| 145 void init(const char* format, va_list args); | 142 private: |
| 146 void writeNewlineIfNeeded(); | 143 friend class AssertionsTest; |
| 147 void indent(); | 144 using PrintFunctionPtr = void (*)(const char* format, va_list args); |
| 148 void print(const char* format, ...); | 145 static void setPrintFuncForTests(PrintFunctionPtr p) { m_printFunc = p; } //
Note: not thread safe. |
| 149 static ScopedLogger*& current(); | |
| 150 | 146 |
| 151 ScopedLogger* const m_parent; | 147 void init(const char* format, va_list args); |
| 152 bool m_multiline; // The ')' will go on the same line if there is only one e
ntry. | 148 void writeNewlineIfNeeded(); |
| 153 static PrintFunctionPtr m_printFunc; | 149 void indent(); |
| 150 void print(const char* format, ...); |
| 151 static ScopedLogger*& current(); |
| 152 |
| 153 ScopedLogger* const m_parent; |
| 154 bool m_multiline; // The ')' will go on the same line if there is only one en
try. |
| 155 static PrintFunctionPtr m_printFunc; |
| 154 }; | 156 }; |
| 155 | 157 |
| 156 #if LOG_DISABLED | 158 #if LOG_DISABLED |
| 157 #define WTF_CREATE_SCOPED_LOGGER(...) ((void) 0) | 159 #define WTF_CREATE_SCOPED_LOGGER(...) ((void)0) |
| 158 #define WTF_CREATE_SCOPED_LOGGER_IF(...) ((void) 0) | 160 #define WTF_CREATE_SCOPED_LOGGER_IF(...) ((void)0) |
| 159 #define WTF_APPEND_SCOPED_LOGGER(...) ((void) 0) | 161 #define WTF_APPEND_SCOPED_LOGGER(...) ((void)0) |
| 160 #else | 162 #else |
| 161 #define WTF_CREATE_SCOPED_LOGGER(name, ...) ScopedLogger name(true, __VA_ARGS__) | 163 #define WTF_CREATE_SCOPED_LOGGER(name, ...) ScopedLogger name(true, __VA_ARGS__) |
| 162 #define WTF_CREATE_SCOPED_LOGGER_IF(name, condition, ...) ScopedLogger name(cond
ition, __VA_ARGS__) | 164 #define WTF_CREATE_SCOPED_LOGGER_IF(name, condition, ...) ScopedLogger name(cond
ition, __VA_ARGS__) |
| 163 #define WTF_APPEND_SCOPED_LOGGER(name, ...) (name.log(__VA_ARGS__)) | 165 #define WTF_APPEND_SCOPED_LOGGER(name, ...) (name.log(__VA_ARGS__)) |
| 164 #endif | 166 #endif |
| 165 | 167 |
| 166 } // namespace WTF | 168 } // namespace WTF |
| 167 | 169 |
| 168 using WTF::FrameToNameScope; | 170 using WTF::FrameToNameScope; |
| 169 using WTF::ScopedLogger; | 171 using WTF::ScopedLogger; |
| 170 | 172 |
| 171 /* IMMEDIATE_CRASH() - Like CRASH() below but crashes in the fastest, simplest p
ossible way with no attempt at logging. */ | 173 /* IMMEDIATE_CRASH() - Like CRASH() below but crashes in the fastest, simplest p
ossible way with no attempt at logging. */ |
| 172 #ifndef IMMEDIATE_CRASH | 174 #ifndef IMMEDIATE_CRASH |
| 173 #if COMPILER(GCC) || COMPILER(CLANG) | 175 #if COMPILER(GCC) || COMPILER(CLANG) |
| 174 #define IMMEDIATE_CRASH() __builtin_trap() | 176 #define IMMEDIATE_CRASH() __builtin_trap() |
| 175 #else | 177 #else |
| 176 #define IMMEDIATE_CRASH() ((void)(*(volatile char*)0 = 0)) | 178 #define IMMEDIATE_CRASH() ((void)(*(volatile char*)0 = 0)) |
| 177 #endif | 179 #endif |
| 178 #endif | 180 #endif |
| 179 | 181 |
| 180 /* CRASH() - Raises a fatal error resulting in program termination and triggerin
g either the debugger or the crash reporter. | 182 /* CRASH() - Raises a fatal error resulting in program termination and triggerin
g either the debugger or the crash reporter. |
| 181 | 183 |
| 182 Use CRASH() in response to known, unrecoverable errors like out-of-memory. | 184 Use CRASH() in response to known, unrecoverable errors like out-of-memory. |
| 183 Macro is enabled in both debug and release mode. | 185 Macro is enabled in both debug and release mode. |
| 184 To test for unknown errors and verify assumptions, use ASSERT instead, to avo
id impacting performance in release builds. | 186 To test for unknown errors and verify assumptions, use ASSERT instead, to avo
id impacting performance in release builds. |
| 185 | 187 |
| 186 Signals are ignored by the crash reporter on OS X so we must do better. | 188 Signals are ignored by the crash reporter on OS X so we must do better. |
| 187 */ | 189 */ |
| 188 #ifndef CRASH | 190 #ifndef CRASH |
| 189 #if COMPILER(MSVC) | 191 #if COMPILER(MSVC) |
| 190 #define CRASH() (__debugbreak(), IMMEDIATE_CRASH()) | 192 #define CRASH() (__debugbreak(), IMMEDIATE_CRASH()) |
| 191 #else | 193 #else |
| 192 #define CRASH() \ | 194 #define CRASH() \ |
| 193 (WTFReportBacktrace(), (*(int*)0xfbadbeef = 0), IMMEDIATE_CRASH()) | 195 (WTFReportBacktrace(), (*(int*)0xfbadbeef = 0), IMMEDIATE_CRASH()) |
| 194 #endif | 196 #endif |
| 195 #endif | 197 #endif |
| 196 | 198 |
| 197 #if COMPILER(CLANG) | 199 #if COMPILER(CLANG) |
| 198 #define NO_RETURN_DUE_TO_CRASH NO_RETURN | 200 #define NO_RETURN_DUE_TO_CRASH NO_RETURN |
| 199 #else | 201 #else |
| 200 #define NO_RETURN_DUE_TO_CRASH | 202 #define NO_RETURN_DUE_TO_CRASH |
| 201 #endif | 203 #endif |
| 202 | 204 |
| 203 /* BACKTRACE | 205 /* BACKTRACE |
| 204 | 206 |
| 205 Print a backtrace to the same location as ASSERT messages. | 207 Print a backtrace to the same location as ASSERT messages. |
| 206 */ | 208 */ |
| 207 #if BACKTRACE_DISABLED | 209 #if BACKTRACE_DISABLED |
| 208 | 210 |
| 209 #define BACKTRACE() ((void)0) | 211 #define BACKTRACE() ((void)0) |
| 210 | 212 |
| 211 #else | 213 #else |
| 212 | 214 |
| 213 #define BACKTRACE() do { \ | 215 #define BACKTRACE() \ |
| 216 do { \ |
| 214 WTFReportBacktrace(); \ | 217 WTFReportBacktrace(); \ |
| 215 } while (false) | 218 } while (false) |
| 216 | 219 |
| 217 #endif | 220 #endif |
| 218 | 221 |
| 219 /* ASSERT, ASSERT_NOT_REACHED, ASSERT_UNUSED | 222 /* ASSERT, ASSERT_NOT_REACHED, ASSERT_UNUSED |
| 220 | 223 |
| 221 These macros are compiled out of release builds. | 224 These macros are compiled out of release builds. |
| 222 Expressions inside them are evaluated in debug builds only. | 225 Expressions inside them are evaluated in debug builds only. |
| 223 */ | 226 */ |
| 224 #if OS(WIN) | 227 #if OS(WIN) |
| 225 /* FIXME: Change to use something other than ASSERT to avoid this conflict with
the underlying platform */ | 228 /* FIXME: Change to use something other than ASSERT to avoid this conflict with
the underlying platform */ |
| 226 #undef ASSERT | 229 #undef ASSERT |
| 227 #endif | 230 #endif |
| 228 | 231 |
| 229 #if ENABLE(ASSERT) | 232 #if ENABLE(ASSERT) |
| 230 | 233 |
| 231 #define ASSERT(assertion) \ | 234 #define ASSERT(assertion)
\ |
| 232 (!(assertion) ? \ | 235 (!(assertion) ? (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNC
TION, #assertion), \ |
| 233 (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #ass
ertion), \ | 236 CRASH())
\ |
| 234 CRASH()) : \ | 237 : (void)0) |
| 235 (void)0) | |
| 236 | 238 |
| 237 #define ASSERT_AT(assertion, file, line, function) \ | 239 #define ASSERT_AT(assertion, file, line, function) \ |
| 238 (!(assertion) ? \ | 240 (!(assertion) ? (WTFReportAssertionFailure(file, line, function, #assertion),
CRASH()) : (void)0) |
| 239 (WTFReportAssertionFailure(file, line, function, #assertion), CRASH()) :
\ | |
| 240 (void)0) | |
| 241 | 241 |
| 242 #define ASSERT_NOT_REACHED() do { \ | 242 #define ASSERT_NOT_REACHED() \ |
| 243 do { \ |
| 243 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \ | 244 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \ |
| 244 CRASH(); \ | 245 CRASH(); \ |
| 245 } while (0) | 246 } while (0) |
| 246 | 247 |
| 247 #define ASSERT_UNUSED(variable, assertion) ASSERT(assertion) | 248 #define ASSERT_UNUSED(variable, assertion) ASSERT(assertion) |
| 248 | 249 |
| 249 #define NO_RETURN_DUE_TO_ASSERT NO_RETURN_DUE_TO_CRASH | 250 #define NO_RETURN_DUE_TO_ASSERT NO_RETURN_DUE_TO_CRASH |
| 250 | 251 |
| 251 #else | 252 #else |
| 252 | 253 |
| 253 #define ASSERT(assertion) ((void)0) | 254 #define ASSERT(assertion) ((void)0) |
| 254 #define ASSERT_AT(assertion, file, line, function) ((void)0) | 255 #define ASSERT_AT(assertion, file, line, function) ((void)0) |
| 255 #define ASSERT_NOT_REACHED() ((void)0) | 256 #define ASSERT_NOT_REACHED() ((void)0) |
| 256 #define NO_RETURN_DUE_TO_ASSERT | 257 #define NO_RETURN_DUE_TO_ASSERT |
| 257 | 258 |
| 258 #define ASSERT_UNUSED(variable, assertion) ((void)variable) | 259 #define ASSERT_UNUSED(variable, assertion) ((void)variable) |
| 259 | 260 |
| 260 #endif | 261 #endif |
| 261 | 262 |
| 262 /* ASSERT_WITH_SECURITY_IMPLICATION / RELEASE_ASSERT_WITH_SECURITY_IMPLICATION | 263 /* ASSERT_WITH_SECURITY_IMPLICATION / RELEASE_ASSERT_WITH_SECURITY_IMPLICATION |
| 263 | 264 |
| 264 Use in places where failure of the assertion indicates a possible security | 265 Use in places where failure of the assertion indicates a possible security |
| 265 vulnerability. Classes of these vulnerabilities include bad casts, out of | 266 vulnerability. Classes of these vulnerabilities include bad casts, out of |
| 266 bounds accesses, use-after-frees, etc. Please be sure to file bugs for these | 267 bounds accesses, use-after-frees, etc. Please be sure to file bugs for these |
| 267 failures using the security template: | 268 failures using the security template: |
| 268 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug | 269 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug |
| 269 */ | 270 */ |
| 270 #ifdef ADDRESS_SANITIZER | 271 #ifdef ADDRESS_SANITIZER |
| 271 | 272 |
| 272 #define ASSERT_WITH_SECURITY_IMPLICATION(assertion) \ | 273 #define ASSERT_WITH_SECURITY_IMPLICATION(assertion)
\ |
| 273 (!(assertion) ? \ | 274 (!(assertion) ? (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNC
TION, #assertion), \ |
| 274 (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #ass
ertion), \ | 275 CRASH())
\ |
| 275 CRASH()) : \ | 276 : (void)0) |
| 276 (void)0) | |
| 277 | 277 |
| 278 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT_WITH_SECURITY
_IMPLICATION(assertion) | 278 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT_WITH_SECURITY
_IMPLICATION(assertion) |
| 279 | 279 |
| 280 #else | 280 #else |
| 281 | 281 |
| 282 #define ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT(assertion) | 282 #define ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT(assertion) |
| 283 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) RELEASE_ASSERT(asser
tion) | 283 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) RELEASE_ASSERT(asser
tion) |
| 284 | 284 |
| 285 #endif | 285 #endif |
| 286 | 286 |
| 287 // Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure | 287 // Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure |
| 288 // that code testing this macro has included this header. | 288 // that code testing this macro has included this header. |
| 289 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT) | 289 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT) |
| 290 #define ENABLE_SECURITY_ASSERT 1 | 290 #define ENABLE_SECURITY_ASSERT 1 |
| 291 #else | 291 #else |
| 292 #define ENABLE_SECURITY_ASSERT 0 | 292 #define ENABLE_SECURITY_ASSERT 0 |
| 293 #endif | 293 #endif |
| 294 | 294 |
| 295 /* ASSERT_WITH_MESSAGE */ | 295 /* ASSERT_WITH_MESSAGE */ |
| 296 | 296 |
| 297 #if ASSERT_MSG_DISABLED | 297 #if ASSERT_MSG_DISABLED |
| 298 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0) | 298 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0) |
| 299 #else | 299 #else |
| 300 #define ASSERT_WITH_MESSAGE(assertion, ...) do \ | 300 #define ASSERT_WITH_MESSAGE(assertion, ...)
\ |
| 301 if (!(assertion)) { \ | 301 do
\ |
| 302 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC
TION, #assertion, __VA_ARGS__); \ | 302 if (!(assertion)) {
\ |
| 303 CRASH(); \ | 303 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTI
ON, #assertion, __VA_ARGS__); \ |
| 304 } \ | 304 CRASH();
\ |
| 305 while (0) | 305 }
\ |
| 306 while (0) |
| 306 #endif | 307 #endif |
| 307 | 308 |
| 308 /* ASSERT_WITH_MESSAGE_UNUSED */ | 309 /* ASSERT_WITH_MESSAGE_UNUSED */ |
| 309 | 310 |
| 310 #if ASSERT_MSG_DISABLED | 311 #if ASSERT_MSG_DISABLED |
| 311 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) ((void)variable) | 312 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) ((void)variable) |
| 312 #else | 313 #else |
| 313 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) do \ | 314 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...)
\ |
| 314 if (!(assertion)) { \ | 315 do
\ |
| 315 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC
TION, #assertion, __VA_ARGS__); \ | 316 if (!(assertion)) {
\ |
| 316 CRASH(); \ | 317 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTI
ON, #assertion, __VA_ARGS__); \ |
| 317 } \ | 318 CRASH();
\ |
| 318 while (0) | 319 }
\ |
| 320 while (0) |
| 319 #endif | 321 #endif |
| 320 | 322 |
| 321 /* ASSERT_ARG */ | 323 /* ASSERT_ARG */ |
| 322 | 324 |
| 323 #if ASSERT_ARG_DISABLED | 325 #if ASSERT_ARG_DISABLED |
| 324 | 326 |
| 325 #define ASSERT_ARG(argName, assertion) ((void)0) | 327 #define ASSERT_ARG(argName, assertion) ((void)0) |
| 326 | 328 |
| 327 #else | 329 #else |
| 328 | 330 |
| 329 #define ASSERT_ARG(argName, assertion) do \ | 331 #define ASSERT_ARG(argName, assertion)
\ |
| 330 if (!(assertion)) { \ | 332 do
\ |
| 331 WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTIO
N, #argName, #assertion); \ | 333 if (!(assertion)) {
\ |
| 332 CRASH(); \ | 334 WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION,
#argName, #assertion); \ |
| 333 } \ | 335 CRASH();
\ |
| 334 while (0) | 336 }
\ |
| 337 while (0) |
| 335 | 338 |
| 336 #endif | 339 #endif |
| 337 | 340 |
| 338 /* FATAL */ | 341 /* FATAL */ |
| 339 | 342 |
| 340 #if FATAL_DISABLED | 343 #if FATAL_DISABLED |
| 341 #define FATAL(...) ((void)0) | 344 #define FATAL(...) ((void)0) |
| 342 #else | 345 #else |
| 343 #define FATAL(...) do { \ | 346 #define FATAL(...) \ |
| 347 do { \ |
| 344 WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \ | 348 WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \ |
| 345 CRASH(); \ | 349 CRASH(); \ |
| 346 } while (0) | 350 } while (0) |
| 347 #endif | 351 #endif |
| 348 | 352 |
| 349 /* WTF_LOG_ERROR */ | 353 /* WTF_LOG_ERROR */ |
| 350 | 354 |
| 351 #if ERROR_DISABLED | 355 #if ERROR_DISABLED |
| 352 #define WTF_LOG_ERROR(...) ((void)0) | 356 #define WTF_LOG_ERROR(...) ((void)0) |
| 353 #else | 357 #else |
| 354 #define WTF_LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTIO
N, __VA_ARGS__) | 358 #define WTF_LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTIO
N, __VA_ARGS__) |
| 355 #endif | 359 #endif |
| 356 | 360 |
| 357 /* WTF_LOG */ | 361 /* WTF_LOG */ |
| 358 | 362 |
| 359 #if LOG_DISABLED | 363 #if LOG_DISABLED |
| 360 #define WTF_LOG(channel, ...) ((void)0) | 364 #define WTF_LOG(channel, ...) ((void)0) |
| 361 #else | 365 #else |
| 362 #define WTF_LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_P
REFIX, channel), __VA_ARGS__) | 366 #define WTF_LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_P
REFIX, channel), __VA_ARGS__) |
| 363 #define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREF
IX_LEVEL_2(prefix, channel) | 367 #define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREF
IX_LEVEL_2(prefix, channel) |
| 364 #define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel | 368 #define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix##channel |
| 365 #endif | 369 #endif |
| 366 | 370 |
| 367 /* UNREACHABLE_FOR_PLATFORM */ | 371 /* UNREACHABLE_FOR_PLATFORM */ |
| 368 | 372 |
| 369 #if COMPILER(CLANG) | 373 #if COMPILER(CLANG) |
| 370 /* This would be a macro except that its use of #pragma works best around | 374 /* This would be a macro except that its use of #pragma works best around |
| 371 a function. Hence it uses macro naming convention. */ | 375 a function. Hence it uses macro naming convention. */ |
| 372 #pragma clang diagnostic push | 376 #pragma clang diagnostic push |
| 373 #pragma clang diagnostic ignored "-Wmissing-noreturn" | 377 #pragma clang diagnostic ignored "-Wmissing-noreturn" |
| 374 static inline void UNREACHABLE_FOR_PLATFORM() | 378 static inline void UNREACHABLE_FOR_PLATFORM() { |
| 375 { | 379 ASSERT_NOT_REACHED(); |
| 376 ASSERT_NOT_REACHED(); | |
| 377 } | 380 } |
| 378 #pragma clang diagnostic pop | 381 #pragma clang diagnostic pop |
| 379 #else | 382 #else |
| 380 #define UNREACHABLE_FOR_PLATFORM() ASSERT_NOT_REACHED() | 383 #define UNREACHABLE_FOR_PLATFORM() ASSERT_NOT_REACHED() |
| 381 #endif | 384 #endif |
| 382 | 385 |
| 383 /* RELEASE_ASSERT | 386 /* RELEASE_ASSERT |
| 384 | 387 |
| 385 Use in places where failure of an assertion indicates a definite security | 388 Use in places where failure of an assertion indicates a definite security |
| 386 vulnerability from which execution must not continue even in a release build. | 389 vulnerability from which execution must not continue even in a release build. |
| 387 Please sure to file bugs for these failures using the security template: | 390 Please sure to file bugs for these failures using the security template: |
| 388 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug | 391 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug |
| 389 */ | 392 */ |
| 390 | 393 |
| 391 #if ENABLE(ASSERT) | 394 #if ENABLE(ASSERT) |
| 392 #define RELEASE_ASSERT(assertion) ASSERT(assertion) | 395 #define RELEASE_ASSERT(assertion) ASSERT(assertion) |
| 393 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio
n, __VA_ARGS__) | 396 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio
n, __VA_ARGS__) |
| 394 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED() | 397 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED() |
| 395 #else | 398 #else |
| 396 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH())
: (void)0) | 399 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH())
: (void)0) |
| 397 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion) | 400 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion) |
| 398 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH() | 401 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH() |
| 399 #endif | 402 #endif |
| 400 | 403 |
| 401 /* DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES */ | 404 /* DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES */ |
| 402 | 405 |
| 403 // Allow equality comparisons of Objects by reference or pointer, interchangeabl
y. | 406 // Allow equality comparisons of Objects by reference or pointer, interchangeabl
y. |
| 404 // This can be only used on types whose equality makes no other sense than point
er equality. | 407 // This can be only used on types whose equality makes no other sense than point
er equality. |
| 405 #define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \ | 408 #define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType)
\ |
| 406 inline bool operator==(const thisType& a, const thisType& b) { return &a ==
&b; } \ | 409 inline bool operator==(const thisType& a, const thisType& b) { return &a == &b
; } \ |
| 407 inline bool operator==(const thisType& a, const thisType* b) { return &a ==
b; } \ | 410 inline bool operator==(const thisType& a, const thisType* b) { return &a == b;
} \ |
| 408 inline bool operator==(const thisType* a, const thisType& b) { return a == &
b; } \ | 411 inline bool operator==(const thisType* a, const thisType& b) { return a == &b;
} \ |
| 409 inline bool operator!=(const thisType& a, const thisType& b) { return !(a ==
b); } \ | 412 inline bool operator!=(const thisType& a, const thisType& b) { return !(a == b
); } \ |
| 410 inline bool operator!=(const thisType& a, const thisType* b) { return !(a ==
b); } \ | 413 inline bool operator!=(const thisType& a, const thisType* b) { return !(a == b
); } \ |
| 411 inline bool operator!=(const thisType* a, const thisType& b) { return !(a ==
b); } | 414 inline bool operator!=(const thisType* a, const thisType& b) { return !(a == b
); } |
| 412 | 415 |
| 413 #define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES_REFCOUNTED(thisType) \ | 416 #define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES_REFCOUNTED(thisType)
\ |
| 414 DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \ | 417 DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType)
\ |
| 415 inline bool operator==(const PassRefPtr<thisType>& a, const thisType& b) { r
eturn a.get() == &b; } \ | 418 inline bool operator==(const PassRefPtr<thisType>& a, const thisType& b) { ret
urn a.get() == &b; } \ |
| 416 inline bool operator==(const thisType& a, const PassRefPtr<thisType>& b) { r
eturn &a == b.get(); } \ | 419 inline bool operator==(const thisType& a, const PassRefPtr<thisType>& b) { ret
urn &a == b.get(); } \ |
| 417 inline bool operator!=(const PassRefPtr<thisType>& a, const thisType& b) { r
eturn !(a == b); } \ | 420 inline bool operator!=(const PassRefPtr<thisType>& a, const thisType& b) { ret
urn !(a == b); } \ |
| 418 inline bool operator!=(const thisType& a, const PassRefPtr<thisType>& b) { r
eturn !(a == b); } | 421 inline bool operator!=(const thisType& a, const PassRefPtr<thisType>& b) { ret
urn !(a == b); } |
| 419 | 422 |
| 420 /* DEFINE_TYPE_CASTS */ | 423 /* DEFINE_TYPE_CASTS */ |
| 421 | 424 |
| 422 #define DEFINE_TYPE_CASTS(thisType, argumentType, argumentName, pointerPredicate
, referencePredicate) \ | 425 #define DEFINE_TYPE_CASTS(thisType, argumentType, argumentName, pointerPredicate
, referencePredicate) \ |
| 423 inline thisType* to##thisType(argumentType* argumentName) \ | 426 inline thisType* to##thisType(argumentType* argumentName) {
\ |
| 424 { \ | 427 ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate));
\ |
| 425 ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate)); \ | 428 return static_cast<thisType*>(argumentName);
\ |
| 426 return static_cast<thisType*>(argumentName); \ | 429 }
\ |
| 427 } \ | 430 inline const thisType* to##thisType(const argumentType* argumentName) {
\ |
| 428 inline const thisType* to##thisType(const argumentType* argumentName) \ | 431 ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate));
\ |
| 429 { \ | 432 return static_cast<const thisType*>(argumentName);
\ |
| 430 ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate)); \ | 433 }
\ |
| 431 return static_cast<const thisType*>(argumentName); \ | 434 inline thisType& to##thisType(argumentType& argumentName) {
\ |
| 432 } \ | 435 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate);
\ |
| 433 inline thisType& to##thisType(argumentType& argumentName) \ | 436 return static_cast<thisType&>(argumentName);
\ |
| 434 { \ | 437 }
\ |
| 435 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ | 438 inline const thisType& to##thisType(const argumentType& argumentName) {
\ |
| 436 return static_cast<thisType&>(argumentName); \ | 439 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate);
\ |
| 437 } \ | 440 return static_cast<const thisType&>(argumentName);
\ |
| 438 inline const thisType& to##thisType(const argumentType& argumentName) \ | 441 }
\ |
| 439 { \ | 442 void to##thisType(const thisType*);
\ |
| 440 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ | 443 void to##thisType(const thisType&) |
| 441 return static_cast<const thisType&>(argumentName); \ | |
| 442 } \ | |
| 443 void to##thisType(const thisType*); \ | |
| 444 void to##thisType(const thisType&) | |
| 445 | 444 |
| 446 #endif /* WTF_Assertions_h */ | 445 #endif /* WTF_Assertions_h */ |
| OLD | NEW |