Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start accepting correct parameters for the Blob constructor #9977

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Start accepting correct parameters for the Blob constructor

Touches #8397.
  • Loading branch information
tbu- committed Mar 12, 2016
commit c955a9ed3c28ee7adf7ba7bb46c875063112eae7
@@ -4,6 +4,7 @@

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;
@@ -120,16 +121,28 @@ impl Blob {

// https://w3c.github.io/FileAPI/#constructorBlob
pub fn Constructor_(global: GlobalRef,
blobParts: DOMString,
blobParts: Vec<BlobOrString>,
blobPropertyBag: &BlobBinding::BlobPropertyBag)
-> Fallible<Root<Blob>> {
fn to_bytes(blob_or_string: &BlobOrString) -> &[u8] {
match *blob_or_string {
BlobOrString::Blob(ref b) => b.get_data().get_bytes(),
BlobOrString::String(ref s) => s.as_bytes(),
}
}

// TODO: accept other blobParts types - ArrayBuffer or ArrayBufferView or Blob
let typeString = if is_ascii_printable(&blobPropertyBag.type_) {
&*blobPropertyBag.type_
} else {
""
};
Ok(Blob::new(global, blobParts.into(), &typeString.to_ascii_lowercase()))
let len = blobParts.iter().map(|p| to_bytes(p).len()).fold(0, |s, a| s + a);
let mut bytes = Vec::with_capacity(len);
for part in blobParts.iter().map(to_bytes) {
bytes.push(part);
}
Ok(Blob::new(global, Vec::new(), &typeString.to_ascii_lowercase()))
}

pub fn get_data(&self) -> &DataSlice {
@@ -8,7 +8,8 @@
// Constructor(sequence<(ArrayBuffer or ArrayBufferView or Blob or DOMString)> blobParts,
// optional BlobPropertyBag options)]
[Constructor,
Constructor(DOMString blobParts, optional BlobPropertyBag options),
Constructor(sequence<(Blob or DOMString)> blobParts,
optional BlobPropertyBag options),
Exposed=Window/*,Worker*/]
interface Blob {

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.