aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
authorecoal95 <ecoal95@gmail.com>2015-05-25 14:47:23 +0200
committerecoal95 <ecoal95@gmail.com>2015-06-01 15:29:38 +0200
commitb3ac3467494377569997126103005382793d8081 (patch)
treeeb0117a3dd980e6ff8b8657ecbab176faf229cb5 /components/script/dom/bindings/codegen/CodegenRust.py
parentb1a773a15bd2e022aa45c3672e51467e994badfe (diff)
downloadservo-b3ac3467494377569997126103005382793d8081.tar.gz
servo-b3ac3467494377569997126103005382793d8081.zip
Add WebGLContextAttributes support
This commit also: * Allows to return non-rootable dictionaries from Codegen. * Merges the two context types in an enum type.
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index d44db4078b4..9f965a9c7e8 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1165,6 +1165,15 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
return CGGeneric("*mut JSObject")
if returnType.isSequence():
raise TypeError("We don't support sequence return values")
+ if returnType.isDictionary():
+ nullable = returnType.nullable()
+ dictName = returnType.inner.name if nullable else returnType.name
+ result = CGGeneric(dictName)
+ if typeNeedsRooting(returnType, descriptorProvider):
+ raise TypeError("We don't support rootable dictionaries return values")
+ if nullable:
+ result = CGWrapper(result, pre="Option<", post=">")
+ return result
raise TypeError("Don't know how to declare return value for %s" %
returnType)
@@ -4517,7 +4526,14 @@ class CGDictionary(CGThing):
conversion = self.getMemberConversion(memberInfo)
return CGGeneric("%s: %s,\n" % (name, conversion.define()))
+ def memberInsert(memberInfo):
+ member, _ = memberInfo
+ name = self.makeMemberName(member.identifier.name)
+ insertion = ("set_dictionary_property(cx, obj, \"%s\", &mut self.%s.to_jsval(cx)).unwrap();" % (name, name))
+ return CGGeneric("%s\n" % insertion)
+
memberInits = CGList([memberInit(m) for m in self.memberInfo])
+ memberInserts = CGList([memberInsert(m) for m in self.memberInfo])
return string.Template(
"impl ${selfName} {\n"
@@ -4538,10 +4554,19 @@ class CGDictionary(CGThing):
"${initMembers}"
" })\n"
" }\n"
- "}").substitute({
+ "}\n"
+ "\n"
+ "impl ToJSValConvertible for ${selfName} {\n"
+ " fn to_jsval(&self, cx: *mut JSContext) -> JSVal {\n"
+ " let obj = unsafe { JS_NewObject(cx, 0 as *const JSClass, 0 as *const JSObject, 0 as *const JSObject) };\n"
+ "${insertMembers}"
+ " ObjectOrNullValue(obj)\n"
+ " }\n"
+ "}\n").substitute({
"selfName": self.makeClassName(d),
"initParent": CGIndenter(CGGeneric(initParent), indentLevel=12).define(),
"initMembers": CGIndenter(memberInits, indentLevel=12).define(),
+ "insertMembers": CGIndenter(memberInserts, indentLevel=8).define(),
})
@staticmethod
@@ -4590,6 +4615,7 @@ class CGDictionary(CGThing):
return CGGeneric(conversion)
+
@staticmethod
def makeIdName(name):
return name + "_id"
@@ -4750,6 +4776,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::utils::{Reflectable}',
'dom::bindings::utils::throwing_constructor',
'dom::bindings::utils::get_dictionary_property',
+ 'dom::bindings::utils::set_dictionary_property',
'dom::bindings::utils::{NativeProperties, NativePropertyHooks}',
'dom::bindings::utils::ConstantVal::{IntVal, UintVal}',
'dom::bindings::utils::NonNullJSNative',