Lightpanda: the headless browser designed for AI and automation
resolve timing issues within LockManager
Muki Kiboigo9965e27b85a9
diff --git a/src/browser/tests/weblocks.html b/src/browser/tests/weblocks.htmlindex c8d679e30..942c9563e 100644--- a/src/browser/tests/weblocks.html+++ b/src/browser/tests/weblocks.html@@ -417,6 +417,28 @@}</script>+<script id=stealDoesNotDrainMicrotasksSynchronously type=module>+{+ const state = await testing.async();+ const order = [];++ navigator.locks.request('c', () => {+ order.push('A');+ navigator.locks.request('c', { steal: true }, () => {});+ order.push('B');+ return new Promise(() => {});+ }).catch(() => order.push('C'));++ setTimeout(() => {+ state.resolve(order.join(','));+ }, 50);++ await state.done((v) => {+ testing.expectEqual('A,B,C', v);+ });+}+</script>+<script id=queryReportsHeldAndPending type=module>{const state = await testing.async();diff --git a/src/browser/webapi/LockManager.zig b/src/browser/webapi/LockManager.zigindex 3c92a8380..4f900c7b9 100644--- a/src/browser/webapi/LockManager.zig+++ b/src/browser/webapi/LockManager.zig@@ -25,6 +25,7 @@ const js = @import("../js/js.zig");const Frame = @import("../Frame.zig");const Execution = @import("../js/Execution.zig");const AbortSignal = @import("AbortSignal.zig");+const DOMException = @import("DOMException.zig");const Lock = @import("Lock.zig");@@ -313,10 +314,18 @@ pub fn request(_ = self._locks.orderedRemove(i);const lock_resolver = lr.resolver.local(lr.exec.js.local.?);- lock_resolver.rejectError(- "steal weblock",- .{ .dom_exception = .{ .err = error.AbortError } },- );+ const exception = DOMException.fromError(error.AbortError) orelse unreachable;+ if (lock_resolver.local.zigValueToJs(exception, .{})) |js_val| {+ // Use rejectValue (no microtask drain): the stealing+ // script may still be on the stack (e.g. steal called+ // from within the held lock's own callback), and+ // draining here would run unrelated reactions mid-script.+ lock_resolver.rejectValue(js_val) catch |err| {+ log.err(.bug, "steal weblock", .{ .err = err, .persistent = false });+ };+ } else |err| {+ log.err(.bug, "steal weblock", .{ .err = err, .persistent = false });+ }lr.finished = true;lr.deinit();