Skip to content

Commit b23a1f4

Browse files
Add binary key definition. Resolves #21
1 parent 1e40729 commit b23a1f4

File tree

1 file changed

+105
-41
lines changed

1 file changed

+105
-41
lines changed

index.html

Lines changed: 105 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,10 @@ <h3>Dependencies</h3>
377377
</dd>
378378
<dt>WebIDL</dt>
379379
<dd>
380-
The terms and types
380+
The terms, types, and algorithms
381381
<dfn>throw</dfn>,
382+
<dfn>getting a copy of the bytes held by a buffer source</dfn>,
383+
<dfn>octet</dfn>,
382384
<dfn>unrestricted double</dfn>,
383385
<dfn>DOMString</dfn>,
384386
<dfn>sequence&lt;DOMString&gt;</dfn>,
@@ -601,14 +603,17 @@ <h4>Keys</h4>
601603
<i>number</i>,
602604
<i>date</i>,
603605
<i>string</i>,
606+
<i>binary</i>,
604607
or
605608
<i>array</i>.
606609
</p>
610+
<aside class="note">Support for <i>binary</i> keys is new in this edition.</aside>
607611
<p>
608612
A <a>key</a> also has an associated <dfn title="key value">value</dfn>, which will
609613
be either:
610614
an <a>unrestricted double</a> if type is <i>number</i> or <i>date</i>,
611615
a <a>DOMString</a> if type is <i>string</i>,
616+
a list of <a title="octet">octets</a> if type is <i>binary</i>,
612617
or a list of other <a title="key">keys</a> if type is <i>array</i>.
613618
</p>
614619
<p>
@@ -620,8 +625,9 @@ <h4>Keys</h4>
620625
<p>The following ECMAScript types are valid keys:</p>
621626
<ul>
622627
<li><code>Number</code> primitive values, except NaN. This includes Infinity and -Infinity.</li>
623-
<li><code>Date</code> objects, except where the [<span>[</span>PrimitiveValue]] internal property is NaN</li>
628+
<li><code>Date</code> objects, except where the [<span>[</span>PrimitiveValue]] internal slot is NaN</li>
624629
<li><code>String</code> primitive values.</li>
630+
<li><code>ArrayBuffer</code> objects (or views on buffers such as <code>Uint8Array</code>).</li>
625631
<li><code>Array</code> objects, where every item is defined, is itself a valid key, and does not directly or indirectly contain itself.
626632
This includes empty arrays. Arrays may contain other arrays.</li>
627633
</ul>
@@ -642,9 +648,16 @@ <h4>Keys</h4>
642648
<li>Let <var>tb</var> be the <a title="key type">type</a> of <var>b</var>.</li>
643649

644650
<li>If <var>ta</var> is <i>array</i> and <var>tb</var> is
645-
<i>string</i>, <i>date</i> or <i>number</i>,
651+
<i>binary</i>, <i>string</i>, <i>date</i> or <i>number</i>,
646652
return 1.</li>
647653
<li>If <var>tb</var> is <i>array</i> and <var>ta</var> is
654+
<i>binary</i>, <i>string</i>, <i>date</i> or <i>number</i>,
655+
return -1.</li>
656+
657+
<li>If <var>ta</var> is <i>binary</i> and <var>tb</var> is
658+
<i>string</i>, <i>date</i> or <i>number</i>,
659+
return 1.</li>
660+
<li>If <var>tb</var> is <i>binary</i> and <var>ta</var> is
648661
<i>string</i>, <i>date</i> or <i>number</i>,
649662
return -1.</li>
650663

@@ -701,6 +714,26 @@ <h4>Keys</h4>
701714
</ol>
702715
</dd>
703716

717+
<dt><i>binary</i></dt>
718+
<dd>
719+
<ol>
720+
<li>Let <var>length</var> be the lesser of <var>va</var>'s length and <var>vb</var>'s length.</li>
721+
<li>Let <var>i</var> be 0.</li>
722+
<li>While <var>i</var> is less than <var>length</var>:
723+
<ol>
724+
<li>Let <var>u</var> be the <a>octet</a> in <var>va</var> at index <var>i</var></li>
725+
<li>Let <var>v</var> be the <a>octet</a> in <var>vb</var> at index <var>i</var></li>
726+
<li>If <var>u</var> is greater than <var>v</var> then return 1</li>
727+
<li>If <var>u</var> is less than <var>v</var> then return -1</li>
728+
<li>Increase <var>i</var> by 1</li>
729+
</ol>
730+
</li>
731+
<li>If <var>va</var>'s length is greater than <var>vb</var>'s length, then return 1</li>
732+
<li>If <var>va</var>'s length is less than <var>vb</var>'s length, then return -1</li>
733+
<li>Return 0</li>
734+
</ol>
735+
</dd>
736+
704737
<dt><i>array</i></dt>
705738
<dd>
706739
<ol>
@@ -737,12 +770,20 @@ <h4>Keys</h4>
737770
of running the steps to <a>compare two keys</a> with <var>a</var> and <var>b</var> is 0.
738771
</p>
739772

