mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Use Option<T> to return from getters
This removes the cumbersome &mut bool argument and offers overall a more readable code.
This commit is contained in:
parent
6e1523f4ae
commit
7dfb336be8
22 changed files with 72 additions and 109 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue