Skip to content

Commit 5ad6327

Browse files
committed
Stop using extended attributes for constructors
Fixes #636.
1 parent c86c55b commit 5ad6327

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
@@ -507,8 +507,9 @@ in [[#es-extended-attributes]].
507507
attribute DOMString imageURL;
508508
};
509509

510-
[Exposed=Window, Constructor]
510+
[Exposed=Window]
511511
interface GraphicalWindow {
512+
constructor();
512513
readonly attribute unsigned long width;
513514
readonly attribute unsigned long height;
514515

@@ -535,12 +536,13 @@ in [[#es-extended-attributes]].
535536
objects; each ECMAScript object that implements <code class="idl">GraphicalWindow</code>
536537
will have that prototype object in its prototype chain.
537538

538-
The [{{Constructor}}] that appears on <code class="idl">GraphicalWindow</code>
539-
is an [=extended attribute=].
540-
This extended attribute causes a [=constructor=] to exist in ECMAScript implementations,
539+
The [=constructor method=] that appears on <code class="idl">GraphicalWindow</code>
540+
causes a [=constructor=] to exist in ECMAScript implementations,
541541
so that calling <code>new GraphicalWindow()</code> would return a new object
542542
that implemented the interface.
543543

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

546548

@@ -1057,7 +1059,6 @@ The relevant language binding determines how interfaces correspond to constructs
10571059
in the language.
10581060

10591061
The following extended attributes are applicable to interfaces:
1060-
[{{Constructor}}],
10611062
[{{Exposed}}],
10621063
[{{Global}}],
10631064
[{{LegacyWindowAlias}}],
@@ -1145,6 +1146,7 @@ The <dfn>qualified name</dfn> of an [=interface=] |interface| is defined as foll
11451146
<pre class="grammar" id="prod-InterfaceMember">
11461147
InterfaceMember :
11471148
Const
1149+
Constructor
11481150
Operation
11491151
Stringifier
11501152
StaticMember
@@ -2155,7 +2157,8 @@ language bindings.
21552157
</pre>
21562158
</div>
21572159

2158-
An operation is considered to be <dfn id="dfn-variadic" export>variadic</dfn>
2160+
An operation or [=constructor method=] is considered to be
2161+
<dfn id="dfn-variadic" export>variadic</dfn>
21592162
if the final argument uses the <emu-t>...</emu-t> token just
21602163
after the argument type. Declaring an operation to be variadic indicates that
21612164
the operation can be invoked with any number of arguments after that final argument.
@@ -2174,8 +2177,7 @@ is the final argument in the operation’s argument list.
21742177

21752178
[=Extended attributes=]
21762179
that [=takes an argument list|take an argument list=]
2177-
([{{Constructor}}] and
2178-
[{{NamedConstructor}}], of those
2180+
([{{NamedConstructor}}], of those
21792181
defined in this specification) and [=callback functions=]
21802182
are also considered to be [=variadic=]
21812183
when the <emu-t>...</emu-t> token is used in their argument lists.
@@ -2540,6 +2542,82 @@ in which case the [=default toJSON operation=] is exposed instead.
25402542
</div>
25412543

25422544

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

25452623
A <dfn id="dfn-special-operation" export>special operation</dfn> is a
@@ -3166,7 +3244,7 @@ of an overloaded operation is used to invoke one of the
31663244
operations on an object that implements the interface, the
31673245
number and types of the arguments passed to the operation
31683246
determine which of the overloaded operations is actually
3169-
invoked. In the ECMAScript language binding, <a href="#Constructor">constructors</a>
3247+
invoked. In the ECMAScript language binding, [=constructor methods=]
31703248
can be overloaded too. There are some restrictions on the arguments
31713249
that overloaded operations and constructors can be
31723250
specified to take, and in order to describe these restrictions,
@@ -3200,7 +3278,7 @@ definitions.
32003278
};
32013279
</pre>
32023280

3203-
Note that the [{{Constructor}}] and
3281+
Note that [=constructor methods=] and
32043282
[{{NamedConstructor}}]
32053283
[=extended attributes=] are disallowed from appearing
32063284
on [=partial interface=] definitions,
@@ -3211,7 +3289,7 @@ definitions.
32113289
An <dfn id="dfn-effective-overload-set" export>effective overload set</dfn>
32123290
represents the allowable invocations for a particular
32133291
[=operation=],
3214-
constructor (specified with [{{Constructor}}]
3292+
constructor (specified with a [=constructor method=]
32153293
or [{{NamedConstructor}}]), or
32163294
[=callback function=].
32173295
The algorithm to compute an [=effective overload set=]
@@ -3224,7 +3302,7 @@ the inputs to the algorithm needed to compute the set.
32243302
* the [=identifier=] of the operations
32253303
* the number of arguments to be passed
32263304
: For constructors
3227-
:: * the [=interface=] on which the [{{Constructor}}] [=extended attributes=] are to be found
3305+
:: * the [=interface=] on which the [=constructor methods=] are to be found
32283306
* the number of arguments to be passed
32293307
: For named constructors
32303308
:: * the [=interface=] on which the [{{NamedConstructor}}] [=extended attributes=] are to be found
@@ -3280,8 +3358,7 @@ the same operation or constructor.
32803358
identifier |A| defined on interface |I|.
32813359
: For constructors
32823360
:: The elements of |F| are the
3283-
[{{Constructor}}]
3284-
[=extended attributes=] on interface |I|.
3361+
[=constructor methods=] on interface |I|.
32853362
: For named constructors
32863363
:: The elements of |F| are the
32873364
[{{NamedConstructor}}]
@@ -8308,87 +8385,6 @@ for the specific requirements that the use of
83088385
</div>
83098386

83108387

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

83948390
If the [{{Default}}] [=extended attribute=] appears on a [=regular operation=],
@@ -9432,15 +9428,12 @@ will not exist for the interface in the ECMAScript binding.
94329428
The [{{NoInterfaceObject}}] extended attribute
94339429
must [=takes no arguments|take no arguments=].
94349430

9435-
If the [{{NoInterfaceObject}}] extended attribute
9436-
is specified on an interface, then the [{{Constructor}}]
9437-
extended attribute must not also be specified on that interface.
9438-
A [{{NamedConstructor}}] extended attribute is fine,
9439-
however.
9440-
94419431
The [{{NoInterfaceObject}}] extended attribute
94429432
must not be specified on an interface that has any
9443-
[=static operations=] defined on it.
9433+
[=constructors=] or [=static operations=] defined on it.
9434+
9435+
Note: Combining the [{{NoInterfaceObject}}] and [{{NamedConstructor}}] extended attribute is not
9436+
forbidden, however.
94449437

94459438
The [{{NoInterfaceObject}}] extended attribute
94469439
must not be specified on a [=callback interface=].
@@ -10637,13 +10630,13 @@ It has properties that correspond to the [=constants=] and [=static operations=]
1063710630
defined on that interface,
1063810631
as described in sections [[#es-constants]] and [[#es-operations]].
1063910632

10640-
If the [=interface=] is declared with a [{{Constructor}}] [=extended attribute=],
10633+
If the [=interface=] is declared with a [=constructor method=],
1064110634
then the [=interface object=] can be called as a [=constructor=]
1064210635
to create an object that [=implements=] that interface.
1064310636
Calling that interface as a function will throw an exception.
1064410637

1064510638
[=Interface objects=] whose [=interfaces=] are not declared
10646-
with a [{{Constructor}}] [=extended attribute=] will throw when called,
10639+
with a [=constructor method=] will throw when called,
1064710640
both as a function and as a [=constructor=].
1064810641

1064910642
An [=interface object=] for a non-callback [=interface=]
@@ -10662,7 +10655,7 @@ the <code>typeof</code> operator will return "function" when applied to an inter
1066210655
is <dfn lt="create an interface object">created</dfn> as follows:
1066310656

1066410657
1. Let |steps| be the following steps:
10665-
1. If |I| was not declared with a [{{Constructor}}] [=extended attribute=],
10658+
1. If |I| was not declared with a [=constructor method=],
1066610659
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
1066710660
1. If {{NewTarget}} is <emu-val>undefined</emu-val>, then
1066810661
[=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
@@ -10701,7 +10694,7 @@ the <code>typeof</code> operator will return "function" when applied to an inter
1070110694
function|operation functions=].
1070210695
1. Perform [=!=] <a abstract-op>SetFunctionName</a>(|F|, |id|).
1070310696
1. Let |length| be 0.
10704-
1. If |I| was declared with a [{{Constructor}}] [=extended attribute=], then
10697+
1. If |I| was declared with a [=constructor method=], then
1070510698
1. Initialize |S| to the [=effective overload set=]
1070610699
for constructors with [=identifier=] |id| on [=interface=] |I| and
1070710700
with argument count 0.
@@ -13718,8 +13711,8 @@ terminal symbol <emu-t>const</emu-t>, an
1371813711
[=identifier=]
1371913712
"<code>A</code>" is distinct from one named "<code>a</code>", and an
1372013713
[=extended attribute=]
13721-
[<code class="idl">constructor</code>] will not be recognized as
13722-
the [{{Constructor}}]
13714+
[<code class="idl">namedconstructor</code>] will not be recognized as
13715+
the [{{NamedConstructor}}]
1372313716
extended attribute.
1372413717

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

0 commit comments

Comments
 (0)