js/src/assembler/wtf/Assertions.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
michael@0 3 * Copyright (C) 2007-2009 Torch Mobile, Inc.
michael@0 4 *
michael@0 5 * Redistribution and use in source and binary forms, with or without
michael@0 6 * modification, are permitted provided that the following conditions
michael@0 7 * are met:
michael@0 8 * 1. Redistributions of source code must retain the above copyright
michael@0 9 * notice, this list of conditions and the following disclaimer.
michael@0 10 * 2. Redistributions in binary form must reproduce the above copyright
michael@0 11 * notice, this list of conditions and the following disclaimer in the
michael@0 12 * documentation and/or other materials provided with the distribution.
michael@0 13 *
michael@0 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
michael@0 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
michael@0 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
michael@0 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
michael@0 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 25 */
michael@0 26
michael@0 27 #include "assembler/wtf/Assertions.h"
michael@0 28
michael@0 29 #include <stdio.h>
michael@0 30 #include <stdarg.h>
michael@0 31 #include <string.h>
michael@0 32
michael@0 33 #if WTF_COMPILER_MSVC
michael@0 34 #ifndef WINVER
michael@0 35 #define WINVER 0x0500
michael@0 36 #endif
michael@0 37 #ifndef _WIN32_WINNT
michael@0 38 #define _WIN32_WINNT 0x0500
michael@0 39 #endif
michael@0 40 #include "jswin.h"
michael@0 41 #include <crtdbg.h>
michael@0 42 #endif
michael@0 43
michael@0 44 extern "C" {
michael@0 45
michael@0 46 WTF_ATTRIBUTE_PRINTF(1, 0)
michael@0 47 static void vprintf_stderr_common(const char* format, va_list args)
michael@0 48 {
michael@0 49 vfprintf(stderr, format, args);
michael@0 50 }
michael@0 51
michael@0 52 WTF_ATTRIBUTE_PRINTF(1, 2)
michael@0 53 static void printf_stderr_common(const char* format, ...)
michael@0 54 {
michael@0 55 va_list args;
michael@0 56 va_start(args, format);
michael@0 57 vprintf_stderr_common(format, args);
michael@0 58 va_end(args);
michael@0 59 }
michael@0 60
michael@0 61 static void printCallSite(const char* file, int line, const char* function)
michael@0 62 {
michael@0 63 #if WTF_COMPILER_MSVC && defined _DEBUG
michael@0 64 _CrtDbgReport(_CRT_WARN, file, line, NULL, "%s\n", function);
michael@0 65 #else
michael@0 66 printf_stderr_common("(%s:%d %s)\n", file, line, function);
michael@0 67 #endif
michael@0 68 }
michael@0 69
michael@0 70 void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion)
michael@0 71 {
michael@0 72 if (assertion)
michael@0 73 printf_stderr_common("Assertion failure: %s\n", assertion);
michael@0 74 else
michael@0 75 printf_stderr_common("Should never be reached\n");
michael@0 76 printCallSite(file, line, function);
michael@0 77 }
michael@0 78
michael@0 79 void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...)
michael@0 80 {
michael@0 81 printf_stderr_common("Assertion failure: ");
michael@0 82 va_list args;
michael@0 83 va_start(args, format);
michael@0 84 vprintf_stderr_common(format, args);
michael@0 85 va_end(args);
michael@0 86 printf_stderr_common("\n%s\n", assertion);
michael@0 87 printCallSite(file, line, function);
michael@0 88 }
michael@0 89
michael@0 90 void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion)
michael@0 91 {
michael@0 92 printf_stderr_common("Argument bad: %s, %s\n", argName, assertion);
michael@0 93 printCallSite(file, line, function);
michael@0 94 }
michael@0 95
michael@0 96 void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...)
michael@0 97 {
michael@0 98 printf_stderr_common("Fatal error: ");
michael@0 99 va_list args;
michael@0 100 va_start(args, format);
michael@0 101 vprintf_stderr_common(format, args);
michael@0 102 va_end(args);
michael@0 103 printf_stderr_common("\n");
michael@0 104 printCallSite(file, line, function);
michael@0 105 }
michael@0 106
michael@0 107 void WTFReportError(const char* file, int line, const char* function, const char* format, ...)
michael@0 108 {
michael@0 109 printf_stderr_common("Error: ");
michael@0 110 va_list args;
michael@0 111 va_start(args, format);
michael@0 112 vprintf_stderr_common(format, args);
michael@0 113 va_end(args);
michael@0 114 printf_stderr_common("\n");
michael@0 115 printCallSite(file, line, function);
michael@0 116 }
michael@0 117
michael@0 118 void WTFLog(WTFLogChannel* channel, const char* format, ...)
michael@0 119 {
michael@0 120 if (channel->state != WTFLogChannelOn)
michael@0 121 return;
michael@0 122
michael@0 123 va_list args;
michael@0 124 va_start(args, format);
michael@0 125 vprintf_stderr_common(format, args);
michael@0 126 va_end(args);
michael@0 127 if (format[strlen(format) - 1] != '\n')
michael@0 128 printf_stderr_common("\n");
michael@0 129 }
michael@0 130
michael@0 131 void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel* channel, const char* format, ...)
michael@0 132 {
michael@0 133 if (channel->state != WTFLogChannelOn)
michael@0 134 return;
michael@0 135
michael@0 136 va_list args;
michael@0 137 va_start(args, format);
michael@0 138 vprintf_stderr_common(format, args);
michael@0 139 va_end(args);
michael@0 140 if (format[strlen(format) - 1] != '\n')
michael@0 141 printf_stderr_common("\n");
michael@0 142 printCallSite(file, line, function);
michael@0 143 }
michael@0 144
michael@0 145 } // extern "C"

mercurial