mirror of
https://github.com/servo/servo
synced 2026-05-03 04:42:17 +02:00
script: Drop ModuleTree network_error and simplify pending fetches logic (#42127)
Since we use `NetworkError` just for logging reasons, we don't really need to pass it around; instead lets follow spec more closely and pass a `None` on network failures. Make more explicit if a `modulemap` entry is currently fetching or ready. Testing: No functional change, covered by existing tests --------- Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
This commit is contained in:
@@ -450,12 +450,12 @@ pub(crate) fn host_load_imported_module(
|
||||
|
||||
// Step 9.1. If loadState is not undefined and loadState.[[ErrorToRethrow]] is null,
|
||||
// set loadState.[[ErrorToRethrow]] to resolutionError.
|
||||
if let Some(load_state) = load_state {
|
||||
load_state.as_ref().inspect(|load_state| {
|
||||
load_state
|
||||
.error_to_rethrow
|
||||
.borrow_mut()
|
||||
.get_or_insert(resolution_error.clone());
|
||||
}
|
||||
});
|
||||
|
||||
// Step 9.2. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, ThrowCompletion(resolutionError)).
|
||||
finish_loading_imported_module(
|
||||
@@ -488,43 +488,45 @@ pub(crate) fn host_load_imported_module(
|
||||
),
|
||||
};
|
||||
|
||||
let on_single_fetch_complete = move |global: &GlobalScope, module_tree: Rc<ModuleTree>| {
|
||||
let on_single_fetch_complete = move |module_tree: Option<Rc<ModuleTree>>| {
|
||||
// Step 1. Let completion be null.
|
||||
// Step 2. If moduleScript is null, then set completion to ThrowCompletion(a new TypeError).
|
||||
let completion = if module_tree.get_network_error().is_some() {
|
||||
Err(gen_type_error(
|
||||
global,
|
||||
let completion = match module_tree {
|
||||
// Step 2. If moduleScript is null, then set completion to ThrowCompletion(a new TypeError).
|
||||
None => Err(gen_type_error(
|
||||
&global_scope,
|
||||
Error::Type("Module fetching failed".to_string()),
|
||||
CanGc::note(),
|
||||
))
|
||||
} else {
|
||||
// Step 3. Otherwise, if moduleScript's parse error is not null, then:
|
||||
// Step 3.1 Let parseError be moduleScript's parse error.
|
||||
if let Some(parse_error) = module_tree.get_parse_error() {
|
||||
// Step 3.3 If loadState is not undefined and loadState.[[ErrorToRethrow]] is null,
|
||||
// set loadState.[[ErrorToRethrow]] to parseError.
|
||||
if let Some(load_state) = load_state {
|
||||
load_state
|
||||
.error_to_rethrow
|
||||
.borrow_mut()
|
||||
.get_or_insert(parse_error.clone());
|
||||
}
|
||||
)),
|
||||
Some(module_tree) => {
|
||||
// Step 3. Otherwise, if moduleScript's parse error is not null, then:
|
||||
// Step 3.1 Let parseError be moduleScript's parse error.
|
||||
if let Some(parse_error) = module_tree.get_parse_error() {
|
||||
// Step 3.3 If loadState is not undefined and loadState.[[ErrorToRethrow]] is null,
|
||||
// set loadState.[[ErrorToRethrow]] to parseError.
|
||||
load_state.as_ref().inspect(|load_state| {
|
||||
load_state
|
||||
.error_to_rethrow
|
||||
.borrow_mut()
|
||||
.get_or_insert(parse_error.clone());
|
||||
});
|
||||
|
||||
// Step 3.2 Set completion to ThrowCompletion(parseError).
|
||||
Err(parse_error.clone())
|
||||
} else {
|
||||
assert!(
|
||||
module_tree
|
||||
.get_record()
|
||||
.is_some_and(|record| !record.handle().is_null())
|
||||
);
|
||||
// Step 4. Otherwise, set completion to NormalCompletion(moduleScript's record).
|
||||
Ok(module_tree)
|
||||
}
|
||||
// Step 3.2 Set completion to ThrowCompletion(parseError).
|
||||
Err(parse_error.clone())
|
||||
} else {
|
||||
// Step 4. Otherwise, set completion to NormalCompletion(moduleScript's record).
|
||||
Ok(module_tree)
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// Step 5. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, completion).
|
||||
finish_loading_imported_module(global, referrer_module, specifier, payload, completion);
|
||||
finish_loading_imported_module(
|
||||
&global_scope,
|
||||
referrer_module,
|
||||
specifier,
|
||||
payload,
|
||||
completion,
|
||||
);
|
||||
};
|
||||
|
||||
// Step 14 Fetch a single imported module script given url, fetchClient, destination, fetchOptions, settingsObject,
|
||||
@@ -547,7 +549,7 @@ fn fetch_a_single_imported_module_script(
|
||||
destination: Destination,
|
||||
options: ScriptFetchOptions,
|
||||
referrer: Referrer,
|
||||
on_complete: impl FnOnce(&GlobalScope, Rc<ModuleTree>) + 'static,
|
||||
on_complete: impl FnOnce(Option<Rc<ModuleTree>>) + 'static,
|
||||
) {
|
||||
// TODO Step 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.
|
||||
|
||||
Reference in New Issue
Block a user