mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:58:11 +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
|
@ -219,7 +219,7 @@ JS::GCPtr<DOM::Document> load_document(Optional<HTML::NavigationParams> navigati
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto process_body_error = [](auto&) {
|
auto process_body_error = [](auto) {
|
||||||
// FIXME: Load html page with an error if read of body failed.
|
// FIXME: Load html page with an error if read of body failed.
|
||||||
TODO();
|
TODO();
|
||||||
};
|
};
|
||||||
|
|
|
@ -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.
|
// 3. Let errorSteps given error be to reject promise with error.
|
||||||
// NOTE: `promise` and `realm` is protected by JS::SafeFunction.
|
// 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.
|
// 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)
|
// (In this case, Promise's reject function)
|
||||||
auto& environment_settings_object = Bindings::host_defined_environment_settings_object(realm);
|
auto& environment_settings_object = Bindings::host_defined_environment_settings_object(realm);
|
||||||
environment_settings_object.prepare_to_run_script();
|
environment_settings_object.prepare_to_run_script();
|
||||||
|
|
||||||
WebIDL::reject_promise(realm, promise, &error);
|
WebIDL::reject_promise(realm, promise, error);
|
||||||
|
|
||||||
// See above NOTE.
|
// See above NOTE.
|
||||||
environment_settings_object.clean_up_after_running_script();
|
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()) {
|
if (!request->integrity_metadata().is_empty()) {
|
||||||
// 1. Let processBodyError be this step: run fetch response handover given fetchParams and a network
|
// 1. Let processBodyError be this step: run fetch response handover given fetchParams and a network
|
||||||
// error.
|
// error.
|
||||||
// FIXME: The spec disagrees on whether fully_read()'s process_body_error should take an argument or not.
|
Infrastructure::Body::ProcessBodyErrorCallback process_body_error = [&realm, &vm, &fetch_params](auto) {
|
||||||
// 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&) {
|
|
||||||
TRY_OR_IGNORE(fetch_response_handover(realm, fetch_params, Infrastructure::Response::network_error(vm, "Response body could not be processed"sv)));
|
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.
|
// 2. If response’s body is null, then run processBodyError and abort these steps.
|
||||||
if (!response->body().has_value()) {
|
if (!response->body().has_value()) {
|
||||||
process_body_error_no_argument();
|
process_body_error({});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Let processBody given bytes be these steps:
|
// 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.
|
// 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()))) {
|
if (!TRY_OR_IGNORE(SRI::do_bytes_match_metadata_list(bytes, request->integrity_metadata()))) {
|
||||||
process_body_error();
|
process_body_error({});
|
||||||
return;
|
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
|
// 2. Let processBodyError be this step: run fetchParams’s process response consume body given response and
|
||||||
// failure.
|
// 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 {});
|
(*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 {};
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
// 3. Let errorSteps be to queue a fetch task to run processBodyError, with taskDestination.
|
// 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::Error& error) mutable {
|
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), error = JS::make_handle(error)]() {
|
queue_fetch_task(*task_destination_object, [process_body_error = move(process_body_error), exception = JS::make_handle(exception)]() {
|
||||||
process_body_error(*error);
|
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));
|
TRY_OR_THROW_OOM(vm, success_steps(*byte_buffer));
|
||||||
} else {
|
} else {
|
||||||
// Empty, Blob, FormData
|
// 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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,10 @@ namespace Web::Fetch::Infrastructure {
|
||||||
class Body final {
|
class Body final {
|
||||||
public:
|
public:
|
||||||
using SourceType = Variant<Empty, ByteBuffer, JS::Handle<FileAPI::Blob>>;
|
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 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>);
|
explicit Body(JS::Handle<Streams::ReadableStream>);
|
||||||
Body(JS::Handle<Streams::ReadableStream>, SourceType, Optional<u64>);
|
Body(JS::Handle<Streams::ReadableStream>, SourceType, Optional<u64>);
|
||||||
|
|
|
@ -480,7 +480,7 @@ after_step_6:
|
||||||
auto process_body = [image_request, url_string, this](ByteBuffer data) {
|
auto process_body = [image_request, url_string, this](ByteBuffer data) {
|
||||||
handle_successful_fetch(url_string, image_request, move(data));
|
handle_successful_fetch(url_string, image_request, move(data));
|
||||||
};
|
};
|
||||||
auto process_body_error = [this](auto&) {
|
auto process_body_error = [this](auto) {
|
||||||
handle_failed_fetch();
|
handle_failed_fetch();
|
||||||
};
|
};
|
||||||
// FIXME: See HTMLLinkElement::default_fetch_and_process_linked_resource for thorough notes on the workaround
|
// FIXME: See HTMLLinkElement::default_fetch_and_process_linked_resource for thorough notes on the workaround
|
||||||
|
|
|
@ -324,7 +324,7 @@ void HTMLLinkElement::default_fetch_and_process_linked_resource()
|
||||||
};
|
};
|
||||||
|
|
||||||
// NOTE: `this` and `unsafe_response` are protected by `fully_read` using JS::SafeFunction.
|
// NOTE: `this` and `unsafe_response` are protected by `fully_read` using JS::SafeFunction.
|
||||||
auto process_body_error = [this, unsafe_response](auto&) {
|
auto process_body_error = [this, unsafe_response](auto) {
|
||||||
process_linked_resource(false, unsafe_response, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {});
|
process_linked_resource(false, unsafe_response, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -875,7 +875,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::fetch_resource(AK::URL const& url_re
|
||||||
}
|
}
|
||||||
|
|
||||||
VERIFY(response->body().has_value());
|
VERIFY(response->body().has_value());
|
||||||
auto empty_algorithm = [](auto&) {};
|
auto empty_algorithm = [](auto) {};
|
||||||
|
|
||||||
// FIXME: We are "fully" reading the response here, rather than "incrementally". Memory concerns aside, this should be okay for now as we are
|
// FIXME: We are "fully" reading the response here, rather than "incrementally". Memory concerns aside, this should be okay for now as we are
|
||||||
// always setting byteRange to "entire resource". However, we should switch to incremental reads when that is implemented, and then
|
// always setting byteRange to "entire resource". However, we should switch to incremental reads when that is implemented, and then
|
||||||
|
|
|
@ -195,7 +195,7 @@ WebIDL::ExceptionOr<void> HTMLVideoElement::determine_element_poster_frame(Optio
|
||||||
};
|
};
|
||||||
|
|
||||||
VERIFY(response->body().has_value());
|
VERIFY(response->body().has_value());
|
||||||
auto empty_algorithm = [](auto&) {};
|
auto empty_algorithm = [](auto) {};
|
||||||
|
|
||||||
response->body()->fully_read(realm, move(on_image_data_read), move(empty_algorithm), JS::NonnullGCPtr { global }).release_value_but_fixme_should_propagate_errors();
|
response->body()->fully_read(realm, move(on_image_data_read), move(empty_algorithm), JS::NonnullGCPtr { global }).release_value_but_fixme_should_propagate_errors();
|
||||||
};
|
};
|
||||||
|
|
|
@ -326,7 +326,7 @@ WebIDL::ExceptionOr<void> fetch_classic_script(JS::NonnullGCPtr<HTMLScriptElemen
|
||||||
auto process_body = [response, response_handler](auto bytes) {
|
auto process_body = [response, response_handler](auto bytes) {
|
||||||
response_handler->process_response(response, move(bytes));
|
response_handler->process_response(response, move(bytes));
|
||||||
};
|
};
|
||||||
auto process_body_error = [response, response_handler](auto&) {
|
auto process_body_error = [response, response_handler](auto) {
|
||||||
response_handler->process_response(response, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {});
|
response_handler->process_response(response, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue