Skip to content

Commit dba5577

Browse files
committed
Stop using extended attributes for constructors
Fixes #636.
1 parent 68dbd23 commit dba5577

File tree

1 file changed

+116
-110
lines changed

1 file changed

+116
-110
lines changed

index.bs

Lines changed: 116 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,9 @@ in [[#es-extended-attributes]].
543543
attribute DOMString imageURL;
544544
};
545545

546-
[Exposed=Window, Constructor]
546+
[Exposed=Window]
547547
interface GraphicalWindow {
548+
constructor();
548549
readonly attribute unsigned long width;
549550
readonly attribute unsigned long height;
550551

@@ -571,12 +572,13 @@ in [[#es-extended-attributes]].
571572
objects; each ECMAScript object that implements <code class="idl">GraphicalWindow</code>
572573
will have that prototype object in its prototype chain.
573574

574-
The [{{Constructor}}] that appears on <code class="idl">GraphicalWindow</code>
575-
is an [=extended attribute=].
576-
This extended attribute causes a [=constructor=] to exist in ECMAScript implementations,
575+
The [=constructor operation=] that appears on <code class="idl">GraphicalWindow</code>
576+
causes a [=constructor=] to exist in ECMAScript implementations,
577577
so that calling <code>new GraphicalWindow()</code> would return a new object
578578
that implemented the interface.
579579

580+
All [=interfaces=] have the [{{Exposed}}] [=extended attribute=], which ensures the interfaces
581+
are only available in [=Realms=] whose [=Realm/global object=] is a {{Window}} object.
580582
</div>
581583

582584

@@ -992,7 +994,6 @@ The relevant language binding determines how interfaces correspond to constructs
992994
in the language.
993995

994996
The following extended attributes are applicable to interfaces:
995-
[{{Constructor}}],
996997
[{{Exposed}}],
997998
[{{Global}}],
998999
[{{LegacyWindowAlias}}],
@@ -1061,7 +1062,7 @@ The <dfn>qualified name</dfn> of an [=interface=] |interface| is defined as foll
10611062

10621063
<pre class="grammar" id="prod-PartialInterfaceRest">
10631064
PartialInterfaceRest :
1064-
identifier "{" InterfaceMembers "}" ";"
1065+
identifier "{" PartialInterfaceMembers "}" ";"
10651066
</pre>
10661067

10671068
<pre class="grammar" id="prod-InterfaceMembers">
@@ -1072,6 +1073,18 @@ The <dfn>qualified name</dfn> of an [=interface=] |interface| is defined as foll
10721073

10731074
<pre class="grammar" id="prod-InterfaceMember">
10741075
InterfaceMember :
1076+
PartialInterfaceMember
1077+
Constructor
1078+
</pre>
1079+
1080+
<pre class="grammar" id="prod-PartialInterfaceMembers">
1081+
PartialInterfaceMembers :
1082+
ExtendedAttributeList PartialInterfaceMember PartialInterfaceMembers
1083+
ε
1084+
</pre>
1085+
1086+
<pre class="grammar" id="prod-PartialInterfaceMember">
1087+
PartialInterfaceMember :
10751088
Const
10761089
Operation
10771090
Stringifier
@@ -2166,7 +2179,8 @@ language bindings.
21662179
</pre>
21672180
</div>
21682181

2169-
An operation is considered to be <dfn id="dfn-variadic" export>variadic</dfn>
2182+
An operation or [=constructor operation=] is considered to be
2183+
<dfn id="dfn-variadic" export>variadic</dfn>
21702184
if the final argument uses the <emu-t>...</emu-t> token just
21712185
after the argument type. Declaring an operation to be variadic indicates that
21722186
the operation can be invoked with any number of arguments after that final argument.
@@ -2185,8 +2199,7 @@ is the final argument in the operation’s argument list.
21852199

21862200
[=Extended attributes=]
21872201
that [=takes an argument list|take an argument list=]
2188-
([{{Constructor}}] and
2189-
[{{NamedConstructor}}], of those
2202+
([{{NamedConstructor}}], of those
21902203
defined in this specification) and [=callback functions=]
21912204
are also considered to be [=variadic=]
21922205
when the <emu-t>...</emu-t> token is used in their argument lists.
@@ -2592,6 +2605,82 @@ in which case the [=default toJSON operation=] is exposed instead.
25922605
</div>
25932606

25942607

2608+
<h4 id=idl-constructors oldids="Constructor" dfn>Constructor operations</h4>
2609+
2610+
If an [=interface=] has a [=constructor operation=] member (matching
2611+
<emu-nt><a href="#prod-Constructor">Constructor</a></emu-nt>), it indicates that it is possible to
2612+
create objects that [=implement=] the [=interface=] using a [=constructor=].
2613+
2614+
Multiple [=constructor operations=] may appear on a given [=interface=].
2615+
For each [=constructor operation=] on the [=interface=], there will be a way to attempt to
2616+
construct an instance by passing the specified arguments.
2617+
2618+
The prose definition of a [=constructor operation=] must either initialize the value passed as
2619+
<b>[=this=]</b>, or throw an exception.
2620+
2621+
See [[#interface-object]] for details on how a [=constructor operation=] is to be implemented.
2622+
2623+
<div class="example">
2624+
2625+
The following IDL defines two interfaces. The second has [=constructor operations=], while the
2626+
first does not.
2627+
2628+
<pre highlight="webidl">
2629+
[Exposed=Window]
2630+
interface NodeList {
2631+
Node item(unsigned long index);
2632+
readonly attribute unsigned long length;
2633+
};
2634+
2635+
[Exposed=Window]
2636+
interface Circle {
2637+
constructor();
2638+
constructor(double radius);
2639+
attribute double r;
2640+
attribute double cx;
2641+
attribute double cy;
2642+
readonly attribute double circumference;
2643+
};
2644+
</pre>
2645+
2646+
An ECMAScript implementation supporting these interfaces would implement a \[[Construct]]
2647+
internal method on the <code class="idl">Circle</code> interface object which would return a
2648+
new object that [=implements=] the interface.
2649+
It would take either zero or one argument.
2650+
2651+
Issue(heycam/webidl#698): It is unclear whether the <code class="idl">NodeList</code> interface
2652+
object would implement a \[[Construct]] internal method. In any case, trying to use it as a
2653+
constructor will cause a {{TypeError}} to be thrown.
2654+
2655+
<pre highlight="js">
2656+
var x = new Circle(); // The uses the zero-argument constructor to create a
2657+
// reference to a platform object that implements the
2658+
// Circle interface.
2659+
2660+
var y = new Circle(1.25); // This also creates a Circle object, this time using
2661+
// the one-argument constructor.
2662+
2663+
var z = new NodeList(); // This would throw a TypeError, since no
2664+
// constructor is declared.
2665+
</pre>
2666+
</div>
2667+
2668+
2669+
2670+
<pre class="grammar" id="prod-Constructor">
2671+
Constructor :
2672+
"constructor" "(" ArgumentList ")" ";"
2673+
</pre>
2674+
2675+
<div data-fill-with="grammar-ArgumentList"></div>
2676+
<div data-fill-with="grammar-Arguments"></div>
2677+
<div data-fill-with="grammar-Argument"></div>
2678+
<div data-fill-with="grammar-ArgumentRest"></div>
2679+
<div data-fill-with="grammar-ArgumentName"></div>
2680+
<div data-fill-with="grammar-Ellipsis"></div>
2681+
<div data-fill-with="grammar-ArgumentNameKeyword"></div>
2682+
2683+
25952684
<h4 id="idl-special-operations">Special operations</h4>
25962685

25972686
A <dfn id="dfn-special-operation" export>special operation</dfn> is a
@@ -3212,8 +3301,9 @@ of an overloaded operation is used to invoke one of the
32123301
operations on an object that implements the interface, the
32133302
number and types of the arguments passed to the operation
32143303
determine which of the overloaded operations is actually
3215-
invoked. In the ECMAScript language binding, <a href="#Constructor">constructors</a>
3216-
can be overloaded too. There are some restrictions on the arguments
3304+
invoked.
3305+
[=Constructor operations=] can be overloaded too.
3306+
There are some restrictions on the arguments
32173307
that overloaded operations and constructors can be
32183308
specified to take, and in order to describe these restrictions,
32193309
the notion of an <em>effective overload set</em> is used.
@@ -3246,7 +3336,7 @@ definitions.
32463336
};
32473337
</pre>
32483338

3249-
Note that the [{{Constructor}}] and
3339+
Note that [=constructor operations=] and
32503340
[{{NamedConstructor}}]
32513341
[=extended attributes=] are disallowed from appearing
32523342
on [=partial interface=] definitions,
@@ -3257,7 +3347,7 @@ definitions.
32573347
An <dfn id="dfn-effective-overload-set" export>effective overload set</dfn>
32583348
represents the allowable invocations for a particular
32593349
[=operation=],
3260-
constructor (specified with [{{Constructor}}]
3350+
constructor (specified with a [=constructor operation=]
32613351
or [{{NamedConstructor}}]), or
32623352
[=callback function=].
32633353
The algorithm to [=compute the effective overload set=]
@@ -3270,7 +3360,7 @@ the inputs to the algorithm needed to compute the set.
32703360
* the [=identifier=] of the operations
32713361
* the number of arguments to be passed
32723362
: For constructors
3273-
:: * the [=interface=] on which the [{{Constructor}}] [=extended attributes=] are to be found
3363+
:: * the [=interface=] on which the [=constructor operations=] are to be found
32743364
* the number of arguments to be passed
32753365
: For named constructors
32763366
:: * the [=interface=] on which the [{{NamedConstructor}}] [=extended attributes=] are to be found
@@ -3326,8 +3416,7 @@ the same operation or constructor.
33263416
identifier |A| defined on interface |I|.
33273417
: For constructors
33283418
:: The elements of |F| are the
3329-
[{{Constructor}}]
3330-
[=extended attributes=] on interface |I|.
3419+
[=constructor operations=] on interface |I|.
33313420
: For named constructors
33323421
:: The elements of |F| are the
33333422
[{{NamedConstructor}}]
@@ -8789,87 +8878,6 @@ for the specific requirements that the use of
87898878
</div>
87908879

87918880

8792-
<h4 id="Constructor" extended-attribute lt="Constructor">[Constructor]</h4>
8793-
8794-
If the [{{Constructor}}]
8795-
[=extended attribute=]
8796-
appears on an [=interface=], it indicates that
8797-
the [=interface object=] for this interface
8798-
will have an \[[Construct]] [=internal method=],
8799-
allowing objects implementing the interface to be constructed.
8800-
8801-
Multiple [{{Constructor}}] extended
8802-
attributes may appear on a given interface.
8803-
8804-
The [{{Constructor}}]
8805-
extended attribute must either
8806-
[=takes no arguments|take no arguments=] or
8807-
[=takes an argument list|take an argument list=].
8808-
The bare form, <code>[Constructor]</code>, has the same meaning as
8809-
using an empty argument list, <code>[Constructor()]</code>. For each
8810-
[{{Constructor}}] extended attribute
8811-
on the interface, there will be a way to construct an object that [=implements=]
8812-
the interface by passing the specified arguments.
8813-
8814-
The prose definition of a constructor must either initialize the value passed as <b>[=this=]</b>,
8815-
or throw an exception.
8816-
8817-
The [{{Constructor}}] and
8818-
[{{NoInterfaceObject}}]
8819-
extended attributes must not be specified on the same interface.
8820-
8821-
The [{{Constructor}}] and [{{Global}}] [=extended attributes=] must not be specified on the same
8822-
[=interface=].
8823-
8824-
See [[#interface-object]] for details on how a constructor
8825-
for an interface is to be implemented.
8826-
8827-
<div class="example">
8828-
8829-
The following IDL defines two interfaces. The second has the
8830-
[{{Constructor}}] extended
8831-
attribute, while the first does not.
8832-
8833-
<pre highlight="webidl">
8834-
[Exposed=Window]
8835-
interface NodeList {
8836-
Node item(unsigned long index);
8837-
readonly attribute unsigned long length;
8838-
};
8839-
8840-
[Exposed=Window,
8841-
Constructor,
8842-
Constructor(double radius)]
8843-
interface Circle {
8844-
attribute double r;
8845-
attribute double cx;
8846-
attribute double cy;
8847-
readonly attribute double circumference;
8848-
};
8849-
</pre>
8850-
8851-
An ECMAScript implementation supporting these interfaces would
8852-
have a \[[Construct]] property on the
8853-
<code class="idl">Circle</code> interface object which would
8854-
return a new object that [=implements=] the interface. It would take
8855-
either zero or one argument. The
8856-
<code class="idl">NodeList</code> interface object would not
8857-
have a \[[Construct]] property.
8858-
8859-
<pre highlight="js">
8860-
var x = new Circle(); // The uses the zero-argument constructor to create a
8861-
// reference to a platform object that implements the
8862-
// Circle interface.
8863-
8864-
var y = new Circle(1.25); // This also creates a Circle object, this time using
8865-
// the one-argument constructor.
8866-
8867-
var z = new NodeList(); // This would throw a TypeError, since no
8868-
// [Constructor] is declared.
8869-
</pre>
8870-
</div>
8871-
8872-
88738881
<h4 id="Default" extended-attribute lt="Default">[Default]</h4>
88748882

88758883
If the [{{Default}}] [=extended attribute=] appears on a [=regular operation=],
@@ -9264,6 +9272,7 @@ used on an [=interface=], then:
92649272

92659273
* The interface must not define a [=named property setter=].
92669274
* The interface must not define [=indexed property getters=] or [=indexed property setter|setters=].
9275+
* The interface must not define a [=constructor operation=].
92679276
* The interface must not also be declared with the [{{OverrideBuiltins}}]
92689277
extended attribute.
92699278
* The interface must not [=interface/inherit=] from another interface with the
@@ -9911,15 +9920,12 @@ will not exist for the interface in the ECMAScript binding.
99119920
The [{{NoInterfaceObject}}] extended attribute
99129921
must [=takes no arguments|take no arguments=].
99139922

9914-
If the [{{NoInterfaceObject}}] extended attribute
9915-
is specified on an interface, then the [{{Constructor}}]
9916-
extended attribute must not also be specified on that interface.
9917-
A [{{NamedConstructor}}] extended attribute is fine,
9918-
however.
9919-
99209923
The [{{NoInterfaceObject}}] extended attribute
99219924
must not be specified on an interface that has any
9922-
[=static operations=] defined on it.
9925+
[=constructors=] or [=static operations=] defined on it.
9926+
9927+
Note: Combining the [{{NoInterfaceObject}}] and [{{NamedConstructor}}] extended attribute is not
9928+
forbidden, however.
99239929

99249930
An interface that does not have the [{{NoInterfaceObject}}] extended
99259931
attribute specified must not inherit
@@ -11082,13 +11088,13 @@ It has properties that correspond to the [=constants=] and [=static operations=]
1108211088
defined on that interface,
1108311089
as described in sections [[#es-constants]] and [[#es-operations]].
1108411090

11085-
If the [=interface=] is declared with a [{{Constructor}}] [=extended attribute=],
11091+
If the [=interface=] is declared with a [=constructor operation=],
1108611092
then the [=interface object=] can be called as a [=constructor=]
1108711093
to create an object that [=implements=] that interface.
1108811094
Calling that interface as a function will throw an exception.
1108911095

1109011096
[=Interface objects=] whose [=interfaces=] are not declared
11091-
with a [{{Constructor}}] [=extended attribute=] will throw when called,
11097+
with a [=constructor operation=] will throw when called,
1109211098
both as a function and as a [=constructor=].
1109311099

1109411100
An [=interface object=] for an [=interface=]
@@ -11107,7 +11113,7 @@ the <code>typeof</code> operator will return "function" when applied to an inter
1110711113
is <dfn lt="create an interface object">created</dfn> as follows:
1110811114

1110911115
1. Let |steps| be the following steps:
11110-
1. If |I| was not declared with a [{{Constructor}}] [=extended attribute=],
11116+
1. If |I| was not declared with a [=constructor operation=],
1111111117
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
1111211118
1. If {{NewTarget}} is <emu-val>undefined</emu-val>, then
1111311119
[=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
@@ -11145,7 +11151,7 @@ the <code>typeof</code> operator will return "function" when applied to an inter
1114511151
function|operation functions=].
1114611152
1. Perform [=!=] <a abstract-op>SetFunctionName</a>(|F|, |id|).
1114711153
1. Let |length| be 0.
11148-
1. If |I| was declared with a [{{Constructor}}] [=extended attribute=], then
11154+
1. If |I| was declared with a [=constructor operation=], then
1114911155
1. [=Compute the effective overload set=] for constructors with [=identifier=] |id| on
1115011156
[=interface=] |I| and with argument count 0, and let |S| be the result.
1115111157
1. Set |length| to the length of the
@@ -14483,8 +14489,8 @@ terminal symbol <emu-t>const</emu-t>, an
1448314489
[=identifier=]
1448414490
"<code>A</code>" is distinct from one named "<code>a</code>", and an
1448514491
[=extended attribute=]
14486-
[<code class="idl">constructor</code>] will not be recognized as
14487-
the [{{Constructor}}]
14492+
[<code class="idl">namedconstructor</code>] will not be recognized as
14493+
the [{{NamedConstructor}}]
1448814494
extended attribute.
1448914495

1449014496
Implicitly, any number of <emu-t class="regex"><a href="#prod-whitespace">whitespace</a></emu-t> and

0 commit comments

Comments
 (0)