Krinkle has uploaded a new change for review.

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

Change subject: resourceloader: Simplify and cleanup RLQ wrap
......................................................................

resourceloader: Simplify and cleanup RLQ wrap

startup.js:
* Don't assign to "window.RLQ" and read from "RLQ". Use the same
  identifier in both places instead of relying on global scope.
* Create the global window.RLQ only once. The temporary [] fallback
  doesn't need to be exposed globally, so use a local variable for
  the loop that processes the pre-existing queue built up while
  the startup module was loading.

OutputPage:
* Simplify the RLQ wrap to be more idiomatic and less repetitive.
  Matches the pattern used in Google and Facebook open-source projects.

Change-Id: I9176377bc05432e51add841696a356428feec8ce
---
M includes/resourceloader/ResourceLoader.php
M resources/src/startup.js
M tests/phpunit/includes/OutputPageTest.php
3 files changed, 8 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/63/266463/1

diff --git a/includes/resourceloader/ResourceLoader.php 
b/includes/resourceloader/ResourceLoader.php
index 74ee6ab..d7b51b8 100644
--- a/includes/resourceloader/ResourceLoader.php
+++ b/includes/resourceloader/ResourceLoader.php
@@ -1365,7 +1365,7 @@
         * @return string
         */
        public static function makeLoaderConditionalScript( $script ) {
-               return "window.RLQ = window.RLQ || []; window.RLQ.push( 
function () {\n" .
+               return "(window.RLQ = window.RLQ || []).push(function () {\n" .
                        trim( $script ) . "\n} );";
        }
 
@@ -1382,7 +1382,7 @@
                $js = self::makeLoaderConditionalScript( $script );
                return new WrappedString(
                        Html::inlineScript( $js ),
-                       "<script>window.RLQ = window.RLQ || []; 
window.RLQ.push( function () {\n",
+                       "<script>(window.RLQ = window.RLQ || []).push(function 
() {\n",
                        "\n} );</script>"
                );
        }
diff --git a/resources/src/startup.js b/resources/src/startup.js
index 0f51a35..0c2d6d6 100644
--- a/resources/src/startup.js
+++ b/resources/src/startup.js
@@ -87,7 +87,7 @@
 
                // Must be after mw.config.set because these callbacks may use 
mw.loader which
                // needs to have values 'skin', 'debug' etc. from mw.config.
-               window.RLQ = window.RLQ || [];
+               var RLQ = window.RLQ || [];
                while ( RLQ.length ) {
                        RLQ.shift()();
                }
diff --git a/tests/phpunit/includes/OutputPageTest.php 
b/tests/phpunit/includes/OutputPageTest.php
index f5ef016..cfc416b 100644
--- a/tests/phpunit/includes/OutputPageTest.php
+++ b/tests/phpunit/includes/OutputPageTest.php
@@ -142,7 +142,7 @@
                        // Load module script only
                        array(
                                array( 'test.foo', 
ResourceLoaderModule::TYPE_SCRIPTS ),
-                               "<script>window.RLQ = window.RLQ || []; 
window.RLQ.push( function () {\n"
+                               "<script>(window.RLQ = window.RLQ || 
[]).push(function () {\n"
                                        . 
'mw.loader.load("http://127.0.0.1:8080/w/load.php?debug=false\u0026lang=en\u0026modules=test.foo\u0026only=scripts\u0026skin=fallback";);'
                                        . "\n} );</script>"
                        ),
@@ -161,14 +161,14 @@
                        // Load private module (only=scripts)
                        array(
                                array( 'test.quux', 
ResourceLoaderModule::TYPE_SCRIPTS ),
-                               "<script>window.RLQ = window.RLQ || []; 
window.RLQ.push( function () {\n"
+                               "<script>(window.RLQ = window.RLQ || 
[]).push(function () {\n"
                                        . 
"mw.test.baz({token:123});mw.loader.state({\"test.quux\":\"ready\"});\n"
                                        . "} );</script>"
                        ),
                        // Load private module (combined)
                        array(
                                array( 'test.quux', 
ResourceLoaderModule::TYPE_COMBINED ),
-                               "<script>window.RLQ = window.RLQ || []; 
window.RLQ.push( function () {\n"
+                               "<script>(window.RLQ = window.RLQ || 
[]).push(function () {\n"
                                        . 
"mw.loader.implement(\"test.quux\",function($,jQuery){"
                                        . 
"mw.test.baz({token:123});},{\"css\":[\".mw-icon{transition:none}"
                                        . "\"]});\n} );</script>"
@@ -186,10 +186,10 @@
                        // Load two modules in separate groups
                        array(
                                array( array( 'test.group.foo', 
'test.group.bar' ), ResourceLoaderModule::TYPE_COMBINED ),
-                               "<script>window.RLQ = window.RLQ || []; 
window.RLQ.push( function () {\n"
+                               "<script>(window.RLQ = window.RLQ || 
[]).push(function () {\n"
                                        . 
'mw.loader.load("http://127.0.0.1:8080/w/load.php?debug=false\u0026lang=en\u0026modules=test.group.bar\u0026skin=fallback";);'
                                        . "\n} );</script>\n"
-                                       . "<script>window.RLQ = window.RLQ || 
[]; window.RLQ.push( function () {\n"
+                                       . "<script>(window.RLQ = window.RLQ || 
[]).push(function () {\n"
                                        . 
'mw.loader.load("http://127.0.0.1:8080/w/load.php?debug=false\u0026lang=en\u0026modules=test.group.foo\u0026skin=fallback";);'
                                        . "\n} );</script>"
                        ),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9176377bc05432e51add841696a356428feec8ce
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