Skip to content

Commit

Permalink
fix(color-contrast): support IE extension context (#2008)
Browse files Browse the repository at this point in the history
msElementsFromPoint in IE extensions can return null instead of
an empty array.
  • Loading branch information
WilcoFiers committed Feb 3, 2020
1 parent b406b1f commit 62e31ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/commons/dom/shadow-elements-from-point.js
Expand Up @@ -14,7 +14,8 @@ dom.shadowElementsFromPoint = function(nodeX, nodeY, root = document, i = 0) {
throw new Error('Infinite loop detected');
}
return (
Array.from(root.elementsFromPoint(nodeX, nodeY))
// IE can return null when there are no elements
Array.from(root.elementsFromPoint(nodeX, nodeY) || [])
// As of Chrome 66, elementFromPoint will return elements from parent trees.
// We only want to touch each tree once, so we're filtering out nodes on other trees.
.filter(nodes => dom.getRootNode(nodes) === root)
Expand Down
13 changes: 13 additions & 0 deletions test/commons/dom/shadow-elements-from-point.js
Expand Up @@ -44,4 +44,17 @@ describe('dom.shadowElementsFromPoint', function() {
assert.notInclude(result2, shadowSpan);
}
);

it('does not throw when elementsFromPoints returns null', function() {
var mockDocument = {
elementsFromPoint: function() {
return null;
}
};
var out;
assert.doesNotThrow(function() {
out = axe.commons.dom.shadowElementsFromPoint(10, 10, mockDocument);
});
assert.deepEqual(out, []);
});
});

0 comments on commit 62e31ea

Please sign in to comment.