Bug 148765 - prepend should throw when prepending a Text node to Document
Summary: prepend should throw when prepending a Text node to Document
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL: https://dom.spec.whatwg.org/#concept-...
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-09-03 18:08 PDT by Ryosuke Niwa
Modified: 2016-07-15 17:18 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2015-09-03 18:08:57 PDT
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
Comment 1 Radar WebKit Bug Importer 2015-09-03 18:09:21 PDT
<rdar://problem/22570226>
Comment 2 Chris Dumez 2015-09-03 19:13:33 PDT
(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
Comment 3 Chris Dumez 2015-09-03 19:15:00 PDT
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).
Comment 4 Ryosuke Niwa 2016-07-15 17:18:20 PDT
Fixed in https://trac.webkit.org/changeset/189682.