intel / zephyr.js

JavaScript* Runtime for Zephyr* OS
Other
180 stars 65 forks source link

connection event listener registration error #1904

Closed emarteca closed 3 years ago

emarteca commented 3 years ago

Hi all, I've been working on a tool to identify instances of events registered to the wrong object in uses of some JavaScript event-driven APIs, as part of a research project. The tool flagged line 8 in samples/websockets/NodeWebSocketClient.js, on the registration of the connection event.

The reason I believe this is indicative of an error is as follows (from looking at the ws API documentation). The ws variable is a ws.WebSocket. However, connection is an event on ws.WebSocket.Server.

The other listeners on ws are for open, message, ping, and error all of which are events that do correspond to ws.WebSocket. My guess is that the correct code here would just be to remove the listener for connection.

Thanks!

grgustaf commented 3 years ago

Zephyr.js is actually a separate implementation that is "Node-like" so it can't be directly compared against the Node API. We may have based this on an earlier version of Node or even gotten something wrong in trying to imitate it, but I think in our implementation this is a valid event. Here's a line where it is emitted.

Sounds like a cool project. There might be some way to distinguish our code here from true Node code. Of course, we were trying to make it as similar as we could (but this was targeting very tiny hardware like Arduino).

You might want to figure out a way to limit or prioritize your analysis to projects under active development? Sadly, this one has been inert for several years now. :)

Good luck, and thanks for stopping by! Visit the MFA for me if it's open. :)

emarteca commented 3 years ago

Thanks for the speedy response! Good point, my tool does not account for manually emitted events so that would probably be the best place to start.

The MFA just re-opened, so I'll go check it out asap :)