mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Store rootable dictionary members of dictionaries in RootedTraceableBox.
This commit is contained in:
parent
da65698c5c
commit
b169689f32
4 changed files with 29 additions and 26 deletions
|
@ -1096,9 +1096,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
declType = CGGeneric(typeName)
|
||||
empty = "%s::empty(cx)" % typeName
|
||||
|
||||
if isMember != "Dictionary" and type_needs_tracing(type):
|
||||
if type_needs_tracing(type):
|
||||
declType = CGTemplatedType("RootedTraceableBox", declType)
|
||||
empty = "RootedTraceableBox::new(%s)" % empty
|
||||
|
||||
template = ("match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
|
||||
" Ok(ConversionResult::Success(dictionary)) => dictionary,\n"
|
||||
|
@ -6094,16 +6093,24 @@ class CGDictionary(CGThing):
|
|||
memberInits = CGList([memberInit(m) for m in self.memberInfo])
|
||||
memberInserts = CGList([memberInsert(m) for m in self.memberInfo])
|
||||
|
||||
actualType = self.makeClassName(d)
|
||||
preInitial = ""
|
||||
postInitial = ""
|
||||
if self.membersNeedTracing():
|
||||
actualType = "RootedTraceableBox<%s>" % actualType
|
||||
preInitial = "RootedTraceableBox::new("
|
||||
postInitial = ")"
|
||||
|
||||
return string.Template(
|
||||
"impl ${selfName} {\n"
|
||||
" pub unsafe fn empty(cx: *mut JSContext) -> ${selfName} {\n"
|
||||
" pub unsafe fn empty(cx: *mut JSContext) -> ${actualType} {\n"
|
||||
" match ${selfName}::new(cx, HandleValue::null()) {\n"
|
||||
" Ok(ConversionResult::Success(v)) => v,\n"
|
||||
" _ => unreachable!(),\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" pub unsafe fn new(cx: *mut JSContext, val: HandleValue) \n"
|
||||
" -> Result<ConversionResult<${selfName}>, ()> {\n"
|
||||
" -> Result<ConversionResult<${actualType}>, ()> {\n"
|
||||
" let object = if val.get().is_null_or_undefined() {\n"
|
||||
" ptr::null_mut()\n"
|
||||
" } else if val.get().is_object() {\n"
|
||||
|
@ -6113,17 +6120,18 @@ class CGDictionary(CGThing):
|
|||
" return Err(());\n"
|
||||
" };\n"
|
||||
" rooted!(in(cx) let object = object);\n"
|
||||
" Ok(ConversionResult::Success(${selfName} {\n"
|
||||
" let dictionary = ${preInitial}${selfName} {\n"
|
||||
"${initParent}"
|
||||
"${initMembers}"
|
||||
" }))\n"
|
||||
" }${postInitial};\n"
|
||||
" Ok(ConversionResult::Success(dictionary))\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"impl FromJSValConvertible for ${selfName} {\n"
|
||||
"impl FromJSValConvertible for ${actualType} {\n"
|
||||
" type Config = ();\n"
|
||||
" unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _option: ())\n"
|
||||
" -> Result<ConversionResult<${selfName}>, ()> {\n"
|
||||
" -> Result<ConversionResult<${actualType}>, ()> {\n"
|
||||
" ${selfName}::new(cx, value)\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
|
@ -6136,9 +6144,12 @@ class CGDictionary(CGThing):
|
|||
" }\n"
|
||||
"}\n").substitute({
|
||||
"selfName": self.makeClassName(d),
|
||||
"actualType": actualType,
|
||||
"initParent": CGIndenter(CGGeneric(initParent), indentLevel=12).define(),
|
||||
"initMembers": CGIndenter(memberInits, indentLevel=12).define(),
|
||||
"insertMembers": CGIndenter(memberInserts, indentLevel=8).define(),
|
||||
"preInitial": CGGeneric(preInitial).define(),
|
||||
"postInitial": CGGeneric(postInitial).define(),
|
||||
})
|
||||
|
||||
def membersNeedTracing(self):
|
||||
|
|
|
@ -116,19 +116,11 @@ impl <T: DomObject + IDLInterface> FromJSValConvertible for Root<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl <T: FromJSValConvertible + JSTraceable> FromJSValConvertible for RootedTraceableBox<T> {
|
||||
type Config = T::Config;
|
||||
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
value: HandleValue,
|
||||
config: Self::Config)
|
||||
-> Result<ConversionResult<Self>, ()> {
|
||||
T::from_jsval(cx, value, config).map(|result| {
|
||||
match result {
|
||||
ConversionResult::Success(v) => ConversionResult::Success(RootedTraceableBox::new(v)),
|
||||
ConversionResult::Failure(e) => ConversionResult::Failure(e),
|
||||
}
|
||||
})
|
||||
impl<T: ToJSValConvertible + JSTraceable> ToJSValConvertible for RootedTraceableBox<T> {
|
||||
#[inline]
|
||||
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||
let value = &**self;
|
||||
value.to_jsval(cx, rval);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyOrValu
|
|||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::js::{JS, Root};
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::bindings::trace::{JSTraceable, RootedTraceableBox};
|
||||
use dom::bindings::trace::JSTraceable;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom_struct::dom_struct;
|
||||
use js::conversions::ToJSValConvertible;
|
||||
|
@ -115,7 +115,7 @@ fn dict_return(cx: *mut JSContext,
|
|||
result: MutableHandleObject,
|
||||
done: bool,
|
||||
value: HandleValue) -> Fallible<()> {
|
||||
let mut dict = RootedTraceableBox::new(unsafe { IterableKeyOrValueResult::empty(cx) });
|
||||
let mut dict = unsafe { IterableKeyOrValueResult::empty(cx) };
|
||||
dict.done = done;
|
||||
dict.value.set(value.get());
|
||||
rooted!(in(cx) let mut dict_value = UndefinedValue());
|
||||
|
@ -130,7 +130,7 @@ fn key_and_value_return(cx: *mut JSContext,
|
|||
result: MutableHandleObject,
|
||||
key: HandleValue,
|
||||
value: HandleValue) -> Fallible<()> {
|
||||
let mut dict = RootedTraceableBox::new(unsafe { IterableKeyAndValueResult::empty(cx) });
|
||||
let mut dict = unsafe { IterableKeyAndValueResult::empty(cx) };
|
||||
dict.done = false;
|
||||
dict.value = Some(vec![Heap::new(key.get()), Heap::new(value.get())]);
|
||||
rooted!(in(cx) let mut dict_value = UndefinedValue());
|
||||
|
|
|
@ -343,7 +343,7 @@ impl TestBindingMethods for TestBinding {
|
|||
anyValue: Heap::new(NullValue()),
|
||||
booleanValue: None,
|
||||
byteValue: None,
|
||||
dict: TestDictionaryDefaults {
|
||||
dict: RootedTraceableBox::new(TestDictionaryDefaults {
|
||||
UnrestrictedDoubleValue: 0.0,
|
||||
anyValue: Heap::new(NullValue()),
|
||||
booleanValue: false,
|
||||
|
@ -379,7 +379,7 @@ impl TestBindingMethods for TestBinding {
|
|||
unsignedLongValue: 0,
|
||||
unsignedShortValue: 0,
|
||||
usvstringValue: USVString("".to_owned()),
|
||||
},
|
||||
}),
|
||||
doubleValue: None,
|
||||
enumValue: None,
|
||||
floatValue: None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue