Question

I am developing support for scripting on (X)HTML rendering engine in Java. I would like follow HTML5 specification.

Currently I am trying to figure out in which cases (on which circumstances) should be script "prepared".

Specification denotes three events when to invoke preparation of the script:

1) The script element gets inserted into a document, at the time the node is inserted according to the DOM, after any other script elements inserted at the same time that are earlier in the Document in tree order.

2) The script element is in a Document and a node or document fragment is inserted into the script element, after any script elements inserted at that time.

3) The script element is in a Document and has a src attribute set where previously the element had no such attribute.

As what I understand, so the second event for running "preparation steps" should be an insertion of node into empty script element. So I tried this:

<script id="third"></script> 
<script>
    var thirdScript = document.getElementById("third");
    var thirdScriptBody = document.createTextNode("document.write(\"execution test\");")
    thirdScript.appendChild(thirdScriptBody);
</script>

But body of the script was not executed at all. Even if all conditions are met for it:

  1. parser-inserted is FALSE, because it was parsed during document fetch.

  2. already-started is FALSE, because preparation for the first time failed due to emptiness (step 4 of preparation algorithm)

  3. New text node was inserted into script element.

Finally I tried the corresponding test for the 3rd point from the specification:

<script id="fourth"></script> 
<script>
    var fourthScript = document.getElementById("fourth");
    fourthScript.setAttribute("src","script.js");
</script>

Again, nothing happend. No external script was executed.

What am I missing? What is wrong with my interpretation of the specification?

Thanks for any advice.

Was it helpful?

Solution

Your interpretation of the specification seems fine, so the running of your tests must be flawed.

A JSFiddle of your test "third" is here: http://jsfiddle.net/Pfrkc/1/

A JSFiddle of your test "fourth" is here: http://jsfiddle.net/Pfrkc/2/

Both run fine for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top