1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "native_engine.h"
17 #include "utils/log.h"
18
19 #if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(IOS_PLATFORM) && !defined(LINUX_PLATFORM)
20 #include <sys/epoll.h>
21 #endif
22
23 #ifdef IOS_PLATFORM
24 #include <sys/event.h>
25 #endif
26
27 #include <uv.h>
28
29 constexpr size_t NAME_BUFFER_SIZE = 64;
30 static constexpr size_t DESTRUCTION_TIMEOUT = 5000;
31
32 namespace {
33 const char* g_errorMessages[] = {
34 nullptr,
35 "Invalid parameter",
36 "Need object",
37 "Need string",
38 "Need string or symbol",
39 "Need function",
40 "Need number",
41 "Need boolean",
42 "Need array",
43 "Generic failure",
44 "An exception is blocking",
45 "Asynchronous work cancelled",
46 "Escape called twice",
47 "Handle scope mismatch",
48 "Callback scope mismatch",
49 "Asynchronous work queue is full",
50 "Asynchronous work handle is closing",
51 "Need bigint",
52 "Need date",
53 "Need arraybuffer",
54 "Need detachable arraybuffer",
55 };
56 } // namespace
57
58 static GetContainerScopeIdCallback getContainerScopeIdFunc_;
59 static ContainerScopeCallback initContainerScopeFunc_;
60 static ContainerScopeCallback finishContainerScopeFunc_;
61
NativeEngine(void * jsEngine)62 NativeEngine::NativeEngine(void* jsEngine) : jsEngine_(jsEngine) {}
63
~NativeEngine()64 NativeEngine::~NativeEngine()
65 {
66 HILOG_INFO("NativeEngine::~NativeEngine");
67 if (cleanEnv_ != nullptr) {
68 cleanEnv_();
69 }
70 std::lock_guard<std::mutex> insLock(instanceDataLock_);
71 FinalizerInstanceData();
72 }
73
Init()74 void NativeEngine::Init()
75 {
76 HILOG_INFO("NativeEngine::Init");
77 moduleManager_ = NativeModuleManager::GetInstance();
78 referenceManager_ = new NativeReferenceManager();
79 scopeManager_ = new NativeScopeManager();
80 callbackScopeManager_ = new NativeCallbackScopeManager();
81 loop_ = uv_loop_new();
82 if (loop_ == nullptr) {
83 return;
84 }
85 tid_ = pthread_self();
86 uv_async_init(loop_, &uvAsync_, nullptr);
87 uv_sem_init(&uvSem_, 0);
88 }
89
Deinit()90 void NativeEngine::Deinit()
91 {
92 HILOG_INFO("NativeEngine::Deinit");
93 uv_sem_destroy(&uvSem_);
94 uv_close((uv_handle_t*)&uvAsync_, nullptr);
95 RunCleanup();
96 if (referenceManager_ != nullptr) {
97 delete referenceManager_;
98 referenceManager_ = nullptr;
99 }
100 if (scopeManager_ != nullptr) {
101 delete scopeManager_;
102 scopeManager_ = nullptr;
103 }
104
105 SetStopping(true);
106 uv_loop_delete(loop_);
107 loop_ = nullptr;
108 }
109
GetScopeManager()110 NativeScopeManager* NativeEngine::GetScopeManager()
111 {
112 return scopeManager_;
113 }
114
GetReferenceManager()115 NativeReferenceManager* NativeEngine::GetReferenceManager()
116 {
117 return referenceManager_;
118 }
119
GetModuleManager()120 NativeModuleManager* NativeEngine::GetModuleManager()
121 {
122 return moduleManager_;
123 }
124
GetCallbackScopeManager()125 NativeCallbackScopeManager* NativeEngine::GetCallbackScopeManager()
126 {
127 return callbackScopeManager_;
128 }
129
GetUVLoop() const130 uv_loop_t* NativeEngine::GetUVLoop() const
131 {
132 return loop_;
133 }
134
GetTid() const135 pthread_t NativeEngine::GetTid() const
136 {
137 return tid_;
138 }
139
ReinitUVLoop()140 bool NativeEngine::ReinitUVLoop()
141 {
142 if (loop_ != nullptr) {
143 uv_sem_destroy(&uvSem_);
144 uv_close((uv_handle_t*)&uvAsync_, nullptr);
145 uv_run(loop_, UV_RUN_ONCE);
146 uv_loop_delete(loop_);
147 }
148
149 loop_ = uv_loop_new();
150 if (loop_ == nullptr) {
151 return false;
152 }
153 tid_ = pthread_self();
154 uv_async_init(loop_, &uvAsync_, nullptr);
155 uv_sem_init(&uvSem_, 0);
156 return true;
157 }
158
Loop(LoopMode mode,bool needSync)159 void NativeEngine::Loop(LoopMode mode, bool needSync)
160 {
161 bool more = true;
162 switch (mode) {
163 case LoopMode::LOOP_DEFAULT:
164 more = uv_run(loop_, UV_RUN_DEFAULT);
165 break;
166 case LoopMode::LOOP_ONCE:
167 more = uv_run(loop_, UV_RUN_ONCE);
168 break;
169 case LoopMode::LOOP_NOWAIT:
170 more = uv_run(loop_, UV_RUN_NOWAIT);
171 break;
172 default:
173 return;
174 }
175 if (more == false) {
176 uv_loop_alive(loop_);
177 }
178
179 if (needSync) {
180 uv_sem_post(&uvSem_);
181 }
182 }
183
CreateAsyncWork(NativeValue * asyncResource,NativeValue * asyncResourceName,NativeAsyncExecuteCallback execute,NativeAsyncCompleteCallback complete,void * data)184 NativeAsyncWork* NativeEngine::CreateAsyncWork(NativeValue* asyncResource, NativeValue* asyncResourceName,
185 NativeAsyncExecuteCallback execute, NativeAsyncCompleteCallback complete, void* data)
186 {
187 (void)asyncResource;
188 (void)asyncResourceName;
189 char name[NAME_BUFFER_SIZE] = {0};
190 if (asyncResourceName != nullptr) {
191 auto nativeString = reinterpret_cast<NativeString*>(
192 asyncResourceName->GetInterface(NativeString::INTERFACE_ID));
193 size_t strLength = 0;
194 nativeString->GetCString(name, NAME_BUFFER_SIZE, &strLength);
195 }
196 return new NativeAsyncWork(this, execute, complete, name, data);
197 }
198
CreateAsyncWork(const std::string & asyncResourceName,NativeAsyncExecuteCallback execute,NativeAsyncCompleteCallback complete,void * data)199 NativeAsyncWork* NativeEngine::CreateAsyncWork(const std::string& asyncResourceName, NativeAsyncExecuteCallback execute,
200 NativeAsyncCompleteCallback complete, void* data)
201 {
202 return new NativeAsyncWork(this, execute, complete, asyncResourceName, data);
203 }
204
CreateSafeAsyncWork(NativeValue * func,NativeValue * asyncResource,NativeValue * asyncResourceName,size_t maxQueueSize,size_t threadCount,void * finalizeData,NativeFinalize finalizeCallback,void * context,NativeThreadSafeFunctionCallJs callJsCallback)205 NativeSafeAsyncWork* NativeEngine::CreateSafeAsyncWork(NativeValue* func, NativeValue* asyncResource,
206 NativeValue* asyncResourceName, size_t maxQueueSize, size_t threadCount, void* finalizeData,
207 NativeFinalize finalizeCallback, void* context, NativeThreadSafeFunctionCallJs callJsCallback)
208 {
209 return new NativeSafeAsyncWork(this, func, asyncResource, asyncResourceName, maxQueueSize, threadCount,
210 finalizeData, finalizeCallback, context, callJsCallback);
211 }
212
GetLastError()213 NativeErrorExtendedInfo* NativeEngine::GetLastError()
214 {
215 return &lastError_;
216 }
217
SetLastError(int errorCode,uint32_t engineErrorCode,void * engineReserved)218 void NativeEngine::SetLastError(int errorCode, uint32_t engineErrorCode, void* engineReserved)
219 {
220 lastError_.errorCode = errorCode;
221 lastError_.engineErrorCode = engineErrorCode;
222 lastError_.message = g_errorMessages[lastError_.errorCode];
223 lastError_.reserved = engineReserved;
224 }
225
ClearLastError()226 void NativeEngine::ClearLastError()
227 {
228 lastError_.errorCode = 0;
229 lastError_.engineErrorCode = 0;
230 lastError_.message = nullptr;
231 lastError_.reserved = nullptr;
232 }
233
EncodeToUtf8(NativeValue * nativeValue,char * buffer,int32_t * written,size_t bufferSize,int32_t * nchars)234 void NativeEngine::EncodeToUtf8(
235 NativeValue* nativeValue, char* buffer, int32_t* written, size_t bufferSize, int32_t* nchars)
236 {
237 if (nativeValue == nullptr || nchars == nullptr || written == nullptr) {
238 HILOG_ERROR("NativeEngine EncodeToUtf8 args is nullptr");
239 return;
240 }
241
242 auto nativeString = reinterpret_cast<NativeString*>(nativeValue->GetInterface(NativeString::INTERFACE_ID));
243 if (nativeString == nullptr) {
244 HILOG_ERROR("nativeValue GetInterface is nullptr");
245 return;
246 }
247 *written = nativeString->EncodeWriteUtf8(buffer, bufferSize, nchars);
248 }
249
EncodeToChinese(NativeValue * nativeValue,std::string & buffer,const std::string & encoding)250 void NativeEngine::EncodeToChinese(NativeValue* nativeValue, std::string& buffer, const std::string& encoding)
251 {
252 if (nativeValue == nullptr) {
253 HILOG_ERROR("NativeEngine is nullptr");
254 return;
255 }
256
257 auto nativeString = reinterpret_cast<NativeString*>(nativeValue->GetInterface(NativeString::INTERFACE_ID));
258 if (nativeString == nullptr) {
259 HILOG_ERROR("nativeValue GetInterface is nullptr");
260 return;
261 }
262 nativeString->EncodeWriteChinese(buffer, encoding.c_str());
263 }
264
265 #if !defined(PREVIEW)
CheckUVLoop()266 void NativeEngine::CheckUVLoop()
267 {
268 checkUVLoop_ = true;
269 uv_thread_create(&uvThread_, NativeEngine::UVThreadRunner, this);
270 }
271
UVThreadRunner(void * nativeEngine)272 void NativeEngine::UVThreadRunner(void* nativeEngine)
273 {
274 std::string name("UVLoop");
275 #ifdef IOS_PLATFORM
276 pthread_setname_np(name.c_str());
277 #else
278 pthread_setname_np(pthread_self(), name.c_str());
279 #endif
280 auto engine = static_cast<NativeEngine*>(nativeEngine);
281 engine->PostLoopTask();
282 while (engine->checkUVLoop_) {
283 int32_t fd = uv_backend_fd(engine->loop_);
284 int32_t timeout = uv_backend_timeout(engine->loop_);
285 int32_t result = -1;
286 #ifdef IOS_PLATFORM
287 struct kevent events[1];
288 struct timespec spec;
289 static const int32_t mSec = 1000;
290 static const int32_t uSec = 1000000;
291 if (timeout != -1) {
292 spec.tv_sec = timeout / mSec;
293 spec.tv_nsec = (timeout % mSec) * uSec;
294 }
295 result = kevent(fd, NULL, 0, events, 1, timeout == -1 ? NULL : &spec);
296
297 #else
298 struct epoll_event ev;
299 result = epoll_wait(fd, &ev, 1, timeout);
300 #endif
301
302 if (!engine->checkUVLoop_) {
303 HILOG_INFO("break thread after epoll wait");
304 break;
305 }
306 if (result >= 0) {
307 engine->PostLoopTask();
308 } else {
309 HILOG_ERROR("epoll wait fail: result: %{public}d, errno: %{public}d", result, errno);
310 }
311 if (!engine->checkUVLoop_) {
312 HILOG_INFO("break thread after post loop task");
313 break;
314 }
315 }
316 }
317
CancelCheckUVLoop()318 void NativeEngine::CancelCheckUVLoop()
319 {
320 checkUVLoop_ = false;
321 RunCleanup();
322 uv_async_send(&uvAsync_);
323 uv_sem_post(&uvSem_);
324 uv_thread_join(&uvThread_);
325 }
326
PostLoopTask()327 void NativeEngine::PostLoopTask()
328 {
329 postTask_(true);
330 uv_sem_wait(&uvSem_);
331 }
332 #endif
333
SetPostTask(PostTask postTask)334 void NativeEngine::SetPostTask(PostTask postTask)
335 {
336 postTask_ = postTask;
337 }
338
TriggerPostTask()339 void NativeEngine::TriggerPostTask()
340 {
341 if (postTask_ == nullptr) {
342 HILOG_ERROR("postTask_ is nullptr");
343 return;
344 }
345 postTask_(false);
346 }
347
GetJsEngine()348 void* NativeEngine::GetJsEngine()
349 {
350 return jsEngine_;
351 }
352
353 // register init worker func
SetInitWorkerFunc(InitWorkerFunc func)354 void NativeEngine::SetInitWorkerFunc(InitWorkerFunc func)
355 {
356 initWorkerFunc_ = func;
357 }
GetInitWorkerFunc() const358 InitWorkerFunc NativeEngine::GetInitWorkerFunc() const
359 {
360 return initWorkerFunc_;
361 }
SetGetAssetFunc(GetAssetFunc func)362 void NativeEngine::SetGetAssetFunc(GetAssetFunc func)
363 {
364 getAssetFunc_ = func;
365 }
GetGetAssetFunc() const366 GetAssetFunc NativeEngine::GetGetAssetFunc() const
367 {
368 return getAssetFunc_;
369 }
SetOffWorkerFunc(OffWorkerFunc func)370 void NativeEngine::SetOffWorkerFunc(OffWorkerFunc func)
371 {
372 offWorkerFunc_ = func;
373 }
GetOffWorkerFunc() const374 OffWorkerFunc NativeEngine::GetOffWorkerFunc() const
375 {
376 return offWorkerFunc_;
377 }
378
379 // call init worker func
CallInitWorkerFunc(NativeEngine * engine)380 bool NativeEngine::CallInitWorkerFunc(NativeEngine* engine)
381 {
382 if (initWorkerFunc_ != nullptr) {
383 initWorkerFunc_(engine);
384 return true;
385 }
386 return false;
387 }
CallGetAssetFunc(const std::string & uri,std::vector<uint8_t> & content,std::string & ami)388 bool NativeEngine::CallGetAssetFunc(const std::string& uri, std::vector<uint8_t>& content, std::string& ami)
389 {
390 if (getAssetFunc_ != nullptr) {
391 getAssetFunc_(uri, content, ami);
392 return true;
393 }
394 return false;
395 }
CallOffWorkerFunc(NativeEngine * engine)396 bool NativeEngine::CallOffWorkerFunc(NativeEngine* engine)
397 {
398 if (offWorkerFunc_ != nullptr) {
399 offWorkerFunc_(engine);
400 return true;
401 }
402 return false;
403 }
404
405 // adapt worker to ace container
SetGetContainerScopeIdFunc(GetContainerScopeIdCallback func)406 void NativeEngine::SetGetContainerScopeIdFunc(GetContainerScopeIdCallback func)
407 {
408 getContainerScopeIdFunc_ = func;
409 }
SetInitContainerScopeFunc(ContainerScopeCallback func)410 void NativeEngine::SetInitContainerScopeFunc(ContainerScopeCallback func)
411 {
412 initContainerScopeFunc_ = func;
413 }
SetFinishContainerScopeFunc(ContainerScopeCallback func)414 void NativeEngine::SetFinishContainerScopeFunc(ContainerScopeCallback func)
415 {
416 finishContainerScopeFunc_ = func;
417 }
GetContainerScopeIdFunc()418 int32_t NativeEngine::GetContainerScopeIdFunc()
419 {
420 int32_t scopeId = -1;
421 if (getContainerScopeIdFunc_ != nullptr) {
422 scopeId = getContainerScopeIdFunc_();
423 }
424 return scopeId;
425 }
InitContainerScopeFunc(int32_t id)426 bool NativeEngine::InitContainerScopeFunc(int32_t id)
427 {
428 if (initContainerScopeFunc_ != nullptr) {
429 initContainerScopeFunc_(id);
430 return true;
431 }
432 return false;
433 }
FinishContainerScopeFunc(int32_t id)434 bool NativeEngine::FinishContainerScopeFunc(int32_t id)
435 {
436 if (finishContainerScopeFunc_ != nullptr) {
437 finishContainerScopeFunc_(id);
438 return true;
439 }
440 return false;
441 }
442
443 #if !defined(PREVIEW)
CallDebuggerPostTaskFunc(std::function<void ()> && task)444 void NativeEngine::CallDebuggerPostTaskFunc(std::function<void()>&& task)
445 {
446 if (debuggerPostTaskFunc_ != nullptr) {
447 debuggerPostTaskFunc_(std::move(task));
448 }
449 }
450
SetDebuggerPostTaskFunc(DebuggerPostTask func)451 void NativeEngine::SetDebuggerPostTaskFunc(DebuggerPostTask func)
452 {
453 debuggerPostTaskFunc_ = func;
454 }
455 #endif
456
SetHostEngine(NativeEngine * engine)457 void NativeEngine::SetHostEngine(NativeEngine* engine)
458 {
459 hostEngine_ = engine;
460 }
461
GetHostEngine() const462 NativeEngine* NativeEngine::GetHostEngine() const
463 {
464 return hostEngine_;
465 }
466
AddCleanupHook(CleanupCallback fun,void * arg)467 void NativeEngine::AddCleanupHook(CleanupCallback fun, void* arg)
468 {
469 HILOG_INFO("%{public}s, start.", __func__);
470 auto insertion_info = cleanup_hooks_.emplace(CleanupHookCallback { fun, arg, cleanup_hook_counter_++ });
471 if (insertion_info.second != true) {
472 HILOG_ERROR("AddCleanupHook Failed.");
473 }
474 HILOG_INFO("%{public}s, end.", __func__);
475 }
476
RemoveCleanupHook(CleanupCallback fun,void * arg)477 void NativeEngine::RemoveCleanupHook(CleanupCallback fun, void* arg)
478 {
479 HILOG_INFO("%{public}s, start.", __func__);
480 CleanupHookCallback hook { fun, arg, 0 };
481 cleanup_hooks_.erase(hook);
482 HILOG_INFO("%{public}s, end.", __func__);
483 }
484
StartCleanupTimer()485 void NativeEngine::StartCleanupTimer()
486 {
487 uv_timer_init(loop_, &timer_);
488 timer_.data = this;
489 uv_timer_start(&timer_, [](uv_timer_t* handle) {
490 reinterpret_cast<NativeEngine*>(handle->data)->cleanupTimeout_ = true;
491 uv_close(reinterpret_cast<uv_handle_t*>(handle), nullptr);
492 }, DESTRUCTION_TIMEOUT, 0);
493 }
494
RunCleanup()495 void NativeEngine::RunCleanup()
496 {
497 HILOG_DEBUG("%{public}s, start.", __func__);
498 StartCleanupTimer();
499 CleanupHandles();
500 // sync clean up
501 while (!cleanup_hooks_.empty()) {
502 HILOG_DEBUG("NativeEngine::RunCleanup cleanup_hooks is not empty");
503 // Copy into a vector, since we can't sort an unordered_set in-place.
504 std::vector<CleanupHookCallback> callbacks(cleanup_hooks_.begin(), cleanup_hooks_.end());
505 // We can't erase the copied elements from `cleanup_hooks_` yet, because we
506 // need to be able to check whether they were un-scheduled by another hook.
507
508 std::sort(callbacks.begin(), callbacks.end(), [](const CleanupHookCallback& a, const CleanupHookCallback& b) {
509 // Sort in descending order so that the most recently inserted callbacks are run first.
510 return a.insertion_order_counter_ > b.insertion_order_counter_;
511 });
512 HILOG_DEBUG(
513 "NativeEngine::RunCleanup cleanup_hooks callbacks size:%{public}d", (int32_t)callbacks.size());
514 for (const CleanupHookCallback& cb : callbacks) {
515 if (cleanup_hooks_.count(cb) == 0) {
516 // This hook was removed from the `cleanup_hooks_` set during another
517 // hook that was run earlier. Nothing to do here.
518 continue;
519 }
520 cb.fn_(cb.arg_);
521 cleanup_hooks_.erase(cb);
522 }
523 CleanupHandles();
524 }
525 if (cleanupTimeout_) {
526 HILOG_ERROR("RunCleanup timeout");
527 }
528 HILOG_DEBUG("%{public}s, end.", __func__);
529 }
530
CleanupHandles()531 void NativeEngine::CleanupHandles()
532 {
533 while (request_waiting_.load() > 0 && !cleanupTimeout_) {
534 HILOG_INFO("%{public}s, request waiting:%{public}d.", __func__,
535 request_waiting_.load(std::memory_order_relaxed));
536 uv_run(loop_, UV_RUN_ONCE);
537 }
538 }
539
IncreaseWaitingRequestCounter()540 void NativeEngine::IncreaseWaitingRequestCounter()
541 {
542 request_waiting_++;
543 }
544
DecreaseWaitingRequestCounter()545 void NativeEngine::DecreaseWaitingRequestCounter()
546 {
547 request_waiting_--;
548 }
549
RegisterWorkerFunction(const NativeEngine * engine)550 void NativeEngine::RegisterWorkerFunction(const NativeEngine* engine)
551 {
552 if (engine == nullptr) {
553 return;
554 }
555 SetInitWorkerFunc(engine->GetInitWorkerFunc());
556 SetGetAssetFunc(engine->GetGetAssetFunc());
557 SetOffWorkerFunc(engine->GetOffWorkerFunc());
558 }
559
RunScript(const char * path)560 NativeValue* NativeEngine::RunScript(const char* path)
561 {
562 std::vector<uint8_t> scriptContent;
563 std::string pathStr(path);
564 std::string ami;
565 if (!CallGetAssetFunc(pathStr, scriptContent, ami)) {
566 HILOG_ERROR("Get asset error");
567 return nullptr;
568 }
569 HILOG_INFO("asset size is %{public}zu", scriptContent.size());
570 return RunActor(scriptContent, ami.c_str());
571 }
572
SetInstanceData(void * data,NativeFinalize finalize_cb,void * hint)573 void NativeEngine::SetInstanceData(void* data, NativeFinalize finalize_cb, void* hint)
574 {
575 HILOG_INFO("NativeEngineWraper::%{public}s, start.", __func__);
576 std::lock_guard<std::mutex> insLock(instanceDataLock_);
577 FinalizerInstanceData();
578 instanceDataInfo_.engine = this;
579 instanceDataInfo_.callback = finalize_cb;
580 instanceDataInfo_.nativeObject = data;
581 instanceDataInfo_.hint = hint;
582 }
583
GetInstanceData(void ** data)584 void NativeEngine::GetInstanceData(void** data)
585 {
586 HILOG_INFO("NativeEngineWraper::%{public}s, start.", __func__);
587 std::lock_guard<std::mutex> insLock(instanceDataLock_);
588 if (data) {
589 *data = instanceDataInfo_.nativeObject;
590 }
591 }
592
FinalizerInstanceData(void)593 void NativeEngine::FinalizerInstanceData(void)
594 {
595 if (instanceDataInfo_.engine != nullptr && instanceDataInfo_.callback != nullptr) {
596 instanceDataInfo_.callback(instanceDataInfo_.engine, instanceDataInfo_.nativeObject, instanceDataInfo_.hint);
597 }
598 instanceDataInfo_.engine = nullptr;
599 instanceDataInfo_.callback = nullptr;
600 instanceDataInfo_.nativeObject = nullptr;
601 instanceDataInfo_.hint = nullptr;
602 }
603
GetModuleFileName()604 const char* NativeEngine::GetModuleFileName()
605 {
606 HILOG_INFO("%{public}s, start.", __func__);
607 NativeModuleManager* moduleManager = GetModuleManager();
608 HILOG_INFO("NativeEngineWraper::GetFileName GetModuleManager");
609 if (moduleManager != nullptr) {
610 const char* moduleFileName = moduleManager->GetModuleFileName(moduleName_.c_str(), false);
611 HILOG_INFO("NativeEngineWraper::GetFileName end filename:%{public}s", moduleFileName);
612 return moduleFileName;
613 }
614 return nullptr;
615 }
616
SetModuleFileName(std::string & moduleName)617 void NativeEngine::SetModuleFileName(std::string& moduleName)
618 {
619 moduleName_ = moduleName;
620 }
621
SetExtensionInfos(std::unordered_map<std::string,int32_t> && extensionInfos)622 void NativeEngine::SetExtensionInfos(std::unordered_map<std::string, int32_t>&& extensionInfos)
623 {
624 extensionInfos_ = extensionInfos;
625 }
626
GetExtensionInfos()627 const std::unordered_map<std::string, int32_t>& NativeEngine::GetExtensionInfos()
628 {
629 return extensionInfos_;
630 }
631
SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> & moduleCheckerDelegate)632 void NativeEngine::SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate>& moduleCheckerDelegate)
633 {
634 NativeModuleManager* moduleManager = GetModuleManager();
635 if (!moduleManager) {
636 HILOG_ERROR("SetModuleLoadChecker failed, moduleManager is nullptr");
637 return;
638 }
639 moduleManager->SetModuleLoadChecker(moduleCheckerDelegate);
640 }