From 388beef1fb648b66b903b02d25c94a5c90ed62b2 Mon Sep 17 00:00:00 2001 From: ilikethese Date: Tue, 11 Jul 2023 19:00:47 +0800 Subject: [PATCH] feat(dom): fix empty dom event function crash --- driver/js/src/scope.cc | 1 - .../cpp/src/renderer/native_render_manager.cc | 16 +++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/driver/js/src/scope.cc b/driver/js/src/scope.cc index d066e1019ba..8ddc9de1de1 100644 --- a/driver/js/src/scope.cc +++ b/driver/js/src/scope.cc @@ -381,7 +381,6 @@ hippy::dom::EventListenerInfo Scope::AddListener(const EventListenerInfo& event_ auto context = weak_context.lock(); if (context) { auto callback = event_listener_info.callback.lock(); - FOOTSTONE_DCHECK(callback != nullptr); if (callback == nullptr) return; hippy::DomEventWrapper::Set(event); auto event_class = scope->GetJavascriptClass(kEventName); diff --git a/renderer/native/android/src/main/cpp/src/renderer/native_render_manager.cc b/renderer/native/android/src/main/cpp/src/renderer/native_render_manager.cc index 91057b551b1..2966a75dd17 100644 --- a/renderer/native/android/src/main/cpp/src/renderer/native_render_manager.cc +++ b/renderer/native/android/src/main/cpp/src/renderer/native_render_manager.cc @@ -472,12 +472,18 @@ void NativeRenderManager::ReceivedEvent(std::weak_ptr root_node, uint3 FOOTSTONE_DCHECK(root != nullptr); if (root == nullptr) return; - auto node = manager->GetNode(root_node, dom_id); - // FOOTSTONE_DCHECK(node != nullptr); - if (node == nullptr) return; + std::vector> ops = {[weak_dom_manager = dom_manager_, weak_root_node = root_node, dom_id, + params = std::move(params), use_capture = capture, use_bubble = bubble, + event_name = std::move(event_name)] { + auto manager = weak_dom_manager.lock(); + if (manager == nullptr) return; + + auto root = weak_root_node.lock(); + if (root == nullptr) return; + + auto node = manager->GetNode(root, dom_id); + if (node == nullptr) return; - std::vector> ops = {[node = std::move(node), params = std::move(params), use_capture = capture, - use_bubble = bubble, event_name = std::move(event_name)] { auto event = std::make_shared(event_name, node, use_capture, use_bubble, params); node->HandleEvent(event); }};