Update Blob::{new, new_inherited} to take Strings

This commit is contained in:
Achal Shah 2016-06-16 23:29:09 -07:00
parent 3b98ce0dcc
commit af325a9a3a
5 changed files with 13 additions and 14 deletions

View file

@ -17,7 +17,6 @@ use ipc_channel::ipc;
use net_traits::filemanager_thread::{FileManagerThreadMsg, SelectedFileId};
use num_traits::ToPrimitive;
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::cell::Cell;
use std::cmp::{max, min};
use std::sync::Arc;
@ -127,16 +126,16 @@ pub struct Blob {
}
impl Blob {
pub fn new(global: GlobalRef, blob_impl: BlobImpl, typeString: &str) -> Root<Blob> {
pub fn new(global: GlobalRef, blob_impl: BlobImpl, typeString: String) -> Root<Blob> {
let boxed_blob = box Blob::new_inherited(blob_impl, typeString);
reflect_dom_object(boxed_blob, global, BlobBinding::Wrap)
}
pub fn new_inherited(blob_impl: BlobImpl, typeString: &str) -> Blob {
pub fn new_inherited(blob_impl: BlobImpl, typeString: String) -> Blob {
Blob {
reflector_: Reflector::new(),
blob_impl: blob_impl,
typeString: typeString.to_owned(),
typeString: typeString,
isClosed_: Cell::new(false),
}
}
@ -156,7 +155,7 @@ impl Blob {
};
let slice = DataSlice::from_bytes(bytes);
Ok(Blob::new(global, BlobImpl::new_from_slice(slice), &blobPropertyBag.get_typestring()))
Ok(Blob::new(global, BlobImpl::new_from_slice(slice), blobPropertyBag.get_typestring()))
}
/// Get a slice to inner data, this might incur synchronous read and caching
@ -252,7 +251,7 @@ impl BlobMethods for Blob {
let global = self.global();
let bytes = self.get_slice_or_empty().bytes.clone();
let slice = DataSlice::new(bytes, start, end);
Blob::new(global.r(), BlobImpl::new_from_slice(slice), &relativeContentType)
Blob::new(global.r(), BlobImpl::new_from_slice(slice), relativeContentType.into())
}
// https://w3c.github.io/FileAPI/#dfn-isClosed

View file

@ -26,7 +26,7 @@ impl File {
fn new_inherited(blob_impl: BlobImpl, name: DOMString,
modified: Option<i64>, typeString: &str) -> File {
File {
blob: Blob::new_inherited(blob_impl, typeString),
blob: Blob::new_inherited(blob_impl, typeString.to_owned()),
name: name,
// https://w3c.github.io/FileAPI/#dfn-lastModified
modified: match modified {

View file

@ -101,7 +101,7 @@ impl TestBindingMethods for TestBinding {
fn EnumAttribute(&self) -> TestEnum { TestEnum::_empty }
fn SetEnumAttribute(&self, _: TestEnum) {}
fn InterfaceAttribute(&self) -> Root<Blob> {
Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "")
Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "".to_owned())
}
fn SetInterfaceAttribute(&self, _: &Blob) {}
fn UnionAttribute(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) }
@ -179,7 +179,7 @@ impl TestBindingMethods for TestBinding {
fn SetAttr_to_automatically_rename(&self, _: DOMString) {}
fn GetEnumAttributeNullable(&self) -> Option<TestEnum> { Some(TestEnum::_empty) }
fn GetInterfaceAttributeNullable(&self) -> Option<Root<Blob>> {
Some(Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), ""))
Some(Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "".to_owned()))
}
fn SetInterfaceAttributeNullable(&self, _: Option<&Blob>) {}
fn GetInterfaceAttributeWeak(&self) -> Option<Root<URL>> {
@ -230,7 +230,7 @@ impl TestBindingMethods for TestBinding {
fn ReceiveByteString(&self) -> ByteString { ByteString::new(vec!()) }
fn ReceiveEnum(&self) -> TestEnum { TestEnum::_empty }
fn ReceiveInterface(&self) -> Root<Blob> {
Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "")
Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "".to_owned())
}
fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() }
fn ReceiveObject(&self, _: *mut JSContext) -> *mut JSObject { panic!() }
@ -247,7 +247,7 @@ impl TestBindingMethods for TestBinding {
}
fn ReceiveSequence(&self) -> Vec<i32> { vec![1] }
fn ReceiveInterfaceSequence(&self) -> Vec<Root<Blob>> {
vec![Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "")]
vec![Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "".to_owned())]
}
fn ReceiveNullableBoolean(&self) -> Option<bool> { Some(false) }
@ -268,7 +268,7 @@ impl TestBindingMethods for TestBinding {
fn ReceiveNullableByteString(&self) -> Option<ByteString> { Some(ByteString::new(vec!())) }
fn ReceiveNullableEnum(&self) -> Option<TestEnum> { Some(TestEnum::_empty) }
fn ReceiveNullableInterface(&self) -> Option<Root<Blob>> {
Some(Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), ""))
Some(Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "".to_owned()))
}
fn ReceiveNullableObject(&self, _: *mut JSContext) -> *mut JSObject { ptr::null_mut() }
fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> {

View file

@ -592,7 +592,7 @@ impl Runnable for MessageReceivedTask {
match ws.binary_type.get() {
BinaryType::Blob => {
let slice = DataSlice::from_bytes(data);
let blob = Blob::new(global.r(), BlobImpl::new_from_slice(slice), "");
let blob = Blob::new(global.r(), BlobImpl::new_from_slice(slice), "".to_owned());
blob.to_jsval(cx, message.handle_mut());
}
BinaryType::Arraybuffer => {

View file

@ -1117,7 +1117,7 @@ impl XMLHttpRequest {
// Step 3, 4
let slice = DataSlice::from_bytes(self.response.borrow().to_vec());
let blob = Blob::new(self.global().r(), BlobImpl::new_from_slice(slice), &mime);
let blob = Blob::new(self.global().r(), BlobImpl::new_from_slice(slice), mime);
self.response_blob.set(Some(blob.r()));
blob
}