This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 22310 - onerror handling calls onerror directly, without firing the "error" ErrorEvent
Summary: onerror handling calls onerror directly, without firing the "error" ErrorEvent
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-07 13:59 UTC by Glenn Maynard
Modified: 2013-06-21 18:04 UTC (History)
2 users (show)

See Also:


Attachments

Description Glenn Maynard 2013-06-07 13:59:00 UTC
On non-worker errors, the spec calls window.onerror directly without firing an "error" ErrorEvent, so listeners for the "error" event aren't called.  This doesn't match browsers.

Chrome fires error events with an ErrorEvent; the message, filename and lineno fields are set.
IE10 fires error events with an Error; the message, filename and lineno fields are set, so this is just an ErrorEvent without the interface.
Firefox fires error events with an Error.  The error fields aren't populated in this browser.
Opera is the only browser that doesn't fire the error event at all.

I'd recommend simply firing an error event normally, with an ErrorEvent object, and let window.onerror be called like any other event handler.  The special case of onerror's arguments (msg, file, line rather than the event object) should be handled at the place event handlers are invoked.

This would also mean that firing an error event manually with dispatchEvent would call window.onerror with the special arguments instead of the event.  That seems correct, so user error events work.  Currently, it's hard or impossible to do this in script (eg. catch an exception and fire it as an error event).

Chrome (other WebKits untested) implements this already: http://zewt.org/~glenn/test-error-handler.html.  It only happens if the event is an ErrorEvent.  This change should also be compatible with IE10 and Firefox, simply because there seems to be no way to get an ErrorEvent in the UI thread on those browsers in the first place, so there's no code to break.  (IE10 has ErrorEvent but constructing it doesn't work.  Firefox doesn't appear to have ErrorEvent yet.)
Comment 1 Ian 'Hixie' Hickson 2013-06-13 22:56:01 UTC
This should be doable. Basically move the onerror magic into the event handler part of the spec, and define "report an error" based on a global scope object rather than the onerror handler itself, and based on firing an event and the event's cancelation rather than on the nitty gritty of onerror like now.

Any reason we shouldn't do this for Workers too, other than churn?
Comment 2 Glenn Maynard 2013-06-13 23:12:19 UTC
Not that I can think of, but I only looked closely at the non-worker case.  It would be nice if they were consistent, of course.
Comment 3 Ian 'Hixie' Hickson 2013-06-21 18:04:38 UTC
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2355
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2356


Ok. This is really invasive and dangerous, so let me know if I broke anything.
Comment 4 contributor 2013-06-21 18:04:46 UTC
Checked in as WHATWG revision r7995.
Check-in comment: Revamp how errors are reported to be a little more sane and hopefully slightly closer to more browsers (but there's not a huge amount of interop here and so this won't exactly match anything). This is a very risky change so let me know if anything broke.
http://html5.org/tools/web-apps-tracker?from=7994&to=7995