@@ -1616,8 +1616,8 @@ or one of the three special floating point constant values
1616
1616
(<emu-t>-Infinity</emu-t>, <emu-t>Infinity</emu-t> and <emu-t>NaN</emu-t>).
1617
1617
1618
1618
Note: These values – in addition to strings and the empty sequence – can also be used to specify the
1619
- [=dictionary member/default value|default value of a dictionary member=] or [=optional argument/default value|of an optional argument=]. Note that strings and the
1620
- empty sequence <code >[]</code > cannot be used as the value of a
1619
+ [=dictionary member/default value|default value of a dictionary member=] or [=optional argument/default value|of an optional argument=]. Note that strings, the
1620
+ empty sequence <emu-t >[]</emu-t>, and the default dictionary <emu-t>{}</emu-t > cannot be used as the value of a
1621
1621
[=constant=].
1622
1622
1623
1623
The value of the boolean literal tokens <emu-t>true</emu-t> and
@@ -2242,24 +2242,23 @@ corresponding argument omitted.
2242
2242
conversion of <emu-val>undefined</emu-val> to be used (i.e., <emu-val>false</emu-val>).
2243
2243
</p>
2244
2244
2245
- If the type of an argument is a [=dictionary type=] or a [=union type=] that has a dictionary as one
2245
+ If the type of an argument is a [=dictionary type=] or a [=union type=] that has
2246
+ a [=dictionary type=] as one
2246
2247
of its [=flattened member types=], and that dictionary type and its ancestors have no
2247
2248
[=required dictionary member|required members=], and the argument is either the final argument or is
2248
- followed only by [=optional arguments=], then the argument must be specified as optional. Such
2249
- arguments are always considered to have a [=optional argument/default value=] of an empty
2250
- dictionary, unless otherwise specified.
2249
+ followed only by [=optional arguments=], then the argument must be specified as
2250
+ optional and have a default value provided.
2251
2251
2252
2252
<div class="note">
2253
2253
2254
2254
This is to encourage API designs that do not require authors to pass an
2255
2255
empty dictionary value when they wish only to use the dictionary’s
2256
2256
default values.
2257
2257
2258
- Dictionary types cannot have a default value specified explicitly, so the
2259
- “unless otherwise specified” clause above can only be invoked for
2260
- a [=union type=] that has a
2261
- dictionary type as one of its [=flattened member types=].
2262
-
2258
+ Usually the default value provided will be <emu-t>{}</emu-t>, but in the
2259
+ case of a [=union type=] that has a dictionary type as one of its
2260
+ [=flattened member types=] a default value could be provided that
2261
+ initializes some other member of the union.
2263
2262
</div>
2264
2263
2265
2264
When a boolean literal token (<emu-t>true</emu-t> or <emu-t>false</emu-t>),
@@ -2303,13 +2302,20 @@ is an [=enumeration=], then its
2303
2302
be one of the [=enumeration values|enumeration’s values=].
2304
2303
2305
2304
Optional argument default values can also be specified using the
2306
- two token value <code >[]</code >, which represents an empty sequence
2305
+ two token value <emu-t >[]</emu-t >, which represents an empty sequence
2307
2306
value. The type of this value is the same as the type of the optional
2308
2307
argument it is being used as the default value of. That type
2309
2308
must be a [=sequence type=], a [=nullable type=] whose [=nullable types/inner type=] is a
2310
2309
[=sequence type=] or a [=union type=] or [=nullable type|nullable=] union type
2311
2310
that has a [=sequence type=] in its [=flattened member types=].
2312
2311
2312
+ Optional argument default values can also be specified using the two token value
2313
+ <emu-t>{}</emu-t>, which represents a default-initialized (as if from ES
2314
+ <emu-t>null</emu-t> or an object with no properties) dictionary value. The type
2315
+ of this value is the same as the type of the optional argument it is being used
2316
+ as the default value of. That type must be a [=dictionary type=], or a [=union
2317
+ type=] that has a [=dictionary type=] in its [=flattened member types=].
2318
+
2313
2319
<div class="example">
2314
2320
2315
2321
The following [=IDL fragment=]
@@ -2337,6 +2343,31 @@ that has a [=sequence type=] in its [=flattened member types=].
2337
2343
</pre>
2338
2344
</div>
2339
2345
2346
+ <div class="example">
2347
+
2348
+ The following [=IDL fragment=]
2349
+ defines an [=interface=]
2350
+ with an operation that takes a dictionary argument:
2351
+
2352
+ <!-- Should be `highlight="webidl"`, but that gives bikeshed conniptions
2353
+ because it does not know about the syntax we are introducing -->
2354
+ <pre>
2355
+ dictionary LookupOptions {
2356
+ boolean caseSensitive = false;
2357
+ };
2358
+
2359
+ [Exposed=Window]
2360
+ interface AddressBook {
2361
+ boolean hasAddressForName(USVString name, optional LookupOptions options = {});
2362
+ };
2363
+ </pre>
2364
+
2365
+ If <code>hasAddressForName</code> is called with only one argument, the
2366
+ second argument will be a default-initialized <code>LookupOptions</code>
2367
+ dictionary, which will cause <code>caseSensitive</code> to be set to
2368
+ <emu-t>false</emu-t>.
2369
+ </div>
2370
+
2340
2371
The following extended attributes are applicable to operations:
2341
2372
[{{Default}}],
2342
2373
[{{Exposed}}],
@@ -2349,6 +2380,7 @@ The following extended attributes are applicable to operations:
2349
2380
ConstValue
2350
2381
string
2351
2382
"[" "]"
2383
+ "{" "}"
2352
2384
"null"
2353
2385
</pre>
2354
2386
@@ -4524,8 +4556,9 @@ an <emu-t class="regex"><a href="#prod-integer">integer</a></emu-t> token, a
4524
4556
<emu-t class="regex"><a href="#prod-decimal">decimal</a></emu-t> token,
4525
4557
one of the three special floating point literal values (<emu-t>Infinity</emu-t>,
4526
4558
<emu-t>-Infinity</emu-t> or <emu-t>NaN</emu-t>),
4527
- a <emu-t class="regex"><a href="#prod-string">string</a></emu-t> token or
4528
- the two token sequence <emu-t>[]</emu-t> used as the
4559
+ a <emu-t class="regex"><a href="#prod-string">string</a></emu-t> token, the two
4560
+ token sequence <emu-t>[]</emu-t>, or the two token sequence <emu-t>{}</emu-t> is
4561
+ used as the
4529
4562
[=dictionary member/default value=],
4530
4563
it is interpreted in the same way as for an [=operation=]’s
4531
4564
[=optional argument/default value|optional argument default value=].
0 commit comments