aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/blob.rs22
-rw-r--r--components/script/dom/webidls/Blob.webidl6
-rw-r--r--tests/wpt/metadata/FileAPI/blob/Blob-constructor.html.ini36
-rw-r--r--tests/wpt/metadata/FileAPI/blob/Blob-slice.html.ini61
4 files changed, 22 insertions, 103 deletions
diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs
index dc24cbb01fc..9c23b8f6da0 100644
--- a/components/script/dom/blob.rs
+++ b/components/script/dom/blob.rs
@@ -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 {
diff --git a/components/script/dom/webidls/Blob.webidl b/components/script/dom/webidls/Blob.webidl
index 5f338a15239..bad890fafdc 100644
--- a/components/script/dom/webidls/Blob.webidl
+++ b/components/script/dom/webidls/Blob.webidl
@@ -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 {
diff --git a/tests/wpt/metadata/FileAPI/blob/Blob-constructor.html.ini b/tests/wpt/metadata/FileAPI/blob/Blob-constructor.html.ini
index 3b34e8de52e..e47fa95e7df 100644
--- a/tests/wpt/metadata/FileAPI/blob/Blob-constructor.html.ini
+++ b/tests/wpt/metadata/FileAPI/blob/Blob-constructor.html.ini
@@ -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
-
diff --git a/tests/wpt/metadata/FileAPI/blob/Blob-slice.html.ini b/tests/wpt/metadata/FileAPI/blob/Blob-slice.html.ini
index 9e78feb7d4e..efb90cbe024 100644
--- a/tests/wpt/metadata/FileAPI/blob/Blob-slice.html.ini
+++ b/tests/wpt/metadata/FileAPI/blob/Blob-slice.html.ini
@@ -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
-