002.js (1255B)
1 var port; 2 var timeout; 3 addEventListener('error', function(e) { 4 // event is not canceled, thus the error is "not handled" 5 // so error should be reported to the user, but this test doesn't check 6 // that. 7 // just make sure that this event has the right properties 8 clearTimeout(timeout); 9 var log = ''; 10 if (!self.ErrorEvent || Object.getPrototypeOf(e) != ErrorEvent.prototype) 11 log += 'event should be an ErrorEvent. '; 12 if (e.bubbles) 13 log += 'event should not bubble. '; 14 if (!e.cancelable) 15 log += 'event should be cancelable. '; 16 if (!e.isTrusted) 17 log += 'event should be trusted. '; 18 if (typeof e.message != 'string') 19 log += 'message wasn\'t a string. '; 20 if (e.filename != location.href) 21 log += 'filename was ' + e.filename + ', expected ' + location.href + '. '; 22 if (typeof e.lineno != 'number') 23 log += 'lineno wasn\'t a number. '; 24 if (typeof e.colno != 'number') 25 log += 'colno argument wasn\'t a number. '; 26 if (e.error != 42) 27 log += 'fifth argument wasn\'t the thrown exception. '; 28 port.postMessage(log); 29 }, false); 30 onconnect = function (e) { 31 port = e.ports[0]; 32 timeout = setTimeout(function() { port.postMessage('No error event fired'); }, 250); 33 throw 42; // will "report the error" 34 }