aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/textdecoder.rs
diff options
context:
space:
mode:
authorChristian Poveda <christianpoveda@protonmail.com>2018-03-24 08:58:23 -0500
committerChristian Poveda <christianpoveda@protonmail.com>2018-03-24 16:26:44 -0500
commit2c47e7e1db2d31e6f05b0fbe83a73e7d2dd94595 (patch)
tree874bc49f0e1efb87d68ec18173a7ed6547f83fd0 /components/script/dom/textdecoder.rs
parente8fdc677f440919507209ed42d0ea042c700042c (diff)
downloadservo-2c47e7e1db2d31e6f05b0fbe83a73e7d2dd94595.tar.gz
servo-2c47e7e1db2d31e6f05b0fbe83a73e7d2dd94595.zip
TextDecoder's Decode now receives a BufferSource as input
Diffstat (limited to 'components/script/dom/textdecoder.rs')
-rw-r--r--components/script/dom/textdecoder.rs52
1 files changed, 25 insertions, 27 deletions
diff --git a/components/script/dom/textdecoder.rs b/components/script/dom/textdecoder.rs
index b695af32fe8..38efa977e7f 100644
--- a/components/script/dom/textdecoder.rs
+++ b/components/script/dom/textdecoder.rs
@@ -3,7 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::TextDecoderBinding;
-use dom::bindings::codegen::Bindings::TextDecoderBinding::TextDecoderMethods;
+use dom::bindings::codegen::Bindings::TextDecoderBinding::{TextDecoderMethods, TextDecodeOptions};
+use dom::bindings::codegen::UnionTypes::ArrayBufferViewOrArrayBuffer;
use dom::bindings::error::{Error, Fallible};
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::DomRoot;
@@ -11,7 +12,6 @@ use dom::bindings::str::{DOMString, USVString};
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use encoding_rs::Encoding;
-use js::jsapi::{JSContext, JSObject};
use std::borrow::ToOwned;
#[dom_struct]
@@ -65,32 +65,30 @@ impl TextDecoderMethods for TextDecoder {
self.fatal
}
- #[allow(unsafe_code)]
// https://encoding.spec.whatwg.org/#dom-textdecoder-decode
- unsafe fn Decode(&self, _cx: *mut JSContext, input: Option<*mut JSObject>)
- -> Fallible<USVString> {
- let input = match input {
- Some(input) => input,
- None => return Ok(USVString("".to_owned())),
- };
-
- 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()));
+ fn Decode(
+ &self,
+ input: Option<ArrayBufferViewOrArrayBuffer>,
+ _options: &TextDecodeOptions
+ ) -> Fallible<USVString> {
+ match input {
+ Some(arr) => {
+ let vec: Vec<u8> = match arr {
+ ArrayBufferViewOrArrayBuffer::ArrayBufferView(mut a) => a.to_vec(),
+ ArrayBufferViewOrArrayBuffer::ArrayBuffer(mut a) => a.to_vec()
+ };
+ let s = if self.fatal {
+ match self.encoding.decode_without_bom_handling_and_without_replacement(&vec) {
+ Some(s) => s,
+ None => return Err(Error::Type("Decoding failed".to_owned())),
+ }
+ } else {
+ let (s, _has_errors) = self.encoding.decode_without_bom_handling(&vec);
+ s
+ };
+ Ok(USVString(s.into_owned()))
}
- };
-
- let s = if self.fatal {
- match self.encoding.decode_without_bom_handling_and_without_replacement(data.as_slice()) {
- Some(s) => s,
- None => return Err(Error::Type("Decoding failed".to_owned())),
- }
- } else {
- let (s, _has_errors) = self.encoding.decode_without_bom_handling(data.as_slice());
- s
- };
- Ok(USVString(s.into_owned()))
+ None => Ok(USVString("".to_owned()))
+ }
}
}