fix(plugins): check websocket callbacks before calling (#6314)
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@
|
||||
- Minor: Add an option for the reduced opacity of message history. (#6121)
|
||||
- Minor: Make paused chat indicator more visible, and fix its zoom behavior. (#6123)
|
||||
- Minor: Added interactive REPL for plugins. (#6120)
|
||||
- Minor: Added WebSocket API for plugins. (#6076, #6186)
|
||||
- Minor: Added WebSocket API for plugins. (#6076, #6186, #6314)
|
||||
- Minor: Allow for themes to set transparent values for window background on Linux. (#6137)
|
||||
- Minor: Popup overlay now only draws an outline when being interacted with. (#6140)
|
||||
- Minor: Made filters searchable in the Settings dialog search bar. (#5890)
|
||||
|
||||
@@ -144,7 +144,10 @@ void WebSocketListenerProxy::onClose(std::unique_ptr<WebSocketListener> self)
|
||||
auto cb = std::move(strong->onClose);
|
||||
strong->onText.reset();
|
||||
strong->onBinary.reset();
|
||||
loggedVoidCall(cb, u"WebSocket.on_close", strong->plugin);
|
||||
if (cb)
|
||||
{
|
||||
loggedVoidCall(cb, u"WebSocket.on_close", strong->plugin);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -154,7 +157,7 @@ void WebSocketListenerProxy::onTextMessage(QByteArray data)
|
||||
auto target = this->target;
|
||||
runInGuiThread([target, data{std::move(data)}] {
|
||||
auto strong = target.lock();
|
||||
if (strong)
|
||||
if (strong && strong->onText)
|
||||
{
|
||||
loggedVoidCall(strong->onText, u"WebSocket.on_text", strong->plugin,
|
||||
data);
|
||||
@@ -167,7 +170,7 @@ void WebSocketListenerProxy::onBinaryMessage(QByteArray data)
|
||||
auto target = this->target;
|
||||
runInGuiThread([target, data{std::move(data)}] {
|
||||
auto strong = target.lock();
|
||||
if (strong)
|
||||
if (strong && strong->onBinary)
|
||||
{
|
||||
loggedVoidCall(strong->onBinary, u"WebSocket.on_binary",
|
||||
strong->plugin, data);
|
||||
|
||||
@@ -816,4 +816,27 @@ TEST_F(PluginTest, testWebSocketApi)
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST_F(PluginTest, testWebSocketUnsetFns)
|
||||
{
|
||||
configure({PluginPermission{{{"type", "Network"}}}});
|
||||
|
||||
RequestWaiter waiter;
|
||||
lua->set("done", [&] {
|
||||
waiter.requestDone();
|
||||
});
|
||||
|
||||
lua->script(R"lua(
|
||||
local ws = c2.WebSocket.new("wss://127.0.0.1:9050/echo")
|
||||
ws.on_close = function()
|
||||
done()
|
||||
end
|
||||
ws:send_text("message1")
|
||||
ws:send_text("message2")
|
||||
ws:send_binary("message3")
|
||||
ws:send_binary("/CLOSE")
|
||||
)lua");
|
||||
|
||||
waiter.waitForRequest();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user