Skip to content

Commit eb84ee6

Browse files
authored
DOM: AbortController and AbortSignal
For whatwg/dom#437.
1 parent f90eada commit eb84ee6

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

dom/abort/event.any.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
test(t => {
2+
const c = new AbortController(),
3+
s = c.signal;
4+
let state = "begin";
5+
6+
assert_false(s.aborted);
7+
8+
s.addEventListener("abort",
9+
t.step_func(e => {
10+
assert_equals(state, "begin");
11+
state = "aborted";
12+
})
13+
);
14+
c.abort();
15+
16+
assert_equals(state, "aborted");
17+
assert_true(s.aborted);
18+
19+
c.abort();
20+
}, "AbortController() basics");
21+
22+
done();

dom/interface-objects.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"Event",
1616
"CustomEvent",
1717
"EventTarget",
18+
"AbortController",
19+
"AbortSignal",
1820
"Node",
1921
"Document",
2022
"DOMImplementation",

dom/interfaces.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ <h1>DOM IDL tests</h1>
2424
EventTarget: ['new EventTarget()'],
2525
Event: ['document.createEvent("Event")', 'new Event("foo")'],
2626
CustomEvent: ['new CustomEvent("foo")'],
27+
AbortController: ['new AbortController()'],
28+
AbortSignal: ['new AbortController().signal'],
2729
Document: ['new Document()'],
2830
XMLDocument: ['xmlDoc'],
2931
DOMImplementation: ['document.implementation'],

interfaces/dom.idl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ dictionary EventListenerOptions {
6161
};
6262

6363

64+
[Constructor,
65+
Exposed=(Window,Worker)]
66+
interface AbortController {
67+
[SameObject] readonly attribute AbortSignal signal;
68+
69+
void abort();
70+
};
71+
72+
73+
[Exposed=(Window,Worker)]
74+
interface AbortSignal : EventTarget {
75+
readonly attribute boolean aborted;
76+
77+
attribute EventHandler onabort;
78+
};
79+
80+
6481
[NoInterfaceObject,
6582
Exposed=Window]
6683
interface NonElementParentNode {

0 commit comments

Comments
 (0)