Skip to content

Commit 6c11bcd

Browse files
committed
Rename "named constructors" to "legacy factory functions"
Closes #277. This includes renaming the extended attribute, which is part of #350. Also, since we don't anticipate this being used again, we remove the zero-argument form, which has no current users. As a bonus, this removes some leftover references to "constructor extended attributes".
1 parent 9fa4955 commit 6c11bcd

File tree

1 file changed

+63
-64
lines changed

1 file changed

+63
-64
lines changed

index.bs

Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ The following extended attributes are applicable to interfaces:
10101010
[{{Exposed}}],
10111011
[{{Global}}],
10121012
[{{LegacyWindowAlias}}],
1013-
[{{NamedConstructor}}],
1013+
[{{LegacyFactoryFunction}}],
10141014
[{{NoInterfaceObject}}],
10151015
[{{LegacyOverrideBuiltIns}}], and
10161016
[{{SecureContext}}].
@@ -2212,7 +2212,7 @@ is the final argument in the operation’s argument list.
22122212

22132213
[=Extended attributes=]
22142214
that [=takes an argument list|take an argument list=]
2215-
([{{NamedConstructor}}], of those
2215+
([{{LegacyFactoryFunction}}], of those
22162216
defined in this specification) and [=callback functions=]
22172217
are also considered to be [=variadic=]
22182218
when the <emu-t>...</emu-t> token is used in their argument lists.
@@ -3353,7 +3353,7 @@ definitions.
33533353
</pre>
33543354

33553355
Note that [=constructor operations=] and
3356-
[{{NamedConstructor}}]
3356+
[{{LegacyFactoryFunction}}]
33573357
[=extended attributes=] are disallowed from appearing
33583358
on [=partial interface=] definitions,
33593359
so there is no need to also disallow overloading for constructors.
@@ -3364,7 +3364,7 @@ An <dfn id="dfn-effective-overload-set" export>effective overload set</dfn>
33643364
represents the allowable invocations for a particular
33653365
[=operation=],
33663366
constructor (specified with a [=constructor operation=]
3367-
or [{{NamedConstructor}}]), or
3367+
or [{{LegacyFactoryFunction}}]), or
33683368
[=callback function=].
33693369
The algorithm to [=compute the effective overload set=]
33703370
operates on one of the following four types of IDL constructs, and listed with them below are
@@ -3378,9 +3378,9 @@ the inputs to the algorithm needed to compute the set.
33783378
: For constructors
33793379
:: * the [=interface=] on which the [=constructor operations=] are to be found
33803380
* the number of arguments to be passed
3381-
: For named constructors
3382-
:: * the [=interface=] on which the [{{NamedConstructor}}] [=extended attributes=] are to be found
3383-
* the [=identifier=] of the named constructors
3381+
: For legacy factory functions
3382+
:: * the [=interface=] on which the [{{LegacyFactoryFunction}}] [=extended attributes=] are to be found
3383+
* the [=identifier=] of the legacy factory function
33843384
* the number of arguments to be passed
33853385

33863386
An [=effective overload set=] is used, among other things, to determine whether there are
@@ -3393,7 +3393,7 @@ whose [=tuple/items=] are described below:
33933393
* A <dfn for="effective overload set tuple">callable</dfn> is an [=operation=]
33943394
if the [=effective overload set=] is for [=regular operations=],
33953395
[=static operations=], or [=constructor operations=]; and it is an [=extended attribute=]
3396-
if the [=effective overload set=] is for [=named constructors=].
3396+
if the [=effective overload set=] is for [=legacy factory functions=].
33973397
* A <dfn>type list</dfn> is a [=list=] of IDL types.
33983398
* An <dfn>optionality list</dfn> is a [=list=] of
33993399
three possible <dfn id="dfn-optionality-value" export>optionality values</dfn>
@@ -3413,7 +3413,7 @@ the same operation or constructor.
34133413
The algorithm below describes how to <dfn>compute the effective overload set</dfn>.
34143414
The following input variables are used, if they are required:
34153415

3416-
* the identifier of the operation or named constructor is |A|
3416+
* the identifier of the operation or legacy factory function is |A|
34173417
* the argument count is |N|
34183418
* the interface is |I|
34193419

