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
<rdar://problem/22570226>
(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.