Skip to content

Check BroadcastChannel origin against creation-time current #5729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 46 additions & 53 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -98150,88 +98150,79 @@ interface <dfn>BroadcastChannel</dfn> : <span>EventTarget</span> {

<div w-nodev>

<p>A <code>BroadcastChannel</code> object has a <dfn>channel name</dfn>, a
<dfn><code>BroadcastChannel</code> settings object</dfn>, and a <dfn
<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>The <dfn><code data-x="dom-BroadcastChannel">BroadcastChannel()</code></dfn> constructor, when
invoked, must create and return a <code>BroadcastChannel</code> object whose <span>channel
name</span> is the constructor's first argument, whose <span><code>BroadcastChannel</code>
settings object</span> is the <span>incumbent settings object</span>, and whose <span
data-x="concept-BroadcastChannel-closed">closed flag</span> is false.</p>

<p>The <dfn><code data-x="dom-BroadcastChannel-name">name</code></dfn> attribute must return the
<span>channel name</span>.</p>

<p>The <dfn><code
data-x="dom-BroadcastChannel-postMessage">postMessage(<var>message</var>)</code></dfn> method,
when invoked on a <code>BroadcastChannel</code> object, must run the following steps:</p>
<p>The <dfn><code data-x="dom-BroadcastChannel">new BroadcastChannel(<var>name</var>)</code></dfn>
constructor steps are:</p>

<ol>
<li><p>Let <var>source</var> be this <code>BroadcastChannel</code>.</p></li>
<li><p>Set <span>this</span>'s <span>channel name</span> to <var>name</var>.</p></li>

<li><p>Let <var>sourceSettings</var> be <var>source</var>'s <span><code>BroadcastChannel</code>
settings object</span>.</p></li>
<li><p>Set <span>this</span>'s <span data-x="concept-BroadcastChannel-closed">closed flag</span>
to false.</p></li>
</ol>

<li><p>If <var>source</var>'s <span data-x="concept-BroadcastChannel-closed">closed flag</span>
is true, then throw an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.</p></li>
<p>The <dfn><code data-x="dom-BroadcastChannel-name">name</code></dfn> getter steps are to return
<span>this</span>'s <span>channel name</span>.</p>

<li><p>Let <var>sourceChannel</var> be <var>source</var>'s <span>channel name</span>.</p></li>
<p>The <dfn><code
data-x="dom-BroadcastChannel-postMessage">postMessage(<var>message</var>)</code></dfn> method
steps are:</p>

<li><p>Let <var>targetRealm</var> be an <span>implementation-defined</span> Realm.</p></li>
<ol>
<li><p>If <span>this</span>'s <span data-x="concept-BroadcastChannel-closed">closed flag</span>
is true, then throw an <span>"<code>InvalidStateError</code>"</span>
<code>DOMException</code>.</p></li>

<li><p>Let <var>serialized</var> be <span>StructuredSerialize</span>(<var>message</var>). Rethrow
any exceptions.</p></li>

<li><p>Let <var>sourceOrigin</var> be <span>this</span>'s <span>relevant settings object</span>'s
<span data-x="concept-settings-object-origin">origin</span>.</p></li>

<li>
<p>Let <var>destinations</var> be a list of <code>BroadcastChannel</code> objects that
match the following criteria:</p>

<ul>
<li>
<p>Their <span><code>BroadcastChannel</code> settings object</span> specifies either:</p>
<p>Their <span>relevant global object</span> is either:</p>

<ul>
<li><p>a <span data-x="concept-settings-object-global">global object</span> that is a
<code>Window</code> object whose <span data-x="concept-document-window">associated
<li><p>a <code>Window</code> object whose <span data-x="concept-document-window">associated
<code>Document</code></span> is <span>fully active</span>, or</p></li>

<li><p>a <span data-x="concept-settings-object-global">global object</span> that is a
<code>WorkerGlobalScope</code> object whose <span
<li><p>a <code>WorkerGlobalScope</code> object whose <span
data-x="dom-WorkerGlobalScope-closing">closing</span> flag is false and whose
<span>worker</span> is not a <span>suspendable worker</span>.</p></li>
</ul>
</li>

