aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2017-05-26 13:25:05 -0400
committerJosh Matthews <josh@joshmatthews.net>2017-09-25 16:10:58 -0400
commitb169689f32db6d497b04f3a5b173cba4acd33e93 (patch)
treeec02846b1f99dfac6abc9898ebf873b927bdc598 /components/script
parentda65698c5c5934220b82493b3f7bb2ab05a2e512 (diff)
downloadservo-b169689f32db6d497b04f3a5b173cba4acd33e93.tar.gz
servo-b169689f32db6d497b04f3a5b173cba4acd33e93.zip
Store rootable dictionary members of dictionaries in RootedTraceableBox.
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py27
-rw-r--r--components/script/dom/bindings/conversions.rs18
-rw-r--r--components/script/dom/bindings/iterable.rs6
-rw-r--r--components/script/dom/testbinding.rs4
4 files changed, 29 insertions, 26 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 4d31da25efe..5b2b987c233 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -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):
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs
index 10accbcc62b..69751f2c263 100644
--- a/components/script/dom/bindings/conversions.rs
+++ b/components/script/dom/bindings/conversions.rs
@@ -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);
}
}
diff --git a/components/script/dom/bindings/iterable.rs b/components/script/dom/bindings/iterable.rs
index 39c681c7d8b..03fac1cb27f 100644
--- a/components/script/dom/bindings/iterable.rs
+++ b/components/script/dom/bindings/iterable.rs
@@ -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());
diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs
index 266497da83e..1803403f72f 100644
--- a/components/script/dom/testbinding.rs
+++ b/components/script/dom/testbinding.rs
@@ -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,