servo: Merge #5916 - Prepare for the rustup (from servo:prepare-rustup); r=jdm
authorMs2ger <ms2ger@gmail.com>
Fri, 01 May 2015 14:44:19 -0500
changeset 385275 8a4f1dbfeb2a1dd198b834bb10a8683570c79a7f
parent 385274 3ba4c5400aed0424dbf0258f24a6b8c86837b0df
child 385276 7161fc26d01f683161b44260610c104b06ce6e56
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
servo: Merge #5916 - Prepare for the rustup (from servo:prepare-rustup); r=jdm Source-Repo: https://github.com/servo/servo Source-Revision: 2f0b805fad2419518f0d80e90cf322fbd507a916
servo/components/gfx/buffer_map.rs
servo/components/gfx/font_cache_task.rs
servo/components/layout/table_rowgroup.rs
servo/components/layout/table_wrapper.rs
servo/components/script/dom/bindings/conversions.rs
servo/components/script/dom/bindings/js.rs
servo/components/script/dom/bindings/refcounted.rs
servo/components/script/dom/bindings/str.rs
servo/components/script/dom/bindings/trace.rs
servo/components/script/dom/element.rs
servo/components/script/dom/macros.rs
servo/components/script/dom/textencoder.rs
servo/components/script/dom/xmlhttprequest.rs
--- a/servo/components/gfx/buffer_map.rs
+++ b/servo/components/gfx/buffer_map.rs
@@ -104,17 +104,17 @@ impl BufferMap {
                 None => {
                     match self.map.iter().min_by(|&(_, x)| x.last_action) {
                         Some((k, _)) => *k,
                         None => panic!("BufferMap: tried to delete with no elements in map"),
                     }
                 }
             };
             if {
-                let list = &mut self.map[old_key].buffers;
+                let list = &mut self.map.get_mut(&old_key).unwrap().buffers;
                 let condemned_buffer = list.pop().take().unwrap();
                 self.mem -= condemned_buffer.get_mem();
                 condemned_buffer.destroy(graphics_context);
                 list.is_empty()
             }
             { // then
                 self.map.remove(&old_key); // Don't store empty vectors!
                 opt_key = None;
--- a/servo/components/gfx/font_cache_task.rs
+++ b/servo/components/gfx/font_cache_task.rs
@@ -134,26 +134,26 @@ impl FontCache {
                     }
 
                     match src {
                         Source::Url(ref url_source) => {
                             let url = &url_source.url;
                             let maybe_resource = load_whole_resource(&self.resource_task, url.clone());
                             match maybe_resource {
                                 Ok((_, bytes)) => {
-                                    let family = &mut self.web_families[family_name];
+                                    let family = &mut self.web_families.get_mut(&family_name).unwrap();
                                     family.add_template(&url.to_string(), Some(bytes));
                                 },
                                 Err(_) => {
                                     debug!("Failed to load web font: family={:?} url={}", family_name, url);
                                 }
                             }
                         }
                         Source::Local(ref local_family_name) => {
-                            let family = &mut self.web_families[family_name];
+                            let family = &mut self.web_families.get_mut(&family_name).unwrap();
                             get_variations_for_family(&local_family_name, |path| {
                                 family.add_template(&path, None);
                             });
                         }
                     }
                     result.send(()).unwrap();
                 }
                 Command::Exit(result) => {
@@ -183,17 +183,17 @@ impl FontCache {
     }
 
     fn find_font_in_local_family<'a>(&'a mut self, family_name: &LowercaseString, desc: &FontTemplateDescriptor)
                                 -> Option<Arc<FontTemplateData>> {
         // TODO(Issue #188): look up localized font family names if canonical name not found
         // look up canonical name
         if self.local_families.contains_key(family_name) {
             debug!("FontList: Found font family with name={}", &**family_name);
-            let s = &mut self.local_families[*family_name];
+            let s = self.local_families.get_mut(family_name).unwrap();
 
             if s.templates.len() == 0 {
                 get_variations_for_family(&family_name, |path| {
                     s.add_template(&path, None);
                 });
             }
 
             // TODO(Issue #192: handle generic font families, like 'serif' and 'sans-serif'.
@@ -208,17 +208,17 @@ impl FontCache {
             debug!("FontList: Couldn't find font family with name={}", &**family_name);
             None
         }
     }
 
     fn find_font_in_web_family<'a>(&'a mut self, family_name: &LowercaseString, desc: &FontTemplateDescriptor)
                                 -> Option<Arc<FontTemplateData>> {
         if self.web_families.contains_key(family_name) {
-            let family = &mut self.web_families[*family_name];
+            let family = self.web_families.get_mut(family_name).unwrap();
             let maybe_font = family.find_font_for_style(desc, &self.font_context);
             maybe_font
         } else {
             None
         }
     }
 
     fn get_font_template(&mut self, family: &LowercaseString, desc: &FontTemplateDescriptor)