740-
<p class="note">
773+
<aside class="note">
741774
As a result of the above rules, negative infinity is the lowest possible value for a <a>key</a>.
742-
Numbers are less than dates. Dates are less than strings. Strings are less than arrays.
775+
<i>Number</i> keys are less than <i>date</i> keys.
776+
<i>Date</i> keys are less than <i>string</i> keys.
777+
<i>String</i> keys are less than <i>binary</i> keys.
778+
<i>Binary</i> keys are less than <i>array</i> keys.
743779
There is no highest possible <a>key</a> value.
744780
This is because an array of any candidate highest <a>key</a> followed by another <a>key</a> is even higher.
745-
</p>
781+
</aside>
782+
783+
<aside class="note">
784+
Members of <i>binary</i> keys are compared as unsigned octet values (in the range [0, 255])
785+
rather than signed bytes (in the range [-128, 127]).
786+
</aside>
746787

747788
</section> <!-- key-construct -->
748789

@@ -1424,7 +1465,7 @@ <h4>Key Generators</h4>
14241465
<p class="note">
14251466
Only specified keys of <a title="key type">type</a> <i>number</i>
14261467
may affect the <a>current number</a> of the key generator. Keys of <a title="key type">type</a>
1427-
<i>date</i>, <i>array</i> (regardless of the other keys they contain), or
1468+
<i>date</i>, <i>array</i> (regardless of the other keys they contain), <i>binary</i>, or
14281469
<i>string</i> (regardless of whether they could be parsed as numbers) have
14291470
no effect on the <a>current number</a> of the key generator.
14301471
Keys of <a title="key type">type</a> <i>number</i> with <a title="key value">value</a>
@@ -5094,6 +5135,17 @@ <h4>Steps to convert a key to a value</h4>
50945135
</ol>
50955136
</dd>
50965137

5138+
<dt><i>binary</i></dt>
5139+
<dd>
5140+
<ol>
5141+
<li>Let <var>len</var> be the length of <var>value</var>.</li>
5142+
<li>Let <var>buffer</var> be the result of executing the ECMAScript ArrayBuffer constructor with <var>len</var>.</li>
5143+
<li>Assert: <var>buffer</var> is not an abrupt completion.</li>
5144+
<li>Set the entries in <var>buffer</var>'s [<span>[</span>ArrayBufferData]] internal slot to the entries in <var>value</var>.</li>
5145+
<li>Return <var>buffer</var></li>
5146+
</ol>
5147+
</dd>
5148+
50975149
<dt><i>array</i></dt>
50985150
<dd>
50995151
<ol>
@@ -5129,10 +5181,11 @@ <h4>Steps to convert a value to a key</h4>
51295181
<ol>
51305182
<li>If <var>seen</var> was not given, let <var>seen</var> be a new empty set</li>
51315183
<li>If <var>input</var> is in <var>seen</var> return invalid</li>
5132-
<li>Switch on Type(<var>input</var>):
5184+
<li>Jump to the appropriate step below:
51335185
<dl class="switch">
51345186

5135-
<dt>Number</dt>
5187+
<!-- Number -->
5188+
<dt>If Type(<var>input</var>) is Number</dt>
51365189
<dd>
51375190
<ol>
51385191
<li>If <var>input</var> is <code>NaN</code> then return invalid.</li>
@@ -5141,53 +5194,62 @@ <h4>Steps to convert a value to a key</h4>
51415194
</ol>
51425195
</dd>
51435196

5144-
<dt>String</dt>
5197+
<!-- Date -->
5198+
<dt>If <var>input</var> has an [<span>[</span>DateValue]] internal slot</dt>
51455199
<dd>
51465200
<ol>
5147-
<li>Return <a title="key type">type</a> <i>string</i> and <a title="key value">value</a> <var>input</var>.</li>
5201+
<li>Let <var>ms</var> be the value of <var>input</var>'s [<span>[</span>DateValue]] internal slot.</li>
5202+
<li>If <var>ms</var> is <code>NaN</code> then return invalid.</li>
5203+
<li>Otherwise, return <a title="key type">type</a> <i>date</i> and <a title="key value">value</a> <var>ms</var>.</li>
51485204
</ol>
51495205
</dd>
51505206

5151-
<dt>Object</dt>
5207+
<!-- String -->
5208+
<dt>If Type(<var>input</var>) is String</dt>
51525209
<dd>
5210+
<ol>
5211+
<li>Return <a title="key type">type</a> <i>string</i> and <a title="key value">value</a> <var>input</var>.</li>
5212+
</ol>
5213+
</dd>
51535214

