servo: Merge
#16325 - Fix formdata-blob.htm (from KiChjang:fix-formdata-wpt); r=cbrewster
The other failure is a legitimate WPT bug, will fix upstream.
Source-Repo:
https://github.com/servo/servo
Source-Revision:
638e1dc40bc70c3c0d9cd2efdaef852fdb371382
--- a/servo/components/script/dom/bindings/structuredclone.rs
+++ b/servo/components/script/dom/bindings/structuredclone.rs
@@ -82,17 +82,17 @@ unsafe fn read_blob(cx: *mut JSContext,
return blob.reflector().get_jsobject().get()
}
unsafe fn write_blob(blob: Root<Blob>,
w: *mut JSStructuredCloneWriter)
-> 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);
write_length(w, type_string_length);
assert!(JS_WriteBytes(w, blob_vec.as_ptr() as *const raw::c_void, blob_length));
assert!(JS_WriteBytes(w, type_string_bytes.as_ptr() as *const raw::c_void, type_string_length));
return Ok(())
}
--- a/servo/components/script/dom/blob.rs
+++ b/servo/components/script/dom/blob.rs
@@ -159,17 +159,17 @@ impl Blob {
let range = rel_pos.to_abs_range(v.len());
v.index(range).to_vec()
})
}
}
}
/// Get a copy of the type_string
- pub fn get_type_string(&self) -> String {
+ pub fn type_string(&self) -> String {
self.type_string.clone()
}
/// Get a FileID representing the Blob content,
/// used by URL.createObjectURL
pub fn get_blob_url_id(&self) -> Uuid {
let opt_sliced_parent = match *self.blob_impl.borrow() {
BlobImpl::Sliced(ref parent, ref rel_pos) => {
--- a/servo/components/script/dom/formdata.rs
+++ b/servo/components/script/dom/formdata.rs
@@ -2,16 +2,17 @@
* 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/. */
use dom::bindings::cell::DOMRefCell;
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};
use dom::bindings::str::{DOMString, USVString};
use dom::blob::{Blob, BlobImpl};
use dom::file::File;
use dom::globalscope::GlobalScope;
use dom::htmlformelement::{HTMLFormElement, FormDatumValue, FormDatum};
@@ -74,17 +75,17 @@ impl FormDataMethods for FormData {
}
#[allow(unrooted_must_root)]
// https://xhr.spec.whatwg.org/#dom-formdata-append
fn Append_(&self, name: USVString, blob: &Blob, filename: Option<USVString>) {
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();
match data.entry(LocalName::from(name.0)) {
Occupied(entry) => entry.into_mut().push(datum),
Vacant(entry) => { entry.insert(vec!(datum)); },
}
@@ -132,33 +133,36 @@ impl FormDataMethods for FormData {
}
#[allow(unrooted_must_root)]
// https://xhr.spec.whatwg.org/#dom-formdata-set
fn Set_(&self, name: USVString, blob: &Blob, filename: Option<USVString>) {
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))),
}]);
}
}
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> {
self.data.borrow().values()
.flat_map(|value| value.iter())
.map(|value| value.clone())
.collect()
}