Bug 97361
Summary: | range.selectNode throws INVALID_NODE_TYPE_ERR unless node has Document/DocumentFragment ancestor | ||
---|---|---|---|
Product: | WebKit | Reporter: | Nathan Vander Wilt <natevw> |
Component: | DOM | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED CONFIGURATION CHANGED | ||
Severity: | Normal | CC: | annevk, ap, rniwa |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | All | ||
OS: | Unspecified |
Nathan Vander Wilt
The following code fails unexpectedly in WebKit (works in FF, haven't tested IE):
var range = document.createRange(),
root = document.createElement('div');
root.appendChild(document.createElement('span'));
range.selectNode(root.firstChild); // throws INVALID_NODE_TYPE_ERR
It is possible to `range.selectNodeContents(root)` or `range.setStart(root,0), range.setEnd(root,1)` but the `.selectNode` method specifically, errors when it should not. Reference: http://www.w3.org/TR/dom/#dom-range-selectnode — only case INVALID_NODE_TYPE_ERR should be thrown is if root.firstChild.parentNode is null...but that's unpossible!
Hooking the root element into a document, or even a document fragment via e.g. `document.createDocumentFragment().append(root)`, causes the bug to no longer manifest.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Ojan Vafai
I think the simplifications that DOM4 makes to selectNode are mostly good. There's a bunch of things our code does differently though. Someone needs to evaluate what the WebKit code does now and make sure we're OK with the spec as is (e.g. is it OK for the parent of the refNode to be a DocumentFragment?).
At first glance, the spec looks good to me, but I haven't taken a thorough look.
Anne van Kesteren
This appears to have been fixed at some point.