Changeset 35253 in webkit


Ignore:
Timestamp:
Jul 20, 2008 5:43:22 AM (16 years ago)
Author:
oliver@apple.com
Message:

Bug 15979: Console logs in a database callback lose line number information
<https://bugs.webkit.org/show_bug.cgi?id=15979>

Reviewed by Mark Rowe

The problem was that there were multiple versions of the logic to
log an exception to the console, many of which were incorrect. We
resolve this by making one single shared reportException method,
which handles the exceptions correctly.

This improves fidelity of callback errors, and ensures that
exceptions thrown in timer callbacks correctly report line numbers,
etc.

Test: fast/js/exceptions-thrown-in-callbacks.html

Location:
trunk
Files:
2 added
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r35250 r35253  
     12008-07-20  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Mark Rowe.
     4
     5        Add layout test to check correctly handling of exceptions in callback by WebCore.
     6        Update existing test results for higher fidelity output.
     7
     8        * fast/dom/NamedNodeMap-setNamedItem-crash-expected.txt:
     9        * fast/js/exceptions-thrown-in-callbacks-expected.txt: Added.
     10        * fast/js/exceptions-thrown-in-callbacks.html: Added.
     11        * fast/xpath/nsresolver-exception-expected.txt:
     12        * fast/xsl/transform-xhr-doc-expected.txt:
     13        * http/tests/security/aboutBlank/xss-DENIED-navigate-opener-document-write-expected.txt:
     14        * http/tests/security/aboutBlank/xss-DENIED-navigate-opener-javascript-url-expected.txt:
     15        * http/tests/security/aboutBlank/xss-DENIED-set-opener-expected.txt:
     16        * platform/mac/fast/dynamic/015-expected.txt:
     17        * platform/mac/fast/events/updateLayoutForHitTest-expected.txt:
     18        * platform/mac/tables/mozilla_expected_failures/bugs/bug92868_1-expected.txt:
     19        * platform/mac/tables/mozilla_expected_failures/dom/appendCells1-expected.txt:
     20        * platform/mac/tables/mozilla_expected_failures/dom/appendCellsRebuild1-expected.txt:
     21        * platform/mac/tables/mozilla_expected_failures/dom/insertTbodyExpand1-expected.txt:
     22        * platform/mac/tables/mozilla_expected_failures/dom/insertTbodyRebuild1-expected.txt:
     23        * storage/transaction_callback_exception_crash-expected.txt:
     24
    1252008-07-19  Oliver Hunt  <oliver@apple.com>
    226
  • trunk/LayoutTests/fast/dom/NamedNodeMap-setNamedItem-crash-expected.txt

    r33023 r35253  
    1 CONSOLE MESSAGE: line 7: NOT_FOUND_ERR: DOM Exception 8
     1CONSOLE MESSAGE: line 7: Error: NOT_FOUND_ERR: DOM Exception 8
    22This passes if it does not crash. (see https://bugs.webkit.org/show_bug.cgi?id=18958)
  • trunk/LayoutTests/fast/xpath/nsresolver-exception-expected.txt

    r33979 r35253  
    1 CONSOLE MESSAGE: line 14: this is an exception
     1CONSOLE MESSAGE: line 14: Error: this is an exception
    22SUCCESS
  • trunk/LayoutTests/fast/xsl/transform-xhr-doc-expected.txt

    r35245 r35253  
    1 CONSOLE MESSAGE: line 20: Result of expression 'doc' [undefined] is not an object.
     1CONSOLE MESSAGE: line 20: TypeError: Result of expression 'doc' [undefined] is not an object.
    22Test for bug 10313: xsl:import doesn't work in stylesheets loaded via XMLHttpRequest.
    33
  • trunk/LayoutTests/http/tests/security/aboutBlank/xss-DENIED-navigate-opener-document-write-expected.txt

    r35245 r35253  
    11CONSOLE MESSAGE: line 1: Unsafe JavaScript attempt to access frame with URL http://localhost:8000/security/resources/innocent-victim-with-notify.html from frame with URL about:blank. Domains, protocols and ports must match.
    22
    3 CONSOLE MESSAGE: line 1: Result of expression 'target.document' [undefined] is not an object.
     3CONSOLE MESSAGE: line 1: TypeError: Result of expression 'target.document' [undefined] is not an object.
    44This page opens a window to "", injects malicious code, and then navigates its opener to the victim. The opened window then tries to scripts its opener after document.writeing a new document.
    55Code injected into window:
  • trunk/LayoutTests/http/tests/security/aboutBlank/xss-DENIED-navigate-opener-javascript-url-expected.txt

    r35245 r35253  
    11CONSOLE MESSAGE: line 1: Unsafe JavaScript attempt to access frame with URL http://localhost:8000/security/resources/innocent-victim-with-notify.html from frame with URL http://127.0.0.1:8000/security/aboutBlank/xss-DENIED-navigate-opener-javascript-url.html. Domains, protocols and ports must match.
    22
    3 CONSOLE MESSAGE: line 1: Result of expression 'target.document' [undefined] is not an object.
     3CONSOLE MESSAGE: line 1: TypeError: Result of expression 'target.document' [undefined] is not an object.
    44This page opens a window to "", injects malicious code, and then navigates its opener to the victim. The opened window then tries to scripts its opener after reloading itself as a javascript URL.
    55Code injected into window:
  • trunk/LayoutTests/http/tests/security/aboutBlank/xss-DENIED-set-opener-expected.txt

    r35245 r35253  
    33CONSOLE MESSAGE: line 1: Unsafe JavaScript attempt to access frame with URL http://localhost:8000/security/resources/innocent-victim.html from frame with URL about:blank. Domains, protocols and ports must match.
    44
    5 CONSOLE MESSAGE: line 1: Result of expression 'target.document' [undefined] is not an object.
     5CONSOLE MESSAGE: line 1: TypeError: Result of expression 'target.document' [undefined] is not an object.
    66This page opens a window to "", injects malicious code, and then uses window.open.call to set its opener to the victim. The opened window then tries to scripts its opener.
    77Code injected into window:
  • trunk/LayoutTests/platform/mac/fast/dynamic/015-expected.txt

    r25970 r35253  
    1 CONSOLE MESSAGE: line 16: INDEX_SIZE_ERR: DOM Exception 1
     1CONSOLE MESSAGE: line 16: Error: INDEX_SIZE_ERR: DOM Exception 1
    22layer at (0,0) size 800x600
    33  RenderView at (0,0) size 800x600
  • trunk/LayoutTests/platform/mac/fast/events/updateLayoutForHitTest-expected.txt

    r35245 r35253  
    1 CONSOLE MESSAGE: line 36: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
    2 CONSOLE MESSAGE: line 40: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
    3 CONSOLE MESSAGE: line 36: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
    4 CONSOLE MESSAGE: line 40: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
     1CONSOLE MESSAGE: line 36: TypeError: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
     2CONSOLE MESSAGE: line 40: TypeError: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
     3CONSOLE MESSAGE: line 36: TypeError: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
     4CONSOLE MESSAGE: line 40: TypeError: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
    55layer at (0,0) size 800x600
    66  RenderView at (0,0) size 800x600
  • trunk/LayoutTests/platform/mac/tables/mozilla_expected_failures/bugs/bug92868_1-expected.txt

    r35250 r35253  
    1 CONSOLE MESSAGE: line 14: Result of expression 'document.styleSheets[1]' [undefined] is not an object.
     1CONSOLE MESSAGE: line 14: TypeError: Result of expression 'document.styleSheets[1]' [undefined] is not an object.
    22layer at (0,0) size 800x600
    33  RenderView at (0,0) size 800x600
  • trunk/LayoutTests/platform/mac/tables/mozilla_expected_failures/dom/appendCells1-expected.txt

    r30635 r35253  
    1 CONSOLE MESSAGE: line 7: Can't find variable: appendCellAt
     1CONSOLE MESSAGE: line 7: ReferenceError: Can't find variable: appendCellAt
    22layer at (0,0) size 800x600
    33  RenderView at (0,0) size 800x600
  • trunk/LayoutTests/platform/mac/tables/mozilla_expected_failures/dom/appendCellsRebuild1-expected.txt

    r30635 r35253  
    1 CONSOLE MESSAGE: line 7: Can't find variable: appendCellAt
     1CONSOLE MESSAGE: line 7: ReferenceError: Can't find variable: appendCellAt
    22layer at (0,0) size 800x600
    33  RenderView at (0,0) size 800x600
  • trunk/LayoutTests/platform/mac/tables/mozilla_expected_failures/dom/insertTbodyExpand1-expected.txt

    r30635 r35253  
    1 CONSOLE MESSAGE: line 10: Can't find variable: appendCell
     1CONSOLE MESSAGE: line 10: ReferenceError: Can't find variable: appendCell
    22layer at (0,0) size 800x600
    33  RenderView at (0,0) size 800x600
  • trunk/LayoutTests/platform/mac/tables/mozilla_expected_failures/dom/insertTbodyRebuild1-expected.txt

    r30635 r35253  
    1 CONSOLE MESSAGE: line 10: Can't find variable: appendCell
     1CONSOLE MESSAGE: line 10: ReferenceError: Can't find variable: appendCell
    22layer at (0,0) size 800x600
    33  RenderView at (0,0) size 800x600
  • trunk/LayoutTests/storage/transaction_callback_exception_crash-expected.txt

    r30635 r35253  
    1 CONSOLE MESSAGE: line 0: undefined
     1CONSOLE MESSAGE: line 0: TransactionCallbackError
    22If WebKit doesn't crash, this test has passed
  • trunk/WebCore/ChangeLog

    r35252 r35253  
     12008-07-19  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Mark Rowe.
     4
     5        Bug 15979: Console logs in a database callback lose line number information
     6        <https://bugs.webkit.org/show_bug.cgi?id=15979>
     7
     8        The problem was that there were multiple versions of the logic to
     9        log an exception to the console, many of which were incorrect.  We
     10        resolve this by making one single shared reportException method,
     11        which handles the exceptions correctly.
     12
     13        This improves fidelity of callback errors, and ensures that
     14        exceptions thrown in timer callbacks correctly report line numbers,
     15        etc.
     16
     17        Test: fast/js/exceptions-thrown-in-callbacks.html
     18
     19        * bindings/js/JSCustomSQLStatementCallback.cpp:
     20        (WebCore::JSCustomSQLStatementCallback::handleEvent):
     21        * bindings/js/JSCustomSQLStatementErrorCallback.cpp:
     22        (WebCore::JSCustomSQLStatementErrorCallback::handleEvent):
     23        * bindings/js/JSCustomSQLTransactionCallback.cpp:
     24        (WebCore::JSCustomSQLTransactionCallback::handleEvent):
     25        * bindings/js/JSCustomSQLTransactionErrorCallback.cpp:
     26        (WebCore::JSCustomSQLTransactionErrorCallback::handleEvent):
     27        * bindings/js/JSCustomVoidCallback.cpp:
     28        (WebCore::JSCustomVoidCallback::handleEvent):
     29        * bindings/js/JSCustomXPathNSResolver.cpp:
     30        (WebCore::JSCustomXPathNSResolver::lookupNamespaceURI):
     31        * bindings/js/JSEventListener.cpp:
     32        (WebCore::JSAbstractEventListener::handleEvent):
     33        * bindings/js/ScheduledAction.cpp:
     34        (WebCore::ScheduledAction::execute):
     35        * bindings/js/ScriptController.cpp:
     36        (WebCore::ScriptController::evaluate):
     37        * bindings/objc/WebScriptObject.mm:
     38        (WebCore::addExceptionToConsole):
     39        * page/Console.cpp:
     40        (WebCore::Console::reportException):
     41        * page/Console.h:
     42
    1432008-07-20  Nikolas Zimmermann  <zimmermann@kde.org>
    244
     
    2870        (WebCore::TextResourceDecoder::checkForHeadCharset):
    2971
    30 2008-07-19  Oliver Hunt  <oliver@apple.com>
    31 
    32         Reviewed by NOBODY (Build fix).
     722008-07-20  Oliver Hunt  <oliver@apple.com>
     73
     74        Reviewed by NOBODY (build fix).
    3375
    3476        Attempt to fix windows build
  • trunk/WebCore/bindings/js/JSCustomSQLStatementCallback.cpp

    r34947 r35253  
    8585       
    8686    if (exec->hadException()) {
    87         JSObject* exception = exec->exception()->toObject(exec);
    88         String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
    89         int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
    90         String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
    91         m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
     87        m_frame->domWindow()->console()->reportCurrentException(exec);
    9288       
    9389        raisedException = true;
    94        
    95         exec->clearException();
    9690    }
    9791       
  • trunk/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp

    r34947 r35253  
    9191       
    9292    if (exec->hadException()) {
    93         JSObject* exception = exec->exception()->toObject(exec);
    94         String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
    95         int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
    96         String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
    97         m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
    98         exec->clearException();
     93        m_frame->domWindow()->console()->reportCurrentException(exec);
    9994           
    10095        // The spec says:
  • trunk/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp

    r35148 r35253  
    130130       
    131131    if (exec->hadException()) {
    132         JSObject* exception = exec->exception()->toObject(exec);
    133         String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
    134         int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
    135         String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
    136         m_data->frame()->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
    137         exec->clearException();
     132        m_data->frame()->domWindow()->console()->reportCurrentException(exec);
    138133       
    139134        raisedException = true;
  • trunk/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp

    r34947 r35253  
    8383    globalObject->stopTimeoutCheck();
    8484       
    85     if (exec->hadException()) {
    86         JSObject* exception = exec->exception()->toObject(exec);
    87         String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
    88         int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
    89         String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
    90         m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
    91         exec->clearException();
    92     }
     85    if (exec->hadException())
     86        m_frame->domWindow()->console()->reportCurrentException(exec);
    9387       
    9488    Document::updateDocumentsRendering();
  • trunk/WebCore/bindings/js/JSCustomVoidCallback.cpp

    r34947 r35253  
    8282    globalObject->stopTimeoutCheck();
    8383       
    84     if (exec->hadException()) {
    85         JSObject* exception = exec->exception()->toObject(exec);
    86         String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
    87         int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
    88         String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
    89         m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
    90         exec->clearException();           
    91     }
     84    if (exec->hadException())
     85        m_frame->domWindow()->console()->reportCurrentException(exec);
    9286       
    9387    Document::updateDocumentsRendering();
  • trunk/WebCore/bindings/js/JSCustomXPathNSResolver.cpp

    r34947 r35253  
    105105
    106106    String result;
    107     if (exec->hadException()) {
    108         JSObject* exception = exec->exception()->toObject(exec);
    109         String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
    110         int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
    111         String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
    112         m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
    113         exec->clearException();
    114     } else {
     107    if (exec->hadException())
     108        m_frame->domWindow()->console()->reportCurrentException(exec);
     109    else {
    115110        if (!retval->isUndefinedOrNull())
    116111            result = retval->toString(exec);
  • trunk/WebCore/bindings/js/JSEventListener.cpp

    r35148 r35253  
    9999        window->setCurrentEvent(savedEvent);
    100100
    101         if (exec->hadException()) {
    102             JSObject* exception = exec->exception()->toObject(exec);
    103             String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
    104             int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
    105             String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
    106             frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
    107             exec->clearException();
    108         } else {
     101        if (exec->hadException())
     102            frame->domWindow()->console()->reportCurrentException(exec);
     103        else {
    109104            if (!retval->isUndefinedOrNull() && event->storesResultAsString())
    110105                event->storeResult(retval->toString(exec));
  • trunk/WebCore/bindings/js/ScheduledAction.cpp

    r35203 r35253  
    7575            call(exec, m_function, callType, callData, windowShell, args);
    7676            window->stopTimeoutCheck();
    77             if (exec->hadException()) {
    78                 JSObject* exception = exec->exception()->toObject(exec);
    79                 exec->clearException();
    80                 String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
    81                 int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
    82                 frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, String());
    83             }
     77            if (exec->hadException())
     78                frame->domWindow()->console()->reportCurrentException(exec);
    8479        }
    8580    } else
  • trunk/WebCore/bindings/js/ScriptController.cpp

    r35184 r35253  
    9898    }
    9999
    100     if (comp.complType() == Throw) {
    101         UString errorMessage = comp.value()->toString(exec);
    102         int lineNumber = comp.value()->toObject(exec)->get(exec, Identifier(exec, "line"))->toInt32(exec);
    103         UString exceptionSourceURL = comp.value()->toObject(exec)->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
    104         m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, exceptionSourceURL);
    105     }
     100    if (comp.complType() == Throw)
     101        m_frame->domWindow()->console()->reportException(exec, comp.value());
    106102
    107103    m_sourceURL = savedSourceURL;
  • trunk/WebCore/bindings/objc/WebScriptObject.mm

    r34956 r35253  
    9090{
    9191    JSDOMWindow* window = asJSDOMWindow(exec->dynamicGlobalObject());
    92     JSObject* exception = exec->exception()->toObject(exec);
    93     if (!window || !exception)
     92    if (!window || !exec->hadException())
    9493        return;
    95     String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
    96     int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
    97     String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
    98     window->impl()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
     94    window->impl()->console()->reportCurrentException(exec);
    9995}
    10096
  • trunk/WebCore/page/Console.cpp

    r35039 r35253  
    296296}
    297297
     298void  Console::reportException(ExecState* exec, JSValue* exception)
     299{
     300    UString errorMessage = exception->toString(exec);
     301    JSObject* exceptionObject = exception->toObject(exec);
     302    int lineNumber = exceptionObject->get(exec, Identifier(exec, "line"))->toInt32(exec);
     303    UString exceptionSourceURL = exceptionObject->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
     304    addMessage(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, exceptionSourceURL);
     305}
     306
     307void  Console::reportCurrentException(ExecState* exec)
     308{
     309    JSValue* exception = exec->exception();
     310    exec->clearException();
     311    reportException(exec, exception);
     312}
     313
    298314} // namespace WebCore
  • trunk/WebCore/page/Console.h

    r34696 r35253  
    3939    class ArgList;
    4040    class Profile;
     41    class JSValue;
    4142}
    4243
     
    8081        void finishedProfiling(PassRefPtr<KJS::Profile>);
    8182
     83        void reportException(KJS::ExecState*, KJS::JSValue*);
     84        void reportCurrentException(KJS::ExecState*);
    8285    private:
    8386        Console(Frame*);
Note: See TracChangeset for help on using the changeset viewer.