aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 2e0dc2415dd..8a288694431 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -866,11 +866,22 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
" Err(_) => { %s },\n"
"}" % exceptionCode)
- declType = CGGeneric("ByteString")
+ 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.bytestring)
+ default = 'ByteString::new(b"%s".to_vec())' % defaultValue.value
+ if type.nullable():
+ default = "Some(%s)" % default
+
+ declType = "ByteString"
if type.nullable():
- declType = CGWrapper(declType, pre="Option<", post=">")
+ declType = "Option<%s>" % declType
- return handleOptional(conversionCode, declType, handleDefaultNull("None"))
+ return handleOptional(conversionCode, CGGeneric(declType), default)
if type.isEnum():
assert not isEnforceRange and not isClamp