Skip to content

Commit

Permalink
fix: Don't copy deprecated Event.path (#7782)
Browse files Browse the repository at this point in the history
  • Loading branch information
mister-ben authored May 31, 2022
1 parent a14ace2 commit 27f22ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/js/utils/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
18 changes: 18 additions & 0 deletions test/unit/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
});
});

0 comments on commit 27f22ef

Please sign in to comment.