mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibWeb: Implement FetchController::abort()
This commit is contained in:
parent
4c5019f89c
commit
968c38e54f
Notes:
github-actions[bot]
2024-11-24 10:12:37 +00:00
Author: https://github.com/kennethmyhra Commit: https://github.com/LadybirdBrowser/ladybird/commit/968c38e54fb Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2532
4 changed files with 34 additions and 4 deletions
|
@ -85,9 +85,15 @@ void FetchController::abort(JS::Realm& realm, Optional<JS::Value> 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
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/EventLoop/Task.h>
|
||||
#include <LibWeb/HTML/StructuredSerialize.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
||||
|
@ -74,8 +75,9 @@ private:
|
|||
GC::Ptr<GC::Function<void(JS::Object const&)>> 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)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
AbortError: Aborted without reason
|
||||
Abort with a reason
|
20
Tests/LibWeb/Text/input/Fetch/fetch-controller-abort.html
Normal file
20
Tests/LibWeb/Text/input/Fetch/fetch-controller-abort.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const runAbortController = ((reason) => {
|
||||
let controller = new AbortController();
|
||||
let signal = controller.signal;
|
||||
|
||||
fetch('data:text/plain,fetched from far', { signal })
|
||||
.catch(err => {
|
||||
println(err);
|
||||
});
|
||||
|
||||
controller.abort(reason);
|
||||
});
|
||||
|
||||
runAbortController(undefined);
|
||||
runAbortController("Abort with a reason");
|
||||
});
|
||||
</script>
|
Loading…
Add table
Reference in a new issue