wasm: implement move for QWasmEventHandler
Implement move by copying the emscripten::val member variables, and clearing the moved-from ones. This ensures that the moved-from val is in a known state ("undefined"). Also move the non-default constructor declaration up to the top of the class. Change-Id: If9574cc91a53d4029d49b29b89819d98319acaa3 Reviewed-by: Even Oscar Andersen <even.oscar.andersen@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
dc033758a3
commit
57f98a095e
@ -180,12 +180,37 @@ QWasmEventHandler::QWasmEventHandler(emscripten::val element, const std::string
|
|||||||
|
|
||||||
QWasmEventHandler::~QWasmEventHandler()
|
QWasmEventHandler::~QWasmEventHandler()
|
||||||
{
|
{
|
||||||
|
// Do nothing if this instance is default-constructed, or was moved from.
|
||||||
|
if (m_element.isUndefined())
|
||||||
|
return;
|
||||||
|
|
||||||
QWasmSuspendResumeControl *suspendResume = QWasmSuspendResumeControl::get();
|
QWasmSuspendResumeControl *suspendResume = QWasmSuspendResumeControl::get();
|
||||||
Q_ASSERT(suspendResume);
|
Q_ASSERT(suspendResume);
|
||||||
m_element.call<void>("removeEventListener", m_name, suspendResume->jsEventHandlerAt(m_eventHandlerIndex));
|
m_element.call<void>("removeEventListener", m_name, suspendResume->jsEventHandlerAt(m_eventHandlerIndex));
|
||||||
suspendResume->removeEventHandler(m_eventHandlerIndex);
|
suspendResume->removeEventHandler(m_eventHandlerIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWasmEventHandler::QWasmEventHandler(QWasmEventHandler&& other) noexcept
|
||||||
|
:m_element(std::move(other.m_element))
|
||||||
|
,m_name(std::move(other.m_name))
|
||||||
|
,m_eventHandlerIndex(other.m_eventHandlerIndex)
|
||||||
|
{
|
||||||
|
other.m_element = emscripten::val();
|
||||||
|
other.m_name = emscripten::val();
|
||||||
|
other.m_eventHandlerIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWasmEventHandler& QWasmEventHandler::operator=(QWasmEventHandler&& other) noexcept
|
||||||
|
{
|
||||||
|
m_element = std::move(other.m_element);
|
||||||
|
other.m_element = emscripten::val();
|
||||||
|
m_name = std::move(other.m_name);
|
||||||
|
other.m_name = emscripten::val();
|
||||||
|
m_eventHandlerIndex = other.m_eventHandlerIndex;
|
||||||
|
other.m_eventHandlerIndex = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// The QWasmTimer class creates a native single-shot timer. The event handler is provided in the
|
// The QWasmTimer class creates a native single-shot timer. The event handler is provided in the
|
||||||
// constructor and can be reused: each call setTimeout() sets a new timeout, though with the
|
// constructor and can be reused: each call setTimeout() sets a new timeout, though with the
|
||||||
|
@ -51,12 +51,13 @@ class Q_CORE_EXPORT QWasmEventHandler
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QWasmEventHandler() = default;
|
QWasmEventHandler() = default;
|
||||||
|
QWasmEventHandler(emscripten::val element, const std::string &name,
|
||||||
|
std::function<void(emscripten::val)> fn);
|
||||||
~QWasmEventHandler();
|
~QWasmEventHandler();
|
||||||
QWasmEventHandler(QWasmEventHandler const&) = delete;
|
QWasmEventHandler(QWasmEventHandler const&) = delete;
|
||||||
QWasmEventHandler& operator=(QWasmEventHandler const&) = delete;
|
QWasmEventHandler& operator=(QWasmEventHandler const&) = delete;
|
||||||
QWasmEventHandler(emscripten::val element, const std::string &name,
|
QWasmEventHandler(QWasmEventHandler&& other) noexcept;
|
||||||
std::function<void(emscripten::val)> fn);
|
QWasmEventHandler& operator=(QWasmEventHandler&& other) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
emscripten::val m_element;
|
emscripten::val m_element;
|
||||||
emscripten::val m_name;
|
emscripten::val m_name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user