Throwing an error in an event listener

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 UTC