Implementation of Blob Constructor with test changes

This commit is contained in:
St.Spyder 2016-03-12 20:35:50 +05:30
parent 7a9dc57761
commit 34726d8b9e
4 changed files with 22 additions and 103 deletions

View file

@ -4,11 +4,14 @@
use dom::bindings::codegen::Bindings::BlobBinding; use dom::bindings::codegen::Bindings::BlobBinding;
use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods; use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
use dom::bindings::codegen::UnionTypes::BlobOrString;
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef; use dom::bindings::global::GlobalRef;
use dom::bindings::js::Root; use dom::bindings::js::Root;
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::trace::JSTraceable; use dom::bindings::trace::JSTraceable;
use encoding::all::UTF_8;
use encoding::types::{EncoderTrap, Encoding};
use num::ToPrimitive; use num::ToPrimitive;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::borrow::ToOwned; use std::borrow::ToOwned;
@ -120,16 +123,29 @@ impl Blob {
// https://w3c.github.io/FileAPI/#constructorBlob // https://w3c.github.io/FileAPI/#constructorBlob
pub fn Constructor_(global: GlobalRef, pub fn Constructor_(global: GlobalRef,
blobParts: DOMString, blobParts: Vec<BlobOrString>,
blobPropertyBag: &BlobBinding::BlobPropertyBag) blobPropertyBag: &BlobBinding::BlobPropertyBag)
-> Fallible<Root<Blob>> { -> Fallible<Root<Blob>> {
// TODO: accept other blobParts types - ArrayBuffer or ArrayBufferView or 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 typeString = if is_ascii_printable(&blobPropertyBag.type_) { let typeString = if is_ascii_printable(&blobPropertyBag.type_) {
&*blobPropertyBag.type_ &*blobPropertyBag.type_
} else { } 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 { pub fn get_data(&self) -> &DataSlice {

View file

@ -4,11 +4,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// http://dev.w3.org/2006/webapi/FileAPI/#dfn-Blob // 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,
Constructor(DOMString blobParts, optional BlobPropertyBag options), Constructor(sequence<(/*ArrayBuffer or ArrayBufferView or */Blob or DOMString)> blobParts,
optional BlobPropertyBag options),
Exposed=Window/*,Worker*/] Exposed=Window/*,Worker*/]
interface Blob { interface Blob {

View file

@ -3,22 +3,7 @@
[Passing non-objects, Dates and RegExps for blobParts should throw a TypeError.] [Passing non-objects, Dates and RegExps for blobParts should throw a TypeError.]
expected: FAIL expected: FAIL
[A plain object should be treated as a sequence for the blobParts argument.] [Passing an platform object that supports indexed properties as the blobParts array should work (window).]
expected: FAIL
[A plain object with a length property should be treated as a sequence for the blobParts argument.]
expected: FAIL
[A Uint8Array object should be treated as a sequence for the blobParts argument.]
expected: FAIL
[The length getter should be invoked and any exceptions should be propagated.]
expected: FAIL
[A platform object that supports indexed properties should be treated as a sequence for the blobParts argument (overwritten 'length'.)]
expected: FAIL
[ToUint32 should be applied to the length and any exceptions should be propagated.]
expected: FAIL expected: FAIL
[Getters and value conversions should happen in order until an exception is thrown.] [Getters and value conversions should happen in order until an exception is thrown.]
@ -30,9 +15,6 @@
[Changes to the blobParts array should be reflected in the returned Blob (unshift).] [Changes to the blobParts array should be reflected in the returned Blob (unshift).]
expected: FAIL expected: FAIL
[ToString should be called on elements of the blobParts array.]
expected: FAIL
[ArrayBuffer elements of the blobParts array should be supported.] [ArrayBuffer elements of the blobParts array should be supported.]
expected: FAIL expected: FAIL
@ -42,9 +24,6 @@
[Passing a Float64Array as element of the blobParts array should work.] [Passing a Float64Array as element of the blobParts array should work.]
expected: FAIL expected: FAIL
[Passing an element as the blobParts array should work.]
expected: FAIL
[Passing an platform object that supports indexed properties as the blobParts array should work (window with custom toString).] [Passing an platform object that supports indexed properties as the blobParts array should work (window with custom toString).]
expected: FAIL expected: FAIL
@ -54,12 +33,6 @@
[Passing a platform array object as the blobParts array should work (MessagePort[\]).] [Passing a platform array object as the blobParts array should work (MessagePort[\]).]
expected: FAIL expected: FAIL
[Passing a platform array object as the blobParts array should work (Attr[\]).]
expected: FAIL
[Array with two blobs]
expected: FAIL
[Array with two buffers] [Array with two buffers]
expected: FAIL expected: FAIL
@ -71,10 +44,3 @@
[no-argument Blob constructor without 'new'] [no-argument Blob constructor without 'new']
expected: FAIL expected: FAIL
[A plain object with @@iterator should be treated as a sequence for the blobParts argument.]
expected: FAIL
[A plain object with @@iterator and a length property should be treated as a sequence for the blobParts argument.]
expected: FAIL

View file

@ -1,65 +1,5 @@
[Blob-slice.html] [Blob-slice.html]
type: testharness type: testharness
[Slicing test: slice (1,0).]
expected: FAIL
[Slicing test: slice (1,2).]
expected: FAIL
[Slicing test: slice (1,3).]
expected: FAIL
[Slicing test: slice (1,4).]
expected: FAIL
[Slicing test: slice (1,5).]
expected: FAIL
[Slicing test: slice (1,6).]
expected: FAIL
[Slicing test: slice (1,7).]
expected: FAIL
[Slicing test: slice (2,1).]
expected: FAIL
[Slicing test: slice (2,2).]
expected: FAIL
[Slicing test: slice (2,3).]
expected: FAIL
[Slicing test: slice (3,0).]
expected: FAIL
[Slicing test: slice (3,1).]
expected: FAIL
[Slicing test: slice (3,2).]
expected: FAIL
[Slicing test: slice (3,3).]
expected: FAIL
[Slicing test: slice (3,4).]
expected: FAIL
[Slicing test: slice (4,0).]
expected: FAIL
[Slicing test: slice (4,1).]
expected: FAIL
[Slicing test: slice (4,2).]
expected: FAIL
[Slicing test: slice (4,3).]
expected: FAIL
[Slicing test: slice (4,4).]
expected: FAIL
[Slicing test: slice (5,0).] [Slicing test: slice (5,0).]
expected: FAIL expected: FAIL
@ -158,4 +98,3 @@
[Invalid contentType ("te xt/plain")] [Invalid contentType ("te xt/plain")]
expected: FAIL expected: FAIL