forked from whatwg/webidl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v1.html
13720 lines (13042 loc) · 876 KB
/
v1.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
index.html
Web IDL
Note: This file is generated from index.xml. Run "make" to regenerate it.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Web IDL</title>
<link rel="stylesheet" href="WebIDL.css" type="text/css" />
<script src="section-links.js" type="application/ecmascript"></script>
<script src="dfn.js" type="application/ecmascript"></script>
<link rel="stylesheet" href="http://www.w3.org/StyleSheets/TR/W3C-ED" type="text/css" /></head>
<body>
<div class="head"><div><a href="http://www.w3.org/"><img src="http://www.w3.org/Icons/w3c_home" width="72" height="48" alt="W3C" /></a></div><h1>Web IDL</h1><h2>W3C Editor’s Draft <em>13 December 2013</em></h2><dl><dt>This Version:</dt><dd><a href="http://heycam.github.io/webidl/v1.html">http://heycam.github.io/webidl/v1.html</a></dd><dt>Latest Version:</dt><dd><a href="http://www.w3.org/TR/WebIDL/">http://www.w3.org/TR/WebIDL/</a></dd><dt>Previous Versions:</dt><dd><a href="http://www.w3.org/TR/2012/CR-WebIDL-20120419/">http://www.w3.org/TR/2012/CR-WebIDL-20120419/</a></dd><dd><a href="http://www.w3.org/TR/2012/WD-WebIDL-20120207/">http://www.w3.org/TR/2012/WD-WebIDL-20120207/</a></dd><dd><a href="http://www.w3.org/TR/2011/WD-WebIDL-20110927/">http://www.w3.org/TR/2011/WD-WebIDL-20110927/</a></dd><dd><a href="http://www.w3.org/TR/2011/WD-WebIDL-20110712/">http://www.w3.org/TR/2011/WD-WebIDL-20110712/</a></dd><dd><a href="http://www.w3.org/TR/2010/WD-WebIDL-20101021/">http://www.w3.org/TR/2010/WD-WebIDL-20101021/</a></dd><dd><a href="http://www.w3.org/TR/2008/WD-WebIDL-20081219/">http://www.w3.org/TR/2008/WD-WebIDL-20081219/</a></dd><dd><a href="http://www.w3.org/TR/2008/WD-WebIDL-20080829/">http://www.w3.org/TR/2008/WD-WebIDL-20080829/</a></dd><dd><a href="http://www.w3.org/TR/2008/WD-DOM-Bindings-20080410/">http://www.w3.org/TR/2008/WD-DOM-Bindings-20080410/</a></dd><dd><a href="http://www.w3.org/TR/2007/WD-DOM-Bindings-20071017/">http://www.w3.org/TR/2007/WD-DOM-Bindings-20071017/</a></dd><dt>Participate:</dt><dd>
Send feedback to <a href="mailto:[email protected]">[email protected]</a> or <a href="https://www.w3.org/Bugs/Public/enter_bug.cgi?product=WebAppsWG&component=WebIDL">file a bug</a> (<a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=WebAppsWG&component=WebIDL&resolution=---">open bugs</a>)
</dd><dt>Editor:</dt><dd><a href="http://mcc.id.au/">Cameron McCormack</a>, Mozilla Corporation <[email protected]></dd></dl><p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2013 <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>, <a href="http://ev.buaa.edu.cn/">Beihang</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.</p></div><hr /><script async="" src="file-bug.js"></script>
<!--
<div id='publication-warning'>
<strong>This document is in the process of being prepared to be published as a Candidate Recommendation.
Please note that it as yet has not been published as a CR and that this document
at dev.w3.org is still to be considered an unofficial draft.</strong> <br/> <button onclick="document.body.removeChild(this.parentNode)">Dismiss</button>
</div>
-->
<div class="section">
<h2>Abstract</h2>
<p>
This document 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 ECMAScript
execution environments is also detailed in this document.
It is expected that this document acts
as a guide to implementors of already-published specifications,
and that newly published specifications reference this
document to ensure conforming implementations of interfaces
are interoperable.
</p>
<!-- XXX
Things to consider that aren't in ednotes:
* Consistent linking to term definitions.
* Consistent capitalisation and naming of algorithm variables.
Potential V2 features:
* Parameterized interface types, for BlahLists
http://www.w3.org/mid/[email protected]
-->
<!--
<?revision-note http://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=&product=WebAppsWG&component=WebIDL&longdesc_type=allwordssubstr&longdesc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&status_whiteboard_type=allwordssubstr&status_whiteboard=&keywords_type=allwords&keywords=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailtype1=substring&email1=&emailtype2=substring&email2=&bug_id_type=anyexact&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Importance&field0-0-0=noop&type0-0-0=noop&value0-0-0=?>
-->
</div>
<div class="section">
<h2 id="sotd">Status of This Document</h2>
<p><em>
This section describes the status of this document at the time of
its publication. Other documents may supersede this document. A list
of current W3C publications and the latest revision of this technical
report can be found in the <a href="http://www.w3.org/TR/">W3C technical
reports index</a> at http://www.w3.org/TR/.
</em></p><p>
This document is the 13 December 2013 <b>Editor’s Draft</b> of the
<cite>Web IDL</cite> specification.
Please send comments about this document to
<a href="mailto:[email protected]">[email protected]</a>
(<a href="http://lists.w3.org/Archives/Public/public-script-coord/">archived</a>).
</p>
<p>
This document will remain a Candidate Recommendation until at least 19 July 2012. See the
<a href="#cr-exit">Candidate Recommendation exit criteria</a> section
for details on the criteria that must be met before this document can
progress to the Proposed Recommendation stage, and for the features that
are considered <em>at risk</em> and which may be dropped from the
specification without the document returning to a Last Call Working Draft.
As yet there is no implementation report available.
</p>
<!--
<p>
The following features are considered <em>at risk</em>, and may be removed in
a future publication of this document if they remain unsued by Web specification
authors:
</p>
<ul>
<li>The <span class='idltype'>unrestricted float</span> and <span class='idltype'>unrestricted double</span> types.</li>
<li><a class='dfnref' href='#dfn-optional-argument-default-value'>Default values</a> for optional arguments.</li>
<li>The <a class='xattr' href='#ArrayClass'>[ArrayClass]</a>, <a class='xattr' href='#Clamp'>[Clamp]</a>, <a class='xattr' href='#EnforceRange'>[EnforceRange]</a> and <a class='xattr' href='#ImplicitThis'>[ImplicitThis]</a> extended attributes.</li>
</ul>
-->
<p>
This document is produced by the
<a href="http://www.w3.org/2008/webapps/">Web Applications Working Group</a>, part of the
<a href="http://www.w3.org/2006/rwc/Activity">Rich Web Clients Activity</a>
in the W3C <a href="http://www.w3.org/Interaction/">Interaction Domain</a>.
Changes made to this document can be found in the specification’s
<a href="https://github.com/heycam/webidl/commits/gh-pages/v1.xml">commit
log on GitHub</a>.
</p>
<p>
<!--In addition to the issues marked by editorial notes in this document,-->
There is a <a href="https://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=&product=WebAppsWG&component=WebIDL&longdesc_type=allwordssubstr&longdesc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&status_whiteboard_type=allwordssubstr&status_whiteboard=&keywords_type=allwords&keywords=&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailtype1=substring&email1=&emailtype2=substring&email2=&bug_id_type=anyexact&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse%20same%20sort%20as%20last%20time&field0-0-0=noop&type0-0-0=noop&value0-0-0=">bug tracker</a>
for the specification. Issues raised during the three Last Call comment periods
are tracked in the following documents:
</p>
<dl>
<dt><a href="http://www.w3.org/TR/2011/WD-WebIDL-20110712/">12 July 2011 Last Call Working Draft</a></dt>
<dd><a href="http://heycam.github.io/webidl/lc1.txt">Web IDL LC#1 comment document</a></dd>
<dt><a href="http://www.w3.org/TR/2011/WD-WebIDL-20110927/">27 September 2011 Last call Working Draft</a></dt>
<dd><a href="http://heycam.github.io/webidl/lc2.txt">Web IDL LC#2 comment document</a></dd>
<dt><a href="http://www.w3.org/TR/2012/WD-WebIDL-20120207/">7 February 2012 Last Call Working Draft</a></dt>
<dd><a href="http://heycam.github.io/webidl/lc3.txt">Web IDL LC#3 comment document</a></dd>
</dl>
<p>
Publication as an Editor’s Draft does not imply endorsement by the
W3C Membership. This is a draft document and may be updated, replaced
or obsoleted by other documents at any time. It is inappropriate to cite
this document as other than work in progress.
</p><p>
This document was produced by a group operating under the
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
2004 W3C Patent Policy</a>. W3C maintains a
<a href="http://www.w3.org/2004/01/pp-impl/42538/status">public list of
any patent disclosures</a> made in connection with the deliverables of
the group; that page also includes instructions for disclosing a patent.
An individual who has actual knowledge of a patent which the individual
believes contains
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</a>.
</p>
</div>
<div id="toc">
<h2>Table of Contents</h2>
<div class="toc"><ul><li><a href="#introduction">1. Introduction</a><ul><li><a href="#conventions">1.1. Typographic conventions</a></li></ul></li><li><a href="#conformance">2. Conformance</a></li><li><a href="#idl">3. Interface definition language</a><ul><li><a href="#idl-names">3.1. Names</a></li><li><a href="#idl-interfaces">3.2. Interfaces</a><ul><li><a href="#idl-constants">3.2.1. Constants</a></li><li><a href="#idl-attributes">3.2.2. Attributes</a></li><li><a href="#idl-operations">3.2.3. Operations</a></li><li><a href="#idl-special-operations">3.2.4. Special operations</a><ul><li><a href="#idl-legacy-callers">3.2.4.1. Legacy callers</a></li><li><a href="#idl-stringifiers">3.2.4.2. Stringifiers</a></li><li><a href="#idl-indexed-properties">3.2.4.3. Indexed properties</a></li><li><a href="#idl-named-properties">3.2.4.4. Named properties</a></li></ul></li><li><a href="#idl-static-operations">3.2.5. Static operations</a></li><li><a href="#idl-overloading">3.2.6. Overloading</a></li></ul></li><li><a href="#idl-dictionaries">3.3. Dictionaries</a></li><li><a href="#idl-exceptions">3.4. Exceptions</a></li><li><a href="#idl-enums">3.5. Enumerations</a></li><li><a href="#idl-callback-functions">3.6. Callback functions</a></li><li><a href="#idl-typedefs">3.7. Typedefs</a></li><li><a href="#idl-implements-statements">3.8. Implements statements</a></li><li><a href="#idl-objects">3.9. Objects implementing interfaces</a></li><li><a href="#idl-types">3.10. Types</a><ul><li><a href="#idl-any">3.10.1. any</a></li><li><a href="#idl-boolean">3.10.2. boolean</a></li><li><a href="#idl-byte">3.10.3. byte</a></li><li><a href="#idl-octet">3.10.4. octet</a></li><li><a href="#idl-short">3.10.5. short</a></li><li><a href="#idl-unsigned-short">3.10.6. unsigned short</a></li><li><a href="#idl-long">3.10.7. long</a></li><li><a href="#idl-unsigned-long">3.10.8. unsigned long</a></li><li><a href="#idl-long-long">3.10.9. long long</a></li><li><a href="#idl-unsigned-long-long">3.10.10. unsigned long long</a></li><li><a href="#idl-float">3.10.11. float</a></li><li><a href="#idl-unrestricted-float">3.10.12. unrestricted float</a></li><li><a href="#idl-double">3.10.13. double</a></li><li><a href="#idl-unrestricted-double">3.10.14. unrestricted double</a></li><li><a href="#idl-DOMString">3.10.15. DOMString</a></li><li><a href="#idl-object">3.10.16. object</a></li><li><a href="#idl-interface">3.10.17. Interface types</a></li><li><a href="#idl-dictionary">3.10.18. Dictionary types</a></li><li><a href="#idl-enumeration">3.10.19. Enumeration types</a></li><li><a href="#idl-callback-function">3.10.20. Callback function types</a></li><li><a href="#idl-nullable-type">3.10.21. Nullable types — <var>T</var>?</a></li><li><a href="#idl-sequence">3.10.22. Sequences — sequence<<var>T</var>></a></li><li><a href="#idl-array">3.10.23. Arrays — <var>T</var>[]</a></li><li><a href="#idl-union">3.10.24. Union types</a></li><li><a href="#idl-Date">3.10.25. Date</a></li></ul></li><li><a href="#idl-extended-attributes">3.11. Extended attributes</a></li></ul></li><li><a href="#ecmascript-binding">4. ECMAScript binding</a><ul><li><a href="#es-environment">4.1. ECMAScript environment</a></li><li><a href="#es-type-mapping">4.2. ECMAScript type mapping</a><ul><li><a href="#es-any">4.2.1. any</a></li><li><a href="#es-void">4.2.2. void</a></li><li><a href="#es-boolean">4.2.3. boolean</a></li><li><a href="#es-byte">4.2.4. byte</a></li><li><a href="#es-octet">4.2.5. octet</a></li><li><a href="#es-short">4.2.6. short</a></li><li><a href="#es-unsigned-short">4.2.7. unsigned short</a></li><li><a href="#es-long">4.2.8. long</a></li><li><a href="#es-unsigned-long">4.2.9. unsigned long</a></li><li><a href="#es-long-long">4.2.10. long long</a></li><li><a href="#es-unsigned-long-long">4.2.11. unsigned long long</a></li><li><a href="#es-float">4.2.12. float</a></li><li><a href="#es-unrestricted-float">4.2.13. unrestricted float</a></li><li><a href="#es-double">4.2.14. double</a></li><li><a href="#es-unrestricted-double">4.2.15. unrestricted double</a></li><li><a href="#es-DOMString">4.2.16. DOMString</a></li><li><a href="#es-object">4.2.17. object</a></li><li><a href="#es-interface">4.2.18. Interface types</a></li><li><a href="#es-dictionary">4.2.19. Dictionary types</a></li><li><a href="#es-enumeration">4.2.20. Enumeration types</a></li><li><a href="#es-callback-function">4.2.21. Callback function types</a></li><li><a href="#es-nullable-type">4.2.22. Nullable types — <var>T</var>?</a></li><li><a href="#es-sequence">4.2.23. Sequences — sequence<<var>T</var>></a></li><li><a href="#es-array">4.2.24. Arrays — <var>T</var>[]</a><ul><li><a href="#platform-array-object-getownproperty">4.2.24.1. Platform array object [[GetOwnProperty]] method</a></li><li><a href="#platform-array-object-defineownproperty">4.2.24.2. Platform array object [[DefineOwnProperty]] method</a></li><li><a href="#platform-array-object-delete">4.2.24.3. Platform array object [[Delete]] method</a></li></ul></li><li><a href="#es-union">4.2.25. Union types</a></li><li><a href="#es-Date">4.2.26. Date</a></li></ul></li><li><a href="#es-extended-attributes">4.3. ECMAScript-specific extended attributes</a><ul><li><a href="#ArrayClass">4.3.1. [ArrayClass]</a></li><li><a href="#Clamp">4.3.2. [Clamp]</a></li><li><a href="#Constructor">4.3.3. [Constructor]</a></li><li><a href="#EnforceRange">4.3.4. [EnforceRange]</a></li><li><a href="#Global">4.3.5. [Global]</a></li><li><a href="#ImplicitThis">4.3.6. [ImplicitThis]</a></li><li><a href="#LenientThis">4.3.7. [LenientThis]</a></li><li><a href="#NamedConstructor">4.3.8. [NamedConstructor]</a></li><li><a href="#NoInterfaceObject">4.3.9. [NoInterfaceObject]</a></li><li><a href="#OverrideBuiltins">4.3.10. [OverrideBuiltins]</a></li><li><a href="#PutForwards">4.3.11. [PutForwards]</a></li><li><a href="#Replaceable">4.3.12. [Replaceable]</a></li><li><a href="#TreatNonCallableAsNull">4.3.13. [TreatNonCallableAsNull]</a></li><li><a href="#TreatNullAs">4.3.14. [TreatNullAs]</a></li><li><a href="#TreatUndefinedAs">4.3.15. [TreatUndefinedAs]</a></li><li><a href="#Unforgeable">4.3.16. [Unforgeable]</a></li></ul></li><li><a href="#es-security">4.4. Security</a></li><li><a href="#es-interfaces">4.5. Interfaces</a><ul><li><a href="#interface-object">4.5.1. Interface object</a><ul><li><a href="#es-interface-call">4.5.1.1. Interface object [[Call]] method</a></li><li><a href="#es-interface-hasinstance">4.5.1.2. Interface object [[HasInstance]] method</a></li></ul></li><li><a href="#named-constructors">4.5.2. Named constructors</a></li><li><a href="#interface-prototype-object">4.5.3. Interface prototype object</a></li><li><a href="#named-properties-object">4.5.4. Named properties object</a><ul><li><a href="#named-properties-object-getownproperty">4.5.4.1. Named properties object [[GetOwnProperty]] method</a></li><li><a href="#named-properties-object-defineownproperty">4.5.4.2. Named properties object [[DefineOwnProperty]] method</a></li><li><a href="#named-properties-object-delete">4.5.4.3. Named properties object [[Delete]] method</a></li></ul></li><li><a href="#es-constants">4.5.5. Constants</a></li><li><a href="#es-attributes">4.5.6. Attributes</a></li><li><a href="#es-operations">4.5.7. Operations</a></li></ul></li><li><a href="#es-implements-statements">4.6. Implements statements</a></li><li><a href="#es-platform-objects">4.7. Platform objects implementing interfaces</a><ul><li><a href="#indexed-and-named-properties">4.7.1. Indexed and named properties</a></li><li><a href="#getownproperty">4.7.2. Platform object [[GetOwnProperty]] method</a></li><li><a href="#defineownproperty">4.7.3. Platform object [[DefineOwnProperty]] method</a></li><li><a href="#delete">4.7.4. Platform object [[Delete]] method</a></li><li><a href="#call">4.7.5. Platform object [[Call]] method</a></li><li><a href="#property-enumeration">4.7.6. Property enumeration</a></li></ul></li><li><a href="#es-user-objects">4.8. User objects implementing callback interfaces</a></li><li><a href="#es-invoking-callback-functions">4.9. Invoking callback functions</a></li><li><a href="#es-exceptions">4.10. Exceptions</a><ul><li><a href="#es-exception-interface-object">4.10.1. Exception interface object</a><ul><li><a href="#es-exception-call">4.10.1.1. Exception interface object [[Call]] method</a></li></ul></li><li><a href="#es-exception-interface-prototype-object">4.10.2. Exception interface prototype object</a></li><li><a href="#es-exception-constants">4.10.3. Constants</a></li><li><a href="#es-exception-fields">4.10.4. Exception fields</a></li></ul></li><li><a href="#es-exception-objects">4.11. Exception objects</a></li><li><a href="#es-throwing-exceptions">4.12. Throwing exceptions</a></li><li><a href="#es-handling-exceptions">4.13. Handling exceptions</a></li></ul></li><li><a href="#common">5. Common definitions</a><ul><li><a href="#common-DOMTimeStamp">5.1. DOMTimeStamp</a></li><li><a href="#common-Function">5.2. Function</a></li><li><a href="#common-VoidFunction">5.3. VoidFunction</a></li></ul></li><li><a href="#extensibility">6. Extensibility</a></li><li><a href="#referencing">7. Referencing this specification</a></li><li><a href="#acknowledgements">8. Acknowledgements</a></li></ul><ul><li><a href="#idl-grammar">A. IDL grammar</a></li><li><a href="#references">B. References</a><ul><li><a href="#normative-references">B.1. Normative references</a></li><li><a href="#informative-references">B.2. Informative references</a></li></ul></li><li><a href="#cr-exit">C. Candidate Recommendation exit criteria</a></li><li><a href="#changes">D. Changes</a></li></ul></div>
</div>
<div id="sections">
<div id="introduction" class="section">
<h2>1. Introduction</h2>
<p class="norm">This section is informative.</p>
<p>
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)
<a href="#ref-OMGIDL">[OMGIDL]</a>. 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.
</p>
<p>
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 <a class="idltype" href="#idl-unsigned-long">unsigned
long</a> IDL type mapping to the <span class="estype">Number</span>
type in ECMAScript.
</p>
<p>
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 5.1 are given.
</p>
<div id="conventions" class="section">
<h3>1.1. Typographic conventions</h3>
<p>
The following typographic conventions are used in this document:
</p>
<ul>
<li>Defining instances of terms: <dfn id="dfn-example-term">example term</dfn></li>
<li>Links to terms defined in this document: <a class="dfnref" href="#dfn-example-term">example term</a></li>
<li>Links to terms defined in other documents: <a class="dfnref external" href="#dfn-example-term">example term</a></li>
<li>Grammar symbols: <span class="sym">ExampleGrammarSymbol</span></li>
<li>IDL and ECMAScript types: <span class="idltype">ExampleType</span></li>
<li>Code snippets: <code>a = b + obj.f()</code></li>
<li>Unicode characters: <span class="char">U+0030 DIGIT ZERO ("0")</span></li>
<li>Extended attributes: <span class="xattr">[ExampleExtendedAttribute]</span></li>
<li>Variable names in prose and algorithms: <var>exampleVariableName</var>.</li>
<li>IDL informal syntax examples:
<pre class="syntax">interface <i>identifier</i> {
<em>interface-members…</em>
};</pre>
(Red text is used to highlight specific parts of the syntax discussed in surrounding prose.)</li>
<li>IDL grammar snippets:
<table class="grammar">
<tr><td><span class="prod-number">[5]</span></td><td><span class="sym">ExampleGrammarSymbol</span></td><td class="prod-mid">→</td><td><span class="prod-lines">OtherSymbol "sometoken"<br /> | AnotherSymbol<br /> | ε <span class="comment">// nothing</span></span></td></tr>
</table>
(Each grammar rule is assigned a number for reference, shown on the left.)</li>
<li>Non-normative notes: <div class="note"><div class="noteHeader">Note</div><p>This is a note.</p></div></li>
<li>Non-normative examples: <div class="example"><div class="exampleHeader">Example</div><p>This is an example.</p></div></li>
<li>Normative warnings: <div class="warning"><div class="warningHeader">Warning</div><p>This is a warning.</p></div></li>
<li>Code blocks: <div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code"><span class="comment">// This is an IDL code block.</span>
interface Example {
attribute long something;
};</code></pre></div></div>
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code"><span class="comment">// This is an ECMAScript code block.</span>
window.onload = function() { window.alert("loaded"); };</code></pre></div></div></li>
</ul>
</div>
</div>
<div id="conformance" class="section">
<h2>2. Conformance</h2>
<p>
Everything in this specification is normative except for diagrams,
examples, notes and sections marked as being informative.
</p>
<p>
The keywords “<span class="rfc2119">MUST</span>”,
“<span class="rfc2119">MUST NOT</span>”,
“<span class="rfc2119">REQUIRED</span>”,
“<span class="rfc2119">SHALL</span>”,
“<span class="rfc2119">SHALL NOT</span>”,
“<span class="rfc2119">SHOULD</span>”,
“<span class="rfc2119">SHOULD NOT</span>”,
“<span class="rfc2119">RECOMMENDED</span>”,
“<span class="rfc2119">MAY</span>” and
“<span class="rfc2119">OPTIONAL</span>” 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>
<a href="#ref-RFC2119">[RFC2119]</a>.
</p>
<p>
The following conformance classes are defined by this specification:
</p>
<dl>
<dt><dfn id="dfn-conforming-idl-fragment">conforming IDL fragment</dfn></dt>
<dd>
<p>
An <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> is considered
to be a <a class="dfnref" href="#dfn-conforming-idl-fragment">conforming
IDL fragment</a> if it satisfies all of the
<span class="rfc2119">MUST</span>-,
<span class="rfc2119">REQUIRED</span>- and <span class="rfc2119">SHALL</span>-level
criteria in this specification that apply to IDL fragments.
</p>
</dd>
<dt><dfn id="dfn-conforming-implementation">conforming implementation</dfn></dt>
<dd>
<p>
A user agent is considered to be a
<a class="dfnref" href="#dfn-conforming-implementation">conforming implementation</a>
relative to a <a class="dfnref" href="#dfn-conforming-idl-fragment">conforming
IDL fragment</a> if it satisfies all of the <span class="rfc2119">MUST</span>-,
<span class="rfc2119">REQUIRED</span>- and <span class="rfc2119">SHALL</span>-level
criteria in this specification that apply to implementations for all language
bindings that the user agent supports.
</p>
</dd>
<dt><dfn id="dfn-conforming-ecmascript-implementation">conforming ECMAScript implementation</dfn></dt>
<dd>
<p>
A user agent is considered to be a
<a class="dfnref" href="#dfn-conforming-ecmascript-implementation">conforming ECMAScript implementation</a>
relative to a <a class="dfnref" href="#dfn-conforming-idl-fragment">conforming
IDL fragment</a> if it satisfies all of the <span class="rfc2119">MUST</span>-,
<span class="rfc2119">REQUIRED</span>- and <span class="rfc2119">SHALL</span>-level
criteria in this specification that apply to implementations for the ECMAScript
language binding.
</p>
</dd>
</dl>
</div>
<div id="idl" class="section">
<h2>3. Interface definition language</h2>
<p>
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">IDL fragments</dfn> that
describe the interfaces (the state and behavior that objects can exhibit)
for the APIs defined by that specification.
An <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> is
a sequence of definitions that matches the <a class="sym" href="#prod-Definitions">Definitions</a> grammar symbol.
The set of <a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a> that
an implementation supports is not ordered.
See <a href="#idl-grammar">Appendix A</a> for the complete grammar and an explanation of the notation used.
</p>
<p>
The different kinds of <dfn id="dfn-definition">definitions</dfn> that can appear in an
<a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> are:
<a class="dfnref" href="#dfn-interface">interfaces</a>,
<a class="dfnref" href="#dfn-partial-interface">partial interface definitions</a>,
<a class="dfnref" href="#dfn-dictionary">dictionaries</a>,
<a class="dfnref" href="#dfn-partial-dictionary">partial dictionary definitions</a>,
<a class="dfnref" href="#dfn-exception">exceptions</a>,
<a class="dfnref" href="#dfn-typedef">typedefs</a> and
<a class="dfnref" href="#dfn-implements-statement">implements statements</a>.
These are all defined in the following sections.
</p>
<p>
Each <a class="dfnref" href="#dfn-definition">definition</a>
(matching <a class="sym" href="#prod-Definition">Definition</a>)
can be preceded by a list of <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a> (matching
<a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a>),
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 <a href="#idl-extended-attributes">section 3.11</a>,
while those specific to the ECMAScript language binding are discussed
in <a href="#es-extended-attributes">section 4.3</a>.
</p>
<pre class="syntax">[<em>extended-attributes</em>]
interface <i>identifier</i> {
<i>interface-members…</i>
};</pre>
<table class="grammar"><tr id="proddef-Definitions"><td><span class="prod-number">[1]</span></td><td><a class="sym" href="#prod-Definitions">Definitions</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a> <a class="sym" href="#prod-Definition">Definition</a> <a class="sym" href="#prod-Definitions">Definitions</a> <br /> |
ε</span></td></tr><tr id="proddef-Definition"><td><span class="prod-number">[2]</span></td><td><a class="sym" href="#prod-Definition">Definition</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-CallbackOrInterface">CallbackOrInterface</a> <br /> |
<a class="sym" href="#prod-Partial">Partial</a> <br /> |
<a class="sym" href="#prod-Dictionary">Dictionary</a> <br /> |
<a class="sym" href="#prod-Exception">Exception</a> <br /> |
<a class="sym" href="#prod-Enum">Enum</a> <br /> |
<a class="sym" href="#prod-Typedef">Typedef</a> <br /> |
<a class="sym" href="#prod-ImplementsStatement">ImplementsStatement</a></span></td></tr><tr id="proddef-CallbackOrInterface"><td><span class="prod-number">[3]</span></td><td><a class="sym" href="#prod-CallbackOrInterface">CallbackOrInterface</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"callback" <a class="sym" href="#prod-CallbackRestOrInterface">CallbackRestOrInterface</a> <br /> |
<a class="sym" href="#prod-Interface">Interface</a></span></td></tr></table>
<div class="example"><div class="exampleHeader">Example</div>
<p>
The following is an example of an <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>.
</p>
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">exception GraphicsException {
DOMString reason;
};
interface Paint { };
interface SolidColor : Paint {
attribute float red;
attribute float green;
attribute float 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(float x, float y, float width, float height)<!--
raises(GraphicsException)-->;
void drawText(float x, float y, DOMString text)<!--
raises(GraphicsException)-->;
};</code></pre></div></div>
<p>
Here, four <a class="dfnref" href="#dfn-interface">interfaces</a> and one
<a class="dfnref" href="#dfn-exception">exception</a> are being defined.
The <span class="idltype">GraphicalWindow</span> interface has two
<a class="dfnref" href="#dfn-read-only">read only</a> <a class="dfnref" href="#dfn-attribute">attributes</a>,
one writable attribute, and two <a class="dfnref" href="#dfn-operation">operations</a>
defined on it. Objects that implement the <span class="idltype">GraphicalWindow</span> interface
will expose these attributes and operations in a manner appropriate to the
particular language being used.
</p>
<p>
In ECMAScript, the attributes on the IDL interfaces will be exposed as accessor
properties and the operations as <span class="estype">Function</span>-valued
data properties on a prototype object for all <span class="idltype">GraphicalWindow</span>
objects; each ECMAScript object that implements <span class="idltype">GraphicalWindow</span>
will have that prototype object in its prototype chain.
</p>
<!--JAVA
<p>
In Java, there will exist a Java interface that corresponds to the IDL
<span class='idltype'>GraphicalWindow</span> interface. This Java interface
will have methods that correspond to the operations, and getter and setter
methods that correspond to the attributes. Java objects that are considered
to implement the IDL <span class='idltype'>GraphicalWindow</span> interface
will implement the corresponding Java interface.
</p>
-->
<p>
The <a class="xattr" href="#Constructor">[Constructor]</a> that appears on <span class="idltype">GraphicalWindow</span>
is an <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.
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. <!--JAVA The <a class='xattr' href='#Constructor'>[Constructor]</a>
extended attribute has no effect in the Java language binding, however.-->
</p>
</div>
<div id="idl-names" class="section">
<h3>3.1. Names</h3>
<p>
Every <a class="dfnref" href="#dfn-interface">interface</a>,
<a class="dfnref" href="#dfn-partial-interface">partial interface definition</a>,
<a class="dfnref" href="#dfn-dictionary">dictionary</a>,
<a class="dfnref" href="#dfn-partial-dictionary">partial dictionary definition</a>,
<a class="dfnref" href="#dfn-exception">exception</a>,
<a class="dfnref" href="#dfn-enumeration">enumeration</a>,
<a class="dfnref" href="#dfn-callback-function">callback function</a> and
<a class="dfnref" href="#dfn-typedef">typedef</a> (together called <dfn id="dfn-named-definition">named definitions</dfn>)
and every <a class="dfnref" href="#dfn-constant">constant</a>,
<a class="dfnref" href="#dfn-attribute">attribute</a>,
<a class="dfnref" href="#dfn-exception-field">exception field</a>
and <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> has an
<dfn id="dfn-identifier">identifier</dfn>, as do some
<a class="dfnref" href="#dfn-operation">operations</a>.
The identifier is determined by an
<a class="sym" href="#prod-identifier">identifier</a> token somewhere
in the declaration:
</p>
<ul>
<li>
For <a class="dfnref" href="#dfn-named-definition">named definitions</a>,
the <a class="sym" href="#prod-identifier">identifier</a> token that appears
directly after the <code>interface</code>,
<code>dictionary</code>, <code>exception</code>, <code>enum</code>
or <code>callback</code> keyword
determines the identifier of that definition.
<pre class="syntax">interface <em>interface-identifier</em> { <i>interface-members…</i> };
partial interface <em>interface-identifier</em> { <i>interface-members…</i> };
exception <em>exception-identifier</em> { <i>exception-members…</i> };
dictionary <em>dictionary-identifier</em> { <i>dictionary-members…</i> };
partial dictionary <em>dictionary-identifier</em> { <i>dictionary-members…</i> };
enum <em>enumeration-identifier</em> { <i>enumeration-values…</i> };
callback <em>callback-identifier</em> = <i>callback-signature</i>;</pre>
</li>
<li>
For <a class="dfnref" href="#dfn-attribute">attributes</a>,
<a class="dfnref" href="#dfn-typedef">typedefs</a>, <a class="dfnref" href="#dfn-exception-field">exception fields</a>
and <a class="dfnref" href="#dfn-dictionary-member">dictionary members</a>,
the final <a class="sym" href="#prod-identifier">identifier</a> token before the
semicolon at the end of the declaration determines the identifier.
<pre class="syntax">interface <i>identifier</i> {
attribute <i>type</i> <em>attribute-identifier</em>;
};
typedef <i>type</i> <em>typedef-identifier</em>;
exception <i>identifier</i> {
<i>type</i> <em>exception-member-identifier</em>;
};
dictionary <i>identifier</i> {
<i>type</i> <em>dictionary-member-identifier</em>;
};</pre>
</li>
<li>
For <a class="dfnref" href="#dfn-constant">constants</a>,
the <a class="sym" href="#prod-identifier">identifier</a> token before the
equals sign determines the identifier.
<pre class="syntax">const <i>type</i> <em>constant-identifier</em> = <i>value</i>;</pre>
</li>
<li>
For <a class="dfnref" href="#dfn-operation">operations</a>, the
<a class="sym" href="#prod-identifier">identifier</a> token that appears
after the return type but before the opening parenthesis (that is,
one that is matched as part of the <a class="sym" href="#prod-OptionalIdentifier">OptionalIdentifier</a>
grammar symbol in an <a class="sym" href="#prod-Operation">Operation</a>) determines the identifier of the operation. If
there is no such <a class="sym" href="#prod-identifier">identifier</a> token,
then the operation does not have an identifier.
<pre class="syntax"><i>return-type</i> <em>operation-identifier</em>(<i>arguments…</i>);</pre>
</li>
</ul>
<div class="note"><div class="noteHeader">Note</div>
<p>
Operations can have no identifier when they are being used to declare a
<a href="#idl-special-operations">special kind of operation</a>, such as a getter or setter.
</p>
</div>
<p>
For all of these constructs, the <a class="dfnref" href="#dfn-identifier">identifier</a>
is the value of the <a class="sym" href="#prod-identifier">identifier</a> token with any leading
<span class="char">U+005F LOW LINE ("_")</span> character (underscore) removed.
</p>
<div class="note"><div class="noteHeader">Note</div>
<p>
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.
</p>
</div>
<p>
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 <a class="sym" href="#prod-identifier">identifier</a>
token or by one of the keywords that match the <a class="sym" href="#prod-ArgumentNameKeyword">ArgumentNameKeyword</a>
symbol. If one of these keywords is used, it need not be escaped with a leading
underscore.
</p>
<pre class="syntax"><i>return-type</i> <i>operation-identifier</i>(<i>argument-type</i> <em>argument-identifier</em>, …);</pre>
<table class="grammar"><tr id="proddef-ArgumentNameKeyword"><td><span class="prod-number">[56]</span></td><td><a class="sym" href="#prod-ArgumentNameKeyword">ArgumentNameKeyword</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">
"attribute" <br /> |
"callback" <br /> |
"const" <br /> |
"creator" <br /> |
"deleter" <br /> |
"dictionary"
<br /> |
"enum" <br /> |
"exception" <br /> |
"getter" <br /> |
"implements" <br /> |
"inherit" <br /> |
"interface"
<br /> |
"legacycaller" <br /> |
"partial" <br /> |
"setter" <br /> |
"static" <br /> |
"stringifier" <br /> |
"typedef"
<br /> |
"unrestricted"
</span></td></tr></table>
<p>
If an <a class="sym" href="#prod-identifier">identifier</a> token is used, then the
<a class="dfnref" href="#dfn-identifier">identifier</a> 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 <a class="sym" href="#prod-ArgumentNameKeyword">ArgumentNameKeyword</a>
keyword token is used, then the <a class="dfnref" href="#dfn-identifier">identifier</a> of the operation argument
is simply that token.
</p>
<p>
The <a class="dfnref" href="#dfn-identifier">identifier</a> of any of the abovementioned
IDL constructs <a class="rfc2119">MUST NOT</a> be “constructor”, “toString”
or begin with a <span class="char">U+005F LOW LINE ("_")</span> character. These
are known as <dfn id="dfn-reserved-identifier">reserved identifiers</dfn>.
</p>
<div class="note"><div class="noteHeader">Note</div>
<p>Further restrictions on identifier names for particular constructs may be made
in later sections.</p>
</div>
<p>
Within the set of <a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a>
that a given implementation supports,
the <a class="dfnref" href="#dfn-identifier">identifier</a> of every
<a class="dfnref" href="#dfn-interface">interface</a>,
<a class="dfnref" href="#dfn-dictionary">dictionary</a>,
<a class="dfnref" href="#dfn-exception">exception</a>,
<a class="dfnref" href="#dfn-enumeration">enumeration</a>,
<a class="dfnref" href="#dfn-callback-function">callback function</a> and
<a class="dfnref" href="#dfn-typedef">typedef</a>
<span class="rfc2119">MUST NOT</span>
be the same as the identifier of any other
<a class="dfnref" href="#dfn-interface">interface</a>,
<a class="dfnref" href="#dfn-dictionary">dictionary</a>,
<a class="dfnref" href="#dfn-exception">exception</a>,
<a class="dfnref" href="#dfn-enumeration">enumeration</a>,
<a class="dfnref" href="#dfn-callback-function">callback function</a> or
<a class="dfnref" href="#dfn-typedef">typedef</a>.
</p>
<p>
Within an <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>, a reference
to a <a class="dfnref" href="#dfn-definition">definition</a> need not appear after
the declaration of the referenced definition. References can also be made
across <a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a>.
</p>
<div class="example"><div class="exampleHeader">Example</div>
<p>Therefore, the following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> is valid:</p>
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface B : A {
void f(ArrayOfLongs x);
};
interface A {
};
typedef long[] ArrayOfLongs;</code></pre></div></div>
</div>
<div class="example"><div class="exampleHeader">Example</div>
<p>
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
demonstrates how <a class="dfnref" href="#dfn-identifier">identifiers</a>
are given to definitions, <a class="dfnref" href="#dfn-interface-member">interface members</a>
and <a class="dfnref" href="#dfn-exception-member">exception members</a>.
</p>
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code"><span class="comment">// Typedef identifier: "number"</span>
typedef float number;
<span class="comment">// Exception identifier: "FrameworkException"</span>
exception FrameworkException {
<span class="comment">// Constant identifier: "ERR_NOT_FOUND"</span>
const long ERR_NOT_FOUND = 1;
<span class="comment">// Exception field identifier: "code"</span>
long code;
};
<span class="comment">// Interface identifier: "System"</span>
interface System {
<span class="comment">// Operation identifier: "createObject"</span>
<span class="comment">// Operation argument identifier: "interface"</span>
object createObject(DOMString _interface);
<span class="comment">// Operation argument identifier: "interface"</span>
object[] createObjectArray(DOMString interface);
<span class="comment">// Operation has no identifier; it declares a getter.</span>
getter DOMString (DOMString keyName);
};
<span class="comment">// Interface identifier: "TextField"</span>
interface TextField {
<span class="comment">// Attribute identifier: "const"</span>
attribute boolean _const;
<span class="comment">// Attribute identifier: "value"</span>
attribute DOMString? _value;
};</code></pre></div></div>
<p>
Note that while the second <a class="dfnref" href="#dfn-attribute">attribute</a>
on the <span class="idltype">TextField</span> <a class="dfnref" href="#dfn-interface">interface</a>
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 <a class="dfnref" href="#dfn-identifier">identifier</a>.
</p>
</div>
</div>
<div id="idl-interfaces" class="section">
<h3>3.2. Interfaces</h3>
<p>
<a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a> 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">interface</dfn> is a definition (matching
<a class="sym" href="#prod-Interface">Interface</a> or
<span class="sym">"callback"</span> <a class="sym" href="#prod-Interface">Interface</a>) that declares some
state and behavior that an object implementing that interface will expose.
</p>
<pre class="syntax">interface <i>identifier</i> {
<i>interface-members…</i>
};</pre>
<p>
An interface is a specification of a set of
<dfn id="dfn-interface-member">interface members</dfn>
(matching <a class="sym" href="#prod-InterfaceMembers">InterfaceMembers</a>),
which are the <a class="dfnref" href="#dfn-constant">constants</a>,
<a class="dfnref" href="#dfn-attribute">attributes</a> and
<a class="dfnref" href="#dfn-operation">operations</a>
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.
</p>
<p>
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.
</p>
<!--JAVA
<div class='note'>
<p>
In the Java language binding, for example, this is achieved by having the
object implement a Java interface that has methods for reading and
writing attribute values and to invoke an operation.
</p>
</div>
-->
<p>
An interface can be defined to <dfn id="dfn-inherit">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 <a class="dfnref" href="#dfn-identifier">identifier</a>,
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.
</p>
<pre class="syntax">interface <i>identifier</i> : <em>identifier-of-inherited-interface</em> {
<i>interface-members…</i>
};</pre>
<p>
The order that members appear in has no significance except in the
case of <a href="#idl-overloading">overloading</a>.
</p>
<p>
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.
</p>
<div class="example"><div class="exampleHeader">Example</div>
<p>
Consider the following two interfaces.
</p>
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A {
void f();
void g();
};
interface B : A {
void f();
void g(DOMString x);
};</code></pre></div></div>
<p>
In the ECMAScript language binding, an instance of <span class="idltype">B</span>
will have a prototype chain that looks like the following:
</p>
<pre> [Object.prototype: the Object prototype object]
↑
[A.prototype: interface prototype object for A]
↑
[B.prototype: interface prototype object for B]
↑
[instanceOfB]</pre>
<p>
Calling <code>instanceOfB.f()</code> in ECMAScript will invoke the f defined
on <span class="idltype">B</span>. However, the f from <span class="idltype">A</span>
can still be invoked on an object that implements <span class="idltype">B</span> by
calling <code>A.prototype.f.call(instanceOfB)</code>.
</p>
<!--JAVA
<p>
In the Java language binding, the two IDL interfaces will correspond to
the following Java interfaces:
</p>
<x:codeblock language='java'>public interface A {
void f();
void g();
}
public interface B extends A {
void f();
void g(String x);
}</x:codeblock>
<p>
Calling <code>instanceOfB.f()</code> in Java will invoke
the f defined on <span class='idltype'>B</span>. Due to
the way method overriding is defined in Java, there is no
way to call the f defined on <span class='idltype'>A</span>
on an object that implements <span class='idltype'>B</span>.
Since the signature of g is different in <span class='idltype'>A</span>
and <span class='idltype'>B</span>, however, both can be called
with, for example, <code>instanceOfB.g()</code> and
<code>instanceOfB.g("")</code>.
</p>
<p>
In both languages, the f and g from the derived interface
<span class='idltype'>B</span> are always accessible.
</p>
-->
</div>
<p>
The <dfn id="dfn-inherited-interfaces">inherited interfaces</dfn> of
a given interface <var>A</var> is the set of all interfaces that <var>A</var>
inherits from, directly or indirectly. If <var>A</var> does not <a class="dfnref" href="#dfn-inherit">inherit</a>
from another interface, then the set is empty. Otherwise, the set
includes the interface <var>B</var> that <var>A</var> <a class="dfnref" href="#dfn-inherit-dictionary">inherits</a>
from and all of <var>B</var>’s <a class="dfnref" href="#dfn-inherited-interfaces">inherited interfaces</a>.
</p>
<p>
An interface <span class="rfc2119">MUST NOT</span> be declared such that
its inheritance hierarchy has a cycle. That is, an interface
<var>A</var> cannot inherit from itself, nor can it inherit from another
interface <var>B</var> that inherits from <var>A</var>, and so on.
</p>
<p>
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 <var>A</var>,
which means that it also implements all of <var>A</var>’s
<a class="dfnref" href="#dfn-inherited-interfaces">inherited interfaces</a>. 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.
</p>
<p>
Each interface member can be preceded by a list of <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a> (matching
<a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a>),
which can control how the interface member will be handled in language bindings.
</p>
<pre class="syntax">interface <i>identifier</i> {
[<em>extended-attributes</em>]
const <i>type</i> <i>identifier</i> = <i>value</i>;
[<em>extended-attributes</em>]
attribute <i>type</i> <i>identifier</i>;
[<em>extended-attributes</em>]
<i>return-type</i> <i>identifier</i>(<i>arguments…</i>);
};</pre>
<p>
A <dfn id="dfn-callback-interface">callback interface</dfn> is
an <a class="dfnref" href="#dfn-interface">interface</a>
that uses the <code>callback</code> keyword at the start of
its definition. Callback interfaces are ones that can be
implemented by <a class="dfnref" href="#dfn-user-object">user objects</a>
and not by <a class="dfnref" href="#dfn-platform-object">platform objects</a>,
as described in <a href="#idl-objects">section 3.9</a>
below.
</p>
<pre class="syntax">callback interface <i>identifier</i> {
<i>interface-members…</i>
};</pre>
<div class="note"><div class="noteHeader">Note</div>
<p>See also the similarly named <a class="dfnref" href="#dfn-callback-function">callback function</a> definition.</p>
</div>
<p>
<a class="dfnref" href="#dfn-callback-interface">Callback interfaces</a>
<span class="rfc2119">MUST NOT</span> <a class="dfnref" href="#dfn-inherit">inherit</a>
from any non-callback interfaces, and non-callback interfaces <span class="rfc2119">MUST NOT</span>
inherit from any callback interfaces.
Callback interfaces <span class="rfc2119">MUST NOT</span> have any
have any <a class="dfnref" href="#dfn-consequential-interfaces">consequential interfaces</a>.
</p>
<p>
<a class="dfnref" href="#dfn-static-attribute">Static attributes</a> <span class="rfc2119">MUST NOT</span>
be defined on a <a class="dfnref" href="#dfn-callback-interface">callback interface</a>.
</p>
<div class="warning"><div class="warningHeader">Warning</div>
<p>
Specification authors <span class="rfc2119">SHOULD NOT</span> define
<a class="dfnref" href="#dfn-callback-interface">callback interfaces</a>
that have only a single <a class="dfnref" href="#dfn-operation">operation</a>,
unless required to describe the requirements of existing APIs.
Instead, a <a class="dfnref" href="#dfn-callback-function">callback function</a> <span class="rfc2119">SHOULD</span> used.
</p>
<p>
The definition of <span class="idltype">EventListener</span> as a
<a class="dfnref" href="#dfn-callback-interface">callback interface</a>
is an example of an existing API that needs to allow
<a class="dfnref" href="#dfn-user-object">user objects</a> 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 <a class="dfnref" href="#dfn-callback-function">callback function</a> will allow
only a <span class="estype">Function</span> object (in the ECMAScript
language binding).
</p>
</div>
<div class="note"><div class="noteHeader">Note</div>
<p>
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
<a class="dfnref" href="#dfn-callback-interface">callback interfaces</a>.
</p>
<p>
For example, instead of this:
</p>
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">callback interface Options {
attribute DOMString? option1;
attribute DOMString? option2;
attribute long? option3;
};
interface A {
void doTask(DOMString type, Options options);
};</code></pre></div></div>
<p>
to be used like this:
</p>
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var a = getA(); <span class="comment">// Get an instance of A.</span>
a.doTask("something", { option1: "banana", option3: 100 });</code></pre></div></div>
<p>
instead write the following:
</p>
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">dictionary Options {
DOMString? option1;
DOMString? option2;
long? option3;
};
interface A {
void doTask(DOMString type, Options options);
};</code></pre></div></div>
</div>
<p>
The IDL for interfaces can be split into multiple parts by using
<dfn id="dfn-partial-interface">partial interface</dfn> definitions
(matching <span class="sym">"partial"</span> <a class="sym" href="#prod-PartialInterface">PartialInterface</a>).
The <a class="dfnref" href="#dfn-identifier">identifier</a> of a partial
interface definition <span class="rfc2119">MUST</span> 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.
</p>
<pre class="syntax">interface <em>SomeInterface</em> {
<i>interface-members…</i>
};
partial interface <em>SomeInterface</em> {
<i>interface-members…</i>
};</pre>
<div class="note"><div class="noteHeader">Note</div>
<p>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.</p>
</div>
<p>
The order of appearance of an <a class="dfnref" href="#dfn-interface">interface</a>
definition and any of its <a class="dfnref" href="#dfn-partial-interface">partial interface</a>
definitions does not matter.
</p>
<div class="note"><div class="noteHeader">Note</div>
<p>A partial interface definition cannot specify that the interface
<a class="dfnref" href="#dfn-inherit">inherits</a> from another interface.
Inheritance must be specified on the original <a class="dfnref" href="#dfn-interface">interface</a>
definition.</p>
</div>
<p>
<a class="dfnref" href="#dfn-extended-attribute">Extended attributes</a> can be specified on
<a class="dfnref" href="#dfn-partial-interface">partial interface</a> definitions, with some
limitations. The following extended attributes <span class="rfc2119">MUST NOT</span>
be specified on partial interface definitions:
<a class="xattr" href="#ArrayClass">[ArrayClass]</a>,
<a class="xattr" href="#Constructor">[Constructor]</a>,
<a class="xattr" href="#ImplicitThis">[ImplicitThis]</a>,
<!--JAVA
<a class='xattr' href='#JavaPackage'>[JavaPackage]</a>,
-->
<a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>,
<a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>.
</p>
<div class="note"><div class="noteHeader">Note</div>
<p>The above list of <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
is all of those defined in this document that are applicable to
<a class="dfnref" href="#dfn-interface">interfaces</a> except for
<a class="xattr" href="#Global">[Global]</a>,
<a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a> and
<a class="xattr" href="#Unforgeable">[Unforgeable]</a>.</p>
</div>
<p>
Any <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a> specified
on a <a class="dfnref" href="#dfn-partial-interface">partial interface</a> definition
is considered to appear on the <a class="dfnref" href="#dfn-interface">interface</a>
itself.
</p>
<p>
The relevant language binding determines how interfaces correspond to constructs
in the language.
</p>
<!--
<p>
An <dfn id='dfn-interface-forward-declaration'>interface forward declaration</dfn>
is a definition that matches the <a class='sym' href='#prod-Interface'>Interface</a> non-terminal
whose <a class='sym' href='#prod-InterfaceBody'>InterfaceBody</a> is empty
(that is, <a class='sym' href='#prod-InterfaceBody'>InterfaceBody</a> ⇒ ε). A forward declaration
is used to introduce an interface name to allow for the definition of mutually
recursive interfaces, since scoped names
need to resolve to types that have been
<a class='dfnref' href='#dfn-declared-previously'>declared previously</a>.
</p>
-->
<p>
The following extended attributes are applicable to interfaces:
<a class="xattr" href="#ArrayClass">[ArrayClass]</a>,
<a class="xattr" href="#Constructor">[Constructor]</a>,
<a class="xattr" href="#Global">[Global]</a>,
<a class="xattr" href="#ImplicitThis">[ImplicitThis]</a>,
<!--JAVA
<a class='xattr' href='#JavaPackage'>[JavaPackage]</a>,
-->
<a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>,
<a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>,
<a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a>,