6 <p>Test that window.onerror and
"error" event listeners from isolated world are
7 invoked for uncaught exceptions in scripts running in isolate worlds as
8 well as for exceptions in the main world.
<a href=
"https://bugs.webkit.org/show_bug.cgi?id=8519">Bug
8519.
</a>
10 <pre id=
"console"></pre>
12 var expectedRecordCount
= 10;
14 document
.getElementById("console").addEventListener("DOMNodeInserted", function(e
) {
15 if (++recordCount
=== expectedRecordCount
&& window
.testRunner
)
16 testRunner
.notifyDone();
20 var throwExceptions = function(isolatedWorld
)
22 window
.addEventListener("load", function(e
) {
23 // Do the following call from load listener to make sure error in the setTimeout callback always happens after the error in this listener.
24 setTimeout(function() {
25 throw new Error("Error in " + isolatedWorld
+ " setTimeout callback.");
27 throw new Error("Error in " + isolatedWorld
+ " load handler.");
30 throw new Error("Error in "+ isolatedWorld
+ " inline script.");
33 var errorHandlers = function(isolatedWorld
)
35 function lastUrlComponent(url
) {
36 return url
? url
.match( /[^\/]+\/?$/ )[0] : url
;
40 var record
= document
.createElement("div");
41 record
.innerHTML
= msg
;
42 document
.getElementById("console").appendChild(record
);
45 window
.onerror = function(msg
, url
, line
, column
, error
) {
46 log(isolatedWorld
+ " window.onerror: " + msg
+ " at " + lastUrlComponent(url
) + ", Line: " + line
+ ", Column: " + column
, "*");
48 log("Error object present!");
50 log("No error object present!");
54 window
.addEventListener("error", function(e
) {
55 var url
= lastUrlComponent(e
.filename
);
56 log(isolatedWorld
+ " error event listener: " + e
.message
+ " at " + url
+ ":, Line: " + e
.lineno
, "*");
58 log("Error object present!");
60 log("No error object present!");
65 if (window
.testRunner
) {
66 testRunner
.dumpAsText();
67 testRunner
.waitUntilDone();
68 testRunner
.evaluateScriptInIsolatedWorld(1, "(" + errorHandlers
+ ")('isolated world'); (" + throwExceptions
+ ")('isolated world')");
71 throwExceptions("main world");