forked from whatwg/webidl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.bs
13930 lines (11391 loc) · 572 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">
Title: Web IDL
Shortname: WebIDL
Level: 2
Status: ED
Group: webplatform
Mailing list: [email protected]
Mailing List Archives: https://lists.w3.org/Archives/Public/public-script-coord/
Repository: heycam/webidl
!Participate: <a href="https://github.com/heycam/webidl">GitHub</a> (<a href="https://github.com/heycam/webidl/issues/new">new issue</a>, <a href="https://github.com/heycam/webidl/issues">open issues</a>, <a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=WebAppsWG&component=WebIDL&resolution=---">legacy bug tracker</a>)
ED: https://heycam.github.io/webidl/
<!--TR: http://www.w3.org/TR/WebIDL/
Previous Version: http://www.w3.org/TR/2012/CR-WebIDL-20120419/
Previous Version: http://www.w3.org/TR/2012/WD-WebIDL-20120207/
Previous Version: http://www.w3.org/TR/2011/WD-WebIDL-20110927/
Previous Version: http://www.w3.org/TR/2011/WD-WebIDL-20110712/
Previous Version: http://www.w3.org/TR/2010/WD-WebIDL-20101021/
Previous Version: http://www.w3.org/TR/2008/WD-WebIDL-20081219/
Previous Version: http://www.w3.org/TR/2008/WD-WebIDL-20080829/
Previous Version: http://www.w3.org/TR/2008/WD-DOM-Bindings-20080410/
Previous Version: http://www.w3.org/TR/2007/WD-DOM-Bindings-20071017/ -->
Editor: Cameron McCormack, Mozilla Corporation, http://mcc.id.au/, [email protected]
Editor: Boris Zbarsky, Mozilla Corporation, [email protected]
Abstract: This document defines an interface definition language, Web IDL,
Abstract: that can be used to describe interfaces that are intended to be
Abstract: implemented in web browsers. Web IDL is an IDL variant with a
Abstract: number of features that allow the behavior of common script objects in
Abstract: the web platform to be specified more readily. How interfaces
Abstract: described with Web IDL correspond to constructs within ECMAScript
Abstract: execution environments is also detailed in this document.
Abstract: It is expected that this document acts
Abstract: as a guide to implementors of already-published specifications,
Abstract: and that newly published specifications reference this
Abstract: document to ensure conforming implementations of interfaces
Abstract: are interoperable.
Ignored Vars: callback, op, ownDesc, exampleVariableName, target, f, g
Boilerplate: omit issues-index, omit conformance
</pre>
<pre class="anchors">
urlPrefix: http://www.unicode.org/glossary/; spec: UNICODE
type: dfn
text: Unicode scalar value; url: unicode_scalar_value
urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
type: dfn
text: NumericLiteral; url: sec-literals-numeric-literals
text: ECMAScript error objects; url: sec-error-objects
text: ToBoolean; url: sec-toboolean
text: ToNumber; url: sec-tonumber
text: ToUint16; url: sec-touint16
text: ToInt32; url: sec-toint32
text: ToUint32; url: sec-touint32
text: ToString; url: sec-tostring
text: ToObject; url: sec-toobject
text: IsAccessorDescriptor; url: sec-isaccessordescriptor
text: IsDataDescriptor; url: sec-isdatadescriptor
url: sec-ecmascript-data-types-and-values
text: Type
text: Type(x)
url: sec-algorithm-conventions
text: sign
text: floor
text: abs
text: modulo
text: !
text: ?
text: ECMA-262 section 5.2
text: conventions of the ECMAScript specification
text: element; url: sec-ecmascript-language-types-string-type
url: sec-iscallable
text: IsCallable
text: callable
url: sec-well-known-intrinsic-objects
text: %ArrayPrototype%
text: %ArrayProto_values%
text: %MapPrototype%
text: %SetPrototype%
text: %Error%
text: %ErrorPrototype%
text: %ObjProto_toString%
text: %IteratorPrototype%
text: %ObjectPrototype%; url: sec-properties-of-the-object-prototype-object
text: %FunctionPrototype%; url: sec-properties-of-the-function-prototype-object
text: %Promise%; url: sec-promise-constructor
text: Property Descriptor; url: sec-property-descriptor-specification-type
text: array index; url: sec-array-exotic-objects
text: OrdinaryGetOwnProperty; url: sec-ordinarygetownproperty
text: OrdinaryDefineOwnProperty; url: sec-ordinarydefineownproperty
text: default [[Set]] internal method; url: sec-ordinary-object-internal-methods-and-internal-slots-set-p-v-receiver
text: equally close values; url: sec-ecmascript-language-types-number-type
text: internal slot; url: sec-object-internal-methods-and-internal-slots
text: JavaScript execution context stack; url: execution-context-stack
text: running JavaScript execution context; url: running-execution-context
text: ReturnIfAbrupt; url: sec-returnifabrupt
text: GetIterator; url: sec-getiterator
text: IteratorStep; url: sec-iteratorstep
text: NormalCompletion; url: sec-normalcompletion
text: IteratorValue; url: sec-iteratorvalue
url: sec-well-known-symbols
text: @@iterator
text: @@toStringTag
text: CreateArrayIterator; url: sec-createarrayiterator
text: CreateIterResultObject; url: sec-createiterresultobject
text: CreateMapIterator; url: sec-createmapiterator
text: CreateSetIterator; url: sec-createsetiterator
text: ArrayCreate; url: sec-arraycreate
text: CreateDataProperty; url: sec-createdataproperty
text: DetachArrayBuffer; url: sec-detacharraybuffer
text: IsDetachedBuffer; url: sec-isdetachedbuffer
text: SetIntegrityLevel; url: sec-setintegritylevel
url: sec-array-iterator-objects
text: array iterator object
text: array iterator objects
text: Call; url: sec-call
text: Get; url: sec-get-o-p
text: Set; url: sec-set-o-p-v-throw
text: IsConstructor; url: sec-isconstructor
text: Construct; url: sec-construct
text: DefinePropertyOrThrow; url: sec-definepropertyorthrow
url: sec-code-realms
text: Realm
text: ECMAScript global environment
text: Completion; url: sec-completion-record-specification-type
text: ObjectCreate; url: sec-objectcreate
text: CreateBuiltinFunction; url: sec-createbuiltinfunction
text: SetFunctionName; url: sec-setfunctionname
text: immutable prototype exotic object; url: sec-immutable-prototype-exotic-objects
text: sections 9.1; url: sec-ordinary-object-internal-methods-and-internal-slots
text: 9.3.1; url: sec-built-in-function-objects-call-thisargument-argumentslist
text: ECMA-262 section 9.1.8; url: sec-ordinary-object-internal-methods-and-internal-slots-get-p-receiver
text: ECMA-262 section 19.2.2.3; url: sec-function-@@create
text: ECMA-262 section 19.2.3.8; url: sec-function.prototype-@@hasinstance
text: Array methods; url: sec-properties-of-the-array-prototype-object
text: typed arrays; url: sec-typedarray-objects
text: GetMethod; url: sec-getmethod
text: @@unscopables; url: sec-well-known-symbols
urlPrefix: https://html.spec.whatwg.org/multipage/webappapis.html; spec: HTML
type: dfn
text: relevant settings object
text: relevant Realm; url: concept-relevant-realm
text: Prepare to run script
text: Clean up after running script
text: Prepare to run a callback
text: Clean up after running a callback
text: incumbent settings object
text: event handler IDL attributes; url: event-handler-attributes
text: settings object; url: concept-realm-settings-object
</pre>
<style>
pre.set {
font-size: 80%;
}
.syntax .n,
.syntax .nv {
font-style: italic;
}
.mute {
color: #9D937D
}
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;
display: inline-block;
font-weight: bold;
white-space: nowrap;
}
emu-t.symbol {
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;
}
.char {
font-size: 85%
}
#distinguishable-table {
font-size: 80%;
border-collapse: collapse;
}
#distinguishable-table th {
text-align: right;
}
#distinguishable-table tr:first-child th {
white-space: nowrap;
text-align: center;
}
#distinguishable-table .belowdiagonal {
background: #ddd;
}
#distinguishable-table td {
text-align: center;
padding: 5px 10px;
}
.csstransforms #distinguishable-table tr:first-child th {
text-align: left;
border: none;
height: 100px;
padding: 0;
}
.csstransforms #distinguishable-table td {
text-align: center;
width: 30px;
padding: 10px 5px;
height: 19px
}
/* Firefox needs the extra DIV for some reason, otherwise the text disappears if you rotate */
.csstransforms #distinguishable-table tr:first-child th div {
-webkit-transform: translate(26px, 31px) rotate(315deg);
transform: translate(26px, 31px) rotate(315deg);
width: 30px;
}
.csstransforms #distinguishable-table tr:first-child th div span {
border-bottom: 1px solid #ccc;
padding: 5px 10px;
display: block;
min-width: 120px;
text-align: left
}
.csstransforms #distinguishable-table tr:first-child th:last-child div span {
border-bottom: none;
}
</style>
<h2 id="introduction">Introduction</h2>
<i>This section is informative.</i>
Technical reports published by the W3C that include programming
language interfaces have typically been described using the
Object Management Group’s Interface Definition Language (IDL)
[[OMGIDL]]. The IDL provides a means to
describe these interfaces in a language independent manner. Usually,
additional language binding appendices are included in such
documents which detail how the interfaces described with the IDL
correspond to constructs in the given language.
However, the bindings in these specifications for the language most
commonly used on the web, ECMAScript, are consistently specified with
low enough precision as to result in interoperability issues. In
addition, each specification must describe the same basic information,
such as DOM interfaces described in IDL corresponding to properties
on the ECMAScript global object, or the {{unsigned long}} IDL type mapping to the <emu-val>Number</emu-val>
type in ECMAScript.
This specification defines an IDL language similar to OMG IDL
for use by specifications that define interfaces for Web APIs. A number of extensions are
given to the IDL to support common functionality that previously must
have been written in prose. In addition, precise language bindings
for ECMAScript Edition 6 are given.
<h3 id="conventions">Typographic conventions</h3>
The following typographic conventions are used in this document:
* Defining instances of terms: <dfn id="dfn-example-term">example term</dfn>
* Links to terms defined in this document or elsewhere: [=example term=]
* Grammar terminals: <emu-t>sometoken</emu-t>
* Grammar non-terminals: <emu-nt>ExampleGrammarNonTerminal</emu-t>
* Grammar symbols: <emu-t class="symbol">identifier</emu-t>
* IDL and ECMAScript types: <code class="idl">ExampleType</code>
* Code snippets: <code>a = b + obj.f()</code>
* Unicode characters: <span class="char">U+0030 DIGIT ZERO ("0")</span>
* Extended attributes: [<code class="idl">ExampleExtendedAttribute</code>]
* Variable names in prose and algorithms: |exampleVariableName|.
* Algorithms use the [=conventions of the ECMAScript specification=],
including the ! and ? notation for unwrapping completion records.
* IDL informal syntax examples:
<pre highlight="webidl" class="syntax">
interface identifier {
<mark>/* interface_members... */</mark>
};
</pre>
(Specific parts of the syntax discussed in surrounding prose are <mark>highlighted</mark>.)
* IDL grammar snippets:
<pre class="grammar no-index">
ExampleGrammarNonTerminal :
OtherNonTerminal "sometoken"
other AnotherNonTerminal
ε // nothing
</pre>
* Non-normative notes:
Note: This is a note.
* Non-normative examples:
<div class="example">
This is an example.
</div>
* Normative warnings:
<p class="advisement">
This is a warning.
</p>
* Code blocks:
<pre highlight="webidl">
// This is an IDL code block.
interface Example {
attribute long something;
};
</pre>
<pre highlight="js">
// This is an ECMAScript code block.
window.onload = function() { window.alert("loaded"); };
</pre>
<h2 id="conformance">Conformance</h2>
Everything in this specification is normative except for diagrams,
examples, notes and sections marked as being informative.
The keywords “must”,
“must not”,
“required”,
“shall”,
“shall not”,
“should”,
“should not”,
“recommended”,
“may” and
“optional” in this document are to be
interpreted as described in
<cite><a href="http://tools.ietf.org/html/rfc2119">Key words for use in RFCs to
Indicate Requirement Levels</a></cite>
[[!RFC2119]].
The following conformance classes are defined by this specification:
: <dfn id="dfn-conforming-set-of-idl-fragments" export>conforming set of IDL fragments</dfn>
:: A set of [=IDL fragments=] is considered
to be a [=conforming set of IDL fragments=] if, taken together, they satisfy all of the
must-,
required- and shall-level
criteria in this specification that apply to IDL fragments.
: <dfn id="dfn-conforming-implementation" export>conforming implementation</dfn>
:: A user agent is considered to be a
[=conforming implementation=]
relative to a [=conforming set of IDL fragments=] if it satisfies all of the must-,
required- and shall-level
criteria in this specification that apply to implementations for all language
bindings that the user agent supports.
: <dfn id="dfn-conforming-ecmascript-implementation" export>conforming ECMAScript implementation</dfn>
:: A user agent is considered to be a
[=conforming ECMAScript implementation=]
relative to a [=conforming set of IDL fragments=] if it satisfies all of the must-,
required- and shall-level
criteria in this specification that apply to implementations for the ECMAScript
language binding.
<h3 id="conformant-algorithms">Conformant Algorithms</h3>
Requirements phrased in the imperative as part of algorithms (such as
“strip any leading space characters” or “return false and abort these
steps”) are to be interpreted with the meaning of the key word (“must”,
“should”, “may”, etc) used in introducing the algorithm.
Conformance requirements phrased as algorithms or specific steps can be
implemented in any manner, so long as the end result is <dfn lt="processing equivalence" id="dfn-processing-equivalence">equivalent</dfn>. In
particular, the algorithms defined in this specification are intended to
be easy to understand and are not intended to be performant. Implementers
are encouraged to optimize.
<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=],
[=namespaces=],
[=partial namespace|partial namespace definitions=],
[=dictionary|dictionaries=],
[=partial dictionary|partial dictionary definitions=],
[=typedefs=] and
[=implements 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 ECMAScript language binding are discussed
in [[#es-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 :
CallbackOrInterface
Namespace
Partial
Dictionary
Enum
Typedef
ImplementsStatement
</pre>
<pre class="grammar" id="prod-CallbackOrInterface">
CallbackOrInterface :
"callback" CallbackRestOrInterface
Interface
</pre>
<div class="example">
The following is an example of an [=IDL fragment=].
<pre highlight="webidl">
interface Paint { };
interface SolidColor : Paint {
attribute double red;
attribute double green;
attribute double blue;
};
interface Pattern : Paint {
attribute DOMString imageURL;
};
[Constructor]
interface GraphicalWindow {
readonly attribute unsigned long width;
readonly attribute unsigned long height;
attribute Paint currentPaint;
void drawRectangle(double x, double y, double width, double height);
void 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 ECMAScript, the attributes on the IDL interfaces will be exposed as accessor
properties and the operations as <emu-val>Function</emu-val>-valued
data properties on a prototype object for all <code class="idl">GraphicalWindow</code>
objects; each ECMAScript object that implements <code class="idl">GraphicalWindow</code>
will have that prototype object in its prototype chain.
The [{{Constructor}}] that appears on <code class="idl">GraphicalWindow</code>
is an [=extended attribute=].
This extended attribute causes a constructor to exist in ECMAScript implementations,
so that calling <code>new GraphicalWindow()</code> would return a new object
that implemented the interface.
</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=] 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="symbol"><a href="#prod-identifier">identifier</a></emu-t> token somewhere
in the declaration:
* For [=named definitions=],
the <emu-t class="symbol"><a href="#prod-identifier">identifier</a></emu-t> token that appears
directly after the <code>interface</code>, <code>namespace</code>,
<code>dictionary</code>, <code>enum</code>
or <code>callback</code> 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... */);
</pre>
* For [=attributes=],
[=typedefs=]
and [=dictionary members=],
the final <emu-t class="symbol"><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">
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="symbol"><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="symbol"><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-OptionalIdentifier">OptionalIdentifier</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="symbol"><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="symbol"><a href="#prod-identifier">identifier</a></emu-t> token with any leading
<span class="char">U+005F LOW LINE ("_")</span> character (underscore) removed.
Note: A leading <span class="char">"_"</span> is used to escape an identifier from looking
like a reserved word so that, for example, an interface named “interface” can be
defined. The leading <span class="char">"_"</span> 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="symbol"><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 :
"attribute"
"callback"
"const"
"deleter"
"dictionary"
"enum"
"getter"
"implements"
"inherit"
"interface"
"iterable"
"legacycaller"
"maplike"
"namespace"
"partial"
"required"
"serializer"
"setlike"
"setter"
"static"
"stringifier"
"typedef"
"unrestricted"
</pre>
If an <emu-t class="symbol"><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
<span class="char">U+005F LOW LINE ("_")</span> character (underscore) 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 must not be “constructor”,
“toString”, “toJSON”,
or begin with a <span class="char">U+005F LOW LINE ("_")</span> character. These
are known as <dfn id="dfn-reserved-identifier" export>reserved identifiers</dfn>.
Note: Further restrictions on identifier names for particular constructs may 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=] and
[=typedef=]
must not
be the same as the identifier of any other
[=interface=],
[=namespace=],
[=dictionary=],
[=enumeration=],
[=callback function=] 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">
Therefore, the following [=IDL fragment=] is valid:
<pre highlight="webidl">
interface B : A {
void f(SequenceOfLongs x);
};
interface A {
};
typedef sequence<long> SequenceOfLongs;
</pre>
</div>
<div class="example">
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"
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"
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 “value” 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-nt><a href="#prod-Interface">Interface</a></emu-nt> or
<emu-t>callback</emu-t> <emu-nt><a href="#prod-Interface">Interface</a></emu-nt>) that declares some
state and behavior that an object implementing that interface will expose.
<pre highlight="webidl" class="syntax">
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>),
which are the [=constants=],
[=attributes=],
[=operations=] and
other declarations that appear between the braces in the interface declaration.
Attributes describe the state that an object
implementing the interface will expose, and operations describe the
behaviors that can be invoked on the object. Constants declare
named constant values that are exposed as a convenience to users
of objects in the system.
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
<span class="char">U+003A COLON (":")</span> character
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="#es-interfaces">ECMAScript 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">
Consider the following two interfaces.
<pre highlight="webidl">
interface A {
void f();
void g();
};
interface B : A {
void f();
void g(DOMString x);
};
</pre>
In the ECMAScript 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 ECMAScript 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.
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 <a href="#idl-implements-statements">implements statement</a> can be
used to define that objects implementing an interface will always
also implement another interface.
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">
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>
A <dfn id="dfn-callback-interface" export>callback interface</dfn> is
an [=interface=]
that uses the <code>callback</code> keyword at the start of
its definition. Callback interfaces are ones that can be
implemented by [=user objects=]
and not by [=platform objects=],
as described in [[#idl-objects]].
<pre highlight="webidl" class="syntax">
callback interface identifier {
/* interface_members... */
};
</pre>
Note: See also the similarly named [=callback function=] definition.
[=Callback interfaces=]
must not [=interface/inherit=]
from any non-callback interfaces, and non-callback interfaces must not
inherit from any callback interfaces.
Callback interfaces must not have any
[=consequential interfaces=].
[=Static attributes=] and
[=static operations=] must not
be defined on a [=callback interface=].
<div class="advisement">
Specification authors should not define
[=callback interfaces=]
that have only a single [=operation=],
unless required to describe the requirements of existing APIs.
Instead, a [=callback function=] should be used.
The definition of <code class="idl">EventListener</code> as a
[=callback interface=]
is an example of an existing API that needs to allow
[=user objects=] with a
given property (in this case “handleEvent”) to be considered to implement the interface.
For new APIs, and those for which there are no compatibility concerns,
using a [=callback function=] will allow
only a <emu-val>Function</emu-val> object (in the ECMAScript
language binding).
</div>
<p class="issue">
Perhaps this warning shouldn't apply if you are planning to extend the callback
interface in the future. That's probably a good reason to start off with a single
operation callback interface.
</p>
<p class="issue">
I think we need to support operations not being implemented on a given
user object implementing a callback interface. If specs extending an existing
callback interface, we probably want to be able to avoid calling the
operations that aren't implemented (and having some default behavior instead).
So we should perhaps define a term that means whether the operation is
implemented, which in the ECMAScript binding would correspond to checking
for the property's existence.
</p>
<div class="note">
Specification authors wanting to define APIs that take ECMAScript objects
as “property bag” like function arguments are suggested to use
<a href="#idl-dictionaries">dictionary types</a> rather than
[=callback interfaces=].
For example, instead of this:
<pre highlight="webidl">
callback interface Options {
attribute DOMString? option1;
attribute DOMString? option2;
attribute long? option3;
};
interface A {
void doTask(DOMString type, Options options);
};
</pre>
to be used like this:
<pre highlight="js">
var a = getA(); // Get an instance of A.
a.doTask("something", { option1: "banana", option3: 100 });
</pre>
instead write the following:
<pre highlight="webidl">
dictionary Options {
DOMString? option1;
DOMString? option2;
long? option3;
};
interface A {
void doTask(DOMString type, Options options);
};
</pre>
</div>
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-nt><a href="#prod-PartialInterface">PartialInterface</a></emu-nt>).
The [=identifier=] of a partial
interface definition must be the same