From 3520066a716b868e8eb7f182600e601007dd458d Mon Sep 17 00:00:00 2001 From: Matthew Flaschen Date: Fri, 11 Jul 2014 00:40:40 -0400 Subject: [PATCH] mw.Debug.profile: Tweak support check to handle PhantomJS * Latest PhantomJS (1.9.7) supports Array.prototype.map, Array.prototype.reduce, Array.prototype.filter, and document.createElementNS, but not Function.prototype.bind * Check all of these in the init function, and if they're available continue (unless there's no profiling data) and initialize this.createSvgElement (previously done inline) * Accordingly, rename buildRequiresES5 to buildRequiresBrowserFeatures and tweak message Change-Id: If464b1093ec445afbb6c6b8c230e0e2669ad8c5c --- .../src/mediawiki/mediawiki.debug.profile.js | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/resources/src/mediawiki/mediawiki.debug.profile.js b/resources/src/mediawiki/mediawiki.debug.profile.js index 7bbbbd39d0..04f7acd012 100644 --- a/resources/src/mediawiki/mediawiki.debug.profile.js +++ b/resources/src/mediawiki/mediawiki.debug.profile.js @@ -37,11 +37,21 @@ // only drop events if requested dropThresholdPx = dropThresholdPx || 0; - if ( !Array.prototype.map || !Array.prototype.reduce || !Array.prototype.filter ) { - profile.container = profile.buildRequiresES5(); + if ( + !Array.prototype.map || + !Array.prototype.reduce || + !Array.prototype.filter || + !document.createElementNS || + !document.createElementNS.bind + ) { + profile.container = profile.buildRequiresBrowserFeatures(); } else if ( data.length === 0 ) { profile.container = profile.buildNoData(); } else { + // Initialize createSvgElement (now that we know we have + // document.createElementNS and bind) + this.createSvgElement = document.createElementNS.bind( document, 'http://www.w3.org/2000/svg' ); + // generate a flyout profile.data = new ProfileData( data, profile.width, mergeThresholdPx, dropThresholdPx ); // draw it @@ -52,9 +62,9 @@ return profile.container; }, - buildRequiresES5: function () { + buildRequiresBrowserFeatures: function () { return $( '
' ) - .text( 'An ES5 compatible javascript engine is required for the profile visualization.' ) + .text( 'Certain browser features, including parts of ECMAScript 5 and document.createElementNS, are required for the profile visualization.' ) .get( 0 ); }, @@ -66,14 +76,12 @@ /** * Creates DOM nodes appropriately namespaced for SVG. + * Initialized in init after checking support * * @param string tag to create * @return DOMElement */ - createSvgElement: ( document.createElementNS && Function.prototype.bind ) - ? document.createElementNS.bind( document, 'http://www.w3.org/2000/svg' ) - // throw a error for browsers which does not support document.createElementNS (IE<8) - : function () { throw new Error( 'An ES5 compatible javascript engine is required for the profile visualization.' ); }, + createSvgElement: null, /** * @param DOMElement|undefined -- 2.20.1