mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibWeb: Don't discard PostedMessage tasks when closing a worker
The spec expects `postMessage()` to act as if it is invoked immediately. Since `postMessage()` isn't actually invoked immediately, keep tasks with source `PostedMessage` in the task queue, so that these tasks are processed. Fixes a hang when `WorkerGlobalScope.close()` is called immediately after `postMessage()`.
This commit is contained in:
committed by
Andreas Kling
parent
d30ae92b82
commit
fd8d350b47
@@ -4,6 +4,7 @@ Text/input/Crypto/SubtleCrypto-exportKey.html
|
|||||||
Text/input/Crypto/SubtleCrypto-generateKey.html
|
Text/input/Crypto/SubtleCrypto-generateKey.html
|
||||||
Text/input/WebAnimations/misc/DocumentTimeline.html
|
Text/input/WebAnimations/misc/DocumentTimeline.html
|
||||||
Text/input/Worker/Worker-blob.html
|
Text/input/Worker/Worker-blob.html
|
||||||
|
Text/input/Worker/Worker-close-after-postMessage.html
|
||||||
Text/input/Worker/Worker-crypto.html
|
Text/input/Worker/Worker-crypto.html
|
||||||
Text/input/Worker/Worker-echo.html
|
Text/input/Worker/Worker-echo.html
|
||||||
Text/input/Worker/Worker-importScripts.html
|
Text/input/Worker/Worker-importScripts.html
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
PASS (didn't hang)
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
asyncTest(done => {
|
||||||
|
let work = new Worker("worker-close-after-postMessage.js");
|
||||||
|
work.onmessage = (evt) => {
|
||||||
|
println(evt.data);
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
work.postMessage("")
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
self.onmessage = function () {
|
||||||
|
postMessage("PASS (didn't hang)");
|
||||||
|
self.close();
|
||||||
|
};
|
||||||
@@ -68,8 +68,9 @@ void WorkerGlobalScope::set_internal_port(JS::NonnullGCPtr<MessagePort> port)
|
|||||||
void WorkerGlobalScope::close_a_worker()
|
void WorkerGlobalScope::close_a_worker()
|
||||||
{
|
{
|
||||||
// 1. Discard any tasks that have been added to workerGlobal's relevant agent's event loop's task queues.
|
// 1. Discard any tasks that have been added to workerGlobal's relevant agent's event loop's task queues.
|
||||||
relevant_settings_object(*this).responsible_event_loop().task_queue().remove_tasks_matching([](HTML::Task const&) {
|
relevant_settings_object(*this).responsible_event_loop().task_queue().remove_tasks_matching([](HTML::Task const& task) {
|
||||||
return true;
|
// NOTE: We don't discard tasks with the PostedMessage source, as the spec expects PostMessage() to act as if it is invoked immediately
|
||||||
|
return task.source() != HTML::Task::Source::PostedMessage;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. Set workerGlobal's closing flag to true. (This prevents any further tasks from being queued.)
|
// 2. Set workerGlobal's closing flag to true. (This prevents any further tasks from being queued.)
|
||||||
|
|||||||
Reference in New Issue
Block a user