Changeset 161678 in webkit


Ignore:
Timestamp:
Jan 10, 2014 2:16:17 PM (10 years ago)
Author:
timothy@apple.com
Message:

Clean up and fix some issues with stdout formatting of console messages.

  • Fix URLs not printing line numbers unless column number is > 0.
  • Change "CONSOLEAPI" to "CONSOLE" for the source.
  • Clean up how console.trace outputs and print URL, line and column for each frame.
  • Print "(unknown)" for anonymous and native code call frames.

https://bugs.webkit.org/show_bug.cgi?id=126767

Reviewed by Joseph Pecoraro.

  • page/Console.cpp:

(WebCore::internalAddMessage):

  • page/PageConsole.cpp:

(WebCore::PageConsole::printSourceURLAndPosition):
(WebCore::PageConsole::printMessageSourceAndLevelPrefix):

  • page/PageConsole.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r161676 r161678  
     12014-01-10  Timothy Hatcher  <timothy@apple.com>
     2
     3        Clean up and fix some issues with stdout formatting of console messages.
     4
     5        * Fix URLs not printing line numbers unless column number is > 0.
     6        * Change "CONSOLEAPI" to "CONSOLE" for the source.
     7        * Clean up how console.trace outputs and print URL, line and column for each frame.
     8        * Print "(unknown)" for anonymous and native code call frames.
     9
     10        https://bugs.webkit.org/show_bug.cgi?id=126767
     11
     12        Reviewed by Joseph Pecoraro.
     13
     14        * page/Console.cpp:
     15        (WebCore::internalAddMessage):
     16        * page/PageConsole.cpp:
     17        (WebCore::PageConsole::printSourceURLAndPosition):
     18        (WebCore::PageConsole::printMessageSourceAndLevelPrefix):
     19        * page/PageConsole.h:
     20
    1212014-01-10  Joseph Pecoraro  <pecoraro@apple.com>
    222
  • trunk/Source/WebCore/page/Console.cpp

    r160457 r161678  
    9494
    9595    PageConsole::printSourceURLAndPosition(lastCaller.sourceURL(), lastCaller.lineNumber());
    96     PageConsole::printMessageSourceAndLevelPrefix(ConsoleAPIMessageSource, level);
     96
     97    printf(": ");
     98
     99    PageConsole::printMessageSourceAndLevelPrefix(ConsoleAPIMessageSource, level, printTrace);
    97100
    98101    for (size_t i = 0; i < arguments->argumentCount(); ++i) {
     
    103106    printf("\n");
    104107
    105     if (printTrace) {
    106         printf("Stack Trace\n");
    107         for (size_t i = 0; i < callStack->size(); ++i) {
    108             String functionName = String(callStack->at(i).functionName());
    109             printf("\t%s\n", functionName.utf8().data());
    110         }
     108    if (!printTrace)
     109        return;
     110
     111    for (size_t i = 0; i < callStack->size(); ++i) {
     112        const ScriptCallFrame& callFrame = callStack->at(i);
     113
     114        String functionName = String(callFrame.functionName());
     115        if (functionName.isEmpty())
     116            functionName = ASCIILiteral("(unknown)");
     117
     118        printf("%lu: %s (", i, functionName.utf8().data());
     119
     120        PageConsole::printSourceURLAndPosition(callFrame.sourceURL(), callFrame.lineNumber());
     121
     122        printf(")\n");
    111123    }
    112124}
  • trunk/Source/WebCore/page/PageConsole.cpp

    r160457 r161678  
    6969    if (!sourceURL.isEmpty()) {
    7070        if (lineNumber > 0 && columnNumber > 0)
    71             printf("%s:%u:%u: ", sourceURL.utf8().data(), lineNumber, columnNumber);
     71            printf("%s:%u:%u", sourceURL.utf8().data(), lineNumber, columnNumber);
     72        else if (lineNumber > 0)
     73            printf("%s:%u", sourceURL.utf8().data(), lineNumber);
    7274        else
    73             printf("%s: ", sourceURL.utf8().data());
    74     }
    75 }
    76 
    77 void PageConsole::printMessageSourceAndLevelPrefix(MessageSource source, MessageLevel level)
     75            printf("%s", sourceURL.utf8().data());
     76    }
     77}
     78
     79void PageConsole::printMessageSourceAndLevelPrefix(MessageSource source, MessageLevel level, bool showAsTrace)
    7880{
    7981    const char* sourceString;
     
    8991        break;
    9092    case ConsoleAPIMessageSource:
    91         sourceString = "CONSOLEAPI";
     93        sourceString = "CONSOLE";
    9294        break;
    9395    case StorageMessageSource:
     
    134136        break;
    135137    }
     138
     139    if (showAsTrace)
     140        levelString = "TRACE";
    136141
    137142    printf("%s %s:", sourceString, levelString);
  • trunk/Source/WebCore/page/PageConsole.h

    r160374 r161678  
    5050
    5151    static void printSourceURLAndPosition(const String& sourceURL, unsigned lineNumber, unsigned columnNumber = 0);
    52     static void printMessageSourceAndLevelPrefix(MessageSource, MessageLevel);
     52    static void printMessageSourceAndLevelPrefix(MessageSource, MessageLevel, bool showAsTrace = false);
    5353
    5454    void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, PassRefPtr<ScriptCallStack> = 0, JSC::ExecState* = 0, unsigned long requestIdentifier = 0);
Note: See TracChangeset for help on using the changeset viewer.