From: Youngsoo Choi Date: Mon, 12 Aug 2019 02:03:05 +0000 (-0700) Subject: [WRT Service] Provide sandbox context per servcie app and support legacy APIs X-Git-Tag: submit/tizen/20190829.041451~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=27657bc4db89f5f6fd2beb799c6a05503c5d25f0;p=platform%2Fframework%2Fweb%2Fwrtjs.git [WRT Service] Provide sandbox context per servcie app and support legacy APIs This provides sandbox context per service application and supports onStart and onRequest legacy APIs on single nodejs instance. Change-Id: Ia2552c77385bee09ca231a9b70272311c9993724 Signed-off-by: Youngsoo Choi --- diff --git a/wrt_app/service/main.js b/wrt_app/service/main.js index 6a99f557..9b1edad6 100755 --- a/wrt_app/service/main.js +++ b/wrt_app/service/main.js @@ -18,12 +18,26 @@ const wrt = require('../browser/wrt'); const vm = require('vm'); +var sandbox = []; -wrt.on('start-service', (event, appID) => { - console.log('start service app : ' + appID); - let sandbox = { console: console }; - let options = { filename: appID }; - vm.runInNewContext(wrt.readService(appID), sandbox, options); +wrt.on('start-service', (event, app_id) => { + console.log('start service app : ' + app_id); + if (sandbox[app_id] === undefined) { + sandbox[app_id] = { + console: console, + module: module, + require: require, + }; + let options = { filename: app_id }; + vm.runInNewContext(wrt.readService(app_id), sandbox[app_id], options); + } + if (sandbox[app_id]['started'] === undefined) { + sandbox[app_id]['started'] = true; + const start_callback_string = 'if (module.exports.onStart !== undefined) { module.exports.onStart(); }'; + vm.runInContext(start_callback_string, sandbox[app_id]); + } + const request_callback_string = 'if (module.exports.onRequest !== undefined) { module.exports.onRequest(); }'; + vm.runInContext(request_callback_string, sandbox[app_id]); if (!wrt.terminateClient(app_id)) { console.log('Failed to terminate client process'); }