Skip to content

Commit 4035d0a

Browse files
committed
Disallow non-attribute frozen arrays
Also an an example of how to specify frozen array attributes. Closes #1399.
1 parent f2b124e commit 4035d0a

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

index.bs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6539,6 +6539,44 @@ A <dfn id="dfn-frozen-array-type" export>frozen array type</dfn> is a parameteri
65396539
type whose values are references to objects that hold a fixed length array
65406540
of unmodifiable values. The values in the array are of type |T|.
65416541

6542+
Frozen array types must only be used as the type of [=regular attributes=] or [=static attributes=]
6543+
defined on an [=interface=].
6544+
6545+
<div class="example" id="example-frozen-array">
6546+
The following [=IDL fragment=] defines an [=interface=] with two frozen array attributes, one
6547+
[=read only=] and one not.
6548+
6549+
<pre highlight="webidl">
6550+
[Exposed=Window]
6551+
interface PersonalPreferences {
6552+
readonly attribute FrozenArray&lt;DOMString> favoriteColors;
6553+
attribute FrozenArray&lt;DOMString> favoriteFoods;
6554+
6555+
undefined randomizeFavoriteColors();
6556+
};
6557+
</pre>
6558+
6559+
The behavior of these attributes could be defined like so:
6560+
6561+
<blockquote>
6562+
Each <code>PersonalPreferences</code> has associated <b>favorite colors</b>, a {{FrozenArray}}&lt;{{DOMString}}>, initially equal to the result of [=creating a frozen array=] from « "<code>purple</code>", "<code>aquamarine</code>" ».
6563+
6564+
Each <code>PersonalPreferences</code> has an associated <b>favorite foods</b>, a {{FrozenArray}}&lt;{{DOMString}}>, initially equal to the result of [=creating a frozen array=] from the empty list.
6565+
6566+
The <code>favoriteColors</code> [=getter steps=] are to return [=this=]'s favorite colors.
6567+
6568+
The <code>favoriteFoods</code> [=getter steps=] are to return [=this=]'s favorite foods.
6569+
6570+
The <code>favoriteFoods</code> [=setter steps=] are to set [=this=]'s favorite foods to [=the given value=].
6571+
6572+
The <code>randomizeFavoriteColors()</code> [=method steps=] are:
6573+
6574+
1. Let |newFavoriteColors| be a list of two strings representing colors, chosen randomly.
6575+
6576+
1. Set [=this=]'s favorite colors to the result of [=creating a frozen array=] from |newFavoriteColors|.
6577+
</blockquote>
6578+
</div>
6579+
65426580
Since <a interface lt="FrozenArray">FrozenArray&lt;|T|&gt;</a> values
65436581
are references, they are unlike [=sequence types=],
65446582
which are lists of values that are passed by value.
@@ -11189,11 +11227,10 @@ Note: The HTML Standard defines how a security check is performed. [[!HTML]]
1118911227
there is an entry in |S| that has one of the
1119011228
following types at position |i| of its type list,
1119111229
* a [=sequence type=]
11192-
* a [=frozen array type=]
11193-
* a [=nullable type|nullable=] version of any of the above types
11194-
* an [=annotated type=] whose [=annotated types/inner type=] is one of the above types
11230+
* a [=nullable type|nullable=] [=sequence type=]
11231+
* an [=annotated type=] whose [=annotated types/inner type=] is a [=sequence type=]
1119511232
* a [=union type=], [=nullable type|nullable=] union type, or [=annotated type|annotated=] union type
11196-
that has one of the above types in its [=flattened member types=]
11233+
that has a [=sequence type=] in its [=flattened member types=]
1119711234

1119811235
and after performing the following steps,
1119911236

@@ -11290,13 +11327,10 @@ Note: The HTML Standard defines how a security check is performed. [[!HTML]]
1129011327
1. Let |V| be |args|[|i|].
1129111328
1. Let |T| be the type at index |i| in the
1129211329
type list of the remaining entry in |S|.
11293-
1. If |T| is a [=sequence type=], then
11294-
append to |values| the result of
11330+
1. Assert: |T| is a [=sequence type=].
11331+
1. Append to |values| the result of
1129511332
[=creating a sequence from an iterable|creating a sequence=]
1129611333
of type |T| from |V| and |method|.
11297-
1. Otherwise, |T| is a [=frozen array type=].
11298-
Append to |values| the result of
11299-
[=Creating a frozen array from an iterable|creating a frozen array of type T from V and method=].
1130011334
1. Set |i| to |i| + 1.
1130111335
1. While |i| &lt; |argcount|:
1130211336
1. Let |V| be |args|[|i|].

0 commit comments

Comments
 (0)