@@ -507,8 +507,9 @@ in [[#es-extended-attributes]].
507
507
attribute DOMString imageURL;
508
508
};
509
509
510
- [Exposed=Window, Constructor ]
510
+ [Exposed=Window]
511
511
interface GraphicalWindow {
512
+ constructor();
512
513
readonly attribute unsigned long width;
513
514
readonly attribute unsigned long height;
514
515
@@ -535,12 +536,13 @@ in [[#es-extended-attributes]].
535
536
objects; each ECMAScript object that implements <code class="idl">GraphicalWindow</code>
536
537
will have that prototype object in its prototype chain.
537
538
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,
541
541
so that calling <code>new GraphicalWindow()</code> would return a new object
542
542
that implemented the interface.
543
543
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.
544
546
</div>
545
547
546
548
@@ -1057,7 +1059,6 @@ The relevant language binding determines how interfaces correspond to constructs
1057
1059
in the language.
1058
1060
1059
1061
The following extended attributes are applicable to interfaces:
1060
- [{{Constructor}}],
1061
1062
[{{Exposed}}],
1062
1063
[{{Global}}],
1063
1064
[{{LegacyWindowAlias}}],
@@ -1145,6 +1146,7 @@ The <dfn>qualified name</dfn> of an [=interface=] |interface| is defined as foll
1145
1146
<pre class="grammar" id="prod-InterfaceMember">
1146
1147
InterfaceMember :
1147
1148
Const
1149
+ Constructor
1148
1150
Operation
1149
1151
Stringifier
1150
1152
StaticMember
@@ -2155,7 +2157,8 @@ language bindings.
2155
2157
</pre>
2156
2158
</div>
2157
2159
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>
2159
2162
if the final argument uses the <emu-t>...</emu-t> token just
2160
2163
after the argument type. Declaring an operation to be variadic indicates that
2161
2164
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.
2174
2177
2175
2178
[=Extended attributes=]
2176
2179
that [=takes an argument list|take an argument list=]
2177
- ([{{Constructor}}] and
2178
- [{{NamedConstructor}}], of those
2180
+ ([{{NamedConstructor}}], of those
2179
2181
defined in this specification) and [=callback functions=]
2180
2182
are also considered to be [=variadic=]
2181
2183
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.
2540
2542
</div>
2541
2543
2542
2544
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
+
2543
2621
<h4 id="idl-special-operations">Special operations</h4>
2544
2622
2545
2623
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
3166
3244
operations on an object that implements the interface, the
3167
3245
number and types of the arguments passed to the operation
3168
3246
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=]
3170
3248
can be overloaded too. There are some restrictions on the arguments
3171
3249
that overloaded operations and constructors can be
3172
3250
specified to take, and in order to describe these restrictions,
@@ -3200,7 +3278,7 @@ definitions.
3200
3278
};
3201
3279
</pre>
3202
3280
3203
- Note that the [{{Constructor}} ] and
3281
+ Note that [=constructor methods= ] and
3204
3282
[{{NamedConstructor}}]
3205
3283
[=extended attributes=] are disallowed from appearing
3206
3284
on [=partial interface=] definitions,
@@ -3211,7 +3289,7 @@ definitions.
3211
3289
An <dfn id="dfn-effective-overload-set" export>effective overload set</dfn>
3212
3290
represents the allowable invocations for a particular
3213
3291
[=operation=],
3214
- constructor (specified with [{{Constructor}} ]
3292
+ constructor (specified with a [=constructor method= ]
3215
3293
or [{{NamedConstructor}}]), or
3216
3294
[=callback function=].
3217
3295
The algorithm to compute an [=effective overload set=]
@@ -3224,7 +3302,7 @@ the inputs to the algorithm needed to compute the set.
3224
3302
* the [=identifier=] of the operations
3225
3303
* the number of arguments to be passed
3226
3304
: 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
3228
3306
* the number of arguments to be passed
3229
3307
: For named constructors
3230
3308
:: * the [=interface=] on which the [{{NamedConstructor}}] [=extended attributes=] are to be found
@@ -3280,8 +3358,7 @@ the same operation or constructor.
3280
3358
identifier |A| defined on interface |I|.
3281
3359
: For constructors
3282
3360
:: The elements of |F| are the
3283
- [{{Constructor}}]
3284
- [=extended attributes=] on interface |I|.
3361
+ [=constructor methods=] on interface |I|.
3285
3362
: For named constructors
3286
3363
:: The elements of |F| are the
3287
3364
[{{NamedConstructor}}]
@@ -8308,87 +8385,6 @@ for the specific requirements that the use of
8308
8385
</div>
8309
8386
8310
8387
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
-
8392
8388
<h4 id="Default" extended-attribute lt="Default">[Default]</h4>
8393
8389
8394
8390
If the [{{Default}}] [=extended attribute=] appears on a [=regular operation=],
@@ -9432,15 +9428,12 @@ will not exist for the interface in the ECMAScript binding.
9432
9428
The [{{NoInterfaceObject}}] extended attribute
9433
9429
must [=takes no arguments|take no arguments=].
9434
9430
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
-
9441
9431
The [{{NoInterfaceObject}}] extended attribute
9442
9432
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.
9444
9437
9445
9438
The [{{NoInterfaceObject}}] extended attribute
9446
9439
must not be specified on a [=callback interface=].
@@ -10637,13 +10630,13 @@ It has properties that correspond to the [=constants=] and [=static operations=]
10637
10630
defined on that interface,
10638
10631
as described in sections [[#es-constants]] and [[#es-operations]].
10639
10632
10640
- If the [=interface=] is declared with a [{{Constructor}}] [=extended attribute =],
10633
+ If the [=interface=] is declared with a [=constructor method =],
10641
10634
then the [=interface object=] can be called as a [=constructor=]
10642
10635
to create an object that [=implements=] that interface.
10643
10636
Calling that interface as a function will throw an exception.
10644
10637
10645
10638
[=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,
10647
10640
both as a function and as a [=constructor=].
10648
10641
10649
10642
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
10662
10655
is <dfn lt="create an interface object">created</dfn> as follows:
10663
10656
10664
10657
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 =],
10666
10659
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
10667
10660
1. If {{NewTarget}} is <emu-val>undefined</emu-val>, then
10668
10661
[=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
@@ -10701,7 +10694,7 @@ the <code>typeof</code> operator will return "function" when applied to an inter
10701
10694
function|operation functions=].
10702
10695
1. Perform [=!=] <a abstract-op>SetFunctionName</a>(|F|, |id|).
10703
10696
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
10705
10698
1. Initialize |S| to the [=effective overload set=]
10706
10699
for constructors with [=identifier=] |id| on [=interface=] |I| and
10707
10700
with argument count 0.
@@ -13718,8 +13711,8 @@ terminal symbol <emu-t>const</emu-t>, an
13718
13711
[=identifier=]
13719
13712
"<code>A</code>" is distinct from one named "<code>a</code>", and an
13720
13713
[=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 }}]
13723
13716
extended attribute.
13724
13717
13725
13718
Implicitly, any number of <emu-t class="regex"><a href="#prod-whitespace">whitespace</a></emu-t> and
0 commit comments