Commit 908c8159 authored by Robert Knight's avatar Robert Knight

Fix issue with `getTextNodes` and nodes from other iframes

I don't believe this issue will ever occur in the real application, but
we currently have tests (in `html-test.js`) where the passed node comes from
a different iframe and therefore a different JS environment where globals including
`Text` and `Element` have different identities.
parent 28300faf
...@@ -70,10 +70,12 @@ export function xpathFromNode(node, root) { ...@@ -70,10 +70,12 @@ export function xpathFromNode(node, root) {
export function getTextNodes(element) { export function getTextNodes(element) {
const nodes = []; const nodes = [];
for (let node of Array.from(element.childNodes)) { for (let node of Array.from(element.childNodes)) {
if (node instanceof Text) { // We test `nodeType` here rather than using `instanceof` because we have
nodes.push(node); // tests where `node` comes from a different iframe.
} else if (node instanceof Element) { if (node.nodeType === Node.TEXT_NODE) {
nodes.push(...getTextNodes(node)); nodes.push(/** @type {Text} */ (node));
} else if (node.nodeType === Node.ELEMENT_NODE) {
nodes.push(...getTextNodes(/** @type {Element} */ (node)));
} }
} }
return nodes; return nodes;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment