Add WebSocketInit dictionary as option for second param in constructor - #76
christhompson wants to merge 3 commits into
Conversation
ricea
left a comment
There was a problem hiding this comment.
Looks minimal and good. I'm holding off on approval only because it's been so long since I've used Bikeshed I don't trust my eyes.
| 1. If |urlRecord|'s [=scheme=] is not "<code>[=ws=]</code>" or "<code>[=wss=]</code>", then throw a | ||
| "{{SyntaxError}}" {{DOMException}}. | ||
| 1. If |urlRecord|'s [=fragment=] is non-null, then throw a "{{SyntaxError}}" {{DOMException}}. | ||
| 1. Let |protocols| be an empty sequence. |
There was a problem hiding this comment.
| 1. Let |protocols| be an empty sequence. | |
| 1. Let |protocols| be « ». |
| 1. Let |protocols| be an empty sequence. | ||
| 1. If |protocolsOrOptions| is a {{WebSocketInit}} dictionary, set |protocols| to | ||
| |protocolsOrOptions|["{{WebSocketInit/protocols}}"]. | ||
| 1. Otherwise, set |protocols| to |protocolsOrOptions|. |
There was a problem hiding this comment.
Maybe using a lambda would be clearer here.
- Let protocols be the return value of running these steps:
- If protocolsOrOptions is a dictionary, then return protocolsOrOptions["protocols"].
- If protocolsOrOptions is a string, then return « protocolsOrOptions ».
- Return protocolsOrOptions.
|
This change might not be web-compatible. I am currently investigating. It turns out that new WebSocket(url, undefined, isNodeJS() ? { headers } : {});in the wild. Before this change, the above constructor call behaves like After this change, the above constructor call behaves like Without actually trying it, I don't know whether servers will stop returning |
|
Seems worth measuring. We could special case |
Adds the option for using a WebSocketInit dictionary as the second param in the WebSocket constructor. This updates the non-normative description of how the constructor works, and adds steps to the constructor processing algorithm to handle the case where the second param is a WebSocketInit dictionary (extracting the "protocols" field if present).
Fixes #42
(See WHATWG Working Mode: Changes for more details.)
Preview | Diff