mw.loader: Don't assume var 'loading' assigns before Promise resolves
authorFomafix <fomafix@googlemail.com>
Wed, 12 Apr 2017 05:15:24 +0000 (07:15 +0200)
committerKrinkle <krinklemail@gmail.com>
Wed, 12 Apr 2017 17:41:43 +0000 (17:41 +0000)
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

index 86a9a0a..08807fb 100644 (file)
         * @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();
                                } );