修复畅连core文件

Signed-off-by: wlh2624 <1968860844@qq.com>
Change-Id: I28b9983aecae49aea6cc6fffa8297c252e0648fd
This commit is contained in:
wlh2624 2024-06-12 10:44:23 +08:00
parent 6f916ce9a5
commit 7c3dce65d7
2 changed files with 9 additions and 1 deletions

View File

@ -249,7 +249,9 @@ void ComponentObserver::Destroy(napi_env env)
for (auto& drawitem : cbDrawList_) {
napi_delete_reference(env, drawitem);
}
auto jsEngine = EngineHelper::GetCurrentEngineSafely();
cbLayoutList_.clear();
cbDrawList_.clear();
auto jsEngine = weakEngine_.Upgrade();
if (!jsEngine) {
return;
}
@ -304,6 +306,7 @@ static napi_value JSCreateComponentObserver(napi_env env, napi_callback_info inf
jsEngine->RegisterLayoutInspectorCallback(observer->layoutEvent_, observer->componentId_);
jsEngine->RegisterDrawInspectorCallback(observer->drawEvent_, observer->componentId_);
observer->SetEngine(jsEngine);
#if defined(PREVIEW)
layoutCallback();
drawCallback();

View File

@ -51,10 +51,15 @@ public:
std::string componentId_;
std::list<napi_ref> cbLayoutList_;
std::list<napi_ref> cbDrawList_;
void SetEngine(const RefPtr<Framework::JsEngine>& engine)
{
weakEngine_ = engine;
}
private:
void FunctionOn(napi_env& env, napi_value result, const char* funName);
void FunctionOff(napi_env& env, napi_value result, const char* funName);
WeakPtr<Framework::JsEngine> weakEngine_;
};
} // namespace OHOS::Ace::Napi
#endif