Repository: servo/servo
File: components/script/module_loading.rs (Rust)

Code before:
                            .get_or_insert(parse_error.clone());
                    });

                    // 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_scope,
            referrer_module,
            specifier,
            payload,
            completion,
        );
    };

    // Step 14 Fetch a single imported module script given url, fetchClient, destination, fetchOptions, settingsObject,
    // fetchReferrer, moduleRequest, and onSingleFetchComplete as defined below.
    // If loadState is not undefined and loadState.[[PerformFetch]] is not null, pass loadState.[[PerformFetch]] along as well.
    // Note: we don't have access to the requested `ModuleObject`, so we pass only it's type.
    fetch_a_single_imported_module_script(
        url.unwrap(),
        fetch_client,
        destination,
        fetch_options,
        fetch_referrer,
        module_type,
        on_single_fetch_complete,
    );
}

/// <https://html.spec.whatwg.org/multipage/#fetch-a-single-imported-module-script>
fn fetch_a_single_imported_module_script(
    url: ServoUrl,
    owner: ModuleOwner,
    destination: Destination,
    options: ScriptFetchOptions,
    referrer: Referrer,
    module_type: ModuleType,
    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.

    // TODO Step 2. Let moduleType be the result of running the module type from module request steps given moduleRequest.

Review comment (suggestion):
```suggestion
    // Note: we don't have access to the requested `ModuleObject`, so we pass only its type.
```

Code after:
                            .get_or_insert(parse_error.clone());
                    });

                    // 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_scope,
            referrer_module,
            specifier,
            payload,
            completion,
        );
    };

    // Step 14 Fetch a single imported module script given url, fetchClient, destination, fetchOptions, settingsObject,
    // fetchReferrer, moduleRequest, and onSingleFetchComplete as defined below.
    // If loadState is not undefined and loadState.[[PerformFetch]] is not null, pass loadState.[[PerformFetch]] along as well.
    // Note: we don't have access to the requested `ModuleObject`, so we pass only its type.
    fetch_a_single_imported_module_script(
        url.unwrap(),
        fetch_client,
        destination,
        fetch_options,
        fetch_referrer,
        module_type,
        on_single_fetch_complete,
    );
}

/// <https://html.spec.whatwg.org/multipage/#fetch-a-single-imported-module-script>
fn fetch_a_single_imported_module_script(
    url: ServoUrl,
    owner: ModuleOwner,
    destination: Destination,
    options: ScriptFetchOptions,
    referrer: Referrer,
    module_type: ModuleType,
    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.

    // TODO Step 2. Let moduleType be the result of running the module type from module request steps given moduleRequest.