* 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
/**
* 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' );
};
}() );
+ if ( window.mw ) {
+ mw.log = log;
+ }
+
+ window.onerror = function ( error, filePath, linerNr ) {
+ log( filePath + ':' + linerNr );
+ };
+
/**
* Method called by jsduck to execute the example code.
*/
eval( code );
callback && callback( true );
} catch ( e ) {
- mw.log( 'Uncaught ' + e );
+ log( 'Uncaught ' + e );
callback && callback( false, e );
throw e;
}