aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
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/dom/bindings/codegen/CodegenRust.py
parentda65698c5c5934220b82493b3f7bb2ab05a2e512 (diff)
downloadservo-b169689f32db6d497b04f3a5b173cba4acd33e93.tar.gz
servo-b169689f32db6d497b04f3a5b173cba4acd33e93.zip
Store rootable dictionary members of dictionaries in RootedTraceableBox.
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py27
1 files changed, 19 insertions, 8 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):