Revert "[Service] Call destroy() of FunctionTemplate" 47/265647/1
authorwei li <wei90727.li@samsung.com>
Tue, 26 Oct 2021 06:19:54 +0000 (06:19 +0000)
committerwei li <wei90727.li@samsung.com>
Tue, 26 Oct 2021 06:19:54 +0000 (06:19 +0000)
This reverts commit dc19d94f302de3e48620be09b4a09e876cfeabc7.

Change-Id: Ibe9a5392d70d55425bf8cab7a6355bbd0bb26757

wrt_app/common/wrt_xwalk_extension.ts
wrt_app/service/device_api_router.ts
wrt_app/service/service_runner.ts

index 9ea29f4..4e32394 100644 (file)
@@ -26,14 +26,13 @@ let extensions_: { [key: string]: NativeXWalkExtension } = {};
 global.window = global.window ?? global;
 
 class XWalkExtension {
-  extensions: NativeXWalkExtension[] =
-      process.wrtBinding('wrt_xwalk_extension').getExtensions();
-
   constructor() {
-    for (var i = 0; i < this.extensions.length; i++) {
-      this.extensions[i].loaded = false;
-      console.debug("Load extension : " + this.extensions[i].name);
-      extensions_[this.extensions[i].name] = this.extensions[i];
+    const binding: NativeWRTjs.XWalkExtensionBinding = process.wrtBinding('wrt_xwalk_extension')
+    var extensions: NativeXWalkExtension[] = binding.getExtensions();
+    for (var i = 0; i < extensions.length; i++) {
+      extensions[i].loaded = false;
+      console.debug("Load extension : " + extensions[i].name);
+      extensions_[extensions[i].name] = extensions[i];
     }
     for (var name in extensions_) {
       if (!extensions_[name].use_trampoline) {
@@ -219,11 +218,6 @@ class XWalkExtension {
       delete global[parent_name][base_name];
     }
   }
-
-  destory() {
-    for (var i = 0; i < this.extensions.length; i++)
-      this.extensions[i].destroy();
-  }
 }
 
 export const initialize = () => {
@@ -236,7 +230,6 @@ export const setRuntimeMessageHandler = (handler: (type: string, data?: string,
 }
 
 export let cleanup = () => {
-  instance?.destory();
   delete global.tizen;
   instance = undefined;
 }
index 955fc7d..98cbe03 100644 (file)
@@ -349,13 +349,3 @@ export class DeviceAPIRouter {
     }
   }
 }
-
-let instance: DeviceAPIRouter | undefined;
-export const initialize = (id: string, isGlobal: boolean) => {
-  instance = new DeviceAPIRouter(id, isGlobal);
-}
-
-export const cleanup = () => {
-  delete global.webapis;
-  instance = undefined;
-}
\ No newline at end of file
index d3a47f3..d110017 100644 (file)
@@ -1,9 +1,14 @@
 import '../common/init';
 import * as XWalkExtension from '../common/wrt_xwalk_extension';
-import * as DeviceAPIRouter from './device_api_router';
+import { DeviceAPIRouter } from './device_api_router';
 import { isMainThread, parentPort, workerData } from 'worker_threads';
 import { wrt } from '../browser/wrt';
 
+Object.defineProperty(global, 'serviceType', {
+  value: wrt.getServiceModel(),
+  writable: false
+});
+
 function isServiceApplication() {
   return global['serviceType'] !== 'UI';
 }
@@ -62,8 +67,7 @@ let checkLauncherAlive = (id: string) => {
   }
 }
 
-function start(id: string, filename: string) {
-  wrt.tv?.serviceMount(id);
+export function start(id: string, filename: string) {
   let ids = id.split(':');
   let serviceId = ids[0];
   let packageId = wrt.getPackageId(id);
@@ -84,7 +88,7 @@ function start(id: string, filename: string) {
   });
 
   console.debug(`serviceType : ${global['serviceType']}`)
-  DeviceAPIRouter.initialize(id, isGlobalService());
+  new DeviceAPIRouter(id, isGlobalService());
   printAppControlData(id);
 
   // This is for awaking up uv loop.
@@ -118,7 +122,7 @@ function start(id: string, filename: string) {
   }
 }
 
-function stop(id: string) {
+export function stop(id: string) {
   if (dummyTimer)
     clearInterval(dummyTimer);
   try {
@@ -135,35 +139,19 @@ function stop(id: string) {
   }
 }
 
-function destroy(id: string) {
-  XWalkExtension.cleanup();
-  DeviceAPIRouter.cleanup();
-  wrt.tv?.serviceUmount(id);
-
-  wrt.edge?.destroy(); delete wrt.edge;
-  wrt.mde?.destroy(); delete wrt.mde;
-  wrt.security?.destroy(); delete wrt.security;
-  wrt.tv?.destroy(); delete wrt.tv;
-  wrt.destroy();
-}
-
 function run() {
   let id = workerData.id;
   if (!id) {
     console.debug('workerData.id is empty!');
     process.exit();
   }
-  Object.defineProperties(global, {
-    'serviceType': {
-      value: wrt.getServiceModel(),
-      writable: false
-    },
-    'internalId': {
-      value: id,
-      writable: false
-    }
+
+  Object.defineProperty(global, 'internalId', {
+    value: id,
+    writable: false
   });
 
+  wrt.tv?.serviceMount(id);
   let filename = workerData.filename;
   start(id, filename);
 
@@ -174,9 +162,10 @@ function run() {
     } else if (message.type === 'stop') {
       stop(id);
       setTimeout(() => {
-        destroy(id);
+        XWalkExtension.cleanup();
         parentPort?.postMessage("will-terminate");
         parentPort?.close();
+        wrt.tv?.serviceUmount(id);
       }, message.delay);
     }
   });