From ed7666903bd34e8f047fd5724fd7eb3e8ffaaca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 6 Apr 2022 23:37:30 +0200 Subject: [PATCH] wasm: fix qstweb::EventCallback destructor Make ~EventCallback() not clear properties belonging to other EventCallback instances. This fixes File::stream(), which creates a new EventCallback before deleting the old one when updating the callback function. Pick-to: 6.3 Change-Id: Ib5f78ccc4158d94e8d3f5b9ebb9979c123b1966a Reviewed-by: Lorn Potter --- src/corelib/platform/wasm/qstdweb.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/corelib/platform/wasm/qstdweb.cpp b/src/corelib/platform/wasm/qstdweb.cpp index a085e53f63..5b77dbf5eb 100644 --- a/src/corelib/platform/wasm/qstdweb.cpp +++ b/src/corelib/platform/wasm/qstdweb.cpp @@ -327,8 +327,11 @@ emscripten::val Uint8Array::constructor_() // name must be the name as returned by the Event.type property: e.g. "load", "error". EventCallback::~EventCallback() { - m_element.set(contextPropertyName(m_eventName).c_str(), emscripten::val::undefined()); - m_element.set((std::string("on") + m_eventName).c_str(), emscripten::val::undefined()); + // Clean up if this instance's callback is still installed on the element + if (m_element[contextPropertyName(m_eventName).c_str()].as() == intptr_t(this)) { + m_element.set(contextPropertyName(m_eventName).c_str(), emscripten::val::undefined()); + m_element.set((std::string("on") + m_eventName).c_str(), emscripten::val::undefined()); + } } EventCallback::EventCallback(emscripten::val element, const std::string &name, const std::function &fn)