Opened on 11/01/2016 at 12:02:24 AM
Closed on 11/03/2016 at 10:13:18 AM
Last modified on 11/03/2016 at 10:15:42 AM
#4590 closed defect (duplicate)
WebSocket wrapper breaking code that extends the WebSocket object
Reported by: | yaief | Assignee: | |
---|---|---|---|
Priority: | Unknown | Milestone: | |
Module: | Platform | Keywords: | |
Cc: | kzar, sebastian, mapx | Blocked By: | |
Blocking: | Platform: | Unknown / Cross platform | |
Ready: | no | Confidential: | no |
Tester: | Unknown | Verified working: | no |
Review URL(s): |
Description (last modified by kzar)
Environment
Everything
How to reproduce
Extend WebSocket in JS.
In this case extended through TypeScript, but obviously similar effect can be had by raw JS
Observed behaviour
WebSocket breaks on creation
Expected behaviour
WebSocket works
This is the adblock plus code:
function WrappedWebSocket(url) { // Throw correct exceptions if the constructor is used improperly. if (!(this instanceof WrappedWebSocket)) return RealWebSocket(); if (arguments.length < 1) return new RealWebSocket();
Note that the line with the first if-statement has an error where it call return RealWebSocket instead of return new RealWebSocket
This is triggered by "this" being set to Window when extending WebSocket, and the crashing on "return RealWebSocket"
Notes
- Also see issue #4563
Attachments (0)
Change History (3)
comment:1 Changed on 11/02/2016 at 07:21:58 AM by mapx
- Cc kzar sebastian mapx added
- Platform changed from Unknown / Cross platform to Chrome
comment:2 Changed on 11/03/2016 at 09:42:25 AM by kzar
- Component changed from Unknown to Platform
- Description modified (diff)
- Platform changed from Chrome to Unknown / Cross platform
- Summary changed from Fix #4563 to WebSocket wrapper breaking code that extends the WebSocket object
comment:3 in reply to: ↑ description Changed on 11/03/2016 at 10:13:18 AM by sebastian
- Resolution set to duplicate
- Status changed from new to closed
Replying to yaief:
function WrappedWebSocket(url) { // Throw correct exceptions if the constructor is used improperly. if (!(this instanceof WrappedWebSocket)) return RealWebSocket(); if (arguments.length < 1) return new RealWebSocket();Note that the line with the first if-statement has an error where it call return RealWebSocket instead of return new RealWebSocket
This is on purpose, so that when you call WebSocket() (without new keyword) it errors out in the same way as it would without the wrapper.
I also cannot think of a scenario, from the top of my head, where this would break any code that would work without the wrapper. Also this is a duplicate of #4563, so I'm closing this issue now. Feel free to reopen the original issue, once there is actually a way to reproduce this.
Please give a concrete example (ideally in plain JavaScript and as simple as possible) of how we can reproduce this problem.
Please give an example of an environment where this happens. For example a specific version of Chrome, OS and Adblock Plus.