Skip to content

Commit 7b54a1a

Browse files
shaseleychromium-wpt-export-bot
authored andcommitted
Implement AbortSignal.timeout
AbortSignal.timeout is a static method that creates a new AbortSignal that is automatically aborted after a specified duration. The implementation is essentially PostDelayedTask(SignalAbort, ms). Throttling: this API is specced to use the timer task source, but there are three internally due to our throttling implementation. We use immediate for the timeout == 0 case and high nesting for timeount > 0 (the typical case), i.e. all non-zero timeouts are eligible for throttling (Note: this matches scheduler.postTask()). Spec PR: whatwg/dom#1032 I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ Bug: 1181925 Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
1 parent 0598a56 commit 7b54a1a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

dom/abort/AbortSignal.any.js

+28
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,31 @@ async_test(t => {
1010
s.onabort = t.unreached_func("abort event handler called");
1111
t.step_timeout(() => { t.done(); }, 2000);
1212
}, "signal returned by AbortSignal.abort() should not fire abort event");
13+
14+
test(t => {
15+
const signal = AbortSignal.timeout(0);
16+
assert_true(signal instanceof AbortSignal, "returned object is an AbortSignal");
17+
assert_false(signal.aborted, "returned signal is not already aborted");
18+
}, "AbortSignal.timeout() returns a non-aborted signal");
19+
20+
async_test(t => {
21+
const signal = AbortSignal.timeout(5);
22+
signal.onabort = t.step_func_done(() => {
23+
assert_true(signal.aborted, "signal is aborted");
24+
assert_true(signal.reason instanceof DOMException, "signal.reason is a DOMException");
25+
assert_equals(signal.reason.name, "TimeoutError", "signal.reason is a TimeoutError");
26+
});
27+
}, "Signal returned by AbortSignal.timeout() times out");
28+
29+
async_test(t => {
30+
let result = "";
31+
for (const value of ["1", "2", "3"]) {
32+
const signal = AbortSignal.timeout(5);
33+
signal.onabort = t.step_func(() => { result += value; });
34+
}
35+
36+
const signal = AbortSignal.timeout(5);
37+
signal.onabort = t.step_func_done(() => {
38+
assert_equals(result, "123", "Timeout order should be 123");
39+
});
40+
}, "AbortSignal timeouts fire in order");

dom/abort/abort-signal-timeout.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE HTML>
2+
<meta charset=utf-8>
3+
<title>AbortSignal.timeout frame detach</title>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<iframe id="iframe"></iframe>
7+
<script>
8+
async_test(t => {
9+
const signal = iframe.contentWindow.AbortSignal.timeout(5);
10+
signal.onabort = t.unreached_func("abort must not fire");
11+
12+
iframe.remove();
13+
14+
t.step_timeout(() => {
15+
assert_false(signal.aborted);
16+
t.done();
17+
}, 10);
18+
}, "Signal returned by AbortSignal.timeout() is not aborted after frame detach");
19+
</script>

0 commit comments

Comments
 (0)