@@ -3434,17 +3434,17 @@ the same operation or constructor.
34343434
: For constructors
34353435
:: The elements of |F| are the
34363436
[=constructor operations=] on interface |I|.
3437-
: For named constructors
3437+
: For legacy factory functions
34383438
:: The elements of |F| are the
3439-
[{{NamedConstructor}}]
3439+
[{{LegacyFactoryFunction}}]
34403440
[=extended attributes=] on interface |I| whose
34413441
[=takes a named argument list|named argument lists’=]
34423442
identifiers are |A|.
34433443
</dl>
34443444

34453445
1. Let |maxarg| be the maximum number of arguments the operations,
3446-
constructor extended attributes or callback functions in |F| are declared to take.
3447-
For [=variadic=] operations and constructor extended attributes,
3446+
legacy factory functions, or callback functions in |F| are declared to take.
3447+
For [=variadic=] operations and legacy factory functions,
34483448
the argument on which the ellipsis appears counts as a single argument.
34493449

34503450
Note: So <code>void f(long x, long... y);</code> is considered to be declared to take two arguments.
@@ -6949,7 +6949,7 @@ which form (or forms) it is in:
69496949
<dfn id="dfn-xattr-named-argument-list" for="extended attribute" export>takes a named argument list</dfn>
69506950
</td>
69516951
<td>
6952-
<code>[NamedConstructor=Image(DOMString src)]</code>
6952+
<code>[LegacyFactoryFunction=Image(DOMString src)]</code>
69536953
</td>
69546954
</tr>
69556955
<tr>
@@ -7202,7 +7202,7 @@ and comprise the following:
72027202

72037203
* [=interface objects=]
72047204
* [=legacy callback interface objects=]
7205-
* [=named constructors=]
7205+
* [=legacy factory functions=]
72067206
* [=interface prototype objects=]
72077207
* [=named properties objects=]
72087208
* [=iterator prototype objects=]
@@ -9703,7 +9703,7 @@ The <emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t>s that
97039703
Each of the [=LegacyWindowAlias identifier|identifiers=] of [{{LegacyWindowAlias}}]
97049704
must not be the same as one used by a [{{LegacyWindowAlias}}]
97059705
extended attribute on this interface or another interface,
9706-
must not be the same as the [=NamedConstructor identifier|identifier=] used by a [{{NamedConstructor}}]
9706+
must not be the same as the [=LegacyFactoryFunction identifier|identifier=] used by a [{{LegacyFactoryFunction}}]
97079707
extended attribute on this interface or another interface,
97089708
must not be the same as an [=identifier=] of an interface that has an [=interface object=],
97099709
and must not be one of the [=reserved identifiers=].
@@ -9915,52 +9915,48 @@ is to be implemented.
99159915
</div>
99169916

99179917

9918-
<h4 id="NamedConstructor" extended-attribute lt="NamedConstructor">[NamedConstructor]</h4>
9918+
<h4 id="LegacyFactoryFunction" extended-attribute lt="LegacyFactoryFunction">[LegacyFactoryFunction]</h4>
99199919

99209920
<div class="advisement">
99219921

9922-
[{{NamedConstructor}}] [=extended attribute=] is an undesirable feature.
9922+
[{{LegacyFactoryFunction}}] [=extended attribute=] is an undesirable feature.
99239923
It exists only so that legacy Web platform features can be specified.
99249924
It should not be used in specifications
99259925
unless required to specify the behavior of legacy APIs,
99269926
or for consistency with these APIs.
99279927
Editors who wish to use this feature are strongly advised to discuss this
9928-
by <a href="https://github.com/heycam/webidl/issues/new?title=Intent%20to%20use%20[NamedConstructor]">filing an issue</a>
9928+
by <a href="https://github.com/heycam/webidl/issues/new?title=Intent%20to%20use%20[LegacyFactoryFunction]">filing an issue</a>
99299929
before proceeding.
99309930

