Skip to content

Commit 6c68bd8

Browse files
committed
Use Extended MessageEvent
whatwg/html#1944 extended MessageEvent to accept a ServiceWorker object as a type of the source attribute. This replaces ServiceWorkerMessageEvent with MessageEvent to reduce the redundancy. Fixes #989. Related changes: whatwg/html#1944.
1 parent f3fec29 commit 6c68bd8

File tree

4 files changed

+275
-709
lines changed

4 files changed

+275
-709
lines changed

docs/index.bs

Lines changed: 10 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
355355
<li>Let <var>newPorts</var> be a new <a lt="frozen array type">frozen array</a> consisting of all {{MessagePort}} objects in <var>cloneRecord</var>.\[[TransferList]], if any, maintaining their relative order.</li>
356356
<li><a>Queue a task</a> that runs the following steps:
357357
<ol>
358-
<li>Create an event <var>e</var> that uses the {{ExtendableMessageEvent}} interface, with the event type <a href="#service-worker-global-scope-message-event">message</a>, which does not bubble and is not cancelable.</li>
358+
<li>Create an event <var>e</var> that uses the {{ExtendableMessageEvent}} interface, with the event type {{message!!event}}, which does not bubble and is not cancelable.</li>
359359
<li>Let the {{ExtendableMessageEvent/data}} attribute of <var>e</var> be initialized to <var>clonedMessage</var>.</li>
360360
<li>Let the {{ExtendableMessageEvent/origin}} attribute of <var>e</var> be initialized to the <a lt="Unicode serialization of an origin">Unicode serialization</a> of <var>incumbentSettings</var>'s <a for="resource">origin</a>.</li>
361361
<li>If <var>incumbentGlobal</var> is a {{ServiceWorkerGlobalScope}} object, let the {{ExtendableMessageEvent/source}} attribute of <var>e</var> be initialized to a new {{ServiceWorker}} object that represents <var>incumbentGlobal</var>'s <a for="ServiceWorkerGlobalScope">service worker</a>.</li>
@@ -700,7 +700,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
700700
</tr>
701701
<tr>
702702
<td><dfn attribute for="ServiceWorkerContainer"><code>onmessage</code></dfn></td>
703-
<td><code><a href="#service-worker-container-message-event">message</a></code></td>
703+
<td><code><a href="https://html.spec.whatwg.org/#event-message">message</a></code></td>
704704
</tr>
705705
</tbody>
706706
</table>
@@ -709,62 +709,6 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
709709
</section>
710710
</section>
711711

