Skip to content

Commit fc9f8da

Browse files
committed
Meta: define events instead of relying on HTML's definitions
Part of whatwg/html#7414.
1 parent fee98ff commit fc9f8da

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

index.bs

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ spec:url; type:dfn;
3030
spec:html; type:dfn;
3131
text:task queues
3232
for:/; text:event loop
33-
spec:html; type:idl; text:MessageEvent
34-
spec:html; type:event; for:WebSocket;
35-
text:message
36-
text:error
37-
spec:encoding-1; type:dfn; for:/; text:encoding
3833
spec:url; type:dfn;
3934
text:origin
4035
for:/; text:url
@@ -343,7 +338,7 @@ It can have the following values:
343338
fails, it triggers the [=fail the WebSocket connection=] algorithm, which
344339
then invokes the [=close the WebSocket connection=] algorithm, which then
345340
establishes that [=the WebSocket connection is closed=], which fires the
346-
{{close!!event}} event <a href="#closeWebSocket">as described below</a>.
341+
{{WebSocket/close}} event <a href="#closeWebSocket">as described below</a>.
347342
</div>
348343

349344
<hr>
@@ -375,15 +370,15 @@ string. After [=the WebSocket connection is established=], its value might chang
375370
:: Do nothing.
376371

377372
<p class="note">The connection is already closing or is already closed. If it has not already, a
378-
{{close!!event}} event will eventually fire <a href="#closeWebSocket">as described below</a>.
373+
{{WebSocket/close}} event will eventually fire <a href="#closeWebSocket">as described below</a>.
379374

380375
: If the WebSocket connection is not yet [=established=] [[!WSP]]
381376
:: [=Fail the WebSocket connection=] and set [=this=]'s [=WebSocket/ready state=] to
382377
{{WebSocket/CLOSING}} (2). [[!WSP]]
383378

384379
<p class="note">The [=fail the WebSocket connection=] algorithm invokes the [=close the
385380
WebSocket connection=] algorithm, which then establishes that [=the WebSocket connection is
386-
closed=], which fires the {{close!!event}} event <a href="#closeWebSocket">as described
381+
closed=], which fires the {{WebSocket/close}} event <a href="#closeWebSocket">as described
387382
below</a>.
388383

389384
: If the WebSocket closing handshake has not yet been <a lt="the WebSocket closing handshake is
@@ -405,15 +400,15 @@ string. After [=the WebSocket connection is established=], its value might chang
405400

406401
<p class="note">The [=start the WebSocket closing handshake=] algorithm eventually invokes the
407402
[=close the WebSocket connection=] algorithm, which then establishes that [=the WebSocket
408-
connection is closed=], which fires the {{close!!event}} event <a href="#closeWebSocket">as
403+
connection is closed=], which fires the {{WebSocket/close}} event <a href="#closeWebSocket">as
409404
described below</a>.
410405

411406
: Otherwise
412407
:: Set [=this=]'s [=WebSocket/ready state=] to {{WebSocket/CLOSING}} (2).
413408

414409
<p class="note">[=The WebSocket closing handshake is started=], and will eventually invoke the
415410
[=close the WebSocket connection=] algorithm, which will establish that [=the WebSocket
416-
connection is closed=], and thus the {{close!!event}} event will fire, <a
411+
connection is closed=], and thus the {{WebSocket/close}} event will fire, <a
417412
href="#closeWebSocket">as described below</a>.
418413
</dl>
419414
</div>
@@ -540,10 +535,10 @@ that must be supported, as [=event handler IDL attributes=], by all objects impl
540535
<thead>
541536
<tr><th>[=Event handler=] <th>[=Event handler event type=]
542537
<tbody>
543-
<tr><td><dfn attribute for=WebSocket>onopen</dfn> <td> {{open!!event}}
544-
<tr><td><dfn attribute for=WebSocket>onmessage</dfn> <td> {{message!!event}}
545-
<tr><td><dfn attribute for=WebSocket>onerror</dfn> <td> {{error!!event}}
546-
<tr><td><dfn attribute for=WebSocket>onclose</dfn> <td> {{close!!event}}
538+
<tr><td><dfn attribute for=WebSocket>onopen</dfn> <td> {{WebSocket/open}}
539+
<tr><td><dfn attribute for=WebSocket>onmessage</dfn> <td> {{WebSocket/message}}
540+
<tr><td><dfn attribute for=WebSocket>onerror</dfn> <td> {{WebSocket/error}}
541+
<tr><td><dfn attribute for=WebSocket>onclose</dfn> <td> {{WebSocket/close}}
547542
</table>
548543

549544

@@ -559,11 +554,12 @@ steps:
559554
use=], if it is not the null value. [[!WSP]]
560555
1. Change the {{WebSocket/protocol}} attribute's value to the [=subprotocol in
561556
use=], if it is not the null value. [[!WSP]]
562-
1. [=Fire an event=] named {{open!!event}} at the {{WebSocket}} object.
557+
1. [=Fire an event=] named <dfn event for="WebSocket">open</dfn> at the {{WebSocket}} object.
563558

564559
<p class="note">Since the algorithm above is <a lt="queue a task">queued as a task</a>, there is no
565560
race condition between <a lt="the WebSocket connection is established">the WebSocket connection
566-
being established</a> and the script setting up an event listener for the {{open!!event}} event.
561+
being established</a> and the script setting up an event listener for the {{WebSocket/open}}
562+
event.
567563

