http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88706

Revision: 88706
Author:   brion
Date:     2011-05-24 00:42:42 +0000 (Tue, 24 May 2011)
Log Message:
-----------
* (bug 29107) Fix regression in ResourceLoader debug mode for WikiEditor

One of WikiEditor's modules had only messages, no scripts; updates to the debug 
mode loader had ended up failing in the case where no scripts got passed in (if 
passed with a loader function we were fine, hence non-debug mode being ok)
This commit explicitly checks for the empty-array case and marks the module as 
ready immediately, instead of waiting for the last item in the loop to finish, 
which never happens. :)

Also consolidated three calls to the same few lines of code into a lambda 
function.

Modified Paths:
--------------
    trunk/phase3/resources/mediawiki/mediawiki.js

Modified: trunk/phase3/resources/mediawiki/mediawiki.js
===================================================================
--- trunk/phase3/resources/mediawiki/mediawiki.js       2011-05-24 00:21:42 UTC 
(rev 88705)
+++ trunk/phase3/resources/mediawiki/mediawiki.js       2011-05-24 00:42:42 UTC 
(rev 88706)
@@ -481,27 +481,30 @@
                        // Execute script
                        try {
                                var script = registry[module].script;
+                               var markModuleReady = function() {
+                                       registry[module].state = 'ready';
+                                       handlePending( module );
+                                       if ( $.isFunction( callback ) ) {
+                                               callback();
+                                       }
+                               };
                                if ( $.isArray( script ) ) {
                                        var done = 0;
+                                       if (script.length == 0 ) {
+                                               // No scripts in this module? 
Let's dive out early.
+                                               markModuleReady();
+                                       }
                                        for ( var i = 0; i < script.length; i++ 
) {
                                                registry[module].state = 
'loading';
                                                addScript( script[i], 
function() {
                                                        if ( ++done == 
script.length ) {
-                                                               
registry[module].state = 'ready';
-                                                               handlePending( 
module );
-                                                               if ( 
$.isFunction( callback ) ) {
-                                                                       
callback();
-                                                               }
+                                                               
markModuleReady();
                                                        }
                                                } );
                                        }
                                } else if ( $.isFunction( script ) ) {
                                        script( jQuery );
-                                       registry[module].state = 'ready';
-                                       handlePending( module );
-                                       if ( $.isFunction( callback ) ) {
-                                               callback();
-                                       }
+                                       markModuleReady();
                                }
                        } catch ( e ) {
                                // This needs to NOT use mw.log because these 
errors are common in production mode


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to