--- a/servo/components/layout/table_rowgroup.rs
+++ b/servo/components/layout/table_rowgroup.rs
@@ -83,17 +83,17 @@ impl TableRowGroupFlow {
             &mut self,
             collapsed_inline_direction_border_widths_for_table: &[Au],
             collapsed_block_direction_border_widths_for_table: &mut Peekable<I>)
             where I: Iterator<Item=&'a Au> {
         self.collapsed_inline_direction_border_widths_for_table.clear();
         self.collapsed_inline_direction_border_widths_for_table
             .extend(collapsed_inline_direction_border_widths_for_table.into_iter().map(|x| *x));
 
-        for _ in range(0, self.block_flow.base.children.len()) {
+        for _ in 0..self.block_flow.base.children.len() {
             if let Some(collapsed_block_direction_border_width_for_table) =
                     collapsed_block_direction_border_widths_for_table.next() {
                 self.collapsed_block_direction_border_widths_for_table
                     .push(*collapsed_block_direction_border_width_for_table)
             }
         }
         if let Some(collapsed_block_direction_border_width_for_table) =
                 collapsed_block_direction_border_widths_for_table.peek() {
--- a/servo/components/layout/table_wrapper.rs
+++ b/servo/components/layout/table_wrapper.rs
@@ -300,17 +300,17 @@ impl Flow for TableWrapperFlow {
         let containing_block_inline_size = self.block_flow.base.block_container_inline_size;
         if self.block_flow.base.flags.is_float() {
             self.block_flow.float.as_mut().unwrap().containing_inline_size =
                 containing_block_inline_size;
         }
 
         self.compute_used_inline_size(layout_context,
                                       containing_block_inline_size,
-                                      intermediate_column_inline_sizes.as_slice());
+                                      &intermediate_column_inline_sizes);
 
         if let TableLayout::Auto = self.table_layout {
             self.calculate_table_column_sizes_for_automatic_layout(
                 &mut intermediate_column_inline_sizes)
         }
 
         let inline_start_content_edge = self.block_flow.fragment.border_box.start.i;
         let content_inline_size = self.block_flow.fragment.border_box.size.inline;
--- a/servo/components/script/dom/bindings/conversions.rs
+++ b/servo/components/script/dom/bindings/conversions.rs
@@ -395,19 +395,18 @@ impl FromJSValConvertible for USVString 
             }
         }
     }
 }
 
 impl ToJSValConvertible for ByteString {
     fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
         unsafe {
-            let slice = self.as_slice();
-            let jsstr = JS_NewStringCopyN(cx, slice.as_ptr() as *const libc::c_char,
-                                          slice.len() as libc::size_t);
+            let jsstr = JS_NewStringCopyN(cx, self.as_ptr() as *const libc::c_char,
+                                          self.len() as libc::size_t);
             if jsstr.is_null() {
                 panic!("JS_NewStringCopyN failed");
             }
             StringValue(&*jsstr)
         }
     }
 }
 
