Re: [heycam/webidl] Specify open dictionaries. (#180)

jyasskin commented on this pull request.



> @@ -7529,6 +7575,95 @@ iterable |iterable| and an iterator getter
 </div>
 
 
+<h4 id="es-open-dictionary">Open dictionaries — OpenDictionary&lt;[|K|,] |V|&gt;</h4>
+
+IDL {{OpenDictionary}}&lt;|K|, |V|&gt; values are represented by
+ECMAScript <emu-val>Object</emu-val> values.
+
+<p id="es-to-open-dictionary">
+    An ECMAScript value |O| is [=converted to an IDL value|converted=] to an IDL <code>{{OpenDictionary}}<|K|, |V|></code> value as follows:
+</p>
+
+<ol class="algorithm">
+    1.  Let |result| be a new empty instance of <code>{{OpenDictionary}}<|K|, |V|></code>.
+    1.  If [=Type=](|O|) is <emu-val>Undefined</emu-val> or <emu-val>Null</emu-val>,
+        return |result|.

This was in response to @bzbarsky's «Do we want to allow passing null or undefined to mean "empty open dictionary" the way we do for dictionaries?», and he's right that closed dictionaries [treat null and undefined as empty](https://heycam.github.io/webidl/#es-to-dictionary).

> @@ -7529,6 +7575,95 @@ iterable |iterable| and an iterator getter
 </div>
 
 
+<h4 id="es-open-dictionary">Open dictionaries — OpenDictionary&lt;[|K|,] |V|&gt;</h4>
+
+IDL {{OpenDictionary}}&lt;|K|, |V|&gt; values are represented by
+ECMAScript <emu-val>Object</emu-val> values.
+
+<p id="es-to-open-dictionary">
+    An ECMAScript value |O| is [=converted to an IDL value|converted=] to an IDL <code>{{OpenDictionary}}<|K|, |V|></code> value as follows:
+</p>
+
+<ol class="algorithm">
+    1.  Let |result| be a new empty instance of <code>{{OpenDictionary}}<|K|, |V|></code>.
+    1.  If [=Type=](|O|) is <emu-val>Undefined</emu-val> or <emu-val>Null</emu-val>,
+        return |result|.
+    1.  If [=Type=](|O|) is not <emu-val>Object</emu-val>,
+        <a lt="es throw">throw a <emu-val>TypeError</emu-val></a>.

Again, closed dictionaries do throw a `TypeError` for non-Object,Null,Undefined arguments: https://heycam.github.io/webidl/#es-to-dictionary

> +IDL {{OpenDictionary}}&lt;|K|, |V|&gt; values are represented by
+ECMAScript <emu-val>Object</emu-val> values.
+
+<p id="es-to-open-dictionary">
+    An ECMAScript value |O| is [=converted to an IDL value|converted=] to an IDL <code>{{OpenDictionary}}<|K|, |V|></code> value as follows:
+</p>
+
+<ol class="algorithm">
+    1.  Let |result| be a new empty instance of <code>{{OpenDictionary}}<|K|, |V|></code>.
+    1.  If [=Type=](|O|) is <emu-val>Undefined</emu-val> or <emu-val>Null</emu-val>,
+        return |result|.
+    1.  If [=Type=](|O|) is not <emu-val>Object</emu-val>,
+        <a lt="es throw">throw a <emu-val>TypeError</emu-val></a>.
+    1.  Let |keys| be [=?=] [=EnumerableOwnProperties=](|O|, "key").
+    1.  Repeat, for each element |key| of |keys| in [=List=] order:
+        1.  If [=!=] [=HasOwnProperty=](|O|, |key|) is <code>true</code>, then:

I'd like you, @annevk, and @bzbarsky to come to some conclusion about this. So far, @annevk [wondered](https://github.com/heycam/webidl/pull/180#issuecomment-250673458) if we should match [StructuredClone()](https://html.spec.whatwg.org/multipage/infrastructure.html#structuredclone:structuredclone-4), and @bzbarsky [said](https://github.com/heycam/webidl/pull/180#issuecomment-250836913) that MozMap is like StructuredClone but omits the HasOwnProperty() check (so, I think we'd include the key in the map but initialize it from `undefined`). I don't care which we do.

> +    </pre>
+
+    Open dictionary keys and values can be constrained, although keys can only be
+    constrained among the three string types.
+    The following conversions have the described results:
+    <table class="data">
+        <thead><th>Value</th><th>Passed to type</th><th>Result</th></thead>
+        <tr>
+            <td><code>{"😞": 1}</code></td>
+            <td><code>{{OpenDictionary}}&lt;ByteString, double></code></td>
+            <td><emu-val>TypeError</emu-val></td>
+        </tr>
+        <tr>
+            <td><code>{"\uD83D": 1}</code></td>
+            <td><code>{{OpenDictionary}}&lt;USVString, double></code></td>
+            <td>[ "\uFFFD" ⇒ 1 ]</td>

Yeah. I don't want to make WebIDL's users type a non-ascii character in order to iterate over a map, so (key, value) is better for that. I can change to that here too.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/pull/180

Received on Saturday, 1 October 2016 08:01:06 UTC