99319931
<small class="non-normative">
9932-
The [{{NamedConstructor}}] [=extended attribute=] appears on the following [=interfaces=]:
9932+
The [{{LegacyFactoryFunction}}] [=extended attribute=] appears on the following [=interfaces=]:
99339933
{{HTMLAudioElement}},
99349934
{{HTMLOptionElement}}, and
99359935
{{HTMLImageElement}}. [[HTML]]
99369936
</small>
99379937

99389938
</div>
99399939

9940-
If the [{{NamedConstructor}}]
9940+
If the [{{LegacyFactoryFunction}}]
99419941
[=extended attribute=]
99429942
appears on an [=interface=],
99439943
it indicates that the ECMAScript global object will have a property with the
9944-
specified name whose value is a [=constructor=] that can
9944+
specified name whose value is a function that can
99459945
create objects that implement the interface.
9946-
Multiple [{{NamedConstructor}}] extended
9946+
Multiple [{{LegacyFactoryFunction}}] extended
99479947
attributes may appear on a given interface.
99489948

9949-
The [{{NamedConstructor}}] extended attribute must either
9950-
[=takes an identifier|take an identifier=] or
9949+
The [{{LegacyFactoryFunction}}] extended attribute must
99519950
[=takes a named argument list|take a named argument list=].
99529951
The <emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t> that occurs directly after the
9953-
“<emu-t>=</emu-t>” is the [{{NamedConstructor}}]'s <dfn lt="NamedConstructor identifier">identifier</dfn>.
9954-
The first form, <code>[NamedConstructor=<emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t>]</code>,
9955-
has the same meaning as using an empty argument list,
9956-
<code>[NamedConstructor=<emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t>()]</code>.
9957-
For each [{{NamedConstructor}}] extended attribute on the interface,
9952+
“<emu-t>=</emu-t>” is the [{{LegacyFactoryFunction}}]'s <dfn lt="LegacyFactoryFunction identifier">identifier</dfn>.
9953+
For each [{{LegacyFactoryFunction}}] extended attribute on the interface,
99589954
there will be a way to construct an object that
99599955
[=implements=] the interface by passing the specified arguments to the [=constructor=]
99609956
that is the value of the aforementioned property.
99619957

9962-
The [=NamedConstructor identifier|identifier=] used for the named constructor must not
9963-
be the same as that used by a [{{NamedConstructor}}]
9958+
The [=LegacyFactoryFunction identifier|identifier=] used for the legacy factory function must not
9959+
be the same as that used by a [{{LegacyFactoryFunction}}]
99649960
extended attribute on another interface, must not
99659961
be the same as an [=LegacyWindowAlias identifier|identifier=] used by a [{{LegacyWindowAlias}}]
99669962
extended attribute on this interface or another interface,
@@ -9969,41 +9965,43 @@ that has an [=interface object=],
99699965
and must not be one of the
99709966
[=reserved identifiers=].
99719967

9972-
The [{{NamedConstructor}}] and [{{Global}}] [=extended attributes=] must not be specified on the
9968+
The [{{LegacyFactoryFunction}}] and [{{Global}}] [=extended attributes=] must not be specified on the
99739969
same [=interface=].
99749970

