From dd140224c850e011f9c5ea4a8763c5918d4ab566 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Wed, 12 Apr 2017 07:15:24 +0200 Subject: [PATCH] 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 --- resources/src/mediawiki/mediawiki.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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(); } ); -- 2.20.1