resourceloader: Minor optims in startup JS
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 2 Aug 2019 14:41:21 +0000 (15:41 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Fri, 2 Aug 2019 16:51:33 +0000 (17:51 +0100)
Change-Id: I3bb6e77e3572c212ea32838f7668940b5abc99d8

resources/src/startup/mediawiki.js

index ace92f0..95d2d7f 100644 (file)
         * @class mw
         */
        mw = {
-               redefineFallbacksForTest: function () {
-                       if ( !window.QUnit ) {
-                               throw new Error( 'Not allowed' );
-                       }
-                       defineFallbacks();
-               },
+               redefineFallbacksForTest: window.QUnit && defineFallbacks,
 
                /**
                 * Get the current time, measured in milliseconds since January 1, 1970 (UTC).
                                        }
 
                                        if ( !hasOwn.call( scriptFiles, fileName ) ) {
-                                               throw new Error( 'Cannot require() undefined file ' + fileName );
+                                               throw new Error( 'Cannot require undefined file ' + fileName );
                                        }
                                        if ( hasOwn.call( moduleObj.packageExports, fileName ) ) {
                                                // File has already been executed, return the cached result
                                        cssPending = 0;
 
                                if ( registry[ module ].state !== 'loaded' ) {
-                                       throw new Error( 'Module in state "' + registry[ module ].state + '" may not be executed: ' + module );
+                                       throw new Error( 'Module in state "' + registry[ module ].state + '" may not execute: ' + module );
                                }
 
                                registry[ module ].state = 'executing';
                                                        } else {
                                                                mainScript = script.files[ script.main ];
                                                                if ( typeof mainScript !== 'function' ) {
-                                                                       throw new Error( 'Main file ' + script.main + ' in module ' + module +
-                                                                               ' must be of type function, found ' + typeof mainScript );
+                                                                       throw new Error( 'Main file in module ' + module + ' must be a function' );
                                                                }
                                                                // jQuery parameters are not passed for multi-file modules
                                                                mainScript(
                                 * @param {string} [type='text/javascript'] MIME type to use if calling with a URL of an
                                 *  external script or style; acceptable values are "text/css" and
                                 *  "text/javascript"; if no type is provided, text/javascript is assumed.
+                                * @throws {Error} If type is invalid
                                 */
                                load: function ( modules, type ) {
                                        if ( typeof modules === 'string' && /^(https?:)?\/?\//.test( modules ) ) {
                                                        addScript( modules );
                                                } else {
                                                        // Unknown type
-                                                       throw new Error( 'type must be text/css or text/javascript, found ' + type );
+                                                       throw new Error( 'Invalid type ' + type );
                                                }
                                        } else {
                                                // One or more modules