| Summary: | prepend should throw when prepending a Text node to Document | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Ryosuke Niwa <rniwa> |
| Component: | DOM | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | cdumez, webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| URL: | https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity | ||
(In reply to comment #0) > document.createElement('div').prepend(document.createElement('span')) should > throw HierarchyRequestError when ensureing pre-insertion validity. > > This bug was found by the newly added test: > LayoutTests/http/tests/w3c/dom/nodes/prepend-on-Document.html The case you're mentioning seems like it should work and I don't see anything in the spec [1] saying it shouldn't. Looking at http/tests/w3c/dom/nodes/prepend-on-Document.html, I see the following test case: === test(function() { var parent = node.cloneNode(); var x = document.createElement('x'); parent.prepend(x); assert_array_equals(parent.childNodes, [x]); }, 'Document.prepend() with only one element as an argument, on a Document having no child.'); === This seems to be the case you mention and the test does not expect an exception. [1] https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity Maybe you were referring to the following check in the test?
===
test(function() {
var parent = node.cloneNode();
assert_throws('HierarchyRequestError', function() { parent.prepend('text'); });
assert_array_equals(parent.childNodes, []);
}, 'Document.prepend() with text as an argument, on a Document having no child.');
===
If so, the reason this is expected to throw is because the parent is a Document and the child is a Text Node (step 5 of https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity).
Fixed in https://trac.webkit.org/changeset/189682. |
document.createElement('div').prepend(document.createElement('span')) should throw HierarchyRequestError when ensureing pre-insertion validity. This bug was found by the newly added test: LayoutTests/http/tests/w3c/dom/nodes/prepend-on-Document.html