diff --git a/src/diff/props.js b/src/diff/props.js index 8d1b5d165d..c65c5783ac 100644 --- a/src/diff/props.js +++ b/src/diff/props.js @@ -150,9 +150,13 @@ export function setProperty(dom, name, value, oldValue, isSvg) { * @private */ function eventProxy(e) { - this._listeners[e.type + false](options.event ? options.event(e) : e); + if (this._listeners && this._listeners[e.type + false]) { + this._listeners[e.type + false](options.event ? options.event(e) : e); + } } function eventProxyCapture(e) { - this._listeners[e.type + true](options.event ? options.event(e) : e); + if (this._listeners && this._listeners[e.type + true]) { + this._listeners[e.type + true](options.event ? options.event(e) : e); + } } diff --git a/test/browser/events.test.js b/test/browser/events.test.js index 2e43cba73a..b893118747 100644 --- a/test/browser/events.test.js +++ b/test/browser/events.test.js @@ -152,6 +152,19 @@ describe('event handling', () => { ); }); + it('should not throw an exception if the listeners array is cleared', () => { + render( +
{}}> +
, + scratch + ); + + let root = scratch.firstChild; + root._listeners = undefined; + root.firstElementChild.click(); + }); + // Skip test if browser doesn't support passive events if (supportsPassiveEvents()) { it('should use capturing for event props ending with *Capture', () => { @@ -198,5 +211,18 @@ describe('event handling', () => { expect(clickCapture, 'click').to.have.been.calledOnce; expect(click, 'click').to.have.been.calledOnce; }); + + it('should not throw an exception if the listeners array is cleared on capture event', () => { + render( +
{}}> +
, + scratch + ); + + let root = scratch.firstChild; + root._listeners = undefined; + root.firstElementChild.click(); + }); } });