Follow-up 4107d1d4: avoid JS errors when trying to call mw.track() from jquery.migrate
authorRoan Kattouw <roan.kattouw@gmail.com>
Mon, 18 Sep 2017 19:24:43 +0000 (12:24 -0700)
committerRoan Kattouw <roan.kattouw@gmail.com>
Mon, 18 Sep 2017 19:24:43 +0000 (12:24 -0700)
Some migrateWarn() calls (like the one for compatMode) happen before
mw is created. Don't crash on trying to call mw.track() in that case.

Change-Id: I9e33af2865bb10adc0473045f714fe4f9f699861

resources/lib/jquery/jquery.migrate.js

index 12212ff..70512e0 100644 (file)
@@ -83,7 +83,9 @@ function migrateWarn( msg ) {
                warnedAbout[ msg ] = true;
                jQuery.migrateWarnings.push( msg );
                // PATCH: Add instrumentation for statistics --Krinkle
                warnedAbout[ msg ] = true;
                jQuery.migrateWarnings.push( msg );
                // PATCH: Add instrumentation for statistics --Krinkle
-               mw.track( "mw.deprecate", "jquery-migrate" );
+               if ( window.mw && window.mw.track ) {
+                       window.mw.track( "mw.deprecate", "jquery-migrate" );
+               }
                if ( console && console.warn && !jQuery.migrateMute ) {
                        console.warn( "JQMIGRATE: " + msg );
                        if ( jQuery.migrateTrace && console.trace ) {
                if ( console && console.warn && !jQuery.migrateMute ) {
                        console.warn( "JQMIGRATE: " + msg );
                        if ( jQuery.migrateTrace && console.trace ) {