From: Timo Tijhof Date: Tue, 15 Sep 2015 00:50:32 +0000 (+0100) Subject: resourceloader: Proxy 'window.performance' to support Safari bug X-Git-Tag: 1.31.0-rc.0~10026 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/voir.php?a=commitdiff_plain;h=47dda77573f27d4126690dfc00df5c10224d1488;p=lhc%2Fweb%2Fwiklou.git resourceloader: Proxy 'window.performance' to support Safari bug Follows-up 5b0749d, which first introduced a call to performance.mark outside of startup.js – thus triggering this excotic bug in Safari. In Safari the native thread MAY (emphasis on MAY) decide at any point to recreate window.performance and blow away any previously succesfully attached properties. Bug: T112287 Change-Id: I653e580566da5335d34f1cf1ef52f51ceee2cf5a --- diff --git a/.jshintrc b/.jshintrc index b84d276621..b776e8f21a 100644 --- a/.jshintrc +++ b/.jshintrc @@ -22,7 +22,7 @@ "mediaWiki": true, "JSON": true, "OO": true, - "performance": true, + "mwPerformance": true, "jQuery": false, "QUnit": false, "sinon": false diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index c6e41c45b3..af89b9a8b9 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -2599,7 +2599,7 @@ } ); } ); $.when.apply( $, loading ).then( function () { - performance.mark( 'mwLoadEnd' ); + mwPerformance.mark( 'mwLoadEnd' ); mw.hook( 'resourceloader.loadEnd' ).fire(); } ); } ); diff --git a/resources/src/startup.js b/resources/src/startup.js index 97b4fce258..1a10f8379e 100644 --- a/resources/src/startup.js +++ b/resources/src/startup.js @@ -3,16 +3,16 @@ * continue loading jQuery and the MediaWiki modules. This code should work on * even the most ancient of browsers, so be very careful when editing. */ +/*jshint unused: false, evil: true */ +/*globals mw, RLQ: true, $VARS, $CODE, performance */ -var mediaWikiLoadStart = ( new Date() ).getTime(); +var mediaWikiLoadStart = ( new Date() ).getTime(), -if ( !window.performance ) { - window.performance = {}; -} -if ( !performance.mark ) { - performance.mark = function () {}; -} -performance.mark( 'mwLoadStart' ); + mwPerformance = ( window.performance && performance.mark ) ? performance : { + mark: function () {} + }; + +mwPerformance.mark( 'mwLoadStart' ); /** * Returns false for Grade C supported browsers. @@ -24,9 +24,6 @@ performance.mark( 'mwLoadStart' ); * - https://www.mediawiki.org/wiki/Compatibility#Browsers * - https://jquery.com/browser-support/ */ - -/*jshint unused: false, evil: true */ -/*globals mw, RLQ: true, $VARS, $CODE */ function isCompatible( ua ) { if ( ua === undefined ) { ua = navigator.userAgent;