Merge "Verify parameter for MapCacheLRU::has() can be passed to array_key_exists()"
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.errorLogger.js
1 /**
2 * Try to catch errors in modules which don't do their own error handling.
3 * @class mw.errorLogger
4 * @singleton
5 */
6 ( function ( mw ) {
7 'use strict';
8
9 mw.errorLogger = {
10 /**
11 * Fired via mw.track when an error is not handled by local code and is caught by the
12 * window.onerror handler.
13 *
14 * @event global_error
15 * @param {string} errorMessage Error errorMessage.
16 * @param {string} url URL where error was raised.
17 * @param {number} lineNumber Line number where error was raised.
18 * @param {number} [columnNumber] Line number where error was raised. Not all browsers
19 * support this.
20 * @param {Error|Mixed} [errorObject] The error object. Typically an instance of Error, but anything
21 * (even a primitive value) passed to a throw clause will end up here.
22 */
23
24 /**
25 * Install a window.onerror handler that will report via mw.track, while preserving
26 * any previous handler.
27 * @param {Object} window
28 */
29 installGlobalHandler: function ( window ) {
30 // We will preserve the return value of the previous handler. window.onerror works the
31 // opposite way than normal event handlers (returning true will prevent the default
32 // action, returning false will let the browser handle the error normally, by e.g.
33 // logging to the console), so our fallback old handler needs to return false.
34 var oldHandler = window.onerror || function () { return false; };
35
36 /**
37 * Dumb window.onerror handler which forwards the errors via mw.track.
38 * @fires global_error
39 */
40 window.onerror = function ( errorMessage, url, lineNumber, columnNumber, errorObject ) {
41 mw.track( 'global.error', { errorMessage: errorMessage, url: url,
42 lineNumber: lineNumber, columnNumber: columnNumber, errorObject: errorObject } );
43 return oldHandler.apply( this, arguments );
44 };
45 }
46 };
47
48 mw.errorLogger.installGlobalHandler( window );
49 }( mediaWiki ) );