11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<meta charset="UTF-8">
31cb0ef41Sopenharmony_ci<title>Throwing in event listeners</title>
41cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script>
51cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script>
61cb0ef41Sopenharmony_ci<div id="log"></div>
71cb0ef41Sopenharmony_ci<script>
81cb0ef41Sopenharmony_cisetup({allow_uncaught_exception:true})
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_citest(function() {
111cb0ef41Sopenharmony_ci    var errorEvents = 0;
121cb0ef41Sopenharmony_ci    window.onerror = this.step_func(function(e) {
131cb0ef41Sopenharmony_ci        assert_equals(typeof e, 'string');
141cb0ef41Sopenharmony_ci        ++errorEvents;
151cb0ef41Sopenharmony_ci    });
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci    var element = document.createElement('div');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci    element.addEventListener('click', function() {
201cb0ef41Sopenharmony_ci        throw new Error('Error from only listener');
211cb0ef41Sopenharmony_ci    });
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci    element.dispatchEvent(new Event('click'));
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci    assert_equals(errorEvents, 1);
261cb0ef41Sopenharmony_ci}, "Throwing in event listener with a single listeners");
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_citest(function() {
291cb0ef41Sopenharmony_ci    var errorEvents = 0;
301cb0ef41Sopenharmony_ci    window.onerror = this.step_func(function(e) {
311cb0ef41Sopenharmony_ci        assert_equals(typeof e, 'string');
321cb0ef41Sopenharmony_ci        ++errorEvents;
331cb0ef41Sopenharmony_ci    });
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci    var element = document.createElement('div');
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci    var secondCalled = false;
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci    element.addEventListener('click', function() {
401cb0ef41Sopenharmony_ci        throw new Error('Error from first listener');
411cb0ef41Sopenharmony_ci    });
421cb0ef41Sopenharmony_ci    element.addEventListener('click', this.step_func(function() {
431cb0ef41Sopenharmony_ci        secondCalled = true;
441cb0ef41Sopenharmony_ci    }), false);
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci    element.dispatchEvent(new Event('click'));
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci    assert_equals(errorEvents, 1);
491cb0ef41Sopenharmony_ci    assert_true(secondCalled);
501cb0ef41Sopenharmony_ci}, "Throwing in event listener with multiple listeners");
511cb0ef41Sopenharmony_ci</script>
52