servo: Merge #10503 - Replaced SendParam with BodyInit (from canaltinova:master); r=KiChjang
authorNazım Can Altınova <canaltinova@gmail.com>
Sun, 10 Apr 2016 03:08:38 +0500
changeset 476637 8eb22df0b6e38a00c3a88539441c60ae9d6cb952
parent 476636 1c3e662ecb2d6a03198b69711afd715e664da892
child 476638 e81b35c89383c52211e04e53842f52f2dc125db4
push id44079
push userbmo:gps@mozilla.com
push dateSat, 04 Feb 2017 00:14:49 +0000
reviewersKiChjang
servo: Merge #10503 - Replaced SendParam with BodyInit (from canaltinova:master); r=KiChjang Replaced SendParam with BodyInit. Fixes #9433 . Source-Repo: https://github.com/servo/servo Source-Revision: e10ab5ae532037de37295680ce38eca27e2f5b95
servo/components/script/dom/xmlhttprequest.rs
--- a/servo/components/script/dom/xmlhttprequest.rs
+++ b/servo/components/script/dom/xmlhttprequest.rs
@@ -5,19 +5,19 @@
 use cors::CORSResponse;
 use cors::{AsyncCORSResponseListener, CORSRequest, RequestMode, allow_cross_origin_request};
 use document_loader::DocumentLoader;
 use dom::bindings::cell::DOMRefCell;
 use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
 use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
 use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
 use dom::bindings::codegen::Bindings::XMLHttpRequestBinding;
+use dom::bindings::codegen::Bindings::XMLHttpRequestBinding::BodyInit;
 use dom::bindings::codegen::Bindings::XMLHttpRequestBinding::XMLHttpRequestMethods;
 use dom::bindings::codegen::Bindings::XMLHttpRequestBinding::XMLHttpRequestResponseType;
-use dom::bindings::codegen::UnionTypes::BlobOrStringOrURLSearchParams;
 use dom::bindings::conversions::{ToJSValConvertible};
 use dom::bindings::error::{Error, ErrorResult, Fallible};
 use dom::bindings::global::{GlobalRef, GlobalRoot};
 use dom::bindings::inheritance::Castable;
 use dom::bindings::js::{JS, MutHeapJSVal, MutNullableHeap};
 use dom::bindings::js::{Root, RootedReference};
 use dom::bindings::refcounted::Trusted;
 use dom::bindings::reflector::{Reflectable, reflect_dom_object};
@@ -60,18 +60,16 @@ use std::sync::{Arc, Mutex};
 use string_cache::Atom;
 use time;
 use timers::{OneshotTimerCallback, OneshotTimerHandle};
 use url::Url;
 use url::percent_encoding::{utf8_percent_encode, USERNAME_ENCODE_SET, PASSWORD_ENCODE_SET};
 use util::prefs;
 use util::str::DOMString;
 
-pub type SendParam = BlobOrStringOrURLSearchParams;
-
 #[derive(JSTraceable, PartialEq, Copy, Clone, HeapSizeOf)]
 enum XMLHttpRequestState {
     Unsent = 0,
     Opened = 1,
     HeadersReceived = 2,
     Loading = 3,
     Done = 4,
 }
@@ -525,17 +523,17 @@ impl XMLHttpRequestMethods for XMLHttpRe
     }
 
     // https://xhr.spec.whatwg.org/#the-upload-attribute
     fn Upload(&self) -> Root<XMLHttpRequestUpload> {
         Root::from_ref(&*self.upload)
     }
 
     // https://xhr.spec.whatwg.org/#the-send()-method
-    fn Send(&self, data: Option<SendParam>) -> ErrorResult {
+    fn Send(&self, data: Option<BodyInit>) -> ErrorResult {
         // Step 1, 2
         if self.ready_state.get() != XMLHttpRequestState::Opened || self.send_flag.get() {
             return Err(Error::InvalidState);
         }
 
         // Step 3
         let data = match *self.request_method.borrow() {
             Method::Get | Method::Head => None,
@@ -1392,31 +1390,31 @@ impl XHRTimeoutCallback {
             xhr.process_partial_response(XHRProgress::Errored(self.generation_id, Error::Timeout));
         }
     }
 }
 
 trait Extractable {
     fn extract(&self) -> (Vec<u8>, Option<DOMString>);
 }
-impl Extractable for SendParam {
+impl Extractable for BodyInit {
     // https://fetch.spec.whatwg.org/#concept-bodyinit-extract
     fn extract(&self) -> (Vec<u8>, Option<DOMString>) {
         match *self {
-            BlobOrStringOrURLSearchParams::String(ref s) => {
+            BodyInit::String(ref s) => {
                 let encoding = UTF_8 as EncodingRef;
                 (encoding.encode(s, EncoderTrap::Replace).unwrap(),
                     Some(DOMString::from("text/plain;charset=UTF-8")))
             },
-            BlobOrStringOrURLSearchParams::URLSearchParams(ref usp) => {
+            BodyInit::URLSearchParams(ref usp) => {
                 // Default encoding is UTF-8.
                 (usp.serialize(None).into_bytes(),
                     Some(DOMString::from("application/x-www-form-urlencoded;charset=UTF-8")))
             },
-            BlobOrStringOrURLSearchParams::Blob(ref b) => {
+            BodyInit::Blob(ref b) => {
                 let data = b.get_data();
                 let content_type = if b.Type().as_ref().is_empty() {
                     None
                 } else {
                     Some(b.Type())
                 };
                 (data.get_bytes().to_vec(), content_type)
             },