<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>148765</bug_id>
          
          <creation_ts>2015-09-03 18:08:57 -0700</creation_ts>
          <short_desc>prepend should throw when prepending a Text node to Document</short_desc>
          <delta_ts>2016-07-15 17:18:20 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ryosuke Niwa">rniwa</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cdumez</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1123252</commentid>
    <comment_count>0</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2015-09-03 18:08:57 -0700</bug_when>
    <thetext>document.createElement(&apos;div&apos;).prepend(document.createElement(&apos;span&apos;)) 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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1123253</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2015-09-03 18:09:21 -0700</bug_when>
    <thetext>&lt;rdar://problem/22570226&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1123278</commentid>
    <comment_count>2</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2015-09-03 19:13:33 -0700</bug_when>
    <thetext>(In reply to comment #0)
&gt; document.createElement(&apos;div&apos;).prepend(document.createElement(&apos;span&apos;)) should
&gt; throw HierarchyRequestError when ensureing pre-insertion validity.
&gt; 
&gt; This bug was found by the newly added test:
&gt; LayoutTests/http/tests/w3c/dom/nodes/prepend-on-Document.html

The case you&apos;re mentioning seems like it should work and I don&apos;t see anything in the spec [1] saying it shouldn&apos;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(&apos;x&apos;);
        parent.prepend(x);
        assert_array_equals(parent.childNodes, [x]);
    }, &apos;Document.prepend() with only one element as an argument, on a Document having no child.&apos;);
===

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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1123281</commentid>
    <comment_count>3</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2015-09-03 19:15:00 -0700</bug_when>
    <thetext>Maybe you were referring to the following check in the test?
===
    test(function() {
        var parent = node.cloneNode();
        assert_throws(&apos;HierarchyRequestError&apos;, function() { parent.prepend(&apos;text&apos;); });
        assert_array_equals(parent.childNodes, []);
    }, &apos;Document.prepend() with text as an argument, on a Document having no child.&apos;);
===

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).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1211691</commentid>
    <comment_count>4</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2016-07-15 17:18:20 -0700</bug_when>
    <thetext>Fixed in https://trac.webkit.org/changeset/189682.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>