Skip to content

Commit

Permalink
Merge pull request #187 from jyasskin/reject-empty-filters
Browse files Browse the repository at this point in the history
Block an empty list of filters.
  • Loading branch information
jyasskin committed Nov 9, 2015
2 parents e8dba07 + 3722594 commit b62a8e5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
27 changes: 24 additions & 3 deletions index.bs
Expand Up @@ -720,22 +720,38 @@ spec: html
</td>
<td>D3, D5</td>
</tr>
</table>
</div>

<div class="example" id="example-disallowed-filters">
<p>
Filters that either accept or reject all possible devices cause {{TypeError}}s.
</p>

<table>
<tr><th><var>filters</var></th><th>Notes</th></tr>
<tr>
<td>
<pre highlight="js">
[]
</pre>
</td>
<td>An empty list of filters doesn't accept any devices.</td>
</tr>
<tr>
<td>
<pre highlight="js">
[{}]
</pre>
</td>
<td><i>TypeError</i></td>
<td>A filter must restrict the devices in some way.</td>
<td>An empty filter accepts all devices, and so isn't allowed either.</td>
</tr>
<tr>
<td>
<pre highlight="js">
[{namePrefix: ""}]
</pre>
</td>
<td><i>TypeError</i></td>
<td>`namePrefix`, if present, must be non-empty to filter devices.</td>
</tr>
</table>
Expand Down Expand Up @@ -797,6 +813,11 @@ spec: html
In order to convert the arguments from service names and aliases to just <a>UUID</a>s,
do the following substeps:
<ol>
<li>
If <code><var>options</var>.filters.length === 0</code>,
<a>reject</a> <var>promise</var> with a {{TypeError}}
and abort these steps.
</li>
<li>
Let <var>uuidFilters</var> be a new {{Array}} and
<var>requiredServiceUUIDs</var> be a new {{Set}}.
Expand Down
21 changes: 17 additions & 4 deletions index.html
Expand Up @@ -1072,7 +1072,7 @@
<div class="head">
<div data-fill-with="logo"></div>
<h1 class="p-name no-ref" id="title">Web Bluetooth</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Draft Community Group Report, <time class="dt-updated" datetime="2015-10-30">30 October 2015</time></span></h2>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Draft Community Group Report, <time class="dt-updated" datetime="2015-11-09">9 November 2015</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
Expand Down Expand Up @@ -1610,15 +1610,27 @@ <h2 class="heading settled" data-level="3" id="device-discovery"><span class="se
<span class="nx">namePrefix</span><span class="o">:</span> <span class="s2">"Device"</span><span class="p">},</span>
<span class="p">{</span><span class="nx">name</span><span class="o">:</span> <span class="s2">"Unique Name"</span><span class="p">}]</span></pre>
<td>D3, D5
</table>
</div>
<div class="example" id="example-disallowed-filters">
<a class="self-link" href="#example-disallowed-filters"></a>
<p> Filters that either accept or reject all possible devices cause <code class="idl"><a data-link-type="idl" href="http://ecma-international.org/ecma-262/6.0/#sec-native-error-types-used-in-this-standard-typeerror">TypeError</a></code>s. </p>
<table>
<tbody>
<tr>
<th><var>filters</var>
<th>Notes
<tr>
<td>
<pre class="highlight"><span class="p">[]</span></pre>
<td>An empty list of filters doesn’t accept any devices.
<tr>
<td>
<pre class="highlight"><span class="p">[{}]</span></pre>
<td><i>TypeError</i>
<td>A filter must restrict the devices in some way.
<td>An empty filter accepts all devices, and so isn’t allowed either.
<tr>
<td>
<pre class="highlight"><span class="p">[{</span><span class="nx">namePrefix</span><span class="o">:</span> <span class="s2">""</span><span class="p">}]</span></pre>
<td><i>TypeError</i>
<td><code>namePrefix</code>, if present, must be non-empty to filter devices.
</table>
</div>
Expand Down Expand Up @@ -1655,6 +1667,7 @@ <h2 class="heading settled" data-level="3" id="device-discovery"><span class="se
In order to convert the arguments from service names and aliases to just <a data-link-type="dfn" href="#uuid">UUID</a>s,
do the following substeps:
<ol>
<li> If <code><var>options</var>.filters.length === 0</code>, <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide#reject-promise">reject</a> <var>promise</var> with a <code class="idl"><a data-link-type="idl" href="http://ecma-international.org/ecma-262/6.0/#sec-native-error-types-used-in-this-standard-typeerror">TypeError</a></code> and abort these steps.
<li> Let <var>uuidFilters</var> be a new <code class="idl"><a data-link-type="idl" href="http://ecma-international.org/ecma-262/6.0/#sec-array-objects">Array</a></code> and <var>requiredServiceUUIDs</var> be a new <code class="idl"><a data-link-type="idl" href="http://ecma-international.org/ecma-262/6.0/#sec-set-objects">Set</a></code>.
<li>
For each <var>filter</var> in <code><var>options</var>.filters</code>,
Expand Down

0 comments on commit b62a8e5

Please sign in to comment.