Ignore TaskQueue::DeleteJobs when worker terminated 32/285532/1
authorDongHyun Song <dh81.song@samsung.com>
Wed, 14 Dec 2022 07:04:10 +0000 (16:04 +0900)
committerPiotr Kosko <p.kosko@samsung.com>
Wed, 14 Dec 2022 07:37:32 +0000 (07:37 +0000)
From Tizen 7.0, tizen.ml is enabled in web worker. Because 'tizen'
and 'xwalk' extensions are loaded on web worker. Global TaskQueue
can be truncated at 'xwalk' instance is deleted.

This singleton TaskQueue should be truncated when main JS context
is destroyed, not by web worker.

Change-Id: I078a7217622d107799a9a47786d1680db5bed5db
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
(cherry picked from commit 3f743e319889eefce19e73b3d181232cde185368)

src/common/extension.h
src/utils/utils_api.js
src/utils/utils_instance.cc
src/utils/utils_instance.h

index 7e6cf3f..6c5d916 100644 (file)
@@ -114,11 +114,17 @@ class Instance {
 
   virtual void HandleBinaryMessage(const char* msg, size_t size) = 0;
   virtual void HandleSyncBinaryMessage(const char* msg, size_t size) = 0;
+  virtual void SetWebWorker(bool worker) {
+    is_web_worker_ = worker;
+  }
 
   XW_Instance xw_instance() const {
     return xw_instance_;
   }
 
+ protected:
+  bool is_web_worker_ = false;
+
  private:
   friend class Extension;
 
index 7d184af..f580950 100644 (file)
@@ -1734,6 +1734,9 @@ Utils.prototype.exportModuleIfFeatureSupported = exportModuleIfFeatureSupported;
 Utils.prototype.ArrayBufferParser = ArrayBufferParser;
 
 var native_ = new NativeManager(extension);
+if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
+    native_.callSync('UtilsSetWorkerScope', {});
+}
 
 exports.utils = new Utils();
 
index e90f8b2..65edc0d 100644 (file)
@@ -31,6 +31,7 @@ UtilsInstance::UtilsInstance() {
   REGISTER_METHOD(UtilsToLongLong);
   REGISTER_METHOD(UtilsToUnsignedLongLong);
   REGISTER_METHOD(UtilsCheckProfile);
+  REGISTER_METHOD(UtilsSetWorkerScope);
 #undef REGISTER_METHOD
 }
 
@@ -129,5 +130,13 @@ void UtilsInstance::UtilsCheckProfile(const picojson::value& args, picojson::obj
   ReportSuccess(picojson::value(profile), out);
 }
 
+void UtilsInstance::UtilsSetWorkerScope(const picojson::value& args, picojson::object& out) {
+  ScopeLogger();
+
+  SetWebWorker(true);
+
+  ReportSuccess(picojson::value(true), out);
+}
+
 }  // namespace utils
 }  // namespace extension
index 5708a92..71f013d 100644 (file)
@@ -18,7 +18,9 @@ class UtilsInstance : public common::ParsedInstance {
   virtual ~UtilsInstance() {
     // At this point, frame of the page is destroyed or reloaded, so all the jobs have to be
     // removed.
-    common::TaskQueue::GetInstance().DeleteJobs();
+    if (!is_webworker_) {
+      common::TaskQueue::GetInstance().DeleteJobs();
+    }
   }
 
  private:
@@ -30,6 +32,7 @@ class UtilsInstance : public common::ParsedInstance {
   void UtilsToLongLong(const picojson::value& args, picojson::object& out);
   void UtilsToUnsignedLongLong(const picojson::value& args, picojson::object& out);
   void UtilsCheckProfile(const picojson::value& args, picojson::object& out);
+  void UtilsSetWorkerScope(const picojson::value& args, picojson::object& out);
 };
 }  // namespace utils
 }  // namespace extension