Adding for support Blob.{close,isClose} #6723

This commit is contained in:
farodin91 2015-07-28 08:57:08 +02:00
parent fff104bb41
commit 20f99e92d8
7 changed files with 67 additions and 61 deletions

View file

@ -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 {