diff options
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index fa6c0475000..583a0233c7f 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -419,7 +419,8 @@ def typeIsSequenceOrHasSequenceMember(type): return False def typeNeedsRooting(type, descriptorProvider): - return type.isGeckoInterface() and descriptorProvider.getDescriptor(type.name).needsRooting + return (type.isGeckoInterface() and + descriptorProvider.getDescriptor(type.unroll().inner.identifier.name).needsRooting) def union_native_type(t): @@ -716,6 +717,32 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, return handleOptional(conversionCode, CGGeneric(declType), default) + if type.isUSVString(): + assert not isEnforceRange and not isClamp + + conversionCode = ( + "match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n" + " Ok(strval) => strval,\n" + " Err(_) => { %s },\n" + "}" % exceptionCode) + + if defaultValue is None: + default = None + elif isinstance(defaultValue, IDLNullValue): + assert type.nullable() + default = "None" + else: + assert defaultValue.type.tag() in (IDLType.Tags.domstring, IDLType.Tags.usvstring) + default = 'USVString("%s".to_owned())' % defaultValue.value + if type.nullable(): + default = "Some(%s)" % default + + declType = "USVString" + if type.nullable(): + declType = "Option<%s>" % declType + + return handleOptional(conversionCode, CGGeneric(declType), default) + if type.isByteString(): assert not isEnforceRange and not isClamp @@ -1085,6 +1112,11 @@ def getRetvalDeclarationForType(returnType, descriptorProvider): if returnType.nullable(): result = CGWrapper(result, pre="Option<", post=">") return result + if returnType.isUSVString(): + result = CGGeneric("USVString") + if returnType.nullable(): + result = CGWrapper(result, pre="Option<", post=">") + return result if returnType.isByteString(): result = CGGeneric("ByteString") if returnType.nullable(): @@ -4646,6 +4678,7 @@ class CGBindingRoot(CGThing): 'dom::bindings::proxyhandler::{fill_property_descriptor, get_expando_object}', 'dom::bindings::proxyhandler::{get_property_descriptor}', 'dom::bindings::str::ByteString', + 'dom::bindings::str::USVString', 'libc', 'util::str::DOMString', 'std::borrow::ToOwned', |