aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlscriptelement.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-03-20 06:28:25 +0530
committerbors-servo <lbergstrom+bors@mozilla.com>2016-03-20 06:28:25 +0530
commit8e95f54501efd74007bb19009b6d2b7522872d57 (patch)
treeab151875af69d35604f06c2e919719de081def52 /components/script/dom/htmlscriptelement.rs
parenta4251c832d605a02d6c82fc188d1746367599e59 (diff)
parentf1f53468a072365fe9dae72422afe428d813e794 (diff)
downloadservo-8e95f54501efd74007bb19009b6d2b7522872d57.tar.gz
servo-8e95f54501efd74007bb19009b6d2b7522872d57.zip
Auto merge of #10079 - servo:script-encoding, r=jdm
Implement encoding determination for external scripts. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10079) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/htmlscriptelement.rs')
-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..eb63d524c9c 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: Cell<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: Cell::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.set(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.get())
+ .unwrap_or_else(|| self.parser_document.encoding());
+
+ (DOMString::from(encoding.decode(&*bytes, DecoderTrap::Replace).unwrap()),
+ true,
+ metadata.final_url)
},
// Step 2.b.1.c.