@@ -543,8 +543,9 @@ in [[#es-extended-attributes]].
543
543
attribute DOMString imageURL;
544
544
};
545
545
546
- [Exposed=Window, Constructor ]
546
+ [Exposed=Window]
547
547
interface GraphicalWindow {
548
+ constructor();
548
549
readonly attribute unsigned long width;
549
550
readonly attribute unsigned long height;
550
551
@@ -571,12 +572,13 @@ in [[#es-extended-attributes]].
571
572
objects; each ECMAScript object that implements <code class="idl">GraphicalWindow</code>
572
573
will have that prototype object in its prototype chain.
573
574
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,
577
577
so that calling <code>new GraphicalWindow()</code> would return a new object
578
578
that implemented the interface.
579
579
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.
580
582
</div>
581
583
582
584
@@ -992,7 +994,6 @@ The relevant language binding determines how interfaces correspond to constructs
992
994
in the language.
993
995
994
996
The following extended attributes are applicable to interfaces:
995
- [{{Constructor}}],
996
997
[{{Exposed}}],
997
998
[{{Global}}],
998
999
[{{LegacyWindowAlias}}],
@@ -1061,7 +1062,7 @@ The <dfn>qualified name</dfn> of an [=interface=] |interface| is defined as foll
1061
1062
1062
1063
<pre class="grammar" id="prod-PartialInterfaceRest">
1063
1064
PartialInterfaceRest :
1064
- identifier "{" InterfaceMembers "}" ";"
1065
+ identifier "{" PartialInterfaceMembers "}" ";"
1065
1066
</pre>
1066
1067
1067
1068
<pre class="grammar" id="prod-InterfaceMembers">
@@ -1072,6 +1073,18 @@ The <dfn>qualified name</dfn> of an [=interface=] |interface| is defined as foll
1072
1073
1073
1074
<pre class="grammar" id="prod-InterfaceMember">
1074
1075
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 :
1075
1088
Const
1076
1089
Operation
1077
1090
Stringifier
@@ -2166,7 +2179,8 @@ language bindings.
2166
2179
</pre>
2167
2180
</div>
2168
2181
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>
2170
2184
if the final argument uses the <emu-t>...</emu-t> token just
2171
2185
after the argument type. Declaring an operation to be variadic indicates that
2172
2186
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.
2185
2199
2186
2200
[=Extended attributes=]
2187
2201
that [=takes an argument list|take an argument list=]
2188
- ([{{Constructor}}] and
2189
- [{{NamedConstructor}}], of those
2202
+ ([{{NamedConstructor}}], of those
2190
2203
defined in this specification) and [=callback functions=]
2191
2204
are also considered to be [=variadic=]
2192
2205
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.
2592
2605
</div>
2593
2606
2594
2607
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
+
2595
2684
<h4 id="idl-special-operations">Special operations</h4>
2596
2685
2597
2686
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
3212
3301
operations on an object that implements the interface, the
3213
3302
number and types of the arguments passed to the operation
3214
3303
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
3217
3307
that overloaded operations and constructors can be
3218
3308
specified to take, and in order to describe these restrictions,
3219
3309
the notion of an <em>effective overload set</em> is used.
@@ -3246,7 +3336,7 @@ definitions.
3246
3336
};
3247
3337
</pre>
3248
3338
3249
- Note that the [{{Constructor}} ] and
3339
+ Note that [=constructor operations= ] and
3250
3340
[{{NamedConstructor}}]
3251
3341
[=extended attributes=] are disallowed from appearing
3252
3342
on [=partial interface=] definitions,
@@ -3257,7 +3347,7 @@ definitions.
3257
3347
An <dfn id="dfn-effective-overload-set" export>effective overload set</dfn>
3258
3348
represents the allowable invocations for a particular
3259
3349
[=operation=],
3260
- constructor (specified with [{{Constructor}} ]
3350
+ constructor (specified with a [=constructor operation= ]
3261
3351
or [{{NamedConstructor}}]), or
3262
3352
[=callback function=].
3263
3353
The algorithm to [=compute the effective overload set=]
@@ -3270,7 +3360,7 @@ the inputs to the algorithm needed to compute the set.
3270
3360
* the [=identifier=] of the operations
3271
3361
* the number of arguments to be passed
3272
3362
: 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
3274
3364
* the number of arguments to be passed
3275
3365
: For named constructors
3276
3366
:: * the [=interface=] on which the [{{NamedConstructor}}] [=extended attributes=] are to be found
@@ -3326,8 +3416,7 @@ the same operation or constructor.
3326
3416
identifier |A| defined on interface |I|.
3327
3417
: For constructors
3328
3418
:: The elements of |F| are the
3329
- [{{Constructor}}]
3330
- [=extended attributes=] on interface |I|.
3419
+ [=constructor operations=] on interface |I|.
3331
3420
: For named constructors
3332
3421
:: The elements of |F| are the
3333
3422
[{{NamedConstructor}}]
@@ -8789,87 +8878,6 @@ for the specific requirements that the use of
8789
8878
</div>
8790
8879
8791
8880
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
-
8873
8881
<h4 id="Default" extended-attribute lt="Default">[Default]</h4>
8874
8882
8875
8883
If the [{{Default}}] [=extended attribute=] appears on a [=regular operation=],
@@ -9264,6 +9272,7 @@ used on an [=interface=], then:
9264
9272
9265
9273
* The interface must not define a [=named property setter=].
9266
9274
* The interface must not define [=indexed property getters=] or [=indexed property setter|setters=].
9275
+ * The interface must not define a [=constructor operation=].
9267
9276
* The interface must not also be declared with the [{{OverrideBuiltins}}]
9268
9277
extended attribute.
9269
9278
* 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.
9911
9920
The [{{NoInterfaceObject}}] extended attribute
9912
9921
must [=takes no arguments|take no arguments=].
9913
9922
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
-
9920
9923
The [{{NoInterfaceObject}}] extended attribute
9921
9924
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.
9923
9929
9924
9930
An interface that does not have the [{{NoInterfaceObject}}] extended
9925
9931
attribute specified must not inherit
@@ -11082,13 +11088,13 @@ It has properties that correspond to the [=constants=] and [=static operations=]
11082
11088
defined on that interface,
11083
11089
as described in sections [[#es-constants]] and [[#es-operations]].
11084
11090
11085
- If the [=interface=] is declared with a [{{Constructor}}] [=extended attribute =],
11091
+ If the [=interface=] is declared with a [=constructor operation =],
11086
11092
then the [=interface object=] can be called as a [=constructor=]
11087
11093
to create an object that [=implements=] that interface.
11088
11094
Calling that interface as a function will throw an exception.
11089
11095
11090
11096
[=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,
11092
11098
both as a function and as a [=constructor=].
11093
11099
11094
11100
An [=interface object=] for an [=interface=]
@@ -11107,7 +11113,7 @@ the <code>typeof</code> operator will return "function" when applied to an inter
11107
11113
is <dfn lt="create an interface object">created</dfn> as follows:
11108
11114
11109
11115
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 =],
11111
11117
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
11112
11118
1. If {{NewTarget}} is <emu-val>undefined</emu-val>, then
11113
11119
[=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
@@ -11145,7 +11151,7 @@ the <code>typeof</code> operator will return "function" when applied to an inter
11145
11151
function|operation functions=].
11146
11152
1. Perform [=!=] <a abstract-op>SetFunctionName</a>(|F|, |id|).
11147
11153
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
11149
11155
1. [=Compute the effective overload set=] for constructors with [=identifier=] |id| on
11150
11156
[=interface=] |I| and with argument count 0, and let |S| be the result.
11151
11157
1. Set |length| to the length of the
@@ -14483,8 +14489,8 @@ terminal symbol <emu-t>const</emu-t>, an
14483
14489
[=identifier=]
14484
14490
"<code>A</code>" is distinct from one named "<code>a</code>", and an
14485
14491
[=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 }}]
14488
14494
extended attribute.
14489
14495
14490
14496
Implicitly, any number of <emu-t class="regex"><a href="#prod-whitespace">whitespace</a></emu-t> and
0 commit comments