mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:17:44 +00:00
LibJS+LibWeb: Another round of bringing module loading closer to spec
In particular, this patch focuses on: - Updating the old "import assertions" to the new "import attributes" - Allowing realms as module import referrer
This commit is contained in:
parent
82977ab44b
commit
07f567cd9f
14 changed files with 244 additions and 178 deletions
|
@ -397,8 +397,8 @@ ErrorOr<void> initialize_main_thread_vm()
|
|||
// FIXME: Implement 8.1.5.5.2 HostImportModuleDynamically(referencingScriptOrModule, moduleRequest, promiseCapability), https://html.spec.whatwg.org/multipage/webappapis.html#hostimportmoduledynamically(referencingscriptormodule,-modulerequest,-promisecapability)
|
||||
// FIXME: Implement 8.1.5.5.3 HostResolveImportedModule(referencingScriptOrModule, moduleRequest), https://html.spec.whatwg.org/multipage/webappapis.html#hostresolveimportedmodule(referencingscriptormodule,-modulerequest)
|
||||
|
||||
// 8.1.5.5.4 HostGetSupportedImportAssertions(), https://html.spec.whatwg.org/multipage/webappapis.html#hostgetsupportedimportassertions
|
||||
s_main_thread_vm->host_get_supported_import_assertions = []() -> Vector<DeprecatedString> {
|
||||
// 8.1.6.5.2 HostGetSupportedImportAttributes(), https://html.spec.whatwg.org/multipage/webappapis.html#hostgetsupportedimportassertions
|
||||
s_main_thread_vm->host_get_supported_import_attributes = []() -> Vector<DeprecatedString> {
|
||||
// 1. Return « "type" ».
|
||||
return { "type"sv };
|
||||
};
|
||||
|
@ -515,15 +515,14 @@ ErrorOr<void> initialize_main_thread_vm()
|
|||
};
|
||||
|
||||
// 8.1.6.5.3 HostResolveImportedModule(referencingScriptOrModule, moduleRequest), https://html.spec.whatwg.org/multipage/webappapis.html#hostresolveimportedmodule(referencingscriptormodule,-modulerequest)
|
||||
s_main_thread_vm->host_resolve_imported_module = [](JS::ScriptOrModule const& referencing_string_or_module, JS::ModuleRequest const& module_request) -> JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Module>> {
|
||||
s_main_thread_vm->host_resolve_imported_module = [](JS::ImportedModuleReferrer referrer, JS::ModuleRequest const& module_request) -> JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Module>> {
|
||||
// 1. Let moduleMap and referencingScript be null.
|
||||
Optional<HTML::ModuleMap&> module_map;
|
||||
Optional<HTML::Script&> referencing_script;
|
||||
|
||||
// 2. If referencingScriptOrModule is not null, then:
|
||||
if (!referencing_string_or_module.has<Empty>()) {
|
||||
if (referrer.has<JS::NonnullGCPtr<JS::Script>>() || referrer.has<JS::NonnullGCPtr<JS::CyclicModule>>()) {
|
||||
// 1. Set referencingScript to referencingScriptOrModule.[[HostDefined]].
|
||||
referencing_script = verify_cast<HTML::Script>(referencing_string_or_module.has<JS::NonnullGCPtr<JS::Script>>() ? *referencing_string_or_module.get<JS::NonnullGCPtr<JS::Script>>()->host_defined() : *referencing_string_or_module.get<JS::NonnullGCPtr<JS::Module>>()->host_defined());
|
||||
referencing_script = verify_cast<HTML::Script>(referrer.has<JS::NonnullGCPtr<JS::Script>>() ? *referrer.get<JS::NonnullGCPtr<JS::Script>>()->host_defined() : *referrer.get<JS::NonnullGCPtr<JS::CyclicModule>>()->host_defined());
|
||||
|
||||
// 2. Set moduleMap to referencingScript's settings object's module map.
|
||||
module_map = referencing_script->settings_object().module_map();
|
||||
|
|
|
@ -59,8 +59,8 @@ DeprecatedString module_type_from_module_request(JS::ModuleRequest const& module
|
|||
// 1. Let moduleType be "javascript".
|
||||
DeprecatedString module_type = "javascript"sv;
|
||||
|
||||
// 2. If moduleRequest.[[Assertions]] has a Record entry such that entry.[[Key]] is "type", then:
|
||||
for (auto const& entry : module_request.assertions) {
|
||||
// 2. If moduleRequest.[[Attributes]] has a Record entry such that entry.[[Key]] is "type", then:
|
||||
for (auto const& entry : module_request.attributes) {
|
||||
if (entry.key != "type"sv)
|
||||
continue;
|
||||
|
||||
|
@ -719,7 +719,7 @@ void fetch_single_imported_module_script(JS::Realm& realm,
|
|||
{
|
||||
// 1. Assert: moduleRequest.[[Attributes]] does not contain any Record entry such that entry.[[Key]] is not "type",
|
||||
// because we only asked for "type" attributes in HostGetSupportedImportAttributes.
|
||||
for (auto const& entry : module_request.assertions)
|
||||
for (auto const& entry : module_request.attributes)
|
||||
VERIFY(entry.key == "type"sv);
|
||||
|
||||
// 2. Let moduleType be the result of running the module type from module request steps given moduleRequest.
|
||||
|
|
|
@ -68,17 +68,27 @@ WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::c
|
|||
return script;
|
||||
}
|
||||
|
||||
// 10. For each ModuleRequest record requested of result.[[RequestedModules]]:
|
||||
// 9. For each ModuleRequest record requested of result.[[RequestedModules]]:
|
||||
for (auto const& requested : result.value()->requested_modules()) {
|
||||
// FIXME: Clarify if this should be checked for all requested before running the steps below.
|
||||
// 9. Assert: requested.[[Assertions]] does not contain any Record entry such that entry.[[Key]] is not "type",
|
||||
// because we only asked for "type" assertions in HostGetSupportedImportAssertions.
|
||||
VERIFY(all_of(requested.assertions, [](auto const& assertion) { return assertion.key == "type"sv; }));
|
||||
// 1. If requested.[[Attributes]] contains a Record entry such that entry.[[Key]] is not "type", then:
|
||||
for (auto const& attribute : requested.attributes) {
|
||||
if (attribute.key != "type"sv) {
|
||||
// 1. Let error be a new SyntaxError exception.
|
||||
auto error = JS::SyntaxError::create(settings_object.realm(), "Module request attributes must only contain a type attribute"_fly_string);
|
||||
|
||||
// 1. Let url be the result of resolving a module specifier given script and requested.[[Specifier]], catching any exceptions.
|
||||
// 2. Set script's parse error to error.
|
||||
script->set_parse_error(error);
|
||||
|
||||
// 3. Return script.
|
||||
return script;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Let url be the result of resolving a module specifier given script and requested.[[Specifier]], catching any exceptions.
|
||||
auto url = resolve_module_specifier(*script, requested.module_specifier);
|
||||
|
||||
// 2. If the previous step threw an exception, then:
|
||||
// 3. If the previous step threw an exception, then:
|
||||
if (url.is_exception()) {
|
||||
// FIXME: 1. Set script's parse error to that exception.
|
||||
|
||||
|
@ -86,10 +96,10 @@ WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::c
|
|||
return script;
|
||||
}
|
||||
|
||||
// 3. Let moduleType be the result of running the module type from module request steps given requested.
|
||||
// 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);
|
||||
|
||||
// 4. If the result of running the module type allowed steps given moduleType and settings is false, then:
|
||||
// 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)) {
|
||||
// FIXME: 1. Let error be a new TypeError exception.
|
||||
|
||||
|
@ -100,10 +110,10 @@ WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::c
|
|||
}
|
||||
}
|
||||
|
||||
// 11. Set script's record to result.
|
||||
// 10. Set script's record to result.
|
||||
script->m_record = result.value();
|
||||
|
||||
// 12. Return script.
|
||||
// 11. Return script.
|
||||
return script;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue