Skip to content

Commit 037fff2

Browse files
Web Locks: If aborted due to an AbortSignal, use signal's reason
Updated in the spec a year ago[1], if the AbortSignal has a reason, use that as the rejection, rather than a stock AbortError w/ hardcoded message. The WPTs didn't cover verifying the reason for an already-aborted signal, so add coverage for those cases too. [1] w3c/web-locks#86 Bug: 1279877 Change-Id: I9838805b10dbb3dae0371abe41faf922344a43f3
1 parent a0ed458 commit 037fff2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

web-locks/signal.tentative.https.any.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,36 @@ promise_test(async t => {
2929
'Request should reject with AbortError');
3030
}, 'Passing an already aborted signal aborts');
3131

32+
promise_test(async t => {
33+
const res = uniqueName(t);
34+
35+
const controller = new AbortController();
36+
const reason = 'My dog ate it.';
37+
controller.abort(reason);
38+
39+
const promise =
40+
navigator.locks.request(res, {signal: controller.signal},
41+
t.unreached_func('callback should not run'));
42+
43+
await promise_rejects_exactly(
44+
t, reason, promise, "Rejection should give the abort reason");
45+
}, 'Passing an already aborted signal rejects with the custom abort reason.');
46+
47+
promise_test(async t => {
48+
const res = uniqueName(t);
49+
50+
const controller = new AbortController();
51+
controller.abort();
52+
53+
const promise =
54+
navigator.locks.request(res, {signal: controller.signal},
55+
t.unreached_func('callback should not run'));
56+
57+
await promise_rejects_exactly(
58+
t, controller.signal.reason, promise,
59+
"Rejection should give the abort reason");
60+
}, 'Passing an already aborted signal rejects with the default abort reason.');
61+
3262
promise_test(async t => {
3363
const res = uniqueName(t);
3464

0 commit comments

Comments
 (0)