Address one of the fixmes on r88053: because addScript() is asynchronous, calling...
authorRoan Kattouw <catrope@users.mediawiki.org>
Tue, 13 Sep 2011 13:55:43 +0000 (13:55 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Tue, 13 Sep 2011 13:55:43 +0000 (13:55 +0000)
commit40ed8e0f8e4ac1cde023a0ba2bac13755cd40406
treed477d9cfba35f44a1bce3197f2dd74b61562d146
parenta0fbb287ae58054ee3d9b69bf1afaf4edea327bb
Address one of the fixmes on r88053: because addScript() is asynchronous, calling it repeatedly can lead to scripts loading out of order. The specific bug was that if you had a module with two script files, A and B (in that order; scripts are always loaded in the order in which they are specified for multi-file modules) and A is 40M while B is 1K, then B would be executed before A if the module is loaded after document ready (through e.g. mw.loader.using) and the files are not in the browser cache.

So instead of calling addScript() repeatedly in a loop, this commit calls addScript() recursively from its own callback, using a helper function called nestedAddScript(). This also means the if block that checks if the scripts array is empty can be removed, because nestedAddScript() handles empty arrays correctly.
resources/mediawiki/mediawiki.js