Fix broken console.error.call in IE9
authorTimo Tijhof <ttijhof@wikimedia.org>
Thu, 28 Jun 2012 12:07:10 +0000 (14:07 +0200)
committerTimo Tijhof <ttijhof@wikimedia.org>
Thu, 28 Jun 2012 12:14:29 +0000 (14:14 +0200)
* 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

index 793cf22..f29a9bd 100644 (file)
@@ -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 );
                                                                }
                                                        }
                                                }