// 2. If parsed is not an ordered map, then throw a TypeError indicating that the top-level value needs to be a JSON object.
if(!parsed.is_object())
returnWebIDL::SimpleException{WebIDL::SimpleExceptionType::TypeError,String::formatted("The top-level value of an importmap needs to be a JSON object.").release_value_but_fixme_should_propagate_errors()};
auto&parsed_object=parsed.as_object();
// 3. Let sortedAndNormalizedImports be an empty ordered map.
ModuleSpecifierMapsorted_and_normalised_imports;
// 4. If parsed["imports"] exists, then:
if(TRY(parsed_object.has_property("imports"))){
autoimports=TRY(parsed_object.get("imports"));
// If parsed["imports"] is not an ordered map, then throw a TypeError indicating that the value for the "imports" top-level key needs to be a JSON object.
if(!imports.is_object())
returnWebIDL::SimpleException{WebIDL::SimpleExceptionType::TypeError,String::formatted("The 'imports' top-level value of an importmap needs to be a JSON object.").release_value_but_fixme_should_propagate_errors()};
// Set sortedAndNormalizedImports to the result of sorting and normalizing a module specifier map given parsed["imports"] and baseURL.
// If parsed["scopes"] is not an ordered map, then throw a TypeError indicating that the value for the "scopes" top-level key needs to be a JSON object.
if(!scopes.is_object())
returnWebIDL::SimpleException{WebIDL::SimpleExceptionType::TypeError,String::formatted("The 'scopes' top-level value of an importmap needs to be a JSON object.").release_value_but_fixme_should_propagate_errors()};
// Set sortedAndNormalizedScopes to the result of sorting and normalizing scopes given parsed["scopes"] and baseURL.
// 1. If parsed["integrity"] is not an ordered map, then throw a TypeError indicating that the value for the "integrity" top-level key needs to be a JSON object.
if(!integrity.is_object())
returnWebIDL::SimpleException{WebIDL::SimpleExceptionType::TypeError,String::formatted("The 'integrity' top-level value of an importmap needs to be a JSON object.").release_value_but_fixme_should_propagate_errors()};
// 2. Set normalizedIntegrity to the result of normalizing a module integrity map given parsed["integrity"] and baseURL.
// 9. If parsed's keys contains any items besides "imports", "scopes", or "integrity", then the user agent should report a warning to the console indicating that an invalid top-level key was present in the import map.
// 10. Return an import map whose imports are sortedAndNormalizedImports, whose scopes are sortedAndNormalizedScopes, and whose integrity are normalizedIntegrity.
// 1. The user agent may report a warning to the console indicating that an invalid address was given for the specifier key specifierKey; since specifierKey ends with a slash, the address needs to as well.
TRY_OR_THROW_OOM(realm.vm(),String::formatted("An invalid address was given for the specifier key ({}); since specifierKey ends with a slash, the address needs to as well",specifier_key.as_string())));
// 2. Set normalized[normalizedSpecifierKey] to null.
// 3. Return the result of sorting in descending order normalized, with an entry a being less than an entry b if a's key is code unit less than b's key.
// 1. If potentialSpecifierMap is not an ordered map, then throw a TypeError indicating that the value of the scope with prefix scopePrefix needs to be a JSON object.
if(!potential_specifier_map.is_object())
returnWebIDL::SimpleException{WebIDL::SimpleExceptionType::TypeError,String::formatted("The value of the scope with the prefix '{}' needs to be a JSON object.",scope_prefix.as_string()).release_value_but_fixme_should_propagate_errors()};
// 2. Let scopePrefixURL be the result of URL parsing scopePrefix with baseURL.
// 3. Return the result of sorting in descending order normalized, with an entry a being less than an entry b if a's key is code unit less than b's key.