resourceloader: Minor clean up in mw.loader and mw.html
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 15 Sep 2018 17:45:50 +0000 (18:45 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 15 Sep 2018 17:45:50 +0000 (18:45 +0100)
* Remove redundant registry check in the internal
  queueModuleScript function. Like most internal methods,
  it can only be inside the mw.loader closure, and is only
  called with extant module name.

* Remove redundant registry check from execute().

* Rename local variable in mw.loader.state() from 'modules'
  to 'states' to avoid confusion.

* Shorten exception messages in mw.html to not prefix the method
  names, because we don't do that anywhere else in RL JS.

Change-Id: Idf1a49fd98445477f2d940624ca0d079325bd15b

resources/src/mediawiki.base/mediawiki.base.js
resources/src/startup/mediawiki.js

index 16994f5..5820b83 100644 (file)
                } );
        };
 
-       // Fire events from before track() triggred fire()
+       // Fire events from before track() triggered fire()
        trackCallbacks.fire( mw.trackQueue );
 
        /**
                                                } else if ( contents instanceof this.Cdata ) {
                                                        // CDATA
                                                        if ( /<\/[a-zA-z]/.test( contents.value ) ) {
-                                                               throw new Error( 'mw.html.element: Illegal end tag found in CDATA' );
+                                                               throw new Error( 'Illegal end tag found in CDATA' );
                                                        }
                                                        s += contents.value;
                                                } else {
-                                                       throw new Error( 'mw.html.element: Invalid type of contents' );
+                                                       throw new Error( 'Invalid type of contents' );
                                                }
                                }
                                s += '</' + name + '>';
index c169487..b2aff43 100644 (file)
                        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 );
                                }
                                /**
                                 * 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 ];
+                                       for ( module in states ) {
+                                               state = states[ module ];
                                                if ( !hasOwn.call( registry, module ) ) {
                                                        mw.loader.register( module );
                                                }