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 <lorn.potter@gmail.com>
bb10
Morten Johan Sørvig 2022-04-06 23:37:30 +02:00
parent 0742e5770b
commit ed7666903b
1 changed files with 5 additions and 2 deletions

View File

@ -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>() == 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<void(emscripten::val)> &fn)