Skip to content

Commit

Permalink
updated Blob constructor to use optional, fixes #10779
Browse files Browse the repository at this point in the history
  • Loading branch information
yoava333 committed Apr 21, 2016
1 parent 98ae238 commit 711c23a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
41 changes: 20 additions & 21 deletions components/script/dom/blob.rs
Expand Up @@ -117,29 +117,28 @@ impl Blob {
}

// 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 {
Expand Down
3 changes: 1 addition & 2 deletions components/script/dom/webidls/Blob.webidl
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions tests/wpt/metadata/FileAPI/blob/Blob-constructor.html.ini
Expand Up @@ -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

0 comments on commit 711c23a

Please sign in to comment.