712-
<section>
713-
<h3 id="serviceworkermessageevent-interface">{{ServiceWorkerMessageEvent}}</h3>
714-
715-
<pre class="idl">
716-
[Constructor(DOMString type, optional ServiceWorkerMessageEventInit eventInitDict), Exposed=(Window,Worker)]
717-
interface ServiceWorkerMessageEvent : Event {
718-
readonly attribute any data;
719-
readonly attribute USVString origin;
720-
readonly attribute DOMString lastEventId;
721-
[SameObject] readonly attribute (ServiceWorker or MessagePort)? source;
722-
readonly attribute FrozenArray&lt;MessagePort&gt; ports;
723-
};
724-
</pre>
725-
<pre class="idl" id="serviceworkermessage-event-init-dictionary">
726-
dictionary ServiceWorkerMessageEventInit : EventInit {
727-
any data = null;
728-
USVString origin = "";
729-
DOMString lastEventId = "";
730-
(ServiceWorker or MessagePort)? source = null;
731-
sequence&lt;MessagePort&gt; ports = [];
732-
};
733-
</pre>
734-
735-
<p><a href="#dfn-service-worker">Service workers</a> define the <a href="#service-worker-container-message-event">message</a> event that extends the {{Window/message}} event defined in [[!HTML]] to allow setting a {{ServiceWorker}} object as the source of the message. For the <a href="#service-worker-container-message-event">message</a> event, <a href="#dfn-service-worker">service workers</a> use the {{ServiceWorkerMessageEvent}} interface.</p>
736-
737-
<section>
738-
<h4 id="serviceworkermessage-event-data">{{ServiceWorkerMessageEvent/data|event.data}}</h4>
739-
740-
<p>The <dfn attribute for="ServiceWorkerMessageEvent">data</dfn> attribute <em class="rfc2119" title="MUST">must</em> return the value it was initialized to. When the object is created, this attribute <em class="rfc2119" title="MUST">must</em> be initialized to null. It represents the message being sent.</p>
741-
</section>
742-
743-
<section>
744-
<h4 id="serviceworkermessage-event-origin">{{ServiceWorkerMessageEvent/origin|event.origin}}</h4>
745-
746-
<p>The <dfn attribute for="ServiceWorkerMessageEvent">origin</dfn> attribute <em class="rfc2119" title="MUST">must</em> return the value it was initialized to. When the object is created, this attribute <em class="rfc2119" title="MUST">must</em> be initialized to the empty string. It represents the <a for="resource">origin</a> of the <a href="#dfn-service-worker">service worker</a>'s <a>environment settings object</a> from which the message is sent.</p>
747-
</section>
748-
749-
<section>
750-
<h4 id="serviceworkermessage-event-lasteventid">{{ServiceWorkerMessageEvent/lastEventId|event.lastEventId}}</h4>
751-
752-
<p>The <dfn attribute for="ServiceWorkerMessageEvent">lastEventId</dfn> attribute <em class="rfc2119" title="MUST">must</em> return the value it was initialized to. When the object is created, this attribute <em class="rfc2119" title="MUST">must</em> be initialized to the empty string.</p>
753-
</section>
754-
755-
<section>
756-
<h4 id="serviceworkermessage-event-source">{{ServiceWorkerMessageEvent/source|event.source}}</h4>
757-
758-
<p>The <dfn attribute for="ServiceWorkerMessageEvent">source</dfn> attribute <em class="rfc2119" title="MUST">must</em> return the value it was initialized to. When the object is created, this attribute <em class="rfc2119" title="MUST">must</em> be initialized to null. It represents the {{ServiceWorker}} object whose associated <a href="#dfn-service-worker">service worker</a> the message is sent from.</p>
759-
</section>
760-
761-
<section>
762-
<h4 id="serviceworkermessage-event-ports">{{ServiceWorkerMessageEvent/ports|event.ports}}</h4>
763-
764-
<p>The <dfn attribute for="ServiceWorkerMessageEvent">ports</dfn> attribute <em class="rfc2119" title="MUST">must</em> return the value it was initialized to. When the object is created, this attribute <em class="rfc2119" title="MUST">must</em> be initialized to the empty array. It represents the {{MessagePort}} array being sent.</p>
765-
</section>
766-
</section>
767-
768712
<section>
769713
<h3 id="document-context-events">Events</h3>
770714

