W3C home > Mailing lists > Public > public-html@w3.org > May 2009

Running "Zombie" Script Elements

From: Travis Leithead <Travis.Leithead@microsoft.com>
Date: Fri, 22 May 2009 23:24:32 -0700
To: "'public-html@w3.org'" <public-html@w3.org>, "ian@hixie.ch" <ian@hixie.ch>
CC: Harley Rosnow <Harley.Rosnow@microsoft.com>, Kirk Sykora <ksykora@microsoft.com>
Message-ID: <0003CB8B8FE2154EB50431DB2B8F69C02145C8305A@NA-EXMSG-W601.wingroup.windeploy.ntdev.microsoft.com>
Now that IE8’s out the door, I’m looking again at tackling the Operation Aborted problem once-and-for-all in IE (again: see [1]).

Ian, thanks to your help last time, I believe I really understand how the whole process should work regarding the stack, and parsing into removed markups, etc., etc. However, while prototyping we ran into one other interesting case that I believe I understand how it should be handled, but I wanted to confirm with you just to be sure ☺

The scenario is regarding secondary script blocks that get parsed out of the primary document because their parent node was already removed from the tree. (I'll call this the "zombie" script.) The question is: “should the zombie script run?”

Here’s a quick markup and script sample:

<body>
 <div>
  <span>
   <script> 
    var d = document.querySelector(“body > div”); 
    d.parentNode.removeChild(d); 
   </script>
   <code>
    <script> 
     alert(“a running zombie script?”); 
    </script>
   </code>
  </span>
 </div>
</body>

I think the answer is "no" because, according to 4.3.1 " When a script element that is neither marked as having "already executed" nor marked as being "parser-inserted" experiences one of the events listed in the following list, the user agent must run the script element:

    * The script element gets inserted into a document.
    * The script element's child nodes are changed.
    * The script element has a src attribute set where previously the element had no such attribute."

Regarding the scenario in question above, I _don't_ think the 2nd script block should be run because it will not be parsed _into_ the document. Indeed, this is the behavior I see in Firefox. However, if I later take my variable "d" and add it back into the tree, I'd expect that script to be run at that time.

However, section  9.2.5.11 does not include an exception for scripts parsed into portions of a document that are not in the primary document. For end Script tags, it simply sets up the algorithm to run the script.

Does my assertion agree with the intention of the spec? I'm a little hesitant about the "parser-inserted" flag that section 9.2.5.11. Also, I noticed that Safari runs the 2nd script at parse time. Opera's no good to compare because their parsing algorithm goes off into left-field in these scenarios. It's going to be much easier to implement in IE if we don't have to make the script run in this scenario.

Let me know what you think,
-Travis

P.S. Great work on the spec so far.

[1] http://lists.w3.org/Archives/Public/public-html/2008May/0574.html 
Received on Saturday, 23 May 2009 06:25:10 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 9 May 2012 00:16:37 GMT