@@ -537,8 +537,9 @@ in [[#es-extended-attributes]].
537
537
attribute DOMString imageURL;
538
538
};
539
539
540
- [Exposed=Window, Constructor ]
540
+ [Exposed=Window]
541
541
interface GraphicalWindow {
542
+ constructor();
542
543
readonly attribute unsigned long width;
543
544
readonly attribute unsigned long height;
544
545
@@ -565,12 +566,13 @@ in [[#es-extended-attributes]].
565
566
objects; each ECMAScript object that implements <code class="idl">GraphicalWindow</code>
566
567
will have that prototype object in its prototype chain.
567
568
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,
571
571
so that calling <code>new GraphicalWindow()</code> would return a new object
572
572
that implemented the interface.
573
573
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.
574
576
</div>
575
577
576
578
@@ -985,7 +987,6 @@ The relevant language binding determines how interfaces correspond to constructs
985
987
in the language.
986
988
987
989
The following extended attributes are applicable to interfaces:
988
- [{{Constructor}}],
989
990
[{{Exposed}}],
990
991
[{{Global}}],
991
992
[{{LegacyWindowAlias}}],
@@ -1066,6 +1067,7 @@ The <dfn>qualified name</dfn> of an [=interface=] |interface| is defined as foll
1066
1067
<pre class="grammar" id="prod-InterfaceMember">
1067
1068
InterfaceMember :
1068
1069
Const
1070
+ Constructor
1069
1071
Operation
1070
1072
Stringifier
1071
1073
StaticMember
@@ -2149,7 +2151,8 @@ language bindings.
2149
2151
</pre>
2150
2152
</div>
2151
2153
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>
2153
2156
if the final argument uses the <emu-t>...</emu-t> token just
2154
2157
after the argument type. Declaring an operation to be variadic indicates that
2155
2158
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.
2168
2171
2169
2172
[=Extended attributes=]
2170
2173
that [=takes an argument list|take an argument list=]
2171
- ([{{Constructor}}] and
2172
- [{{NamedConstructor}}], of those
2174
+ ([{{NamedConstructor}}], of those
2173
2175
defined in this specification) and [=callback functions=]
2174
2176
are also considered to be [=variadic=]
2175
2177
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.
2564
2566
</div>
2565
2567
2566
2568
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
+
2567
2645
<h4 id="idl-special-operations">Special operations</h4>
2568
2646
2569
2647
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
3184
3262
operations on an object that implements the interface, the
3185
3263
number and types of the arguments passed to the operation
3186
3264
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=]
3188
3266
can be overloaded too. There are some restrictions on the arguments
3189
3267
that overloaded operations and constructors can be
3190
3268
specified to take, and in order to describe these restrictions,
@@ -3218,7 +3296,7 @@ definitions.
3218
3296
};
3219
3297
</pre>
3220
3298
3221
- Note that the [{{Constructor}} ] and
3299
+ Note that [=constructor methods= ] and
3222
3300
[{{NamedConstructor}}]
3223
3301
[=extended attributes=] are disallowed from appearing
3224
3302
on [=partial interface=] definitions,
@@ -3229,7 +3307,7 @@ definitions.
3229
3307
An <dfn id="dfn-effective-overload-set" export>effective overload set</dfn>
3230
3308
represents the allowable invocations for a particular
3231
3309
[=operation=],
3232
- constructor (specified with [{{Constructor}} ]
3310
+ constructor (specified with a [=constructor method= ]
3233
3311
or [{{NamedConstructor}}]), or
3234
3312
[=callback function=].
3235
3313
The algorithm to [=compute the effective overload set=]
@@ -3242,7 +3320,7 @@ the inputs to the algorithm needed to compute the set.
3242
3320
* the [=identifier=] of the operations
3243
3321
* the number of arguments to be passed
3244
3322
: 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
3246
3324
* the number of arguments to be passed
3247
3325
: For named constructors
3248
3326
:: * the [=interface=] on which the [{{NamedConstructor}}] [=extended attributes=] are to be found
@@ -3298,8 +3376,7 @@ the same operation or constructor.
3298
3376
identifier |A| defined on interface |I|.
3299
3377
: For constructors
3300
3378
:: The elements of |F| are the
3301
- [{{Constructor}}]
3302
- [=extended attributes=] on interface |I|.
3379
+ [=constructor methods=] on interface |I|.
3303
3380
: For named constructors
3304
3381
:: The elements of |F| are the
3305
3382
[{{NamedConstructor}}]
@@ -8286,87 +8363,6 @@ for the specific requirements that the use of
8286
8363
</div>
8287
8364
8288
8365
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
-
8370
8366
<h4 id="Default" extended-attribute lt="Default">[Default]</h4>
8371
8367
8372
8368
If the [{{Default}}] [=extended attribute=] appears on a [=regular operation=],
@@ -9407,15 +9403,12 @@ will not exist for the interface in the ECMAScript binding.
9407
9403
The [{{NoInterfaceObject}}] extended attribute
9408
9404
must [=takes no arguments|take no arguments=].
9409
9405
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
-
9416
9406
The [{{NoInterfaceObject}}] extended attribute
9417
9407
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.
9419
9412
9420
9413
An interface that does not have the [{{NoInterfaceObject}}] extended
9421
9414
attribute specified must not inherit
@@ -10578,13 +10571,13 @@ It has properties that correspond to the [=constants=] and [=static operations=]
10578
10571
defined on that interface,
10579
10572
as described in sections [[#es-constants]] and [[#es-operations]].
10580
10573
10581
- If the [=interface=] is declared with a [{{Constructor}}] [=extended attribute =],
10574
+ If the [=interface=] is declared with a [=constructor method =],
10582
10575
then the [=interface object=] can be called as a [=constructor=]
10583
10576
to create an object that [=implements=] that interface.
10584
10577
Calling that interface as a function will throw an exception.
10585
10578
10586
10579
[=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,
10588
10581
both as a function and as a [=constructor=].
10589
10582
10590
10583
An [=interface object=] for an [=interface=]
@@ -10603,7 +10596,7 @@ the <code>typeof</code> operator will return "function" when applied to an inter
10603
10596
is <dfn lt="create an interface object">created</dfn> as follows:
10604
10597
10605
10598
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 =],
10607
10600
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
10608
10601
1. If {{NewTarget}} is <emu-val>undefined</emu-val>, then
10609
10602
[=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
@@ -10641,7 +10634,7 @@ the <code>typeof</code> operator will return "function" when applied to an inter
10641
10634
function|operation functions=].
10642
10635
1. Perform [=!=] <a abstract-op>SetFunctionName</a>(|F|, |id|).
10643
10636
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
10645
10638
1. [=Compute the effective overload set=] for constructors with [=identifier=] |id| on
10646
10639
[=interface=] |I| and with argument count 0, and let |S| be the result.
10647
10640
1. Set |length| to the length of the
@@ -13752,8 +13745,8 @@ terminal symbol <emu-t>const</emu-t>, an
13752
13745
[=identifier=]
13753
13746
"<code>A</code>" is distinct from one named "<code>a</code>", and an
13754
13747
[=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 }}]
13757
13750
extended attribute.
13758
13751
13759
13752
Implicitly, any number of <emu-t class="regex"><a href="#prod-whitespace">whitespace</a></emu-t> and
0 commit comments