Re: Out of order JS file execution in WebKit

[email protected] Mon, 12 Apr 2010 18:37:09 -0000
Newsgroups gmane.comp.python.quotient.dev
Message-ID <20100412183709.2779.807228650.divmod.xquotient.373@localhost.localdomain>
On 06:23 pm, [email protected] wrote:
>Hi
>
>Seems that the quest for more speed in JS execution goes into the next
>round. WebKit does not load and execute JS files in the order they are
>specified either by '// include' or in the header of the LivePage.
>
>The problems I observed were that depending on load/response time my
>LivePage based RIAs sometimes worked perfectly and sometimes simply
>stopped working at certain stages in the WebKit based browsers.
>
>After some digging and inserting alert's in the JS files before 
>creating
>a new class, the alerts showed that base classes were sometimes empty
>and therefore the class trying to inherit died.
>
>A simple solution was to push the '// include' of the base classes back
>to some early point when loading the initial page, the after wards
>injected LiveElements then do find their base classes because 
>everything
>is settled by then.
>
>I'm not familiar enough with the import system used by nevow/athena to
>see a path for a solution but maybe somebody with the knowledge can
>enlighten me if more refined solution could be built into nevow/athena.
>
>Question: Would it be feasible to extend the '// include' system such
>that it can be guaranteed that a following constructor for YYY can rely
>on the base class XXX being present?

There's no need to extend it.  This is exactly how it's supposed to 
work.

The question is how to make the implementation work properly on WebKit,
which is violating an assumption being made.

One approach might be to have Athena wrap the entire contents of each js 
module in something like this:

    waitForModules(
        ["Nevow.Athena", "common.xxx"],
        function() {
            // import Nevow.Athena
            // import common.xxx

            // the rest of the original js module

            // This call inserted, perhaps not lexically here, but
            // somewhere which gives equivalent ordering.
            moduleLoaded("the name of this module");
        });

waitForModules and moduleLoaded would use a simple event-based system so 
that the function given to waitForModules would never be called until 
all of the necessary modules had been evaluated.

This would let the modules be loaded in parallel or out of order or 
however (wrong?) WebKit wants to do things, but still guarantee the 
ordering that Athena is supposed to be guaranteeing.

If this idea makes sense, I can go into more detail about what the 
implementation might look like.

Jean-Paul