From 7be0fc008f1040296e7c67bb756be0291751aa19 Mon Sep 17 00:00:00 2001 From: Emad Eid Date: Sun, 8 Mar 2015 10:04:58 -0400 Subject: [PATCH] unable to call document.createTreeWalker without unwrapping root --- src/ShadowDOM/wrappers/Document.js | 7 +++++++ tests/ShadowDOM/js/Document.js | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/ShadowDOM/wrappers/Document.js b/src/ShadowDOM/wrappers/Document.js index 6dee221..b658fe1 100644 --- a/src/ShadowDOM/wrappers/Document.js +++ b/src/ShadowDOM/wrappers/Document.js @@ -338,6 +338,13 @@ 'hasFeature', ]); + var originalCreateTreeWalker = document.createTreeWalker; + function createTreeWalker(root, whatToShow, filter, entityReferenceExpansion){ + return originalCreateTreeWalker.call(document,unwrap(root), whatToShow, filter, entityReferenceExpansion); + } + + document.createTreeWalker = createTreeWalker; // override + scope.adoptNodeNoRemove = adoptNodeNoRemove; scope.wrappers.DOMImplementation = DOMImplementation; scope.wrappers.Document = Document; diff --git a/tests/ShadowDOM/js/Document.js b/tests/ShadowDOM/js/Document.js index 45f2453..52a2dd9 100644 --- a/tests/ShadowDOM/js/Document.js +++ b/tests/ShadowDOM/js/Document.js @@ -677,6 +677,19 @@ htmlSuite('Document', function() { assert.equal('', a3.outerHTML); }); + test('document.createTreeWalker', function() { + div = document.body.appendChild(document.createElement('div')); + div.innerHTML = '
'; + var treeWalker = document.createTreeWalker(div, NodeFilter.SHOW_ELEMENT, null, null); + var found; + while (treeWalker.nextNode()) { + if (treeWalker.currentNode.hasAttribute("myattribute")){ + found=treeWalker.currentNode.getAttribute("myattribute")==='a'; + } + } + assert.isTrue(found); + }); + htmlTest('../html/document-write.html'); htmlTest('../html/head-then-body.html');