resourceloader: Fix RLQ script to support IE8 quirk
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 4 Aug 2015 23:07:45 +0000 (16:07 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 4 Aug 2015 23:25:11 +0000 (16:25 -0700)
In IE8 there is a race condition. If the window.RLQ runs first (that is, the
startup module loads first) then 'var RLQ' does not get associated
properly to our custom window.RLQ object.

The other way around is fine, but never happens because <script async>
isn't supported in IE8.

Consistently use 'window.RLQ' (never 'var RLQ') to bypass this bug.

Also updating the startup.js file for consistency (though not strictly
needed since the implicit global reference without 'var' also works fine
in IE8.

Bug: T107954
Change-Id: I3f46fee7c4528abf806bb9c51fc767eceb795009

includes/resourceloader/ResourceLoader.php
resources/src/startup.js
tests/phpunit/includes/OutputPageTest.php

index b9bc773..eb28109 100644 (file)
@@ -1380,7 +1380,7 @@ MESSAGE;
         * @return string
         */
        public static function makeLoaderConditionalScript( $script ) {
-               return "var RLQ = RLQ || []; RLQ.push( function () {\n" . trim( $script ) . "\n} );";
+               return "window.RLQ = window.RLQ || []; window.RLQ.push( function () {\n" . trim( $script ) . "\n} );";
        }
 
        /**
@@ -1396,7 +1396,7 @@ MESSAGE;
                $js = self::makeLoaderConditionalScript( $script );
                return new WrappedString(
                        Html::inlineScript( $js ),
-                       "<script>var RLQ = RLQ || []; RLQ.push( function () {\n",
+                       "<script>window.RLQ = window.RLQ || []; window.RLQ.push( function () {\n",
                        "\n} );</script>"
                );
        }
index d4cfa02..3b79bd3 100644 (file)
@@ -84,7 +84,7 @@ function startUp() {
        while ( RLQ.length ) {
                RLQ.shift()();
        }
-       RLQ = {
+       window.RLQ = {
                push: function ( fn ) {
                        fn();
                }
index 6a25d8b..4b90372 100644 (file)
@@ -141,7 +141,7 @@ class OutputPageTest extends MediaWikiTestCase {
                        // Load module script only
                        array(
                                array( 'test.foo', ResourceLoaderModule::TYPE_SCRIPTS ),
-                               "<script>var RLQ = RLQ || []; RLQ.push( function () {\n"
+                               "<script>window.RLQ = 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\u0026*");'
                                        . "\n} );</script>"
                        ),
@@ -160,14 +160,14 @@ class OutputPageTest extends MediaWikiTestCase {
                        // Load private module (only=scripts)
                        array(
                                array( 'test.quux', ResourceLoaderModule::TYPE_SCRIPTS ),
-                               "<script>var RLQ = RLQ || []; RLQ.push( function () {\n"
+                               "<script>window.RLQ = window.RLQ || []; window.RLQ.push( function () {\n"
                                        . "mw.test.baz({token:123});mw.loader.state({\"test.quux\":\"ready\"});\n"
                                        . "\n} );</script>"
                        ),
                        // Load private module (combined)
                        array(
                                array( 'test.quux', ResourceLoaderModule::TYPE_COMBINED ),
-                               "<script>var RLQ = RLQ || []; RLQ.push( function () {\n"
+                               "<script>window.RLQ = 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"
                                        . "\"]});\n\n} );</script>"
@@ -185,10 +185,10 @@ class OutputPageTest extends MediaWikiTestCase {
                        // Load two modules in separate groups
                        array(
                                array( array( 'test.group.foo', 'test.group.bar' ), ResourceLoaderModule::TYPE_COMBINED ),
-                               "<script>var RLQ = RLQ || []; RLQ.push( function () {\n"
+                               "<script>window.RLQ = 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\u0026*");'
                                        . "\n} );</script>\n"
-                                       . "<script>var RLQ = RLQ || []; RLQ.push( function () {\n"
+                                       . "<script>window.RLQ = 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\u0026*");'
                                        . "\n} );</script>"
                        ),