forked from whatwg/dom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverview.src.html
9672 lines (7822 loc) · 422 KB
/
Overview.src.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>
<html lang="en-US">
<head>
<meta charset=UTF-8>
<title>DOM Standard</title>
<style>
@media print {
[data-anolis-spec]::after { content:"[" attr(data-anolis-spec) "]"; font-size:.6em; vertical-align:super; text-transform:uppercase }
}
</style>
<link rel=stylesheet href=http://www.whatwg.org/style/specification>
<link rel=icon href=//resources.whatwg.org/logo-dom.svg>
</head>
<body>
<div class=head>
<p><a class=logo href=//www.whatwg.org/><img alt=WHATWG src=//resources.whatwg.org/logo-dom.svg width=100 height=100></a></p>
<h1>DOM</h1>
<h2 class="no-num no-toc">Living Standard — Last Updated [DATE: 01 Jan 1901]</h2>
<dl>
<dt>This Version:
<dd><a href="http://dom.spec.whatwg.org/">http://dom.spec.whatwg.org/</a>
<dt>Participate:</dt>
<dd class=dontpublish>Send feedback to
<a href="mailto:[email protected]?subject=DOM%3A%20">[email protected]</a> (<a href="http://lists.w3.org/Archives/Public/www-dom/">archives</a>) or
<a href="https://www.w3.org/Bugs/Public/enter_bug.cgi?product=WebAppsWG&component=DOM">file a bug</a>
(<a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=WebAppsWG&component=DOM&resolution=---">open bugs</a>)
<dd class=dontpublish><a href="http://wiki.whatwg.org/wiki/IRC">IRC: #whatwg on Freenode</a>
<dt>Version History:
<dd><a href=https://github.com/whatwg/dom/commits>https://github.com/whatwg/dom/commits</a>
<dd><a href="https://twitter.com/thedomstandard">@thedomstandard</a>
<dt>Editors:
<dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a>
(<a href="http://www.mozilla.org/">Mozilla</a>)
<<a href="mailto:[email protected]">[email protected]</a>>
<dd>Aryeh Gregor
(<a href="http://www.mozilla.org/">Mozilla</a>)
<<a href=mailto:[email protected]>[email protected]</a>>
<dd>Ms2ger
(<a href="http://www.mozilla.org/">Mozilla</a>)
<<a href="mailto:[email protected]">[email protected]</a>>
</dl>
<script src=//resources.whatwg.org/file-bug.js async></script>
<p class=copyright><a rel="license" href="http://creativecommons.org/publicdomain/zero/1.0/"><img src="http://i.creativecommons.org/p/zero/1.0/80x15.png" alt="CC0"></a>
To the extent possible under law, the editors have waived all copyright and
related or neighboring rights to this work. In addition, as of
[DATE: 01 Jan 1901], the editors have made this specification available
under the
<a rel="license"
href="http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0">Open Web Foundation Agreement Version 1.0</a>,
which is available at
http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
</div>
<h2 class="no-num no-toc">Abstract</h2>
<p>DOM defines a platform-neutral model for events, futures, and document nodes.
<h2 class="no-num no-toc">Table of Contents</h2>
<!--toc-->
<h2 class=no-num>Goals</h2>
<p>This specification standardizes the DOM. It does so as follows:</p>
<ol>
<li>
<p>By consolidating <cite>DOM Level 3 Core</cite>
<span data-anolis-ref class=informative>DOM3CORE</span>,
<cite>Element Traversal</cite>
<span data-anolis-ref class=informative>ELEMENTTRAVERSAL</span>, the
"DOM Event Architecture" and "Basic Event Interfaces" chapters of
<cite>DOM Level 3 Events</cite>
<span data-anolis-ref class=informative>DOM3EVENTS</span> (specific type
of events do not belong in the base specification), and
<cite>DOM Level 2 Traversal and Range</cite>
<span data-anolis-ref class=informative>DOM2TR</span>, and:
<ul>
<li>Aligning them with the needs of ECMAScript where possible.
<li>Aligning them with existing implementations.
<li>Simplifying them as much as possible.
</ul>
<li><p>By moving features from HTML5 that ought to be part of the DOM
platform here, while preventing a dependency on HTML5.
<span data-anolis-ref>HTML</span>
<li>
<p>By defining a replacement for the "Mutation Events" and
"Mutation Name Event Types" chapters of <cite>DOM Level 3 Events</cite>
<span data-anolis-ref class=informative>DOM3EVENTS</span> as the old model
was problematic.
<p class=note>The old model is expected to be removed from implementations
in due course.
<li><p>By defining new features that simplify common DOM operations.
</ol>
<h2>Conformance</h2>
<p>All diagrams, examples, and notes in this specification are
non-normative, as are all sections explicitly marked non-normative.
Everything else in this specification is normative.
<p>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in RFC 2119.
For readability, these words do not appear in all uppercase letters in this
specification. <span data-anolis-ref>RFC2119</span>
<p>Requirements phrased in the imperative as part of algorithms
(such as "strip any leading space characters" or "return false and
terminate these steps") are to be interpreted with the meaning of the
key word ("must", "should", "may", etc) used in introducing the
algorithm.
<p>Conformance requirements phrased as algorithms or specific steps
may be implemented in any manner, so long as the end result is
equivalent. (In particular, the algorithms defined in this
specification are intended to be easy to follow, and not intended to
be performant.)
<p id="hardwareLimitations">User agents may impose
implementation-specific limits on otherwise unconstrained inputs,
e.g. to prevent denial of service attacks, to guard against running
out of memory, or to work around platform-specific limitations.
<p>When a method or an attribute is said to call another method or attribute, the user agent must invoke its internal API for that attribute or method so that e.g. the author can't change the behavior by overriding attributes or methods with custom properties or functions in ECMAScript.
<p>Unless otherwise stated, string comparisons are done in a <span>case-sensitive</span> manner.
<h3>Dependencies</h3>
<p>The IDL fragments in this specification must be interpreted as
required for conforming IDL fragments, as described in the Web IDL
specification. <span data-anolis-ref>WEBIDL</span>
<p>Some of the terms used in this specification are defined in
<cite>Encoding</cite>, <cite>Web IDL</cite>, <cite>XML</cite>, and
<cite>Namespaces in XML</cite>.
<span data-anolis-ref>ENCODING</span>
<span data-anolis-ref>WEBIDL</span>
<span data-anolis-ref>XML</span>
<span data-anolis-ref>XMLNS</span>
<h3>Extensibility</h3>
<p>Vendor-specific proprietary extensions to this specification are
strongly discouraged. Authors must not use such extensions, as
doing so reduces interoperability and fragments the user base,
allowing only users of specific user agents to access the content in
question.
<p>If vendor-specific extensions are needed, the members should be
prefixed by vendor-specific strings to prevent clashes with future
versions of this specification. Extensions must be defined so that
the use of extensions neither contradicts nor causes the
non-conformance of functionality defined in the specification.
<!-- thanks to QA Framework -->
<p>When vendor-neutral extensions to this specification are needed,
either this specification can be updated accordingly, or an
extension specification can be written that overrides the
requirements in this specification. When someone applying this
specification to their activities decides that they will recognize
the requirements of such an extension specification, it becomes an
<dfn title="other applicable specifications">applicable
specification</dfn> for the purposes of conformance requirements in
this specification.
<!-- http://www.w3.org/mid/[email protected] -->
<h2>Terminology</h2>
<p>The term <dfn>context object</dfn> means the object on which the method
or attribute being discussed was called. When the
<span>context object</span> is unambiguous, the term can be omitted.
<!-- XXX we should prolly explain that "set attribute X to Y" works even for
readonly attributes when it is language for implementors -->
<h3>Trees</h3> <!-- Sorry reddit, this is not /r/trees -->
<p>A <dfn title=concept-tree>tree</dfn> is a finite hierarchical tree structure. In
<dfn title=concept-tree-order>tree order</dfn> is preorder, depth-first
traversal of a <span title=concept-tree>tree</span>.
<!-- http://en.wikipedia.org/wiki/Tree_traversal#Depth-first_Traversal -->
<p>An object that <dfn title=concept-tree-participate>participates</dfn> in
a <span title=concept-tree>tree</span> has a
<dfn title=concept-tree-parent>parent</dfn>, which is either another object
or null, and an ordered list of zero or more
<dfn title=concept-tree-child>child</dfn> objects. An object <var title>A</var> whose
<span title=concept-tree-parent>parent</span> is object <var title>B</var> is a
<span title=concept-tree-child>child</span> of <var title>B</var>.
<p>The <dfn title=concept-tree-root>root</dfn> of an object is itself, if its
<span title=concept-tree-parent>parent</span> is null, or else it is the
<span title=concept-tree-root>root</span> of its
<span title=concept-tree-parent>parent</span>.
<p>An object <var title>A</var> is called a
<dfn title=concept-tree-descendant>descendant</dfn> of an object
<var title>B</var>, if either <var title>A</var> is a
<span title=concept-tree-child>child</span> of <var title>B</var> or
<var title>A</var> is a <span title=concept-tree-child>child</span> of an
object <var title>C</var> that is a
<span title=concept-tree-descendant>descendant</span> of <var title>B</var>.
<p>An
<dfn title=concept-tree-inclusive-descendant>inclusive descendant</dfn> is
an object or one of its
<span title=concept-tree-descendant>descendants</span>.
<p>An object <var title>A</var> is called an
<dfn title=concept-tree-ancestor>ancestor</dfn> of an object
<var title>B</var> if and only if <var title>B</var> is a
<span title=concept-tree-descendant>descendant</span> of
<var title>A</var>.
<p>An <dfn title=concept-tree-inclusive-ancestor>inclusive ancestor</dfn> is
an object or one of its <span title=concept-tree-ancestor>ancestors</span>.
<p>An object <var title>A</var> is called a
<dfn title=concept-tree-sibling>sibling</dfn> of an object
<var title>B</var>, if and only if <var title>B</var> and <var title>A</var>
share the same non-null <span title=concept-tree-parent>parent</span>.
<p>An object <var title>A</var> is
<dfn title=concept-tree-preceding>preceding</dfn> an object
<var title>B</var> if <var title>A</var> and <var title>B</var> are in the
same <span title=concept-tree>tree</span> and <var title>A</var> comes
before <var title>B</var> in
<span title=concept-tree-order>tree order</span>.
<p>An object <var title>A</var> is
<dfn title=concept-tree-following>following</dfn> an object
<var title>B</var> if <var title>A</var> and <var title>B</var> are in the
same <span title=concept-tree>tree</span> and <var title>A</var> comes
after <var title>B</var> in
<span title=concept-tree-order>tree order</span>.
<p>The <dfn title=concept-tree-first-child>first child</dfn> of an object is
its first <span title=concept-tree-child>child</span> or null if it has no
<span title=concept-tree-child>child</span>.
<p>The <dfn title=concept-tree-last-child>last child</dfn> of an object is
its last <span title=concept-tree-child>child</span> or null if it has no
<span title=concept-tree-child>child</span>.
<p>The <dfn title=concept-tree-previous-sibling>previous sibling</dfn> of an
object is its first <span title=concept-tree-preceding>preceding</span>
<span title=concept-tree-sibling>sibling</span> or null if it has no
<span title=concept-tree-preceding>preceding</span>
<span title=concept-tree-sibling>sibling</span>.
<p>The <dfn title=concept-tree-next-sibling>next sibling</dfn> of an
object is its first <span title=concept-tree-following>following</span>
<span title=concept-tree-sibling>sibling</span> or null if it has no
<span title=concept-tree-following>following</span>
<span title=concept-tree-sibling>sibling</span>.
<p>The <dfn title=concept-tree-index>index</dfn> of an object is its number
of <span title=concept-tree-preceding>preceding</span>
<span title=concept-tree-sibling>siblings</span>.
<h3>Strings</h3>
<p>Comparing two strings in a <dfn>case-sensitive</dfn> manner means comparing them exactly, code point for code point.
<p>Comparing two strings in a <dfn>ASCII case-insensitive</dfn> manner means comparing them exactly, code point for code point, except that the characters in the range U+0041 .. U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z) and the corresponding characters in the range U+0061 .. U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z) are considered to also match.
<p><dfn title="converted to ascii uppercase">Converting a string to ASCII uppercase</dfn> means replacing all characters in the range U+0061 to U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z) with the corresponding characters in the range U+0041 to U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z).
<p><dfn title="converted to ascii lowercase">Converting a string to ASCII lowercase</dfn> means replacing all characters in the range U+0041 to U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z) with the corresponding characters in the range U+0061 to U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z).
<p>A string <var title>pattern</var> is a <dfn>prefix match</dfn> for a string
<var title>s</var> when <var title>pattern</var> is not longer than
<var title>s</var> and truncating <var title>s</var> to
<var title>pattern</var>'s length leaves the two strings as matches of each
other.
<h3>Ordered sets</h3>
<p>The <dfn title=concept-set-parser>set parser</dfn> takes a string
<var title>input</var> and then runs these steps:
<ol>
<li><p>Let <var title>position</var> be a pointer into <var title>input</var>,
initially pointing at the start of the string.
<li><p>Let <var title>tokens</var> be a list of tokens, initially empty.
<li><p><span>Skip ASCII whitespace</span>.
<li><p>While <var title>position</var> is not past the end of
<var title>input</var>:
<ol>
<li><p><span>Collect a code point sequence</span> of code points that are
not <span data-anolis-spec=encoding>ASCII whitespace</span>.
<li><p>If the collected string is not in <var title>tokens</var>, append the
collected string to <var title>tokens</var>.
<li><p><span>Skip ASCII whitespace</span>.
</ol>
<li><p>Return <var title>tokens</var>.
</ol>
<p>To <dfn>collect a code point sequence</dfn> of
<var title>code points</var>, run these steps:
<ol>
<li><p>Let <var title>input</var> and <var title>position</var> be the same
variables as those of the same name in the algorithm that invoked these
steps.
<li><p>Let <var title>result</var> be the empty string.
<li><p>While <var title>position</var> does not point past the end of
<var title>input</var> and the code point at <var title>position</var> is
one of the <var title>code points</var>, append that code point to the end
of <var title>result</var> and advance <var title>position</var> to the
next code point in <var title>input</var>.
<li><p>Return <var title>result</var>.
</ol>
<p>To <dfn>skip ASCII whitespace</dfn> means to
<span>collect a code point sequence</span> of
<span data-anolis-spec=encoding>ASCII whitespace</span> and discard the
return value.
<p>The <dfn title=concept-set-serializer>set serializer</dfn> takes a
<var title>set</var> and returns the concatenation of the strings in
<var title>set</var>, separated from each other by U+0020.
<h3>Namespaces</h3>
<p>The <dfn>HTML namespace</dfn> is
<code title>http://www.w3.org/1999/xhtml</code>.
<p>The <dfn>XML namespace</dfn> is
<code title>http://www.w3.org/XML/1998/namespace</code>.
<p>The <dfn>XMLNS namespace</dfn> is
<code title>http://www.w3.org/2000/xmlns/</code>.
<h2>Errors</h2>
<h3>Exception <code>DOMException</code></h3>
<pre class=idl>exception <dfn>DOMException</dfn> {
const unsigned short <span title=dom-DOMException-INDEX_SIZE_ERR>INDEX_SIZE_ERR</span> = 1;
const unsigned short <span title=dom-DOMException-DOMSTRING_SIZE_ERR>DOMSTRING_SIZE_ERR</span> = 2; // historical
const unsigned short <span title=dom-DOMException-HIERARCHY_REQUEST_ERR>HIERARCHY_REQUEST_ERR</span> = 3;
const unsigned short <span title=dom-DOMException-WRONG_DOCUMENT_ERR>WRONG_DOCUMENT_ERR</span> = 4;
const unsigned short <span title=dom-DOMException-INVALID_CHARACTER_ERR>INVALID_CHARACTER_ERR</span> = 5;
const unsigned short <span title=dom-DOMException-NO_DATA_ALLOWED_ERR>NO_DATA_ALLOWED_ERR</span> = 6; // historical
const unsigned short <span title=dom-DOMException-NO_MODIFICATION_ALLOWED_ERR>NO_MODIFICATION_ALLOWED_ERR</span> = 7;
const unsigned short <span title=dom-DOMException-NOT_FOUND_ERR>NOT_FOUND_ERR</span> = 8;
const unsigned short <span title=dom-DOMException-NOT_SUPPORTED_ERR>NOT_SUPPORTED_ERR</span> = 9;
const unsigned short <span title=dom-DOMException-INUSE_ATTRIBUTE_ERR>INUSE_ATTRIBUTE_ERR</span> = 10; // historical
const unsigned short <span title=dom-DOMException-INVALID_STATE_ERR>INVALID_STATE_ERR</span> = 11;
const unsigned short <span title=dom-DOMException-SYNTAX_ERR>SYNTAX_ERR</span> = 12;
const unsigned short <span title=dom-DOMException-INVALID_MODIFICATION_ERR>INVALID_MODIFICATION_ERR</span> = 13;
const unsigned short <span title=dom-DOMException-NAMESPACE_ERR>NAMESPACE_ERR</span> = 14;
const unsigned short <span title=dom-DOMException-INVALID_ACCESS_ERR>INVALID_ACCESS_ERR</span> = 15;
const unsigned short <span title=dom-DOMException-VALIDATION_ERR>VALIDATION_ERR</span> = 16; // historical
const unsigned short <span title=dom-DOMException-TYPE_MISMATCH_ERR>TYPE_MISMATCH_ERR</span> = 17; // historical; use JavaScript's TypeError instead
const unsigned short <span title=dom-DOMException-SECURITY_ERR>SECURITY_ERR</span> = 18;
const unsigned short <span title=dom-DOMException-NETWORK_ERR>NETWORK_ERR</span> = 19;
const unsigned short <span title=dom-DOMException-ABORT_ERR>ABORT_ERR</span> = 20;
const unsigned short <span title=dom-DOMException-URL_MISMATCH_ERR>URL_MISMATCH_ERR</span> = 21;
const unsigned short <span title=dom-DOMException-QUOTA_EXCEEDED_ERR>QUOTA_EXCEEDED_ERR</span> = 22;
const unsigned short <span title=dom-DOMException-TIMEOUT_ERR>TIMEOUT_ERR</span> = 23;
const unsigned short <span title=dom-DOMException-INVALID_NODE_TYPE_ERR>INVALID_NODE_TYPE_ERR</span> = 24;
const unsigned short <span title=dom-DOMException-DATA_CLONE_ERR>DATA_CLONE_ERR</span> = 25;
unsigned short <span title=dom-DOMException-code>code</span>;
};</pre>
<p>The <dfn title=dom-DOMException-code><code>code</code></dfn> exception
field must return the value it was initialized to.
<p>To <dfn title=concept-throw>throw</dfn> a <var title>name</var> exception
run these steps:
<ol>
<li><p>Let <var title>code</var> be zero.
<li><p>If <var title>name</var> is in the first column of the
<span>error names table</span> and has a corresponding legacy
<code title=dom-DOMException-code>code</code> exception field value in the
third column, set <var title>code</var> to that value.
<li><p><span data-anolis-spec=webidl>Throw</span> a new
<code>DOMException</code> exception, whose
<span data-anolis-spec=webidl>message</span> is a user agent-defined value,
<span data-anolis-spec=webidl>name</span> is <var title>name</var>, and
whose <code title=dom-DOMException-code>code</code> exception field is
<var title>code</var>.
</ol>
<p class=example>To
<i title>throw a "<code>TimeoutError</code>" exception</i>, a
user agent would construct a <code>DOMException</code> exception whose
<span data-anolis-spec=webidl>name</span> is
"<code>TimeoutError</code>" and
<code title=dom-DOMException-code>code</code> exception field value is 23,
and actually throw that object as an exception. In JavaScript, this
exception will have a <code title>name</code> property whose value is
"<code>TimeoutError</code>".
<h3>Interface <code>DOMError</code></h3>
<p class=note>This interface is intended for other specifications that want
to introduce error handling through other means than exceptions. As with
exceptions, the <span>error names table</span> is used.
<pre class=idl>[<span title=dom-DOMError>Constructor</span>(DOMString <var title>name</var>, optional DOMString <var title>message</var> = "")]
interface <dfn>DOMError</dfn> {
readonly attribute DOMString <span title=dom-DOMError-name>name</span>;
readonly attribute DOMString <span title=dom-DOMError-message>message</span>;
};</pre>
<p>The <dfn title=dom-DOMError><code>DOMError(<var title>name</var>, <var title>message</var>)</code></dfn>
constructor must return a new <code>DOMError</code> object whose
<code title=dom-DOMError-name>name</code> attribute is initialized to
<var title>name</var> and whose <code title=dom-DOMError-message>message</code> attribute
is initialized to <var title>message</var>.
<p>The <dfn title=dom-DOMError-name><code>name</code></dfn> attribute must
return the value it was initialized to.
<p>The <dfn title=dom-DOMError-message><code>message</code></dfn> attribute must
return the value it was initialized to.
<p class=note>The value of the <code title=dom-DOMError-message>message</code> will
typically be implementation-dependent and for informational purposes only.
<p>A
<dfn title=concept-DOMError><var title>name</var> <code>DOMError</code></dfn>
means a <code>DOMError</code> object whose
<code title=dom-DOMError-name>name</code> attribute is initialized to
<var title>name</var> and whose <code title=dom-DOMError-message>message</code> attribute
is initialized to a helpful implementation-dependent message that explains the error.
<p class=example>A specification could say that an <code title>error</code>
attribute must return a
<span title=concept-DOMError>"<code>SyntaxError</code>" <code>DOMError</code></span>.
<h3>Error names</h3>
<p>The <dfn>error names table</dfn> below lists all the allowed error names,
a description, and legacy <code title=dom-DOMException-code>code</code>
exception field values (when the error name is used for
<span title=concept-throw>throwing</span> an exception).
<p class=note>If an error name is not listed here, please file a bug as
indicated at the top of this specification and it will be addressed shortly.
Thanks!
<table id=error-names>
<thead>
<tr><th>Name<th>Description<th>Legacy <code title=dom-DOMException-code>code</code> exception field value (if any)
<tbody>
<tr>
<td>"<dfn><code>IndexSizeError</code></dfn>"
<td>The index is not in the allowed range.
<td><dfn title=dom-DOMException-INDEX_SIZE_ERR><code>INDEX_SIZE_ERR</code></dfn> (1)
<tr>
<td>"<dfn><code>HierarchyRequestError</code></dfn>"
<td>The operation would yield an incorrect <span title=concept-node-tree>node tree</span>.
<td><dfn title=dom-DOMException-HIERARCHY_REQUEST_ERR><code>HIERARCHY_REQUEST_ERR</code></dfn> (3)
<tr>
<td>"<dfn><code>WrongDocumentError</code></dfn>"
<td>The object is in the wrong <span title=concept-document>document</span>.
<td><dfn title=dom-DOMException-WRONG_DOCUMENT_ERR><code>WRONG_DOCUMENT_ERR</code></dfn> (4)
<tr>
<td>"<dfn><code>InvalidCharacterError</code></dfn>"
<td>The string contains invalid characters.
<td><dfn title=dom-DOMException-INVALID_CHARACTER_ERR><code>INVALID_CHARACTER_ERR</code></dfn> (5)
<tr>
<td>"<dfn><code>NoModificationAllowedError</code></dfn>"
<td>The object can not be modified.
<td><dfn title=dom-DOMException-NO_MODIFICATION_ALLOWED_ERR><code>NO_MODIFICATION_ALLOWED_ERR</code></dfn> (7)
<tr>
<td>"<dfn><code>NotFoundError</code></dfn>"
<td>The object can not be found here.
<td><dfn title=dom-DOMException-NOT_FOUND_ERR><code>NOT_FOUND_ERR</code></dfn> (8)
<tr>
<td>"<dfn><code>NotSupportedError</code></dfn>"
<td>The operation is not supported.
<td><dfn title=dom-DOMException-NOT_SUPPORTED_ERR><code>NOT_SUPPORTED_ERR</code></dfn> (9)
<tr>
<td>"<dfn><code>InvalidStateError</code></dfn>"
<td>The object is in an invalid state.
<td><dfn title=dom-DOMException-INVALID_STATE_ERR><code>INVALID_STATE_ERR</code></dfn> (11)
<tr>
<td>"<dfn><code>SyntaxError</code></dfn>"
<td>The string did not match the expected pattern.
<td><dfn title=dom-DOMException-SYNTAX_ERR><code>SYNTAX_ERR</code></dfn> (12)
<tr>
<td>"<dfn><code>InvalidModificationError</code></dfn>"
<td>The object can not be modified in this way.
<td><dfn title=dom-DOMException-INVALID_MODIFICATION_ERR><code>INVALID_MODIFICATION_ERR</code></dfn> (13)
<tr>
<td>"<dfn><code>NamespaceError</code></dfn>"
<td>The operation is not allowed by <cite>Namespaces in XML</cite>. <span data-anolis-ref>XMLNS</span>
<td><dfn title=dom-DOMException-NAMESPACE_ERR><code>NAMESPACE_ERR</code></dfn> (14)
<tr>
<td>"<dfn><code>InvalidAccessError</code></dfn>"
<td>The object does not support the operation or argument.
<td><dfn title=dom-DOMException-INVALID_ACCESS_ERR><code>INVALID_ACCESS_ERR</code></dfn> (15)
<tr>
<!-- XHR -->
<td>"<dfn><code>SecurityError</code></dfn>"
<td>The operation is insecure.
<td><dfn title=dom-DOMException-SECURITY_ERR><code>SECURITY_ERR</code></dfn> (18)
<tr>
<!-- XHR -->
<td>"<dfn><code>NetworkError</code></dfn>"
<td>A network error occurred.
<td><dfn title=dom-DOMException-NETWORK_ERR><code>NETWORK_ERR</code></dfn> (19)
<tr>
<!-- XHR -->
<td>"<dfn><code>AbortError</code></dfn>"
<td>The operation was aborted.
<td><dfn title=dom-DOMException-ABORT_ERR><code>ABORT_ERR</code></dfn> (20)
<tr>
<!-- Workers -->
<td>"<dfn><code>URLMismatchError</code></dfn>"
<td>The given URL does not match another URL.
<td><dfn title=dom-DOMException-URL_MISMATCH_ERR><code>URL_MISMATCH_ERR</code></dfn> (21)
<tr>
<!-- HTML -->
<td>"<dfn><code>QuotaExceededError</code></dfn>"
<td>The quota has been exceeded.
<td><dfn title=dom-DOMException-QUOTA_EXCEEDED_ERR><code>QUOTA_EXCEEDED_ERR</code></dfn> (22)
<tr>
<!-- XHR -->
<td>"<dfn><code>TimeoutError</code></dfn>"
<td>The operation timed out.
<td><dfn title=dom-DOMException-TIMEOUT_ERR><code>TIMEOUT_ERR</code></dfn> (23)
<tr>
<td>"<dfn><code>InvalidNodeTypeError</code></dfn>"
<td>The supplied node is incorrect or has an incorrect ancestor for this operation.
<td><dfn title=dom-DOMException-INVALID_NODE_TYPE_ERR><code>INVALID_NODE_TYPE_ERR</code></dfn> (24)
<tr>
<!-- HTML -->
<td>"<dfn><code>DataCloneError</code></dfn>"
<td>The object can not be cloned.
<td><dfn title=dom-DOMException-DATA_CLONE_ERR><code>DATA_CLONE_ERR</code></dfn> (25)
<tr>
<td>"<dfn><code>EncodingError</code></dfn>"
<td>The encoding operation (either encoded or decoding) failed.
<td>—
</table>
<h2>Futures</h2>
<h3>Introduction to the <code title>Future</code></h3>
<p><span title=concept-future>Futures</span> provide a convenient way to get access to the
result of an operation.
<p><span title=concept-future>Futures</span> can be returned by platform APIs, but can
also be used in conjunction with an existing API to make it easier to work with.
<div class=example>
<p>This example demonstrates creating a <code title>fetchJSON(<var>url</var>)</code>
function that returns a <code>Future</code> that is responsible for fetching a
<span data-anolis-spec=url>URL</span> and parsing the response as JSON.
<pre>function fetchJSON(url) {
return new Future(function(resolver) {
var xhr = new XMLHttpRequest()
xhr.open("GET", url)
xhr.responseType = "json"
xhr.send()
// resolver.reject() is ignored once resolver.resolve() has been invoked
xhr.onload = function() {
if(xhr.response)
resolver.resolve(xhr.response)
resolver.reject(new DOMError("JSONError"))
}
xhr.onloadend = function() { resolver.reject(new DOMError("NetworkError")) }
})
}</pre>
<p>This can be used to create more idiomatic code:
<pre>fetchJSON("/user/posts").done(showPosts, showFailcat)</pre>
<p>Using static methods <span title=concept-future>futures</span> can be combined to
create new <span title=concept-future>futures</span>, which allows for operating on the
results of several asynchronous requests at once:
<pre>Future.every(fetchJSON("/user/mario"), fetchJSON("/user/luigi")).done(
function(mario, luigi) { … },
showFailcat
)</pre>
<p>Enjoy!
</div>
<h3>Futures Model</h3>
<p>A <dfn title=concept-future>future</dfn> provides asynchronous access to the result of
an operation that is ongoing, has yet to start, or has completed.
<p>A <span title=concept-future>future</span> has associated
<dfn title=concept-future-accept-callbacks>accept callbacks</dfn> and
<dfn title=concept-future-reject-callbacks>reject callbacks</dfn>, an associated
<dfn title=concept-future-state>state</dfn>, and an associated
<dfn title=concept-future-result>result</dfn>. Unless stated otherwise, a
<span title=concept-future>future</span>'s <span title=concept-future-state>state</span>
is <i title>pending</i>.
<p>A <span title=concept-future>future</span> also has an associated
<span title=concept-resolver>resolver</span>.
<p>To <dfn title=concept-future-append>append</dfn> an
<var title>acceptCallback</var> and a <var title>rejectCallback</var> to a
<var title>future</var>, run these steps:
<ol>
<li><p>Append <var title>acceptCallback</var> to <var title>future</var>'s
<span title=concept-future-accept-callbacks>accept callbacks</span>.
<li><p>Append <var title>rejectCallback</var> to <var title>future</var>'
<span title=concept-future-reject-callbacks>reject callbacks</span>.
<li><p>If <var title>future</var>'s <span title=concept-future-state>state</span> is
<i title>accepted</i>, <span data-anolis-spec=html>queue a task</span> to
<span title=concept-future-process>process</span> <var title>future</var>'s
<span title=concept-future-accept-callbacks>accept callbacks</span> with
<var title>future</var>'s <span title=concept-future-result>result</span>.
<li><p>If <var title>future</var>'s <span title=concept-future-state>state</span> is
<i title>rejected</i>, <span data-anolis-spec=html>queue a task</span> to
<span title=concept-future-process>process</span> <var title>future</var>'s
<span title=concept-future-reject-callbacks>reject callbacks</span> with
<var title>future</var>'s <span title=concept-future-result>result</span>.
</ol>
<p>A <dfn title=concept-future-callback>future callback</dfn> for a
<span title=concept-resolver>resolver</span> <var title>resolver</var> and algorithm
<var title>algorithm</var> is a JavaScript <code title>Function</code> Object which when
called runs these steps:
<ol>
<li><p>Let <var title>value</var> be the first argument that is passed, and
<code title>undefined</code> otherwise.
<li><p>Run <var title>resolver</var>'s <var title>algorithm</var> with
<var title>value</var> and the <i title>synchronous flag</i> set.
</ol>
<p>A <dfn title=concept-future-wrapper-callback>future wrapper callback</dfn> for a
<span title=concept-resolver>resolver</span> <var title>resolver</var> and callback
<var title>callback</var> is a JavaScript <code title>Function</code> Object which when
called runs these steps:
<ol>
<li><p>Let <var title>argument</var> be the first argument that is passed, and
<code title>undefined</code> otherwise.
<li><p>Set <var title>callback</var>'s
<span data-anolis-spec=webidl>callback this value</span> to <var title>resolver</var>'s
associated <span title=concept-future>future</span>.
<li><p>Let <var title>value</var> be the result of invoking <var title>callback</var>
with <var title>argument</var> as argument.
<li><p>If invoking <var title>callback</var> threw an exception, run
<var title>resolver</var>'s <span title=concept-resolver-reject>reject</span> with the
thrown exception as argument and the <i title>synchronous flag</i> set.
<li><p>Otherwise, run <var title>resolver</var>'s
<span title=concept-resolver-resolve>resolve</span> with <var title>value</var> and the
<i title>synchronous flag</i> set.
</ol>
<p>To <dfn title=concept-future-process>process</dfn> a <var title>future</var>'s
<span title=concept-future-accept-callbacks>accept callbacks</span> or
<span title=concept-future-reject-callbacks>reject callbacks</span> with a given
<var title>value</var>, call each callback with <var title>value</var> as argument and
then discard it.
<p>A <dfn title=concept-resolver>resolver</dfn> is in control of a
<span title=concept-future>future</span>'s <span title=concept-future-state>state</span>.
<p>A <span title=concept-resolver>resolver</span> has an associated
<dfn>resolved flag</dfn>. Unless stated otherwise a
<span title=concept-resolver>resolver</span>'s <span>resolved flag</span> is unset.
<p>A <span title=concept-resolver>resolver</span>'s
<dfn title=concept-resolver-accept>accept</dfn> algorithm takes a <var title>value</var>
and optionally a <i title>synchronous flag</i>, and runs these steps:
<ol>
<li><p>If the <span>context object</span>'s <span>resolved flag</span> is set, terminate
these steps.
<li><p>Let <var title>future</var> be the <span>context object</span>'s associated
<span title=concept-future>future</span>.
<li><p>Set <var title>future</var>'s <span title=concept-future-state>state</span> to
<i title>accepted</i>.
<li><p>Set <var title>future</var>'s <span title=concept-future-result>result</span> to
<var title>value</var>.
<li><p>Set the <span>context object</span>'s <span>resolved flag</span>.
<li><p>If the <i title>synchronous flag</i> is set,
<span title=concept-future-process>process</span> <var title>future</var>'s
<span title=concept-future-accept-callbacks>accept callbacks</span> with
<var title>value</var>.
<li><p>Otherwise, the <i title>synchronous flag</i> is unset,
<span data-anolis-spec=html>queue a task</span> to
<span title=concept-future-process>process</span> <var title>future</var>'s
<span title=concept-future-accept-callbacks>accept callbacks</span> with
<var title>value</var>.
</ol>
<p>A <span title=concept-resolver>resolver</span>'s
<dfn title=concept-resolver-resolve>resolve</dfn> algorithm takes a <var title>value</var>
and optionally a <i title>synchronous flag</i>, and runs these steps:
<ol>
<li><p>If the <span>context object</span>'s <span>resolved flag</span> is set, terminate
these steps.
<li>
<p>Let <var title>then</var> be null.
<p class=note>Starting here the algorithm is described in terms of the JavaScript
specification. (Or ECMAScript, if you feel that is a more suitable name.)
<li><p>If <var title>value</var> is a JavaScript Object, set <var title>then</var> to
the result of calling the JavaScript <code title>[[Get]]</code> internal method of
<var title>value</var> with property name <code title>then</code>.
<li><p>If calling the <code title>[[Get]]</code> internal method threw an exception, run
<span title=concept-resolver-reject>reject</span> with the thrown exception and the
<i title>synchronous flag</i> if set, and then terminate these steps.
<li>
<p>If JavaScript IsCallable(<var title>then</var>) is true, run these substeps and then
terminate these steps:
<ol>
<li><p>Let <var title>acceptCallback</var> be a
<span title=concept-future-callback>future callback</span> for the
<span>context object</span> and its <span title=concept-resolver-resolve>resolve</span>
algorithm.
<li><p>Let <var title>rejectCallback</var> be a
<span title=concept-future-callback>future callback</span> for the
<span>context object</span> and its <span title=concept-resolver-reject>reject</span>
algorithm.
<li><p>Call the JavaScript <code title>[[Call]]</code> internal method of
<var title>then</var> with <b title>this</b> value <var title>value</var> and
<var title>acceptCallback</var> and <var title>rejectCallback</var> as arguments.
<li><p>If calling the <code title>[[Call]]</code> internal method threw an exception,
run <span>context object</span>'s <span title=concept-resolver-reject>reject</span>
with the thrown exception and the <i title>synchronous flag</i> if set.
</ol>
<li><p>Run <span>context object</span>'s
<span title=concept-resolver-accept>accept</span> with <var title>value</var> and the
<i title>synchronous flag</i> if set.
</ol>
<p>A <span title=concept-resolver>resolver</span>'s
<dfn title=concept-resolver-reject>reject</dfn> algorithm takes a <var title>value</var>
and optionally a <i title>synchronous flag</i>, and runs these steps:
<ol>
<li><p>If the <span>context object</span>'s <span>resolved flag</span> is set, terminate
these steps.
<li><p>Let <var title>future</var> be the <span>context object</span>'s associated
<span title=concept-future>future</span>.
<li><p>Set <var title>future</var>'s <span title=concept-future-state>state</span> to
<i title>rejected</i>.
<li><p>Set <var title>future</var>'s <span title=concept-future-result>result</span> to
<var title>value</var>.
<li><p>Set the <span>context object</span>'s <span>resolved flag</span>.
<li><p>If the <i title>synchronous flag</i> is set,
<span title=concept-future-process>process</span> <var title>future</var>'s
<span title=concept-future-reject-callbacks>reject callbacks</span> with
<var title>value</var>.
<li><p>Otherwise, the <i title>synchronous flag</i> is unset,
<span data-anolis-spec=html>queue a task</span> to
<span title=concept-future-process>process</span> <var title>future</var>'s
<span title=concept-future-reject-callbacks>reject callbacks</span> with
<var title>value</var>.
</ol>
<p>Unless stated otherwise, the <span data-anolis-spec=html>task source</span> used by
<span title=concept-future>futures</span> and their
<span title=concept-resolver>resolvers</span> is the
<span data-anolis-spec=html>DOM manipulation task source</span>.
<h3>Futures API</h3>
<pre class=idl>interface <dfn>FutureResolver</dfn> {
void <span title=dom-FutureResolver-accept>accept</span>(optional any <var title>value</var>);
void <span title=dom-FutureResolver-resolve>resolve</span>(optional any <var title>value</var>);
void <span title=dom-FutureResolver-reject>reject</span>(optional any <var title>value</var>);
};
callback <dfn>FutureInit</dfn> = void (<span>FutureResolver</span> <var title>resolver</var>);
callback <dfn>AnyCallback</dfn> = any (optional any <var title>value</var>);
[<span title=dom-Future>Constructor</span>(<span>FutureInit</span> <var title>init</var>)]
interface <dfn>Future</dfn> {
static <span>Future</span> <span title=dom-Future-accept>accept</span>(any <var title>value</var>);
static <span>Future</span> <span title=dom-Future-resolve>resolve</span>(any <var title>value</var>); // same as <span title=dom-Future-any>any(<var>value</var>)</span>
static <span>Future</span> <span title=dom-Future-reject>reject</span>(any <var title>value</var>);
static <span>Future</span> <span title=dom-Future-any>_any</span>(any... <var title>values</var>); // exposed as "any" in JavaScript, without "_"
static <span>Future</span> <span title=dom-Future-every>every</span>(any... <var title>values</var>);
static <span>Future</span> <span title=dom-Future-some>some</span>(any... <var title>values</var>);
<span>Future</span> <span title=dom-Future-then>then</span>([TreatUndefinedAs=Missing] optional <span>AnyCallback</span> <var title>acceptCallback</var>, [TreatUndefinedAs=Missing] optional <span>AnyCallback</span> <var title>rejectCallback</var>);
<span>Future</span> <span title=dom-Future-catch>catch</span>([TreatUndefinedAs=Missing] optional <span>AnyCallback</span> <var title>rejectCallback</var>);
void <span title=dom-Future-done>done</span>([TreatUndefinedAs=Missing] optional <span>AnyCallback</span> <var title>acceptCallback</var>, [TreatUndefinedAs=Missing] optional <span>AnyCallback</span> <var title>rejectCallback</var>);
};</pre>
<p>A <code>FutureResolver</code> object is a <span title=concept-resolver>resolver</span>.
<dl class=domintro>
<dt><code><var title>resolver</var> . <span title=dom-FutureResolver-accept>accept</span>(<var title>value</var>)</code>
<dd><p>Runs <var title>resolver</var>'s
<span title=concept-resolver-accept>accept</span>.
<dt><code><var title>resolver</var> . <span title=dom-FutureResolver-resolve>resolve</span>(<var title>value</var>)</code>
<dd><p>Runs <var title>resolver</var>'s
<span title=concept-resolver-resolve>resolve</span>.
<dt><code><var title>resolver</var> . <span title=dom-FutureResolver-reject>reject</span>(<var title>value</var>)</code>
<dd><p>Runs <var title>resolver</var>'s
<span title=concept-resolver-reject>reject</span>.
</dl>
<p>The <dfn title=dom-FutureResolver-accept><code>accept(<var>value</var>)</code></dfn>
method must run <span>context object</span>'s
<span title=concept-resolver-accept>accept</span> with <var title>value</var>.
<p>The <dfn title=dom-FutureResolver-resolve><code>resolve(<var>value</var>)</code></dfn>
method must run <span>context object</span>'s
<span title=concept-resolver-resolve>resolve</span> with <var title>value</var>.
<p>The <dfn title=dom-FutureResolver-reject><code>reject(<var>value</var>)</code></dfn>
method must run <span>context object</span>'s
<span title=concept-resolver-reject>reject</span> with <var title>value</var>.
<p>A <code>Future</code> object is a <span title=concept-future>future</span>.
<dl class=domintro>
<dt><code><var title>future</var> = new <span title=dom-Future>Future</span>(<var title>init</var>)</code>
<dd><p>Creates a new <span title=concept-future>future</span>. The <var title>init</var>
callback is passed the associated <span title=concept-resolver>resolver</span>. If the
callback throws an exception, the <span title=concept-future>future</span>'s associated
<span title=concept-resolver>resolver</span>'s
<span title=concept-resolver-reject>reject</span> is run with the thrown exception.
<dt><code><var title>newFuture</var> = <var title>future</var>.<span title=dom-Future-then>then</span>([<var title>acceptCallback</var> [, <var title>rejectCallback</var>]])</code>
<dd>
<p>Appends callbacks to <var title>future</var> of which one will be invoked with
<var title>future</var>'s <span title=concept-future-result>result</span> at some point
after <var title>future</var>'s <span title=concept-future-state>state</span> is set to
either <i title>accepted</i> or <i title>rejected</i>.
<p>If <var title>acceptCallback</var> or <var title>rejectCallback</var> is omitted or undefined, a
callback will be appended that when invoked runs <var title>newFuture</var>'s associated
<span title=concept-resolver>resolver</span>'s
<span title=concept-resolve>resolve</span> or <span title=concept-reject>reject</span>
algorithm respectively, with <var title>future</var>'s
<span title=concept-future-result>result</span>.
<p>If they are not omitted or undefined, when invoked their return value is passed to
<var title>newFuture</var>'s associated <span title=concept-resolver>resolver</span>'s
<span title=concept-resolve>resolve</span> algorithm. If a callback throws an exception,
that exception is passed to <var title>newFuture</var>'s associated
<span title=concept-resolver>resolver</span>'s
<span title=concept-reject>reject</span> algorithm.
<dt><code><var title>newFuture</var> = <var title>future</var>.<span title=dom-Future-catch>catch</span>([<var title>rejectCallback</var>])</code>
<dd><p>Identical to invoking <code><var title>future</var>.<span title=dom-Future-then>then</span>(undefined, <var title>rejectCallback</var>)</code>.
<dt><code><var title>future</var>.<span title=dom-Future-done>done</span>([<var title>acceptCallback</var> [, <var title>rejectCallback</var>]])</code>
<dd>
<p>Appends callbacks to <var title>future</var> of which one will be invoked with
<var title>future</var>'s <span title=concept-future-result>result</span> at some point
after <var title>future</var>'s <span title=concept-future-state>state</span> is set to
either <i title>accepted</i> or <i title>rejected</i>.
<p>Exceptions raised will reach <code title>window.onerror</code>.
</dl>
<p>The <dfn title=dom-Future><code>Future(<var>init</var>)</code></dfn> constructor must
run these steps:
<ol>
<li><p>Let <var title>future</var> be a new <span title=concept-future>future</span>.
<li><p>Let <var title>resolver</var> be <var title>future</var>'s associated
<span title=concept-resolver>resolver</span>.
<li><p>Set <var title>init</var>'s
<span data-anolis-spec=webidl>callback this value</span> to <var title>future</var>.
<li><p>Invoke <var title>init</var> with <var title>resolver</var> passed as parameter.
<li><p>If <var title>init</var> threw an exception, run <var title>resolver</var>'s
<span title=concept-resolver-reject>reject</span> with the thrown exception as argument.
<li><p>Return <var title>future</var>.
</ol>
<p>The
<dfn title=dom-Future-then><code>then(<var>acceptCallback</var>, <var>rejectCallback</var>)</code></dfn>
method must run these steps:
<ol>
<li><p>Let <var title>future</var> be a new <span title=concept-future>future</span>.
<li><p>Let <var title>resolver</var> be <var title>future</var>'s associated
<span title=concept-resolver>resolver</span>.
<li><p>Let <var title>acceptWrapper</var> be a
<span title=concept-future-wrapper-callback>future wrapper callback</span> for
<var title>resolver</var> and <var title>acceptCallback</var> if
<var title>acceptCallback</var> is not omitted and a
<span title=concept-future-callback>future callback</span> for <var title>resolver</var>
and its <span title=concept-resolver-accept>accept</span> algorithm otherwise.
<li><p>Let <var title>rejectWrapper</var> be a
<span title=concept-future-wrapper-callback>future wrapper callback</span> for
<var title>resolver</var> and <var title>rejectCallback</var> if
<var title>rejectCallback</var> is not omitted and a
<span title=concept-future-callback>future callback</span> for <var title>resolver</var>
and its <span title=concept-resolver-reject>reject</span> algorithm otherwise.
<li><p><span title=concept-future-append>Append</span> <var title>acceptWrapper</var> and
<var title>rejectWrapper</var> to the <span>context object</span>.
<li><p>Return <var title>future</var>.
</ol>
<p>The <dfn title=dom-Future-catch><code>catch(<var>rejectCallback</var>)</code></dfn>
method must run these steps:
<ol>
<li><p>Let <var title>future</var> be a new <span title=concept-future>future</span>.
<li><p>Let <var title>resolver</var> be <var title>future</var>'s associated
<span title=concept-resolver>resolver</span>.
<li><p>Let <var title>acceptCallback</var> be a new
<span title=concept-future-callback>future callback</span> for <var title>resolver</var>