mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibWeb: Change HTML::Script to hold a realm instead of settings object
This is part of a refactor needed for introduction of the shadow realm proposal in the web platform.
This commit is contained in:
parent
0382933a0a
commit
da18551f10
Notes:
github-actions[bot]
2024-11-02 00:56:21 +00:00
Author: https://github.com/shannonbooth
Commit: da18551f10
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1955
Reviewed-by: https://github.com/ADKaster ✅
17 changed files with 164 additions and 155 deletions
|
@ -20,9 +20,8 @@ JS_DEFINE_ALLOCATOR(ClassicScript);
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-classic-script
|
||||
// https://whatpr.org/html/9893/webappapis.html#creating-a-classic-script
|
||||
JS::NonnullGCPtr<ClassicScript> ClassicScript::create(ByteString filename, StringView source, EnvironmentSettingsObject& environment_settings_object, URL::URL base_url, size_t source_line_number, MutedErrors muted_errors)
|
||||
JS::NonnullGCPtr<ClassicScript> ClassicScript::create(ByteString filename, StringView source, JS::Realm& realm, URL::URL base_url, size_t source_line_number, MutedErrors muted_errors)
|
||||
{
|
||||
auto& realm = environment_settings_object.realm();
|
||||
auto& vm = realm.vm();
|
||||
|
||||
// 1. If muted errors is true, then set baseURL to about:blank.
|
||||
|
@ -34,11 +33,9 @@ JS::NonnullGCPtr<ClassicScript> ClassicScript::create(ByteString filename, Strin
|
|||
source = ""sv;
|
||||
|
||||
// 3. Let script be a new classic script that this algorithm will subsequently initialize.
|
||||
auto script = vm.heap().allocate_without_realm<ClassicScript>(move(base_url), move(filename), environment_settings_object);
|
||||
|
||||
// FIXME: 4. Set script's realm to realm. (NOTE: This was already done when constructing.)
|
||||
|
||||
// 5. Set script's base URL to baseURL. (NOTE: This was already done when constructing.)
|
||||
// 4. Set script's realm to realm.
|
||||
// 5. Set script's base URL to baseURL.
|
||||
auto script = vm.heap().allocate_without_realm<ClassicScript>(move(base_url), move(filename), realm);
|
||||
|
||||
// FIXME: 6. Set script's fetch options to options.
|
||||
|
||||
|
@ -80,11 +77,10 @@ JS::NonnullGCPtr<ClassicScript> ClassicScript::create(ByteString filename, Strin
|
|||
// https://whatpr.org/html/9893/webappapis.html#run-a-classic-script
|
||||
JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
|
||||
{
|
||||
// 1. Let settings be the settings object of script.
|
||||
auto& settings = settings_object();
|
||||
auto& realm = settings.realm();
|
||||
// 1. Let realm be the realm of script.
|
||||
auto& realm = this->realm();
|
||||
|
||||
// 2. Check if we can run script with settings. If this returns "do not run" then return NormalCompletion(empty).
|
||||
// 2. Check if we can run script with realm. If this returns "do not run" then return NormalCompletion(empty).
|
||||
if (can_run_script(realm) == RunScriptDecision::DoNotRun)
|
||||
return JS::normal_completion({});
|
||||
|
||||
|
@ -131,8 +127,8 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
|
|||
// 3. Otherwise, rethrow errors is false. Perform the following steps:
|
||||
VERIFY(rethrow_errors == RethrowErrors::No);
|
||||
|
||||
// 1. Report an exception given by evaluationStatus.[[Value]] for script's settings object's global object.
|
||||
auto* window_or_worker = dynamic_cast<WindowOrWorkerGlobalScopeMixin*>(&settings.global_object());
|
||||
// 1. Report an exception given by evaluationStatus.[[Value]] for realms's global object.
|
||||
auto* window_or_worker = dynamic_cast<WindowOrWorkerGlobalScopeMixin*>(&realm.global_object());
|
||||
VERIFY(window_or_worker);
|
||||
window_or_worker->report_an_exception(*evaluation_status.value());
|
||||
|
||||
|
@ -154,8 +150,8 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
|
|||
// Return Completion { [[Type]]: throw, [[Value]]: a new "QuotaExceededError" DOMException, [[Target]]: empty }.
|
||||
}
|
||||
|
||||
ClassicScript::ClassicScript(URL::URL base_url, ByteString filename, EnvironmentSettingsObject& environment_settings_object)
|
||||
: Script(move(base_url), move(filename), environment_settings_object)
|
||||
ClassicScript::ClassicScript(URL::URL base_url, ByteString filename, JS::Realm& realm)
|
||||
: Script(move(base_url), move(filename), realm)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
No,
|
||||
Yes,
|
||||
};
|
||||
static JS::NonnullGCPtr<ClassicScript> create(ByteString filename, StringView source, EnvironmentSettingsObject&, URL::URL base_url, size_t source_line_number = 1, MutedErrors = MutedErrors::No);
|
||||
static JS::NonnullGCPtr<ClassicScript> create(ByteString filename, StringView source, JS::Realm&, URL::URL base_url, size_t source_line_number = 1, MutedErrors = MutedErrors::No);
|
||||
|
||||
JS::Script* script_record() { return m_script_record; }
|
||||
JS::Script const* script_record() const { return m_script_record; }
|
||||
|
@ -38,7 +38,7 @@ public:
|
|||
MutedErrors muted_errors() const { return m_muted_errors; }
|
||||
|
||||
private:
|
||||
ClassicScript(URL::URL base_url, ByteString filename, EnvironmentSettingsObject& environment_settings_object);
|
||||
ClassicScript(URL::URL base_url, ByteString filename, JS::Realm&);
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
|
|
|
@ -260,23 +260,25 @@ bool is_scripting_disabled(JS::Realm const& realm)
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#module-type-allowed
|
||||
bool EnvironmentSettingsObject::module_type_allowed(StringView module_type) const
|
||||
// https://whatpr.org/html/9893/webappapis.html#module-type-allowed
|
||||
bool module_type_allowed(JS::Realm const&, StringView module_type)
|
||||
{
|
||||
// 1. If moduleType is not "javascript", "css", or "json", then return false.
|
||||
if (module_type != "javascript"sv && module_type != "css"sv && module_type != "json"sv)
|
||||
return false;
|
||||
|
||||
// FIXME: 2. If moduleType is "css" and the CSSStyleSheet interface is not exposed in settings's Realm, then return false.
|
||||
// FIXME: 2. If moduleType is "css" and the CSSStyleSheet interface is not exposed in realm, then return false.
|
||||
|
||||
// 3. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#disallow-further-import-maps
|
||||
void EnvironmentSettingsObject::disallow_further_import_maps()
|
||||
// https://whatpr.org/html/9893/webappapis.html#disallow-further-import-maps
|
||||
void disallow_further_import_maps(JS::Realm& realm)
|
||||
{
|
||||
// 1. Let global be settingsObject's global object.
|
||||
auto& global = global_object();
|
||||
// 1. Let global be realm's global object.
|
||||
auto& global = realm.global_object();
|
||||
|
||||
// 2. If global does not implement Window, then return.
|
||||
if (!is<Window>(global))
|
||||
|
|
|
@ -96,10 +96,6 @@ public:
|
|||
// https://fetch.spec.whatwg.org/#concept-fetch-group
|
||||
Vector<JS::NonnullGCPtr<Fetch::Infrastructure::FetchRecord>>& fetch_group() { return m_fetch_group; }
|
||||
|
||||
bool module_type_allowed(StringView module_type) const;
|
||||
|
||||
void disallow_further_import_maps();
|
||||
|
||||
SerializedEnvironmentSettingsObject serialize();
|
||||
|
||||
JS::NonnullGCPtr<StorageAPI::StorageManager> storage_manager();
|
||||
|
@ -142,6 +138,8 @@ void clean_up_after_running_script(JS::Realm const&);
|
|||
void prepare_to_run_callback(JS::Realm&);
|
||||
void clean_up_after_running_callback(JS::Realm const&);
|
||||
ModuleMap& module_map_of_realm(JS::Realm&);
|
||||
bool module_type_allowed(JS::Realm const&, StringView module_type);
|
||||
void disallow_further_import_maps(JS::Realm&);
|
||||
|
||||
EnvironmentSettingsObject& incumbent_settings_object();
|
||||
JS::Realm& incumbent_realm();
|
||||
|
|
|
@ -369,11 +369,11 @@ WebIDL::ExceptionOr<void> fetch_classic_script(JS::NonnullGCPtr<HTMLScriptElemen
|
|||
// 6. Let muted errors be true if response was CORS-cross-origin, and false otherwise.
|
||||
auto muted_errors = response->is_cors_cross_origin() ? ClassicScript::MutedErrors::Yes : ClassicScript::MutedErrors::No;
|
||||
|
||||
// 7. Let script be the result of creating a classic script given source text, settings object, response's URL,
|
||||
// 7. Let script be the result of creating a classic script given source text, settings object's realm, response's URL,
|
||||
// options, and muted errors.
|
||||
// FIXME: Pass options.
|
||||
auto response_url = response->url().value_or({});
|
||||
auto script = ClassicScript::create(response_url.to_byte_string(), source_text, settings_object, response_url, 1, muted_errors);
|
||||
auto script = ClassicScript::create(response_url.to_byte_string(), source_text, settings_object.realm(), response_url, 1, muted_errors);
|
||||
|
||||
// 8. Run onComplete given script.
|
||||
on_complete->function()(script);
|
||||
|
@ -440,10 +440,10 @@ WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL::URL const& url, Envir
|
|||
VERIFY(decoder.has_value());
|
||||
auto source_text = TextCodec::convert_input_to_utf8_using_given_decoder_unless_there_is_a_byte_order_mark(*decoder, body_bytes.template get<ByteBuffer>()).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
// 5. Let script be the result of creating a classic script using sourceText, settingsObject,
|
||||
// 5. Let script be the result of creating a classic script using sourceText, settingsObject's realm,
|
||||
// response's URL, and the default classic script fetch options.
|
||||
auto response_url = response->url().value_or({});
|
||||
auto script = ClassicScript::create(response_url.to_byte_string(), source_text, settings_object, response_url);
|
||||
auto script = ClassicScript::create(response_url.to_byte_string(), source_text, settings_object.realm(), response_url);
|
||||
|
||||
// 6. Run onComplete given script.
|
||||
on_complete->function()(script);
|
||||
|
@ -532,9 +532,9 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ClassicScript>> fetch_a_classic_worker_impo
|
|||
// 9. Let mutedErrors be true if response was CORS-cross-origin, and false otherwise.
|
||||
auto muted_errors = response->is_cors_cross_origin() ? ClassicScript::MutedErrors::Yes : ClassicScript::MutedErrors::No;
|
||||
|
||||
// 10. Let script be the result of creating a classic script given sourceText, settingsObject, response's URL, the default classic script fetch options, and mutedErrors.
|
||||
// 10. Let script be the result of creating a classic script given sourceText, settingsObject's realm, response's URL, the default classic script fetch options, and mutedErrors.
|
||||
auto response_url = response->url().value_or({});
|
||||
auto script = ClassicScript::create(response_url.to_byte_string(), source_text, settings_object, response_url, 1, muted_errors);
|
||||
auto script = ClassicScript::create(response_url.to_byte_string(), source_text, settings_object.realm(), response_url, 1, muted_errors);
|
||||
|
||||
// 11. Return script.
|
||||
return script;
|
||||
|
@ -547,6 +547,7 @@ WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL::URL const& url,
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-worklet/module-worker-script-graph
|
||||
// https://whatpr.org/html/9893/webappapis.html#fetch-a-worklet/module-worker-script-graph
|
||||
WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL::URL const& url, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete)
|
||||
{
|
||||
auto& realm = settings_object.realm();
|
||||
|
@ -578,9 +579,9 @@ WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL::URL cons
|
|||
fetch_descendants_of_and_link_a_module_script(realm, verify_cast<JavaScriptModuleScript>(*result), fetch_client, destination, move(perform_fetch), on_complete);
|
||||
});
|
||||
|
||||
// 2. Fetch a single module script given url, fetchClient, destination, options, settingsObject, "client", true,
|
||||
// 2. Fetch a single module script given url, fetchClient, destination, options, settingsObject's realm, "client", true,
|
||||
// and onSingleFetchComplete as defined below. If performFetch was given, pass it along as well.
|
||||
fetch_single_module_script(realm, url, fetch_client, destination, options, settings_object, Fetch::Infrastructure::Request::Referrer::Client, {}, TopLevelModule::Yes, move(perform_fetch), on_single_fetch_complete);
|
||||
fetch_single_module_script(realm, url, fetch_client, destination, options, settings_object.realm(), Fetch::Infrastructure::Request::Referrer::Client, {}, TopLevelModule::Yes, move(perform_fetch), on_single_fetch_complete);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -613,9 +614,9 @@ void fetch_internal_module_script_graph(JS::Realm& realm, JS::ModuleRequest cons
|
|||
fetch_descendants_of_a_module_script(realm, module_script, fetch_client_settings_object, destination, visited_set, perform_fetch, on_complete);
|
||||
});
|
||||
|
||||
// 5. Fetch a single module script given url, fetch client settings object, destination, options, referringScript's settings object,
|
||||
// 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.settings_object(), 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(), 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
|
||||
|
@ -726,12 +727,13 @@ Fetch::Infrastructure::Request::Destination fetch_destination_from_module_type(F
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
|
||||
// https://whatpr.org/html/9893/webappapis.html#fetch-a-single-module-script
|
||||
void fetch_single_module_script(JS::Realm& realm,
|
||||
URL::URL const& url,
|
||||
EnvironmentSettingsObject& fetch_client,
|
||||
Fetch::Infrastructure::Request::Destination destination,
|
||||
ScriptFetchOptions const& options,
|
||||
EnvironmentSettingsObject& settings_object,
|
||||
JS::Realm& module_map_realm,
|
||||
Web::Fetch::Infrastructure::Request::ReferrerType const& referrer,
|
||||
Optional<JS::ModuleRequest> const& module_request,
|
||||
TopLevelModule is_top_level,
|
||||
|
@ -745,13 +747,13 @@ void fetch_single_module_script(JS::Realm& realm,
|
|||
if (module_request.has_value())
|
||||
module_type = module_type_from_module_request(*module_request);
|
||||
|
||||
// 3. Assert: the result of running the module type allowed steps given moduleType and settingsObject is true.
|
||||
// 3. Assert: the result of running the module type allowed steps given moduleType and moduleMapRealm is true.
|
||||
// Otherwise we would not have reached this point because a failure would have been raised when inspecting moduleRequest.[[Assertions]]
|
||||
// in create a JavaScript module script or fetch a single imported module script.
|
||||
VERIFY(settings_object.module_type_allowed(module_type));
|
||||
VERIFY(module_type_allowed(module_map_realm, module_type));
|
||||
|
||||
// 4. Let moduleMap be settingsObject's module map.
|
||||
auto& module_map = settings_object.module_map();
|
||||
// 4. Let moduleMap be moduleMapRealm's module map.
|
||||
auto& module_map = module_map_of_realm(module_map_realm);
|
||||
|
||||
// 5. If moduleMap[(url, moduleType)] is "fetching", wait in parallel until that entry's value changes,
|
||||
// then queue a task on the networking task source to proceed with running the following steps.
|
||||
|
@ -801,7 +803,7 @@ void fetch_single_module_script(JS::Realm& realm,
|
|||
// 13. If performFetch was given, run performFetch with request, isTopLevel, and with processResponseConsumeBody as defined below.
|
||||
// Otherwise, fetch request with processResponseConsumeBody set to processResponseConsumeBody as defined below.
|
||||
// In both cases, let processResponseConsumeBody given response response and null, failure, or a byte sequence bodyBytes be the following algorithm:
|
||||
auto process_response_consume_body = [&module_map, url, module_type, &settings_object, on_complete](JS::NonnullGCPtr<Fetch::Infrastructure::Response> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) {
|
||||
auto process_response_consume_body = [&module_map, url, module_type, &module_map_realm, on_complete](JS::NonnullGCPtr<Fetch::Infrastructure::Response> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) {
|
||||
// 1. If either of the following conditions are met:
|
||||
// - bodyBytes is null or failure; or
|
||||
// - response's status is not an ok status,
|
||||
|
@ -826,10 +828,10 @@ void fetch_single_module_script(JS::Realm& realm,
|
|||
// FIXME: 5. Let referrerPolicy be the result of parsing the `Referrer-Policy` header given response. [REFERRERPOLICY]
|
||||
// FIXME: 6. If referrerPolicy is not the empty string, set options's referrer policy to referrerPolicy.
|
||||
|
||||
// 7. If mimeType is a JavaScript MIME type and moduleType is "javascript", then set moduleScript to the result of creating a JavaScript module script given sourceText, settingsObject, response's URL, and options.
|
||||
// 7. If mimeType is a JavaScript MIME type and moduleType is "javascript", then set moduleScript to the result of creating a JavaScript module script given sourceText, moduleMapRealm, response's URL, and options.
|
||||
// FIXME: Pass options.
|
||||
if (mime_type->is_javascript() && module_type == "javascript")
|
||||
module_script = JavaScriptModuleScript::create(url.basename(), source_text, settings_object, response->url().value_or({})).release_value_but_fixme_should_propagate_errors();
|
||||
module_script = JavaScriptModuleScript::create(url.basename(), source_text, module_map_realm, response->url().value_or({})).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
// FIXME: 8. If the MIME type essence of mimeType is "text/css" and moduleType is "css", then set moduleScript to the result of creating a CSS module script given sourceText and settingsObject.
|
||||
// FIXME: 9. If mimeType is a JSON MIME type and moduleType is "json", then set moduleScript to the result of creating a JSON module script given sourceText and settingsObject.
|
||||
|
@ -849,10 +851,11 @@ void fetch_single_module_script(JS::Realm& realm,
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree
|
||||
// https://whatpr.org/html/9893/webappapis.html#fetch-a-module-script-tree
|
||||
void fetch_external_module_script_graph(JS::Realm& realm, URL::URL const& url, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const& options, OnFetchScriptComplete on_complete)
|
||||
{
|
||||
// 1. Disallow further import maps given settingsObject.
|
||||
settings_object.disallow_further_import_maps();
|
||||
// 1. Disallow further import maps given settingsObject's realm.
|
||||
disallow_further_import_maps(settings_object.realm());
|
||||
|
||||
auto steps = create_on_fetch_script_complete(realm.heap(), [&realm, &settings_object, on_complete, url](auto result) mutable {
|
||||
// 1. If result is null, run onComplete given null, and abort these steps.
|
||||
|
@ -866,18 +869,19 @@ void fetch_external_module_script_graph(JS::Realm& realm, URL::URL const& url, E
|
|||
fetch_descendants_of_and_link_a_module_script(realm, module_script, settings_object, Fetch::Infrastructure::Request::Destination::Script, nullptr, on_complete);
|
||||
});
|
||||
|
||||
// 2. Fetch a single module script given url, settingsObject, "script", options, settingsObject, "client", true, and with the following steps given result:
|
||||
fetch_single_module_script(realm, url, settings_object, Fetch::Infrastructure::Request::Destination::Script, options, settings_object, Web::Fetch::Infrastructure::Request::Referrer::Client, {}, TopLevelModule::Yes, nullptr, steps);
|
||||
// 2. Fetch a single module script given url, settingsObject, "script", options, settingsObject's realm, "client", true, and with the following steps given result:
|
||||
fetch_single_module_script(realm, url, settings_object, Fetch::Infrastructure::Request::Destination::Script, options, settings_object.realm(), Web::Fetch::Infrastructure::Request::Referrer::Client, {}, TopLevelModule::Yes, nullptr, steps);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-an-inline-module-script-graph
|
||||
// https://whatpr.org/html/9893/webappapis.html#fetch-an-inline-module-script-graph
|
||||
void fetch_inline_module_script_graph(JS::Realm& realm, ByteString const& filename, ByteString const& source_text, URL::URL const& base_url, EnvironmentSettingsObject& settings_object, OnFetchScriptComplete on_complete)
|
||||
{
|
||||
// 1. Disallow further import maps given settingsObject.
|
||||
settings_object.disallow_further_import_maps();
|
||||
// 1. Disallow further import maps given settingsObject's realm.
|
||||
disallow_further_import_maps(settings_object.realm());
|
||||
|
||||
// 2. Let script be the result of creating a JavaScript module script using sourceText, settingsObject, baseURL, and options.
|
||||
auto script = JavaScriptModuleScript::create(filename, source_text.view(), settings_object, base_url).release_value_but_fixme_should_propagate_errors();
|
||||
// 2. Let script be the result of creating a JavaScript module script using sourceText, settingsObject's realm, baseURL, and options.
|
||||
auto script = JavaScriptModuleScript::create(filename, source_text.view(), settings_object.realm(), base_url).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
// 3. If script is null, run onComplete given null, and return.
|
||||
if (!script) {
|
||||
|
@ -895,7 +899,7 @@ void fetch_single_imported_module_script(JS::Realm& realm,
|
|||
EnvironmentSettingsObject& fetch_client,
|
||||
Fetch::Infrastructure::Request::Destination destination,
|
||||
ScriptFetchOptions const& options,
|
||||
EnvironmentSettingsObject& settings_object,
|
||||
JS::Realm& module_map_realm,
|
||||
Fetch::Infrastructure::Request::ReferrerType referrer,
|
||||
JS::ModuleRequest const& module_request,
|
||||
PerformTheFetchHook perform_fetch,
|
||||
|
@ -909,16 +913,16 @@ void fetch_single_imported_module_script(JS::Realm& realm,
|
|||
// 2. Let moduleType be the result of running the module type from module request steps given moduleRequest.
|
||||
auto module_type = module_type_from_module_request(module_request);
|
||||
|
||||
// 3. If the result of running the module type allowed steps given moduleType and settingsObject is false,
|
||||
// 3. If the result of running the module type allowed steps given moduleType and moduleMapRealm is false,
|
||||
// then run onComplete given null, and return.
|
||||
if (!settings_object.module_type_allowed(module_type)) {
|
||||
if (!module_type_allowed(module_map_realm, module_type)) {
|
||||
on_complete->function()(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. Fetch a single module script given url, fetchClient, destination, options, settingsObject, referrer, moduleRequest, false,
|
||||
// 4. Fetch a single module script given url, fetchClient, destination, options, moduleMapRealm, referrer, moduleRequest, false,
|
||||
// and onComplete. If performFetch was given, pass it along as well.
|
||||
fetch_single_module_script(realm, url, fetch_client, destination, options, settings_object, referrer, module_request, TopLevelModule::No, perform_fetch, on_complete);
|
||||
fetch_single_module_script(realm, url, fetch_client, destination, options, module_map_realm, referrer, module_request, TopLevelModule::No, perform_fetch, on_complete);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-the-descendants-of-and-link-a-module-script
|
||||
|
|
|
@ -96,12 +96,12 @@ WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL::URL cons
|
|||
void fetch_internal_module_script_graph(JS::Realm&, JS::ModuleRequest const& module_request, EnvironmentSettingsObject& fetch_client_settings_object, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, Script& referring_script, HashTable<ModuleLocationTuple> const& visited_set, PerformTheFetchHook, OnFetchScriptComplete on_complete);
|
||||
void fetch_external_module_script_graph(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const&, OnFetchScriptComplete on_complete);
|
||||
void fetch_inline_module_script_graph(JS::Realm&, ByteString const& filename, ByteString const& source_text, URL::URL const& base_url, EnvironmentSettingsObject& settings_object, OnFetchScriptComplete on_complete);
|
||||
void fetch_single_imported_module_script(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject& settings_object, Fetch::Infrastructure::Request::ReferrerType, JS::ModuleRequest const&, PerformTheFetchHook, OnFetchScriptComplete on_complete);
|
||||
void fetch_single_imported_module_script(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, JS::Realm& module_map_realm, Fetch::Infrastructure::Request::ReferrerType, JS::ModuleRequest const&, PerformTheFetchHook, OnFetchScriptComplete on_complete);
|
||||
|
||||
void fetch_descendants_of_a_module_script(JS::Realm&, JavaScriptModuleScript& module_script, EnvironmentSettingsObject& fetch_client_settings_object, Fetch::Infrastructure::Request::Destination, HashTable<ModuleLocationTuple> visited_set, PerformTheFetchHook, OnFetchScriptComplete callback);
|
||||
void fetch_descendants_of_and_link_a_module_script(JS::Realm&, JavaScriptModuleScript&, EnvironmentSettingsObject&, Fetch::Infrastructure::Request::Destination, PerformTheFetchHook, OnFetchScriptComplete on_complete);
|
||||
|
||||
Fetch::Infrastructure::Request::Destination fetch_destination_from_module_type(Fetch::Infrastructure::Request::Destination, ByteString const&);
|
||||
|
||||
void fetch_single_module_script(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject& settings_object, Web::Fetch::Infrastructure::Request::ReferrerType const&, Optional<JS::ModuleRequest> const&, TopLevelModule, PerformTheFetchHook, OnFetchScriptComplete callback);
|
||||
void fetch_single_module_script(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, JS::Realm& module_map_realm, Web::Fetch::Infrastructure::Request::ReferrerType const&, Optional<JS::ModuleRequest> const&, TopLevelModule, PerformTheFetchHook, OnFetchScriptComplete callback);
|
||||
}
|
||||
|
|
|
@ -17,36 +17,30 @@ JS_DEFINE_ALLOCATOR(JavaScriptModuleScript);
|
|||
|
||||
ModuleScript::~ModuleScript() = default;
|
||||
|
||||
ModuleScript::ModuleScript(URL::URL base_url, ByteString filename, EnvironmentSettingsObject& environment_settings_object)
|
||||
: Script(move(base_url), move(filename), environment_settings_object)
|
||||
ModuleScript::ModuleScript(URL::URL base_url, ByteString filename, JS::Realm& realm)
|
||||
: Script(move(base_url), move(filename), realm)
|
||||
{
|
||||
}
|
||||
|
||||
JavaScriptModuleScript::~JavaScriptModuleScript() = default;
|
||||
|
||||
JavaScriptModuleScript::JavaScriptModuleScript(URL::URL base_url, ByteString filename, EnvironmentSettingsObject& environment_settings_object)
|
||||
: ModuleScript(move(base_url), move(filename), environment_settings_object)
|
||||
JavaScriptModuleScript::JavaScriptModuleScript(URL::URL base_url, ByteString filename, JS::Realm& realm)
|
||||
: ModuleScript(move(base_url), move(filename), realm)
|
||||
{
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-javascript-module-script
|
||||
// https://whatpr.org/html/9893/webappapis.html#creating-a-javascript-module-script
|
||||
WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::create(ByteString const& filename, StringView source, EnvironmentSettingsObject& settings_object, URL::URL base_url)
|
||||
WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::create(ByteString const& filename, StringView source, JS::Realm& realm, URL::URL base_url)
|
||||
{
|
||||
auto& realm = settings_object.realm();
|
||||
|
||||
// 1. If scripting is disabled for settings, then set source to the empty string.
|
||||
// 1. If scripting is disabled for realm, then set source to the empty string.
|
||||
if (HTML::is_scripting_disabled(realm))
|
||||
source = ""sv;
|
||||
|
||||
// 2. Let script be a new module script that this algorithm will subsequently initialize.
|
||||
auto script = realm.heap().allocate<JavaScriptModuleScript>(realm, move(base_url), filename, settings_object);
|
||||
|
||||
// FIXME: 3. Set script's settings object to settings.
|
||||
// NOTE: This was already done when constructing.
|
||||
|
||||
// 3. Set script's realm to realm.
|
||||
// 4. Set script's base URL to baseURL.
|
||||
// NOTE: This was already done when constructing.
|
||||
auto script = realm.heap().allocate<JavaScriptModuleScript>(realm, move(base_url), filename, realm);
|
||||
|
||||
// FIXME: 5. Set script's fetch options to options.
|
||||
|
||||
|
@ -100,8 +94,8 @@ WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::c
|
|||
// 4. Let moduleType be the result of running the module type from module request steps given requested.
|
||||
auto module_type = module_type_from_module_request(requested);
|
||||
|
||||
// 5. If the result of running the module type allowed steps given moduleType and settings is false, then:
|
||||
if (!settings_object.module_type_allowed(module_type)) {
|
||||
// 5. If the result of running the module type allowed steps given moduleType and realm is false, then:
|
||||
if (!module_type_allowed(realm, module_type)) {
|
||||
// FIXME: 1. Let error be a new TypeError exception.
|
||||
|
||||
// FIXME: 2. Set script's parse error to error.
|
||||
|
@ -122,13 +116,12 @@ WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::c
|
|||
// https://whatpr.org/html/9893/webappapis.html#run-a-module-script
|
||||
JS::Promise* JavaScriptModuleScript::run(PreventErrorReporting)
|
||||
{
|
||||
// 1. Let settings be the settings object of script.
|
||||
auto& settings = settings_object();
|
||||
auto& realm = settings.realm();
|
||||
// 1. Let realm be the realm of script.
|
||||
auto& realm = this->realm();
|
||||
|
||||
// 2. Check if we can run script with realm. If this returns "do not run", then return a promise resolved with undefined.
|
||||
if (can_run_script(realm) == RunScriptDecision::DoNotRun) {
|
||||
auto promise = JS::Promise::create(settings.realm());
|
||||
auto promise = JS::Promise::create(realm);
|
||||
promise->fulfill(JS::js_undefined());
|
||||
return promise;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
virtual ~ModuleScript() override;
|
||||
|
||||
protected:
|
||||
ModuleScript(URL::URL base_url, ByteString filename, EnvironmentSettingsObject& environment_settings_object);
|
||||
ModuleScript(URL::URL base_url, ByteString filename, JS::Realm&);
|
||||
};
|
||||
|
||||
class JavaScriptModuleScript final : public ModuleScript {
|
||||
|
@ -29,7 +29,7 @@ class JavaScriptModuleScript final : public ModuleScript {
|
|||
public:
|
||||
virtual ~JavaScriptModuleScript() override;
|
||||
|
||||
static WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> create(ByteString const& filename, StringView source, EnvironmentSettingsObject&, URL::URL base_url);
|
||||
static WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> create(ByteString const& filename, StringView source, JS::Realm&, URL::URL base_url);
|
||||
|
||||
enum class PreventErrorReporting {
|
||||
Yes,
|
||||
|
@ -42,7 +42,7 @@ public:
|
|||
JS::SourceTextModule* record() { return m_record.ptr(); }
|
||||
|
||||
protected:
|
||||
JavaScriptModuleScript(URL::URL base_url, ByteString filename, EnvironmentSettingsObject& environment_settings_object);
|
||||
JavaScriptModuleScript(URL::URL base_url, ByteString filename, JS::Realm&);
|
||||
|
||||
private:
|
||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||
|
|
|
@ -11,15 +11,22 @@ namespace Web::HTML {
|
|||
|
||||
JS_DEFINE_ALLOCATOR(Script);
|
||||
|
||||
Script::Script(URL::URL base_url, ByteString filename, EnvironmentSettingsObject& environment_settings_object)
|
||||
Script::Script(URL::URL base_url, ByteString filename, JS::Realm& realm)
|
||||
: m_base_url(move(base_url))
|
||||
, m_filename(move(filename))
|
||||
, m_settings_object(environment_settings_object)
|
||||
, m_realm(realm)
|
||||
{
|
||||
}
|
||||
|
||||
Script::~Script() = default;
|
||||
|
||||
// https://whatpr.org/html/9893/webappapis.html#settings-object
|
||||
EnvironmentSettingsObject& Script::settings_object()
|
||||
{
|
||||
// The settings object of a script is the settings object of the principal realm of the script's realm.
|
||||
return principal_realm_settings_object(principal_realm(realm()));
|
||||
}
|
||||
|
||||
void Script::visit_host_defined_self(JS::Cell::Visitor& visitor)
|
||||
{
|
||||
visitor.visit(*this);
|
||||
|
@ -28,7 +35,7 @@ void Script::visit_host_defined_self(JS::Cell::Visitor& visitor)
|
|||
void Script::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_settings_object);
|
||||
visitor.visit(m_realm);
|
||||
visitor.visit(m_parse_error);
|
||||
visitor.visit(m_error_to_rethrow);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script
|
||||
// https://whatpr.org/html/9893/webappapis.html#concept-script
|
||||
class Script
|
||||
: public JS::Cell
|
||||
, public JS::Script::HostDefined {
|
||||
|
@ -26,7 +27,8 @@ public:
|
|||
URL::URL const& base_url() const { return m_base_url; }
|
||||
ByteString const& filename() const { return m_filename; }
|
||||
|
||||
EnvironmentSettingsObject& settings_object() { return m_settings_object; }
|
||||
JS::Realm& realm() { return m_realm; }
|
||||
EnvironmentSettingsObject& settings_object();
|
||||
|
||||
[[nodiscard]] JS::Value error_to_rethrow() const { return m_error_to_rethrow; }
|
||||
void set_error_to_rethrow(JS::Value value) { m_error_to_rethrow = value; }
|
||||
|
@ -35,7 +37,7 @@ public:
|
|||
void set_parse_error(JS::Value value) { m_parse_error = value; }
|
||||
|
||||
protected:
|
||||
Script(URL::URL base_url, ByteString filename, EnvironmentSettingsObject& environment_settings_object);
|
||||
Script(URL::URL base_url, ByteString filename, JS::Realm&);
|
||||
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
|
@ -44,7 +46,7 @@ private:
|
|||
|
||||
URL::URL m_base_url;
|
||||
ByteString m_filename;
|
||||
JS::NonnullGCPtr<EnvironmentSettingsObject> m_settings_object;
|
||||
JS::NonnullGCPtr<JS::Realm> m_realm;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-parse-error
|
||||
JS::Value m_parse_error;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue