From: Fomafix Date: Wed, 12 Apr 2017 05:15:24 +0000 (+0200) Subject: mw.loader: Don't assume var 'loading' assigns before Promise resolves X-Git-Tag: 1.31.0-rc.0~3527^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=dd140224c850e011f9c5ea4a8763c5918d4ab566;p=lhc%2Fweb%2Fwiklou.git mw.loader: Don't assume var 'loading' assigns before Promise resolves In rare situations the variable loading already assigned with a promise and the call to loading.map fails with TypeError: loading.map is not a function Change-Id: Ie50bdda229e48b159702fc2a83e641a35d7c850c --- diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index 86a9a0af1b..08807fb0ce 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -2754,14 +2754,16 @@ * @member mw.hook */ $( function () { - var loading = $.grep( mw.loader.getModuleNames(), function ( module ) { + var loading, modules; + + modules = $.grep( mw.loader.getModuleNames(), function ( module ) { return mw.loader.getState( module ) === 'loading'; } ); // We only need a callback, not any actual module. First try a single using() // for all loading modules. If one fails, fall back to tracking each module // separately via $.when(), this is expensive. - loading = mw.loader.using( loading ).then( null, function () { - var all = loading.map( function ( module ) { + loading = mw.loader.using( modules ).then( null, function () { + var all = modules.map( function ( module ) { return mw.loader.using( module ).then( null, function () { return $.Deferred().resolve(); } );