Add some more Blob methods/types

This commit is contained in:
Tom Schuster 2013-11-15 15:41:49 +01:00
parent e98ddef9bb
commit 586dd6aed6
4 changed files with 63 additions and 17 deletions

View file

@ -4,12 +4,25 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* http://dev.w3.org/2006/webapi/FileAPI/
* http://dev.w3.org/2006/webapi/FileAPI/#blob
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
[Constructor]
[Constructor/*,
Constructor(sequence<(ArrayBuffer or ArrayBufferView or Blob or DOMString)> blobParts, optional BlobPropertyBag option)*/]
interface Blob {
readonly attribute unsigned long long size;
readonly attribute DOMString type;
Blob slice([Clamp] optional long long start,
[Clamp] optional long long end,
optional DOMString contentType);
void close();
};
dictionary BlobPropertyBag {
DOMString type = "";
};

View file

@ -1097,14 +1097,9 @@ for (uint32_t i = 0; i < length; ++i) {
if isMember:
# We have to make a copy, because our jsval may well not
# live as long as our string needs to.
declType = CGGeneric("nsString")
return (
"{\n"
" FakeDependentString str;\n"
"%s\n"
" ${declName} = str;\n"
"}\n" % CGIndenter(CGGeneric(getConversionCode("str"))).define(),
declType, None, isOptional, None)
declType = CGGeneric("DOMString")
return ("%s\n" % getConversionCode("${declName}"),
declType, None, isOptional, None)
declType = "DOMString"
initialValue = None
@ -4833,7 +4828,7 @@ class CGDictionary(CGThing):
else:
inheritance = ""
memberDecls = [" %s: %s," %
(m[0].identifier.name, self.getMemberType(m))
(self.makeMemberName(m[0].identifier.name), self.getMemberType(m))
for m in self.memberInfo]
return (string.Template(
@ -4876,8 +4871,8 @@ class CGDictionary(CGThing):
return "false"
elif ty in ["i32", "u32", "i16", "u16"]:
return "0"
elif ty is "nsString":
return "\"\""
elif ty == "DOMString":
return '~""'
elif ty.startswith("Option"):
return "None"
else:
@ -4895,7 +4890,7 @@ class CGDictionary(CGThing):
" ${selfName} {\n" +
((" parent: %s::%s::new(),\n" % (self.makeModuleName(d.parent),
self.makeClassName(d.parent))) if d.parent else "") +
"\n".join(" %s: %s," % (m[0].identifier.name, defaultValue(self.getMemberType(m))) for m in self.memberInfo) + "\n"
"\n".join(" %s: %s," % (self.makeMemberName(m[0].identifier.name), defaultValue(self.getMemberType(m))) for m in self.memberInfo) + "\n"
" }\n"
" }\n"
"\n"
@ -4965,7 +4960,7 @@ class CGDictionary(CGThing):
holderType, dealWithOptional, initialValue)) = memberInfo
replacements = { "val": "temp",
"valPtr": "&temp",
"declName": ("self.%s" % member.identifier.name),
"declName": ("self.%s" % self.makeMemberName(member.identifier.name)),
# We need a holder name for external interfaces, but
# it's scoped down to the conversion so we can just use
# anything we want.
@ -5021,7 +5016,7 @@ class CGDictionary(CGThing):
"}")
conversionReplacements["convert"] = CGIndenter(
CGGeneric(conversionReplacements["convert"])).define()
return CGGeneric(
string.Template(conversion).substitute(conversionReplacements)
)
@ -5030,6 +5025,13 @@ class CGDictionary(CGThing):
def makeIdName(name):
return name + "_id"
@staticmethod
def makeMemberName(name):
# Can't use Rust keywords as member names.
if name == "type":
return name + "_"
return name
@staticmethod
def getDictionaryDependencies(dictionary):
deps = set();

View file

@ -11,6 +11,23 @@ pub trait JSValConvertible {
fn from_jsval(val: JSVal) -> Option<Self>;
}
impl JSValConvertible for i64 {
#[fixed_stack_segment]
fn to_jsval(&self) -> JSVal {
unsafe {
RUST_DOUBLE_TO_JSVAL(*self as f64)
}
}
#[fixed_stack_segment]
fn from_jsval(val: JSVal) -> Option<i64> {
unsafe {
Some(RUST_JSVAL_TO_DOUBLE(val) as i64)
}
}
}
impl JSValConvertible for u32 {
#[fixed_stack_segment]
fn to_jsval(&self) -> JSVal {

View file

@ -2,7 +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::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::utils::{DOMString, Reflectable, Reflector, reflect_dom_object};
use dom::bindings::utils::Fallible;
use dom::bindings::codegen::BlobBinding;
use dom::window::Window;
@ -29,6 +29,20 @@ impl Blob {
pub fn Constructor(window: @mut Window) -> Fallible<@mut Blob> {
Ok(Blob::new(window))
}
pub fn Size(&self) -> u64 {
0
}
pub fn Type(&self) -> DOMString {
~""
}
pub fn Slice(&self, _start: i64, _end: i64, _contentType: Option<DOMString>) -> @mut Blob {
Blob::new(self.window)
}
pub fn Close(&self) {}
}
impl Reflectable for Blob {