From 1e78813c956f4b3e7c7cbb5de9e3b1c55ebef178 Mon Sep 17 00:00:00 2001 From: "surya.kumar7" Date: Tue, 1 Sep 2020 23:13:35 +0530 Subject: [PATCH] [SONARJS] Rectify defects on "delete" & unused objects 1. #444449 & #444450 defects recommend not to use "delete" on arrays 2. #444451 defect recommends using instantiated XWalkExtension() object Change-Id: I0f76e5ef98fbea360efab5cfe607af0708e712f9 Signed-off-by: surya.kumar7 --- wrt_app/service/main.js | 5 +---- wrt_app/src/runtime.js | 14 +++++--------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/wrt_app/service/main.js b/wrt_app/service/main.js index 3ae77a63..a944d4d9 100755 --- a/wrt_app/service/main.js +++ b/wrt_app/service/main.js @@ -22,7 +22,7 @@ const vm = require('vm'); const AccessControlManager = require('./access_control_manager'); const XWalkExtension = require('../common/wrt_xwalk_extension'); -var sandbox = []; +var sandbox = {}; var sandbox_count = 0; var service_source = []; @@ -91,9 +91,6 @@ wrt.on('stop-service', (event, internal_id) => { sandbox[internal_id]['started'] = undefined; const stop_callback_string = 'if (module.exports.onStop !== undefined) { module.exports.onStop(); }'; vm.runInContext(stop_callback_string, sandbox[internal_id]); - for(let key in sandbox[internal_id]) { - delete sandbox[internal_id][key]; - } delete sandbox[internal_id]; if (sandbox_count === 0) { tizen = null; diff --git a/wrt_app/src/runtime.js b/wrt_app/src/runtime.js index 1b4428d6..5534bd34 100755 --- a/wrt_app/src/runtime.js +++ b/wrt_app/src/runtime.js @@ -36,7 +36,7 @@ class Runtime { this.sandbox_count = 0; this.webContents = null; this.addonPkgs = []; - this.extensionInit = false; + this.xwalkExtension = null; var _this = this; app.on('before-quit', function(event) { @@ -95,10 +95,8 @@ class Runtime { if (!options.noAddons) { let addonBuilt = _this.addonManager.build(); console.log("addonBuild : " + addonBuilt.length); - if (!_this.extensionInit && addonBuilt.length) { - new XWalkExtension(); - _this.extensionInit = true; - } + if (!_this.xwalkExtension && addonBuilt.length) + _this.xwalkExtension = new XWalkExtension(); } if (wrt.tv) { wrt.tv.importCertificate(''); @@ -220,10 +218,8 @@ class Runtime { const vm = require('vm'); if (type === 'startService') { if (_this.sandbox[app_id] === undefined) { - if (_this.sandbox_count === 0 && !_this.extensionInit) { - new XWalkExtension(); - _this.extensionInit = true; - } + if (_this.sandbox_count === 0 && !_this.xwalkExtension) + _this.xwalkExtension = new XWalkExtension(); _this.sandbox_count++; const fs = require('fs'); const Module = require('module'); -- 2.34.1