diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index 049ca1d052..9b6720d5e1 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -357,16 +357,15 @@ void CNetClient::CheckServerConnection() } } -void CNetClient::GuiPoll(const ScriptRequest& rq, JS::MutableHandleValue ret) +JS::Value CNetClient::GuiPoll(const ScriptRequest& rq) { if (m_GuiMessageQueue.empty()) - { - ret.setUndefined(); - return; - } + return JS::UndefinedValue(); - Script::ReadStructuredClone(rq, m_GuiMessageQueue.front(), ret); + JS::RootedValue ret{rq.cx}; + Script::ReadStructuredClone(rq, m_GuiMessageQueue.front(), &ret); m_GuiMessageQueue.pop_front(); + return ret; } std::string CNetClient::TestReadGuiMessages() @@ -374,10 +373,9 @@ std::string CNetClient::TestReadGuiMessages() ScriptRequest rq(GetScriptInterface()); std::string r; - JS::RootedValue msg(rq.cx); while (true) { - GuiPoll(rq, &msg); + JS::RootedValue msg{rq.cx, GuiPoll(rq)}; if (msg.isUndefined()) break; r += Script::ToString(rq, &msg) + "\n"; diff --git a/source/network/NetClient.h b/source/network/NetClient.h index 4c8179b5f5..37cf5047e5 100644 --- a/source/network/NetClient.h +++ b/source/network/NetClient.h @@ -156,7 +156,7 @@ public: * * @return next message, or the value 'undefined' if the queue is empty */ - void GuiPoll(const ScriptRequest& rq, JS::MutableHandleValue ret); + JS::Value GuiPoll(const ScriptRequest& rq); /** * Add a message to the queue, to be read by GuiPoll. diff --git a/source/network/scripting/JSInterface_Network.cpp b/source/network/scripting/JSInterface_Network.cpp index 9d97509d48..86dd2e4a47 100644 --- a/source/network/scripting/JSInterface_Network.cpp +++ b/source/network/scripting/JSInterface_Network.cpp @@ -198,12 +198,7 @@ CStr GetPlayerGUID() JS::Value PollNetworkClient(const ScriptRequest& rq) { - if (!g_NetClient) - return JS::UndefinedValue(); - - JS::RootedValue message{rq.cx}; - g_NetClient->GuiPoll(rq, &message); - return message; + return g_NetClient ? g_NetClient->GuiPoll(rq) : JS::UndefinedValue(); } void SendGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue attribs1)