resourceloader: Proxy 'window.performance' to support Safari bug
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 15 Sep 2015 00:50:32 +0000 (01:50 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 15 Sep 2015 00:55:24 +0000 (01:55 +0100)
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
resources/src/mediawiki/mediawiki.js
resources/src/startup.js

index b84d276..b776e8f 100644 (file)
--- a/.jshintrc
+++ b/.jshintrc
@@ -22,7 +22,7 @@
                "mediaWiki": true,
                "JSON": true,
                "OO": true,
-               "performance": true,
+               "mwPerformance": true,
                "jQuery": false,
                "QUnit": false,
                "sinon": false
index c6e41c4..af89b9a 100644 (file)
                        } );
                } );
                $.when.apply( $, loading ).then( function () {
-                       performance.mark( 'mwLoadEnd' );
+                       mwPerformance.mark( 'mwLoadEnd' );
                        mw.hook( 'resourceloader.loadEnd' ).fire();
                } );
        } );
index 97b4fce..1a10f83 100644 (file)
@@ -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;