1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/assembler/wtf/Assertions.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,145 @@ 1.4 +/* 1.5 + * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. 1.6 + * Copyright (C) 2007-2009 Torch Mobile, Inc. 1.7 + * 1.8 + * Redistribution and use in source and binary forms, with or without 1.9 + * modification, are permitted provided that the following conditions 1.10 + * are met: 1.11 + * 1. Redistributions of source code must retain the above copyright 1.12 + * notice, this list of conditions and the following disclaimer. 1.13 + * 2. Redistributions in binary form must reproduce the above copyright 1.14 + * notice, this list of conditions and the following disclaimer in the 1.15 + * documentation and/or other materials provided with the distribution. 1.16 + * 1.17 + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 1.18 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.20 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 1.21 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.22 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.23 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.24 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 1.25 + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.26 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.28 + */ 1.29 + 1.30 +#include "assembler/wtf/Assertions.h" 1.31 + 1.32 +#include <stdio.h> 1.33 +#include <stdarg.h> 1.34 +#include <string.h> 1.35 + 1.36 +#if WTF_COMPILER_MSVC 1.37 +#ifndef WINVER 1.38 +#define WINVER 0x0500 1.39 +#endif 1.40 +#ifndef _WIN32_WINNT 1.41 +#define _WIN32_WINNT 0x0500 1.42 +#endif 1.43 +#include "jswin.h" 1.44 +#include <crtdbg.h> 1.45 +#endif 1.46 + 1.47 +extern "C" { 1.48 + 1.49 +WTF_ATTRIBUTE_PRINTF(1, 0) 1.50 +static void vprintf_stderr_common(const char* format, va_list args) 1.51 +{ 1.52 + vfprintf(stderr, format, args); 1.53 +} 1.54 + 1.55 +WTF_ATTRIBUTE_PRINTF(1, 2) 1.56 +static void printf_stderr_common(const char* format, ...) 1.57 +{ 1.58 + va_list args; 1.59 + va_start(args, format); 1.60 + vprintf_stderr_common(format, args); 1.61 + va_end(args); 1.62 +} 1.63 + 1.64 +static void printCallSite(const char* file, int line, const char* function) 1.65 +{ 1.66 +#if WTF_COMPILER_MSVC && defined _DEBUG 1.67 + _CrtDbgReport(_CRT_WARN, file, line, NULL, "%s\n", function); 1.68 +#else 1.69 + printf_stderr_common("(%s:%d %s)\n", file, line, function); 1.70 +#endif 1.71 +} 1.72 + 1.73 +void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion) 1.74 +{ 1.75 + if (assertion) 1.76 + printf_stderr_common("Assertion failure: %s\n", assertion); 1.77 + else 1.78 + printf_stderr_common("Should never be reached\n"); 1.79 + printCallSite(file, line, function); 1.80 +} 1.81 + 1.82 +void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...) 1.83 +{ 1.84 + printf_stderr_common("Assertion failure: "); 1.85 + va_list args; 1.86 + va_start(args, format); 1.87 + vprintf_stderr_common(format, args); 1.88 + va_end(args); 1.89 + printf_stderr_common("\n%s\n", assertion); 1.90 + printCallSite(file, line, function); 1.91 +} 1.92 + 1.93 +void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion) 1.94 +{ 1.95 + printf_stderr_common("Argument bad: %s, %s\n", argName, assertion); 1.96 + printCallSite(file, line, function); 1.97 +} 1.98 + 1.99 +void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) 1.100 +{ 1.101 + printf_stderr_common("Fatal error: "); 1.102 + va_list args; 1.103 + va_start(args, format); 1.104 + vprintf_stderr_common(format, args); 1.105 + va_end(args); 1.106 + printf_stderr_common("\n"); 1.107 + printCallSite(file, line, function); 1.108 +} 1.109 + 1.110 +void WTFReportError(const char* file, int line, const char* function, const char* format, ...) 1.111 +{ 1.112 + printf_stderr_common("Error: "); 1.113 + va_list args; 1.114 + va_start(args, format); 1.115 + vprintf_stderr_common(format, args); 1.116 + va_end(args); 1.117 + printf_stderr_common("\n"); 1.118 + printCallSite(file, line, function); 1.119 +} 1.120 + 1.121 +void WTFLog(WTFLogChannel* channel, const char* format, ...) 1.122 +{ 1.123 + if (channel->state != WTFLogChannelOn) 1.124 + return; 1.125 + 1.126 + va_list args; 1.127 + va_start(args, format); 1.128 + vprintf_stderr_common(format, args); 1.129 + va_end(args); 1.130 + if (format[strlen(format) - 1] != '\n') 1.131 + printf_stderr_common("\n"); 1.132 +} 1.133 + 1.134 +void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel* channel, const char* format, ...) 1.135 +{ 1.136 + if (channel->state != WTFLogChannelOn) 1.137 + return; 1.138 + 1.139 + va_list args; 1.140 + va_start(args, format); 1.141 + vprintf_stderr_common(format, args); 1.142 + va_end(args); 1.143 + if (format[strlen(format) - 1] != '\n') 1.144 + printf_stderr_common("\n"); 1.145 + printCallSite(file, line, function); 1.146 +} 1.147 + 1.148 +} // extern "C"