W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2012

Throwing an error in an event listener

From: David Bruant <bruant.d@gmail.com>
Date: Sat, 27 Oct 2012 16:13:42 +0200
Message-ID: <CAHbscB2yZY4a1Js1R+_p88s0VXGEeK35Zgg6Sf8VAOgp37+r0A@mail.gmail.com>
To: www-dom@w3.org
Hi,

Live from Test the web forward in Paris. Here is a test case I've just
written (don't bother):

        var element = document.getElementById('bim');
        var secondCalled = false;

        element.addEventListener('click', function(){
            throw new Error('Error from listener');
        });
        element.addEventListener('click', function(){ secondCalled = true;
}, false);
        element.click();

        assert_true(secondCalled);

It's unclear what's the expected behavior in the spec.
The dispatch algorithm says:
(Step 8) Invoke the event listeners of event's target attribute value with
event
Then, the invoke algorithm says:
(Step 4.7) Call listener's callback, with the event passed to this
algorithm as the first argument.

But nothing is said about what happens if during this call an error is
thrown. In browsers I have tested (Firefox 18, Opera 12, latest Chrome),
the error is absorbed and the next listener is called (so the test
succeeds).
I think the invoke algorithm should make a mention of that somewhere.

David
Received on Saturday, 27 October 2012 14:14:09 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 27 October 2012 14:14:11 GMT