Truly independent web browser
LibWeb: Require a consuming intent of algorithms that consume a body
Luke Wildeff738769d9ca
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cppindex 8caffa67504..a56d245c853 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp@@ -16,6 +16,9 @@ GC_DEFINE_ALLOCATOR(FetchAlgorithms);GC::Ref<FetchAlgorithms> FetchAlgorithms::create(Input input){+ auto has_consuming_intent = input.body_intent == Engine::BodyIntent::ConsumeForCallback || input.body_intent == Engine::BodyIntent::SyncAccumulate;+ VERIFY(has_consuming_intent || !input.process_response_consume_body);+return GC::Heap::the().allocate<FetchAlgorithms>(input.body_intent,input.process_request_body_chunk_length,diff --git a/Tests/LibWeb/TestFetchAlgorithms.cpp b/Tests/LibWeb/TestFetchAlgorithms.cppindex bf73da60156..e36a69c7ae1 100644--- a/Tests/LibWeb/TestFetchAlgorithms.cpp+++ b/Tests/LibWeb/TestFetchAlgorithms.cpp@@ -1066,3 +1066,21 @@ TEST_CASE(a_fetch_reads_the_network_activity_observers_of_its_agent)agent.network_activity_observers->page_did_lose_devtools_client();EXPECT(!fetch_params->engine_record()->network_activity_observers().has_devtools_client());}++TEST_CASE(algorithms_that_consume_a_body_need_a_consuming_intent)+{+ Core::EventLoop event_loop;+ install_font_plugin();+ FetchHarness harness;++ auto& heap = harness.realm->heap();+ auto algorithms_that_consume_a_body = [&heap](Web::Fetch::Engine::BodyIntent body_intent) {+ FetchAlgorithms::Input input { body_intent };+ input.process_response_consume_body = GC::create_function(heap, [](GC::Ref<ResponseView>, FetchAlgorithms::BodyBytes) { });+ return FetchAlgorithms::create(move(input));+ };++ EXPECT_DEATH("algorithms that consume a body have a consuming intent", (void)algorithms_that_consume_a_body(Web::Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent));+ EXPECT_DEATH("algorithms that consume a body have a consuming intent", (void)algorithms_that_consume_a_body(Web::Fetch::Engine::BodyIntent::DrainAndDiscard));+ EXPECT_EQ(algorithms_that_consume_a_body(Web::Fetch::Engine::BodyIntent::SyncAccumulate)->body_intent(), Web::Fetch::Engine::BodyIntent::SyncAccumulate);+}