aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authoraskalski <andrzej.j.skalski@gmail.com>2016-01-09 21:40:45 +0100
committerMs2ger <Ms2ger@gmail.com>2016-03-18 16:51:25 +0100
commit89b8499df8bd9a9c4a78d93fb644fb764c5fabbb (patch)
tree237be6f5416d8a75674c116f42ccae523adfadb7 /components/script/dom
parentb1cd28e9c674467fc30ffc22c4ea99fa94022d0e (diff)
downloadservo-89b8499df8bd9a9c4a78d93fb644fb764c5fabbb.tar.gz
servo-89b8499df8bd9a9c4a78d93fb644fb764c5fabbb.zip
Implement encoding determination for external scripts.
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/htmlscriptelement.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs
index bbd1884dc4f..eaafcadd7cc 100644
--- a/components/script/dom/htmlscriptelement.rs
+++ b/components/script/dom/htmlscriptelement.rs
@@ -25,7 +25,6 @@ use dom::node::{ChildrenMutation, CloneChildrenFlag, Node};
use dom::node::{document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods;
use dom::window::ScriptHelpers;
-use encoding::all::UTF_8;
use encoding::label::encoding_from_whatwg_label;
use encoding::types::{DecoderTrap, Encoding, EncodingRef};
use html5ever::tree_builder::NextParserState;
@@ -71,7 +70,7 @@ pub struct HTMLScriptElement {
#[ignore_heap_size_of = "Defined in rust-encoding"]
/// https://html.spec.whatwg.org/multipage/#concept-script-encoding
- block_character_encoding: DOMRefCell<EncodingRef>,
+ block_character_encoding: DOMRefCell<Option<EncodingRef>>,
}
impl HTMLScriptElement {
@@ -86,7 +85,7 @@ impl HTMLScriptElement {
ready_to_be_parser_executed: Cell::new(false),
parser_document: JS::from_ref(document),
load: DOMRefCell::new(None),
- block_character_encoding: DOMRefCell::new(UTF_8 as EncodingRef),
+ block_character_encoding: DOMRefCell::new(None),
}
}
@@ -248,7 +247,7 @@ impl HTMLScriptElement {
// Step 13.
if let Some(ref charset) = element.get_attribute(&ns!(), &atom!("charset")) {
if let Some(encodingRef) = encoding_from_whatwg_label(&charset.Value()) {
- *self.block_character_encoding.borrow_mut() = encodingRef;
+ *self.block_character_encoding.borrow_mut() = Some(encodingRef);
}
}
@@ -391,10 +390,16 @@ impl HTMLScriptElement {
// Step 2.b.1.a.
ScriptOrigin::External(Ok((metadata, bytes))) => {
- // TODO(#9185): implement encoding determination.
- (DOMString::from(UTF_8.decode(&*bytes, DecoderTrap::Replace).unwrap()),
- true,
- metadata.final_url)
+ debug!("loading external script, url = {}", metadata.final_url);
+
+ let encoding = metadata.charset
+ .and_then(|encoding| encoding_from_whatwg_label(&encoding))
+ .or_else(|| *self.block_character_encoding.borrow())
+ .unwrap_or_else(|| self.parser_document.encoding());
+
+ (DOMString::from(encoding.decode(&*bytes, DecoderTrap::Replace).unwrap()),
+ true,
+ metadata.final_url)
},
// Step 2.b.1.c.