From: Timo Tijhof Date: Tue, 26 Jun 2018 17:22:26 +0000 (+0100) Subject: mediawiki.inspect: Fix exception when calling mw.inspect() a second time X-Git-Tag: 1.34.0-rc.0~4947^2 X-Git-Url: http://git.cyclocoop.org///%22%40url%40//%22?a=commitdiff_plain;h=2e1b3f94ad3620c87d8f5587576628a56556054e;p=lhc%2Fweb%2Fwiklou.git mediawiki.inspect: Fix exception when calling mw.inspect() a second time In mediawiki.js, the mw.inspect() method is defined to lazy-load the 'mediawiki.inspect' module, and then call mw.inspect.runReports(). The problem is that, mediawiki.inspect.js, re-creates mw.inspect as a plain object, which blows away the mw.inspect() function that was there. Calling it a second time threw "TypeError: inspect is not a function". Fix this by making mediawiki.inspect.js extend the function object, instead of re-defining it. Bug: T197810 Change-Id: I61aa965f3e1fd0a1c9f9d98310632b4a8d5e1683 --- diff --git a/resources/src/mediawiki.inspect.js b/resources/src/mediawiki.inspect.js index cf94083676..e2030c9e55 100644 --- a/resources/src/mediawiki.inspect.js +++ b/resources/src/mediawiki.inspect.js @@ -1,5 +1,5 @@ /*! - * Tools for inspecting page composition and performance. + * The mediawiki.inspect module. * * @author Ori Livneh * @since 1.22 @@ -9,7 +9,19 @@ ( function ( mw, $ ) { - var inspect, + // mw.inspect is a singleton class with static methods + // that itself can also be invoked as a function (mediawiki.base/mw#inspect). + // In JavaScript, that is implemented by starting with a function, + // and subsequently setting additional properties on the function object. + + /** + * Tools for inspecting page composition and performance. + * + * @class mw.inspect + * @singleton + */ + + var inspect = mw.inspect, byteLength = require( 'mediawiki.String' ).byteLength, hasOwn = Object.prototype.hasOwnProperty; @@ -32,12 +44,6 @@ return bytes.toFixed( i > 0 ? 1 : 0 ) + units[ i ]; } - /** - * @class mw.inspect - * @singleton - */ - inspect = {}; - /** * Return a map of all dependency relationships between loaded modules. * @@ -332,6 +338,4 @@ mw.log( 'mw.inspect: reports are not available in debug mode.' ); } - mw.inspect = inspect; - }( mediaWiki, jQuery ) );