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

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

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

Powered by Google App Engine
This is Rietveld 408576698