Re: cloneNode() and script execution

Hallvord R. M. Steen wrote:
> Here is another issue for Ian to ponder while working on the script 
> execution stuff:
> 
> If you clone a script node and append the to the document, does it run?

Assuming this is a script node that already ran?  In Gecko we just copy 
the "node has run" flag when cloning, so if you createElement a 
<script>, set its src, then clone it, then insert both scripts in the 
document they'll both run.

>  From my naturally biased point of view I think Opera makes more sense - 
> a "deep" clone remembers that the script was already executed, a shallow 
> doesn't because it doesn't clone the script code.

Here's what the DOM spec says about the "deep" argument to cloneNode [1]:

   deep of type boolean
     If true, recursively clone the subtree under the specified node;
     if false, clone only the node itself (and its attributes, if it
     is an Element).

So I don't see how "because it doesn't clone the script node" can 
possibly be supported by the spec text here.  Certainly if the script is 
one loaded via @src it's cloning all the information there is to clone.

I agree that the spec is not clear on what cloning should do with state 
not represented in attributes, but what it sounds like to me is that 
Opera (and Gecko, for that matter) added a hack to work around pages 
that broke because of assuming the IE behavior and Opera just added a 
slightly different hack than Gecko.  Nothing wrong with that, but let's 
not try to invent post-facto justifications.

For what it's worth, https://bugzilla.mozilla.org/show_bug.cgi?id=127016 
is the Gecko bug that led to the current Gecko behavior, so I can in 
fact say with confidence that my description above of why Gecko behaves 
the way it does is correct.  ;)

-Boris

[1] 
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-3A0ED0A4

Received on Sunday, 18 January 2009 18:17:09 UTC