r88706 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88705‎ | r88706 | r88707 >
Date:00:42, 24 May 2011
Author:brion
Status:ok (Comments)
Tags:
Comment:
* (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) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -481,27 +481,30 @@
482482 // Execute script
483483 try {
484484 var script = registry[module].script;
 485+ var markModuleReady = function() {
 486+ registry[module].state = 'ready';
 487+ handlePending( module );
 488+ if ( $.isFunction( callback ) ) {
 489+ callback();
 490+ }
 491+ };
485492 if ( $.isArray( script ) ) {
486493 var done = 0;
 494+ if (script.length == 0 ) {
 495+ // No scripts in this module? Let's dive out early.
 496+ markModuleReady();
 497+ }
487498 for ( var i = 0; i < script.length; i++ ) {
488499 registry[module].state = 'loading';
489500 addScript( script[i], function() {
490501 if ( ++done == script.length ) {
491 - registry[module].state = 'ready';
492 - handlePending( module );
493 - if ( $.isFunction( callback ) ) {
494 - callback();
495 - }
 502+ markModuleReady();
496503 }
497504 } );
498505 }
499506 } else if ( $.isFunction( script ) ) {
500507 script( jQuery );
501 - registry[module].state = 'ready';
502 - handlePending( module );
503 - if ( $.isFunction( callback ) ) {
504 - callback();
505 - }
 508+ markModuleReady();
506509 }
507510 } catch ( e ) {
508511 // This needs to NOT use mw.log because these errors are common in production mode

Follow-up revisions

RevisionCommit summaryAuthorDate
r89243Follow-up to r88706: add qunit regression test case for bug 29107....brion00:13, 1 June 2011

Comments

#Comment by Krinkle (talk | contribs)   20:48, 28 May 2011

I'm not sure how this failed before this commit, I know it works now.

Could you perhaps add a test suite for this in /tests/qunit/suites/ ?

Probably something with mw.loader.implement and mw.messages.exists.

#Comment by Brion VIBBER (talk | contribs)   23:55, 31 May 2011

Think I can whip something together for this...

#Comment by Brion VIBBER (talk | contribs)   00:13, 1 June 2011

Added in r89243.

Status & tagging log