Skip to content
Permalink
Browse files

Add `type_` for script origin to distinguish module or classic

  • Loading branch information...
CYBAI committed Jun 8, 2019
1 parent 19eb239 commit 70c5cfdbdb9c4945a222503fe3873ff774537097
Showing with 12 additions and 4 deletions.
  1. +12 −4 components/script/dom/htmlscriptelement.rs
@@ -125,6 +125,7 @@ static SCRIPT_JS_MIMES: StaticStringVec = &[
"text/x-javascript",
];

#[derive(JSTraceable, MallocSizeOf)]
pub enum ScriptType {
Classic,
Module,
@@ -135,22 +136,25 @@ pub struct ScriptOrigin {
text: DOMString,
url: ServoUrl,
external: bool,
type_: ScriptType,
}

impl ScriptOrigin {
fn internal(text: DOMString, url: ServoUrl) -> ScriptOrigin {
fn internal(text: DOMString, url: ServoUrl, type_: ScriptType) -> ScriptOrigin {
ScriptOrigin {
text: text,
url: url,
external: false,
type_,
}
}

fn external(text: DOMString, url: ServoUrl) -> ScriptOrigin {
fn external(text: DOMString, url: ServoUrl, type_: ScriptType) -> ScriptOrigin {
ScriptOrigin {
text: text,
url: url,
external: true,
type_,
}
}
}
@@ -231,7 +235,11 @@ impl FetchResponseListener for ClassicContext {

// Step 7.
let (source_text, _, _) = encoding.decode(&self.data);
ScriptOrigin::external(DOMString::from(source_text), metadata.final_url)
ScriptOrigin::external(
DOMString::from(source_text),
metadata.final_url,
ScriptType::Classic,
)
});

// Step 9.
@@ -526,7 +534,7 @@ impl HTMLScriptElement {
// Step 25.
assert!(!text.is_empty());
// Step 25-1.
let result = Ok(ScriptOrigin::internal(text, base_url));
let result = Ok(ScriptOrigin::internal(text, base_url, ScriptType::Classic));

// TODO: Step 25-2.

0 comments on commit 70c5cfd

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