Show warning when the script is a module

The warning can be removed in #23545.
This commit is contained in:
CYBAI 2019-09-05 12:41:22 +09:00
parent 70c5cfdbdb
commit 95ddfb3930

View file

@ -125,7 +125,7 @@ static SCRIPT_JS_MIMES: StaticStringVec = &[
"text/x-javascript",
];
#[derive(JSTraceable, MallocSizeOf)]
#[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)]
pub enum ScriptType {
Classic,
Module,
@ -388,7 +388,7 @@ impl HTMLScriptElement {
return;
}
let _script_type = if let Some(ty) = self.get_script_type() {
let script_type = if let Some(ty) = self.get_script_type() {
ty
} else {
// Step 7.
@ -493,50 +493,72 @@ impl HTMLScriptElement {
},
};
// Preparation for step 26.
let kind = if element.has_attribute(&local_name!("defer")) &&
was_parser_inserted &&
!r#async
{
// Step 26.a: classic, has src, has defer, was parser-inserted, is not async.
ExternalScriptKind::Deferred
} else if was_parser_inserted && !r#async {
// Step 26.c: classic, has src, was parser-inserted, is not async.
ExternalScriptKind::ParsingBlocking
} else if !r#async && !self.non_blocking.get() {
// Step 26.d: classic, has src, is not async, is not non-blocking.
ExternalScriptKind::AsapInOrder
} else {
// Step 26.f: classic, has src.
ExternalScriptKind::Asap
};
match script_type {
ScriptType::Classic => {
// Preparation for step 26.
let kind = if element.has_attribute(&local_name!("defer")) &&
was_parser_inserted &&
!r#async
{
// Step 26.a: classic, has src, has defer, was parser-inserted, is not async.
ExternalScriptKind::Deferred
} else if was_parser_inserted && !r#async {
// Step 26.c: classic, has src, was parser-inserted, is not async.
ExternalScriptKind::ParsingBlocking
} else if !r#async && !self.non_blocking.get() {
// Step 26.d: classic, has src, is not async, is not non-blocking.
ExternalScriptKind::AsapInOrder
} else {
// Step 26.f: classic, has src.
ExternalScriptKind::Asap
};
// Step 24.6.
fetch_a_classic_script(
self,
kind,
url,
cors_setting,
integrity_metadata.to_owned(),
encoding,
);
// Step 24.6.
fetch_a_classic_script(
self,
kind,
url,
cors_setting,
integrity_metadata.to_owned(),
encoding,
);
// Step 23.
match kind {
ExternalScriptKind::Deferred => doc.add_deferred_script(self),
ExternalScriptKind::ParsingBlocking => {
doc.set_pending_parsing_blocking_script(self, None)
// Step 23.
match kind {
ExternalScriptKind::Deferred => doc.add_deferred_script(self),
ExternalScriptKind::ParsingBlocking => {
doc.set_pending_parsing_blocking_script(self, None)
},
ExternalScriptKind::AsapInOrder => doc.push_asap_in_order_script(self),
ExternalScriptKind::Asap => doc.add_asap_script(self),
}
},
ScriptType::Module => {
warn!(
"{} is a module script. It should be fixed after #23545 landed.",
url.clone()
);
},
ExternalScriptKind::AsapInOrder => doc.push_asap_in_order_script(self),
ExternalScriptKind::Asap => doc.add_asap_script(self),
}
} else {
// Step 25.
assert!(!text.is_empty());
// Step 25-1.
let result = Ok(ScriptOrigin::internal(text, base_url, ScriptType::Classic));
let result = Ok(ScriptOrigin::internal(
text.clone(),
base_url.clone(),
script_type.clone(),
));
// TODO: Step 25-2.
if let ScriptType::Module = script_type {
warn!(
"{} is a module script. It should be fixed after #23545 landed.",
base_url.clone()
);
return;
}
// Step 26.
if was_parser_inserted &&