Merge "resoureloader: Restore support for plain callbacks in mediawiki.base's RLQ"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 27 Oct 2018 04:03:43 +0000 (04:03 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 27 Oct 2018 04:03:43 +0000 (04:03 +0000)
resources/src/mediawiki.base/mediawiki.base.js
resources/src/startup/startup.js
tests/qunit/suites/resources/mediawiki/mediawiki.base.test.js

index 5820b83..8a44dcc 100644 (file)
        mw.log.deprecate( window, '$j', $, 'Use $ or jQuery instead.' );
 
        // Process callbacks for Grade A that require modules.
-       // Plain ones were already processed by startup.js.
        queue = window.RLQ;
-       // Redefine publicly to capture any late arrivals
+       // Replace temporary RLQ implementation from startup.js with the
+       // final implementation that also processes callbacks that can
+       // require modules. It must also support late arrivals of
+       // plain callbacks. (T208093)
        window.RLQ = {
                push: function ( entry ) {
-                       mw.loader.using( entry[ 0 ], entry[ 1 ] );
+                       if ( typeof entry === 'function' ) {
+                               entry();
+                       } else {
+                               mw.loader.using( entry[ 0 ], entry[ 1 ] );
+                       }
                }
        };
        while ( queue[ 0 ] ) {
index 5483ad2..bebf4dc 100644 (file)
@@ -118,9 +118,10 @@ if ( !isCompatible() ) {
                mw.config.set( $VARS.configuration );
 
                // Process callbacks for Grade A
-               // Must be after registrations and mw.config.set, which mw.loader depends on.
                var queue = window.RLQ;
-               // Redefine push(), but keep type as array for storing callbacks that require modules.
+               // Replace RLQ placeholder from ResourceLoaderClientHtml with an implementation
+               // that executes simple callbacks, but continues to store callbacks that require
+               // modules.
                window.RLQ = [];
                /* global RLQ */
                RLQ.push = function ( fn ) {
@@ -132,7 +133,7 @@ if ( !isCompatible() ) {
                        }
                };
                while ( queue && queue[ 0 ] ) {
-                       // Re-use our push()
+                       // Re-use our new push() method
                        RLQ.push( queue.shift() );
                }
 
index 33423d8..b8f0d12 100644 (file)
        QUnit.test( 'RLQ.push', function ( assert ) {
                /* global RLQ */
                var loaded = 0,
+                       called = 0,
                        done = assert.async();
                mw.loader.testCallback = function () {
                        loaded++;
                        delete mw.loader.testCallback;
                };
-               mw.loader.implement( 'test.rlq-push', [ QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/mwLoaderTestCallback.js' ) ] );
+               mw.loader.implement( 'test.rlq-push', [
+                       QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/mwLoaderTestCallback.js' )
+               ] );
+
+               // Regression test for T208093
+               RLQ.push( function () {
+                       called++;
+               } );
+               assert.strictEqual( called, 1, 'Invoke plain callbacks' );
 
                RLQ.push( [ 'test.rlq-push', function () {
                        assert.strictEqual( loaded, 1, 'Load the required module' );