Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#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

Change History (3)

comment:1 Changed 3 years ago by mapx

  • Cc kzar sebastian mapx added
  • Platform changed from Unknown / Cross platform to Chrome

comment:2 Changed 3 years ago 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

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.

comment:3 in reply to: ↑ description Changed 3 years ago 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.

Last edited 3 years ago by mapx (previous) (diff)
Note: See TracTickets for help on using tickets.