LibWeb: Make base URL of HTML::Script Optional

This is a null or a URL in the spec, which we were previously
representing through the invalid state of URL.
This commit is contained in:
Shannon Booth 2025-02-16 15:53:04 +13:00 committed by Tim Flynn
commit 705001483a
Notes: github-actions[bot] 2025-02-19 13:02:39 +00:00
5 changed files with 9 additions and 9 deletions

View file

@ -354,10 +354,10 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
auto& module_script = *as<HTML::Script>(module_record.host_defined());
// 2. Assert: moduleScript's base URL is not null, as moduleScript is a JavaScript module script.
VERIFY(module_script.base_url().is_valid());
VERIFY(module_script.base_url().has_value());
// 3. Let urlString be moduleScript's base URL, serialized.
auto url_string = module_script.base_url().serialize();
auto url_string = module_script.base_url()->serialize();
// 4. Let steps be the following steps, given the argument specifier:
auto steps = [module_script = GC::Ref { module_script }](JS::VM& vm) -> JS::ThrowCompletionOr<JS::Value> {
@ -427,7 +427,7 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
referencing_script = as<HTML::Script>(referrer.has<GC::Ref<JS::Script>>() ? *referrer.get<GC::Ref<JS::Script>>()->host_defined() : *referrer.get<GC::Ref<JS::CyclicModule>>()->host_defined());
// 2. Set fetchReferrer to referencingScript's base URL.
fetch_referrer = referencing_script->base_url();
fetch_referrer = referencing_script->base_url().value();
// FIXME: 3. Set originalFetchOptions to referencingScript's fetch options.

View file

@ -623,7 +623,7 @@ void fetch_internal_module_script_graph(JS::Realm& realm, JS::ModuleRequest cons
// 5. Fetch a single module script given url, fetch client settings object, destination, options, referringScript's settings object's realm,
// referringScript's base URL, moduleRequest, false, and onSingleFetchComplete as defined below. If performFetch was given, pass it along as well.
fetch_single_module_script(realm, url, fetch_client_settings_object, destination, options, referring_script.realm(), referring_script.base_url(), module_request, TopLevelModule::No, perform_fetch, on_single_fetch_complete);
fetch_single_module_script(realm, url, fetch_client_settings_object, destination, options, referring_script.realm(), referring_script.base_url().value(), module_request, TopLevelModule::No, perform_fetch, on_single_fetch_complete);
}
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-the-descendants-of-a-module-script

View file

@ -11,7 +11,7 @@ namespace Web::HTML {
GC_DEFINE_ALLOCATOR(Script);
Script::Script(URL::URL base_url, ByteString filename, JS::Realm& realm)
Script::Script(Optional<URL::URL> base_url, ByteString filename, JS::Realm& realm)
: m_base_url(move(base_url))
, m_filename(move(filename))
, m_realm(realm)

View file

@ -24,7 +24,7 @@ class Script
public:
virtual ~Script() override;
URL::URL const& base_url() const { return m_base_url; }
Optional<URL::URL> const& base_url() const { return m_base_url; }
ByteString const& filename() const { return m_filename; }
JS::Realm& realm() { return m_realm; }
@ -37,14 +37,14 @@ public:
void set_parse_error(JS::Value value) { m_parse_error = value; }
protected:
Script(URL::URL base_url, ByteString filename, JS::Realm&);
Script(Optional<URL::URL> base_url, ByteString filename, JS::Realm&);
virtual void visit_edges(Visitor&) override;
private:
virtual void visit_host_defined_self(JS::Cell::Visitor&) override;
URL::URL m_base_url;
Optional<URL::URL> m_base_url;
ByteString m_filename;
GC::Ref<JS::Realm> m_realm;

View file

@ -329,7 +329,7 @@ i32 WindowOrWorkerGlobalScopeMixin::run_timer_initialization_steps(TimerHandler
// options's credentials mode, referrer policy is initiating script's fetch options's referrer policy, and fetch priority is "auto".
// 2. Set base URL to initiating script's base URL.
base_url = initiating_script->base_url();
base_url = initiating_script->base_url().value();
// Spec Note: The effect of these steps ensures that the string compilation done by setTimeout() and setInterval() behaves equivalently to that
// done by eval(). That is, module script fetches via import() will behave the same in both contexts.