Skip to content

Commit 691b8d2

Browse files
committed
Editorial: Better explanation of the TreatNonObjectAsNull extended attribute.
When the name and behaviour of the extended attribute were changed back in 4043b05, various prose around the specification became somewhat unclear. This tries to make everything agree on what happens.
1 parent 5a3d5b7 commit 691b8d2

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

index.bs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6241,6 +6241,9 @@ An [=identifier=] that identifies
62416241
a [=callback function=] is used to refer to
62426242
a type whose values are references to objects that are functions with the given signature.
62436243

6244+
Note: If the [{{TreatNonObjectAsNull}}] [=extended attribute=] is specified on the [=definition=] of
6245+
the [=callback function=], the values can be references to objects that are not functions.
6246+
62446247
An IDL value of the callback function type is represented by a tuple of an object
62456248
reference and a [=callback context=].
62466249

@@ -10485,16 +10488,13 @@ that does specify [{{SecureContext}}].
1048510488

1048610489
</div>
1048710490

10488-
If the [{{TreatNonObjectAsNull}}]
10489-
[=extended attribute=]
10490-
appears on a [=callback function=],
10491-
then it indicates that any value assigned to an [=attribute=]
10492-
whose type is a [=nullable type|nullable=]
10493-
[=callback function=]
10494-
that is not an object will be converted to
10495-
the <emu-val>null</emu-val> value.
10496-
10497-
See [[#es-nullable-type]]
10491+
If the [{{TreatNonObjectAsNull}}] [=extended attribute=] appears on a [=callback function=], then
10492+
it indicates that any value assigned to an [=attribute=] whose type is a [=nullable type|nullable=]
10493+
[=callback function=] will be converted more loosely: if the value is not an object, it will be
10494+
converted to null, and if the value is not [=ECMAScript/callable=], it will be converted to a
10495+
[=callback function=] value that does nothing when called.
10496+
10497+
See [[#es-nullable-type]], [[#es-callback-function]] and [[#es-invoking-callback-functions]]
1049810498
for the specific requirements that the use of
1049910499
[{{TreatNonObjectAsNull}}] entails.
1050010500

@@ -10519,7 +10519,7 @@ for the specific requirements that the use of
1051910519
</pre>
1052010520

1052110521
In an ECMAScript implementation, assigning a value that is not
10522-
an object (such as a Number value)
10522+
an object (such as a Number value), or that is not [=ECMAScript/callable=]
1052310523
to handler1 will have different behavior from that when assigning
1052410524
to handler2:
1052510525

@@ -10534,11 +10534,19 @@ for the specific requirements that the use of
1053410534
} catch (e) {
1053510535
}
1053610536

10537+
try {
10538+
manager.handler1 = {}; // Throws a TypeError.
10539+
} catch (e) {
10540+
}
10541+
1053710542
manager.handler2 = function() { };
1053810543
manager.handler2; // Evaluates to the function.
1053910544

1054010545
manager.handler2 = 123;
1054110546
manager.handler2; // Evaluates to null.
10547+
10548+
manager.handler2 = {};
10549+
manager.handler2; // Evaluates to the object.
1054210550
</pre>
1054310551
</div>
1054410552

@@ -13744,11 +13752,9 @@ described in the previous section).
1374413752
1. If |thisArg| was not given, let |thisArg| be <emu-val>undefined</emu-val>.
1374513753
1. Let |F| be the ECMAScript object corresponding to |callable|.
1374613754
1. If [=!=] <a abstract-op>IsCallable</a>(|F|) is <emu-val>false</emu-val>:
13747-
1. If the callback function's return type is {{void}}, return.
13748-
13749-
Note: This is only possible when the callback function came from an attribute
13755+
1. Note: This is only possible when the [=callback function=] came from an attribute
1375013756
marked with [{{TreatNonObjectAsNull}}].
13751-
13757+
1. If the callback function's return type is {{void}}, return.
1375213758
1. Return the result of [=converted to an IDL value|converting=]
1375313759
<emu-val>undefined</emu-val> to the callback function's return type.
1375413760
1. Let |realm| be |F|'s [=associated Realm=].

0 commit comments

Comments
 (0)