15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2003, 2006, 2007 Apple Inc.  All rights reserved.
353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved.
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met:
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    documentation and/or other materials provided with the distribution.
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef WTF_Assertions_h
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define WTF_Assertions_h
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)   No namespaces because this file has to be includable from C and Objective-C.
325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)   Note, this file uses many GCC extensions, but it should be compatible with
345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)   C, Objective C, C++, and Objective C++.
355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)   For non-debug builds, everything is disabled by default, except for the
3753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)   RELEASE_ASSERT family of macros.
3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)   Defining any of the symbols explicitly prevents this from having any effect.
4053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)*/
425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
43a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "wtf/Compiler.h"
4493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "wtf/WTFExport.h"
4593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
46197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch// Users must test "#if ENABLE(ASSERT)", which helps ensure that code
47197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch// testing this macro has included this header.
48197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#ifndef ENABLE_ASSERT
497242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
50197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch/* Disable ASSERT* macros in release mode by default. */
51197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define ENABLE_ASSERT 0
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
53197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define ENABLE_ASSERT 1
547242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#endif /* defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) */
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef BACKTRACE_DISABLED
58197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define BACKTRACE_DISABLED !ENABLE(ASSERT)
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef ASSERT_MSG_DISABLED
62197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define ASSERT_MSG_DISABLED !ENABLE(ASSERT)
635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef ASSERT_ARG_DISABLED
66197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define ASSERT_ARG_DISABLED !ENABLE(ASSERT)
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef FATAL_DISABLED
70197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define FATAL_DISABLED !ENABLE(ASSERT)
715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef ERROR_DISABLED
74197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define ERROR_DISABLED !ENABLE(ASSERT)
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef LOG_DISABLED
78197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define LOG_DISABLED !ENABLE(ASSERT)
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* WTF logging functions can process %@ in the format string to log a NSObject* but the printf format attribute
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)   emits a warning when %@ is used in the format string.  Until <rdar://problem/5195437> is resolved we can't include
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)   the attribute when being used from Objective-C code in case it decides to use %@. */
845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if COMPILER(GCC) && !defined(__OBJC__)
855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__((__format__(printf, formatStringArgument, extraArguments)))
865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
8702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments)
885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* These helper functions are always declared, but not necessarily always defined if the corresponding function is disabled. */
915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef enum { WTFLogChannelOff, WTFLogChannelOn } WTFLogChannelState;
935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef struct {
955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WTFLogChannelState state;
965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} WTFLogChannel;
975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion);
9993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
10093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion);
10193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
10293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFReportError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
10393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFLog(WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
10493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
10593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFLogAlways(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFGetBacktrace(void** stack, int* size);
1088abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)WTF_EXPORT void WTFReportBacktrace(int framesToShow = 31);
10993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFPrintBacktrace(void** stack, int size);
1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef void (*WTFCrashHookFunction)();
11293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFSetCrashHook(WTFCrashHookFunction);
11393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFInvokeCrashHook();
11493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)WTF_EXPORT void WTFInstallReportBacktraceOnCrashHook();
1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1165d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)namespace WTF {
1175d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
1185d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)class WTF_EXPORT FrameToNameScope {
1195d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)public:
1205d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    explicit FrameToNameScope(void*);
1215d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    ~FrameToNameScope();
1225d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    const char* nullableName() { return m_name; }
1235d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
1245d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)private:
1255d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    const char* m_name;
1265d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    char* m_cxaDemangled;
1275d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)};
1285d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
1295d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)} // namespace WTF
1305d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
1315d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)using WTF::FrameToNameScope;
1325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)/* IMMEDIATE_CRASH() - Like CRASH() below but crashes in the fastest, simplest possible way with no attempt at logging. */
13453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#ifndef IMMEDIATE_CRASH
13593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if COMPILER(GCC)
13653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#define IMMEDIATE_CRASH() __builtin_trap()
13753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#else
13853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#define IMMEDIATE_CRASH() ((void(*)())0)()
13953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#endif
14053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#endif
14153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
1425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* CRASH() - Raises a fatal error resulting in program termination and triggering either the debugger or the crash reporter.
1435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)   Use CRASH() in response to known, unrecoverable errors like out-of-memory.
1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)   Macro is enabled in both debug and release mode.
1465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)   To test for unknown errors and verify assumptions, use ASSERT instead, to avoid impacting performance in release builds.
1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)   Signals are ignored by the crash reporter on OS X so we must do better.
1495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)*/
1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef CRASH
1515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define CRASH() \
1525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    (WTFReportBacktrace(), \
1535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)     WTFInvokeCrashHook(), \
15409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)     (*(int*)0xfbadbeef = 0), \
15553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)     IMMEDIATE_CRASH())
1565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
1575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if COMPILER(CLANG)
1595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define NO_RETURN_DUE_TO_CRASH NO_RETURN
1605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
1615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define NO_RETURN_DUE_TO_CRASH
1625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* BACKTRACE
1655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  Print a backtrace to the same location as ASSERT messages.
1675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)*/
1685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if BACKTRACE_DISABLED
1695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define BACKTRACE() ((void)0)
1715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
1735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define BACKTRACE() do { \
1755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WTFReportBacktrace(); \
1765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} while(false)
1775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
1795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* ASSERT, ASSERT_NOT_REACHED, ASSERT_UNUSED
1815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  These macros are compiled out of release builds.
1835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  Expressions inside them are evaluated in debug builds only.
1845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)*/
1858abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#if OS(WIN)
1865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* FIXME: Change to use something other than ASSERT to avoid this conflict with the underlying platform */
1875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#undef ASSERT
1885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
1895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
190197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if ENABLE(ASSERT)
1915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ASSERT(assertion) \
1935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    (!(assertion) ? \
1945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion), \
1955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)         CRASH()) : \
1965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        (void)0)
1975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ASSERT_AT(assertion, file, line, function) \
1995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    (!(assertion) ? \
2005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        (WTFReportAssertionFailure(file, line, function, #assertion), \
2015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)         CRASH()) :                                                   \
2025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        (void)0)
2035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ASSERT_NOT_REACHED() do { \
2055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \
2065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    CRASH(); \
2075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} while (0)
2085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ASSERT_UNUSED(variable, assertion) ASSERT(assertion)
2105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define NO_RETURN_DUE_TO_ASSERT NO_RETURN_DUE_TO_CRASH
2125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2135d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#else
2145d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
2155d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#define ASSERT(assertion) ((void)0)
2165d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#define ASSERT_AT(assertion, file, line, function) ((void)0)
2175d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#define ASSERT_NOT_REACHED() ((void)0)
2185d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#define NO_RETURN_DUE_TO_ASSERT
2195d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
2205d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#define ASSERT_UNUSED(variable, assertion) ((void)variable)
2215d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
2225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
2235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
22493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)/* ASSERT_WITH_SECURITY_IMPLICATION / RELEASE_ASSERT_WITH_SECURITY_IMPLICATION
225926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
22653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)   Use in places where failure of the assertion indicates a possible security
22753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)   vulnerability. Classes of these vulnerabilities include bad casts, out of
22853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)   bounds accesses, use-after-frees, etc. Please be sure to file bugs for these
22953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)   failures using the security template:
23053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)      http://code.google.com/p/chromium/issues/entry?template=Security%20Bug
231926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)*/
232926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#ifdef ADDRESS_SANITIZER
233926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
234926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#define ASSERT_WITH_SECURITY_IMPLICATION(assertion) \
235926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    (!(assertion) ? \
236926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion), \
237926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)         CRASH()) : \
238926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        (void)0)
239926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
24093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT_WITH_SECURITY_IMPLICATION(assertion)
24193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
242926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#else
243926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
244926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#define ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT(assertion)
24593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) RELEASE_ASSERT(assertion)
246926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
247926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#endif
248926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
249197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch// Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure
250197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch// that code testing this macro has included this header.
251197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT)
252197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define ENABLE_SECURITY_ASSERT 1
2531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#else
254197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define ENABLE_SECURITY_ASSERT 0
2551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#endif
2561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* ASSERT_WITH_MESSAGE */
2585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
25993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if ASSERT_MSG_DISABLED
2605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0)
2615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
2625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ASSERT_WITH_MESSAGE(assertion, ...) do \
2635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!(assertion)) { \
2645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
2655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        CRASH(); \
2665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } \
2675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)while (0)
2685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
2695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* ASSERT_WITH_MESSAGE_UNUSED */
2715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
27293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if ASSERT_MSG_DISABLED
2735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) ((void)variable)
2745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
2755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) do \
2765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!(assertion)) { \
2775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
2785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        CRASH(); \
2795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } \
2805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)while (0)
2815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
28253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
2835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* ASSERT_ARG */
2845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if ASSERT_ARG_DISABLED
2865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ASSERT_ARG(argName, assertion) ((void)0)
2885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
2905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ASSERT_ARG(argName, assertion) do \
2925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!(assertion)) { \
2935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #argName, #assertion); \
2945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        CRASH(); \
2955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } \
2965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)while (0)
2975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
2995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* COMPILE_ASSERT */
3015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef COMPILE_ASSERT
3025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if COMPILER_SUPPORTS(C_STATIC_ASSERT)
30353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)/* Unlike static_assert below, this also works in plain C code. */
3045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define COMPILE_ASSERT(exp, name) _Static_assert((exp), #name)
30553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#elif COMPILER_SUPPORTS(CXX_STATIC_ASSERT)
30653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#define COMPILE_ASSERT(exp, name) static_assert((exp), #name)
3075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
3085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define COMPILE_ASSERT(exp, name) typedef int dummy##name [(exp) ? 1 : -1]
3095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
3105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
3115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* FATAL */
3135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
31493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if FATAL_DISABLED
3155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define FATAL(...) ((void)0)
3165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
3175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define FATAL(...) do { \
3185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \
3195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    CRASH(); \
3205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} while (0)
3215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
3225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
323a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)/* WTF_LOG_ERROR */
3245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
32593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if ERROR_DISABLED
326a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#define WTF_LOG_ERROR(...) ((void)0)
3275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
328a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#define WTF_LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__)
3295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
3305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
331a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)/* WTF_LOG */
3325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
33393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if LOG_DISABLED
334a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#define WTF_LOG(channel, ...) ((void)0)
3355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
336a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#define WTF_LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
3375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel)
3385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel
3395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
3405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* UNREACHABLE_FOR_PLATFORM */
3425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if COMPILER(CLANG)
34453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)/* This would be a macro except that its use of #pragma works best around
34553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)   a function. Hence it uses macro naming convention. */
3465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#pragma clang diagnostic push
3475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#pragma clang diagnostic ignored "-Wmissing-noreturn"
3485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static inline void UNREACHABLE_FOR_PLATFORM()
3495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
3505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT_NOT_REACHED();
3515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#pragma clang diagnostic pop
3535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else
3545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define UNREACHABLE_FOR_PLATFORM() ASSERT_NOT_REACHED()
3555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
3565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
35753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)/* RELEASE_ASSERT
35853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
35953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)   Use in places where failure of an assertion indicates a definite security
36053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)   vulnerability from which execution must not continue even in a release build.
36153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)   Please sure to file bugs for these failures using the security template:
36253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)      http://code.google.com/p/chromium/issues/entry?template=Security%20Bug
36353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)*/
36453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
365197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if ENABLE(ASSERT)
366926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#define RELEASE_ASSERT(assertion) ASSERT(assertion)
367926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertion, __VA_ARGS__)
368926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED()
3695d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#else
3705d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0)
3715d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion)
3725d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH()
373926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#endif
374926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
375f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)/* DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES */
376f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
377f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)// Allow equality comparisons of Objects by reference or pointer, interchangeably.
378197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch// This can be only used on types whose equality makes no other sense than pointer equality.
379f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \
380f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    inline bool operator==(const thisType& a, const thisType& b) { return &a == &b; } \
381f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    inline bool operator==(const thisType& a, const thisType* b) { return &a == b; } \
382f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    inline bool operator==(const thisType* a, const thisType& b) { return a == &b; } \
383f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    inline bool operator!=(const thisType& a, const thisType& b) { return !(a == b); } \
384f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    inline bool operator!=(const thisType& a, const thisType* b) { return !(a == b); } \
385f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    inline bool operator!=(const thisType* a, const thisType& b) { return !(a == b); }
386f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
387f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES_REFCOUNTED(thisType) \
388f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \
389f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    inline bool operator==(const PassRefPtr<thisType>& a, const thisType& b) { return a.get() == &b; } \
390f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    inline bool operator==(const thisType& a, const PassRefPtr<thisType>& b) { return &a == b.get(); } \
391f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    inline bool operator!=(const PassRefPtr<thisType>& a, const thisType& b) { return !(a == b); } \
392f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    inline bool operator!=(const thisType& a, const PassRefPtr<thisType>& b) { return !(a == b); }
393f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
394bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)/* DEFINE_TYPE_CASTS */
395bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
396bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#define DEFINE_TYPE_CASTS(thisType, argumentType, argumentName, pointerPredicate, referencePredicate) \
397bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)inline thisType* to##thisType(argumentType* argumentName) \
398bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){ \
399bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate)); \
400bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    return static_cast<thisType*>(argumentName); \
401bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)} \
402bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)inline const thisType* to##thisType(const argumentType* argumentName) \
403bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){ \
404bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate)); \
405bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    return static_cast<const thisType*>(argumentName); \
406bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)} \
407bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)inline thisType& to##thisType(argumentType& argumentName) \
408bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){ \
409bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \
410bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    return static_cast<thisType&>(argumentName); \
411bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)} \
412bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)inline const thisType& to##thisType(const argumentType& argumentName) \
413bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){ \
414bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \
415bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    return static_cast<const thisType&>(argumentName); \
416bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)} \
417bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)void to##thisType(const thisType*); \
418bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)void to##thisType(const thisType&)
419bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
4205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif /* WTF_Assertions_h */
421