mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
HTMLScriptElement: add ScriptType::ImportMap
(#37291)
HTMLScriptElement: add `ScriptType::ImportMap` Part of #37262 This covers most steps that are related to import map. Testing: Existing WPT on HTMLScriptElement should remain the same. --------- Signed-off-by: Yu Wei Wu <yuweiwu@YunoMacBook-Air.local> Co-authored-by: Yu Wei Wu <yuweiwu@YunoMacBook-Air.local>
This commit is contained in:
parent
32cffbc985
commit
ba33fd1318
1 changed files with 36 additions and 27 deletions
|
@ -275,6 +275,7 @@ pub(crate) static SCRIPT_JS_MIMES: StaticStringVec = &[
|
||||||
pub(crate) enum ScriptType {
|
pub(crate) enum ScriptType {
|
||||||
Classic,
|
Classic,
|
||||||
Module,
|
Module,
|
||||||
|
ImportMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(JSTraceable, MallocSizeOf)]
|
#[derive(JSTraceable, MallocSizeOf)]
|
||||||
|
@ -770,7 +771,8 @@ impl HTMLScriptElement {
|
||||||
// Step 23. Module script credentials mode.
|
// Step 23. Module script credentials mode.
|
||||||
let module_credentials_mode = match script_type {
|
let module_credentials_mode = match script_type {
|
||||||
ScriptType::Classic => CredentialsMode::CredentialsSameOrigin,
|
ScriptType::Classic => CredentialsMode::CredentialsSameOrigin,
|
||||||
ScriptType::Module => reflect_cross_origin_attribute(element).map_or(
|
ScriptType::Module | ScriptType::ImportMap => reflect_cross_origin_attribute(element)
|
||||||
|
.map_or(
|
||||||
CredentialsMode::CredentialsSameOrigin,
|
CredentialsMode::CredentialsSameOrigin,
|
||||||
|attr| match &*attr {
|
|attr| match &*attr {
|
||||||
"use-credentials" => CredentialsMode::Include,
|
"use-credentials" => CredentialsMode::Include,
|
||||||
|
@ -821,7 +823,13 @@ impl HTMLScriptElement {
|
||||||
if let Some(src) = element.get_attribute(&ns!(), &local_name!("src")) {
|
if let Some(src) = element.get_attribute(&ns!(), &local_name!("src")) {
|
||||||
// Step 31. If el has a src content attribute, then:
|
// Step 31. If el has a src content attribute, then:
|
||||||
|
|
||||||
// TODO: Step 31.1. If el's type is "importmap".
|
// Step 31.1. If el's type is "importmap".
|
||||||
|
if script_type == ScriptType::ImportMap {
|
||||||
|
// then queue an element task on the DOM manipulation task source
|
||||||
|
// given el to fire an event named error at el, and return.
|
||||||
|
self.queue_error_event();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Step 31.2. Let src be the value of el's src attribute.
|
// Step 31.2. Let src be the value of el's src attribute.
|
||||||
let src = src.value();
|
let src = src.value();
|
||||||
|
@ -904,7 +912,7 @@ impl HTMLScriptElement {
|
||||||
doc.add_asap_script(self);
|
doc.add_asap_script(self);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
// TODO: Case "importmap"
|
ScriptType::ImportMap => (),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Step 32. If el does not have a src content attribute:
|
// Step 32. If el does not have a src content attribute:
|
||||||
|
@ -913,7 +921,9 @@ impl HTMLScriptElement {
|
||||||
|
|
||||||
let text_rc = Rc::new(text);
|
let text_rc = Rc::new(text);
|
||||||
|
|
||||||
// TODO: Fix step number or match spec text. Is this step 32.1?
|
// Step 32.2: Switch on el's type:
|
||||||
|
match script_type {
|
||||||
|
ScriptType::Classic => {
|
||||||
let result = Ok(ScriptOrigin::internal(
|
let result = Ok(ScriptOrigin::internal(
|
||||||
Rc::clone(&text_rc),
|
Rc::clone(&text_rc),
|
||||||
base_url.clone(),
|
base_url.clone(),
|
||||||
|
@ -922,9 +932,6 @@ impl HTMLScriptElement {
|
||||||
self.global().unminified_js_dir(),
|
self.global().unminified_js_dir(),
|
||||||
));
|
));
|
||||||
|
|
||||||
// TODO: Fix step number or match spec text. Is this step 32.2?
|
|
||||||
match script_type {
|
|
||||||
ScriptType::Classic => {
|
|
||||||
if was_parser_inserted &&
|
if was_parser_inserted &&
|
||||||
doc.get_current_parser()
|
doc.get_current_parser()
|
||||||
.is_some_and(|parser| parser.script_nesting_level() <= 1) &&
|
.is_some_and(|parser| parser.script_nesting_level() <= 1) &&
|
||||||
|
@ -958,6 +965,10 @@ impl HTMLScriptElement {
|
||||||
can_gc,
|
can_gc,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
ScriptType::ImportMap => {
|
||||||
|
// TODO: Let result be the result of creating an import map
|
||||||
|
// parse result given source text and base URL.
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1054,19 +1065,17 @@ impl HTMLScriptElement {
|
||||||
} else {
|
} else {
|
||||||
document.set_current_script(Some(self))
|
document.set_current_script(Some(self))
|
||||||
}
|
}
|
||||||
},
|
|
||||||
ScriptType::Module => document.set_current_script(None),
|
|
||||||
}
|
|
||||||
|
|
||||||
match script.type_ {
|
|
||||||
ScriptType::Classic => {
|
|
||||||
self.run_a_classic_script(&script, can_gc);
|
self.run_a_classic_script(&script, can_gc);
|
||||||
document.set_current_script(old_script.as_deref());
|
document.set_current_script(old_script.as_deref());
|
||||||
},
|
},
|
||||||
ScriptType::Module => {
|
ScriptType::Module => {
|
||||||
assert!(document.GetCurrentScript().is_none());
|
document.set_current_script(None);
|
||||||
self.run_a_module_script(&script, false, can_gc);
|
self.run_a_module_script(&script, false, can_gc);
|
||||||
},
|
},
|
||||||
|
ScriptType::ImportMap => {
|
||||||
|
// TODO: Register an import map given el's relevant
|
||||||
|
// global object and el's result.
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 7.
|
// Step 7.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue