mediawiki.inspect: use $.toJSON & add workaround for FF oddity
authorOri Livneh <ori@wikimedia.org>
Thu, 24 Oct 2013 00:37:21 +0000 (17:37 -0700)
committerOri Livneh <ori@wikimedia.org>
Thu, 24 Oct 2013 00:37:21 +0000 (17:37 -0700)
* Use $.toJSON rather than JSON.stringify. Make mediawiki.inspect depend on
  jquery.json.
* Firefox doesn't define a console.table, but doesn't throw an exception either
  if you attempt to invoke it. Use Function.prototype#call to call Firefox's
  bluff.

Change-Id: Ib45487d10488f08a98d9635ab9a2a9212e9ef69f

resources/Resources.php
resources/mediawiki/mediawiki.inspect.js

index c033647..2c02de8 100644 (file)
@@ -655,7 +655,10 @@ return array(
        ),
        'mediawiki.inspect' => array(
                'scripts' => 'resources/mediawiki/mediawiki.inspect.js',
-               'dependencies' => 'jquery.byteLength',
+               'dependencies' => array(
+                       'jquery.byteLength',
+                       'jquery.json',
+               ),
                'targets' => array( 'desktop', 'mobile' ),
        ),
        'mediawiki.feedback' => array(
index 8268f12..c895adf 100644 (file)
                        try {
                                // Bartosz made me put this here.
                                if ( window.opera ) { throw window.opera; }
-                               console.table( data );
+                               // Use Function.prototype#call to force an exception on Firefox,
+                               // which doesn't define console#table but doesn't complain if you
+                               // try to invoke it.
+                               console.table.call( console.table, data );
                                return;
                        } catch (e) {}
                        try {
-                               console.log( JSON.stringify( data, null, 2 ) );
+                               console.log( $.toJSON( data, null, 2 ) );
                                return;
                        } catch (e) {}
                        mw.log( data );