Skip to content

Commit

Permalink
Web Locks: If aborted due to an AbortSignal, use signal's reason
Browse files Browse the repository at this point in the history
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
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4112925
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1084556}
  • Loading branch information
inexorabletash authored and chromium-wpt-export-bot committed Dec 16, 2022
1 parent 51bf605 commit 9ce4a64
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions web-locks/signal.tentative.https.any.js
Expand Up @@ -29,6 +29,36 @@ promise_test(async t => {
'Request should reject with AbortError');
}, 'Passing an already aborted signal aborts');

promise_test(async t => {
const res = uniqueName(t);

const controller = new AbortController();
const reason = 'My dog ate it.';
controller.abort(reason);

const promise =
navigator.locks.request(res, {signal: controller.signal},
t.unreached_func('callback should not run'));

await promise_rejects_exactly(
t, reason, promise, "Rejection should give the abort reason");
}, 'Passing an already aborted signal rejects with the custom abort reason.');

promise_test(async t => {
const res = uniqueName(t);

const controller = new AbortController();
controller.abort();

const promise =
navigator.locks.request(res, {signal: controller.signal},
t.unreached_func('callback should not run'));

await promise_rejects_exactly(
t, controller.signal.reason, promise,
"Rejection should give the abort reason");
}, 'Passing an already aborted signal rejects with the default abort reason.');

promise_test(async t => {
const res = uniqueName(t);

Expand Down

0 comments on commit 9ce4a64

Please sign in to comment.