Skip to content

Commit

Permalink
Allow records to be nullable in all cases and omitted as optional ope…
Browse files Browse the repository at this point in the history
…ration arguments. (#305)

Basically, make record<> more like sequence<> than like dictionary in terms of things that can be converted to it (without the requirement for iterability, of course)
  • Loading branch information
bzbarsky committed Feb 13, 2017
1 parent 8c11c7e commit 9af88fa
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 181 deletions.
45 changes: 17 additions & 28 deletions index.bs
Expand Up @@ -1633,7 +1633,7 @@ identify any one of those definitions or a [=dictionary=].

If the operation argument type, after resolving typedefs,
is a [=nullable type=],
its [=inner type=] must not be a [=record type=] or [=dictionary type=].
its [=inner type=] must not be a [=dictionary type=].

<pre highlight="webidl" class="syntax">
interface interface_identifier {
Expand Down Expand Up @@ -1772,16 +1772,12 @@ corresponding argument omitted.
conversion of <emu-val>undefined</emu-val> to be used (i.e., <emu-val>false</emu-val>).
</p>

If the type of an argument is a [=dictionary type=] or [=record type=]
or a [=union type=] that has a
dictionary or record type as one of its [=flattened member types=],
and that dictionary type and its ancestors have no [=required dictionary member|required members=],
and the argument is either the final argument or is followed only by
[=optional arguments=], then
the argument must be specified as optional.
Such arguments are always considered to have a
[=optional argument/default value=] of an empty dictionary or record, as appropriate,
unless otherwise specified.
If the type of an argument is a [=dictionary type=] or a [=union type=] that has a dictionary as one
of its [=flattened member types=], and that dictionary type and its ancestors have no
[=required dictionary member|required members=], and the argument is either the final argument or is
followed only by [=optional arguments=], then the argument must be specified as optional. Such
arguments are always considered to have a [=optional argument/default value=] of an empty
dictionary, unless otherwise specified.

<div class="note">

Expand Down Expand Up @@ -3296,15 +3292,15 @@ the following algorithm returns <i>true</i>.
and the other type either
[=includes a nullable type=],
is a [=union type=] with [=flattened member types=]
including a [=dictionary type=] or [=record type=], or
is a [=dictionary type=] or [=record type=],
including a [=dictionary type=], or
is a [=dictionary type=],
return <i>false</i>.
<div class="example" id="example-distinguishability-nullable">
None of the following pairs are distinguishable:
<ul>
<li>
<code>{{double}}?</code> and
<code>[=record=]&lt;{{DOMString}}, {{DOMString}}></code>
<code>Dictionary1</code>
</li>
<li>
<code>(Interface1 or {{long}})?</code> and
Expand Down Expand Up @@ -4131,7 +4127,7 @@ identify any one of those definitions or a [=dictionary=].

If the type of the [=dictionary member=], after resolving typedefs,
is a [=nullable type=],
its [=inner type=] must not be a [=record type=] or [=dictionary type=].
its [=inner type=] must not be a [=dictionary type=].

<pre highlight="webidl" class="syntax">
dictionary identifier {
Expand Down Expand Up @@ -5720,9 +5716,9 @@ The inner type must not be:
* a [=Promise type=],
* another nullable type, or
* a [=union type=] that itself has [=includes a nullable type=]
or has a dictionary or record type as one of its [=flattened member types=].
or has a dictionary type as one of its [=flattened member types=].

Note: Although dictionary and record types can in general be nullable,
Note: Although dictionary types can in general be nullable,
they cannot when used as the type of an operation argument or a dictionary member.

Nullable type constant values in IDL are represented in the same way that
Expand Down Expand Up @@ -5922,8 +5918,7 @@ be used as a [=member types|union member type=].
The [=number of nullable member types=]
of a [=union type=] must
be 0 or 1, and if it is 1 then the union type must also not have
a [=dictionary type=] or [=record type=] in its
[=flattened member types=].
a [=dictionary type=] in its [=flattened member types=].

A type <dfn id="dfn-includes-a-nullable-type" export>includes a nullable type</dfn> if:

Expand Down Expand Up @@ -7410,11 +7405,9 @@ ECMAScript <emu-val>Object</emu-val> values.
An ECMAScript value |O| is [=converted to an IDL value|converted=]
to an IDL <code>[=record=]&lt;|K|, |V|></code> value as follows:

1. Let |result| be a new empty instance of <code>[=record=]&lt;|K|, |V|></code>.
1. If [=Type=](|O|) is Undefined or Null,
return |result|.
1. If [=Type=](|O|) is not Object,
[=ECMAScript/throw=] a <emu-val>TypeError</emu-val>.
1. Let |result| be a new empty instance of <code>[=record=]&lt;|K|, |V|></code>.
1. Let |keys| be [=?=] |O|.\[[OwnPropertyKeys]]().
1. Repeat, for each element |key| of |keys| in [=List=] order:
1. Let |desc| be [=?=] |O|.\[[GetOwnProperty]](|key|).
Expand Down Expand Up @@ -7584,8 +7577,6 @@ that correspond to the union’s [=member types=].
1. If |V| is <emu-val>null</emu-val> or <emu-val>undefined</emu-val>, then:
1. If |types| includes a [=dictionary type=], then return the
result of [=converted to an IDL value|converting=] |V| to that dictionary type.
1. If |types| includes a [=record type=], then return the
result of [=converted to an IDL value|converting=] |V| to that record type.
1. If |V| is a [=platform object=], then:
1. If |types| includes an [=interface type=] that |V|
implements, then return the IDL value that is a reference to the object |V|.
Expand Down Expand Up @@ -9723,10 +9714,8 @@ Note: The HTML Standard defines how a security check is performed. [[!HTML]]
and there is an entry in |S| that has one of the following types at position |i| of its type list,
* a [=nullable type=]
* a [=dictionary type=]
* a [=record type=]
* a [=union type=] that
[=includes a nullable type=] or that
has a [=dictionary type=] or a [=record type=] in its [=flattened member types|flattened members=]
* a [=union type=] that [=includes a nullable type=] or that has a [=dictionary type=] in
its [=flattened member types|flattened members=]

then remove from |S| all other entries.

Expand Down

0 comments on commit 9af88fa

Please sign in to comment.