region改为智能指针

Signed-off-by: s30043564 <shenxiaoliang1@huawei.com>
This commit is contained in:
s30043564 2024-06-07 09:31:06 +00:00
parent 3f87756f01
commit 45f3e85201
2 changed files with 5 additions and 14 deletions

View File

@ -68,14 +68,13 @@ napi_value JsRegion::Constructor(napi_env env, napi_callback_info info)
ROSEN_LOGE("JsRegion::Constructor failed to napi_get_cb_info");
return nullptr;
}
Region *region = new Region();
auto region = std::make_shared<Region>();
JsRegion* jsRegion = new(std::nothrow) JsRegion(region);
status = napi_wrap(env, jsThis, jsRegion,
JsRegion::Destructor, nullptr, nullptr);
if (status != napi_ok) {
if (jsRegion != nullptr) {
delete jsRegion;
jsRegion = nullptr;
}
ROSEN_LOGE("JsRegion::Constructor Failed to wrap native instance");
return nullptr;
@ -93,14 +92,6 @@ void JsRegion::Destructor(napi_env env, void* nativeObject, void* finalize)
}
}
JsRegion::~JsRegion()
{
if (m_region != nullptr) {
delete m_region;
m_region = nullptr;
}
}
napi_value JsRegion::IsPointContained(napi_env env, napi_callback_info info)
{
JsRegion* me = CheckParamsAndGetThis<JsRegion>(env, info);
@ -278,7 +269,7 @@ napi_value JsRegion::OnSetPath(napi_env env, napi_callback_info info)
Region* JsRegion::GetRegion()
{
return m_region;
return m_region.get();
}
} // namespace Drawing
} // namespace OHOS::Rosen

View File

@ -26,8 +26,8 @@ namespace OHOS::Rosen {
namespace Drawing {
class JsRegion final {
public:
explicit JsRegion(Region* region) : m_region(region) {};
~JsRegion();
explicit JsRegion(std::shared_ptr<Region> region) : m_region(region) {};
~JsRegion() {};
static napi_value Init(napi_env env, napi_value exportObj);
static napi_value Constructor(napi_env env, napi_callback_info info);
@ -51,7 +51,7 @@ private:
napi_value OnSetPath(napi_env env, napi_callback_info info);
static thread_local napi_ref constructor_;
Region* m_region = nullptr;
std::shared_ptr<Region> m_region = nullptr;
};
} // namespace Drawing
} // namespace OHOS::Rosen