From 9ce4a6482a088da3d74f895d8ad15c5ce0c25d28 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Fri, 16 Dec 2022 14:19:27 -0800 Subject: [PATCH] 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] https://github.com/w3c/web-locks/pull/86 Bug: 1279877 Change-Id: I9838805b10dbb3dae0371abe41faf922344a43f3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4112925 Reviewed-by: Ayu Ishii Reviewed-by: Tom Sepez Commit-Queue: Joshua Bell Cr-Commit-Position: refs/heads/main@{#1084556} --- web-locks/signal.tentative.https.any.js | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/web-locks/signal.tentative.https.any.js b/web-locks/signal.tentative.https.any.js index cbb23df8a0567f..5a37e3ae87182e 100644 --- a/web-locks/signal.tentative.https.any.js +++ b/web-locks/signal.tentative.https.any.js @@ -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);