-
Notifications
You must be signed in to change notification settings - Fork 165
/
index.bs
15353 lines (12460 loc) · 663 KB
/
index.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<pre class="metadata">
Group: WHATWG
H1: Web IDL
Shortname: webidl
Text Macro: TWITTER webidl
Text Macro: LATESTRD 2024-09
Abstract: This standard defines an interface definition language, Web IDL, that can be used to describe interfaces that
Abstract: are intended to be implemented in web browsers.
Translation: ja https://triple-underscore.github.io/WebIDL-ja.html
Complain About: accidental-2119 no
</pre>
<pre class="link-defaults">
spec: infra; type: dfn;
text: code unit
text: list
spec: ecmascript; type: dfn;
for: ECMAScript;
text: constructor
text: realm
spec: dom; type: dfn; text: element
</pre>
<pre class="anchors">
urlPrefix: https://tc39.es/ecma262/; spec: ecmascript
type: method; for: ECMAScript
text: JSON.stringify(); url: sec-json.stringify
text: %Array.prototype.entries%; url: sec-array.prototype.entries
text: %Array.prototype.forEach%; url: sec-array.prototype.foreach
text: %Array.prototype.keys%; url: sec-array.prototype.keys
text: %Array.prototype.values%; url: sec-array.prototype.values
text: %Promise.reject%; url: sec-promise.reject
text: %Promise.prototype.then%; url: sec-promise.prototype.then
type: argument
text: NewTarget; url: sec-built-in-function-objects
type: abstract-op
text: Completion; url: sec-completion-record-specification-type
text: IsInteger; url: sec-isinteger
text: abs; url: eqn-abs
text: floor; url: eqn-floor
text: max; url: eqn-max
text: min; url: eqn-min
type: dfn;
text: Abstract Closure; url: sec-abstract-closure
text: NumericLiteral; url: sec-literals-numeric-literals
text: modulo; url: eqn-modulo
url: sec-returnifabrupt-shorthands
text: !
text: ?
text: ECMA-262 Immutable Prototype Exotic Objects; url: sec-immutable-prototype-exotic-objects
text: abrupt completion; url: sec-completion-record-specification-type
text: array iterator object; url: sec-array-iterator-objects
text: built-in function object; url: sec-built-in-function-objects
text: callable; for: ECMAScript; url: sec-iscallable
text: Completion Record; url: sec-completion-record-specification-type
text: conventions; for: ECMAScript; url: sec-algorithm-conventions
text: current realm; url: current-realm
text: element; for: ECMAScript String; url: sec-ecmascript-language-types-string-type
text: enumerable; url: sec-property-attributes
text: equally close values; url: sec-ecmascript-language-types-number-type
text: error objects; for: ECMAScript; url: sec-error-objects
url: sec-object-internal-methods-and-internal-slots
text: internal method
text: internal slot
for: ordinary object; url: sec-ordinary-object-internal-methods-and-internal-slots
text: internal method
text: internal slot
text: own property; url: sec-own-property
text: PromiseCapability; url: sec-promisecapability-records
text: element size; url: table-the-typedarray-constructors
url: sec-ecmascript-language-types-bigint-type
text: is a BigInt
text: is not a BigInt
url: sec-ecmascript-language-types-boolean-type
text: is a Boolean
text: is not a Boolean
url: sec-ecmascript-language-types-number-type
text: is a Number
text: is not a Number
url: sec-ecmascript-language-types-string-type
text: is a String
text: is not a String
url: sec-ecmascript-language-types-symbol-type
text: is a Symbol
text: is not a Symbol
url: sec-object-type
text: is an Object
text: is not an Object
urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: RESIZABLE-BUFFERS-PROPOSAL
type: abstract-op
text: IsResizableArrayBuffer; url: sec-isresizablearraybuffer
</pre>
<pre class=biblio>
{
"PROPOSAL-FLOAT16ARRAY": {
"publisher": "Ecma",
"href": "https://tc39.es/proposal-float16array/",
"title": "Proposal to add float16 TypedArrays to JavaScript"
}
}
</pre>
<style>
pre.set {
font-size: 80%;
}
.syntax .n,
.syntax .nv {
font-style: italic;
}
.mute,
.deprecated,
.deprecated a,
.deprecated code {
color: #9D937D;
}
.deprecated a:visited,
.deprecated a {
border-bottom-color: #9D937D;
}
emu-const {
font-family: sans-serif;
}
emu-val {
font-weight: bold;
}
emu-nt {
font-family: sans-serif;
font-style: italic;
white-space: nowrap;
}
emu-t {
font-family: Menlo, Consolas, "DejaVu Sans Mono", Monaco, monospace;
font-weight: bold;
white-space: nowrap;
}
emu-t.regex {
font-family: sans-serif;
font-weight: bold;
}
emu-t a[href],
emu-nt a[href] {
color: inherit;
border-bottom: 1px solid transparent;
}
emu-t a[href]:focus,
emu-nt a[href]:focus,
emu-t a[href]:hover,
emu-nt a[href]:hover {
background: #f8f8f8;
background: rgba(75%, 75%, 75%, .25);
border-bottom: 3px solid #707070;
margin-bottom: -2px;
}
/* start bug fix, see: https://github.com/tobie/webidl/issues/24 */
pre.grammar {
padding-bottom: 1px
}
/* end bug fix */
dt p {
display: inline;
}
#distinguishable-table {
font-size: 80%;
border-collapse: collapse;
width: auto;
}
#distinguishable-table th {
text-align: right;
}
#distinguishable-table thead th {
white-space: nowrap;
text-align: left;
border: none;
height: 100px;
padding: 0;
}
#distinguishable-table .belowdiagonal {
background: #ddd;
}
#distinguishable-table td {
text-align: center;
padding: 5px 10px;
width: 30px;
min-width: 30px;
padding: 10px 5px;
height: 19px
}
/* Firefox needs the extra DIV for some reason, otherwise the text disappears if you rotate */
#distinguishable-table tr:first-child th div {
transform: translate(27px, 64px) rotate(315deg);
width: 30px;
}
#distinguishable-table thead th div span {
border-bottom: 1px solid #ccc;
padding: 5px 10px;
display: block;
min-width: 120px;
text-align: left
}
#distinguishable-table thead th:last-child div span {
border-bottom: none;
}
</style>
<h2 id="introduction">Introduction</h2>
<i>This section is informative.</i>
This standard defines an interface definition language, Web IDL, that can be used to describe
interfaces that are intended to be implemented in web browsers. Web IDL is an IDL variant with a
number of features that allow the behavior of common script objects in the web platform to be
specified more readily. How interfaces described with Web IDL correspond to constructs within
JavaScript execution environments is also detailed here.
Concretely, Web IDL provides a syntax for specifying the surface APIs of web platform objects, as
well as JavaScript bindings that detail how those APIs manifest as JavaScript constructs. This
ensures common tasks, such as installing global properties, processing numeric inputs, or exposing
iteration behavior, remain uniform across web platform specifications: such specifications describe
their interfaces using Web IDL, and then use prose to specify API-specific details.
<p class="note">The term "JavaScript" is used to refer to ECMA-262, rather than the official term ECMAScript, since the term JavaScript is more widely known.</p>
<h2 id="idl">Interface definition language</h2>
This section describes a language, <em>Web IDL</em>, which can be used to define
interfaces for APIs in the Web platform. A specification that defines Web APIs
can include one or more <dfn id="dfn-idl-fragment" export lt="IDL fragment">IDL fragments</dfn> that
describe the interfaces (the state and behavior that objects can exhibit)
for the APIs defined by that specification.
An [=IDL fragment=] is
a sequence of definitions that matches the <emu-nt><a href="#prod-Definitions">Definitions</a></emu-nt> grammar symbol.
The set of [=IDL fragments=] that
an implementation supports is not ordered.
See [[#idl-grammar]] for the complete grammar and an explanation of the notation used.
The different kinds of <dfn id="dfn-definition">definitions</dfn> that can appear in an
[=IDL fragment=] are:
[=interfaces=],
[=partial interface|partial interface definitions=],
[=interface mixins=],
[=partial interface mixin|partial mixin definitions=],
[=callback functions=],
[=callback interfaces=],
[=namespaces=],
[=partial namespace|partial namespace definitions=],
[=dictionary|dictionaries=],
[=partial dictionary|partial dictionary definitions=],
[=typedefs=] and
[=includes statements=].
These are all defined in the following sections.
Each [=definition=]
(matching <emu-nt><a href="#prod-Definition">Definition</a></emu-nt>)
can be preceded by a list of [=extended attributes=] (matching
<emu-nt><a href="#prod-ExtendedAttributeList">ExtendedAttributeList</a></emu-nt>),
which can control how the definition will be handled in language bindings.
The extended attributes defined by this specification that are language binding
agnostic are discussed in [[#idl-extended-attributes]],
while those specific to the JavaScript language binding are discussed
in [[#js-extended-attributes]].
<pre highlight="webidl" class="syntax">
[<mark>extended_attributes</mark>]
interface identifier {
/* interface_members... */
};
</pre>
<pre class="grammar" id="prod-Definitions">
Definitions :
ExtendedAttributeList Definition Definitions
ε
</pre>
<pre class="grammar" id="prod-Definition">
Definition :
CallbackOrInterfaceOrMixin
Namespace
Partial
Dictionary
Enum
Typedef
IncludesStatement
</pre>
<div class="example" id="example-25f60a7c">
The following is an example of an [=IDL fragment=].
<pre highlight="webidl">
[Exposed=Window]
interface Paint { };
[Exposed=Window]
interface SolidColor : Paint {
attribute double red;
attribute double green;
attribute double blue;
};
[Exposed=Window]
interface Pattern : Paint {
attribute DOMString imageURL;
};
[Exposed=Window]
interface GraphicalWindow {
constructor();
readonly attribute unsigned long width;
readonly attribute unsigned long height;
attribute Paint currentPaint;
undefined drawRectangle(double x, double y, double width, double height);
undefined drawText(double x, double y, DOMString text);
};
</pre>
Here, four [=interfaces=]
are being defined.
The <code class="idl">GraphicalWindow</code> interface has two
[=read only=] [=attributes=],
one writable attribute, and two [=operations=]
defined on it. Objects that implement the <code class="idl">GraphicalWindow</code> interface
will expose these attributes and operations in a manner appropriate to the
particular language being used.
In JavaScript, the attributes on the IDL interfaces will be exposed as accessor
properties and the operations as data properties whose value is a [=built-in function object=] on a
prototype object for all <code class="idl">GraphicalWindow</code>
objects; each JavaScript object that implements <code class="idl">GraphicalWindow</code>
will have that prototype object in its prototype chain.
The [=constructor operation=] that appears on <code class="idl">GraphicalWindow</code>
causes a [=constructor=] to exist in JavaScript implementations,
so that calling <code>new GraphicalWindow()</code> would return a new object
that implemented the interface.
All [=interfaces=] have the [{{Exposed}}] [=extended attribute=], which ensures the interfaces
are only available in [=realms=] whose [=realm/global object=] is a {{Window}} object.
</div>
<h3 id="idl-names">Names</h3>
Every [=interface=],
[=partial interface|partial interface definition=],
[=namespace=],
[=partial namespace|partial namespace definition=],
[=dictionary=],
[=partial dictionary|partial dictionary definition=],
[=enumeration=],
[=callback function=],
[=callback interface=] and
[=typedef=] (together called <dfn id="dfn-named-definition" export lt="named definition">named definitions</dfn>)
and every [=constant=],
[=attribute=],
and [=dictionary member=] has an
<dfn id="dfn-identifier" export>identifier</dfn>, as do some
[=operations=].
The identifier is determined by an
<emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t> token somewhere
in the declaration:
* For [=named definitions=],
the <emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t> token that appears
directly after the <emu-t>interface</emu-t>, <emu-t>namespace</emu-t>,
<emu-t>dictionary</emu-t>, <emu-t>enum</emu-t>
or <emu-t>callback</emu-t> keyword
determines the identifier of that definition.
<pre highlight="webidl" class="syntax">
interface <mark>interface_identifier</mark> { /* interface_members... */ };
partial interface <mark>interface_identifier</mark> { /* interface_members... */ };
namespace <mark>namespace_identifier</mark> { /* namespace_members... */ };
partial namespace <mark>namespace_identifier</mark> { /* namespace_members... */ };
dictionary <mark>dictionary_identifier</mark> { /* dictionary_members... */ };
partial dictionary <mark>dictionary_identifier</mark> { /* dictionary_members... */ };
enum <mark>enumeration_identifier</mark> { "enum", "values" /* , ... */ };
callback <mark>callback_identifier</mark> = return_type (/* arguments... */);
callback interface <mark>callback_interface_identifier</mark> { /* interface_members... */ };
</pre>
* For [=attributes=],
[=typedefs=]
and [=dictionary members=],
the final <emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t> token before the
semicolon at the end of the declaration determines the identifier.
<pre highlight="webidl" class="syntax">
[extended_attributes]
interface identifier {
attribute type <mark>attribute_identifier</mark>;
};
typedef type <mark>typedef_identifier</mark>;
dictionary identifier {
type <mark>dictionary_member_identifier</mark>;
};
</pre>
* For [=constants=],
the <emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t> token before the
equals sign determines the identifier.
<pre highlight="webidl" class="syntax">const type <mark>constant_identifier</mark> = 42;</pre>
* For [=operations=], the
<emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t> token that appears
after the return type but before the opening parenthesis (that is,
one that is matched as part of the <emu-nt><a href="#prod-OptionalOperationName">OptionalOperationName</a></emu-nt>
grammar symbol in an <emu-nt><a href="#prod-OperationRest">OperationRest</a></emu-nt>) determines the identifier of the operation. If
there is no such <emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t> token,
then the operation does not have an identifier.
<pre highlight="webidl" class="syntax">
interface interface_identifier {
return_type <mark>operation_identifier</mark>(/* arguments... */);
};
</pre>
Note: Operations can have no identifier when they are being used to declare a
[=special operation|special kind of operation=], such as a getter or setter.
For all of these constructs, the [=identifier=]
is the value of the <emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t> token with any leading
U+005F (_) removed.
Note: A leading U+005F (_) is used to escape an identifier from looking
like a reserved word so that, for example, an interface named "<code>interface</code>" can be
defined. The leading U+005F (_) is dropped to unescape the
identifier.
Operation arguments can take a slightly wider set of identifiers. In an operation
declaration, the identifier of an argument is specified immediately after its
type and is given by either an <emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t>
token or by one of the keywords that match the <emu-nt><a href="#prod-ArgumentNameKeyword">ArgumentNameKeyword</a></emu-nt>
symbol. If one of these keywords is used, it need not be escaped with a leading
underscore.
<pre highlight="webidl" class="syntax">
interface interface_identifier {
return_type operation_identifier(argument_type <mark>argument_identifier</mark> /* , ... */);
};
</pre>
<pre class="grammar" id="prod-ArgumentNameKeyword">
ArgumentNameKeyword :
"async"
"attribute"
"callback"
"const"
"constructor"
"deleter"
"dictionary"
"enum"
"getter"
"includes"
"inherit"
"interface"
"iterable"
"maplike"
"mixin"
"namespace"
"partial"
"readonly"
"required"
"setlike"
"setter"
"static"
"stringifier"
"typedef"
"unrestricted"
</pre>
If an <emu-t class="regex"><a href="#prod-identifier">identifier</a></emu-t> token is used, then the
[=identifier=] of the operation argument
is the value of that token with any leading
U+005F (_) removed.
If instead one of the <emu-nt><a href="#prod-ArgumentNameKeyword">ArgumentNameKeyword</a></emu-nt>
keyword token is used, then the [=identifier=] of the operation argument
is simply that token.
The [=identifier=] of any of the abovementioned
IDL constructs (except operation arguments) must not be "<code>constructor</code>",
"<code>toString</code>",
or begin with a U+005F (_). These
are known as <dfn id="dfn-reserved-identifier" export>reserved identifiers</dfn>.
Although the "<code>toJSON</code>" [=identifier=] is not a [=reserved identifier=],
it must only be used for [=regular operations=]
that convert objects to [=JSON types=],
as described in [[#idl-tojson-operation]].
Note: Further restrictions on identifier names for particular constructs can be made
in later sections.
Within the set of [=IDL fragments=]
that a given implementation supports,
the [=identifier=] of every
[=interface=],
[=namespace=],
[=dictionary=],
[=enumeration=],
[=callback function=],
[=callback interface=] and
[=typedef=]
must not
be the same as the identifier of any other
[=interface=],
[=namespace=],
[=dictionary=],
[=enumeration=],
[=callback function=],
[=callback interface=] or
[=typedef=].
Within an [=IDL fragment=], a reference
to a [=definition=] need not appear after
the declaration of the referenced definition. References can also be made
across [=IDL fragments=].
<div class="example" id="example-679e8e2c">
Therefore, the following [=IDL fragment=] is valid:
<pre highlight="webidl">
[Exposed=Window]
interface B : A {
undefined f(SequenceOfLongs x);
};
[Exposed=Window]
interface A {
};
typedef sequence<long> SequenceOfLongs;
</pre>
</div>
<div class="example" id="example-1192ff1f">
The following [=IDL fragment=]
demonstrates how [=identifiers=]
are given to definitions and [=interface members=].
<pre highlight="webidl">
// Typedef identifier: "number"
typedef double number;
// Interface identifier: "System"
[Exposed=Window]
interface System {
// Operation identifier: "createObject"
// Operation argument identifier: "interface"
object createObject(DOMString _interface);
// Operation argument identifier: "interface"
sequence<object> getObjects(DOMString interface);
// Operation has no identifier; it declares a getter.
getter DOMString (DOMString keyName);
};
// Interface identifier: "TextField"
[Exposed=Window]
interface TextField {
// Attribute identifier: "const"
attribute boolean _const;
// Attribute identifier: "value"
attribute DOMString? _value;
};
</pre>
Note that while the second [=attribute=]
on the <code class="idl">TextField</code> [=interface=]
need not have been escaped with an underscore (because "<code>value</code>" is
not a keyword in the IDL grammar), it is still unescaped
to obtain the attribute's [=identifier=].
</div>
<h3 id="idl-interfaces">Interfaces</h3>
[=IDL fragments=] are used to
describe object oriented systems. In such systems, objects are entities
that have identity and which are encapsulations of state and behavior.
An <dfn id="dfn-interface" export>interface</dfn> is a definition (matching
<emu-t>interface</emu-t> <emu-nt><a href="#prod-InterfaceRest">InterfaceRest</a></emu-nt>) that declares some
state and behavior that an object implementing that interface will expose.
<pre highlight="webidl" class="syntax">
[extended_attributes]
interface identifier {
/* interface_members... */
};
</pre>
An interface is a specification of a set of
<dfn id="dfn-interface-member" export lt="interface member">interface members</dfn>
(matching <emu-nt><a href="#prod-InterfaceMembers">InterfaceMembers</a></emu-nt>).
These are the [=members=] that appear between the braces in the interface declaration.
Interfaces in Web IDL describe how objects that implement the
interface behave. In bindings for object oriented languages, it is
expected that an object that implements a particular IDL interface
provides ways to inspect and modify the object's state and to
invoke the behavior described by the interface.
An interface can be defined to <dfn id="dfn-inherit" for="interface" export>inherit</dfn> from another interface.
If the identifier of the interface is followed by a
U+003A (:)
and an [=identifier=],
then that identifier identifies the inherited interface.
An object that implements an interface that inherits from another
also implements that inherited interface. The object therefore will also
have members that correspond to the interface members from the inherited interface.
<pre highlight="webidl" class="syntax">
interface identifier : <mark>identifier_of_inherited_interface</mark> {
/* interface_members... */
};
</pre>
The order that members appear in has significance for property enumeration in the <a href="#js-interfaces">JavaScript binding</a>.
Interfaces may specify an interface member that has the same name as
one from an inherited interface. Objects that implement the derived
interface will expose the member on the derived interface. It is
language binding specific whether the overridden member can be
accessed on the object.
<div class="example" id="example-367b9481">
Consider the following two interfaces.
<pre highlight="webidl">
[Exposed=Window]
interface A {
undefined f();
undefined g();
};
[Exposed=Window]
interface B : A {
undefined f();
undefined g(DOMString x);
};
</pre>
In the JavaScript language binding, an instance of <code class="idl">B</code>
will have a prototype chain that looks like the following:
<pre>
[Object.prototype: the Object prototype object]
↑
[A.prototype: interface prototype object for A]
↑
[B.prototype: interface prototype object for B]
↑
[instanceOfB]
</pre>
Calling <code>instanceOfB.f()</code> in JavaScript will invoke the f defined
on <code class="idl">B</code>. However, the f from <code class="idl">A</code>
can still be invoked on an object that implements <code class="idl">B</code> by
calling <code>A.prototype.f.call(instanceOfB)</code>.
</div>
The <dfn id="dfn-inherited-interfaces" export>inherited interfaces</dfn> of
a given interface |A| is the set of all interfaces that |A|
inherits from, directly or indirectly. If |A| does not [=interface/inherit=]
from another interface, then the set is empty. Otherwise, the set
includes the interface |B| that |A| [=interface/inherits=]
from and all of |B|'s [=inherited interfaces=].
An interface must not be declared such that
its inheritance hierarchy has a cycle. That is, an interface
|A| cannot inherit from itself, nor can it inherit from another
interface |B| that inherits from |A|, and so on.
<div algorithm>
The [=list=] of <dfn for=interface>inclusive inherited interfaces</dfn> of an [=interface=] |I|
is defined as follows:
1. Let |result| be « ».
1. Let |interface| be |I|.
1. While |interface| is not null:
1. [=list/Append=] |interface| to |result|.
1. Set |interface| to the [=interface=] that |I| [=interface/inherits=] from, if any, and
null otherwise.
1. Return |result|.
</div>
Note that general multiple inheritance of interfaces is not supported, and
objects also cannot implement arbitrary sets of interfaces.
Objects can be defined to implement a single given interface |A|,
which means that it also implements all of |A|'s [=inherited interfaces=].
In addition, an [=includes statement=] can be used
to define that objects implementing an [=interface=] |A|
will always also include the [=interface mixin member|members=]
of the [=interface mixins=] |A| [=includes=].
Each interface member can be preceded by a list of [=extended attributes=] (matching
<emu-nt><a href="#prod-ExtendedAttributeList">ExtendedAttributeList</a></emu-nt>),
which can control how the interface member will be handled in language bindings.
<pre highlight="webidl" class="syntax">
[extended_attributes]
interface identifier {
[<mark>extended_attributes</mark>]
const type constant_identifier = 42;
[<mark>extended_attributes</mark>]
attribute type identifier;
[<mark>extended_attributes</mark>]
return_type identifier(/* arguments... */);
};
</pre>
The IDL for interfaces can be split into multiple parts by using
<dfn id="dfn-partial-interface" export>partial interface</dfn> definitions
(matching <emu-t>partial</emu-t> <emu-t>interface</emu-t>
<emu-nt><a href="#prod-PartialInterfaceRest">PartialInterfaceRest</a></emu-nt>).
The [=identifier=] of a partial
interface definition must be the same
as the identifier of an interface definition. All of
the members that appear on each of the partial interfaces are considered to be
members of the interface itself.
<pre highlight="webidl" class="syntax">
interface <mark>SomeInterface</mark> {
/* interface_members... */
};
partial interface <mark>SomeInterface</mark> {
/* interface_members... */
};
</pre>
Note: Partial interface definitions are intended for use as a specification
editorial aide, allowing the definition of an interface to be separated
over more than one section of the document, and sometimes multiple documents.
The order of appearance of an [=interface=]
definition and any of its [=partial interface=]
definitions does not matter.
Note: A partial interface definition cannot specify that the interface
[=interface/inherits=] from another interface.
Inheritance is to be specified on the original [=interface=]
definition.
The relevant language binding determines how interfaces correspond to constructs
in the language.
The following extended attributes are applicable to interfaces:
[{{CrossOriginIsolated}}],
[{{Exposed}}],
[{{Global}}],
[{{LegacyFactoryFunction}}],
[{{LegacyNoInterfaceObject}}],
[{{LegacyOverrideBuiltIns}}],
[{{LegacyWindowAlias}}], and
[{{SecureContext}}].
The following extended attributes are applicable to [=partial interfaces=]:
[{{CrossOriginIsolated}}],
[{{Exposed}}],
[{{LegacyOverrideBuiltIns}}], and
[{{SecureContext}}].
[=Interfaces=] must be annotated with an [{{Exposed}}] [=extended attribute=].
<div algorithm>
The <dfn>qualified name</dfn> of an [=interface=] |interface| is defined as follows:
1. Let |identifier| be the [=identifier=] of |interface|.
1. If |interface| has a [{{LegacyNamespace}}] [=extended attribute=], then:
1. Let |namespace| be the identifier argument of the [{{LegacyNamespace}}]
[=extended attribute=].
1. Return the [=concatenation=] of « |namespace|, |identifier| » with
separator U+002E (.).
1. Return |identifier|.
</div>
<pre class="grammar" id="prod-CallbackOrInterfaceOrMixin">
CallbackOrInterfaceOrMixin :
"callback" CallbackRestOrInterface
"interface" InterfaceOrMixin
</pre>
<pre class="grammar" id="prod-InterfaceOrMixin">
InterfaceOrMixin :
InterfaceRest
MixinRest
</pre>
<pre class="grammar" id="prod-InterfaceRest">
InterfaceRest :
identifier Inheritance "{" InterfaceMembers "}" ";"
</pre>
<pre class="grammar" id="prod-Partial">
Partial :
"partial" PartialDefinition
</pre>
<pre class="grammar" id="prod-PartialDefinition">
PartialDefinition :
"interface" PartialInterfaceOrPartialMixin
PartialDictionary
Namespace
</pre>
<pre class="grammar" id="prod-PartialInterfaceOrPartialMixin">
PartialInterfaceOrPartialMixin :
PartialInterfaceRest
MixinRest
</pre>
<pre class="grammar" id="prod-PartialInterfaceRest">
PartialInterfaceRest :
identifier "{" PartialInterfaceMembers "}" ";"
</pre>
<pre class="grammar" id="prod-InterfaceMembers">
InterfaceMembers :
ExtendedAttributeList InterfaceMember InterfaceMembers
ε
</pre>
<pre class="grammar" id="prod-InterfaceMember">
InterfaceMember :
PartialInterfaceMember
Constructor
</pre>
<pre class="grammar" id="prod-PartialInterfaceMembers">
PartialInterfaceMembers :
ExtendedAttributeList PartialInterfaceMember PartialInterfaceMembers
ε
</pre>
<pre class="grammar" id="prod-PartialInterfaceMember">
PartialInterfaceMember :
Const
Operation
Stringifier
StaticMember
Iterable
AsyncIterable
ReadOnlyMember
ReadWriteAttribute
ReadWriteMaplike
ReadWriteSetlike
InheritAttribute
</pre>
<pre class="grammar" id="prod-Inheritance">
Inheritance :
":" identifier
ε
</pre>
<div class="example" id="example-0f0ea08a">
The following [=IDL fragment=]
demonstrates the definition of two mutually referential [=interfaces=].
Both <code class="idl">Human</code> and <code class="idl">Dog</code>
inherit from <code class="idl">Animal</code>. Objects that implement
either of those two interfaces will thus have a <code>name</code> attribute.
<pre highlight="webidl">
[Exposed=Window]
interface Animal {
attribute DOMString name;
};
[Exposed=Window]
interface Human : Animal {
attribute Dog? pet;
};
[Exposed=Window]
interface Dog : Animal {
attribute Human? owner;
};
</pre>
</div>
<div class="example" id="example-25ab6a82">
The following [=IDL fragment=] defines
simplified versions of a DOM [=interfaces=]
and a [=callback interface=].
<pre highlight="webidl">
[Exposed=Window]
interface Node {
readonly attribute DOMString nodeName;
readonly attribute Node? parentNode;
Node appendChild(Node newChild);
undefined addEventListener(DOMString type, EventListener listener);
};
callback interface EventListener {
undefined handleEvent(Event event);
};
</pre>
Plain objects can implement a [=callback interface=] like
<code class="idl">EventListener</code>:
<pre highlight="js">
var node = getNode(); // Obtain an instance of Node.
var listener = {
handleEvent: function(event) {
// ...
}
};
node.addEventListener("click", listener); // This works.
node.addEventListener("click", function() { ... }); // As does this.
</pre>
It is not possible for such an object to implement an [=interface=] like
<code class="idl">Node</code>, however:
<pre highlight="js">
var node = getNode(); // Obtain an instance of Node.
var newNode = {
nodeName: "span",
parentNode: null,
appendChild: function(newchild) {
// ...
},
addEventListener: function(type, listener) {
// ...
}
};
node.appendChild(newNode); // This will throw a TypeError exception.
</pre>
</div>
<h3 id="idl-interface-mixins">Interface mixins</h3>
An <dfn export>interface mixin</dfn> is a definition (matching <emu-t>interface</emu-t> <emu-nt><a href="#prod-MixinRest">MixinRest</a></emu-nt>)
that declares state and behavior that can be [=included=] by one or more [=interfaces=],
and that are exposed by objects that implement an [=interface=]
that [=includes=] the [=interface mixin=].
<pre highlight="webidl" class="syntax">
interface mixin identifier {
/* mixin_members... */
};
</pre>
Note: [=Interface mixins=], much like [=partial interfaces=],
are intended for use as a specification editorial aide,
allowing a coherent set of functionalities to be grouped together,
and included in multiple interfaces, possibly across documents.
They are not meant to be exposed through language bindings.
Guidance on when to choose [=partial interfaces=], [=interface mixins=],
or [=partial interface mixins=] can be found in [[#using-mixins-and-partials]].
An [=interface mixin=] is a specification of a set of <dfn export lt="interface mixin member">interface mixin members</dfn>
(matching <emu-nt><a href="#prod-MixinMembers">MixinMembers</a></emu-nt>),
which are the [=constants=], [=regular operations=], [=regular attributes=], and [=stringifiers=]