btford / btford/angular-socket-io
Emit scrambles variables if passing 4+ parameters with a callback, in IE9.
- Dominant language
- JavaScript
- Stars
- 1.5k
- Forks
- 225
- PR merge metrics
- No merged PRs in 30d
Description
Odd title but this is a very specific issue, it seems. I've only seen this happen in Internet Explorer 9.
If you emit four or more variables with the last parameter being a function. When the function is passed through, "asyncAngularify", it also causes the third parameter (index 2) to change in to the resulting function.
E.g.
`angularSocket.emit("MyEvent", dataA, dataB, dataC, someCallback);`
Will get passed to socket as:
`emit("MyEvent", dataA, wrappedCallback, dataC, wrappedCallback);`
I believe this is a crazy issue to do with IE9s interpretation of the function. The function is defined as:
`emit: function (eventName, data, callback)`
Yet these parameters are never used, however, it does do:
`var callback = arguments[lastIndex];`
The key part here being that callback has been declared twice. Once, as parameter 3 of the arguments array (function definition) and now once as the final parameter of the arguments. So when:
`callback = asyncAngularify(socket, callback);`
happens, I believe it overwrites both `arguments[2]` and `arguments[length - 1]`
The fix for me so far is just to remove the variables in the function definition. Other methods would be to rename the parameters so there are no conflicting ones.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.