Commit c8a06eb9 authored by yurys@chromium.org's avatar yurys@chromium.org
Browse files

2010-12-27 yury semikhatsky <yurys@chromium.org>

        reviewed by pavel feldman.

        webcore doesn't fire window.onerror event when uncaught javascript exceptions are thrown
        https://bugs.webkit.org/show_bug.cgi?id=8519

        uncaught exceptions are propagated to window.onerror hander if one is present.
        the handler is expected to be a function accepting three arguments: error message,
        resource url and line number where the exception occured.

        it was decided to dispatch errorevent to all listeners/handlers no matter if they
        were created in the same isolated world where the exception occured or not.

        tests: fast/events/window-onerror1.html
               fast/events/window-onerror10.html
               fast/events/window-onerror11.html
               fast/events/window-onerror12.html
               fast/events/window-onerror2.html
               fast/events/window-onerror3.html
               fast/events/window-onerror4.html
               fast/events/window-onerror5.html
               fast/events/window-onerror6.html
               fast/events/window-onerror7.html
               fast/events/window-onerror8.html
               fast/events/window-onerror9.html
               http/tests/security/window-onerror-exception-in-iframe.html
               userscripts/window-onerror-for-isolated-world-1.html
               userscripts/window-onerror-for-isolated-world-2.html

        * android.jscbindings.mk:
        * cmakelists.txt:
        * gnumakefile.am:
        * webcore.gypi:
        * webcore.order:
        * webcore.pro:
        * webcore.vcproj/webcore.vcproj:
        * webcore.xcodeproj/project.pbxproj:
        * bindings/js/jsbindingsallinone.cpp:
        * bindings/js/jsdombinding.cpp:
        (webcore::reportexception):
        * bindings/js/jserrorhandler.cpp: renamed from webcore/bindings/js/jsworkercontexterrorhandler.cpp.
        (webcore::jserrorhandler::jserrorhandler):
        (webcore::jserrorhandler::~jserrorhandler):
        (webcore::jserrorhandler::handleevent):
        * bindings/js/jserrorhandler.h: copied from webcore/bindings/js/jsworkercontexterrorhandler.h.
        (webcore::jserrorhandler::create):
        (webcore::createjserrorhandler):
        * bindings/js/jseventlistener.h:
        * bindings/scripts/codegeneratorjs.pm:
        * bindings/scripts/codegeneratorv8.pm:
        * bindings/v8/v8consolemessage.cpp:
        (webcore::v8consolemessage::dispatchnow):
        (webcore::v8consolemessage::handler): the method was changed to use generic webcore exception
        reporting mechanism which is also used by jsc bindings.
        * bindings/v8/v8consolemessage.h:
        * bindings/v8/v8eventlistener.h:
        * bindings/v8/v8windowerrorhandler.cpp: renamed from webcore/bindings/js/jsworkercontexterrorhandler.h.
        (webcore::v8windowerrorhandler::v8windowerrorhandler):
        (webcore::v8windowerrorhandler::calllistenerfunction):
        * bindings/v8/v8windowerrorhandler.h: copied from webcore/dom/errorevent.cpp.
        (webcore::v8windowerrorhandler::create):
        * bindings/v8/workercontextexecutionproxy.cpp:
        (webcore::v8messagehandler):
        * bindings/v8/workerscriptcontroller.cpp:
        (webcore::workerscriptcontroller::evaluate):
        * dom/document.cpp:
        (webcore::document::erroreventtarget):
        (webcore::document::logexceptiontoconsole):
        (webcore::document::addmessage):
        * dom/document.h:
        * dom/errorevent.cpp:
        * dom/errorevent.h:
        * dom/event.cpp:
        (webcore::event::iserrorevent):
        * dom/event.h:
        * dom/scriptexecutioncontext.cpp:
        (webcore::scriptexecutioncontext::pendingexception::pendingexception):
        (webcore::scriptexecutioncontext::scriptexecutioncontext):
        (webcore::scriptexecutioncontext::reportexception): this method is not virtual anymore to
        ensure that error event dispatching algorithm is the same in workercontext and in document.
        (webcore::scriptexecutioncontext::dispatcherrorevent):
        * dom/scriptexecutioncontext.h:
        * websockets/websocket.cpp:
        (webcore::websocket::connect):
        * websockets/websocketchannel.cpp:
        (webcore::websocketchannel::didopen):
        (webcore::websocketchannel::didfail):
        (webcore::websocketchannel::appendtobuffer):
        * websockets/websockethandshake.cpp:
        (webcore::websockethandshake::readserverhandshake):
        (webcore::websockethandshake::readstatusline):
        (webcore::websockethandshake::readhttpheaders):
        (webcore::websockethandshake::checkresponseheaders):
        * workers/defaultsharedworkerrepository.cpp:
        (webcore::postexceptiontask):
        (webcore::postconsolemessagetask):
        * workers/workercontext.cpp:
        (webcore::workercontext::workercontext):
        (webcore::workercontext::erroreventtarget):
        (webcore::workercontext::logexceptiontoconsole):
        (webcore::workercontext::addmessage):
        * workers/workercontext.h:
        * workers/workermessagingproxy.cpp:
        (webcore::workerexceptiontask::performtask):
        (webcore::postconsolemessagetask):
        * xml/xmlhttprequest.cpp:
        (webcore::reportunsafeusage):

