From 968c38e54fb3a51cd74f8796b23f17523635ee12 Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Fri, 22 Nov 2024 12:30:16 +0100 Subject: [PATCH] LibWeb: Implement FetchController::abort() --- .../Fetch/Infrastructure/FetchController.cpp | 12 ++++++++--- .../Fetch/Infrastructure/FetchController.h | 4 +++- .../expected/Fetch/fetch-controller-abort.txt | 2 ++ .../input/Fetch/fetch-controller-abort.html | 20 +++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/Fetch/fetch-controller-abort.txt create mode 100644 Tests/LibWeb/Text/input/Fetch/fetch-controller-abort.html diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp index 1bb6754d404..26f0299c61a 100644 --- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp +++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp @@ -85,9 +85,15 @@ void FetchController::abort(JS::Realm& realm, Optional error) if (!error.has_value()) error = fallback_error; - // FIXME: 4. Let serializedError be StructuredSerialize(error). If that threw an exception, catch it, and let serializedError be StructuredSerialize(fallbackError). - // FIXME: 5. Set controller’s serialized abort reason to serializedError. - (void)error; + // 4. Let serializedError be StructuredSerialize(error). If that threw an exception, catch it, and let serializedError be StructuredSerialize(fallbackError). + // 5. Set controller’s serialized abort reason to serializedError + auto structured_serialize = [](JS::VM& vm, JS::Value error, JS::Value fallback_error) { + auto serialized_value_or_error = HTML::structured_serialize(vm, error); + return serialized_value_or_error.is_error() + ? HTML::structured_serialize(vm, fallback_error).value() + : serialized_value_or_error.value(); + }; + m_serialized_abort_reason = structured_serialize(realm.vm(), error.value(), fallback_error); } // FIXME: https://fetch.spec.whatwg.org/#deserialize-a-serialized-abort-reason diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h index 52a4a46d3d2..cbefaa2ffd8 100644 --- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h +++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h @@ -16,6 +16,7 @@ #include #include #include +#include namespace Web::Fetch::Infrastructure { @@ -74,8 +75,9 @@ private: GC::Ptr> m_report_timing_steps; // https://fetch.spec.whatwg.org/#fetch-controller-report-timing-steps - // FIXME: serialized abort reason (default null) + // serialized abort reason (default null) // Null or a Record (result of StructuredSerialize). + HTML::SerializationRecord m_serialized_abort_reason; // https://fetch.spec.whatwg.org/#fetch-controller-next-manual-redirect-steps // next manual redirect steps (default null) diff --git a/Tests/LibWeb/Text/expected/Fetch/fetch-controller-abort.txt b/Tests/LibWeb/Text/expected/Fetch/fetch-controller-abort.txt new file mode 100644 index 00000000000..3267f26c896 --- /dev/null +++ b/Tests/LibWeb/Text/expected/Fetch/fetch-controller-abort.txt @@ -0,0 +1,2 @@ +AbortError: Aborted without reason +Abort with a reason diff --git a/Tests/LibWeb/Text/input/Fetch/fetch-controller-abort.html b/Tests/LibWeb/Text/input/Fetch/fetch-controller-abort.html new file mode 100644 index 00000000000..55fc7ed175e --- /dev/null +++ b/Tests/LibWeb/Text/input/Fetch/fetch-controller-abort.html @@ -0,0 +1,20 @@ + + +