From 47dda77573f27d4126690dfc00df5c10224d1488 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 15 Sep 2015 01:50:32 +0100 Subject: [PATCH] resourceloader: Proxy 'window.performance' to support Safari bug MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- .jshintrc | 2 +- resources/src/mediawiki/mediawiki.js | 2 +- resources/src/startup.js | 19 ++++++++----------- 3 files changed, 10 insertions(+), 13 deletions(-) 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; -- 2.20.1