From 605ebb52872e4ab53f64588108d258e08bb8ea01 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 28 Jun 2012 14:07:10 +0200 Subject: [PATCH] Fix broken console.error.call in IE9 * It turns out IE9 throws up on console.error.call ("TypeError: Object does not property method 'call'.") Which is problematic since module handlers that catch exceptions and try to log them, now still get a global uncaught exception. Luckily it only affected users of IE9 that have DevTools installed locally -and- were on a page with module that throws an exception. * Follows-up 4c80300499d783333e24331f7c5a368ecf24c3bf * Now just not logging the exception object if there is no console.error. Pretty much every console has it, and when they don't, then having the exception object is likely not going to help either. Not to confuse with mw.log, which is elaborate cross-browser fallbacks and always shows all information in the browser somehow. This is for logging errors without debug mode. Change-Id: I1bf6c6f963ca64182dd447bebc0e6751bce325ae --- resources/mediawiki/mediawiki.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 793cf225ed..f29a9bd377 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -637,10 +637,12 @@ var mw = ( function ( $, undefined ) { var console = window.console; if ( console && console.log ) { console.log( msg ); - // console.error triggers the proper handling of exception objects in - // consoles that support it. Fallback to passing as plain object to log(). - if ( e ) { - (console.error || console.log).call( console, e ); + // If we have an exception object, log it through .error() to trigger + // proper stacktraces in browsers that support it. There are no (known) + // browsers that don't support .error(), that do support .log() and + // have useful exception handling through .log(). + if ( e && console.error ) { + console.error( e ); } } } @@ -697,7 +699,7 @@ var mw = ( function ( $, undefined ) { } catch ( ex ) { // A user-defined operation raised an exception. Swallow to protect // our state machine! - log( 'mw.loader::handlePending> Exception thrown by job.error()', ex ); + log( 'Exception thrown by job.error()', ex ); } } } -- 2.20.1