Assert on overwriting a previously set EventCallback on wasm

Overwriting a previously set EventCallback may lead to subtle,
hard-to-detect errors. Since it constitutes a programming error, assert
on such attempts to detect potential event handling problems.

Change-Id: I9d3647cbd0a1733741d16681cdad150c85848f97
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This commit is contained in:
Mikolaj Boc 2023-02-13 15:35:10 +01:00
parent 490c4558f7
commit 5999ff4fd6

View File

@ -760,6 +760,8 @@ EventCallback::EventCallback(emscripten::val element, const std::string &name, c
,m_eventName(name)
,m_fn(fn)
{
Q_ASSERT_X(m_element[contextPropertyName(m_eventName)].isUndefined(), Q_FUNC_INFO,
"Only one event callback of type currently supported with EventCallback");
m_element.set(contextPropertyName(m_eventName).c_str(), emscripten::val(intptr_t(this)));
m_element.set((std::string("on") + m_eventName).c_str(), emscripten::val::module_property("qtStdWebEventCallbackActivate"));
}