From 714e9bc5a30615531cb128fd8811f22605b690a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=89=91?= Date: Wed, 14 May 2025 21:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=86=85=E7=BD=AEintl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王剑 --- js_concurrent_module/taskpool/worker.cpp | 24 +++++++++++++++++++++++ js_concurrent_module/worker/worker.cpp | 25 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/js_concurrent_module/taskpool/worker.cpp b/js_concurrent_module/taskpool/worker.cpp index 36f5dc96..6c06b1c7 100644 --- a/js_concurrent_module/taskpool/worker.cpp +++ b/js_concurrent_module/taskpool/worker.cpp @@ -28,6 +28,7 @@ #include "native_engine.h" namespace Commonlibrary::Concurrent::TaskPoolModule { +using RegisterIntl = bool (*)(napi_env); using namespace OHOS::JsSysModule; using namespace Commonlibrary::Platform; static constexpr uint32_t TASKPOOL_TYPE = 2; @@ -264,6 +265,26 @@ void Worker::ExecuteInThread(const void* data) worker = nullptr; } +void RegisterIntlModule(napi_env env) +{ + void *intlUtilHandle = dlopen("libintl_napi.z.so", RTLD_NOW); + if (intlUtilHandle == nullptr) { + HILOG_ERROR("ReplaceBuildInAPI: taskpool load libintl_napi.z.so failed"); + return; + } + RegisterIntl registerIntl = (RegisterIntl)dlsym(intlUtilHandle, "RegisterIntl"); + + bool ret = false; + if (registerIntl) { + ret = registerIntl(env); + } else { + HILOG_ERROR("ReplaceBuildInAPI: taskpool registerIntl is null"); + } + if (!ret) { + HILOG_ERROR("ReplaceBuildInAPI: taskpool Register intl failed"); + } +} + bool Worker::PrepareForWorkerInstance() { HITRACE_HELPER_METER_NAME(__PRETTY_FUNCTION__); @@ -311,6 +332,9 @@ bool Worker::PrepareForWorkerInstance() // register timer interface Timer::RegisterTime(workerEnv_); + // register intl interface + RegisterIntlModule(workerEnv_); + // Check exception after worker construction if (NapiHelper::IsExceptionPending(workerEnv_)) { HILOG_ERROR("taskpool:: Worker construction occur exception"); diff --git a/js_concurrent_module/worker/worker.cpp b/js_concurrent_module/worker/worker.cpp index 5a70a71a..c75f7140 100644 --- a/js_concurrent_module/worker/worker.cpp +++ b/js_concurrent_module/worker/worker.cpp @@ -31,6 +31,7 @@ #include "native_engine.h" namespace Commonlibrary::Concurrent::WorkerModule { +using RegisterIntl = bool (*)(napi_env); using namespace OHOS::JsSysModule; static constexpr int8_t NUM_WORKER_ARGS = 2; static constexpr uint8_t NUM_GLOBAL_CALL_ARGS = 3; @@ -1506,6 +1507,26 @@ void Worker::ExecuteInThread(const void* data) } } +void RegisterIntlModule(napi_env env) +{ + void *intlUtilHandle = dlopen("libintl_napi.z.so", RTLD_NOW); + if (intlUtilHandle == nullptr) { + HILOG_ERROR("worker: worker load libintl_napi.z.so failed"); + return; + } + RegisterIntl registerIntl = (RegisterIntl)dlsym(intlUtilHandle, "RegisterIntl"); + + bool ret = false; + if (registerIntl) { + ret = registerIntl(env); + } else { + HILOG_ERROR("worker: worker registerIntl is null"); + } + if (!ret) { + HILOG_ERROR("worker: worker Register intl failed"); + } +} + bool Worker::PrepareForWorkerInstance() { std::string rawFileName = script_; @@ -1534,6 +1555,10 @@ bool Worker::PrepareForWorkerInstance() } // add timer interface Timer::RegisterTime(workerEnv_); + + // register intl interface + RegisterIntlModule(workerEnv_); + napi_value execScriptResult = nullptr; napi_status status = napi_run_actor(workerEnv_, const_cast(rawFileName.c_str()), const_cast(script_.c_str()), &execScriptResult); -- Gitee