Changeset 36029 in webkit


Ignore:
Timestamp:
Sep 2, 2008 2:35:02 PM (16 years ago)
Author:
timothy@apple.com
Message:

Make console functions log the correct resource URL and
line number for where the call originated.

https://bugs.webkit.org/show_bug.cgi?id=17234
<rdar://problem/5732837>

Reviewed by Kevin McCullough.

Test: manual-tests/inspector/console-call-line-numbers.html

  • bindings/js/JSConsoleCustom.cpp: (WebCore::JSConsole::count): Call the impl. (WebCore::JSConsole::timeEnd): Ditto.
  • manual-tests/inspector/console-call-line-numbers.html: Added.
  • manual-tests/inspector/resources/script-console-calls.js: Added.
  • page/Console.cpp: (WebCore::retrieveLastCaller): Helper to get the URL and line. (WebCore::Console::error): Call retrieveLastCaller to get the URL and line number to pass to addMessageToConsole. (WebCore::Console::info): Ditto. (WebCore::Console::log): Ditto. (WebCore::Console::assertCondition): Ditto. (WebCore::Console::count): Ditto. (WebCore::Console::timeEnd): Ditto. (WebCore::Console::warn): Ditto.
  • page/Console.h:
  • page/Console.idl: Make count and timeEnd custom.
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r36028 r36029  
     12008-09-02  Timothy Hatcher  <timothy@apple.com>
     2
     3        Make console functions log the correct resource URL and
     4        line number for where the call originated.
     5
     6        https://bugs.webkit.org/show_bug.cgi?id=17234
     7        <rdar://problem/5732837>
     8
     9        Reviewed by Kevin McCullough.
     10
     11        Test: manual-tests/inspector/console-call-line-numbers.html
     12
     13        * bindings/js/JSConsoleCustom.cpp:
     14        (WebCore::JSConsole::count): Call the impl.
     15        (WebCore::JSConsole::timeEnd): Ditto.
     16        * manual-tests/inspector/console-call-line-numbers.html: Added.
     17        * manual-tests/inspector/resources/script-console-calls.js: Added.
     18        * page/Console.cpp:
     19        (WebCore::retrieveLastCaller): Helper to get the URL and line.
     20        (WebCore::Console::error): Call retrieveLastCaller to get the URL and
     21        line number to pass to addMessageToConsole.
     22        (WebCore::Console::info): Ditto.
     23        (WebCore::Console::log): Ditto.
     24        (WebCore::Console::assertCondition): Ditto.
     25        (WebCore::Console::count): Ditto.
     26        (WebCore::Console::timeEnd): Ditto.
     27        (WebCore::Console::warn): Ditto.
     28        * page/Console.h:
     29        * page/Console.idl: Make count and timeEnd custom.
     30
    1312008-09-02  Timothy Hatcher  <timothy@apple.com>
    232
  • trunk/WebCore/bindings/js/JSConsoleCustom.cpp

    r35787 r36029  
    7878}
    7979
     80JSValue* JSConsole::count(ExecState* exec, const ArgList& arguments)
     81{
     82    impl()->count(exec, arguments);
     83    return jsUndefined();
     84}
     85
     86JSValue* JSConsole::timeEnd(ExecState* exec, const ArgList& arguments)
     87{
     88    impl()->timeEnd(exec, arguments);
     89    return jsUndefined();
     90}
     91
    8092JSValue* JSConsole::profile(ExecState* exec, const ArgList& arguments)
    8193{
  • trunk/WebCore/page/Console.cpp

    r35918 r36029  
    3636#include "FrameTree.h"
    3737#include "InspectorController.h"
     38#include "JSDOMBinding.h"
    3839#include "Page.h"
    3940#include "PageGroup.h"
     
    145146}
    146147
     148static inline void retrieveLastCaller(ExecState* exec, KURL& url, unsigned& lineNumber)
     149{
     150    int signedLineNumber;
     151    int sourceIdentifer;
     152    UString urlString;
     153
     154    exec->machine()->retrieveLastCaller(exec, signedLineNumber, sourceIdentifer, urlString);
     155
     156    url = KURL(urlString);
     157    lineNumber = (signedLineNumber >= 0 ? signedLineNumber : 0);
     158}
     159
    147160void Console::addMessage(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL)
    148161{
     
    178191
    179192    String message = args.at(exec, 0)->toString(exec);
    180     const KURL& url = m_frame->loader()->url();
    181     String prettyURL = url.prettyURL();
    182 
    183     page->chrome()->client()->addMessageToConsole(message, 0, prettyURL);
    184     page->inspectorController()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, exec, args, 0, url.string());
     193
     194    KURL url;
     195    unsigned lineNumber;
     196    retrieveLastCaller(exec, url, lineNumber);
     197
     198    page->chrome()->client()->addMessageToConsole(message, lineNumber, url.prettyURL());
     199    page->inspectorController()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, exec, args, lineNumber, url.string());
    185200
    186201    printToStandardOut(ErrorMessageLevel, exec, args, url);
     
    200215
    201216    String message = args.at(exec, 0)->toString(exec);
    202     const KURL& url = m_frame->loader()->url();
    203     String prettyURL = url.prettyURL();
    204 
    205     page->chrome()->client()->addMessageToConsole(message, 0, prettyURL);
    206     page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, exec, args, 0, url.string());
     217
     218    KURL url;
     219    unsigned lineNumber;
     220    retrieveLastCaller(exec, url, lineNumber);
     221
     222    page->chrome()->client()->addMessageToConsole(message, lineNumber, url.prettyURL());
     223    page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, exec, args, lineNumber, url.string());
    207224
    208225    printToStandardOut(LogMessageLevel, exec, args, url);
     
    222239
    223240    String message = args.at(exec, 0)->toString(exec);
    224     const KURL& url = m_frame->loader()->url();
    225     String prettyURL = url.prettyURL();
    226 
    227     page->chrome()->client()->addMessageToConsole(message, 0, prettyURL);
    228     page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, exec, args, 0, url.string());
     241
     242    KURL url;
     243    unsigned lineNumber;
     244    retrieveLastCaller(exec, url, lineNumber);
     245
     246    page->chrome()->client()->addMessageToConsole(message, lineNumber, url.prettyURL());
     247    page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, exec, args, lineNumber, url.string());
    229248
    230249    printToStandardOut(LogMessageLevel, exec, args, url);
     
    255274        return;
    256275
    257     const KURL& url = m_frame->loader()->url();
     276    KURL url;
     277    unsigned lineNumber;
     278    retrieveLastCaller(exec, url, lineNumber);
    258279
    259280    // FIXME: <https://bugs.webkit.org/show_bug.cgi?id=19135> It would be nice to prefix assertion failures with a message like "Assertion failed: ".
    260281    // FIXME: <https://bugs.webkit.org/show_bug.cgi?id=19136> We should print a message even when args.isEmpty() is true.
    261282
    262     page->inspectorController()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, exec, args, 0, url.string());
     283    page->inspectorController()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, exec, args, lineNumber, url.string());
    263284
    264285    printToStandardOut(ErrorMessageLevel, exec, args, url);
    265286}
    266287
    267 void Console::count(const UString& title)
     288void Console::count(ExecState* exec, const ArgList& args)
    268289{
    269290    if (!m_frame)
     
    274295        return;
    275296
    276     // FIXME: pass the file and line number to the InspectorController
    277     // when we have this information.
    278     page->inspectorController()->count(title, 0, String());
     297    KURL url;
     298    unsigned lineNumber;
     299    retrieveLastCaller(exec, url, lineNumber);
     300
     301    UString title;
     302    if (args.size() >= 1)
     303        title = valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 0));
     304
     305    page->inspectorController()->count(title, lineNumber, url.string());
    279306}
    280307
     
    289316    UString title;
    290317    if (args.size() >= 1)
    291         title = args.at(exec, 0)->toString(exec);
     318        title = valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 0));
    292319
    293320    int sourceId;
     
    309336}
    310337
    311 void Console::timeEnd(const UString& title)
    312 {
     338void Console::timeEnd(ExecState* exec, const ArgList& args)
     339{
     340    UString title;
     341    if (args.size() >= 1)
     342        title = valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 0));
    313343    if (title.isNull())
    314344        return;
     
    323353
    324354    String message = String(title) + String::format(": %.0fms", elapsed);
    325     // FIXME: <https://bugs.webkit.org/show_bug.cgi?id=19791> We should pass in the real sourceURL here so that the Inspector can show it.
    326     page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, message, 0, String());
     355
     356    KURL url;
     357    unsigned lineNumber;
     358    retrieveLastCaller(exec, url, lineNumber);
     359
     360    page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, message, lineNumber, url.string());
    327361}
    328362
     
    364398
    365399    String message = args.at(exec, 0)->toString(exec);
    366     const KURL& url = m_frame->loader()->url();
    367     String prettyURL = url.prettyURL();
    368 
    369     page->chrome()->client()->addMessageToConsole(message, 0, prettyURL);
    370     page->inspectorController()->addMessageToConsole(JSMessageSource, WarningMessageLevel, exec, args, 0, url.string());
     400
     401    KURL url;
     402    unsigned lineNumber;
     403    retrieveLastCaller(exec, url, lineNumber);
     404
     405    page->chrome()->client()->addMessageToConsole(message, lineNumber, url.prettyURL());
     406    page->inspectorController()->addMessageToConsole(JSMessageSource, WarningMessageLevel, exec, args, lineNumber, url.string());
    371407
    372408    printToStandardOut(WarningMessageLevel, exec, args, url);
  • trunk/WebCore/page/Console.h

    r35918 r36029  
    7474        void addMessage(MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL);
    7575
    76         void debug(KJS::ExecState*, const KJS::ArgList& arguments);
    77         void error(KJS::ExecState*, const KJS::ArgList& arguments);
    78         void info(KJS::ExecState*, const KJS::ArgList& arguments);
    79         void log(KJS::ExecState*, const KJS::ArgList& arguments);
    80         void warn(KJS::ExecState*, const KJS::ArgList& arguments);
    81         void dir(KJS::ExecState*, const KJS::ArgList& arguments);
    82         void assertCondition(bool condition, KJS::ExecState*, const KJS::ArgList& arguments);
    83         void count(const KJS::UString& title);
    84         void profile(KJS::ExecState*, const KJS::ArgList& arguments);
    85         void profileEnd(KJS::ExecState*, const KJS::ArgList& arguments);
     76        void debug(KJS::ExecState*, const KJS::ArgList&);
     77        void error(KJS::ExecState*, const KJS::ArgList&);
     78        void info(KJS::ExecState*, const KJS::ArgList&);
     79        void log(KJS::ExecState*, const KJS::ArgList&);
     80        void warn(KJS::ExecState*, const KJS::ArgList&);
     81        void dir(KJS::ExecState*, const KJS::ArgList&);
     82        void assertCondition(bool condition, KJS::ExecState*, const KJS::ArgList&);
     83        void count(KJS::ExecState*, const KJS::ArgList&);
     84        void profile(KJS::ExecState*, const KJS::ArgList&);
     85        void profileEnd(KJS::ExecState*, const KJS::ArgList&);
    8686        void time(const KJS::UString& title);
    87         void timeEnd(const KJS::UString& title);
    88         void group(KJS::ExecState*, const KJS::ArgList& arguments);
     87        void timeEnd(KJS::ExecState*, const KJS::ArgList&);
     88        void group(KJS::ExecState*, const KJS::ArgList&);
    8989        void groupEnd();
    9090
  • trunk/WebCore/page/Console.idl

    r35842 r36029  
    3737        [Custom] void dir();
    3838        [Custom, ImplementationFunction=assertCondition] void assert(in boolean condition);
    39         void count(in [ConvertUndefinedOrNullToNullString] DOMString title);
     39        [Custom] void count();
    4040
    4141        [Custom] void profile(in DOMString title);
    4242        [Custom] void profileEnd();
    4343        void time(in [ConvertUndefinedOrNullToNullString] DOMString title);
    44         void timeEnd(in [ConvertUndefinedOrNullToNullString] DOMString title);
     44        [Custom] void timeEnd();
    4545        [Custom] void group();
    4646        void groupEnd();
Note: See TracChangeset for help on using the changeset viewer.