From 45f3e85201a0ee99e426b6044a3f2f441e1dc560 Mon Sep 17 00:00:00 2001 From: s30043564 Date: Fri, 7 Jun 2024 09:31:06 +0000 Subject: [PATCH] =?UTF-8?q?region=E6=94=B9=E4=B8=BA=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E6=8C=87=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30043564 --- .../napi/graphic/drawing/region_napi/js_region.cpp | 13 ++----------- .../napi/graphic/drawing/region_napi/js_region.h | 6 +++--- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/interfaces/kits/napi/graphic/drawing/region_napi/js_region.cpp b/interfaces/kits/napi/graphic/drawing/region_napi/js_region.cpp index 2fc019d030..4c834921cd 100644 --- a/interfaces/kits/napi/graphic/drawing/region_napi/js_region.cpp +++ b/interfaces/kits/napi/graphic/drawing/region_napi/js_region.cpp @@ -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(); 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(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 diff --git a/interfaces/kits/napi/graphic/drawing/region_napi/js_region.h b/interfaces/kits/napi/graphic/drawing/region_napi/js_region.h index d1f71c110a..50519f984c 100644 --- a/interfaces/kits/napi/graphic/drawing/region_napi/js_region.h +++ b/interfaces/kits/napi/graphic/drawing/region_napi/js_region.h @@ -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) : 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 m_region = nullptr; }; } // namespace Drawing } // namespace OHOS::Rosen