Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use typed array API in TextDecoder::Decode
  • Loading branch information
zaynetro committed Dec 27, 2016
1 parent 93e3c3f commit 40fa021
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions components/script/dom/textdecoder.rs
Expand Up @@ -4,7 +4,6 @@

use dom::bindings::codegen::Bindings::TextDecoderBinding;
use dom::bindings::codegen::Bindings::TextDecoderBinding::TextDecoderMethods;
use dom::bindings::conversions::array_buffer_view_data;
use dom::bindings::error::{Error, Fallible};
use dom::bindings::js::Root;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
Expand Down Expand Up @@ -85,9 +84,10 @@ impl TextDecoderMethods for TextDecoder {
None => return Ok(USVString("".to_owned())),
};

let data = match array_buffer_view_data::<u8>(input) {
Some(data) => data,
None => {
typedarray!(in(_cx) let data_res: ArrayBufferView = input);
let mut data = match data_res {
Ok(data) => data,
Err(_) => {
return Err(Error::Type("Argument to TextDecoder.decode is not an ArrayBufferView".to_owned()));
}
};
Expand All @@ -98,7 +98,7 @@ impl TextDecoderMethods for TextDecoder {
DecoderTrap::Replace
};

match self.encoding.decode(data, trap) {
match self.encoding.decode(data.as_slice(), trap) {
Ok(s) => Ok(USVString(s)),
Err(_) => Err(Error::Type("Decoding failed".to_owned())),
}
Expand Down

0 comments on commit 40fa021

Please sign in to comment.