Re: Running "Zombie" Script Elements

On Thu, 11 Jun 2009, Jonas Sicking wrote:
> 
> So implementation wise the implementation will have to set some special 
> flag on the script element to tell it not to execute when it otherwise 
> normally would.

Implementations already have at least one flag for <script> that's similar 
to this ("has already executed"), so that seems likely to be pretty 
lightweight, as I understand it.


> The implementation works something like this:
> 
> scriptElement::onTextContentChange()
> {
>   maybeEvalScript();
> }
> 
> scriptElement::onDocumentChange()
> {
>   maybeEvalScript();
> }
> 
> scriptElement::onAttrChange()
> {
>   maybeEvalScript();
> }
> 
> scriptElement::maybeEvalScript()
> {
>   if (!didEvaluate && !wasCreatedByParser && isInDocument() &&
>       (getTextContent() != "" || hasSrcAttribute)) {
>     didEvaluate = true;
>     <evaluate script>;
>   }
> }
> 
> Once the parser is done creating the script, it'll call some function
> on the script to tell it to go. If this function simply unsets the
> wasCreatedByParser flag and calls maybeEvalScript, or if that function
> evaluates the script directly, doesn't really make a difference from
> an implementation complexity view.
> 
> So we'd never need to not insert the script into the DOM (that would
> be more complex all around I'd think).
> 
> The difference implementation wise is very small, simply choosing
> which one of two functions to call.
> 
> As stated before, I don't have a strong preference either way. It seems 
> like good consistency arguments can be made either way, and 
> implementation wise both solutions are equally simple to implement.

I'm not sure I understand exactly what the two proposals you're referring 
to are, but if the spec as is is ok, then let's stick with that. :-)

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Friday, 10 July 2009 05:14:02 UTC