Bug 15979: Console logs in a database callback lose line number information
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 20 Jul 2008 12:43:22 +0000 (12:43 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 20 Jul 2008 12:43:22 +0000 (12:43 +0000)
<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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@35253 268f45cc-cd09-0410-ab3c-d52691b4dbfc

30 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/NamedNodeMap-setNamedItem-crash-expected.txt
LayoutTests/fast/js/exceptions-thrown-in-callbacks-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/exceptions-thrown-in-callbacks.html [new file with mode: 0644]
LayoutTests/fast/xpath/nsresolver-exception-expected.txt
LayoutTests/fast/xsl/transform-xhr-doc-expected.txt
LayoutTests/http/tests/security/aboutBlank/xss-DENIED-navigate-opener-document-write-expected.txt
LayoutTests/http/tests/security/aboutBlank/xss-DENIED-navigate-opener-javascript-url-expected.txt
LayoutTests/http/tests/security/aboutBlank/xss-DENIED-set-opener-expected.txt
LayoutTests/platform/mac/fast/dynamic/015-expected.txt
LayoutTests/platform/mac/fast/events/updateLayoutForHitTest-expected.txt
LayoutTests/platform/mac/tables/mozilla_expected_failures/bugs/bug92868_1-expected.txt
LayoutTests/platform/mac/tables/mozilla_expected_failures/dom/appendCells1-expected.txt
LayoutTests/platform/mac/tables/mozilla_expected_failures/dom/appendCellsRebuild1-expected.txt
LayoutTests/platform/mac/tables/mozilla_expected_failures/dom/insertTbodyExpand1-expected.txt
LayoutTests/platform/mac/tables/mozilla_expected_failures/dom/insertTbodyRebuild1-expected.txt
LayoutTests/storage/transaction_callback_exception_crash-expected.txt
WebCore/ChangeLog
WebCore/bindings/js/JSCustomSQLStatementCallback.cpp
WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp
WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp
WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp
WebCore/bindings/js/JSCustomVoidCallback.cpp
WebCore/bindings/js/JSCustomXPathNSResolver.cpp
WebCore/bindings/js/JSEventListener.cpp
WebCore/bindings/js/ScheduledAction.cpp
WebCore/bindings/js/ScriptController.cpp
WebCore/bindings/objc/WebScriptObject.mm
WebCore/page/Console.cpp
WebCore/page/Console.h

index 771f78775319c3a7676315e895c69b71e7a70fd9..b21c336c0e845a2f7aa271522573254f7a89fafe 100644 (file)
@@ -1,3 +1,27 @@
+2008-07-20  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Mark Rowe.
+
+        Add layout test to check correctly handling of exceptions in callback by WebCore.
+        Update existing test results for higher fidelity output.
+
+        * fast/dom/NamedNodeMap-setNamedItem-crash-expected.txt:
+        * fast/js/exceptions-thrown-in-callbacks-expected.txt: Added.
+        * fast/js/exceptions-thrown-in-callbacks.html: Added.
+        * fast/xpath/nsresolver-exception-expected.txt:
+        * fast/xsl/transform-xhr-doc-expected.txt:
+        * http/tests/security/aboutBlank/xss-DENIED-navigate-opener-document-write-expected.txt:
+        * http/tests/security/aboutBlank/xss-DENIED-navigate-opener-javascript-url-expected.txt:
+        * http/tests/security/aboutBlank/xss-DENIED-set-opener-expected.txt:
+        * platform/mac/fast/dynamic/015-expected.txt:
+        * platform/mac/fast/events/updateLayoutForHitTest-expected.txt:
+        * platform/mac/tables/mozilla_expected_failures/bugs/bug92868_1-expected.txt:
+        * platform/mac/tables/mozilla_expected_failures/dom/appendCells1-expected.txt:
+        * platform/mac/tables/mozilla_expected_failures/dom/appendCellsRebuild1-expected.txt:
+        * platform/mac/tables/mozilla_expected_failures/dom/insertTbodyExpand1-expected.txt:
+        * platform/mac/tables/mozilla_expected_failures/dom/insertTbodyRebuild1-expected.txt:
+        * storage/transaction_callback_exception_crash-expected.txt:
+
 2008-07-19  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Cameron Zwarich.
index 0cab08c2283563088f0add1378926f947f583888..b7c020cb991403fb01b5d6f62f5eb8ea5eb957fc 100644 (file)
@@ -1,2 +1,2 @@
-CONSOLE MESSAGE: line 7: NOT_FOUND_ERR: DOM Exception 8
+CONSOLE MESSAGE: line 7: Error: NOT_FOUND_ERR: DOM Exception 8
 This passes if it does not crash. (see https://bugs.webkit.org/show_bug.cgi?id=18958)
diff --git a/LayoutTests/fast/js/exceptions-thrown-in-callbacks-expected.txt b/LayoutTests/fast/js/exceptions-thrown-in-callbacks-expected.txt
new file mode 100644 (file)
index 0000000..a5cd00a
--- /dev/null
@@ -0,0 +1,5 @@
+CONSOLE MESSAGE: line 17: PASS: toString called on exception value thrown from event handler
+CONSOLE MESSAGE: line 23: PASS: toString called on exception value thrown from sql transaction callback
+CONSOLE MESSAGE: line 33: PASS: toString called on exception value thrown from sql error callback
+CONSOLE MESSAGE: line 41: PASS: toString called on exception value thrown from timer
+This test ensures that exceptions are handled correctly by the various callback mechanisms present in WebCore.
diff --git a/LayoutTests/fast/js/exceptions-thrown-in-callbacks.html b/LayoutTests/fast/js/exceptions-thrown-in-callbacks.html
new file mode 100644 (file)
index 0000000..221fe00
--- /dev/null
@@ -0,0 +1,46 @@
+This test ensures that exceptions are handled correctly by the various callback mechanisms present in WebCore.
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+
+var db = openDatabase("exception-info-test", "1.0", "Test for exception information thrown by callbacks and timers", 1);
+
+function errorObject(msg) {
+    return { message: "FAIL: message incorrectly pulled from thrown object in " + msg, 
+             toString: function() {return "PASS: toString called on exception value thrown from " + msg} }
+}
+
+function eventTest() {
+    setTimeout(dbTransactionTest, 0);
+    throw errorObject("event handler");
+}
+
+function dbTransactionTest() {
+    db.transaction(function(tx) { 
+        setTimeout(dbStatementTest, 0);
+        throw errorObject("sql transaction callback");
+    });
+}
+
+function dbStatementTest() {
+    db.transaction(
+        function(tx) {
+            tx.executeSql("I am bogus syntax", [], function() {
+        }, function(tx, error) {
+            setTimeout(timerTest, 0);
+            throw errorObject("sql error callback");
+        });
+    });
+}
+
+function timerTest() {
+    if (window.layoutTestController)
+        setTimeout("layoutTestController.notifyDone()", 0);
+    throw errorObject("timer");
+}
+
+window.onload = eventTest;
+</script>
+
index 801289738826f46f74a9ad5338d4a338c9afc558..06e55a44629483bf77b8db59051a5a7d43134ba9 100644 (file)
@@ -1,2 +1,2 @@
-CONSOLE MESSAGE: line 14: this is an exception
+CONSOLE MESSAGE: line 14: Error: this is an exception
 SUCCESS
index d2bb492223ce4585e9848ce3963935d28f29fa87..8881d1d74c1c411c7ebaf2f960dd2702176fcbd7 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 20: Result of expression 'doc' [undefined] is not an object.
+CONSOLE MESSAGE: line 20: TypeError: Result of expression 'doc' [undefined] is not an object.
 Test for bug 10313: xsl:import doesn't work in stylesheets loaded via XMLHttpRequest.
 
 It's nice that this hasn't crashed, but the XSL transformation has failed.
index 126cef4130be1032f232778ce5409e5b9aff1b6f..119b8092e78f66a577912c3e2f43a31b2f20ad65 100644 (file)
@@ -1,6 +1,6 @@
 CONSOLE 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.
 
-CONSOLE MESSAGE: line 1: Result of expression 'target.document' [undefined] is not an object.
+CONSOLE MESSAGE: line 1: TypeError: Result of expression 'target.document' [undefined] is not an object.
 This 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.
 Code injected into window:
 <script>document.write('<script>function write(target, message) { target.document.body.innerHTML = message; }setTimeout(function() {write(window.opener, \'FAIL: XSS was allowed.\');}, 100);setTimeout(function() {write(window.opener.top.frames[1], \'SUCCESS: Window remained in original SecurityOrigin.\');}, 200);setTimeout(function() { if (window.layoutTestController) layoutTestController.globalFlag = true; }, 300);<\/script>');</script>
index 8218e30ea276fd86ab2b4fef45c0789d403ebdda..56f2c05815dca0eda25db60469fb05e7fb3123f3 100644 (file)
@@ -1,6 +1,6 @@
 CONSOLE 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.
 
-CONSOLE MESSAGE: line 1: Result of expression 'target.document' [undefined] is not an object.
+CONSOLE MESSAGE: line 1: TypeError: Result of expression 'target.document' [undefined] is not an object.
 This 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.
 Code injected into window:
 <script>window.location = 'javascript:\'<script>function write(target, message) { target.document.body.innerHTML = message; }setTimeout(function() {write(window.opener, \\\'FAIL: XSS was allowed.\\\');}, 100);setTimeout(function() {write(window.opener.top.frames[1], \\\'SUCCESS: Window remained in original SecurityOrigin.\\\');}, 200);setTimeout(function() { if (window.layoutTestController) layoutTestController.globalFlag = true; }, 300);<\\\/script>\''</script>
index a658c755bf2c9c87439cee24e36da0f02b6eb534..83f57eb3c54230a4fde9ee73967f249dffc8c2b8 100644 (file)
@@ -2,7 +2,7 @@ CONSOLE MESSAGE: line 1: Unsafe JavaScript attempt to access frame with URL http
 
 CONSOLE 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.
 
-CONSOLE MESSAGE: line 1: Result of expression 'target.document' [undefined] is not an object.
+CONSOLE MESSAGE: line 1: TypeError: Result of expression 'target.document' [undefined] is not an object.
 This 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.
 Code injected into window:
 <script>function write(target, message) { target.document.body.innerHTML = message; }
index 3193072ab92b120a2a83163c7f5b31a330a94261..728640021b4d20b346ce1378f98404409891f0fd 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 16: INDEX_SIZE_ERR: DOM Exception 1
+CONSOLE MESSAGE: line 16: Error: INDEX_SIZE_ERR: DOM Exception 1
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
 layer at (0,0) size 800x600
index 3801ee37d98e4f378302d52bb737c7a7c16e0fad..c580fe6b2698289e0ecea40d33867c44830db0b9 100644 (file)
@@ -1,7 +1,7 @@
-CONSOLE MESSAGE: line 36: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
-CONSOLE MESSAGE: line 40: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
-CONSOLE MESSAGE: line 36: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
-CONSOLE MESSAGE: line 40: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
+CONSOLE MESSAGE: line 36: TypeError: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
+CONSOLE MESSAGE: line 40: TypeError: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
+CONSOLE MESSAGE: line 36: TypeError: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
+CONSOLE MESSAGE: line 40: TypeError: Result of expression 'triangleSpan.nextSibling.nextSibling.nextSibling.nextSibling' [null] is not an object.
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
 layer at (0,0) size 800x600
index 6a563c075538e4cc491b301c7ad1178f9fee091e..16b8ecd31de43fa450eb9ba4a8c6f51bfc061f7a 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 14: Result of expression 'document.styleSheets[1]' [undefined] is not an object.
+CONSOLE MESSAGE: line 14: TypeError: Result of expression 'document.styleSheets[1]' [undefined] is not an object.
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
 layer at (0,0) size 800x76
index f988c0603b3c33dba78924e02e2a62fe411942ef..42c07612b448fb5cd19fe833f8777a05f52d5bc1 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 7: Can't find variable: appendCellAt
+CONSOLE MESSAGE: line 7: ReferenceError: Can't find variable: appendCellAt
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
 layer at (0,0) size 800x600
index 0d42d2578cc6e17f7d53a3d984ed727537a9694b..bd9e212f570db42aa90eb85012b79c3803b971e5 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 7: Can't find variable: appendCellAt
+CONSOLE MESSAGE: line 7: ReferenceError: Can't find variable: appendCellAt
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
 layer at (0,0) size 800x600
index 33986b1876e22bab9b64739b378c5bd428fb5d8e..18ee319eed839525e51f02f78a1d649847df9f6c 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 10: Can't find variable: appendCell
+CONSOLE MESSAGE: line 10: ReferenceError: Can't find variable: appendCell
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
 layer at (0,0) size 800x600
index caefffbbcc6124764785ca4985a1e2dbe93cce86..85fe0c7175ce51fa28feebc240bf392cfe41d855 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 10: Can't find variable: appendCell
+CONSOLE MESSAGE: line 10: ReferenceError: Can't find variable: appendCell
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
 layer at (0,0) size 800x600
index 02b8a48b934a42fb30d3e7ce871c3ae55d7e1f99..0e2eb3339de67ae27c9079532f08f6670d02fb9a 100644 (file)
@@ -1,2 +1,2 @@
-CONSOLE MESSAGE: line 0: undefined
+CONSOLE MESSAGE: line 0: TransactionCallbackError
 If WebKit doesn't crash, this test has passed
index 68040639bb9760372c8f7eea92b31035160c0c55..0203efbc278c4eef7793b0588c19b7bbdd022527 100644 (file)
@@ -1,3 +1,45 @@
+2008-07-19  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Mark Rowe.
+
+        Bug 15979: Console logs in a database callback lose line number information
+        <https://bugs.webkit.org/show_bug.cgi?id=15979>
+
+        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
+
+        * bindings/js/JSCustomSQLStatementCallback.cpp:
+        (WebCore::JSCustomSQLStatementCallback::handleEvent):
+        * bindings/js/JSCustomSQLStatementErrorCallback.cpp:
+        (WebCore::JSCustomSQLStatementErrorCallback::handleEvent):
+        * bindings/js/JSCustomSQLTransactionCallback.cpp:
+        (WebCore::JSCustomSQLTransactionCallback::handleEvent):
+        * bindings/js/JSCustomSQLTransactionErrorCallback.cpp:
+        (WebCore::JSCustomSQLTransactionErrorCallback::handleEvent):
+        * bindings/js/JSCustomVoidCallback.cpp:
+        (WebCore::JSCustomVoidCallback::handleEvent):
+        * bindings/js/JSCustomXPathNSResolver.cpp:
+        (WebCore::JSCustomXPathNSResolver::lookupNamespaceURI):
+        * bindings/js/JSEventListener.cpp:
+        (WebCore::JSAbstractEventListener::handleEvent):
+        * bindings/js/ScheduledAction.cpp:
+        (WebCore::ScheduledAction::execute):
+        * bindings/js/ScriptController.cpp:
+        (WebCore::ScriptController::evaluate):
+        * bindings/objc/WebScriptObject.mm:
+        (WebCore::addExceptionToConsole):
+        * page/Console.cpp:
+        (WebCore::Console::reportException):
+        * page/Console.h:
+
 2008-07-20  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Rubber stamped by Oliver.
@@ -27,9 +69,9 @@
         * loader/TextResourceDecoder.cpp:
         (WebCore::TextResourceDecoder::checkForHeadCharset): 
 
-2008-07-19  Oliver Hunt  <oliver@apple.com>
+2008-07-20  Oliver Hunt  <oliver@apple.com>
 
-        Reviewed by NOBODY (Build fix).
+        Reviewed by NOBODY (build fix).
 
         Attempt to fix windows build
 
index cceca29cba57ac7f9f2f3edd7581503e9aa30ab9..4b34ad1e1b7643c7c3897e995eec250d30ca0f61 100644 (file)
@@ -84,15 +84,9 @@ void JSCustomSQLStatementCallback::handleEvent(SQLTransaction* transaction, SQLR
     globalObject->stopTimeoutCheck();
         
     if (exec->hadException()) {
-        JSObject* exception = exec->exception()->toObject(exec);
-        String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
-        int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
-        String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
-        m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
+        m_frame->domWindow()->console()->reportCurrentException(exec);
         
         raisedException = true;
-        
-        exec->clearException();
     }
         
     Document::updateDocumentsRendering();
index ffa7c29ce5b80b95a4806ee6f5fce35eb0f42247..4c08872ff25ae8bf408668b80c3f7f50b48a10dd 100644 (file)
@@ -90,12 +90,7 @@ bool JSCustomSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction,
     globalObject->stopTimeoutCheck();
         
     if (exec->hadException()) {
-        JSObject* exception = exec->exception()->toObject(exec);
-        String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
-        int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
-        String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
-        m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
-        exec->clearException();
+        m_frame->domWindow()->console()->reportCurrentException(exec);
             
         // The spec says:
         // "If the error callback returns false, then move on to the next statement..."
index 1d8acff0bca22ac0c4639dc98e3c7478588b975a..431df5ade06bfebb0a8a4acbc71b9bb089962dc9 100644 (file)
@@ -129,12 +129,7 @@ void JSCustomSQLTransactionCallback::handleEvent(SQLTransaction* transaction, bo
     globalObject->stopTimeoutCheck();
         
     if (exec->hadException()) {
-        JSObject* exception = exec->exception()->toObject(exec);
-        String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
-        int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
-        String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
-        m_data->frame()->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
-        exec->clearException();
+        m_data->frame()->domWindow()->console()->reportCurrentException(exec);
         
         raisedException = true;
     }
index 76e86f87a13b4e7953b6397108e8381a5aa737d6..da042ca81a5ad2cb7af990e41e9377ac73c92712 100644 (file)
@@ -82,14 +82,8 @@ bool JSCustomSQLTransactionErrorCallback::handleEvent(SQLError* error)
     result = call(exec, function, callType, callData, m_callback, args);
     globalObject->stopTimeoutCheck();
         
-    if (exec->hadException()) {
-        JSObject* exception = exec->exception()->toObject(exec);
-        String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
-        int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
-        String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
-        m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
-        exec->clearException();
-    }
+    if (exec->hadException())
+        m_frame->domWindow()->console()->reportCurrentException(exec);
         
     Document::updateDocumentsRendering();
     
index 9227e9b3a180795a200f53a2a2a0774a5af448db..d347e71f6016cd8dd51ee56453a0f3695c6d72ff 100644 (file)
@@ -81,14 +81,8 @@ void JSCustomVoidCallback::handleEvent()
     call(exec, function, callType, callData, m_callback, args);
     globalObject->stopTimeoutCheck();
         
-    if (exec->hadException()) {
-        JSObject* exception = exec->exception()->toObject(exec);
-        String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
-        int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
-        String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
-        m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
-        exec->clearException();            
-    }
+    if (exec->hadException())
+        m_frame->domWindow()->console()->reportCurrentException(exec);
         
     Document::updateDocumentsRendering();
 }
index 1bbe84f87225babdb364fd86558e64be879698a8..9f2c16eb44d794a4c2366d0f575ea5711c566873 100644 (file)
@@ -104,14 +104,9 @@ String JSCustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
     globalObject->stopTimeoutCheck();
 
     String result;
-    if (exec->hadException()) {
-        JSObject* exception = exec->exception()->toObject(exec);
-        String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
-        int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
-        String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
-        m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
-        exec->clearException();
-    } else {
+    if (exec->hadException())
+        m_frame->domWindow()->console()->reportCurrentException(exec);
+    else {
         if (!retval->isUndefinedOrNull())
             result = retval->toString(exec);
     }
index 153e8f9ed5138643940a4e8103303121128144c5..d57143da1a45b81126c05aca7ca6fdfbfbb2de01 100644 (file)
@@ -98,14 +98,9 @@ void JSAbstractEventListener::handleEvent(Event* event, bool isWindowEvent)
 
         window->setCurrentEvent(savedEvent);
 
-        if (exec->hadException()) {
-            JSObject* exception = exec->exception()->toObject(exec);
-            String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
-            int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
-            String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
-            frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
-            exec->clearException();
-        } else {
+        if (exec->hadException())
+            frame->domWindow()->console()->reportCurrentException(exec);
+        else {
             if (!retval->isUndefinedOrNull() && event->storesResultAsString())
                 event->storeResult(retval->toString(exec));
             if (m_isHTML) {
index 7642453cc1c7b2a1583bfd0dd1bf09cf228196ed..4a4104a50dd25d2db611a243045f612b5a330ab3 100644 (file)
@@ -74,13 +74,8 @@ void ScheduledAction::execute(JSDOMWindowShell* windowShell)
             window->startTimeoutCheck();
             call(exec, m_function, callType, callData, windowShell, args);
             window->stopTimeoutCheck();
-            if (exec->hadException()) {
-                JSObject* exception = exec->exception()->toObject(exec);
-                exec->clearException();
-                String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
-                int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
-                frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, String());
-            }
+            if (exec->hadException())
+                frame->domWindow()->console()->reportCurrentException(exec);
         }
     } else
         frame->loader()->executeScript(m_code);
index 6f7e1dd6e1550b137a133ad355d00ac4b61508d8..093a748ee0b45833c55042a7126315a7b29d95cc 100644 (file)
@@ -97,12 +97,8 @@ JSValue* ScriptController::evaluate(const String& sourceURL, int baseLine, const
         return comp.value();
     }
 
-    if (comp.complType() == Throw) {
-        UString errorMessage = comp.value()->toString(exec);
-        int lineNumber = comp.value()->toObject(exec)->get(exec, Identifier(exec, "line"))->toInt32(exec);
-        UString exceptionSourceURL = comp.value()->toObject(exec)->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
-        m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, exceptionSourceURL);
-    }
+    if (comp.complType() == Throw)
+        m_frame->domWindow()->console()->reportException(exec, comp.value());
 
     m_sourceURL = savedSourceURL;
     return 0;
index 17b3118bec646578fc367e6a2fe5de0b3b064fda..95000889403f1d45e35c1a4139f6ae9916eea4de 100644 (file)
@@ -89,13 +89,9 @@ id createJSWrapper(KJS::JSObject* object, PassRefPtr<KJS::Bindings::RootObject>
 static void addExceptionToConsole(ExecState* exec)
 {
     JSDOMWindow* window = asJSDOMWindow(exec->dynamicGlobalObject());
-    JSObject* exception = exec->exception()->toObject(exec);
-    if (!window || !exception)
+    if (!window || !exec->hadException())
         return;
-    String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
-    int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
-    String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
-    window->impl()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
+    window->impl()->console()->reportCurrentException(exec);
 }
 
 } // namespace WebCore
index e0985b1286258d8ccc5f610817e3b8d97b7614de..993770e7ee1f21a7e6fc7f8a1d11ed2977b50e29 100644 (file)
@@ -295,4 +295,20 @@ void Console::warn(ExecState* exec, const ArgList& arguments)
     printToStandardOut(WarningMessageLevel, exec, arguments, url);
 }
 
+void  Console::reportException(ExecState* exec, JSValue* exception)
+{
+    UString errorMessage = exception->toString(exec);
+    JSObject* exceptionObject = exception->toObject(exec);
+    int lineNumber = exceptionObject->get(exec, Identifier(exec, "line"))->toInt32(exec);
+    UString exceptionSourceURL = exceptionObject->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
+    addMessage(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, exceptionSourceURL);
+}
+
+void  Console::reportCurrentException(ExecState* exec)
+{
+    JSValue* exception = exec->exception();
+    exec->clearException();
+    reportException(exec, exception);
+}
+
 } // namespace WebCore
index 64ae4900f07362ac4bfa0338131f31aeea572943..babe622b268a36c5f370f2872b459b893dd54a91 100644 (file)
@@ -38,6 +38,7 @@ namespace KJS {
     class ExecState;
     class ArgList;
     class Profile;
+    class JSValue;
 }
 
 namespace WebCore {
@@ -79,6 +80,8 @@ namespace WebCore {
 
         void finishedProfiling(PassRefPtr<KJS::Profile>);
 
+        void reportException(KJS::ExecState*, KJS::JSValue*);
+        void reportCurrentException(KJS::ExecState*);
     private:
         Console(Frame*);