unable to call document.createTreeWalker without unwrapping root

This commit is contained in:
Emad Eid
2015-03-08 10:04:58 -04:00
parent add281e429
commit 7be0fc008f
2 changed files with 20 additions and 0 deletions

View File

@@ -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;

View File

@@ -677,6 +677,19 @@ htmlSuite('Document', function() {
assert.equal('<span is="x-a-span-2"></span>', a3.outerHTML);
});
test('document.createTreeWalker', function() {
div = document.body.appendChild(document.createElement('div'));
div.innerHTML = '<div myattribute="a"></div>';
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');