5215+
<!-- Binary -->
5216+
<dt>If <var>input</var> has an [<span>[</span>ArrayBufferData]] internal slot
5217+
or an [<span>[</span>ViewedArrayBuffer]] internal slot</dt>
5218+
<dd>
51545219
<ol>
5155-
<!-- Date -->
5156-
<li>If <var>input</var> has an internal [<span>[</span>DateValue]] slot, then:
5157-
<ol>
5158-
<li>Let <var>ms</var> be the value of <var>input</var>'s [<span>[</span>DateValue]] internal slot.</li>
5159-
<li>If <var>ms</var> is <code>NaN</code> then return invalid.</li>
5160-
<li>Otherwise, return <a title="key type">type</a> <i>date</i> and <a title="key value">value</a> <var>ms</var>.</li>
5161-
</ol>
5220+
<li>
5221+
Let <var>octets</var> be the result of running the steps for
5222+
<a>getting a copy of the bytes held by a buffer source</a> with <var>value</var>.
51625223
</li>
5224+
<li>Return <a title="key type">type</a> <i>binary</i> and <a title="key value">value</a> <var>octets</var>.</li>
5225+
</ol>
5226+
</dd>
51635227

5164-
<!-- Array -->
5165-
<li>If IsArray(<var>input</var>), then:
5228+
<!-- Array -->
5229+
<dt>If IsArray(<var>input</var>)</dt>
5230+
<dd>
5231+
<ol>
5232+
<li>Let <var>len</var> be the ToLength(Get(<var>input</var>, "<code>length</code>"))</li>
5233+
<li>Assert: <var>len</var> will never an abrupt completion.</li>
5234+
<li>Add <var>input</var> to <var>seen</var></li>
5235+
<li>Let <var>keys</var> be a new empty list</li>
5236+
<li>Let <var>index</var> be 0</li>
5237+
<li>While <var>index</var> is less than <var>len</var>:
51665238
<ol>
5167-
<li>Let <var>len</var> be the ToLength(Get(<var>input</var>, "<code>length</code>"))</li>
5168-
<li>Assert: <var>len</var> will never an abrupt completion.</li>
5169-
<li>Add <var>input</var> to <var>seen</var></li>
5170-
<li>Let <var>keys</var> be a new empty list</li>
5171-
<li>Let <var>index</var> be 0</li>
5172-
<li>While <var>index</var> is less than <var>len</var>:
5173-
<ol>
5174-
<li>Let <var>entry</var> be <var>input</var>.[<span>[</span>Get]](<var>index</var>, <var>input</var>)</li>
5175-
<li>ReturnIfAbrupt(<var>entry</var>)</li>
5176-
<li>Let <var>key</var> be the result of running the steps to <a>convert a value to a key</a>
5177-
with arguments <var>entry</var> and <var>seen</var></li>
5178-
<li>ReturnIfAbrupt(<var>key</var>)</li>
5179-
<li>If <var>key</var> is invalid or an exception, then abort these steps and return <var>key</var>.</li>
5180-
<li>Append <var>key</var> to <var>keys</var></li>
5181-
<li>Increase <var>index</var> by 1</li>
5182-
</ol>
5183-
</li>
5184-
<li>Return a new <a>array key</a> with <a title="key value">value</a> <var>keys</var>.</li>
5239+
<li>Let <var>entry</var> be <var>input</var>.[<span>[</span>Get]](<var>index</var>, <var>input</var>)</li>
5240+
<li>ReturnIfAbrupt(<var>entry</var>)</li>
5241+
<li>Let <var>key</var> be the result of running the steps to <a>convert a value to a key</a>
5242+
with arguments <var>entry</var> and <var>seen</var></li>
5243+
<li>ReturnIfAbrupt(<var>key</var>)</li>
5244+
<li>If <var>key</var> is invalid or an exception, then abort these steps and return <var>key</var>.</li>
5245+
<li>Append <var>key</var> to <var>keys</var></li>
5246+
<li>Increase <var>index</var> by 1</li>
51855247
</ol>
51865248
</li>
5187-
5188-
<!-- TODO: BufferSource -->
5249+
<li>Return a new <a>array key</a> with <a title="key value">value</a> <var>keys</var>.</li>
51895250
</ol>
51905251
</dd>
5252+
51915253
<dt>Otherwise</dt>
51925254
<dd>Return invalid</dd>
51935255
</dl>
@@ -5495,6 +5557,8 @@ <h2>Revision History</h2>
54955557
(<a href="https://github.com/w3c/IndexedDB/issues/16">bug #16</a>)</li>
54965558
<li>Added <code>objectStoreNames</code> attribute to <a>IDBTransaction</a>.
54975559
(<a href="https://github.com/w3c/IndexedDB/issues/18">bug #18</a>)</li>
5560+
<li>Added <i>binary</i> <a title="key">keys</a>, including comparisons and ECMAScript bindings.
5561+
(<a href="https://github.com/w3c/IndexedDB/issues/21">bug #21</a>)</li>
54985562
</ul>
54995563
</section>
55005564
<section class="section appendix" id="acknowledgements">

0 commit comments

Comments
 (0)