aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-08-29 00:55:29 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-08-30 19:07:19 +0200
commit7dfb336be8dae1e2be9b898c374b6715e2a00ac7 (patch)
tree775fbf5f78d812db39ddfab79c56731262d5aded /components/script/dom/bindings/codegen
parent6e1523f4ae61c16578a462c2e5335cbc95a6ef04 (diff)
downloadservo-7dfb336be8dae1e2be9b898c374b6715e2a00ac7.tar.gz
servo-7dfb336be8dae1e2be9b898c374b6715e2a00ac7.zip
Use Option<T> to return from getters
This removes the cumbersome &mut bool argument and offers overall a more readable code.
Diffstat (limited to 'components/script/dom/bindings/codegen')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 8a169fe2c31..cf918feb8e3 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -18,6 +18,7 @@ from WebIDL import (
BuiltinTypes,
IDLBuiltinType,
IDLNullValue,
+ IDLNullableType,
IDLType,
IDLInterfaceMember,
IDLUndefinedValue,
@@ -4555,6 +4556,8 @@ class CGProxySpecialOperation(CGPerSignatureCall):
signature = operation.signatures()[0]
(returnType, arguments) = signature
+ if operation.isGetter() and not returnType.nullable():
+ returnType = IDLNullableType(returnType.location, returnType)
# We pass len(arguments) as the final argument so that the
# CGPerSignatureCall won't do any argument conversion of its own.
@@ -4577,8 +4580,6 @@ class CGProxySpecialOperation(CGPerSignatureCall):
self.cgRoot.prepend(instantiateJSToNativeConversionTemplate(
template, templateValues, declType, argument.identifier.name))
self.cgRoot.prepend(CGGeneric("rooted!(in(cx) let value = desc.value);"))
- elif operation.isGetter():
- self.cgRoot.prepend(CGGeneric("let mut found = false;"))
def getArguments(self):
def process(arg):
@@ -4587,10 +4588,6 @@ class CGProxySpecialOperation(CGPerSignatureCall):
argVal += ".r()"
return argVal
args = [(a, process(a)) for a in self.arguments]
- if self.idlNode.isGetter():
- args.append((FakeArgument(BuiltinTypes[IDLBuiltinType.Types.boolean],
- self.idlNode),
- "&mut found"))
return args
def wrap_return_value(self):
@@ -4598,7 +4595,7 @@ class CGProxySpecialOperation(CGPerSignatureCall):
return ""
wrap = CGGeneric(wrapForType(**self.templateValues))
- wrap = CGIfWrapper("found", wrap)
+ wrap = CGIfWrapper("let Some(result) = result", wrap)
return "\n" + wrap.define()
@@ -4974,7 +4971,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
" let this = UnwrapProxy(proxy);\n" +
" let this = &*this;\n" +
CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" +
- " *bp = found;\n" +
+ " *bp = result.is_some();\n" +
" return true;\n" +
"}\n\n")
else:
@@ -4990,7 +4987,7 @@ if RUST_JSID_IS_STRING(id) {
}
if !has_on_proto {
%s
- *bp = found;
+ *bp = result.is_some();
return true;
}
}
@@ -5274,7 +5271,9 @@ class CGInterfaceTrait(CGThing):
infallible = 'infallible' in descriptor.getExtendedAttributes(operation)
if operation.isGetter():
- arguments = method_arguments(descriptor, rettype, arguments, trailing=("found", "&mut bool"))
+ if not rettype.nullable():
+ rettype = IDLNullableType(rettype.location, rettype)
+ arguments = method_arguments(descriptor, rettype, arguments)
# If this interface 'supports named properties', then we
# should be able to access 'supported property names'