diff --git a/servo/components/script/dom/blob.rs b/servo/components/script/dom/blob.rs index dc24cbb01fc8..9c23b8f6da06 100644 --- a/servo/components/script/dom/blob.rs +++ b/servo/components/script/dom/blob.rs @@ -4,11 +4,14 @@ use dom::bindings::codegen::Bindings::BlobBinding; use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods; +use dom::bindings::codegen::UnionTypes::BlobOrString; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::trace::JSTraceable; +use encoding::all::UTF_8; +use encoding::types::{EncoderTrap, Encoding}; use num::ToPrimitive; use std::ascii::AsciiExt; use std::borrow::ToOwned; @@ -120,16 +123,29 @@ impl Blob { // https://w3c.github.io/FileAPI/#constructorBlob pub fn Constructor_(global: GlobalRef, - blobParts: DOMString, + blobParts: Vec, blobPropertyBag: &BlobBinding::BlobPropertyBag) -> Fallible> { - // TODO: accept other blobParts types - ArrayBuffer or ArrayBufferView or Blob + + // TODO: accept other blobParts types - ArrayBuffer or ArrayBufferView + let bytes: Vec = blobParts.iter() + .flat_map(|bPart| { + match bPart { + &BlobOrString::String(ref s) => { + UTF_8.encode(s, EncoderTrap::Replace).unwrap() + }, + &BlobOrString::Blob(ref b) => { + b.get_data().get_bytes().to_vec() + }, + } + }) + .collect(); let typeString = if is_ascii_printable(&blobPropertyBag.type_) { &*blobPropertyBag.type_ } else { "" }; - Ok(Blob::new(global, blobParts.into(), &typeString.to_ascii_lowercase())) + Ok(Blob::new(global, bytes, &typeString.to_ascii_lowercase())) } pub fn get_data(&self) -> &DataSlice { diff --git a/servo/components/script/dom/webidls/Blob.webidl b/servo/components/script/dom/webidls/Blob.webidl index 5f338a152399..bad890fafdcd 100644 --- a/servo/components/script/dom/webidls/Blob.webidl +++ b/servo/components/script/dom/webidls/Blob.webidl @@ -4,11 +4,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // http://dev.w3.org/2006/webapi/FileAPI/#dfn-Blob -//[Exposed=Window,Worker][Constructor, -// Constructor(sequence<(ArrayBuffer or ArrayBufferView or Blob or DOMString)> blobParts, -// optional BlobPropertyBag options)] [Constructor, - Constructor(DOMString blobParts, optional BlobPropertyBag options), + Constructor(sequence<(/*ArrayBuffer or ArrayBufferView or */Blob or DOMString)> blobParts, + optional BlobPropertyBag options), Exposed=Window/*,Worker*/] interface Blob {