1 function stripURL(url) {
2 if (url.match(/^blob:/))
4 return url ? url.match( /[^\/]+\/?$/ )[0] : url;
7 function checkErrorEvent(errorEvent, obj) {
8 window.errorEvent = errorEvent;
9 shouldBeEqualToString('errorEvent.message', obj.message);
10 shouldBeEqualToString('stripURL(errorEvent.filename)', obj.filename);
11 shouldBe('errorEvent.lineno', '' + obj.lineno);
12 shouldBe('errorEvent.colno', '' + obj.colno);
14 // The spec says the error property for worker-generated errors is always initialized to null
15 // outside the worker: http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#runtime-script-errors-0
16 shouldBeNull('errorEvent.error');
19 function checkPostMessage(obj) {
20 window.postMessageCallback = function (e) {
23 debug("\nWorker-level onerror handler triggered:");
24 checkErrorEvent(e.data, obj);
29 function checkErrorEventInHandler(error, returnValue) {
30 var worker = buildInlineWorker();
31 worker.onerror = function (e) {
32 debug("\nPage-level worker.onerror handler triggered:");
33 window.errorEvent = e;
36 obj = error[errorsSeen++];
38 checkErrorEvent(e, obj);
40 if (!error.length || error.length == errorsSeen)
47 function checkErrorEventInListener(error, preventDefault) {
48 var worker = buildInlineWorker();
49 worker.addEventListener('error', function (e) {
50 debug("\nPage-level worker 'error' event listener triggered:");
53 obj = error[errorsSeen++];
55 checkErrorEvent(e, obj);
57 if (!error.length || error.length == errorsSeen)
65 function errorEventHandlerShouldNotFire() {
66 var worker = buildInlineWorker();
67 worker.onerror = function (e) {
68 testFailed("'worker.onerror' should not have been called.");
72 function buildInlineWorker() {
73 var script = document.getElementById('workerCode').innerText;
74 var blob = new Blob([script], {type: 'text/javascript'});
75 var worker = new Worker(URL.createObjectURL(blob));
77 if (window.postMessageCallback)
78 worker.addEventListener('message', postMessageCallback);
79 worker.addEventListener('message', function (e) {
81 return finishJSTest();
87 window.jsTestIsAsync = true;