mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:07:45 +00:00
LibWeb: Make processBodyError
take an optional exception
Changed here:
018ac19838
This commit is contained in:
parent
ae5bb13f1f
commit
9c2d496dbe
10 changed files with 21 additions and 25 deletions
|
@ -158,13 +158,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> consume_body(JS::Realm& realm
|
|||
|
||||
// 3. Let errorSteps given error be to reject promise with error.
|
||||
// NOTE: `promise` and `realm` is protected by JS::SafeFunction.
|
||||
auto error_steps = [promise, &realm](JS::Object& error) {
|
||||
auto error_steps = [promise, &realm](JS::GCPtr<WebIDL::DOMException> error) {
|
||||
// NOTE: Not part of the spec, but we need to have an execution context on the stack to call native functions.
|
||||
// (In this case, Promise's reject function)
|
||||
auto& environment_settings_object = Bindings::host_defined_environment_settings_object(realm);
|
||||
environment_settings_object.prepare_to_run_script();
|
||||
|
||||
WebIDL::reject_promise(realm, promise, &error);
|
||||
WebIDL::reject_promise(realm, promise, error);
|
||||
|
||||
// See above NOTE.
|
||||
environment_settings_object.clean_up_after_running_script();
|
||||
|
|
|
@ -481,27 +481,21 @@ WebIDL::ExceptionOr<Optional<JS::NonnullGCPtr<PendingResponse>>> main_fetch(JS::
|
|||
if (!request->integrity_metadata().is_empty()) {
|
||||
// 1. Let processBodyError be this step: run fetch response handover given fetchParams and a network
|
||||
// error.
|
||||
// FIXME: The spec disagrees on whether fully_read()'s process_body_error should take an argument or not.
|
||||
// See https://github.com/whatwg/fetch/issues/1636
|
||||
// For now, define two versions of processBodyError
|
||||
auto process_body_error_no_argument = [&realm, &vm, &fetch_params]() {
|
||||
TRY_OR_IGNORE(fetch_response_handover(realm, fetch_params, Infrastructure::Response::network_error(vm, "Response body could not be processed"sv)));
|
||||
};
|
||||
Infrastructure::Body::ProcessBodyErrorCallback process_body_error = [&realm, &vm, &fetch_params](auto&) {
|
||||
Infrastructure::Body::ProcessBodyErrorCallback process_body_error = [&realm, &vm, &fetch_params](auto) {
|
||||
TRY_OR_IGNORE(fetch_response_handover(realm, fetch_params, Infrastructure::Response::network_error(vm, "Response body could not be processed"sv)));
|
||||
};
|
||||
|
||||
// 2. If response’s body is null, then run processBodyError and abort these steps.
|
||||
if (!response->body().has_value()) {
|
||||
process_body_error_no_argument();
|
||||
process_body_error({});
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Let processBody given bytes be these steps:
|
||||
Infrastructure::Body::ProcessBodyCallback process_body = [&realm, &request, &response, &fetch_params, process_body_error = move(process_body_error_no_argument)](ByteBuffer bytes) {
|
||||
Infrastructure::Body::ProcessBodyCallback process_body = [&realm, &request, &response, &fetch_params, process_body_error = move(process_body_error)](ByteBuffer bytes) {
|
||||
// 1. If bytes do not match request’s integrity metadata, then run processBodyError and abort these steps.
|
||||
if (!TRY_OR_IGNORE(SRI::do_bytes_match_metadata_list(bytes, request->integrity_metadata()))) {
|
||||
process_body_error();
|
||||
process_body_error({});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -657,7 +651,7 @@ WebIDL::ExceptionOr<void> fetch_response_handover(JS::Realm& realm, Infrastructu
|
|||
|
||||
// 2. Let processBodyError be this step: run fetchParams’s process response consume body given response and
|
||||
// failure.
|
||||
auto process_body_error = [&fetch_params, &response](auto&) {
|
||||
auto process_body_error = [&fetch_params, &response](auto) {
|
||||
(*fetch_params.algorithms()->process_response_consume_body())(response, Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {});
|
||||
};
|
||||
|
||||
|
|
|
@ -57,10 +57,10 @@ WebIDL::ExceptionOr<void> Body::fully_read(JS::Realm& realm, Web::Fetch::Infrast
|
|||
return {};
|
||||
};
|
||||
|
||||
// 3. Let errorSteps be to queue a fetch task to run processBodyError, with taskDestination.
|
||||
auto error_steps = [process_body_error = move(process_body_error), task_destination_object = JS::make_handle(task_destination_object)](JS::Error& error) mutable {
|
||||
queue_fetch_task(*task_destination_object, [process_body_error = move(process_body_error), error = JS::make_handle(error)]() {
|
||||
process_body_error(*error);
|
||||
// 3. Let errorSteps optionally given an exception exception be to queue a fetch task to run processBodyError given exception, with taskDestination.
|
||||
auto error_steps = [process_body_error = move(process_body_error), task_destination_object = JS::make_handle(task_destination_object)](JS::GCPtr<WebIDL::DOMException> exception) mutable {
|
||||
queue_fetch_task(*task_destination_object, [process_body_error = move(process_body_error), exception = JS::make_handle(exception)]() {
|
||||
process_body_error(*exception);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -71,7 +71,7 @@ WebIDL::ExceptionOr<void> Body::fully_read(JS::Realm& realm, Web::Fetch::Infrast
|
|||
TRY_OR_THROW_OOM(vm, success_steps(*byte_buffer));
|
||||
} else {
|
||||
// Empty, Blob, FormData
|
||||
error_steps(TRY(JS::InternalError::create(realm, "Reading from Blob, FormData or null source is not yet implemented"sv)));
|
||||
error_steps(WebIDL::DOMException::create(realm, "DOMException", "Reading from Blob, FormData or null source is not yet implemented"sv));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -24,8 +24,10 @@ namespace Web::Fetch::Infrastructure {
|
|||
class Body final {
|
||||
public:
|
||||
using SourceType = Variant<Empty, ByteBuffer, JS::Handle<FileAPI::Blob>>;
|
||||
// processBody must be an algorithm accepting a byte sequence.
|
||||
using ProcessBodyCallback = JS::SafeFunction<void(ByteBuffer)>;
|
||||
using ProcessBodyErrorCallback = JS::SafeFunction<void(JS::Object&)>;
|
||||
// processBodyError must be an algorithm optionally accepting an exception.
|
||||
using ProcessBodyErrorCallback = JS::SafeFunction<void(JS::GCPtr<WebIDL::DOMException>)>;
|
||||
|
||||
explicit Body(JS::Handle<Streams::ReadableStream>);
|
||||
Body(JS::Handle<Streams::ReadableStream>, SourceType, Optional<u64>);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue