!35420 畅连打开core问题修复

Merge pull request !35420 from wlh2624/0804
This commit is contained in:
openharmony_ci 2024-06-12 08:58:19 +00:00 committed by Gitee
commit 53bcc0a734
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
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