<li><p>Their <span><code>BroadcastChannel</code> settings object</span>'s <span
<li><p>Their <span>relevant settings object</span>'s <span
data-x="concept-settings-object-origin">origin</span> is <span>same origin</span> with
<var>sourceSettings</var>'s <span
data-x="concept-settings-object-origin">origin</span>.</p></li>
<var>sourceOrigin</var>.</p></li>

<li><p>Their <span>channel name</span> <span>is</span> <var>sourceChannel</var>.</p></li>
<li><p>Their <span>channel name</span> <span>is</span> <span>this</span>'s <span>channel
name</span>.</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
<span data-x="BroadcastChannel settings object"><code>BroadcastChannel</code> settings
objects</span> specify the same <span>responsible event loop</span> are sorted in creation
order, oldest first. (This does not define a complete ordering. Within this constraint, user
agents may sort the list in any <span>implementation-defined</span> manner.)</p></li>
<span data-x="relevant agent">relevant agents</span> are the same are sorted in creation order,
oldest first. (This does not define a complete ordering. Within this constraint, user agents may
sort the list in any <span>implementation-defined</span> manner.)</p></li>

<li>
<p>For each <code>BroadcastChannel</code> object <var>destination</var> in
<var>destinations</var>, <span>queue a task</span> on the <span>DOM manipulation task
source</span> of <var>destination</var>'s <span>relevant agent</span>'s <span
data-x="concept-agent-event-loop">event loop</span> that runs the following steps. If that event
loop is a <span>window event loop</span>, then the <span data-x="concept-task">task</span>'s
<span data-x="concept-task-document">document</span> must be set to <var>destination</var>'s
<span><code>BroadcastChannel</code> settings object</span>'s <span>responsible document</span>.</p>
<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 return.</p></li>
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>
Expand All @@ -98244,31 +98235,31 @@ interface <dfn>BroadcastChannel</dfn> : <span>EventTarget</span> {
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>sourceSettings</var>'s <span
data-x="concept-settings-object-origin">origin</span>, and then return.</p>
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>sourceSettings</var>'s <span
data-x="concept-settings-object-origin">origin</span>.</p></li>
<var>sourceOrigin</var>.</p></li>
</ol>
</li>
</ol>

<p>While a <code>BroadcastChannel</code> object whose <span
data-x="concept-BroadcastChannel-closed">closed flag</span> is false has an event listener
registered for <code data-x="event-message">message</code> events, there must be a strong
reference from <span data-x="concept-settings-object-global">global object</span> specified by
the <code>BroadcastChannel</code> object's <span><code>BroadcastChannel</code> settings
object</span> to the <code>BroadcastChannel</code> object itself.</p>
registered for <code data-x="event-message">message</code> or <code
data-x="event-messageerror">messageerror</code> events, there must be a strong reference from the
<code>BroadcastChannel</code> object's <span>relevant global object</span> to the
<code>BroadcastChannel</code> object itself.</p>

<p>The <dfn><code data-x="dom-BroadcastChannel-close">close()</code></dfn> method must set the
<span data-x="concept-BroadcastChannel-closed">closed flag</span> of the
<code>BroadcastChannel</code> object on which it was invoked to true.</p>
<p>The <dfn><code data-x="dom-BroadcastChannel-close">close()</code></dfn> method steps are to set
<span>this</span>'s <span data-x="concept-BroadcastChannel-closed">closed flag</span> to true.</p>

</div>

<p class="note">Authors are strongly encouraged to explicitly close <code>BroadcastChannel</code>
objects when they are no longer needed, so that they can be garbage collected. Creating many
Expand All @@ -98277,6 +98268,8 @@ interface <dfn>BroadcastChannel</dfn> : <span>EventTarget</span> {
continue to live for as long as they have an event listener (or until their page or worker is
closed).</p>

<div w-nodev>

<hr>

<p>The following are the <span>event handlers</span> (and their corresponding <span data-x="event
Expand Down