Avoid "Object has been destroyed" JS error 84/292384/1 tizen_6.0
authorSurya Kumar <surya.kumar7@samsung.com>
Thu, 4 May 2023 12:37:41 +0000 (18:07 +0530)
committerSurya Kumar <surya.kumar7@samsung.com>
Thu, 4 May 2023 12:37:41 +0000 (18:07 +0530)
It's possible mainWindow would be destroyed during suspend,
but addonManager tries to access it without checking it
leading to JS crash. This change fixes it.

Change-Id: Ifbb65e13e290474b7628bc02ccac36a51f8bb367
Signed-off-by: Surya Kumar <surya.kumar7@samsung.com>
wrt_app/src/web_application.ts

index 9695eeb8f3fb63c4b75ac57fc29c170c1826574b..24bfff40360ebb6e7f7810aa611177a114589035 100644 (file)
@@ -345,10 +345,11 @@ Then you can get profile log from the initial loading.`;
     if (this.suspended || this.inQuit)
       return;
     console.log('WebApplication : suspend');
-    addonManager.emit('lcSuspend', this.mainWindow.id);
     this.suspended = true;
-    if (this.windowList.length > 0)
+    if (this.windowList.length > 0) {
+      addonManager.emit('lcSuspend', this.mainWindow.id);
       this.windowList[this.windowList.length - 1].hide();
+    }
     this.flushData();
     if (!this.backgroundRunnable()) {
       if (!this.multitaskingSupport) {
@@ -376,7 +377,10 @@ Then you can get profile log from the initial loading.`;
   finalize() {
     console.log('WebApplication : finalize');
     this.flushData();
-    this.windowList.forEach((window) => window.removeAllListeners());
+    this.windowList.forEach((window) => {
+      window.removeAllListeners();
+      window.setEnabled(false);
+    });
     this.inQuit = false;
     if (!this.suspended)
       this.suspend();
@@ -384,7 +388,8 @@ Then you can get profile log from the initial loading.`;
 
   quit() {
     console.log('WebApplication : quit');
-    addonManager.emit('lcQuit', this.mainWindow.id);
+    if (this.windowList.length > 0)
+      addonManager.emit('lcQuit', this.mainWindow.id);
     if (wrt.tv) {
       this.inspectorSrc = '';
       wrt.tv.cancelDialogs(this.mainWindow.webContents);