@@ -90,18 +90,7 @@ void Request::set_url(URL::URL url)
9090// https://fetch.spec.whatwg.org/#request-destination-script-like
9191bool Request::destination_is_script_like () const
9292{
93- // A request’s destination is script-like if it is "audioworklet", "paintworklet", "script", "serviceworker", "sharedworker", or "worker".
94- static constexpr Array script_like_destinations = {
95- Destination::AudioWorklet,
96- Destination::PaintWorklet,
97- Destination::Script,
98- Destination::ServiceWorker,
99- Destination::SharedWorker,
100- Destination::Worker,
101- };
102- return any_of (script_like_destinations, [this ](auto destination) {
103- return m_destination == destination;
104- });
93+ return m_destination.has_value () && Infrastructure::destination_is_script_like (*m_destination);
10594}
10695
10796// https://fetch.spec.whatwg.org/#subresource-request
@@ -452,6 +441,76 @@ StringView request_destination_to_string(Request::Destination destination)
452441 VERIFY_NOT_REACHED ();
453442}
454443
444+ // https://fetch.spec.whatwg.org/#concept-potential-destination-translate
445+ Optional<Request::Destination> translate_potential_destination (StringView potential_destination)
446+ {
447+ // 1. If potentialDestination is "fetch", then return the empty string.
448+ if (potential_destination == " fetch" sv)
449+ return {};
450+
451+ // 2. Assert: potentialDestination is a destination.
452+ // 3. Return potentialDestination.
453+ if (potential_destination == " audio" sv)
454+ return Request::Destination::Audio;
455+ if (potential_destination == " audioworklet" sv)
456+ return Request::Destination::AudioWorklet;
457+ if (potential_destination == " document" sv)
458+ return Request::Destination::Document;
459+ if (potential_destination == " embed" sv)
460+ return Request::Destination::Embed;
461+ if (potential_destination == " font" sv)
462+ return Request::Destination::Font;
463+ if (potential_destination == " frame" sv)
464+ return Request::Destination::Frame;
465+ if (potential_destination == " iframe" sv)
466+ return Request::Destination::IFrame;
467+ if (potential_destination == " image" sv)
468+ return Request::Destination::Image;
469+ if (potential_destination == " json" sv)
470+ return Request::Destination::JSON;
471+ if (potential_destination == " manifest" sv)
472+ return Request::Destination::Manifest;
473+ if (potential_destination == " object" sv)
474+ return Request::Destination::Object;
475+ if (potential_destination == " paintworklet" sv)
476+ return Request::Destination::PaintWorklet;
477+ if (potential_destination == " report" sv)
478+ return Request::Destination::Report;
479+ if (potential_destination == " script" sv)
480+ return Request::Destination::Script;
481+ if (potential_destination == " serviceworker" sv)
482+ return Request::Destination::ServiceWorker;
483+ if (potential_destination == " sharedworker" sv)
484+ return Request::Destination::SharedWorker;
485+ if (potential_destination == " style" sv)
486+ return Request::Destination::Style;
487+ if (potential_destination == " track" sv)
488+ return Request::Destination::Track;
489+ if (potential_destination == " video" sv)
490+ return Request::Destination::Video;
491+ if (potential_destination == " webidentity" sv)
492+ return Request::Destination::WebIdentity;
493+ if (potential_destination == " worker" sv)
494+ return Request::Destination::Worker;
495+ if (potential_destination == " xslt" sv)
496+ return Request::Destination::XSLT;
497+ VERIFY_NOT_REACHED ();
498+ }
499+
500+ // https://fetch.spec.whatwg.org/#request-destination-script-like
501+ bool destination_is_script_like (Request::Destination destination)
502+ {
503+ // A request’s destination is script-like if it is "audioworklet", "paintworklet", "script", "serviceworker",
504+ // "sharedworker", or "worker".
505+ return first_is_one_of (destination,
506+ Request::Destination::AudioWorklet,
507+ Request::Destination::PaintWorklet,
508+ Request::Destination::Script,
509+ Request::Destination::ServiceWorker,
510+ Request::Destination::SharedWorker,
511+ Request::Destination::Worker);
512+ }
513+
455514StringView request_mode_to_string (Request::Mode mode)
456515{
457516 switch (mode) {
0 commit comments