diff options
author | Ms2ger <ms2ger@gmail.com> | 2015-03-13 16:51:22 +0100 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2015-03-13 21:27:58 +0100 |
commit | bbbdb98897913b06a8a4819498e59dbb09ad9aa7 (patch) | |
tree | 8abf83c7d3aa20ef5c6ded5ceb1a5f4c633451b4 /components/script/dom/bindings/codegen/CodegenRust.py | |
parent | 4157a2b02bcff44ccb476c1b3b52e4f74e650bf4 (diff) | |
download | servo-bbbdb98897913b06a8a4819498e59dbb09ad9aa7.tar.gz servo-bbbdb98897913b06a8a4819498e59dbb09ad9aa7.zip |
Implement USVString.
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 86e2ee1fd34..583a0233c7f 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -717,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 @@ -1086,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(): @@ -4647,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', |