Skip to content

Commit

Permalink
Add queueing spec for broadcast channel
Browse files Browse the repository at this point in the history
  • Loading branch information
lozy219 committed Sep 20, 2023
1 parent 43859d4 commit 7a3925f
Showing 1 changed file with 53 additions and 32 deletions.
85 changes: 53 additions & 32 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -113696,8 +113696,14 @@ interface <dfn interface>BroadcastChannel</dfn> : <span>EventTarget</span> {

<div w-nodev>

<p>A <code>BroadcastChannel</code> object has a <dfn>channel name</dfn> and a <dfn
data-x="concept-BroadcastChannel-closed">closed flag</dfn>.</p>
<p>A <code>BroadcastChannel</code> object has a <dfn>channel name</dfn>, a
<dfn data-x="concept-BroadcastChannel-closed">closed flag</dfn> and an initially empty
<span>task source</span> <dfn>message queue</dfn>.

<p class="note">The <span data-x="concept-task">task</span> from <span>message queue</span>
will only be run by the <span>event loop</span> when the <span>relevant global object</span>
is a <code>Window</code> object whose <span data-x="concept-document-window">associated
<code>Document</code></span> is <span>fully active</span>.</p>

<p>The <dfn><code data-x="dom-BroadcastChannel">new BroadcastChannel(<var>name</var>)</code></dfn>
constructor steps are:</p>
Expand Down Expand Up @@ -113725,6 +113731,37 @@ interface <dfn interface>BroadcastChannel</dfn> : <span>EventTarget</span> {
<span>worker</span> is not a <span>suspendable worker</span>.</p></li>
</ul>

<p>To <dfn data-x="dom-BroadcastChannel-post-a-message">post a message</dfn> to a
<code>BroadcastChannel</code> given a string <var>serialized</var>, run these steps:</p>

<ol>
<li><p>If <code>BroadcastChannel</code>'s <span data-x="concept-BroadcastChannel-closed">closed
flag</span> is true, then abort these steps.</p></li>

<li><p>Let <var>targetRealm</var> be <var>destination</var>'s <span
data-x="concept-relevant-realm">relevant realm</span>.</p></li>

<li>
<p>Let <var>data</var> be <span>StructuredDeserialize</span>(<var>serialized</var>,
<var>targetRealm</var>).</p>

<p>If this throws an exception, catch it, <span data-x="concept-event-fire">fire an
event</span> named <code data-x="event-messageerror">messageerror</code> at
<var>destination</var>, using <code>MessageEvent</code>, with the <code
data-x="dom-MessageEvent-origin">origin</code> attribute initialized to the <span
data-x="serialization of an origin">serialization</span> of <var>sourceOrigin</var>, and then
abort these steps.</p>
</li>

<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
data-x="event-message">message</code> at <code>BroadcastChannel</code>, using
<code>MessageEvent</code>, with the <code data-x="dom-MessageEvent-data">data</code> attribute
initialized to <var>data</var> and the <code data-x="dom-MessageEvent-origin">origin</code>
attribute initialized to the <span data-x="serialization of an origin">serialization</span> of
<var>sourceOrigin</var>.</p></li>
</ol>


<p>The <dfn method for="BroadcastChannel"><code
data-x="dom-BroadcastChannel-postMessage">postMessage(<var>message</var>)</code></dfn> method
steps are:</p>
Expand All @@ -113751,8 +113788,6 @@ interface <dfn interface>BroadcastChannel</dfn> : <span>EventTarget</span> {
match the following criteria:</p>

<ul>
<li><p>They are <span>eligible for messaging</span>.</p></li>

<li><p>The result of running <span>obtain a storage key for non-storage purposes</span> with
their <span>relevant settings object</span> <span data-x="storage key equal">equals</span>
<var>sourceStorageKey</var>.</p></li>
Expand All @@ -113762,6 +113797,18 @@ interface <dfn interface>BroadcastChannel</dfn> : <span>EventTarget</span> {
</ul>
</li>

<li>
<p>For each <var>destination</var> in <var>destinations</var>, if <var>destination</var> is
not <span>eligible for messaging</span>, perfrom the following steps:</p>
<ul>
<li><p>If <var>destination</var>'s <span>relevant global object</span> is a
<code>Window</code>, add a <span data-x="concept-task">task</span> that
<span data-x="dom-BroadcastChannel-post-a-message">posts a message</span> with
<var>serialized</var> to <var>destination</var>.</p></li>
<li><p>Remove <var>destination</var> from <var>destinations</var>.</p></li>
</ul>
</li>

<li><p>Remove <var>source</var> from <var>destinations</var>.</p></li>

<li><p>Sort <var>destinations</var> such that all <code>BroadcastChannel</code> objects whose
Expand All @@ -113772,34 +113819,8 @@ interface <dfn interface>BroadcastChannel</dfn> : <span>EventTarget</span> {
<li>
<p>For each <var>destination</var> in <var>destinations</var>, <span>queue a global task</span>
on the <span>DOM manipulation task source</span> given <var>destination</var>'s <span>relevant
global object</span> to perform the following steps:</p>

<ol>
<li><p>If <var>destination</var>'s <span data-x="concept-BroadcastChannel-closed">closed
flag</span> is true, then abort these steps.</p></li>

<li><p>Let <var>targetRealm</var> be <var>destination</var>'s <span
data-x="concept-relevant-realm">relevant realm</span>.</p></li>

<li>
<p>Let <var>data</var> be <span>StructuredDeserialize</span>(<var>serialized</var>,
<var>targetRealm</var>).</p>

<p>If this throws an exception, catch it, <span data-x="concept-event-fire">fire an
event</span> named <code data-x="event-messageerror">messageerror</code> at
<var>destination</var>, using <code>MessageEvent</code>, with the <code
data-x="dom-MessageEvent-origin">origin</code> attribute initialized to the <span
data-x="serialization of an origin">serialization</span> of <var>sourceOrigin</var>, and then
abort these steps.</p>
</li>

<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
data-x="event-message">message</code> at <var>destination</var>, using
<code>MessageEvent</code>, with the <code data-x="dom-MessageEvent-data">data</code> attribute
initialized to <var>data</var> and the <code data-x="dom-MessageEvent-origin">origin</code>
attribute initialized to the <span data-x="serialization of an origin">serialization</span> of
<var>sourceOrigin</var>.</p></li>
</ol>
global object</span> to <span data-x="dom-BroadcastChannel-post-a-message">post a message</span>
with <var>serialized</var> to <var>destination</var>.</p>
</li>
</ol>

Expand Down

0 comments on commit 7a3925f

Please sign in to comment.