w3c / DOM-Parsing

DOM Parsing and Serialization
https://w3c.github.io/DOM-Parsing/
Other
27 stars 14 forks source link

Scripting flag and behaviour for noscript #7

Open ArkadiuszMichalski opened 8 years ago

ArkadiuszMichalski commented 8 years ago

This flag determinate behaviour for noscript. Default scripting flag depends on scripting was enabled/disabled which depends if node's node document has a browsing context and scripting is enabled in that browsing context. If needed then scripting flag can be force so we can have scripting flag set to "enabled" where scripting was disabled. Comment from HTML spec: "The scripting flag can be enabled even when the parser was originally created for the HTML fragment parsing algorithm, even though script elements don't execute in that case." HTML fragment parsing algorithm only check scripting flag state (doesn't change it). And now in P&S I see:

<script type = "text/javascript">
    var div = document.createElement("div");
    div.innerHTML = "<noscript><p>test1<p>test2</noscript></noscript>";
    console.log(div.firstChild.childNodes.length, div.firstChild.firstChild); // 1 text

    var div2 = document.createElement("div");
    div2.insertAdjacentHTML("afterbegin", "<noscript><p>test1<p>test2</noscript>");
    console.log(div2.firstChild.childNodes.length, div.firstChild.firstChild); // 1 text

    var frag = document.createRange().createContextualFragment("<noscript><p>test1<p>test2</noscript>");
    console.log(frag.firstChild.childNodes.length, frag.firstChild.firstChild); // 1 text

    var doc = new DOMParser().parseFromString("<body><noscript><p>test1<p>test2</noscript>", "text/html");
    console.log(doc.body.firstChild.childNodes.length, doc.body.firstChild.firstChild, doc.body.firstChild.lastChild); // 2 p p 
    console.log(doc.defaultView); // null - this new document is without browsing context
</script>
domenic commented 4 years ago

https://github.com/whatwg/html/pull/5190 takes care of your second point by removing the note about the scripting flag and instead noting that there's no browsing context so scripting is disabled. I will also add tests to https://github.com/web-platform-tests/wpt/pull/21041 if they don't exist already, for DOMParser.

The other part of the issue will wait until we move those APIs into HTML, but it's possible that could be soon.