From 348de7a7b8e2b11c2de192be9d3c94641f8cfb69 Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Wed, 23 Oct 2013 17:37:21 -0700 Subject: [PATCH] mediawiki.inspect: use $.toJSON & add workaround for FF oddity * 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 | 5 ++++- resources/mediawiki/mediawiki.inspect.js | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/resources/Resources.php b/resources/Resources.php index c0336472d6..2c02de88da 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -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( diff --git a/resources/mediawiki/mediawiki.inspect.js b/resources/mediawiki/mediawiki.inspect.js index 8268f12c61..c895adfb8b 100644 --- a/resources/mediawiki/mediawiki.inspect.js +++ b/resources/mediawiki/mediawiki.inspect.js @@ -101,11 +101,14 @@ 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 ); -- 2.20.1