Fix emscripten_websocket_deinitialize() #25744
Open
+46
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
First of all, thank you for making this great piece of technology.
Running my C++ in a web browser feels overpowered and is really fun.
I was looking at
libwebsocket.jstrying to understand how it works and figured thatemscripten_websocket_deinitialize()likely does not work as it references an undefined variable (WS.sockets).It seems another user came to the same conclusion (issue #24613).
As far as I can tell, this bug was introduced in commit e1c39bc, when the javascript array of websockets was replaced by an
HandleAllocator.All references to
WS.socketswere correctly replaced, save for the ones inemscripten_websocket_deinitialize(); introducing the bug.This pull requests consists of 3 commits.
The first one extends the
test_websocket_sendtest to cover the use ofemscripten_websocket_deinitialize()and fails with the current code.The second commit ought to fix the bug and make the test pass.
The last commit is more of a suggestion than anything else, it adds a
list()method toHandleAllocatorin order to avoid iterating over theallocatedarray directly.I ran the following command to test the code and it outputs "OK".
There are many test cases I couldn't get to work, even on the main branch ; but that is probably a skill issue on my part.
I hope the command I ran is sufficient.
I also tried to run clang-format on
test_websocket_send.cafter modifying the file but it produced so many diffs I rolled back the changes. This file doesn't seem to adhere to the style as defined in.clang-format(very long lines, right-aligned pointers) so I left it that way.I think the following may be used as commit message if the branch is squashed:
Please let me know if there is anything wrong with the code.
Thank you for your time.
Best regards,
Vincent.