From 27f22efe6bca4384c34386c01bc6d3fa6a0e9989 Mon Sep 17 00:00:00 2001 From: mister-ben Date: Tue, 31 May 2022 21:51:12 +0200 Subject: [PATCH] fix: Don't copy deprecated Event.path (#7782) --- src/js/utils/events.js | 4 +++- test/unit/events.test.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/js/utils/events.js b/src/js/utils/events.js index 3473f5382..36afd652d 100644 --- a/src/js/utils/events.js +++ b/src/js/utils/events.js @@ -117,8 +117,10 @@ export function fixEvent(event) { // Safari 6.0.3 warns you if you try to copy deprecated layerX/Y // Chrome warns you if you try to copy deprecated keyboardEvent.keyLocation // and webkitMovementX/Y + // Lighthouse complains if Event.path is copied if (key !== 'layerX' && key !== 'layerY' && key !== 'keyLocation' && - key !== 'webkitMovementX' && key !== 'webkitMovementY') { + key !== 'webkitMovementX' && key !== 'webkitMovementY' && + key !== 'path') { // Chrome 32+ warns if you try to copy deprecated returnValue, but // we still want to if preventDefault isn't supported (IE8). if (!(key === 'returnValue' && old.preventDefault)) { diff --git a/test/unit/events.test.js b/test/unit/events.test.js index bc0cde5ef..74832b8b9 100644 --- a/test/unit/events.test.js +++ b/test/unit/events.test.js @@ -383,3 +383,21 @@ QUnit.test('only the first event should call listener via any', function(assert) Events.trigger(el, 'event2'); assert.equal(triggered, 1, 'listener was not triggered again'); }); + +QUnit.test('fixEvent should not copy excluded properties', function(assert) { + const event = Events.fixEvent({ + a: 'a', + layerX: 0, + layerY: 0, + keyLocation: 0, + webkitMovementX: 0, + webkitMovementY: 0, + path: 0 + }); + + assert.true(event.fixed_, 'event is a fixed event'); + assert.strictEqual(event.a, 'a', 'other props copied'); + ['layerX', 'layerY', 'keyLocation', 'webkitMovementX', 'webkitMovementY', 'path'].forEach(prop => { + assert.equal(event[prop], undefined, `${prop} is undefined`); + }); +});