2010-12-27  Yury Semikhatsky  <yurys@chromium.org>

        Reviewed by Pavel Feldman.

        WebCore doesn't fire window.onerror event when uncaught JavaScript exceptions are thrown
        https://bugs.webkit.org/show_bug.cgi?id=8519

        Uncaught exceptions are propagated to window.onerror hander if one is present.
        The handler is expected to be a function accepting three arguments: error message,
        resource url and line number where the exception occured.

        * fast/events/resources/window-onerror.js: Added.
        (throwException):
        * fast/events/window-onerror1-expected.txt: Added.
        * fast/events/window-onerror1.html: Added.
        * fast/events/window-onerror10-expected.txt: Added.
        * fast/events/window-onerror10.html: Added.
        * fast/events/window-onerror11-expected.txt: Added.
        * fast/events/window-onerror11.html: Added.
        * fast/events/window-onerror12-expected.txt: Added.
        * fast/events/window-onerror12.html: Added.
        * fast/events/window-onerror2-expected.txt: Added.
        * fast/events/window-onerror2.html: Added.
        * fast/events/window-onerror3-expected.txt: Added.
        * fast/events/window-onerror3.html: Added.
        * fast/events/window-onerror4-expected.txt: Added.
        * fast/events/window-onerror4.html: Added.
        * fast/events/window-onerror5-expected.txt: Added.
        * fast/events/window-onerror5.html: Added.
        * fast/events/window-onerror6-expected.txt: Added.
        * fast/events/window-onerror6.html: Added.
        * fast/events/window-onerror7-expected.txt: Added.
        * fast/events/window-onerror7.html: Added.
        * fast/events/window-onerror8-expected.txt: Added.
        * fast/events/window-onerror8.html: Added.
        * fast/events/window-onerror9-expected.txt: Added.
        * fast/events/window-onerror9.html: Added.
        * fast/workers/worker-script-error-expected.txt:
        * http/tests/security/resources/onerror-iframe.html: Added.
        * http/tests/security/window-onerror-exception-in-iframe-expected.txt: Added.
        * http/tests/security/window-onerror-exception-in-iframe.html: Added.
        * platform/chromium-win/fast/workers/worker-script-error-expected.txt:
        * platform/chromium/fast/events/window-onerror1-expected.txt: Added.
        * platform/chromium/fast/events/window-onerror10-expected.txt: Added.
        * platform/chromium/fast/events/window-onerror11-expected.txt: Added.
        * platform/chromium/fast/events/window-onerror2-expected.txt: Added.
        * platform/chromium/fast/events/window-onerror3-expected.txt: Added.
        * platform/chromium/fast/events/window-onerror4-expected.txt: Added.
        * platform/chromium/fast/events/window-onerror5-expected.txt: Added.
        * platform/chromium/fast/events/window-onerror6-expected.txt: Added.
        * platform/chromium/fast/events/window-onerror7-expected.txt: Added.
        * platform/chromium/fast/events/window-onerror8-expected.txt: Added.
        * platform/chromium/fast/events/window-onerror9-expected.txt: Added.
        * platform/chromium/http/tests/security/window-onerror-exception-in-iframe-expected.txt: Added.
        * platform/chromium/userscripts/window-onerror-for-isolated-world-1-expected.txt: Added.
        * platform/chromium/userscripts/window-onerror-for-isolated-world-2-expected.txt: Added.
        * platform/gtk/Skipped:
        * userscripts/window-onerror-for-isolated-world-1-expected.txt: Added.
        * userscripts/window-onerror-for-isolated-world-1.html: Added.
        * userscripts/window-onerror-for-isolated-world-2-expected.txt: Added.
        * userscripts/window-onerror-for-isolated-world-2.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76216 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 94c27d14
