Index: gc_core/js/helpers.js ================================================================== --- gc_core/js/helpers.js +++ gc_core/js/helpers.js @@ -1,28 +1,23 @@ // HELPERS "use strict"; -// In Firefox, there is no console.log in PromiseWorker, but there is worker.log. -// In Thunderbird, you can’t access to console directly. So it’s required to pass a log function. -var funcOutput = null; var helpers = { + // In Firefox, there is no console.log in PromiseWorker, but there is worker.log. + // In Thunderbird, you can’t access to console directly. So it’s required to pass a log function. + funcOutput: null, + setLogOutput: function (func) { - try { - funcOutput = func; - } - catch (e) { - func(e); - console.error(e); - } + this.funcOutput = func; }, echo: function (obj) { - if (funcOutput !== null) { - funcOutput(obj); + if (this.funcOutput !== null) { + this.funcOutput(obj); } else { console.log(obj); } return true; }, @@ -30,12 +25,12 @@ logerror: function (e, bStack=false) { let sMsg = "\n" + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message; if (bStack) { sMsg += "\n--- Stack ---\n" + e.stack; } - if (funcOutput !== null) { - funcOutput(sMsg); + if (this.funcOutput !== null) { + this.funcOutput(sMsg); } else { console.error(sMsg); } }, @@ -91,15 +86,15 @@ return obj; } } - if (typeof(exports) !== 'undefined') { + export.funcOutput = helpers.funcOutput; exports.setLogOutput = helpers.setLogOutput; exports.echo = helpers.echo; exports.logerror = helpers.logerror; exports.inspect = helpers.inspect; exports.loadFile = helpers.loadFile; exports.objectToMap = helpers.objectToMap; exports.mapToObject = helpers.mapToObject; }