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.

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

mercurial