From 711c23ae3939263eef6b5ec41253432be9d0104d Mon Sep 17 00:00:00 2001 From: Yoav Alon Date: Thu, 21 Apr 2016 22:26:08 +0300 Subject: [PATCH] updated Blob constructor to use optional, fixes https://github.com/servo/servo/issues/10779 --- components/script/dom/blob.rs | 41 +++++++++---------- components/script/dom/webidls/Blob.webidl | 3 +- .../FileAPI/blob/Blob-constructor.html.ini | 4 -- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs index de7a7b8c35a0..49fc47e8a68e 100644 --- a/components/script/dom/blob.rs +++ b/components/script/dom/blob.rs @@ -117,29 +117,28 @@ impl Blob { } // https://w3c.github.io/FileAPI/#constructorBlob - pub fn Constructor(global: GlobalRef) -> Fallible> { - Ok(Blob::new(global, Vec::new(), "")) - } - - // https://w3c.github.io/FileAPI/#constructorBlob - pub fn Constructor_(global: GlobalRef, - blobParts: Vec, - blobPropertyBag: &BlobBinding::BlobPropertyBag) - -> Fallible> { + pub fn Constructor(global: GlobalRef, + blobParts: Option>, + blobPropertyBag: &BlobBinding::BlobPropertyBag) + -> Fallible> { // 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 bytes: Vec = match blobParts { + None => Vec::new(), + Some(blobs) => { + blobs.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 { diff --git a/components/script/dom/webidls/Blob.webidl b/components/script/dom/webidls/Blob.webidl index bad890fafdcd..f5ef8d035e07 100644 --- a/components/script/dom/webidls/Blob.webidl +++ b/components/script/dom/webidls/Blob.webidl @@ -4,8 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // http://dev.w3.org/2006/webapi/FileAPI/#dfn-Blob -[Constructor, - Constructor(sequence<(/*ArrayBuffer or ArrayBufferView or */Blob or DOMString)> blobParts, +[Constructor(optional sequence<(/*ArrayBuffer or ArrayBufferView or */Blob or DOMString)> blobParts, optional BlobPropertyBag options), Exposed=Window/*,Worker*/] interface Blob { diff --git a/tests/wpt/metadata/FileAPI/blob/Blob-constructor.html.ini b/tests/wpt/metadata/FileAPI/blob/Blob-constructor.html.ini index 5f4c6aaa2449..233ecbce3d64 100644 --- a/tests/wpt/metadata/FileAPI/blob/Blob-constructor.html.ini +++ b/tests/wpt/metadata/FileAPI/blob/Blob-constructor.html.ini @@ -46,7 +46,3 @@ bug: https://github.com/servo/servo/issues/10744 expected: FAIL - [Blob constructor with undefined as first argument] - bug: https://github.com/servo/servo/issues/10779 - expected: FAIL -