mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Implementation of Blob Constructor with test changes
This commit is contained in:
parent
7a9dc57761
commit
34726d8b9e
4 changed files with 22 additions and 103 deletions
|
@ -4,11 +4,14 @@
|
|||
|
||||
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;
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bindings::trace::JSTraceable;
|
||||
use encoding::all::UTF_8;
|
||||
use encoding::types::{EncoderTrap, Encoding};
|
||||
use num::ToPrimitive;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::ToOwned;
|
||||
|
@ -120,16 +123,29 @@ impl Blob {
|
|||
|
||||
// https://w3c.github.io/FileAPI/#constructorBlob
|
||||
pub fn Constructor_(global: GlobalRef,
|
||||
blobParts: DOMString,
|
||||
blobParts: Vec<BlobOrString>,
|
||||
blobPropertyBag: &BlobBinding::BlobPropertyBag)
|
||||
-> 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_) {
|
||||
&*blobPropertyBag.type_
|
||||
} 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 {
|
||||
|
|
|
@ -4,11 +4,9 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// 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(DOMString blobParts, optional BlobPropertyBag options),
|
||||
Constructor(sequence<(/*ArrayBuffer or ArrayBufferView or */Blob or DOMString)> blobParts,
|
||||
optional BlobPropertyBag options),
|
||||
Exposed=Window/*,Worker*/]
|
||||
interface Blob {
|
||||
|
||||
|
|
|
@ -3,22 +3,7 @@
|
|||
[Passing non-objects, Dates and RegExps for blobParts should throw a TypeError.]
|
||||
expected: FAIL
|
||||
|
||||
[A plain object should be treated as a sequence for the blobParts argument.]
|
||||
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.]
|
||||
[Passing an platform object that supports indexed properties as the blobParts array should work (window).]
|
||||
expected: FAIL
|
||||
|
||||
[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).]
|
||||
expected: FAIL
|
||||
|
||||
[ToString should be called on elements of the blobParts array.]
|
||||
expected: FAIL
|
||||
|
||||
[ArrayBuffer elements of the blobParts array should be supported.]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -42,9 +24,6 @@
|
|||
[Passing a Float64Array as element of the blobParts array should work.]
|
||||
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).]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -54,12 +33,6 @@
|
|||
[Passing a platform array object as the blobParts array should work (MessagePort[\]).]
|
||||
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]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -71,10 +44,3 @@
|
|||
|
||||
[no-argument Blob constructor without 'new']
|
||||
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
|
||||
|
||||
|
|
|
@ -1,65 +1,5 @@
|
|||
[Blob-slice.html]
|
||||
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).]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -158,4 +98,3 @@
|
|||
|
||||
[Invalid contentType ("te xt/plain")]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue