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

Hi, Boris et al-

I just wanted to note that Andy Sledd's response with the new wording had
odd links to local file system resources that will, of course, be Web
resources in the published version.  For ease of reading, I'm pasting the
plain text version here:

"The processing model for scripting in SVG requires that the document model
must be updated including any required positioning and sizing computations
and the script element containing the script-content must be fully resolved
before any fragment of that script logic can execute. 

The processing model for script-content is as follows. 

1. The script element is added to the DOM tree. This may be a result of
parsing the original document, or as an addition to the DOM via script or
other means. (Note: script elements are not processed until they are added
to the DOM tree.)
2. The script element is resolved, i.e. if the script element references an
external resource the resource is retrieved.
3. The script-content is loaded into the scripting context and made
available for execution.
4. The script-content is executed as appropriate, (e.g. function
someFunction {...} may be designed to execute through a handler element and
therefore not execute on loading to the scripting context.)
5. The load event is raised.

Scripting logic associated with a given script event must not be raised,
even if the initial script-content had not been made fully available for
execution. This processing model is valid for both elements which are
created through loading a document fragment and for elements added using DOM
methods."

Regards-
Doug
 

Andrew Sledd wrote:
| 
| Hi,
| 
| This is a further response to your email 
| http://lists.w3.org/Archives/Public/www-svg/2006Jul/0182.html
| 
|  
| 
| Boris Zbarsky <bzbarsky@mit.edu 
| <mailto:bzbarsky@mit.edu?Subject=Re%3A%20%5BSVGMobile12%5D%20Q
| uestion%20on%20details%20of%20when%20%3Cscript%3E%20elements%2
| 0execute&In-Reply-To=%253C44C4F234.50807%40mit.edu%253E&Refere
| nces=%253C44C4F234.50807%40mit.edu%253E> > wrote:
| 
| >Andrew Sledd wrote:
| >> [Andy]  The load event description is correct. The script execution
| >> description has also been updated to reflect this.
| >
| >Thank you.
| >>>> 2)  What happens if the xlink:href is changed before the load 
| >>> event fires? 
| >> [Andy] only the original scripts content is executed as per the
| >> spec. The change to xlink:href will raise an additional load
| >> event when the external resource is loaded.
| >That sounds good (especially because it matches the behavior 
| of HTML UAs in 
| >similar circumstances), but where does the spec say this?  I 
| don't see it in the 
| >latest draft.
| >
| Here I must reword and slightly change my earlier statement. 
| After review of how the currently available browsers handle 
| this situation, the WG has discussed the matter and agreed 
| that the update to the xlink:href will not cause the new 
| resource to be retrieved and the load event will not be 
| fired. The specification has been update with the following 
| wording to ensure this is well understood.
| 
| "The processing model for scripting in SVG requires that the 
| document model must be updated including any required 
| positioning and sizing computations and the script 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/script.html#ScriptElement>  element containing 
| the script-content must be fully resolved before any fragment 
| of that script logic can execute. 
| 
| The processing model for script-content is as follows. 
| 
| 1.	The script 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/script.html#ScriptElement>  element is added to 
| the DOM tree. This may be a result of parsing the original 
| document, or as an addition to the DOM via script or other 
| means. (Note: script elements are not processed until they 
| are added to the DOM tree.)
| 2.	The script 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/script.html#ScriptElement>  element is resolved, 
| i.e. if the script element references an external resource 
| the resource is retrieved.
| 3.	The script-content is loaded into the scripting context 
| and made available for execution.
| 4.	The script-content is executed as appropriate, (e.g. 
| function someFunction {...} may be designed to execute 
| through a handler 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/script.html#HandlerElement>  element and 
| therefore not execute on loading to the scripting context.)
| 5.	The load 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/interact.html#EventsLoad>  event is raised.
| 
| Scripting logic associated with a given script 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/script.html#ScriptElement>  element is made 
| available for execution when the element is added to the DOM 
| tree. Removing or altering a script 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/script.html#ScriptElement>  element after the 
| script-content is in the scripting context and available for 
| execution will not prevent the script from executing nor the 
| associated load 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/interact.html#EventsLoad>  event from being 
| raised. Removing or altering a script 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/script.html#ScriptElement>  element before the 
| script-content is in the scripting context will prevent the 
| script from executing, the script-content will not be added 
| to the scripting context and the associated load 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/interact.html#EventsLoad>  event will not be 
| raised. Altering the xlink:href 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/script.html#ScriptElementHrefAttribute>  on a 
| script 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/script.html#ScriptElement>  element in the DOM 
| tree has no effect; loading of the referenced resource is not 
| required, it must not be added to the scripting context and a 
| load 
| <file:///D:/WWW/Graphics/SVG/Group/repository/spec/mobile/1.2/
| 1.2NG/master/interact.html#EventsLoad>  event must not be 
| raised, even if the initial script-content had not been made 
| fully available for execution. This processing model is valid 
| for both elements which are created through loading a 
| document fragment and for elements added using DOM methods."
| 
| 
| >> [Andy] This is meant to answer both 5 and 6; and I hope you agree.
| >> A script element can be cloned or created and inserted.
| >> Each time it is inserted it is executed. The clause "Inserting a 
| >> script element into the DOM tree will cause it to execute." is not 
| >> limited to new or unexecuted script-content. 
| >
| >I'm trying to reconcile that last statement with "Any 
| scripting logic associated 
| >with a given script element is executed at most once.".  I 
| assume that this 
| >overrides the "is not limited to new or unexecuted 
| script-content" language?  If 
| >so, this should be explicitly stated.
| >
| That text has been removed and the text I cited above replaces it.
| 
| >I just realized that there is a further ambiguity in the 
| spec, if the script 
| >content to be executed is that for the "original" 
| xlink:href.  Consider the 
| >following sequence of events:
| >
| >1)  createElementNS a <script> node.
| >2)  Set xlink:href to "foo"
| >3)  Wait for a while (long enough for "foo" to have loaded).
| >4)  Set xlink:href to "bar"
| >5)  Insert the node into the document.
| >
| >How many onload events are fired?  One or two?
| >
| With the new alignement of script resource loading behavior 
| there will be only one load event.
| 
| >Which script is executed?  "foo" or "bar"?
| bar
| Cheers,
| Andy
| 

Received on Wednesday, 2 August 2006 12:21:16 UTC