Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: include.preload.js

Issue 29349737: Issue 1727 - Fix WebSocket constructor without second argument in Chrome 47 (Closed)
Patch Set: Created Aug. 11, 2016, 2:12 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.preload.js
===================================================================
--- a/include.preload.js
+++ b/include.preload.js
@@ -373,6 +373,7 @@
// As far as possible we must track everything we use that could be
// sabotaged by the website later in order to circumvent us.
var RealWebSocket = WebSocket;
+ var bindWebSocket = Function.prototype.bind.apply.bind(Function.prototype.bind, RealWebSocket);
var closeWebSocket = Function.prototype.call.bind(RealWebSocket.prototype.close);
var addEventListener = document.addEventListener.bind(document);
var removeEventListener = document.removeEventListener.bind(document);
@@ -394,13 +395,14 @@
}));
}
- WebSocket = function WrappedWebSocket(url, protocols)
+ WebSocket = function WrappedWebSocket()
{
- // Throw correct exceptions if the constructor is used improperly.
- if (!(this instanceof WrappedWebSocket)) return RealWebSocket();
- if (arguments.length < 1) return new RealWebSocket();
+ var args = [null];
kzar 2016/08/11 14:25:05 I think this approach is extremely hard to follow,
Sebastian Noack 2016/08/11 14:38:46 Well, if you'd write your logic compliant to our c
kzar 2016/08/11 14:54:16 I didn't say anything about the code being shorter
Sebastian Noack 2016/08/11 15:11:35 I don't think that I agree. But there you go.
+ for (var i = 0; i < arguments.length; i++)
+ args.push(arguments[i]);
kzar 2016/08/11 14:25:05 This would allow for circumvention since we didn't
Sebastian Noack 2016/08/11 14:38:46 Well spotted, fixed.
- var websocket = new RealWebSocket(url, protocols);
+ var ctor = bindWebSocket(args);
+ var websocket = this instanceof WrappedWebSocket ? new ctor : ctor();
checkRequest(websocket.url, function(blocked)
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld