resourceloader: remove redundant mw.loader type-checks
authorOri Livneh <ori@wikimedia.org>
Sun, 19 Jun 2016 04:34:38 +0000 (21:34 -0700)
committerKrinkle <krinklemail@gmail.com>
Wed, 22 Jun 2016 16:29:25 +0000 (16:29 +0000)
I searched Google and could not find any indication that anyone has encountered
these error messages in the wild since their introduction, half a decade go.
In my opinion they hurt readability substantially by displacing the main body
of the function away from its declaration.

Change-Id: Ifd33974b0c63f3d7ea44f1b0728de4b8b8dde099

resources/src/mediawiki/mediawiki.js

index 348b617..40c5595 100644 (file)
                                                }
                                                return;
                                        }
-                                       // Validate input
-                                       if ( typeof module !== 'string' ) {
-                                               throw new Error( 'module must be a string, not a ' + typeof module );
-                                       }
                                        if ( hasOwn.call( registry, module ) ) {
                                                throw new Error( 'module already registered: ' + module );
                                        }
                                 * @param {Object} [templates] List of key/value pairs to be added to mw#templates.
                                 */
                                implement: function ( module, script, style, messages, templates ) {
-                                       // Validate input
-                                       if ( typeof module !== 'string' ) {
-                                               throw new Error( 'module must be of type string, not ' + typeof module );
-                                       }
-                                       if ( script && !$.isFunction( script ) && !$.isArray( script ) && typeof script !== 'string' ) {
-                                               throw new Error( 'script must be of type function, array, or script; not ' + typeof script );
-                                       }
-                                       if ( style && !$.isPlainObject( style ) ) {
-                                               throw new Error( 'style must be of type object, not ' + typeof style );
-                                       }
-                                       if ( messages && !$.isPlainObject( messages ) ) {
-                                               throw new Error( 'messages must be of type object, not a ' + typeof messages );
-                                       }
-                                       if ( templates && !$.isPlainObject( templates ) ) {
-                                               throw new Error( 'templates must be of type object, not a ' + typeof templates );
-                                       }
                                        // Automatically register module
                                        if ( !hasOwn.call( registry, module ) ) {
                                                mw.loader.register( module );
                                        // Allow calling with a single dependency as a string
                                        if ( typeof dependencies === 'string' ) {
                                                dependencies = [ dependencies ];
-                                       } else if ( !$.isArray( dependencies ) ) {
-                                               // Invalid input
-                                               throw new Error( 'Dependencies must be a string or an array' );
                                        }
 
                                        if ( ready ) {
                                load: function ( modules, type ) {
                                        var filtered, l;
 
-                                       // Validate input
-                                       if ( typeof modules !== 'object' && typeof modules !== 'string' ) {
-                                               throw new Error( 'modules must be a string or an array, not a ' + typeof modules );
-                                       }
                                        // Allow calling with a url or single dependency as a string
                                        if ( typeof modules === 'string' ) {
                                                // "https://example.org/x.js", "http://example.org/x.js", "//example.org/x.js", "/x.js"