gimite / web-socket-js

HTML5 Web Socket implementation powered by Flash
BSD 3-Clause "New" or "Revised" License
2.73k stars 489 forks source link

Event callback scope #91

Closed alebsack closed 12 years ago

alebsack commented 13 years ago

I noticed on Firefox 6 (possibly other browsers) that the scope of event callbacks is inconsistent with Webkit's Websocket implementation. Websocket in Webkit will call event callbacks within the scope of the Websocket object. In Firefox 6, it is in the scope of the Window.

Here's a patch that addresses the issue, and it works for me:

diff --git a/web_socket.js b/web_socket.js index 947a637..d62e0b6 100644 --- a/web_socket.js +++ b/web_socket.js @@ -149,7 +149,7 @@ eventsi; } var handler = this["on" + event.type];

kanaka commented 13 years ago

This would probably be a good thing to file as a bug with Mozilla too (if you haven't already). They may just not have thought about it and it would be good to get things consistent everywhere (and being called with this set to the WebSocket object makes the most sense).

gimite commented 12 years ago

Thanks for the report and patch. Pulled at: https://github.com/gimite/web-socket-js/commit/66f79da193582bbd21507d80a2e5297de56668a3

@kanaka I confirmed that MozWebSocket in Firefox 6 does correct scope handling. I guess @alebsack only mentioned about Firefox 6 + web-socket-js.