diff --git a/README.md b/README.md index ef33b3898c98ddbe56d1d71d3cac8917de9e1259..eaab4b369821af47ed7c26d65987205518455d62 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,7 @@ worker.on("alert", (e)=>{ - name -| once(type:string, listener:EventListener) | Adds an event listener to the worker and - removes the event listener automically after it is invoked once | +| once(type:string, listener:EventListener) | Adds an event listener to the worker and removes the event listener automically after it is invoked once | |---|---| - example @@ -166,8 +165,7 @@ worker.removeAllListener(); - name -| onexit?:(code:number)=>void | The onexit attribute of the worker specifies the event handler to be called - when the worker exits. The handler is executed in the host thread | +| onexit?:(code:number)=>void | The onexit attribute of the worker specifies the event handler to be called when the worker exits. The handler is executed in the host thread | |---|---| - example @@ -184,8 +182,7 @@ worker.onexit = function(e) { - name -| onerror?:(ev:ErrorEvent)=>void | The onerror attribute of the worker specifies the event handler to be called - when an exception occurs during worker execution. The event handler is executed in the host thread | +| onerror?:(ev:ErrorEvent)=>void | The onerror attribute of the worker specifies the event handler to be called when an exception occurs during worker execution. The event handler is executed in the host thread | |---|---| - example @@ -202,9 +199,7 @@ worker.onerror = function(e) { - name -| onmessage?:(ev:MessageEvent)=>void | The onmessage attribute of the worker specifies the event handler to be called - then the host thread receives a message created by itself and sent by the worker through the parentPort.postMessage. - The event handler is executed in the host thread | +| onmessage?:(ev:MessageEvent)=>void | The onmessage attribute of the worker specifies the event handler to be called then the host thread receives a message created by itself and sent by the worker through the parentPort.postMessage. The event handler is executed in the host thread | |---|---| - example @@ -221,8 +216,7 @@ worker.onmessage = function(e) { - name -| onmessageerror?:(event:MessageEvent)=>void | The onmessage attribute of the worker specifies the event handler - when the worker receives a message that cannot be serialized. The event handler is executed in the host thread | +| onmessageerror?:(event:MessageEvent)=>void | The onmessage attribute of the worker specifies the event handler when the worker receives a message that cannot be serialized. The event handler is executed in the host thread | |---|---| - example @@ -294,9 +288,7 @@ parentPort.onmessage = function(e) { - name -| onmessage?:(event:MessageEvent)=>void | The onmessage attribute of parentPort specifies the event handler to be called - then the worker thread receives a message sent by the host thread through worker postMessage. - The event handler is executed in the worker thread | +| onmessage?:(event:MessageEvent)=>void | The onmessage attribute of parentPort specifies the event handler to be called then the worker thread receives a message sent by the host thread through worker postMessage. The event handler is executed in the worker thread | |---|---| - example @@ -319,8 +311,7 @@ parentPort.onmessage = function(e) { - name -| onerror?:(ev: ErrorEvent)=>void | The onerror attribute of parentPort specifies the event handler to be called - when an exception occurs during worker execution. The event handler is executed in the worker thread | +| onerror?:(ev: ErrorEvent)=>void | The onerror attribute of parentPort specifies the event handler to be called when an exception occurs during worker execution. The event handler is executed in the worker thread | |---|---| - example @@ -344,8 +335,7 @@ parentPort.onerror = function(e) { - name -| onmessageerror?:(event: MessageEvent)=>void | The onmessage attribute of parentPort specifies the event handler to be called - then the worker receives a message that cannot be deserialized. The event handler is executed in the worker thread. | +| onmessageerror?:(event: MessageEvent)=>void | The onmessage attribute of parentPort specifies the event handler to be called then the worker receives a message that cannot be deserialized. The event handler is executed in the worker thread. | |---|---| - example @@ -366,8 +356,11 @@ parentPort.onmessageerror = function(e) { ### Repositories Involved -- ace_ace_engine -- ace_napi +- ace_ace_engine(foundation/ace/ace_engine-readme.md) +- ace_napi(foundation/ace/napi-readme.md) + +## Related warehouse +[js_worker_module Subsystem](base/compileruntime/js_worker_module-readme.md) ### License diff --git a/README.zh.md b/README.zh.md index 30cc5ac2a399493eb6f53ea362e214501170d44b..fd02915c2a9b9ffcb28cf987deb69e4b12726214 100644 --- a/README.zh.md +++ b/README.zh.md @@ -288,8 +288,7 @@ parentPort.onmessage = function(e) { - 属性名 -| onmessage?:(event:MessageEvent)=>void | 宿主线程收到来自其创建的worker通过worker.postMessage接口发送的消息时被调用的事件处理程序, - 处理程序在worker线程中执行 | +| onmessage?:(event:MessageEvent)=>void | 宿主线程收到来自其创建的worker通过worker.postMessage接口发送的消息时被调用的事件处理程序,处理程序在worker线程中执行 | |---|---| - 使用示例 @@ -357,8 +356,12 @@ parentPort.onmessageerror = function(e) { ### 涉及仓 -- ace_ace_engine -- ace_napi +- ace_ace_engine(foundation/ace/ace_engine-readme_zh.md) +- ace_napi(foundation/ace/napi-readme_zh.md) + +## 相关仓 +[js_worker_module 子系统](base/compileruntime/js_worker_module-readme_zh.md) + ### 许可证 diff --git a/jsapi/BUILD.gn b/jsapi/BUILD.gn index d6ef1a03f69833129d040f3e80a6dc69ae77cc59..67d4ff544f8266408cdc95fe21f04260a8ed8aae 100644 --- a/jsapi/BUILD.gn +++ b/jsapi/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/jsapi/worker/message_queue.cpp b/jsapi/worker/message_queue.cpp index 1ef3de08f23840ce0da12fc1944c5859f5bff944..855dc65aa4f7b5b0606f4e44e4054853035b8bdb 100644 --- a/jsapi/worker/message_queue.cpp +++ b/jsapi/worker/message_queue.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,6 +14,7 @@ */ #include "message_queue.h" +#include "utils/log.h" namespace OHOS::CCRuntime::Worker { void MessageQueue::EnQueue(MessageDataType data) @@ -30,9 +31,13 @@ bool MessageQueue::DeQueue(MessageDataType *data) queueLock_.unlock(); return false; } - *data = queue_.front(); - queue_.pop(); - queueLock_.unlock(); + if (data != nullptr) { + *data = queue_.front(); + queue_.pop(); + queueLock_.unlock(); + } else { + HILOG_ERROR("worker:: data is nullptr."); + } return true; } diff --git a/jsapi/worker/message_queue.h b/jsapi/worker/message_queue.h index 67d4a4803394964d5486b10b0bf50d09b805bbd5..eeee987d58bde850e56c38ac67e160ee35f43347 100644 --- a/jsapi/worker/message_queue.h +++ b/jsapi/worker/message_queue.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/jsapi/worker/native_module_worker.cpp b/jsapi/worker/native_module_worker.cpp index c7386e2a959553c3a79ef4e8a0da8614a6a733de..b30437511843780172e21fa12a3d04d9e330e938 100644 --- a/jsapi/worker/native_module_worker.cpp +++ b/jsapi/worker/native_module_worker.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/jsapi/worker/thread.cpp b/jsapi/worker/thread.cpp index 79dacaa44772ac6f06cc1aa70a828ecf2005de8c..b13906f9d90df9b6f602cb57e24fe25d7fedbb42 100644 --- a/jsapi/worker/thread.cpp +++ b/jsapi/worker/thread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/jsapi/worker/thread.h b/jsapi/worker/thread.h index c0e047047620d621652a6f824e2a05aa7b2d9e21..73a83614d0dce4da8c58c1ac6a8e3b032a9d441a 100644 --- a/jsapi/worker/thread.h +++ b/jsapi/worker/thread.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/jsapi/worker/worker.cpp b/jsapi/worker/worker.cpp index e145e84cb6e9f1865e7b09ea330f273da44ea9aa..03b6afcd5986a8c6eece242b8818c77ff7150ec9 100644 --- a/jsapi/worker/worker.cpp +++ b/jsapi/worker/worker.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -45,7 +45,11 @@ void Worker::StartExecuteInThread(napi_env env, const char* script) if (!runner_) { runner_ = std::make_unique(WorkerStartCallback(ExecuteInThread, this)); } - runner_->Execute(); // start a new thread + if (runner_) { + runner_->Execute(); // start a new thread + } else { + HILOG_ERROR("runner_ is nullptr"); + } } void Worker::CloseInner() @@ -394,7 +398,7 @@ void Worker::WorkerOnMessageInner() } MessageDataType data = nullptr; while (workerMessageQueue_.DeQueue(&data)) { - if (data == NULL || IsTerminating()) { + if (data == nullptr || IsTerminating()) { HILOG_INFO("worker:: worker reveive terminate signal"); TerminateWorker(); return; diff --git a/jsapi/worker/worker.h b/jsapi/worker/worker.h index 83c86eae7fb4fbcdcb8d857622bacd90c56525f4..4b5190047b17ea147d6293da88bfd1738eb62812 100644 --- a/jsapi/worker/worker.h +++ b/jsapi/worker/worker.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/jsapi/worker/worker_helper.cpp b/jsapi/worker/worker_helper.cpp index 71f45a0a264bb08126f05ecc9dbb0cc4b497cd2c..18001a98ecba03ba1f10a46492547b05e31ac8c5 100644 --- a/jsapi/worker/worker_helper.cpp +++ b/jsapi/worker/worker_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/jsapi/worker/worker_helper.h b/jsapi/worker/worker_helper.h index 873e0ae85c2af411d76e2509181e47e7556aef48..59d0988c344bae5164f3ccd2f61a3e28712a2546 100644 --- a/jsapi/worker/worker_helper.h +++ b/jsapi/worker/worker_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/jsapi/worker/worker_runner.cpp b/jsapi/worker/worker_runner.cpp index dc8e4aeb9cdd2f779a646931f135af49fcc94d1d..08545b417e454620f2fc20d30a47062f61e802f4 100644 --- a/jsapi/worker/worker_runner.cpp +++ b/jsapi/worker/worker_runner.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/jsapi/worker/worker_runner.h b/jsapi/worker/worker_runner.h index 1835ce42957ca5aef1f8dc57939f50a72855c370..bf70fe7059c9bbec86975b961e994b1a338c521a 100644 --- a/jsapi/worker/worker_runner.h +++ b/jsapi/worker/worker_runner.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/mozilla_docs.txt b/mozilla_docs.txt index 21a26f3acb2b7b1fb88c6ce41e0f5412e685b361..c7b3787573f4c7427f8e5f201d61f0e2a739deea 100644 --- a/mozilla_docs.txt +++ b/mozilla_docs.txt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at