Auto merge of #14727 - zaynetro:textdecoder-use-typedarray, r=jdm

Use typed array in TextDecoder::Decode

<!-- Please describe your changes on the following line: -->

Use typed array API in TextDecoder::Decode

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #14674

<!-- Either: -->
- [x] These changes do not require tests because no new methods were introduced

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14727)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-12-27 06:56:15 -08:00 committed by GitHub
commit eb64edec84

View file

@ -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};
@ -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()));
}
};
@ -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())),
}