568564
</div>
569565

@@ -592,8 +588,8 @@ When [=a WebSocket message has been received=] with type |type| and data |data|,
592588
whose contents are |data|
593589
</dl>
594590

595-
1. [=Fire an event=] named {{message!!event}} at the {{WebSocket}} object, using {{MessageEvent}},
596-
with the {{MessageEvent/origin}} attribute initialized to the <a lt="URL
591+
1. [=Fire an event=] named <dfn event for="WebSocket">message</dfn> at the {{WebSocket}} object,
592+
using {{MessageEvent}}, with the {{MessageEvent/origin}} attribute initialized to the <a lt="URL
597593
serializer">serialization</a> of the {{WebSocket}} object's [=url=]'s [=origin=], and the
598594
{{MessageEvent/data}} attribute initialized to |dataForEvent|.
599595

@@ -609,8 +605,8 @@ this [=task=] so as to avoid stalling the main thread while it created the {{Arr
609605

610606
<div class="example" id="message-example">
611607

612-
Here is an example of how to define a handler for the {{message!!event}}
613-
event in the case of text frames:
608+
Here is an example of how to define a handler for the {{WebSocket/message}} event in the case of
609+
text frames:
614610

615611
<xmp highlight="js">
616612
mysocket.onmessage = function (event) {
@@ -642,12 +638,14 @@ this task runs.) [[!WSP]]
642638
1. Change the [=WebSocket/ready state=] to {{WebSocket/CLOSED}} (3).
643639
1. If the user agent was required to [=fail the WebSocket connection=], or if <a lt="the
644640
WebSocket connection is closed">the WebSocket connection was closed</a> after being <dfn>flagged
645-
as full</dfn>, [=fire an event=] named {{error!!event}} at the {{WebSocket}} object. [[!WSP]]
646-
1. [=Fire an event=] named {{close!!event}} at the {{WebSocket}} object, using {{CloseEvent}}, with
647-
the {{CloseEvent/wasClean}} attribute initialized to true if the connection closed [=cleanly=]
648-
and false otherwise, the {{CloseEvent/code}} attribute initialized to [=the WebSocket connection
649-
close code=], and the {{CloseEvent/reason}} attribute initialized to the result of applying
650-
[=UTF-8 decode without BOM=] to [=the WebSocket connection close reason=]. [[!WSP]]
641+
as full</dfn>, [=fire an event=] named <dfn event for="WebSocket">error</dfn> at the
642+
{{WebSocket}} object. [[!WSP]]
643+
1. [=Fire an event=] named <dfn event for="WebSocket">close</dfn> at the {{WebSocket}} object,
644+
using {{CloseEvent}}, with the {{CloseEvent/wasClean}} attribute initialized to true if the
645+
connection closed [=cleanly=] and false otherwise, the {{CloseEvent/code}} attribute initialized
646+
to [=the WebSocket connection close code=], and the {{CloseEvent/reason}} attribute initialized
647+
to the result of applying [=UTF-8 decode without BOM=] to [=the WebSocket connection close
648+
reason=]. [[!WSP]]
651649
</div>
652650

653651
<div class="warning">
@@ -703,7 +701,7 @@ https://www.w3.org/Bugs/Public/show_bug.cgi?id=17264 -->
703701

704702
# The {{CloseEvent}} interface # {#the-closeevent-interface}
705703

706-
{{WebSocket}} objects use the {{CloseEvent}} interface for their {{close!!event}} events:
704+
{{WebSocket}} objects use the {{CloseEvent}} interface for their {{WebSocket/close}} events:
707705

708706
<xmp class="idl">
709707
[Exposed=(Window,Worker)]
@@ -748,17 +746,17 @@ to. It represents the WebSocket connection close reason provided by the server.
748746

749747
A {{WebSocket}} object whose [=WebSocket/ready state=] was set to {{WebSocket/CONNECTING}} (0) as
750748
of the last time the [=event loop=] reached <a for="event loop">step 1</a> must not be garbage
751-
collected if there are any event listeners registered for {{open!!event}} events,
752-
{{message!!event}} events, {{error!!event}} events, or {{close!!event}} events.
749+
collected if there are any event listeners registered for {{WebSocket/open}} events,
750+
{{WebSocket/message}} events, {{WebSocket/error}} events, or {{WebSocket/close}} events.
753751

754752
A {{WebSocket}} object whose [=WebSocket/ready state=] was set to {{WebSocket/OPEN}} (1) as of the
755753
last time the [=event loop=] reached <a for="event loop">step 1</a> must not be garbage collected
756-
if there are any event listeners registered for {{message!!event}} events, {{error!!event}}, or
757-
{{close!!event}} events.
754+
if there are any event listeners registered for {{WebSocket/message}} events, {{WebSocket/error}},
755+
or {{WebSocket/close}} events.
758756

759757
A {{WebSocket}} object whose [=WebSocket/ready state=] was set to {{WebSocket/CLOSING}} (2) as of
760758
the last time the [=event loop=] reached <a for="event loop">step 1</a> must not be garbage
761-
collected if there are any event listeners registered for {{error!!event}} or {{close!!event}}
759+
collected if there are any event listeners registered for {{WebSocket/error}} or {{WebSocket/close}}
762760
events.
763761

764762
A {{WebSocket}} object with <a lt="the WebSocket connection is established">an established

0 commit comments

Comments
 (0)