diff --git a/js_concurrent_module/taskpool/worker.cpp b/js_concurrent_module/taskpool/worker.cpp index 36f5dc961b00057db25007a138e7e3fafe007e60..6c06b1c7d4ea23b09394727f2e82c4c4f9557952 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 5a70a71aa9f0d4b7c8262448f71e05a35eb9da10..c75f71407da68bf9a8b5fd026434ca55e5793201 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);