9975-
See [[#named-constructors]] for details on how named constructors
9971+
See [[#legacy-factory-functions]] for details on how legacy factory functions
99769972
are to be implemented.
99779973

99789974
<div class="example">
99799975

99809976
The following IDL defines an interface that uses the
9981-
[{{NamedConstructor}}] extended
9977+
[{{LegacyFactoryFunction}}] extended
99829978
attribute.
99839979

99849980
<pre highlight="webidl">
99859981
[Exposed=Window,
9986-
NamedConstructor=Audio,
9987-
NamedConstructor=Audio(DOMString src)]
9982+
LegacyFactoryFunction=Audio(DOMString src)]
99889983
interface HTMLAudioElement : HTMLMediaElement {
99899984
// ...
99909985
};
99919986
</pre>
99929987

99939988
An ECMAScript implementation that supports this interface will
99949989
allow the construction of <code class="idl">HTMLAudioElement</code>
9995-
objects using the <code class="idl">Audio</code> [=constructor=].
9990+
objects using the <code class="idl">Audio</code> function.
99969991

99979992
<pre highlight="js">
99989993
typeof Audio; // Evaluates to 'function'.
99999994

10000-
var a1 = new Audio(); // Creates a new object that implements
10001-
// HTMLAudioElement, using the zero-argument
10002-
// constructor.
10003-
100049995
var a2 = new Audio('a.flac'); // Creates an HTMLAudioElement using the
100059996
// one-argument constructor.
100069997
</pre>
9998+
9999+
As an additional legacy quirk, these factory functions will have a <code>prototype</code>
10000+
property equal to the <code>prototype</code> of the original interface:
10001+
10002+
<pre highlight="js">
10003+
console.assert(Audio.prototype === HTMLAudioElement.prototype);
10004+
</pre>
1000710005
</div>
1000810006

1000910007

@@ -10109,7 +10107,7 @@ The [{{NoInterfaceObject}}] extended attribute
1010910107
must not be specified on an interface that has any
1011010108
[=constructors=] or [=static operations=] defined on it.
1011110109

10112-
Note: Combining the [{{NoInterfaceObject}}] and [{{NamedConstructor}}] extended attribute is not
10110+
Note: Combining the [{{NoInterfaceObject}}] and [{{LegacyFactoryFunction}}] extended attribute is not
1011310111
forbidden, however.
1011410112

1011510113
An interface that does not have the [{{NoInterfaceObject}}] extended
@@ -11269,12 +11267,12 @@ there exists a corresponding property on the {{Window}} global object.
1126911267
The name of the property is the given [=LegacyWindowAlias identifier|identifier=],
1127011268
and its value is a reference to the [=interface object=] for the [=interface=].
1127111269

11272-
In addition, for every [{{NamedConstructor}}] extended attribute on an [=exposed=] interface,
11270+
In addition, for every [{{LegacyFactoryFunction}}] extended attribute on an [=exposed=] interface,
1127311271
a corresponding property exists on the ECMAScript global object.
11274-
The name of the property is the [{{NamedConstructor}}]'s [=NamedConstructor identifier|identifier=],
11275-
and its value is an object called a <dfn id="dfn-named-constructor" export>named constructor</dfn>,
11276-
which allows construction of objects that implement the interface.
11277-
The characteristics of a named constructor are described in [[#named-constructors]].
11272+
The name of the property is the [{{LegacyFactoryFunction}}]'s [=LegacyFactoryFunction identifier|identifier=],
11273+
and its value is an object called a <dfn id="dfn-legacy-factory-function" export oldids="dfn-named-constructor">legacy factory function</dfn>,
11274+
which allows creation of objects that implement the interface.
11275+
The characteristics of a legacy factory function are described in [[#legacy-factory-functions]].
1127811276

1127911277

1128011278
<h4 id="interface-object" oldids="es-interface-call,es-constructible-interfaces">Interface object</h4>
@@ -11377,27 +11375,27 @@ default interfaces do not have such steps.
1137711375
</div>
1137811376

1137911377

11380-
<h4 id="named-constructors">Named constructors</h4>
11378+
<h4 id="legacy-factory-functions" oldids="named-constructors">Legacy factory functions</h4>
1138111379

11382-
A [=named constructor=] that exists due to one or more
11383-
[{{NamedConstructor}}] [=extended attributes=]
11384-
with a given [=NamedConstructor identifier|identifier=] is a [=built-in function object=].
11380+
A [=legacy factory function=] that exists due to one or more
11381+
[{{LegacyFactoryFunction}}] [=extended attributes=]
11382+
with a given [=LegacyFactoryFunction identifier|identifier=] is a [=built-in function object=].
1138511383
It allows constructing objects that
1138611384
implement the interface on which the
11387-
[{{NamedConstructor}}] extended attributes appear.
11385+
[{{LegacyFactoryFunction}}] extended attributes appear.
1138811386

1138911387
<div algorithm>
1139011388

11391-
The [=named constructor=] with [=NamedConstructor identifier|identifier=] |id|
11389+
The [=legacy factory function=] with [=LegacyFactoryFunction identifier|identifier=] |id|
1139211390
for a given [=interface=] |I| in Realm |realm|
11393-
is <dfn lt="create a named constructor">created</dfn> as follows:
11391+
is <dfn lt="create a legacy factory function">created</dfn> as follows:
1139411392

1139511393
1. Let |steps| be the following steps:
1139611394
1. If {{NewTarget}} is <emu-val>undefined</emu-val>, then
1139711395
[=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
1139811396
1. Let |args| be the passed arguments.
1139911397
1. Let |n| be the [=list/size=] of |args|.
11400-
1. [=Compute the effective overload set=] for named constructors with [=identifier=] |id|
11398+
1. [=Compute the effective overload set=] for legacy factory functions with [=identifier=] |id|
1140111399
on [=interface=] |I| and with argument count |n|, and let |S| be the result.
1140211400
1. Let &lt;|constructor|, |values|&gt; be the result of passing |S| and
1140311401
|args| to the [=overload resolution algorithm=].
@@ -11413,7 +11411,7 @@ implement the interface on which the
1141311411
1. Return |O|.
1141411412
1. Let |F| be [=!=] <a abstract-op>CreateBuiltinFunction</a>(|steps|, « », |realm|).
1141511413
1. Perform [=!=] <a abstract-op>SetFunctionName</a>(|F|, |id|).
11416-
1. [=Compute the effective overload set=] for named constructors with [=identifier=] |id|
11414+
1. [=Compute the effective overload set=] for legacy factory functions with [=identifier=] |id|
1141711415
on [=interface=] |I| and with argument count 0, and let |S| be the result.
1141811416
1. Let |length| be the length of the shortest argument list of the entries in |S|.
1141911417
1. Perform [=!=] <a abstract-op>SetFunctionLength</a>(|F|, |length|).
@@ -13251,13 +13249,14 @@ the Realm given as an argument.
1325113249
1. [=list/iterate|For every=] [=LegacyWindowAlias identifier|identifier=] |id| in
1325213250
[{{LegacyWindowAlias}}]'s [=LegacyWindowAlias identifier|identifiers=]:
1325313251
1. Perform [=!=] [$CreateMethodProperty$](|target|, |id|, |interfaceObject|).
13254-
1. If the |interface| is declared with a [{{NamedConstructor}}] [=extended attribute=],
13252+
1. If the |interface| is declared with a [{{LegacyFactoryFunction}}] [=extended attribute=],
1325513253
then:
13256-
1. [=list/iterate|For every=] [=NamedConstructor identifier|identifier=] |id| in
13257-
[{{NamedConstructor}}]'s [=NamedConstructor identifier|identifiers=]:
13258-
1. Let |namedConstructor| be the result of [=create a named constructor|creating
13259-
a named constructor=] with |id| for |interface| in |realm|.
13260-
1. Perform [=!=] [$CreateMethodProperty$](|target|, |id|, |namedConstructor|).
13254+
1. [=list/iterate|For every=] [=LegacyFactoryFunction identifier|identifier=] |id| in
13255+
[{{LegacyFactoryFunction}}]'s [=LegacyFactoryFunction identifier|identifiers=]:
13256+
1. Let |legacyFactoryFunction| be the result of
13257+
[=create a legacy factory function|creating a legacy factory function=] with
13258+
|id| for |interface| in |realm|.
13259+
1. Perform [=!=] [$CreateMethodProperty$](|target|, |id|, |legacyFactoryFunction|).
1326113260
1. [=list/iterate|For every=] [=callback interface=] |interface| that is [=exposed=] in
1326213261
|realm| and on which [=constants=] are defined:
1326313262
1. Let |id| be |interface|'s [=identifier=].
@@ -14908,7 +14907,7 @@ terminal symbol <emu-t>const</emu-t>, an
1490814907
"<code>A</code>" is distinct from one named "<code>a</code>", and an
1490914908
[=extended attribute=]
1491014909
[<code class="idl">namedconstructor</code>] will not be recognized as
14911-
the [{{NamedConstructor}}]
14910+
the [{{LegacyFactoryFunction}}]
1491214911
extended attribute.
1491314912

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

0 commit comments

Comments
 (0)