Re: Exceptions in event listeners triggered by dispatchEvent().

"Simon Pieters" <[email protected]>
Newsgroups gmane.comp.web.dom.general
Message-ID <[email protected]>
On Wed, 05 Jun 2013 16:19:48 +0200, Glenn Maynard <[email protected]> wrote:

>> No. window.onerror is invoked directly without an event. ErrorEvent is  
>> for
>> the case when an uncaught error is fired on a Worker object (if the  
>> error
>> wasn't handled in the worker itself).
>>
>
> Nope.  In Chrome and IE10, ErrorEvent is used for uncaught exceptions in
> the UI thread too, for the "error" event fired on window.  Firefox also
> fires "error" event listeners (not just the event handler), but doesn't  
> yet
> use ErrorEvent there.

Well then those browsers violate the spec and the original  
implementation... At least Presto implements the spec.

> (The spec looks incorrect here.  It bypasses event dispatch entirely and
> calls "onerror" directly, which forgets to fire event listeners.  It also
> doesn't make much sense to support error handling with event listeners in
> workers but not in the UI thread.  This should probably just fire an
> ErrorEvent, and the window.onerror special case should probably be in the
> event dispatch algorithm.)

You misunderstood the worker case. Errors in workers are handled the same  
as in window, i.e. onerror is invoked directly. However, if a worker error  
is not "handled", an ErrorEvent gets fired on the Worker object.

> If you want to catch an exception and have it behave as though the error
> was uncaught and gets sent to onerror, you need to make sure "error" is
> dispatched to event listeners.  If you simply call window.onerror  
> directly,
> event listeners won't be called.
>
> This works in Chrome, including calling the onerror event handler called
> with its special-cased arguments:
> http://zewt.org/~glenn/test-error-handler.html.  Firefox doesn't handle
> this yet, so you end up with the event handler called with incorrect
> arguments.  (IE10 doesn't seem to have any way to create an ErrorEvent
> object yet; the interface exists but isn't a constructor.)  I'll file a  
> bug
> on HTML.

-- 
Simon Pieters
Opera Software
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.