servo: Merge #10795 - updated Blob constructor to use optional (from yoava333:master); r=Ms2ger
authorYoav Alon <yoava333@gmail.com>
Fri, 22 Apr 2016 23:17:55 -0700
changeset 338605 644b3a693d804943223293e3ee1b071a4b19aab8
parent 338604 06c586917f9c78f9825cf12b290187e2763ddf63
child 338606 69abf181f7e581a463bf28b33b83963b955bc60b
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
servo: Merge #10795 - updated Blob constructor to use optional (from yoava333:master); r=Ms2ger fixes https://github.com/servo/servo/issues/10779 Source-Repo: https://github.com/servo/servo Source-Revision: 1b13ddcd8a22694a764260c3573d3b198478d4ce
servo/components/script/dom/blob.rs
servo/components/script/dom/webidls/Blob.webidl
--- a/servo/components/script/dom/blob.rs
+++ b/servo/components/script/dom/blob.rs
@@ -112,39 +112,38 @@ impl Blob {
                   bytes_end: Option<i64>,
                   typeString: &str) -> Root<Blob> {
 
       let boxed_blob = box Blob::new_inherited(bytes, bytes_start, bytes_end, typeString);
       reflect_dom_object(boxed_blob, global, BlobBinding::Wrap)
     }
 
     // https://w3c.github.io/FileAPI/#constructorBlob
-    pub fn Constructor(global: GlobalRef) -> Fallible<Root<Blob>> {
-        Ok(Blob::new(global, Vec::new(), ""))
-    }
-
-    // https://w3c.github.io/FileAPI/#constructorBlob
-    pub fn Constructor_(global: GlobalRef,
-                        blobParts: Vec<BlobOrString>,
-                        blobPropertyBag: &BlobBinding::BlobPropertyBag)
-                        -> Fallible<Root<Blob>> {
+    pub fn Constructor(global: GlobalRef,
+                       blobParts: Option<Vec<BlobOrString>>,
+                       blobPropertyBag: &BlobBinding::BlobPropertyBag)
+                       -> Fallible<Root<Blob>> {
 
         // TODO: accept other blobParts types - ArrayBuffer or ArrayBufferView
-        let bytes: Vec<u8> = 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<u8> = 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 {
             ""
         };
         Ok(Blob::new(global, bytes, &typeString.to_ascii_lowercase()))
     }
 
--- a/servo/components/script/dom/webidls/Blob.webidl
+++ b/servo/components/script/dom/webidls/Blob.webidl
@@ -1,15 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 // 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 {
 
   readonly attribute unsigned long long size;
   readonly attribute DOMString type;
   readonly attribute boolean isClosed;