mirror of
https://github.com/servo/servo.git
synced 2025-06-23 16:44:33 +01:00
Add some more Blob methods/types
This commit is contained in:
parent
e98ddef9bb
commit
586dd6aed6
4 changed files with 63 additions and 17 deletions
|
@ -4,12 +4,25 @@
|
||||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*
|
*
|
||||||
* The origin of this IDL file is
|
* 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
|
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||||
* liability, trademark and document use rules apply.
|
* liability, trademark and document use rules apply.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
[Constructor]
|
[Constructor/*,
|
||||||
|
Constructor(sequence<(ArrayBuffer or ArrayBufferView or Blob or DOMString)> blobParts, optional BlobPropertyBag option)*/]
|
||||||
interface Blob {
|
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 = "";
|
||||||
};
|
};
|
||||||
|
|
|
@ -1097,14 +1097,9 @@ for (uint32_t i = 0; i < length; ++i) {
|
||||||
if isMember:
|
if isMember:
|
||||||
# We have to make a copy, because our jsval may well not
|
# We have to make a copy, because our jsval may well not
|
||||||
# live as long as our string needs to.
|
# live as long as our string needs to.
|
||||||
declType = CGGeneric("nsString")
|
declType = CGGeneric("DOMString")
|
||||||
return (
|
return ("%s\n" % getConversionCode("${declName}"),
|
||||||
"{\n"
|
declType, None, isOptional, None)
|
||||||
" FakeDependentString str;\n"
|
|
||||||
"%s\n"
|
|
||||||
" ${declName} = str;\n"
|
|
||||||
"}\n" % CGIndenter(CGGeneric(getConversionCode("str"))).define(),
|
|
||||||
declType, None, isOptional, None)
|
|
||||||
|
|
||||||
declType = "DOMString"
|
declType = "DOMString"
|
||||||
initialValue = None
|
initialValue = None
|
||||||
|
@ -4833,7 +4828,7 @@ class CGDictionary(CGThing):
|
||||||
else:
|
else:
|
||||||
inheritance = ""
|
inheritance = ""
|
||||||
memberDecls = [" %s: %s," %
|
memberDecls = [" %s: %s," %
|
||||||
(m[0].identifier.name, self.getMemberType(m))
|
(self.makeMemberName(m[0].identifier.name), self.getMemberType(m))
|
||||||
for m in self.memberInfo]
|
for m in self.memberInfo]
|
||||||
|
|
||||||
return (string.Template(
|
return (string.Template(
|
||||||
|
@ -4876,8 +4871,8 @@ class CGDictionary(CGThing):
|
||||||
return "false"
|
return "false"
|
||||||
elif ty in ["i32", "u32", "i16", "u16"]:
|
elif ty in ["i32", "u32", "i16", "u16"]:
|
||||||
return "0"
|
return "0"
|
||||||
elif ty is "nsString":
|
elif ty == "DOMString":
|
||||||
return "\"\""
|
return '~""'
|
||||||
elif ty.startswith("Option"):
|
elif ty.startswith("Option"):
|
||||||
return "None"
|
return "None"
|
||||||
else:
|
else:
|
||||||
|
@ -4895,7 +4890,7 @@ class CGDictionary(CGThing):
|
||||||
" ${selfName} {\n" +
|
" ${selfName} {\n" +
|
||||||
((" parent: %s::%s::new(),\n" % (self.makeModuleName(d.parent),
|
((" parent: %s::%s::new(),\n" % (self.makeModuleName(d.parent),
|
||||||
self.makeClassName(d.parent))) if d.parent else "") +
|
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"
|
" }\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -4965,7 +4960,7 @@ class CGDictionary(CGThing):
|
||||||
holderType, dealWithOptional, initialValue)) = memberInfo
|
holderType, dealWithOptional, initialValue)) = memberInfo
|
||||||
replacements = { "val": "temp",
|
replacements = { "val": "temp",
|
||||||
"valPtr": "&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
|
# We need a holder name for external interfaces, but
|
||||||
# it's scoped down to the conversion so we can just use
|
# it's scoped down to the conversion so we can just use
|
||||||
# anything we want.
|
# anything we want.
|
||||||
|
@ -5021,7 +5016,7 @@ class CGDictionary(CGThing):
|
||||||
"}")
|
"}")
|
||||||
conversionReplacements["convert"] = CGIndenter(
|
conversionReplacements["convert"] = CGIndenter(
|
||||||
CGGeneric(conversionReplacements["convert"])).define()
|
CGGeneric(conversionReplacements["convert"])).define()
|
||||||
|
|
||||||
return CGGeneric(
|
return CGGeneric(
|
||||||
string.Template(conversion).substitute(conversionReplacements)
|
string.Template(conversion).substitute(conversionReplacements)
|
||||||
)
|
)
|
||||||
|
@ -5030,6 +5025,13 @@ class CGDictionary(CGThing):
|
||||||
def makeIdName(name):
|
def makeIdName(name):
|
||||||
return name + "_id"
|
return name + "_id"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def makeMemberName(name):
|
||||||
|
# Can't use Rust keywords as member names.
|
||||||
|
if name == "type":
|
||||||
|
return name + "_"
|
||||||
|
return name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getDictionaryDependencies(dictionary):
|
def getDictionaryDependencies(dictionary):
|
||||||
deps = set();
|
deps = set();
|
||||||
|
|
|
@ -11,6 +11,23 @@ pub trait JSValConvertible {
|
||||||
fn from_jsval(val: JSVal) -> Option<Self>;
|
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 {
|
impl JSValConvertible for u32 {
|
||||||
#[fixed_stack_segment]
|
#[fixed_stack_segment]
|
||||||
fn to_jsval(&self) -> JSVal {
|
fn to_jsval(&self) -> JSVal {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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::utils::Fallible;
|
||||||
use dom::bindings::codegen::BlobBinding;
|
use dom::bindings::codegen::BlobBinding;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
|
@ -29,6 +29,20 @@ impl Blob {
|
||||||
pub fn Constructor(window: @mut Window) -> Fallible<@mut Blob> {
|
pub fn Constructor(window: @mut Window) -> Fallible<@mut Blob> {
|
||||||
Ok(Blob::new(window))
|
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 {
|
impl Reflectable for Blob {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue