Auto merge of #16325 - KiChjang:fix-formdata-wpt, r=cbrewster

Fix formdata-blob.htm

The other failure is a legitimate WPT bug, will fix upstream.

<!-- 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/16325)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-04-10 09:27:01 -05:00 committed by GitHub
commit 638e1dc40b
4 changed files with 10 additions and 14 deletions

View file

@ -87,7 +87,7 @@ unsafe fn write_blob(blob: Root<Blob>,
-> Result<(), ()> {
let blob_vec = try!(blob.get_bytes());
let blob_length = blob_vec.len();
let type_string_bytes = blob.get_type_string().as_bytes().to_vec();
let type_string_bytes = blob.type_string().as_bytes().to_vec();
let type_string_length = type_string_bytes.len();
assert!(JS_WriteUint32Pair(w, StructuredCloneTags::DomBlob as u32, 0));
write_length(w, blob_length);

View file

@ -164,7 +164,7 @@ impl Blob {
}
/// Get a copy of the type_string
pub fn get_type_string(&self) -> String {
pub fn type_string(&self) -> String {
self.type_string.clone()
}

View file

@ -7,6 +7,7 @@ use dom::bindings::codegen::Bindings::FormDataBinding::FormDataMethods;
use dom::bindings::codegen::Bindings::FormDataBinding::FormDataWrap;
use dom::bindings::codegen::UnionTypes::FileOrUSVString;
use dom::bindings::error::Fallible;
use dom::bindings::inheritance::Castable;
use dom::bindings::iterable::Iterable;
use dom::bindings::js::Root;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
@ -79,7 +80,7 @@ impl FormDataMethods for FormData {
let datum = FormDatum {
ty: DOMString::from("file"),
name: DOMString::from(name.0.clone()),
value: FormDatumValue::File(Root::from_ref(&*self.get_file(blob, filename))),
value: FormDatumValue::File(Root::from_ref(&*self.create_an_entry(blob, filename))),
};
let mut data = self.data.borrow_mut();
@ -137,7 +138,7 @@ impl FormDataMethods for FormData {
self.data.borrow_mut().insert(LocalName::from(name.0.clone()), vec![FormDatum {
ty: DOMString::from("file"),
name: DOMString::from(name.0),
value: FormDatumValue::File(Root::from_ref(&*self.get_file(blob, filename))),
value: FormDatumValue::File(Root::from_ref(&*self.create_an_entry(blob, filename))),
}]);
}
@ -145,15 +146,18 @@ impl FormDataMethods for FormData {
impl FormData {
fn get_file(&self, blob: &Blob, opt_filename: Option<USVString>) -> Root<File> {
// https://xhr.spec.whatwg.org/#create-an-entry
// Steps 3-4.
fn create_an_entry(&self, blob: &Blob, opt_filename: Option<USVString>) -> Root<File> {
let name = match opt_filename {
Some(filename) => DOMString::from(filename.0),
None if blob.downcast::<File>().is_none() => DOMString::from("blob"),
None => DOMString::from(""),
};
let bytes = blob.get_bytes().unwrap_or(vec![]);
File::new(&self.global(), BlobImpl::new_from_bytes(bytes), name, None, "")
File::new(&self.global(), BlobImpl::new_from_bytes(bytes), name, None, &blob.type_string())
}
pub fn datums(&self) -> Vec<FormDatum> {

View file

@ -1,8 +0,0 @@
[formdata-blob.htm]
type: testharness
[formdata with blob]
expected: FAIL
[formdata with named blob]
expected: FAIL