RE: [SVGMobile12] Question on details of when <script> elements execute

Dear Boris,
This is the response to your Last Comment comment from email
(http://lists.w3.org/Archives/Public/www-svg/2006Jan/0448.html), which
is copied at the bottom.

Here are responses to your questions, which are repeated inline:

1)  If a script element is modified before script execution has
     taken place (e.g. the xlink:href value is changed while the
     script the original xlink:href value pointed to is loading),
     what happens?  Similar for other DOM mutations to the <script>
     node.

Some factors that are involved:

a) Any asset referenced by xlink:href (e.g., script, image, font,
gradient, etc.) potentially is subject to asynchronous loading
b) The load event associated with an element that references an external
asset via xlink:href does not occur until the asset is fully pulled down
and available
c) it is possible that the referenced resource times out and the user
agent determines that the referenced asset is unavailable

The current SVG Tiny 1.2 spec says that script logic executes in
conjunction with the 'load' event. The 'load' event occurs once the
referenced scripting logic is fully downloaded and available, which
occurs at an unpredictable time due to potential asynchronous
downloading; therefore, if scripting logic changes the <script> element,
in some cases these changes will happen before the original scripting
logic is executed (in which case, the UA must only execute the newer
scripting logic based on the changed DOM) and in other cases after the
original scripting logic is executed. (in which case, the UA must only
execute the original scripting logic).

As a result, the advice to content creators: don't do that. Scripts
should not change <script> tags because this might result in
unpredictable results.

2)  Do scripts created via createElementNS() ever execute?  If so,
     when?  Note that it's not clear to me whether the load event
     fires on nodes created via DOM methods.

Nodes do not become part of the SVG document until they have been
inserted into the DOM tree. Events do not fire on nodes that are not
(yet) in the SVG document tree. In particular, 'load' does not fire and
script logic does not execute simply by creating an svg:script element
via createElementNS().

3)  Do scripts that are clones (via cloneNode()) of other scripts
     execute?  If so, when?  Does it matter whether the script that
     was cloned had already executed at the time of cloning?

Same answer as above.
 
Your comment, along with comments from others, have resulted in
one change to the current wording in the scripting section of the spec.
 
 The old wording included the following sentence: 
"Removing, inserting or altering script elements
after script execution has taken place has no effect." 
 
The new wording is: 
"Removing or altering script elements after script execution has
taken place has no effect. Inserting a script element into the DOM tree
will cause it to execute."
 
If a new <script> element is inserted into the document via scripting
logic, 
its associated scripting logic indeed will get executed (at most once).

Thanks for your feedback, please let us know shortly if you are  
unsatisfied with this answer.
 
Andrew Sledd on behalf of the SVG WG.

--------------------------------------------------------------
From: Boris Zbarsky <bzbarsky@mit.edu
<mailto:bzbarsky@mit.edu?Subject=Re%3A%20ACTION-1092%3A%20Make%20a%20pro
posal%20and%20respond%20to%20LC-495&In-Reply-To=%253C6ECA24BE410D994496A
2AE995367C5C87A0DBA%40namail3.corp.adobe.com%253E&References=%253C6ECA24
BE410D994496A2AE995367C5C87A0DBA%40namail3.corp.adobe.com%253E> > 
Date: Sat, 28 Jan 2006 00:00:47 -0600
Message-ID: <43DB088F.9060609@mit.edu
<mailto:43DB088F.9060609@mit.edu?Subject=Re%3A%20ACTION-1092%3A%20Make%2
0a%20proposal%20and%20respond%20to%20LC-495&In-Reply-To=%253C6ECA24BE410
D994496A2AE995367C5C87A0DBA%40namail3.corp.adobe.com%253E&References=%25
3C6ECA24BE410D994496A2AE995367C5C87A0DBA%40namail3.corp.adobe.com%253E>
> 
To: www-svg@w3.org
<mailto:www-svg@w3.org?Subject=Re%3A%20ACTION-1092%3A%20Make%20a%20propo
sal%20and%20respond%20to%20LC-495&In-Reply-To=%253C6ECA24BE410D994496A2A
E995367C5C87A0DBA%40namail3.corp.adobe.com%253E&References=%253C6ECA24BE
410D994496A2AE995367C5C87A0DBA%40namail3.corp.adobe.com%253E>  

Dear SVG Working Group,

In section 15.2 [1] there is the following text:

   Any scripting logic associated with a given script element is
   executed at most once. Script execution happens just after the
   load event occurs for the given script element. Removing,
   inserting or altering script elements after script execution has
   taken place has no effect.

This leaves the following questions open, I believe:

1)  If a script element is modified before script execution has
     taken place (eg the xlink:href value is changed while the
     script the original xlink:href value pointed to is loading),
     what happens?  Similar for other DOM mutations to the <script>
     node.
2)  Do scripts created via createElementNS() ever execute?  If so,
     when?  Note that it's not clear to me whether the load event
     fires on nodes created via DOM methods.
3)  Do scripts that are clones (via cloneNode()) of other scripts
     execute?  If so, when?  Does it matter whether the script that
     was cloned had already executed at the time of cloning?

-Boris

Received on Wednesday, 12 July 2006 15:58:33 UTC