@@ -84,7 +84,6 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
8484 dbgln_if (WEB_FETCH_DEBUG , " Fetch: Running 'fetch' with: request @ {}" , &request);
8585
8686 auto & vm = realm.vm ();
87- auto & heap = vm.heap ();
8887
8988 // 1. Assert: request’s mode is "navigate" or processEarlyHintsResponse is null.
9089 VERIFY (request.mode () == Infrastructure::Request::Mode::Navigate || !algorithms.process_early_hints_response ());
@@ -95,7 +94,10 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
9594 // 3. Let crossOriginIsolatedCapability be false.
9695 auto cross_origin_isolated_capability = HTML ::CanUseCrossOriginIsolatedAPIs::No;
9796
98- // 4. If request’s client is non-null, then:
97+ // 4. Populate request from client given request.
98+ populate_request_from_client (realm, request);
99+
100+ // 5. If request’s client is non-null, then:
99101 if (request.client () != nullptr ) {
100102 // 1. Set taskDestination to request’s client’s global object.
101103 task_destination = GC ::Ref { request.client ()->global_object () };
@@ -104,11 +106,11 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
104106 cross_origin_isolated_capability = request.client ()->cross_origin_isolated_capability ();
105107 }
106108
107- // 5 . If useParallelQueue is true, then set taskDestination to the result of starting a new parallel queue.
109+ // 6 . If useParallelQueue is true, then set taskDestination to the result of starting a new parallel queue.
108110 if (use_parallel_queue == UseParallelQueue::Yes)
109111 task_destination = HTML::ParallelQueue::create ();
110112
111- // 6 . Let timingInfo be a new fetch timing info whose start time and post-redirect start time are the coarsened
113+ // 7 . Let timingInfo be a new fetch timing info whose start time and post-redirect start time are the coarsened
112114 // shared current time given crossOriginIsolatedCapability, and render-blocking is set to request’s
113115 // render-blocking.
114116 auto timing_info = Infrastructure::FetchTimingInfo::create (vm);
@@ -117,7 +119,7 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
117119 timing_info->set_post_redirect_start_time (now);
118120 timing_info->set_render_blocking (request.render_blocking ());
119121
120- // 7 . Let fetchParams be a new fetch params whose request is request, timing info is timingInfo, process request
122+ // 8 . Let fetchParams be a new fetch params whose request is request, timing info is timingInfo, process request
121123 // body chunk length is processRequestBodyChunkLength, process request end-of-body is processRequestEndOfBody,
122124 // process early hints response is processEarlyHintsResponse, process response is processResponse, process
123125 // response consume body is processResponseConsumeBody, process response end-of-body is processResponseEndOfBody,
@@ -127,34 +129,18 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
127129 fetch_params->set_task_destination (task_destination);
128130 fetch_params->set_cross_origin_isolated_capability (cross_origin_isolated_capability);
129131
130- // 8 . If request’s body is a byte sequence, then set request’s body to request’s body as a body.
132+ // 9 . If request’s body is a byte sequence, then set request’s body to request’s body as a body.
131133 if (auto const * buffer = request.body ().get_pointer <ByteBuffer>())
132134 request.set_body (Infrastructure::byte_sequence_as_body (realm, buffer->bytes ()));
133135
134- // 9. If request’s window is "client", then set request’s window to request’s client, if request’s client’s global
135- // object is a Window object; otherwise "no-window".
136- auto const * window = request.traversable_for_user_prompts ().get_pointer <Infrastructure::Request::TraversableForUserPrompts>();
137- if (window && *window == Infrastructure::Request::TraversableForUserPrompts::Client) {
138- if (is<HTML ::Window>(request.client ()->global_object ())) {
139- request.set_traversable_for_user_prompts (request.client ());
140- } else {
141- request.set_traversable_for_user_prompts (Infrastructure::Request::TraversableForUserPrompts::NoTraversable);
142- }
143- }
144-
145- // 10. If request’s origin is "client", then set request’s origin to request’s client’s origin.
146- auto const * origin = request.origin ().get_pointer <Infrastructure::Request::Origin>();
147- if (origin && *origin == Infrastructure::Request::Origin::Client)
148- request.set_origin (request.client ()->origin ());
149-
150- // 11. If all of the following conditions are true:
136+ // 10. If all of the following conditions are true:
151137 if (
152138 // - request’s URL’s scheme is an HTTP(S) scheme
153139 Infrastructure::is_http_or_https_scheme (request.url ().scheme ())
154140 // - request’s mode is "same-origin", "cors", or "no-cors"
155141 && (request.mode () == Infrastructure::Request::Mode::SameOrigin || request.mode () == Infrastructure::Request::Mode::CORS || request.mode () == Infrastructure::Request::Mode::NoCORS)
156- // - request’s window is an environment settings object
157- && request.traversable_for_user_prompts (). has < GC ::Ptr< HTML ::EnvironmentSettingsObject>>( )
142+ // - request’s client is not null, and request’s client’s global object is a Window object
143+ && request.client () && is< HTML ::Window>(request. client ()-> global_object () )
158144 // - request’s method is `GET`
159145 && StringView { request.method () }.equals_ignoring_ascii_case (" GET" sv)
160146 // - request’s unsafe-request flag is not set or request’s header list is empty
@@ -180,20 +166,7 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
180166 fetch_params->set_preloaded_response_candidate (Infrastructure::FetchParams::PreloadedResponseCandidatePendingTag {});
181167 }
182168
183- // 12. If request’s policy container is "client", then:
184- auto const * policy_container = request.policy_container ().get_pointer <Infrastructure::Request::PolicyContainer>();
185- if (policy_container) {
186- VERIFY (*policy_container == Infrastructure::Request::PolicyContainer::Client);
187- // 1. If request’s client is non-null, then set request’s policy container to a clone of request’s client’s
188- // policy container.
189- if (request.client () != nullptr )
190- request.set_policy_container (request.client ()->policy_container ()->clone (heap));
191- // 2. Otherwise, set request’s policy container to a new policy container.
192- else
193- request.set_policy_container (heap.allocate <HTML ::PolicyContainer>(heap));
194- }
195-
196- // 13. If request’s header list does not contain `Accept`, then:
169+ // 11. If request’s header list does not contain `Accept`, then:
197170 if (!request.header_list ()->contains (" Accept" sv.bytes ())) {
198171 // 1. Let value be `*/*`.
199172 auto value = " */*" sv;
@@ -240,7 +213,7 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
240213 request.header_list ()->append (move (header));
241214 }
242215
243- // 14 . If request’s header list does not contain `Accept-Language`, then user agents should append
216+ // 12 . If request’s header list does not contain `Accept-Language`, then user agents should append
244217 // (`Accept-Language, an appropriate header value) to request’s header list.
245218 if (!request.header_list ()->contains (" Accept-Language" sv.bytes ())) {
246219 StringBuilder accept_language;
@@ -250,24 +223,25 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
250223 request.header_list ()->append (move (header));
251224 }
252225
253- // 15. If request’s priority is null, then use request’s initiator, destination, and render-blocking appropriately
254- // in setting request’s priority to a user-agent-defined object.
226+ // 13. If request’s internal priority is null, then use request’s priority, initiator, destination, and
227+ // render-blocking in an implementation-defined manner to set request’s internal priority to an
228+ // implementation-defined object.
255229 // NOTE: The user-agent-defined object could encompass stream weight and dependency for HTTP/2, and equivalent
256230 // information used to prioritize dispatch and processing of HTTP/1 fetches.
257231
258- // 16 . If request is a subresource request, then:
232+ // 14 . If request is a subresource request, then:
259233 if (request.is_subresource_request ()) {
260234 // 1. Let record be a new fetch record whose request is request and controller is fetchParams’s controller.
261235 auto record = Infrastructure::FetchRecord::create (vm, request, fetch_params->controller ());
262236
263- // 2. Append record to request’s client’s fetch group list of fetch records.
237+ // 2. Append record to request’s client’s fetch group’s fetch records.
264238 request.client ()->fetch_group ().append (record);
265239 }
266240
267- // 17 . Run main fetch given fetchParams.
241+ // 15 . Run main fetch given fetchParams.
268242 (void )TRY (main_fetch (realm, fetch_params));
269243
270- // 18 . Return fetchParams’s controller.
244+ // 16 . Return fetchParams’s controller.
271245 return fetch_params->controller ();
272246}
273247
0 commit comments