From cfda810207ac20c1b0a0237d7024050b64bef7bb Mon Sep 17 00:00:00 2001 From: xdmal Date: Mon, 14 Mar 2022 10:09:07 +0800 Subject: [PATCH] format repair For internal issues raised by Huawei, modify README files, related copyright information, etc. Related issue: https://gitee.com/openharmony/js_worker_module/issues/I4XAYE Signed-off-by: xdmal --- README.md | 33 +++++++++++---------------- README.zh.md | 11 +++++---- jsapi/BUILD.gn | 2 +- jsapi/worker/message_queue.cpp | 13 +++++++---- jsapi/worker/message_queue.h | 2 +- jsapi/worker/native_module_worker.cpp | 2 +- jsapi/worker/thread.cpp | 2 +- jsapi/worker/thread.h | 2 +- jsapi/worker/worker.cpp | 10 +++++--- jsapi/worker/worker.h | 2 +- jsapi/worker/worker_helper.cpp | 2 +- jsapi/worker/worker_helper.h | 2 +- jsapi/worker/worker_runner.cpp | 2 +- jsapi/worker/worker_runner.h | 2 +- mozilla_docs.txt | 2 +- 15 files changed, 47 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index ef33b38..eaab4b3 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 30cc5ac..fd02915 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 d6ef1a0..67d4ff5 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 1ef3de0..855dc65 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 67d4a48..eeee987 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 c7386e2..b304375 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 79dacaa..b13906f 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 c0e0470..73a8361 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 e145e84..03b6afc 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 83c86ea..4b51900 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 71f45a0..18001a9 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 873e0ae..59d0988 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 dc8e4ae..08545b4 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 1835ce4..bf70fe7 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 21a26f3..c7b3787 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 -- Gitee