resourceloader: Use Object.keys() instead of map() to get keys
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.js
index 33f146b..c45a861 100644 (file)
                /* eslint-enable no-bitwise */
        }
 
-       // <https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set>
-       StringSet = window.Set || ( function () {
-               /**
-                * @private
-                * @class
-                */
-               function StringSet() {
-                       this.set = {};
-               }
-               StringSet.prototype.add = function ( value ) {
-                       this.set[ value ] = true;
-               };
-               StringSet.prototype.has = function ( value ) {
-                       return hasOwn.call( this.set, value );
-               };
-               return StringSet;
-       }() );
+       function defineFallbacks() {
+               // <https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set>
+               StringSet = window.Set || ( function () {
+                       /**
+                        * @private
+                        * @class
+                        */
+                       function StringSet() {
+                               this.set = {};
+                       }
+                       StringSet.prototype.add = function ( value ) {
+                               this.set[ value ] = true;
+                       };
+                       StringSet.prototype.has = function ( value ) {
+                               return hasOwn.call( this.set, value );
+                       };
+                       return StringSet;
+               }() );
+       }
 
        /**
         * Create an object that can be read from or written to via methods that allow
                }
        };
 
+       defineFallbacks();
+
        /* eslint-disable no-console */
        log = ( function () {
                // Also update the restoration of methods in mediawiki.log.js
         * @class mw
         */
        mw = {
+               redefineFallbacksForTest: function () {
+                       if ( !window.QUnit ) {
+                               throw new Error( 'Reset not allowed outside unit tests' );
+                       }
+                       defineFallbacks();
+               },
 
                /**
                 * Get the current time, measured in milliseconds since January 1, 1970 (UTC).
                         * @return {string} Hash of concatenated version hashes.
                         */
                        function getCombinedVersion( modules ) {
-                               var hashes = $.map( modules, function ( module ) {
+                               var hashes = modules.map( function ( module ) {
                                        return registry[ module ].version;
                                } );
                                return fnv132( hashes.join( '' ) );
                                 * @return {Array}
                                 */
                                getModuleNames: function () {
-                                       return $.map( registry, function ( i, key ) {
-                                               return key;
-                                       } );
+                                       return Object.keys( registry );
                                },
 
                                /**
                // 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 = $.map( loading, function ( module ) {
+                       var all = loading.map( function ( module ) {
                                return mw.loader.using( module ).then( null, function () {
                                        return $.Deferred().resolve();
                                } );