Skip to content

Commit

Permalink
Wait for an active worker on .register.
Browse files Browse the repository at this point in the history
Events won't get delivered unless there is an active worker, so don't pretend
sync registration succeeds if there won't be an active worker. This fixes #101
  • Loading branch information
mkruisselbrink committed Oct 12, 2015
1 parent 33b155c commit 8c14885
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
25 changes: 19 additions & 6 deletions spec/index.bs
Expand Up @@ -60,9 +60,11 @@ spec: service-workers; urlPrefix: https://slightlyoff.github.io/ServiceWorker/sp
text: control; url: dfn-control
text: extended lifetime promises; url: dfn-extend-lifetime-promises
text: handle functional event; url: handle-functional-event-algorithm
text: installing worker; url: dfn-installing-worker
text: service worker; url: service-worker-concept
text: service worker registration; url: service-worker-registration-concept
text: termination; url: terminate-service-worker-algorithm
text: waiting worker; url: dfn-waiting-worker
type: interface
text: ExtendableEvent; url: extendable-event-interface
text: ExtendableEventInit; url: extendable-event-init-dictionary
Expand All @@ -73,12 +75,7 @@ spec: WebIDL; urlPrefix: https://heycam.github.io/webidl/#
type: exception
text: AbortError; url: aborterror
text: InvalidAccessError; url: invalidaccesserror
text: InvalidModificationError; url: invalidmodificationerror
text: NetworkError; url: networkerror
text: NotFoundError; url: notfounderror
text: NotSupportedError; url: notsupportederror
text: SecurityError; url: securityerror
text: SyntaxError; url: syntaxerror
text: InvalidStateError; url: invalidstateerror
type: interface
text: DOMString; url: idl-DOMString
text: sequence; url: idl-sequence
Expand Down Expand Up @@ -171,6 +168,22 @@ spec: WebIDL; urlPrefix: https://heycam.github.io/webidl/#
<li>
Let <var>serviceWorkerRegistration</var> be the {{SyncManager}}'s associated <a>service worker registration</a>.
</li>
<li>
If <var>serviceWorkerRegistration</var>'s <a>active worker</a> is null:
<ol>
<li>
If <var>serviceWorkerRegistration</var>'s <a>installing worker</a> is null and <var>serviceWorkerRegistration</var>'s <a>waiting worker</a> is null, <a>reject</a> <var>promise</var> with an {{InvalidStateError}} and abort these steps.
</li>
<li>
Wait for the <a>installing worker</a> or the <a>waiting worker</a> of <var>serviceWorkerRegistration</var> to become its <a>active worker</a>.
</li>
<li>
If <var>serviceWorkerRegistration</var> fails to activate either worker, <a>reject</a> <var>promise</var> with an {{InvalidStateError}} and abort these steps.
</li>
<li>
Once <var>serviceWorkerRegistration</var>'s <a>active worker</a> is not null, proceed with the steps below.
</li>
</ol>
<li>
If the <a>global object</a> specified by the <a>incumbent settings object</a> is a {{WorkerGlobalScope}} instance, and the <var>serviceWorkerRegistration</var>'s <a>active worker</a> is not currently <a lt="control">controlling</a> any <a>clients</a>, <a>reject</a> <var>promise</var> with an {{InvalidAccessError}} and abort these steps.
</li>
Expand Down
11 changes: 11 additions & 0 deletions spec/index.html
Expand Up @@ -177,6 +177,14 @@ <h3 class="heading settled" data-level="5.2" id="sync-manager-interface"><span c
<p>The <code><dfn class="idl-code" data-dfn-for="SyncManager" data-dfn-type="method" data-export="" data-lt="register(options)|register()" id="dom-syncmanager-register" title="register(options)">register(<var>options</var>)<a class="self-link" href="#dom-syncmanager-register"></a></dfn></code> method, when invoked, MUST return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide#a-new-promise">a new promise</a> <var>promise</var> and run the following steps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>:</p>
<ol>
<li> Let <var>serviceWorkerRegistration</var> be the <code class="idl"><a data-link-type="idl" href="#syncmanager">SyncManager</a></code>'s associated <a data-link-type="dfn" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-registration-concept">service worker registration</a>.
<li>
If <var>serviceWorkerRegistration</var>’s <a data-link-type="dfn" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-active-worker">active worker</a> is null:
<ol>
<li> If <var>serviceWorkerRegistration</var>’s <a data-link-type="dfn" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-installing-worker">installing worker</a> is null and <var>serviceWorkerRegistration</var>’s <a data-link-type="dfn" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-waiting-worker">waiting worker</a> is null, <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide#reject-promise">reject</a> <var>promise</var> with an <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#invalidstateerror">InvalidStateError</a></code> and abort these steps.
<li> Wait for the <a data-link-type="dfn" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-installing-worker">installing worker</a> or the <a data-link-type="dfn" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-waiting-worker">waiting worker</a> of <var>serviceWorkerRegistration</var> to become its <a data-link-type="dfn" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-active-worker">active worker</a>.
<li> If <var>serviceWorkerRegistration</var> fails to activate either worker, <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide#reject-promise">reject</a> <var>promise</var> with an <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#invalidstateerror">InvalidStateError</a></code> and abort these steps.
<li> Once <var>serviceWorkerRegistration</var>’s <a data-link-type="dfn" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-active-worker">active worker</a> is not null, proceed with the steps below.
</ol>
<li> If the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#global-object">global object</a> specified by the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#incumbent-settings-object">incumbent settings object</a> is a <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/workers.html#workerglobalscope">WorkerGlobalScope</a></code> instance, and the <var>serviceWorkerRegistration</var>’s <a data-link-type="dfn" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-active-worker">active worker</a> is not currently <a data-link-type="dfn" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-control">controlling</a> any <a data-link-type="dfn" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-service-worker-client">clients</a>, <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide#reject-promise">reject</a> <var>promise</var> with an <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#invalidaccesserror">InvalidAccessError</a></code> and abort these steps.
<li> Let <var>currentRegistration</var> be the <a data-link-type="dfn" href="#sync-registration">registration</a> in <var>serviceWorkerRegistration</var>’s <a data-link-type="dfn" href="#list-of-sync-registrations">list of sync registrations</a> whose <a data-link-type="dfn" href="#tag">tag</a> equals <var>options.tag</var> if it exists, else null.
<li>
Expand Down Expand Up @@ -405,6 +413,7 @@ <h3 class="no-num heading settled" id="index-defined-elsewhere"><span class="con
<ul>
<li><a href="https://heycam.github.io/webidl/#aborterror">AbortError</a>
<li><a href="https://heycam.github.io/webidl/#invalidaccesserror">InvalidAccessError</a>
<li><a href="https://heycam.github.io/webidl/#invalidstateerror">InvalidStateError</a>
<li><a href="https://heycam.github.io/webidl/#idl-sequence">sequence</a>
</ul>
<li>
Expand Down Expand Up @@ -449,9 +458,11 @@ <h3 class="no-num heading settled" id="index-defined-elsewhere"><span class="con
<li><a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-control">control</a>
<li><a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-extend-lifetime-promises">extended lifetime promises</a>
<li><a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#handle-functional-event-algorithm">handle functional event</a>
<li><a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-installing-worker">installing worker</a>
<li><a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-concept">service worker</a>
<li><a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-registration-concept">service worker registration</a>
<li><a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#terminate-service-worker-algorithm">termination</a>
<li><a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#dfn-waiting-worker">waiting worker</a>
</ul>
</ul>
<h2 class="no-num heading settled" id="references"><span class="content">References</span><a class="self-link" href="#references"></a></h2>
Expand Down

0 comments on commit 8c14885

Please sign in to comment.