aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
authorKagami Sascha Rosylight <saschanaz@outlook.com>2019-07-06 16:20:50 +0900
committerKagami Sascha Rosylight <saschanaz@outlook.com>2019-07-12 12:16:09 +0900
commit01151274f1487e630852680ba38ab5a651db44ec (patch)
tree5d83ec4a7d401706c2668ee5fac90e99ef734b1e /components/script/dom/bindings/codegen/CodegenRust.py
parent56f31c85ef9cc79140f375641302310c6680ded4 (diff)
downloadservo-01151274f1487e630852680ba38ab5a651db44ec.tar.gz
servo-01151274f1487e630852680ba38ab5a651db44ec.zip
Require default dictionary value for optional dicts
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 114b403d077..98df7a8b51f 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -17,6 +17,7 @@ import functools
from WebIDL import (
BuiltinTypes,
IDLBuiltinType,
+ IDLDefaultDictionaryValue,
IDLEmptySequenceValue,
IDLInterfaceMember,
IDLNullableType,
@@ -678,13 +679,16 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
return None
if isinstance(defaultValue, IDLNullValue):
- assert type.nullable() or type.isDictionary()
+ assert type.nullable()
+ return nullValue
+ elif isinstance(defaultValue, IDLDefaultDictionaryValue):
+ assert type.isDictionary()
return nullValue
elif isinstance(defaultValue, IDLEmptySequenceValue):
assert type.isSequence()
return "Vec::new()"
- raise TypeError("Can't handle non-null or non-empty sequence default value here")
+ raise TypeError("Can't handle non-null, non-empty sequence or non-empty dictionary default value here")
# A helper function for wrapping up the template body for
# possibly-nullable objecty stuff
@@ -747,17 +751,19 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
for memberType in type.unroll().flatMemberTypes
if memberType.isDictionary()
]
- if defaultValue and not isinstance(defaultValue, IDLNullValue):
+ if (defaultValue and
+ not isinstance(defaultValue, IDLNullValue) and
+ not isinstance(defaultValue, IDLDefaultDictionaryValue)):
tag = defaultValue.type.tag()
if tag is IDLType.Tags.bool:
default = "%s::Boolean(%s)" % (
union_native_type(type),
"true" if defaultValue.value else "false")
else:
- raise("We don't currently support default values that aren't null or boolean")
+ raise("We don't currently support default values that aren't null, boolean or default dictionary")
elif dictionaries:
if defaultValue:
- assert isinstance(defaultValue, IDLNullValue)
+ assert isinstance(defaultValue, IDLDefaultDictionaryValue)
dictionary, = dictionaries
default = "%s::%s(%s::%s::empty())" % (
union_native_type(type),