Merge "resourceloader: Simplify StringSet fallback"
[lhc/web/wiklou.git] / resources / src / startup / mediawiki.js
index 06190a8..fee69c0 100644 (file)
@@ -13,7 +13,6 @@
        'use strict';
 
        var mw, StringSet, log,
-               hasOwn = Object.prototype.hasOwnProperty,
                trackQueue = [];
 
        /**
 
        function defineFallbacks() {
                // <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set>
-               StringSet = window.Set || ( function () {
-                       /**
-                        * @private
-                        * @class
-                        */
-                       function StringSet() {
-                               this.set = Object.create( null );
-                       }
-                       StringSet.prototype.add = function ( value ) {
-                               this.set[ value ] = true;
+               /**
+                * @private
+                * @class
+                */
+               StringSet = window.Set || function StringSet() {
+                       var set = Object.create( null );
+                       this.add = function ( value ) {
+                               set[ value ] = true;
                        };
-                       StringSet.prototype.has = function ( value ) {
-                               return value in this.set;
+                       this.has = function ( value ) {
+                               return value in set;
                        };
-                       return StringSet;
-               }() );
+               };
        }
 
        /**
                         * @property
                         * @private
                         */
-                       var registry = {},
+                       var registry = Object.create( null ),
                                // Mapping of sources, keyed by source-id, values are strings.
                                //
                                // Format:
                                //         'sourceId': 'http://example.org/w/load.php'
                                //     }
                                //
-                               sources = {},
+                               sources = Object.create( null ),
 
                                // For queueModuleScript()
                                handlingPendingRequests = false,
                        function sortDependencies( module, resolved, unresolved ) {
                                var i, deps, skip;
 
-                               if ( !hasOwn.call( registry, module ) ) {
+                               if ( !( module in registry ) ) {
                                        throw new Error( 'Unknown dependency: ' + module );
                                }
 
                        function queueModuleScript( src, moduleName, callback ) {
                                pendingRequests.push( function () {
                                        // Keep in sync with execute()/runScript().
-                                       if ( moduleName !== 'jquery' && hasOwn.call( registry, moduleName ) ) {
+                                       if ( moduleName !== 'jquery' ) {
                                                window.require = mw.loader.require;
                                                window.module = registry[ moduleName ].module;
                                        }
                                var key, value, media, i, urls, cssHandle, siteDeps, siteDepErr, runScript,
                                        cssPending = 0;
 
-                               if ( !hasOwn.call( registry, module ) ) {
-                                       throw new Error( 'Module has not been registered yet: ' + module );
-                               }
                                if ( registry[ module ].state !== 'loaded' ) {
                                        throw new Error( 'Module in state "' + registry[ module ].state + '" may not be executed: ' + module );
                                }
                         *  or null if the module does not exist
                         */
                        function getModuleKey( module ) {
-                               return hasOwn.call( registry, module ) ?
-                                       ( module + '@' + registry[ module ].version ) : null;
+                               return module in registry ? ( module + '@' + registry[ module ].version ) : null;
                        }
 
                        /**
                         * @param {string} [skip]
                         */
                        function registerOne( module, version, dependencies, group, source, skip ) {
-                               if ( hasOwn.call( registry, module ) ) {
+                               if ( module in registry ) {
                                        throw new Error( 'module already registered: ' + module );
                                }
                                registry[ module ] = {
                                        // Appends a list of modules from the queue to the batch
                                        for ( q = 0; q < queue.length; q++ ) {
                                                // Only load modules which are registered
-                                               if ( hasOwn.call( registry, queue[ q ] ) && registry[ queue[ q ] ].state === 'registered' ) {
+                                               if ( queue[ q ] in registry && registry[ queue[ q ] ].state === 'registered' ) {
                                                        // Prevent duplicate entries
                                                        if ( batch.indexOf( queue[ q ] ) === -1 ) {
                                                                batch.push( queue[ q ] );
                                addSource: function ( ids ) {
                                        var id;
                                        for ( id in ids ) {
-                                               if ( hasOwn.call( sources, id ) ) {
+                                               if ( id in sources ) {
                                                        throw new Error( 'source already registered: ' + id );
                                                }
                                                sources[ id ] = ids[ id ];
                                                name = split.name,
                                                version = split.version;
                                        // Automatically register module
-                                       if ( !hasOwn.call( registry, name ) ) {
+                                       if ( !( name in registry ) ) {
                                                mw.loader.register( name );
                                        }
                                        // Check for duplicate implementation
                                /**
                                 * Change the state of one or more modules.
                                 *
-                                * @param {Object} modules Object of module name/state pairs
+                                * @param {Object} states Object of module name/state pairs
                                 */
-                               state: function ( modules ) {
+                               state: function ( states ) {
                                        var module, state;
-                                       for ( module in modules ) {
-                                               state = modules[ module ];
-                                               if ( !hasOwn.call( registry, module ) ) {
+                                       for ( module in states ) {
+                                               state = states[ module ];
+                                               if ( !( module in registry ) ) {
                                                        mw.loader.register( module );
                                                }
                                                setAndPropagate( module, state );
                                 *  in the registry.
                                 */
                                getVersion: function ( module ) {
-                                       return hasOwn.call( registry, module ) ? registry[ module ].version : null;
+                                       return module in registry ? registry[ module ].version : null;
                                },
 
                                /**
                                 *  in the registry.
                                 */
                                getState: function ( module ) {
-                                       return hasOwn.call( registry, module ) ? registry[ module ].state : null;
+                                       return module in registry ? registry[ module ].state : null;
                                },
 
                                /**