1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:48:10 +00:00

LibWeb: Reset message port receive state before dispatching events

Dispatching events can cause arbitrary JS to run, which could cause the
event loop to be re-entered, or even post another message to the same
message port.
This commit is contained in:
Andrew Kaster 2024-01-05 14:50:01 -07:00 committed by Andreas Kling
parent 09ce32039f
commit 5ace712282

View file

@ -297,8 +297,11 @@ void MessagePort::read_from_socket()
auto serialize_with_transfer_result = MUST(decoder.decode<SerializedTransferRecord>());
post_message_task_steps(serialize_with_transfer_result);
// Make sure to advance our state machine before dispatching the MessageEvent,
// as dispatching events can run arbitrary JS (and cause us to receive another message!)
m_socket_state = SocketState::Header;
post_message_task_steps(serialize_with_transfer_result);
break;
}
case SocketState::Error: