mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Adding for support Blob.{close,isClose} #6723
This commit is contained in:
parent
fff104bb41
commit
20f99e92d8
7 changed files with 67 additions and 61 deletions
|
@ -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()
|
||||
}
|
||||
|
||||
// http://dev.w3.org/2006/webapi/FileAPI/#dfn-close
|
||||
//fn Close(self) {
|
||||
// TODO
|
||||
//}
|
||||
// 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);
|
||||
|
||||
// TODO Step 3 if Blob URL Store is implemented
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl FileDerived for Blob {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[Blob-close.html]
|
||||
type: testharness
|
||||
[Blob.close]
|
||||
expected: FAIL
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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."
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue