Skip to content

Commit

Permalink
Replaced SendParam with BodyInit
Browse files Browse the repository at this point in the history
  • Loading branch information
canova committed Apr 9, 2016
1 parent 5a3d685 commit d49a84c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions components/script/dom/xmlhttprequest.rs
Expand Up @@ -10,9 +10,9 @@ 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};
Expand Down Expand Up @@ -65,8 +65,6 @@ use url::percent_encoding::{utf8_percent_encode, USERNAME_ENCODE_SET, PASSWORD_E
use util::prefs;
use util::str::DOMString;

pub type SendParam = BlobOrStringOrURLSearchParams;

#[derive(JSTraceable, PartialEq, Copy, Clone, HeapSizeOf)]
enum XMLHttpRequestState {
Unsent = 0,
Expand Down Expand Up @@ -530,7 +528,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
}

// 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);
Expand Down Expand Up @@ -1397,21 +1395,21 @@ impl XHRTimeoutCallback {
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
Expand Down

0 comments on commit d49a84c

Please sign in to comment.