Skip to content
Permalink
Browse files

Show warning when the script is a module

The warning can be removed in #23545.
  • Loading branch information...
CYBAI committed Sep 5, 2019
1 parent 70c5cfd commit 95ddfb3930debb81653dffcade6c2ea15dd30d9b
Showing with 60 additions and 38 deletions.
  1. +60 −38 components/script/dom/htmlscriptelement.rs
@@ -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
};

// 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)
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 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 &&

0 comments on commit 95ddfb3

Please sign in to comment.
You can’t perform that action at this time.