2010-12-27 Yury Semikhatsky <yurys@chromium.org>
Reviewed by Pavel Feldman.
WebCore doesn't fire window.onerror event when uncaught JavaScript exceptions are thrown
https://bugs.webkit.org/show_bug.cgi?id=8519
Uncaught exceptions are propagated to window.onerror hander if one is present.
The handler is expected to be a function accepting three arguments: error message,
resource url and line number where the exception occured.
* fast/events/resources/window-onerror.js: Added.
(throwException):
* fast/events/window-onerror1-expected.txt: Added.
* fast/events/window-onerror1.html: Added.
* fast/events/window-onerror10-expected.txt: Added.
* fast/events/window-onerror10.html: Added.
* fast/events/window-onerror11-expected.txt: Added.
* fast/events/window-onerror11.html: Added.
* fast/events/window-onerror12-expected.txt: Added.
* fast/events/window-onerror12.html: Added.
* fast/events/window-onerror2-expected.txt: Added.
* fast/events/window-onerror2.html: Added.
* fast/events/window-onerror3-expected.txt: Added.
* fast/events/window-onerror3.html: Added.
* fast/events/window-onerror4-expected.txt: Added.
* fast/events/window-onerror4.html: Added.
* fast/events/window-onerror5-expected.txt: Added.
* fast/events/window-onerror5.html: Added.
* fast/events/window-onerror6-expected.txt: Added.
* fast/events/window-onerror6.html: Added.
* fast/events/window-onerror7-expected.txt: Added.
* fast/events/window-onerror7.html: Added.
* fast/events/window-onerror8-expected.txt: Added.
* fast/events/window-onerror8.html: Added.
* fast/events/window-onerror9-expected.txt: Added.
* fast/events/window-onerror9.html: Added.
* fast/workers/worker-script-error-expected.txt:
* http/tests/security/resources/onerror-iframe.html: Added.
* http/tests/security/window-onerror-exception-in-iframe-expected.txt: Added.
* http/tests/security/window-onerror-exception-in-iframe.html: Added.
* platform/chromium-win/fast/workers/worker-script-error-expected.txt:
* platform/chromium/fast/events/window-onerror1-expected.txt: Added.
* platform/chromium/fast/events/window-onerror10-expected.txt: Added.
* platform/chromium/fast/events/window-onerror11-expected.txt: Added.
* platform/chromium/fast/events/window-onerror2-expected.txt: Added.
* platform/chromium/fast/events/window-onerror3-expected.txt: Added.
* platform/chromium/fast/events/window-onerror4-expected.txt: Added.
* platform/chromium/fast/events/window-onerror5-expected.txt: Added.
* platform/chromium/fast/events/window-onerror6-expected.txt: Added.
* platform/chromium/fast/events/window-onerror7-expected.txt: Added.
* platform/chromium/fast/events/window-onerror8-expected.txt: Added.
* platform/chromium/fast/events/window-onerror9-expected.txt: Added.
* platform/chromium/http/tests/security/window-onerror-exception-in-iframe-expected.txt: Added.
* platform/chromium/userscripts/window-onerror-for-isolated-world-1-expected.txt: Added.
* platform/chromium/userscripts/window-onerror-for-isolated-world-2-expected.txt: Added.
* platform/gtk/Skipped:
* userscripts/window-onerror-for-isolated-world-1-expected.txt: Added.
* userscripts/window-onerror-for-isolated-world-1.html: Added.
* userscripts/window-onerror-for-isolated-world-2-expected.txt: Added.
* userscripts/window-onerror-for-isolated-world-2.html: Added.
2011-01-19 MORITA Hajime <morrita@google.com>
 
