Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/180659

Change subject: resourceloader: Make arguments to mw.loader.implement optional
......................................................................

resourceloader: Make arguments to mw.loader.implement optional

This will allow the server to trim any trailing parameters with
empty objects from invocations.

'templates' was the only parameter added after the initial ResourceLoader
release, the other properties have always been required.

Change-Id: Ie32e7d6a3c09f86a52d60394c474a62cb1b4e1d6
---
M resources/src/mediawiki/mediawiki.js
M tests/qunit/suites/resources/mediawiki/mediawiki.test.js
2 files changed, 17 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/59/180659/1

diff --git a/resources/src/mediawiki/mediawiki.js 
b/resources/src/mediawiki/mediawiki.js
index 9235d69..6eb6132 100644
--- a/resources/src/mediawiki/mediawiki.js
+++ b/resources/src/mediawiki/mediawiki.js
@@ -1692,7 +1692,7 @@
                                 * @param {string} module Name of module
                                 * @param {Function|Array} script Function with 
module code or Array of URLs to
                                 *  be used as the src attribute of a new 
`<script>` tag.
-                                * @param {Object} style Should follow one of 
the following patterns:
+                                * @param {Object} [style] Should follow one of 
the following patterns:
                                 *
                                 *     { "css": [css, ..] }
                                 *     { "url": { <media>: [url, ..] } }
@@ -1705,25 +1705,25 @@
                                 * The reason css strings are not concatenated 
anymore is bug 31676. We now check
                                 * whether it's safe to extend the stylesheet 
(see #canExpandStylesheetWith).
                                 *
-                                * @param {Object} msgs List of key/value pairs 
to be added to mw#messages.
+                                * @param {Object} [msgs] List of key/value 
pairs to be added to mw#messages.
                                 * @param {Object} [templates] List of 
key/value pairs to be added to mw#templates.
                                 */
                                implement: function ( module, script, style, 
msgs, templates ) {
                                        // Validate input
                                        if ( typeof module !== 'string' ) {
-                                               throw new Error( 'module must 
be a string, not a ' + typeof module );
+                                               throw new Error( 'module must 
be of type string, not ' + typeof module );
                                        }
                                        if ( !$.isFunction( script ) && 
!$.isArray( script ) ) {
-                                               throw new Error( 'script must 
be a function or an array, not a ' + typeof script );
+                                               throw new Error( 'script must 
be of type function or array, not ' + typeof script );
                                        }
-                                       if ( !$.isPlainObject( style ) ) {
-                                               throw new Error( 'style must be 
an object, not a ' + typeof style );
+                                       if ( style && !$.isPlainObject( style ) 
) {
+                                               throw new Error( 'style must be 
of type object, not ' + typeof style );
                                        }
-                                       if ( !$.isPlainObject( msgs ) ) {
-                                               throw new Error( 'msgs must be 
an object, not a ' + typeof msgs );
+                                       if ( msgs && !$.isPlainObject( msgs ) ) 
{
+                                               throw new Error( 'msgs must be 
of type object, not a ' + typeof msgs );
                                        }
-                                       if ( templates !== undefined && 
!$.isPlainObject( templates ) ) {
-                                               throw new Error( 'templates 
must be an object, not a ' + typeof templates );
+                                       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 ) ) 
{
@@ -1735,8 +1735,8 @@
                                        }
                                        // Attach components
                                        registry[module].script = script;
-                                       registry[module].style = style;
-                                       registry[module].messages = msgs;
+                                       registry[module].style = style || {};
+                                       registry[module].messages = msgs || {};
                                        // Templates are optional (for 
back-compat)
                                        registry[module].templates = templates 
|| {};
                                        // The module may already have been 
marked as erroneous
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js 
b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
index 409f3e6..d415c3c 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
@@ -649,6 +649,11 @@
 
        } );
 
+       QUnit.test( 'mw.loader.implement( only scripts )', 1, function ( assert 
) {
+               mw.loader.implement( 'test.onlyscripts', function () { } );
+               assert.strictEqual( mw.loader.getState( 'test.onlyscripts' ), 
'ready' );
+       } );
+
        QUnit.asyncTest( 'mw.loader.implement( only messages )', 2, function ( 
assert ) {
                assert.assertFalse( mw.messages.exists( 'bug_29107' ), 'Verify 
that the test message doesn\'t exist yet' );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/180659
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie32e7d6a3c09f86a52d60394c474a62cb1b4e1d6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to