Skip to content
Permalink
Browse files

[giow] (1) Make BroadcastChannel objects work in workers

Fixing https://www.w3.org/Bugs/Public/show_bug.cgi?id=24414
Affected topics: DOM APIs

git-svn-id: http://svn.whatwg.org/webapps@8660 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information...
Hixie committed Jun 6, 2014
1 parent ad061c5 commit 300e7def9f9c31b25b995445bed87bfcdad3a3d7
Showing with 46 additions and 27 deletions.
  1. +14 −9 complete.html
  2. +14 −9 index
  3. +18 −9 source
<p>For simple cases, though, where a shared worker would be an unreasonable overhead, authors can
use the simple channel-based broadcast mechanism described in this section.</p>

<pre class=idl>[<a href=#dom-broadcastchannel title=dom-BroadcastChannel>Constructor</a>(DOMString channel)]
<pre class=idl>[<a href=#dom-broadcastchannel title=dom-BroadcastChannel>Constructor</a>(DOMString channel), Exposed=Window,Worker]
interface <dfn id=broadcastchannel>BroadcastChannel</dfn> : <a href=#eventtarget>EventTarget</a> {
readonly attribute DOMString <a href=#dom-broadcastchannel-name title=dom-BroadcastChannel-name>name</a>;
void <a href=#dom-broadcastchannel-postmessage title=dom-BroadcastChannel-postMessage>postMessage</a>(any message);
<p>Let <var title="">destinations</var> be a list of <code><a href=#broadcastchannel>BroadcastChannel</a></code> objects that
match the following criteria:</p>

<ul><li><p>Their <a href=#broadcastchannel-settings-object><code>BroadcastChannel</code> settings object</a> specifies a
<a href=#responsible-document>responsible document</a> that is <a href=#fully-active>fully active</a>.</li>
<ul><li>

<p>Their <a href=#broadcastchannel-settings-object><code>BroadcastChannel</code> settings object</a> specifies either:</p>

<ul><li><p>a <a href=#global-object>global object</a> that is a <code><a href=#window>Window</a></code> object and a
<a href=#responsible-document>responsible document</a> that is <a href=#fully-active>fully active</a>, or</li>

<li><p>a <a href=#global-object>global object</a> that is a <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object whose
<code title=dom-WorkerGlobalScope-closing><a href=#dom-workerglobalscope-closing>closing</a></code> flag is false and whose
<a href=#worker>worker</a> is a <a href=#suspendable-worker>suspendable worker</a>.</li>

</ul></li>

<li><p>Their <a href=#broadcastchannel-settings-object><code>BroadcastChannel</code> settings object</a> specifies an
<a href=#origin>origin</a> that is the <a href=#same-origin>same origin</a> as the <a href=#origin>origin</a> specified
<code><a href=#broadcastchannel>BroadcastChannel</a></code> object.</li>

</ol><p>The <a href=#concept-task title=concept-task>tasks</a> must be associated with the <a href=#responsible-document>responsible
document</a> specified by the <code><a href=#broadcastchannel>BroadcastChannel</a></code> object's
document</a> specified by the target <code><a href=#broadcastchannel>BroadcastChannel</a></code> object's
<a href=#broadcastchannel-settings-object><code>BroadcastChannel</code> settings object</a>, and must use the <a href=#dom-manipulation-task-source>DOM
manipulation task source</a>.</p>

<tbody><tr><td><dfn id=handler-broadcastchannel-onmessage title=handler-BroadcastChannel-onmessage><code>onmessage</code></dfn> <td> <code title=event-message><a href=#event-message>message</a></code>
</table></div>

<p class=note>Authors are strongly encouraged to explicitly close <code><a href=#messageport>MessagePort</a></code>
objects to disentangle them, so that their resources can be recollected. Creating many
<code><a href=#messageport>MessagePort</a></code> objects and discarding them without closing them can lead to high
transient memory usage since garbage collection is not necessarily performed promptly.</p>

<div class=example>

<p>Suppose a page wants to know when the user logs out, even when the user does so from another
23 index
<p>For simple cases, though, where a shared worker would be an unreasonable overhead, authors can
use the simple channel-based broadcast mechanism described in this section.</p>

<pre class=idl>[<a href=#dom-broadcastchannel title=dom-BroadcastChannel>Constructor</a>(DOMString channel)]
<pre class=idl>[<a href=#dom-broadcastchannel title=dom-BroadcastChannel>Constructor</a>(DOMString channel), Exposed=Window,Worker]
interface <dfn id=broadcastchannel>BroadcastChannel</dfn> : <a href=#eventtarget>EventTarget</a> {
readonly attribute DOMString <a href=#dom-broadcastchannel-name title=dom-BroadcastChannel-name>name</a>;
void <a href=#dom-broadcastchannel-postmessage title=dom-BroadcastChannel-postMessage>postMessage</a>(any message);
<p>Let <var title="">destinations</var> be a list of <code><a href=#broadcastchannel>BroadcastChannel</a></code> objects that
match the following criteria:</p>

<ul><li><p>Their <a href=#broadcastchannel-settings-object><code>BroadcastChannel</code> settings object</a> specifies a
<a href=#responsible-document>responsible document</a> that is <a href=#fully-active>fully active</a>.</li>
<ul><li>

<p>Their <a href=#broadcastchannel-settings-object><code>BroadcastChannel</code> settings object</a> specifies either:</p>

<ul><li><p>a <a href=#global-object>global object</a> that is a <code><a href=#window>Window</a></code> object and a
<a href=#responsible-document>responsible document</a> that is <a href=#fully-active>fully active</a>, or</li>

<li><p>a <a href=#global-object>global object</a> that is a <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object whose
<code title=dom-WorkerGlobalScope-closing><a href=#dom-workerglobalscope-closing>closing</a></code> flag is false and whose
<a href=#worker>worker</a> is a <a href=#suspendable-worker>suspendable worker</a>.</li>

</ul></li>

<li><p>Their <a href=#broadcastchannel-settings-object><code>BroadcastChannel</code> settings object</a> specifies an
<a href=#origin>origin</a> that is the <a href=#same-origin>same origin</a> as the <a href=#origin>origin</a> specified
<code><a href=#broadcastchannel>BroadcastChannel</a></code> object.</li>

</ol><p>The <a href=#concept-task title=concept-task>tasks</a> must be associated with the <a href=#responsible-document>responsible
document</a> specified by the <code><a href=#broadcastchannel>BroadcastChannel</a></code> object's
document</a> specified by the target <code><a href=#broadcastchannel>BroadcastChannel</a></code> object's
<a href=#broadcastchannel-settings-object><code>BroadcastChannel</code> settings object</a>, and must use the <a href=#dom-manipulation-task-source>DOM
manipulation task source</a>.</p>

<tbody><tr><td><dfn id=handler-broadcastchannel-onmessage title=handler-BroadcastChannel-onmessage><code>onmessage</code></dfn> <td> <code title=event-message><a href=#event-message>message</a></code>
</table></div>

<p class=note>Authors are strongly encouraged to explicitly close <code><a href=#messageport>MessagePort</a></code>
objects to disentangle them, so that their resources can be recollected. Creating many
<code><a href=#messageport>MessagePort</a></code> objects and discarding them without closing them can lead to high
transient memory usage since garbage collection is not necessarily performed promptly.</p>

<div class=example>

<p>Suppose a page wants to know when the user logs out, even when the user does so from another
27 source
<p>For simple cases, though, where a shared worker would be an unreasonable overhead, authors can
use the simple channel-based broadcast mechanism described in this section.</p>

<pre class="idl">[<span data-x="dom-BroadcastChannel">Constructor</span>(DOMString channel)]
<pre class="idl">[<span data-x="dom-BroadcastChannel">Constructor</span>(DOMString channel), Exposed=Window,Worker]
interface <dfn>BroadcastChannel</dfn> : <span>EventTarget</span> {
readonly attribute DOMString <span data-x="dom-BroadcastChannel-name">name</span>;
void <span data-x="dom-BroadcastChannel-postMessage">postMessage</span>(any message);

<ul>

<li><p>Their <span><code>BroadcastChannel</code> settings object</span> specifies a
<span>responsible document</span> that is <span>fully active</span>.</p></li>
<li>

<p>Their <span><code>BroadcastChannel</code> settings object</span> specifies either:</p>

<ul>

<li><p>a <span>global object</span> that is a <code>Window</code> object and a
<span>responsible document</span> that is <span>fully active</span>, or</p></li>

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

</ul>

</li>

<li><p>Their <span><code>BroadcastChannel</code> settings object</span> specifies an
<span>origin</span> that is the <span>same origin</span> as the <span>origin</span> specified
</ol>

<p>The <span data-x="concept-task">tasks</span> must be associated with the <span>responsible
document</span> specified by the <code>BroadcastChannel</code> object's
document</span> specified by the target <code>BroadcastChannel</code> object's
<span><code>BroadcastChannel</code> settings object</span>, and must use the <span>DOM
manipulation task source</span>.</p>


</div>

<p class="note">Authors are strongly encouraged to explicitly close <code>MessagePort</code>
objects to disentangle them, so that their resources can be recollected. Creating many
<code>MessagePort</code> objects and discarding them without closing them can lead to high
transient memory usage since garbage collection is not necessarily performed promptly.</p>

<div class="example">

<p>Suppose a page wants to know when the user logs out, even when the user does so from another

0 comments on commit 300e7de

Please sign in to comment.
You can’t perform that action at this time.