aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/blob.rs38
-rw-r--r--components/script/dom/filereader.rs28
-rw-r--r--components/script/dom/webidls/Blob.webidl7
-rw-r--r--tests/wpt/metadata/FileAPI/blob/Blob-close.html.ini5
-rw-r--r--tests/wpt/metadata/FileAPI/idlharness.html.ini12
-rw-r--r--tests/wpt/metadata/FileAPI/idlharness.worker.js.ini12
-rw-r--r--tests/wpt/web-platform-tests/FileAPI/blob/Blob-close.html26
7 files changed, 67 insertions, 61 deletions
diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs
index 1ba7b929eaf..4213b8ff2a6 100644
--- a/components/script/dom/blob.rs
+++ b/components/script/dom/blob.rs
@@ -18,6 +18,7 @@ use num::ToPrimitive;
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::cmp::{min, max};
+use std::cell::{Cell};
#[derive(JSTraceable)]
pub enum BlobTypeId {
@@ -32,8 +33,8 @@ pub struct Blob {
type_: BlobTypeId,
bytes: Option<Vec<u8>>,
typeString: DOMString,
- global: GlobalField
- // isClosed_: bool
+ global: GlobalField,
+ isClosed_: Cell<bool>
}
fn is_ascii_printable(string: &DOMString) -> bool{
@@ -50,8 +51,8 @@ impl Blob {
type_: type_,
bytes: bytes,
typeString: typeString.to_owned(),
- global: GlobalField::from_rooted(&global)
- //isClosed_: false
+ global: GlobalField::from_rooted(&global),
+ isClosed_: Cell::new(false)
}
}
@@ -83,7 +84,6 @@ impl Blob {
pub trait BlobHelpers {
fn read_out_buffer(self) -> Receiver<Vec<u8>>;
- fn read_out_type(self) -> DOMString;
}
impl<'a> BlobHelpers for &'a Blob {
@@ -92,9 +92,6 @@ impl<'a> BlobHelpers for &'a Blob {
send.send(self.bytes.clone().unwrap_or(vec![])).unwrap();
recv
}
- fn read_out_type(self) -> DOMString {
- self.typeString.clone()
- }
}
impl<'a> BlobMethods for &'a Blob {
@@ -159,15 +156,24 @@ impl<'a> BlobMethods for &'a Blob {
}
}
- // http://dev.w3.org/2006/webapi/FileAPI/#dfn-isClosed
- //fn IsClosed(self) -> bool {
- // self.isClosed_.clone()
- //}
+ // https://dev.w3.org/2006/webapi/FileAPI/#dfn-isClosed
+ fn IsClosed(self) -> bool {
+ self.isClosed_.get()
+ }
+
+ // https://dev.w3.org/2006/webapi/FileAPI/#dfn-close
+ fn Close(self) {
+ // Step 1
+ if self.isClosed_.get() {
+ return;
+ }
+
+ // Step 2
+ self.isClosed_.set(true);
- // http://dev.w3.org/2006/webapi/FileAPI/#dfn-close
- //fn Close(self) {
- // TODO
- //}
+ // TODO Step 3 if Blob URL Store is implemented
+
+ }
}
impl FileDerived for Blob {
diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs
index 09f6c83a99e..256b1c8b6bc 100644
--- a/components/script/dom/filereader.rs
+++ b/components/script/dom/filereader.rs
@@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
use dom::bindings::codegen::Bindings::FileReaderBinding::{self, FileReaderConstants, FileReaderMethods};
use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast};
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
@@ -268,7 +269,6 @@ impl FileReader {
Ok(Some(output))
}
-
}
impl<'a> FileReaderMethods for &'a FileReader {
@@ -287,13 +287,22 @@ impl<'a> FileReaderMethods for &'a FileReader {
if self.ready_state.get() == FileReaderReadyState::Loading {
return Err(InvalidState);
}
- //TODO STEP 2 if isClosed implemented in Blob
+
+ // Step 2
+ if blob.IsClosed() {
+ let global = self.global.root();
+ let exception = DOMException::new(global.r(), DOMErrorName::InvalidStateError);
+ self.error.set(Some(JS::from_rooted(&exception)));
+
+ self.dispatch_progress_event("error".to_owned(), 0, None);
+ return Ok(());
+ }
// Step 3
self.change_ready_state(FileReaderReadyState::Loading);
let bytes = blob.read_out_buffer();
- let type_ = blob.read_out_type();
+ let type_ = blob.Type();
let load_data = ReadData::new(bytes, type_, None, FileReaderFunction::ReadAsDataUrl);
@@ -307,13 +316,22 @@ impl<'a> FileReaderMethods for &'a FileReader {
if self.ready_state.get() == FileReaderReadyState::Loading {
return Err(InvalidState);
}
- //TODO STEP 2 if isClosed implemented in Blob
+
+ // Step 2
+ if blob.IsClosed() {
+ let global = self.global.root();
+ let exception = DOMException::new(global.r(), DOMErrorName::InvalidStateError);
+ self.error.set(Some(JS::from_rooted(&exception)));
+
+ self.dispatch_progress_event("error".to_owned(), 0, None);
+ return Ok(());
+ }
// Step 3
self.change_ready_state(FileReaderReadyState::Loading);
let bytes = blob.read_out_buffer();
- let type_ = blob.read_out_type();
+ let type_ = blob.Type();
let load_data = ReadData::new(bytes, type_, label, FileReaderFunction::ReadAsText);
diff --git a/components/script/dom/webidls/Blob.webidl b/components/script/dom/webidls/Blob.webidl
index 3b377a938d6..5f338a15239 100644
--- a/components/script/dom/webidls/Blob.webidl
+++ b/components/script/dom/webidls/Blob.webidl
@@ -8,19 +8,20 @@
// Constructor(sequence<(ArrayBuffer or ArrayBufferView or Blob or DOMString)> blobParts,
// optional BlobPropertyBag options)]
[Constructor,
- Constructor(DOMString blobParts, optional BlobPropertyBag options)]
+ Constructor(DOMString blobParts, optional BlobPropertyBag options),
+ Exposed=Window/*,Worker*/]
interface Blob {
readonly attribute unsigned long long size;
readonly attribute DOMString type;
- //readonly attribute boolean isClosed;
+ readonly attribute boolean isClosed;
//slice Blob into byte-ranged chunks
Blob slice([Clamp] optional long long start,
[Clamp] optional long long end,
optional DOMString contentType);
- //void close();
+ void close();
};
diff --git a/tests/wpt/metadata/FileAPI/blob/Blob-close.html.ini b/tests/wpt/metadata/FileAPI/blob/Blob-close.html.ini
deleted file mode 100644
index 644f864f518..00000000000
--- a/tests/wpt/metadata/FileAPI/blob/Blob-close.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[Blob-close.html]
- type: testharness
- [Blob.close]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/FileAPI/idlharness.html.ini b/tests/wpt/metadata/FileAPI/idlharness.html.ini
index 176ebf0bebd..8f91c767de4 100644
--- a/tests/wpt/metadata/FileAPI/idlharness.html.ini
+++ b/tests/wpt/metadata/FileAPI/idlharness.html.ini
@@ -9,18 +9,6 @@
[URL interface: operation revokeObjectURL(DOMString)]
expected: FAIL
- [Blob interface: attribute isClosed]
- expected: FAIL
-
- [Blob interface: operation close()]
- expected: FAIL
-
- [Blob interface: new Blob(["TEST"\]) must inherit property "isClosed" with the proper type (2)]
- expected: FAIL
-
- [Blob interface: new Blob(["TEST"\]) must inherit property "close" with the proper type (4)]
- expected: FAIL
-
[File interface: existence and properties of interface object]
expected: FAIL
diff --git a/tests/wpt/metadata/FileAPI/idlharness.worker.js.ini b/tests/wpt/metadata/FileAPI/idlharness.worker.js.ini
index 665ea8e0562..221a609a2a2 100644
--- a/tests/wpt/metadata/FileAPI/idlharness.worker.js.ini
+++ b/tests/wpt/metadata/FileAPI/idlharness.worker.js.ini
@@ -9,18 +9,6 @@
[URL interface: operation revokeObjectURL(DOMString)]
expected: FAIL
- [Blob interface: attribute isClosed]
- expected: FAIL
-
- [Blob interface: operation close()]
- expected: FAIL
-
- [Blob interface: new Blob(["TEST"\]) must inherit property "isClosed" with the proper type (2)]
- expected: FAIL
-
- [Blob interface: new Blob(["TEST"\]) must inherit property "close" with the proper type (4)]
- expected: FAIL
-
[File interface: existence and properties of interface object]
expected: FAIL
diff --git a/tests/wpt/web-platform-tests/FileAPI/blob/Blob-close.html b/tests/wpt/web-platform-tests/FileAPI/blob/Blob-close.html
index 8ec8bcca0b6..45df1e21166 100644
--- a/tests/wpt/web-platform-tests/FileAPI/blob/Blob-close.html
+++ b/tests/wpt/web-platform-tests/FileAPI/blob/Blob-close.html
@@ -11,17 +11,27 @@ test(function() {
var blob = new Blob(["TEST"]);
var sliced = blob.slice();
blob.close();
- test_blob(function() {
- return blob;
- }, {
- expected: "",
- type: "",
- desc: "Blob should be empty."
- });
+
+ async_test(function(t) {
+ var reader = new FileReader();
+
+ reader.onload = t.step_func(function(evt) {
+ assert_unreached("Should not dispatch the load event");
+ });
+
+ reader.onerror = t.step_func(function(e) {
+ assert_equals(reader.result, null);
+ assert_equals(reader.error.code, DOMException.INVALID_STATE_ERR);
+ t.done();
+ });
+
+ reader.readAsText(blob, "UTF-8");
+ }, "Closed Blob");
+
test_blob(function() {
return sliced;
}, {
- expected: "PASS",
+ expected: "TEST",
type: "",
desc: "Slice should still have the data."
});