@@ -822,11 +766,6 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
822766
<td>{{Event}}</td>
823767
<td>The <a for="ServiceWorkerContainer">service worker client</a>'s <a>active service worker</a> changes. (See step 9.2 of the <a href="#activation-algorithm">Activate</a> algorithm. The <a href="#dfn-skip-waiting-flag">skip waiting flag</a> of a <a href="#dfn-service-worker">service worker</a> causes <a href="#activation-algorithm">activation</a> of the <a href="#dfn-service-worker-registration">service worker registration</a> to occur while <a href="#dfn-service-worker-client">service worker clients</a> are <a href="#dfn-use">using</a> the <a href="#dfn-service-worker-registration">service worker registration</a>, {{ServiceWorkerContainer/controller|navigator.serviceWorker.controller}} immediately reflects the <a href="#dfn-active-worker">active worker</a> as the <a href="#dfn-service-worker">service worker</a> that <a href="#dfn-control">controls</a> the <a href="#dfn-service-worker-client">service worker client</a>.)</td>
824768
</tr>
825-
<tr>
826-
<td><dfn event id="service-worker-container-message-event"><code>message</code></dfn></td>
827-
<td>{{ServiceWorkerMessageEvent}}</td>
828-
<td>When it receives a message.</td>
829-
</tr>
830769
</tbody>
831770
</table>
832771
</section>
@@ -968,7 +907,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
968907
</tr>
969908
<tr>
970909
<td><dfn attribute for="ServiceWorkerGlobalScope"><code>onmessage</code></dfn></td>
971-
<td><code><a href="#service-worker-global-scope-message-event">message</a></code></td>
910+
<td>{{message!!event}}</td>
972911
</tr>
973912
</tbody>
974913
</table>
@@ -1040,11 +979,11 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
1040979
<li>Let <var>newPorts</var> be a new <a lt="frozen array type">frozen array</a> consisting of all {{MessagePort}} objects in <var>cloneRecord</var>.\[[TransferList]], if any, maintaining their relative order.</li>
1041980
<li>Add a <a>task</a> that runs the following steps to <var>destination</var>'s <a for="ServiceWorkerContainer">client message queue</a>:
1042981
<ol>
1043-
<li>Create an event <var>e</var> that uses the {{ServiceWorkerMessageEvent}} interface, with the event type <a href="#service-worker-container-message-event">message</a>, which does not bubble and is not cancelable.</li>
1044-
<li>Let the {{ServiceWorkerMessageEvent/data}} attribute of <var>e</var> be initialized to <var>clonedMessage</var>.</li>
1045-
<li>Let the {{ServiceWorkerMessageEvent/origin}} attribute of <var>e</var> be initialized to the <a lt="Unicode serialization of an origin">Unicode serialization</a> of <var>sourceSettings</var>'s <a for="resource">origin</a>.</li>
1046-
<li>Let the {{ServiceWorkerMessageEvent/source}} attribute of <var>e</var> be initialized to a {{ServiceWorker}} object, which represents the <a for="ServiceWorkerGlobalScope">service worker</a> associated with <var>sourceSettings</var>'s <a for="environment settings object">global object</a>.</li>
1047-
<li>Let the {{ServiceWorkerMessageEvent/ports}} attribute of <var>e</var> be initialized to <var>newPorts</var>.</li>
982+
<li>Create an event <var>e</var> that uses the {{MessageEvent}} interface, with the event type <a href="https://html.spec.whatwg.org/#event-message">message</a>, which does not bubble and is not cancelable.</li>
983+
<li>Let the <a href="https://html.spec.whatwg.org/#dom-messageevent-data">data</a> attribute of <var>e</var> be initialized to <var>clonedMessage</var>.</li>
984+
<li>Let the <a href="https://html.spec.whatwg.org/#dom-messageevent-origin">origin</a> attribute of <var>e</var> be initialized to the <a lt="Unicode serialization of an origin">Unicode serialization</a> of <var>sourceSettings</var>'s <a for="resource">origin</a>.</li>
985+
<li>Let the <a href="https://html.spec.whatwg.org/#dom-messageevent-source">source</a> attribute of <var>e</var> be initialized to a {{ServiceWorker}} object, which represents the <a for="ServiceWorkerGlobalScope">service worker</a> associated with <var>sourceSettings</var>'s <a for="environment settings object">global object</a>.</li>
986+
<li>Let the <a href="https://html.spec.whatwg.org/#dom-messageevent-ports">ports</a> attribute of <var>e</var> be initialized to <var>newPorts</var>.</li>
1048987
<li><a>Dispatch</a> <var>e</var> at <var>destination</var>.</li>
1049988
</ol>
1050989
</li>
@@ -1872,7 +1811,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
18721811
};
18731812
</pre>
18741813

1875-
<p><a href="#dfn-service-worker">Service workers</a> define the <a href="#dom-extendableevent-waituntil">extendable</a> <a href="#service-worker-global-scope-message-event">message</a> event that extends the {{Window/message}} event defined in [[!HTML]] to allow extending the lifetime of the event. For the <a href="#service-worker-global-scope-message-event">message</a> event, <a href="#dfn-service-worker">service workers</a> use the {{ExtendableMessageEvent}} interface which extends the {{ExtendableEvent}} interface.</p>
1814+
<p><a href="#dfn-service-worker">Service workers</a> define the <a href="#dom-extendableevent-waituntil">extendable</a> {{message!!event}} event to allow extending the lifetime of the event. For the {{message!!event}} event, <a href="#dfn-service-worker">service workers</a> use the {{ExtendableMessageEvent}} interface which extends the {{ExtendableEvent}} interface.</p>
18761815

18771816
<section>
18781817
<h4 id="extendablemessage-event-data">{{ExtendableMessageEvent/data|event.data}}</h4>
@@ -1940,7 +1879,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
19401879
<td>[<a href="#dfn-functional-events">Functional event</a>] The <a>http fetch</a> invokes [[#on-foreign-fetch-request-algorithm]] with <var>request</var>. As a result of performing [[#on-foreign-fetch-request-algorithm]], the <a for="ServiceWorkerGlobalScope">service worker</a> returns a <a for="fetch">response</a> to the <a>http fetch</a>. The <a for="fetch">response</a>, represented by a {{Response}} object, can be retrieved from a {{Cache}} object or directly from network using {{WindowOrWorkerGlobalScope/fetch(input, init)|self.fetch(input, init)}} method. (A custom {{Response}} object can be another option.)</td>
19411880
</tr>
19421881
<tr>
1943-
<td><dfn event id="service-worker-global-scope-message-event"><code>message</code></dfn></td>
1882+
<td><dfn event><code>message</code></dfn></td>
19441883
<td>{{ExtendableMessageEvent}}</td>
19451884
<td>When it receives a message.</td>
19461885
</tr>

0 commit comments

Comments
 (0)