From: Timo Tijhof Date: Sun, 8 Mar 2015 17:38:01 +0000 (+0100) Subject: jsduck: Refactor example iframe to catch uncaught errors X-Git-Tag: 1.31.0-rc.0~12139 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=a64a07d;p=lhc%2Fweb%2Fwiklou.git jsduck: Refactor example iframe to catch uncaught errors * Make logging function not depend on 'mw' existing. * Add window.onerror handler. * Keep exporting to mw.log because that's what existing examples use and is what uses should copy for interoperability with the regular runtime. Change-Id: I2925532035974343125e34084f9ac7c8dd1fa279 --- diff --git a/maintenance/jsduck/eg-iframe.html b/maintenance/jsduck/eg-iframe.html index 0792c2491a..50d7921e3c 100644 --- a/maintenance/jsduck/eg-iframe.html +++ b/maintenance/jsduck/eg-iframe.html @@ -48,9 +48,9 @@ /** * Basic log console for the example iframe in documentation pages. */ - ( function () { + var log = ( function () { var pre; - mw.log = function () { + return function () { var str, i, len, line; if ( !pre ) { pre = document.createElement( 'pre' ); @@ -70,6 +70,14 @@ }; }() ); + if ( window.mw ) { + mw.log = log; + } + + window.onerror = function ( error, filePath, linerNr ) { + log( filePath + ':' + linerNr ); + }; + /** * Method called by jsduck to execute the example code. */ @@ -78,7 +86,7 @@ eval( code ); callback && callback( true ); } catch ( e ) { - mw.log( 'Uncaught ' + e ); + log( 'Uncaught ' + e ); callback && callback( false, e ); throw e; }