Skip to content

Commit 3cd7f5c

Browse files
committed
Stop using extended attributes for constructors
Fixes #636.
1 parent 13c7e8f commit 3cd7f5c

File tree

1 file changed

+101
-108
lines changed

1 file changed

+101
-108
lines changed

index.bs

Lines changed: 101 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,9 @@ in [[#es-extended-attributes]].
537537
attribute DOMString imageURL;
538538
};
539539

540-
[Exposed=Window, Constructor]
540+
[Exposed=Window]
541541
interface GraphicalWindow {
542+
constructor();
542543
readonly attribute unsigned long width;
543544
readonly attribute unsigned long height;
544545

@@ -565,12 +566,13 @@ in [[#es-extended-attributes]].
565566
objects; each ECMAScript object that implements <code class="idl">GraphicalWindow</code>
566567
will have that prototype object in its prototype chain.
567568

568-
The [{{Constructor}}] that appears on <code class="idl">GraphicalWindow</code>
569-
is an [=extended attribute=].
570-
This extended attribute causes a [=constructor=] to exist in ECMAScript implementations,
569+
The [=constructor method=] that appears on <code class="idl">GraphicalWindow</code>
570+
causes a [=constructor=] to exist in ECMAScript implementations,
571571
so that calling <code>new GraphicalWindow()</code> would return a new object
572572
that implemented the interface.
573573

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

576578

@@ -985,7 +987,6 @@ The relevant language binding determines how interfaces correspond to constructs
985987
in the language.
986988

987989
The following extended attributes are applicable to interfaces:
988-
[{{Constructor}}],
989990
[{{Exposed}}],
990991
[{{Global}}],
991992
[{{LegacyWindowAlias}}],
@@ -1066,6 +1067,7 @@ The <dfn>qualified name</dfn> of an [=interface=] |interface| is defined as foll
10661067
<pre class="grammar" id="prod-InterfaceMember">
10671068
InterfaceMember :
10681069
Const
1070+
Constructor
10691071
Operation
10701072
Stringifier
10711073
StaticMember
@@ -2149,7 +2151,8 @@ language bindings.
21492151
</pre>
21502152
</div>
21512153

2152-
An operation is considered to be <dfn id="dfn-variadic" export>variadic</dfn>
2154+
An operation or [=constructor method=] is considered to be
2155+
<dfn id="dfn-variadic" export>variadic</dfn>
21532156
if the final argument uses the <emu-t>...</emu-t> token just
21542157
after the argument type. Declaring an operation to be variadic indicates that
21552158
the operation can be invoked with any number of arguments after that final argument.
@@ -2168,8 +2171,7 @@ is the final argument in the operation’s argument list.
21682171

21692172
[=Extended attributes=]
21702173
that [=takes an argument list|take an argument list=]
2171-
([{{Constructor}}] and
2172-
[{{NamedConstructor}}], of those
2174+
([{{NamedConstructor}}], of those
21732175
defined in this specification) and [=callback functions=]
21742176
are also considered to be [=variadic=]
21752177
when the <emu-t>...</emu-t> token is used in their argument lists.
@@ -2564,6 +2566,82 @@ in which case the [=default toJSON operation=] is exposed instead.
25642566
</div>
25652567

25662568

2569+
<h4 id=idl-constructors oldids="Constructor" dfn>Constructor methods</h4>
2570+
2571+
If an [=interface=] has a [=constructor method=] member (matching
2572+
<emu-nt><a href="#prod-Constructor">Constructor</a></emu-nt>), it indicates that it is possible to
2573+
create objects that [=implement=] the [=interface=] using a [=constructor=].
2574+
2575+
Multiple [=constructor methods=] may appear on a given [=interface=].
2576+
For each [=constructor method=] on the [=interface=], there will be a way to construct an instance
2577+
by passing the specified arguments.
2578+
2579+
The prose definition of a [=constructor method=] must either initialize the value passed as
2580+
<b>[=this=]</b>, or throw an exception.
2581+
2582+
A [=constructor method=] must not be defined on a [=callback interface=].
2583+
2584+
See [[#interface-object]] for details on how a [=constructor method=] is to be implemented.
2585+
2586+
<div class="example">
2587+
2588+
The following IDL defines two interfaces. The second has [=constructor methods=], while the
2589+
first does not.
2590+
2591+
<pre highlight="webidl">
2592+
[Exposed=Window]
2593+
interface NodeList {
2594+
Node item(unsigned long index);
2595+
readonly attribute unsigned long length;
2596+
};
2597+
2598+
[Exposed=Window]
2599+
interface Circle {
2600+
constructor();
2601+
constructor(double radius);
2602+
attribute double r;
2603+
attribute double cx;
2604+
attribute double cy;
2605+
readonly attribute double circumference;
2606+
};
2607+
</pre>
2608+
2609+
An ECMAScript implementation supporting these interfaces would have a \[[Construct]] property
2610+
on the <code class="idl">Circle</code> interface object which would return a new object that
2611+
[=implements=] the interface.
2612+
It would take either zero or one argument.
2613+
The <code class="idl">NodeList</code> interface object would not have a \[[Construct]]
2614+
property.
2615+
2616+
<pre highlight="js">
2617+
var x = new Circle(); // The uses the zero-argument constructor to create a
2618+
// reference to a platform object that implements the
2619+
// Circle interface.
2620+
2621+
var y = new Circle(1.25); // This also creates a Circle object, this time using
2622+
// the one-argument constructor.
2623+
2624+
var z = new NodeList(); // This would throw a TypeError, since no
2625+
// [Constructor] is declared.
2626+
</pre>
2627+
</div>
2628+
2629+
2630+
2631+
<pre class="grammar" id="prod-Constructor">
2632+
Constructor :
2633+
"constructor" "(" ArgumentList ")" ";"
2634+
</pre>
2635+
2636+
<div data-fill-with="grammar-ArgumentList"></div>
2637+
<div data-fill-with="grammar-Arguments"></div>
2638+
<div data-fill-with="grammar-Argument"></div>
2639+
<div data-fill-with="grammar-ArgumentRest"></div>
2640+
<div data-fill-with="grammar-ArgumentName"></div>
2641+
<div data-fill-with="grammar-Ellipsis"></div>
2642+
<div data-fill-with="grammar-ArgumentNameKeyword"></div>
2643+
2644+
25672645
<h4 id="idl-special-operations">Special operations</h4>
25682646

25692647
A <dfn id="dfn-special-operation" export>special operation</dfn> is a
@@ -3184,7 +3262,7 @@ of an overloaded operation is used to invoke one of the
31843262
operations on an object that implements the interface, the
31853263
number and types of the arguments passed to the operation
31863264
determine which of the overloaded operations is actually
3187-
invoked. In the ECMAScript language binding, <a href="#Constructor">constructors</a>
3265+
invoked. In the ECMAScript language binding, [=constructor methods=]
31883266
can be overloaded too. There are some restrictions on the arguments
31893267
that overloaded operations and constructors can be
31903268
specified to take, and in order to describe these restrictions,
@@ -3218,7 +3296,7 @@ definitions.
32183296
};
32193297
</pre>
32203298

3221-
Note that the [{{Constructor}}] and
3299+
Note that [=constructor methods=] and
32223300
[{{NamedConstructor}}]
32233301
[=extended attributes=] are disallowed from appearing
32243302
on [=partial interface=] definitions,
@@ -3229,7 +3307,7 @@ definitions.
32293307
An <dfn id="dfn-effective-overload-set" export>effective overload set</dfn>
32303308
represents the allowable invocations for a particular
32313309
[=operation=],
3232-
constructor (specified with [{{Constructor}}]
3310+
constructor (specified with a [=constructor method=]
32333311
or [{{NamedConstructor}}]), or
32343312
[=callback function=].
32353313
The algorithm to [=compute the effective overload set=]
@@ -3242,7 +3320,7 @@ the inputs to the algorithm needed to compute the set.
32423320
* the [=identifier=] of the operations
32433321
* the number of arguments to be passed
32443322
: For constructors
3245-
:: * the [=interface=] on which the [{{Constructor}}] [=extended attributes=] are to be found
3323+
:: * the [=interface=] on which the [=constructor methods=] are to be found
32463324
* the number of arguments to be passed
32473325
: For named constructors
32483326
:: * the [=interface=] on which the [{{NamedConstructor}}] [=extended attributes=] are to be found
@@ -3298,8 +3376,7 @@ the same operation or constructor.
32983376
identifier |A| defined on interface |I|.
32993377
: For constructors
33003378
:: The elements of |F| are the
3301-
[{{Constructor}}]
3302-
[=extended attributes=] on interface |I|.
3379+
[=constructor methods=] on interface |I|.
33033380
: For named constructors
33043381
:: The elements of |F| are the
33053382
[{{NamedConstructor}}]
@@ -8286,87 +8363,6 @@ for the specific requirements that the use of
82868363
</div>
82878364

82888365

8289-
<h4 id="Constructor" extended-attribute lt="Constructor">[Constructor]</h4>
8290-
8291-
If the [{{Constructor}}]
8292-
[=extended attribute=]
8293-
appears on an [=interface=], it indicates that
8294-
the [=interface object=] for this interface
8295-
will have an \[[Construct]] [=internal method=],
8296-
allowing objects implementing the interface to be constructed.
8297-
8298-
Multiple [{{Constructor}}] extended
8299-
attributes may appear on a given interface.
8300-
8301-
The [{{Constructor}}]
8302-
extended attribute must either
8303-
[=takes no arguments|take no arguments=] or
8304-
[=takes an argument list|take an argument list=].
8305-
The bare form, <code>[Constructor]</code>, has the same meaning as
8306-
using an empty argument list, <code>[Constructor()]</code>. For each
8307-
[{{Constructor}}] extended attribute
8308-
on the interface, there will be a way to construct an object that [=implements=]
8309-
the interface by passing the specified arguments.
8310-
8311-
The prose definition of a constructor must either initialize the value passed as <b>[=this=]</b>,
8312-
or throw an exception.
8313-
8314-
The [{{Constructor}}] and
8315-
[{{NoInterfaceObject}}]
8316-
extended attributes must not be specified on the same interface.
8317-
8318-
The [{{Constructor}}] and [{{Global}}] [=extended attributes=] must not be specified on the same
8319-
[=interface=].
8320-
8321-
See [[#interface-object]] for details on how a constructor
8322-
for an interface is to be implemented.
8323-
8324-
<div class="example">
8325-
8326-
The following IDL defines two interfaces. The second has the
8327-
[{{Constructor}}] extended
8328-
attribute, while the first does not.
8329-
8330-
<pre highlight="webidl">
8331-
[Exposed=Window]
8332-
interface NodeList {
8333-
Node item(unsigned long index);
8334-
readonly attribute unsigned long length;
8335-
};
8336-
8337-
[Exposed=Window,
8338-
Constructor,
8339-
Constructor(double radius)]
8340-
interface Circle {
8341-
attribute double r;
8342-
attribute double cx;
8343-
attribute double cy;
8344-
readonly attribute double circumference;
8345-
};
8346-
</pre>
8347-
8348-
An ECMAScript implementation supporting these interfaces would
8349-
have a \[[Construct]] property on the
8350-
<code class="idl">Circle</code> interface object which would
8351-
return a new object that [=implements=] the interface. It would take
8352-
either zero or one argument. The
8353-
<code class="idl">NodeList</code> interface object would not
8354-
have a \[[Construct]] property.
8355-
8356-
<pre highlight="js">
8357-
var x = new Circle(); // The uses the zero-argument constructor to create a
8358-
// reference to a platform object that implements the
8359-
// Circle interface.
8360-
8361-
var y = new Circle(1.25); // This also creates a Circle object, this time using
8362-
// the one-argument constructor.
8363-
8364-
var z = new NodeList(); // This would throw a TypeError, since no
8365-
// [Constructor] is declared.
8366-
</pre>
8367-
</div>
8368-
8369-
83708366
<h4 id="Default" extended-attribute lt="Default">[Default]</h4>
83718367

83728368
If the [{{Default}}] [=extended attribute=] appears on a [=regular operation=],
@@ -9407,15 +9403,12 @@ will not exist for the interface in the ECMAScript binding.
94079403
The [{{NoInterfaceObject}}] extended attribute
94089404
must [=takes no arguments|take no arguments=].
94099405

9410-
If the [{{NoInterfaceObject}}] extended attribute
9411-
is specified on an interface, then the [{{Constructor}}]
9412-
extended attribute must not also be specified on that interface.
9413-
A [{{NamedConstructor}}] extended attribute is fine,
9414-
however.
9415-
94169406
The [{{NoInterfaceObject}}] extended attribute
94179407
must not be specified on an interface that has any
9418-
[=static operations=] defined on it.
9408+
[=constructors=] or [=static operations=] defined on it.
9409+
9410+
Note: Combining the [{{NoInterfaceObject}}] and [{{NamedConstructor}}] extended attribute is not
9411+
forbidden, however.
94199412

94209413
An interface that does not have the [{{NoInterfaceObject}}] extended
94219414
attribute specified must not inherit
@@ -10578,13 +10571,13 @@ It has properties that correspond to the [=constants=] and [=static operations=]
1057810571
defined on that interface,
1057910572
as described in sections [[#es-constants]] and [[#es-operations]].
1058010573

10581-
If the [=interface=] is declared with a [{{Constructor}}] [=extended attribute=],
10574+
If the [=interface=] is declared with a [=constructor method=],
1058210575
then the [=interface object=] can be called as a [=constructor=]
1058310576
to create an object that [=implements=] that interface.
1058410577
Calling that interface as a function will throw an exception.
1058510578

1058610579
[=Interface objects=] whose [=interfaces=] are not declared
10587-
with a [{{Constructor}}] [=extended attribute=] will throw when called,
10580+
with a [=constructor method=] will throw when called,
1058810581
both as a function and as a [=constructor=].
1058910582

1059010583
An [=interface object=] for an [=interface=]
@@ -10603,7 +10596,7 @@ the <code>typeof</code> operator will return "function" when applied to an inter
1060310596
is <dfn lt="create an interface object">created</dfn> as follows:
1060410597

1060510598
1. Let |steps| be the following steps:
10606-
1. If |I| was not declared with a [{{Constructor}}] [=extended attribute=],
10599+
1. If |I| was not declared with a [=constructor method=],
1060710600
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
1060810601
1. If {{NewTarget}} is <emu-val>undefined</emu-val>, then
1060910602
[=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
@@ -10641,7 +10634,7 @@ the <code>typeof</code> operator will return "function" when applied to an inter
1064110634
function|operation functions=].
1064210635
1. Perform [=!=] <a abstract-op>SetFunctionName</a>(|F|, |id|).
1064310636
1. Let |length| be 0.
10644-
1. If |I| was declared with a [{{Constructor}}] [=extended attribute=], then
10637+
1. If |I| was declared with a [=constructor method=], then
1064510638
1. [=Compute the effective overload set=] for constructors with [=identifier=] |id| on
1064610639
[=interface=] |I| and with argument count 0, and let |S| be the result.
1064710640
1. Set |length| to the length of the
@@ -13752,8 +13745,8 @@ terminal symbol <emu-t>const</emu-t>, an
1375213745
[=identifier=]
1375313746
"<code>A</code>" is distinct from one named "<code>a</code>", and an
1375413747
[=extended attribute=]
13755-
[<code class="idl">constructor</code>] will not be recognized as
13756-
the [{{Constructor}}]
13748+
[<code class="idl">namedconstructor</code>] will not be recognized as
13749+
the [{{NamedConstructor}}]
1375713750
extended attribute.
1375813751

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

0 commit comments

Comments
 (0)