mediawiki.js: Show line number of caller of mw.log.warn and .error
authorFomafix <fomafix@googlemail.com>
Sat, 17 Oct 2015 17:49:31 +0000 (17:49 +0000)
committerBartosz Dziewoński <matma.rex@gmail.com>
Sat, 17 Oct 2015 20:27:21 +0000 (20:27 +0000)
Currently the JavaScript console shows the line number from mediawiki.js
where the function mw.log.warn is defined.
With this change the JavaScript console shows the file and the line number
where the function mw.log.warn is called.

Inspirited by https://matthewspencer.github.io/console-log/

Change-Id: I2345333fc0158a66ebcb3abf0e94e6e622b3bdc0

resources/src/mediawiki/mediawiki.js

index 12d698b..568bfd4 100644 (file)
                log: ( function () {
                        // Also update the restoration of methods in mediawiki.log.js
                        // when adding or removing methods here.
-                       var log = function () {};
+                       var log = function () {},
+                               console = window.console;
 
                        /**
                         * @class mw.log
                         *
                         * @param {...string} msg Messages to output to console
                         */
-                       log.warn = function () {
-                               var console = window.console;
-                               if ( console && console.warn && console.warn.apply ) {
-                                       console.warn.apply( console, arguments );
-                               }
-                       };
+                       log.warn = console && console.warn && Function.prototype.bind ?
+                               Function.prototype.bind.call( console.warn, console ) :
+                               $.noop;
 
                        /**
                         * Write a message the console's error channel.
                         * @since 1.26
                         * @param {Error|...string} msg Messages to output to console
                         */
-                       log.error = function () {
-                               var console = window.console;
-                               if ( console && console.error && console.error.apply ) {
-                                       console.error.apply( console, arguments );
-                               }
-                       };
+                       log.error = console && console.error && Function.prototype.bind ?
+                               Function.prototype.bind.call( console.error, console ) :
+                               $.noop;
 
                        /**
                         * Create a property in a host object that, when accessed, will produce