mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 17:31:58 -05:00
LibWeb: Handle abort signal in CloseWatcher
(cherry picked from commit e27c59047a0deebf132ab0822db32cfe064c14ad)
This commit is contained in:
parent
513cac67d9
commit
ab385f8321
7 changed files with 71 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
|||
false
|
||||
false
|
|
@ -0,0 +1,2 @@
|
|||
false
|
||||
false
|
2
Tests/LibWeb/Text/expected/CloseWatcher-fire-once.txt
Normal file
2
Tests/LibWeb/Text/expected/CloseWatcher-fire-once.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
1
|
||||
1
|
18
Tests/LibWeb/Text/input/CloseWatcher-abort-requestClose.html
Normal file
18
Tests/LibWeb/Text/input/CloseWatcher-abort-requestClose.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
let controller = new AbortController();
|
||||
let watcher = new CloseWatcher({ signal: controller.signal });
|
||||
let oncancel_called = false;
|
||||
let onclose_called = false;
|
||||
watcher.oncancel = () => oncancel_called = true;
|
||||
watcher.onclose = () => onclose_called = true;
|
||||
|
||||
controller.abort();
|
||||
watcher.requestClose();
|
||||
|
||||
println(oncancel_called);
|
||||
println(onclose_called);
|
||||
});
|
||||
</script>
|
17
Tests/LibWeb/Text/input/CloseWatcher-already-aborted.html
Normal file
17
Tests/LibWeb/Text/input/CloseWatcher-already-aborted.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
let watcher = new CloseWatcher({ signal: AbortSignal.abort() });
|
||||
let oncancel_called = false;
|
||||
let onclose_called = false;
|
||||
watcher.oncancel = () => oncancel_called = true;
|
||||
watcher.onclose = () => onclose_called = true;
|
||||
|
||||
watcher.requestClose();
|
||||
|
||||
println(oncancel_called);
|
||||
println(onclose_called);
|
||||
});
|
||||
|
||||
</script>
|
18
Tests/LibWeb/Text/input/CloseWatcher-fire-once.html
Normal file
18
Tests/LibWeb/Text/input/CloseWatcher-fire-once.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
let controller = new AbortController();
|
||||
let watcher = new CloseWatcher({ signal: controller.signal });
|
||||
let oncancel_call_count_ = 0;
|
||||
let onclose_call_count_ = 0;
|
||||
watcher.oncancel = () => oncancel_call_count_++;
|
||||
watcher.onclose = () => onclose_call_count_++;
|
||||
|
||||
watcher.requestClose();
|
||||
controller.abort();
|
||||
|
||||
println(oncancel_call_count_);
|
||||
println(onclose_call_count_);
|
||||
})
|
||||
</script>
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2024, the Ladybird developers.
|
||||
* Copyright (c) 2024, Felipe Muñoz Mazur <felipe.munoz.mazur@protonmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -57,9 +58,17 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CloseWatcher>> CloseWatcher::construct_impl
|
|||
auto close_watcher = establish(window);
|
||||
|
||||
// 3. If options["signal"] exists, then:
|
||||
if (options.signal) {
|
||||
// FIXME: 3.1 If options["signal"]'s aborted, then destroy closeWatcher.
|
||||
// FIXME: 3.2 Add the following steps to options["signal"]:
|
||||
if (auto signal = options.signal) {
|
||||
// 3.1 If options["signal"]'s aborted, then destroy closeWatcher.
|
||||
if (signal->aborted()) {
|
||||
close_watcher->destroy();
|
||||
}
|
||||
|
||||
// 3.2 Add the following steps to options["signal"]:
|
||||
signal->add_abort_algorithm([close_watcher] {
|
||||
// 3.2.1 Destroy closeWatcher.
|
||||
close_watcher->destroy();
|
||||
});
|
||||
}
|
||||
|
||||
return close_watcher;
|
||||
|
|
Loading…
Reference in a new issue