--- a/servo/components/script/dom/bindings/js.rs
+++ b/servo/components/script/dom/bindings/js.rs
@@ -588,17 +588,17 @@ impl RootCollection {
 /// A rooted reference to a DOM object.
 ///
 /// The JS value is pinned for the duration of this object's lifetime; roots
 /// are additive, so this object's destruction will not invalidate other roots
 /// for the same JS value. `Root`s cannot outlive the associated
 /// `RootCollection` object. Attempts to transfer ownership of a `Root` via
 /// moving will trigger dynamic unrooting failures due to incorrect ordering.
 #[no_move]
-pub struct Root<T> {
+pub struct Root<T: Reflectable> {
     /// List that ensures correct dynamic root ordering
     root_list: &'static RootCollection,
     /// Reference to rooted value that must not outlive this container
     ptr: NonZero<*const T>,
     /// On-stack JS pointer to assuage conservative stack scanner
     js_ptr: *mut JSObject,
 }
 
--- a/servo/components/script/dom/bindings/refcounted.rs
+++ b/servo/components/script/dom/bindings/refcounted.rs
@@ -42,17 +42,17 @@ thread_local!(pub static LIVE_REFERENCES
 /// A pointer to a Rust DOM object that needs to be destroyed.
 pub struct TrustedReference(*const libc::c_void);
 unsafe impl Send for TrustedReference {}
 
 /// A safe wrapper around a raw pointer to a DOM object that can be
 /// shared among tasks for use in asynchronous operations. The underlying
 /// DOM object is guaranteed to live at least as long as the last outstanding
 /// `Trusted<T>` instance.
-pub struct Trusted<T> {
+pub struct Trusted<T: Reflectable> {
     /// A pointer to the Rust DOM object of type T, but void to allow
     /// sending `Trusted<T>` between tasks, regardless of T's sendability.
     ptr: *const libc::c_void,
     refcount: Arc<Mutex<usize>>,
     script_chan: Box<ScriptChan + Send>,
     owner_thread: *const libc::c_void,
     phantom: PhantomData<T>,
 }
--- a/servo/components/script/dom/bindings/str.rs
+++ b/servo/components/script/dom/bindings/str.rs
@@ -1,16 +1,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! The `ByteString` struct.
 
+use std::ascii::AsciiExt;
 use std::borrow::ToOwned;
 use std::hash::{Hash, Hasher};
+use std::ops;
 use std::str;
 use std::str::FromStr;
 
 /// Encapsulates the IDL `ByteString` type.
 #[derive(Clone,Eq,PartialEq)]
 #[jstraceable]
 pub struct ByteString(Vec<u8>);
 
@@ -22,44 +24,30 @@ impl ByteString {
 
     /// Returns `self` as a string, if it encodes valid UTF-8, and `None`
     /// otherwise.
     pub fn as_str<'a>(&'a self) -> Option<&'a str> {
         let ByteString(ref vec) = *self;
         str::from_utf8(&vec).ok()
     }
 
-    /// Returns the underlying vector as a slice.
-    pub fn as_slice<'a>(&'a self) -> &'a [u8] {
-        let ByteString(ref vector) = *self;
-        vector
-    }
-
     /// Returns the length.
     pub fn len(&self) -> usize {
         let ByteString(ref vector) = *self;
         vector.len()
     }
 
     /// Compare `self` to `other`, matching A–Z and a–z as equal.
     pub fn eq_ignore_case(&self, other: &ByteString) -> bool {
-        // XXXManishearth make this more efficient
-        self.to_lower() == other.to_lower()
+        self.0.eq_ignore_ascii_case(&other.0)
     }
 
     /// Returns `self` with A–Z replaced by a–z.
     pub fn to_lower(&self) -> ByteString {
-        let ByteString(ref vec) = *self;
-        ByteString::new(vec.iter().map(|&x| {
-            if x > 'A' as u8 && x < 'Z' as u8 {
-                x + ('a' as u8) - ('A' as u8)
-            } else {
-                x
-            }
-        }).collect())
+        ByteString::new(self.0.to_ascii_lowercase())
     }
 
     /// Returns whether `self` is a `token`, as defined by
     /// [RFC 2616](http://tools.ietf.org/html/rfc2616#page-17).
     pub fn is_token(&self) -> bool {
         let ByteString(ref vec) = *self;
         if vec.len() == 0 {
             return false; // A token must be at least a single character
@@ -153,11 +141,18 @@ impl Hash for ByteString {
 
 impl FromStr for ByteString {
     type Err = ();
     fn from_str(s: &str) -> Result<ByteString, ()> {
         Ok(ByteString::new(s.to_owned().into_bytes()))
     }
 }
 
+impl ops::Deref for ByteString {
+    type Target = [u8];
+    fn deref(&self) -> &[u8] {
+        &self.0
+    }
+}
+
 /// A string that is constructed from a UCS-2 buffer by replacing invalid code
 /// points with the replacement character.
 pub struct USVString(pub String);
--- a/servo/components/script/dom/bindings/trace.rs
+++ b/servo/components/script/dom/bindings/trace.rs
@@ -94,17 +94,17 @@ no_jsmanaged_fields!(Reflector);
 pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) {
     if !val.is_markable() {
         return;
     }
 
     unsafe {
         let name = CString::new(description).unwrap();
         (*tracer).debugPrinter = None;
-        (*tracer).debugPrintIndex = -1;
+        (*tracer).debugPrintIndex = !0;
         (*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void;
         debug!("tracing value {}", description);
         JS_CallTracer(tracer, val.to_gcthing(), val.trace_kind());
     }
 }
 
 /// Trace the `JSObject` held by `reflector`.
 #[allow(unrooted_must_root)]
@@ -112,17 +112,17 @@ pub fn trace_reflector(tracer: *mut JSTr
     trace_object(tracer, description, reflector.get_jsobject())
 }
 
 /// Trace a `JSObject`.
 pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: *mut JSObject) {
     unsafe {
         let name = CString::new(description).unwrap();
         (*tracer).debugPrinter = None;
-        (*tracer).debugPrintIndex = -1;
+        (*tracer).debugPrintIndex = !0;
         (*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void;
         debug!("tracing {}", description);
         JS_CallTracer(tracer, obj as *mut libc::c_void, JSGCTraceKind::JSTRACE_OBJECT);
     }
 }
 
 impl<T: JSTraceable> JSTraceable for RefCell<T> {
     fn trace(&self, trc: *mut JSTracer) {
@@ -313,26 +313,30 @@ impl JSTraceable for Box<LayoutRPC+'stat
 impl JSTraceable for () {
     #[inline]
     fn trace(&self, _trc: *mut JSTracer) {
     }
 }
 
 /// Holds a set of vectors that need to be rooted
 pub struct RootedCollectionSet {
-    set: Vec<HashSet<*const RootedVec<()>>>
+    set: Vec<HashSet<*const RootedVec<Void>>>
 }
 
 /// TLV Holds a set of vectors that need to be rooted
 thread_local!(pub static ROOTED_COLLECTIONS: Rc<RefCell<RootedCollectionSet>> =
               Rc::new(RefCell::new(RootedCollectionSet::new())));
 
-enum CollectionType {
+/// Type of `RootedVec`
+pub enum CollectionType {
+    /// DOM objects
     DOMObjects,
+    /// `JSVal`s
     JSVals,
+    /// `*mut JSObject`s
     JSObjects,
 }
 
 
 impl RootedCollectionSet {
     fn new() -> RootedCollectionSet {
         RootedCollectionSet {
             set: vec!(HashSet::new(), HashSet::new(), HashSet::new())
@@ -351,63 +355,75 @@ impl RootedCollectionSet {
         ROOTED_COLLECTIONS.with(|ref collections| {
             let type_ = VecRootableType::tag(None::<T>);
             let mut collections = collections.borrow_mut();
             collections.set[type_ as usize].insert(collection as *const _ as *const _);
         })
     }
 
     unsafe fn trace(&self, tracer: *mut JSTracer) {
-        fn trace_collection_type<T: JSTraceable>(tracer: *mut JSTracer,
-                                                 collections: &HashSet<*const RootedVec<()>>) {
+        fn trace_collection_type<T>(tracer: *mut JSTracer,
+                                    collections: &HashSet<*const RootedVec<Void>>)
+            where T: JSTraceable + VecRootableType
+        {
             for collection in collections {
-                let collection: *const RootedVec<()> = *collection;
+                let collection: *const RootedVec<Void> = *collection;
                 let collection = collection as *const RootedVec<T>;
                 unsafe {
                     let _ = (*collection).trace(tracer);
                 }
             }
         }
 
-        let dom_collections = &self.set[CollectionType::DOMObjects as usize] as *const _ as *const HashSet<*const RootedVec<*const Reflector>>;
+        let dom_collections = &self.set[CollectionType::DOMObjects as usize] as *const _ as *const HashSet<*const RootedVec<JS<Void>>>;
         for dom_collection in (*dom_collections).iter() {
             for reflector in (**dom_collection).iter() {
-                trace_reflector(tracer, "", &**reflector);
+                trace_reflector(tracer, "", reflector.reflector());
             }
         }
 
         trace_collection_type::<JSVal>(tracer, &self.set[CollectionType::JSVals as usize]);
         trace_collection_type::<*mut JSObject>(tracer, &self.set[CollectionType::JSObjects as usize]);
     }
 }
 
 
 /// Trait implemented by all types that can be used with RootedVec
-trait VecRootableType {
+pub trait VecRootableType {
     /// Return the type tag used to determine how to trace RootedVec
     fn tag(_a: Option<Self>) -> CollectionType;
 }
 
 impl<T: Reflectable> VecRootableType for JS<T> {
     fn tag(_a: Option<JS<T>>) -> CollectionType { CollectionType::DOMObjects }
 }
 
 impl VecRootableType for JSVal {
     fn tag(_a: Option<JSVal>) -> CollectionType { CollectionType::JSVals }
 }
 
 impl VecRootableType for *mut JSObject {
     fn tag(_a: Option<*mut JSObject>) -> CollectionType { CollectionType::JSObjects }
 }
 
+enum Void {}
+
+impl VecRootableType for Void {
+    fn tag(_a: Option<Void>) -> CollectionType { unreachable!() }
+}
+
+impl Reflectable for Void {
+    fn reflector<'a>(&'a self) -> &'a Reflector { unreachable!() }
+}
+
 /// A vector of items that are rooted for the lifetime
 /// of this struct
 #[allow(unrooted_must_root)]
 #[no_move]
-pub struct RootedVec<T> {
+pub struct RootedVec<T: VecRootableType> {
     v: Vec<T>
 }
 
 
 impl<T: VecRootableType> RootedVec<T> {
     /// Create a vector of items of type T that is rooted for
     /// the lifetime of this struct
     pub fn new() -> RootedVec<T> {
@@ -430,24 +446,24 @@ impl<T: VecRootableType> RootedVec<T> {
 
 #[unsafe_destructor]
 impl<T: VecRootableType> Drop for RootedVec<T> {
     fn drop(&mut self) {
         RootedCollectionSet::remove(self);
     }
 }
 
-impl<T> Deref for RootedVec<T> {
+impl<T: VecRootableType> Deref for RootedVec<T> {
     type Target = Vec<T>;
     fn deref(&self) -> &Vec<T> {
         &self.v
     }
 }
 
-impl<T> DerefMut for RootedVec<T> {
+impl<T: VecRootableType> DerefMut for RootedVec<T> {
     fn deref_mut(&mut self) -> &mut Vec<T> {
         &mut self.v
     }
 }
 
 
 /// SM Callback that traces the rooted collections
 pub unsafe fn trace_collections(tracer: *mut JSTracer) {
--- a/servo/components/script/dom/element.rs
+++ b/servo/components/script/dom/element.rs
@@ -78,17 +78,17 @@ use selectors::smallvec::VecLike;
 use string_cache::{Atom, Namespace, QualName};
 use url::UrlParser;
 
 use std::ascii::AsciiExt;
 use std::borrow::{IntoCow, ToOwned};
 use std::cell::{Ref, RefMut};
 use std::default::Default;
 use std::mem;
-use std::old_io::{MemWriter, Writer};
+use std::old_io::Writer;
 use std::sync::Arc;
 
 #[dom_struct]
 pub struct Element {
     node: Node,
     local_name: Atom,
     namespace: Namespace,
     prefix: Option<DOMString>,
@@ -566,23 +566,23 @@ impl<'a> ElementHelpers<'a> for JSRef<'a
                         .iter()
                         .find(|decl| decl.matches(&property))
                         .map(|decl| decl.clone())
         })
     }
 
     fn serialize(self, traversal_scope: TraversalScope) -> Fallible<DOMString> {
         let node: JSRef<Node> = NodeCast::from_ref(self);
-        let mut writer = MemWriter::new();
+        let mut writer = vec![];
         match serialize(&mut writer, &node,
                         SerializeOpts {
                             traversal_scope: traversal_scope,
                             .. Default::default()
                         }) {
-            Ok(()) => Ok(String::from_utf8(writer.into_inner()).unwrap()),
+            Ok(()) => Ok(String::from_utf8(writer).unwrap()),
             Err(_) => panic!("Cannot serialize element"),
         }
     }
 
     // https://html.spec.whatwg.org/multipage/#root-element
     fn get_root_element(self) -> Option<Temporary<Element>> {
         let node: JSRef<Node> = NodeCast::from_ref(self);
         match node.ancestors().last().map(ElementCast::to_temporary) {
--- a/servo/components/script/dom/macros.rs
+++ b/servo/components/script/dom/macros.rs
@@ -80,22 +80,21 @@ macro_rules! make_url_or_base_getter(
         fn $attr(self) -> DOMString {
             use dom::element::{Element, AttributeHandlers};
             use dom::bindings::codegen::InheritTypes::ElementCast;
             use dom::window::WindowHelpers;
             #[allow(unused_imports)]
             use std::ascii::AsciiExt;
             let element: JSRef<Element> = ElementCast::from_ref(self);
             let url = element.get_url_attribute(&Atom::from_slice($htmlname));
-            match &*url {
-                "" => {
-                    let window = window_from_node(self).root();
-                    window.r().get_url().serialize()
-                },
-                _ => url
+            if url.is_empty() {
+                let window = window_from_node(self).root();
+                window.r().get_url().serialize()
+            } else {
+                url
             }
         }
     );
     ($attr:ident) => {
         make_url_or_base_getter!($attr, to_lower!(stringify!($attr)));
     }
 );
 
--- a/servo/components/script/dom/textencoder.rs
+++ b/servo/components/script/dom/textencoder.rs
@@ -75,18 +75,18 @@ impl<'a> TextEncoderMethods for JSRef<'a
     fn Encoding(self) -> DOMString {
         self.encoding.clone()
     }
 
     // https://encoding.spec.whatwg.org/#dom-textencoder-encode
     #[allow(unsafe_code)]
     fn Encode(self, cx: *mut JSContext, input: USVString) -> *mut JSObject {
         unsafe {
-            let output = self.encoder.encode(&input.0, EncoderTrap::Strict).unwrap();
-            let length = output.len() as u32;
+            let encoded = self.encoder.encode(&input.0, EncoderTrap::Strict).unwrap();
+            let length = encoded.len() as u32;
             let js_object: *mut JSObject = JS_NewUint8Array(cx, length);
 
             let js_object_data: *mut uint8_t = JS_GetUint8ArrayData(js_object, cx);
-            ptr::copy_nonoverlapping(js_object_data, output.as_ptr(), length as usize);
+            ptr::copy_nonoverlapping(js_object_data, encoded.as_ptr(), length as usize);
             return js_object;
         }
     }
 }
--- a/servo/components/script/dom/xmlhttprequest.rs
+++ b/servo/components/script/dom/xmlhttprequest.rs
@@ -394,24 +394,24 @@ impl<'a> XMLHttpRequestMethods for JSRef
 
 
         // Steps 6,7
         match headers.get_raw(name_str) {
             Some(raw) => {
                 debug!("SetRequestHeader: old value = {:?}", raw[0]);
                 let mut buf = raw[0].clone();
                 buf.push_all(b", ");
-                buf.push_all(value.as_slice());
+                buf.push_all(&value);
                 debug!("SetRequestHeader: new value = {:?}", buf);
                 value = ByteString::new(buf);
             },
             None => {}
         }
 
-        headers.set_raw(name_str.to_owned(), vec![value.as_slice().to_vec()]);
+        headers.set_raw(name_str.to_owned(), vec![value.to_vec()]);
         Ok(())
     }
 
     // https://xhr.spec.whatwg.org/#the-timeout-attribute
     fn Timeout(self) -> u32 {
         self.timeout.get()
     }
 
@@ -673,17 +673,17 @@ impl<'a> XMLHttpRequestMethods for JSRef
                 if ready_state == XMLHttpRequestState::Done || ready_state == XMLHttpRequestState::Loading {
                     self.text_response().to_jsval(cx)
                 } else {
                     "".to_jsval(cx)
                 }
             },
             _ if self.ready_state.get() != XMLHttpRequestState::Done => NullValue(),
             Json => {
-                let decoded = UTF_8.decode(self.response.borrow().as_slice(), DecoderTrap::Replace).unwrap().to_owned();
+                let decoded = UTF_8.decode(&self.response.borrow(), DecoderTrap::Replace).unwrap().to_owned();
                 let decoded: Vec<u16> = decoded.utf16_units().collect();
                 let mut vp = UndefinedValue();
                 unsafe {
                     if JS_ParseJSON(cx, decoded.as_ptr(), decoded.len() as u32, &mut vp) == 0 {
                         JS_ClearPendingException(cx);
                         return NullValue();
                     }
                 }
@@ -1023,17 +1023,17 @@ impl<'a> PrivateXMLHttpRequestHelpers fo
             None => {}
         }
 
 
         // FIXME(https://github.com/rust-lang/rust/issues/23338)
         let response = self.response.borrow();
         // According to Simon, decode() should never return an error, so unwrap()ing
         // the result should be fine. XXXManishearth have a closer look at this later
-        encoding.decode(response.as_slice(), DecoderTrap::Replace).unwrap().to_owned()
+        encoding.decode(&response, DecoderTrap::Replace).unwrap().to_owned()
     }
     fn filter_response_headers(self) -> Headers {
         // https://fetch.spec.whatwg.org/#concept-response-header-list
         use std::fmt;
         use hyper::header::{Header, HeaderFormat};
         use hyper::header::SetCookie;
 
         // a dummy header so we can use headers.remove::<SetCookie2>()