RE: Run global <script> before or after <datamodel> initialization?

Yes, that's intentional.  The <scxml> element has an 'initial' attribute, but may not have an <initial> child.   For notational convenience, all 'initial' attributes are converted into <initial> elements in expandSCXMLSource, but the resulting transitions will not contain executable content.  So there's no point in pretending to execute it here.  (Earlier versions of the spec did allow an <initial> attribute,  so we did have to be ready to execute the executable content in the <transition>, and we forgot to modify the algorithm when we restricted the syntax.)


-          Jim

From: Gavin Kistner [mailto:phrogz@me.com]
Sent: Thursday, February 14, 2013 6:59 PM
To: Jim Barnett
Cc: www-voice@w3.org
Subject: Re: Run global <script> before or after <datamodel> initialization?

Looks good to me, except that it's missing (intentionally?) executeTransitionContent([doc.initial.transition])

--

(-, /\ \/ / /\/

On Feb 14, 2013, at 04:27 PM, Jim Barnett <Jim.Barnett@genesyslab.com<mailto:Jim.Barnett@genesyslab.com>> wrote:
F.Y.I, here's what I think the start-up code should look like.  Perhaps 'running' should be set to 'true' earlier ( because you clearly are running, in some sense, when you initialize the datamodel and execute  the global script element), but it is used only in the main event loop.

procedure interpret(doc):
    if not valid(doc): failWithError()
    expandScxmlSource(doc)
    configuration = new OrderedSet()
    statesToInvoke = new OrderedSet()
    internalQueue = new Queue()
    externalQueue = new BlockingQueue()
    historyValue = new HashTable()
    datamodel = new Datamodel(doc)
    if doc.binding == "early":
        initializeDatamodel(datamodel, doc)
    executeGlobalScriptElement(doc)
    enterStates([doc.initial.transition])
    running = true
    mainEventLoop()


-          Jim

From: Gavin Kistner [mailto:phrogz@me.com]
Sent: Thursday, February 14, 2013 4:43 PM
To: www-voice@w3.org<mailto:www-voice@w3.org>; www-voice@w3.org<mailto:www-voice@w3.org>
Subject: Run global <script> before or after <datamodel> initialization?

The prose in the official algorithm describes a <script> element at the root of the document as being run after the data model is initialized:

"Create an empty configuration complete with a new populated instance of the data model and a[sic] execute the global scripts[sic]."

(I assume that "scripts" should be "script", as only one <script> element may appear as a child of <scxml>.)

This order makes sense to me: I want my script to be able to read initial datamodel values and manipulate them. (I'm assuming that script executes in the context of the data model and may thus set values in it as well.)

However, the official pseudo-code executes the global script element before the data model is initialized:

    datamodel = new Datamodel(doc)
    executeGlobalScriptElements(doc)  # Note: this is also plural
    ...
    if binding == "early":
      initializeDatamodel(datamodel, doc)

Is there a compelling reason to execute global <script> before initializing the data model?

Received on Friday, 15 February 2013 02:17:21 UTC