Reviewed by Ryosuke Niwa.
......
function throwException() {
throw new Error("An exception");
}
This page tests setting onerror handlers through the DOM. If it passes, you will see "PASS" messages below.Bug 8519.
PASS: caught global error: ReferenceError: Can't find variable: hahaha_good_luck_finding_me at window-onerror1.html:25
<html>
<head>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
function print(message, color)
{
var paragraph = document.createElement("div");
paragraph.appendChild(document.createTextNode(message));
paragraph.style.fontFamily = "monospace";
if (color)
paragraph.style.color = color;
document.getElementById("console").appendChild(paragraph);
}
function test()
{
// must be last because the exception ends JavaScript execution
window.onerror = function (error, url, line) {
url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
print("PASS: caught global error: " + error + " at " + url + ":" + line, "green");
return false;
};
hahaha_good_luck_finding_me(); // caught by window.onerror
}
</script>
</head>
<body onload="test();">
<p>This page tests setting onerror handlers through the DOM. If it passes, you will
see "PASS" messages below.<a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
<hr>
<div id='console'></div>
</body>
</html>
Test that "error" event listener added with window.addEventListener is invoked for uncaucht exceptions. Bug 8519.
event passed to the listener is the same as window.event: true
Event details:
type: error
phase: 2
currentTarget is the global object: true
message: Error: My fault.
filename: window-onerror10.html
lineno: 29
<html>
<body>
<p>Test that "error" event listener added with window.addEventListener is invoked for uncaucht exceptions. <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
<div id="console"></div>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
function log(msg) {
document.getElementById("console").innerHTML += msg + "<br>";
}
function lastPathComponent(url) {
return url ? url.match( /[^\/]+\/?$/ )[0] : url;
}
window.addEventListener("error", function(e) {
log("event passed to the listener is the same as window.event: " + (window.event === e));
log("Event details:");
log("type: " + e.type);
log("phase: " + e.eventPhase)
log("currentTarget is the global object: " + (e.currentTarget === window));
log("message: " + e.message);
log("filename: " + lastPathComponent(e.filename));
log("lineno: " + e.lineno);
e.preventDefault();
}, false);
throw new Error("My fault.");
</script>
</body>
</html>
Test that window.onerror is called on window object. Bug 8519.
Main frame window.onerror: Error: An exception at window-onerror.js:2
<html>
<head>
<script src="resources/window-onerror.js">
</script>
</head>
<body>
<p>Test that window.onerror is called on window object. <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
<div id="console"></div>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
function log(msg) {
document.getElementById("console").innerHTML += msg + "<br>";
}
window.onerror = function(msg, url, line)
{
url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
return false;
}
throwException();
</script>
</body>
</html>
Test that window.onerror is called on window object for events created using document.createEvent("error"). Bug 8519.
Main frame window.onerror:
msg: [object Event]
url: undefined
line: undefined
DONE.
<html>
<head>
<script src="resources/window-onerror.js">
</script>
</head>
<body>
<p>Test that window.onerror is called on window object for events created using document.createEvent("error"). <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
<div id="console"></div>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
function log(msg) {
document.getElementById("console").innerHTML += msg + "<br>";
}
window.onerror = function(msg, url, line)
{
log("Main frame window.onerror: ");
log("msg: " + msg);
log("url: " + url);
log("line: " + line);
return false;
}
var evt = document.createEvent("Event");
evt.initEvent("error", true, true);
window.dispatchEvent(evt);
log("DONE.");
</script>
</body>
</html>
Test that uncaught exceptions will be reported to the window.onerror handler. Bug 8519.
Main frame window.onerror: Error: Inline script exception at window-onerror2.html:35
Main frame window.onerror: Exception in onload at undefined:0
Main frame window.onerror: Error: Exception in setTimeout at window-onerror2.html:29
<html>
<body onload="throw 'Exception in onload';">
<p>Test that uncaught exceptions will be reported to the window.onerror handler. <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
<div id="result"></div>
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
function log(msg) {
document.getElementById("result").innerHTML += msg + "<br>";
}
var unhandledErrorCount = 0;
window.onerror = function(msg, url, line)
{
url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
if (++unhandledErrorCount === 3 && window.layoutTestController)
layoutTestController.notifyDone();
return false;
}
function delayedThrowException()
{
throw new Error("Exception in setTimeout");
}
setTimeout(delayedThrowException, 0);
function throwException()
{
throw new Error("Inline script exception");
}
throwException();
</script>
</body>
</html>
You should see a message if window.onerror is working properly for this test.Bug 8519.
Error caught successfully: ReferenceError: Can't find variable: unknownObject File: window-onerror3.html Line: 16
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
function log(msg) {
document.getElementById("console").innerHTML += msg + "<br>";
}
function test1()
{
window.onerror = function (error, url, line) {
url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
log("Error caught successfully: " + error + "\nFile: " + url + "\nLine: " + line)
return false;
};
unknownObject.unknownProperty++;
}
</script>
<body onload="test1();">
<p>You should see a message if window.onerror is working properly for this test.<a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
<hr>
<div id='console'></div>
</body>
You should see a log record if window.onerror is working properly for this test.Bug 8519.
Error caught successfully: ReferenceError: Left side of assignment is not a reference. File: undefined Line: 1
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
function log(msg) {
document.getElementById("console").innerHTML += msg + "<br>";
}
function test1()
{
window.onerror = function (error, url, line) {
url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
log("Error caught successfully: " + error + "\nFile: " + url + "\nLine: " + line)
return false;
};
eval("1=2");
}
</script>
<body onload="test1();">
<p>You should see a log record if window.onerror is working properly for this test.<a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
<hr>
<div id='console'></div>
</body>
Test that window.onerror is invoked for syntax error in eval. You should see a log record if window.onerror is working properly for this test.Bug 8519.
Error caught successfully: SyntaxError: Parse error File: undefined Line: 1
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
function log(msg) {
document.getElementById("console").innerHTML += msg + "<br>";
}
function test1()
{
window.onerror = function (error, url, line) {
url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
log("Error caught successfully: " + error + "\nFile: " + url + "\nLine: " + line)
return false;
};
eval("a(");
}
</script>
<body onload="test1();">
<p>Test that window.onerror is invoked for syntax error in eval. You should see a log record if window.onerror is working properly for this test.<a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
<hr>
<div id='console'></div>
</body>
Test that syntax error will be reported to the window.onerror handler. Bug 8519.
Main frame window.onerror: SyntaxError: Parse error at window-onerror6.html:22
<html>
<body>
<p>Test that syntax error will be reported to the window.onerror handler. <a href="https://bugs.webkit.org/show_bug.cgi?id=8519">Bug 8519</a>.</p>
<div id="console"></div>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
function log(msg) {
document.getElementById("console").innerHTML += msg + "<br>";
}
window.onerror = function(msg, url, line)
{
url = url ? url.match( /[^\/]+\/?$/ )[0] : url;
log("Main frame window.onerror: " + msg + " at " + url + ":" + line);
return false;
}
</script>
<script>
a) // syntax error
</script>
</body>
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment