From: Youngsoo Choi Date: Mon, 12 Aug 2019 04:20:23 +0000 (-0700) Subject: Provide exception console log on browser process X-Git-Tag: accepted/tizen/unified/20190814.021400~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=53f8b906ccef2ce4e40d9e9fce7fa75c2854f0bd;p=platform%2Fframework%2Fweb%2Fwrtjs.git Provide exception console log on browser process This provides nodejs exception console log on browser process and refactors it to be used as a module exception_handling with pid. Change-Id: I7859310070f973bff6ea9814e8b86605847224f5 Signed-off-by: Youngsoo Choi --- diff --git a/wrt_app/browser/wrt.js b/wrt_app/browser/wrt.js index b4fb83f..ea4a675 100755 --- a/wrt_app/browser/wrt.js +++ b/wrt_app/browser/wrt.js @@ -13,25 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +require('../common/exception_handling'); const {wrt} = process.binding('wrt'); -const {EventEmitter} = require('events') -const util = require('util') +const {EventEmitter} = require('events'); +const util = require('util'); -Object.setPrototypeOf(Object.getPrototypeOf(wrt), EventEmitter.prototype) +Object.setPrototypeOf(Object.getPrototypeOf(wrt), EventEmitter.prototype); -module.exports = wrt +module.exports = wrt; console.log = console.error = console.warn = function(...args) { wrt.log(util.format(...args)); }; process.stdout.write = process.stderr.write = function (chunk, encoding, callback) { if (Buffer.isBuffer(chunk)) { - chunk = chunk.toString(encoding) + chunk = chunk.toString(encoding); } - wrt.log(chunk) + wrt.log(chunk); if (callback) { - callback() + callback(); } - return true + return true; } diff --git a/wrt_app/common/exception_handling.js b/wrt_app/common/exception_handling.js new file mode 100644 index 0000000..028846d --- /dev/null +++ b/wrt_app/common/exception_handling.js @@ -0,0 +1,6 @@ +process.on('uncaughtException', function (error) { + // Do nothing if the user has a custom uncaught exception handler. + var ref, stack + stack = (ref = error.stack) != null ? ref : error.name + ': ' + error.message + console.error('A JavaScript error occurred in pid ' + process.pid + '\n' + stack) +}); diff --git a/wrt_app/renderer/init.js b/wrt_app/renderer/init.js index 177283d..57f2e92 100755 --- a/wrt_app/renderer/init.js +++ b/wrt_app/renderer/init.js @@ -14,12 +14,6 @@ * limitations under the License. */ +require('../common/exception_handling'); const wrtRenderer = require('./wrt_renderer'); require(wrtRenderer.getElectronPath() + '/renderer/init') - -process.on('uncaughtException', function (error) { - // Do nothing if the user has a custom uncaught exception handler. - var ref, stack - stack = (ref = error.stack) != null ? ref : error.name + ': ' + error.message - console.error('A JavaScript error occurred in the renderer process\n' + stack) -}) diff --git a/wrt_app/src/main.js b/wrt_app/src/main.js index aa07326..ae0de87 100755 --- a/wrt_app/src/main.js +++ b/wrt_app/src/main.js @@ -16,12 +16,7 @@ 'use strict'; -process.on('uncaughtException', function (error) { - // Do nothing if the user has a custom uncaught exception handler. - var ref, stack - stack = (ref = error.stack) != null ? ref : error.name + ': ' + error.message - console.error('A JavaScript error occurred in the main process\n' + stack) -}) +require('../common/exception_handling'); new (require('./runtime'))({ devMode: false,