aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen
diff options
context:
space:
mode:
authorMalisa Smith <malisa.tsmith@gmail.com>2016-08-09 17:51:17 -0700
committerMalisa Smith <malisa.tsmith@gmail.com>2016-08-10 10:50:36 -0700
commit7fd65affabd9ab49b254fefce968a9eafabf1fbf (patch)
tree36b40bf2690eec82b1ac9ce653e29438ef58a89d /components/script/dom/bindings/codegen
parent8cd4b772e90224b344010cc6c38cebe47ce10c48 (diff)
downloadservo-7fd65affabd9ab49b254fefce968a9eafabf1fbf.tar.gz
servo-7fd65affabd9ab49b254fefce968a9eafabf1fbf.zip
bindings generator: support default ByteString values in dictionary
Diffstat (limited to 'components/script/dom/bindings/codegen')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py17
-rw-r--r--components/script/dom/bindings/codegen/parser/WebIDL.py13
2 files changed, 27 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
diff --git a/components/script/dom/bindings/codegen/parser/WebIDL.py b/components/script/dom/bindings/codegen/parser/WebIDL.py
index da32340dda6..54d510781a1 100644
--- a/components/script/dom/bindings/codegen/parser/WebIDL.py
+++ b/components/script/dom/bindings/codegen/parser/WebIDL.py
@@ -3391,6 +3391,11 @@ class IDLValue(IDLObject):
# extra normalization step.
assert self.type.isDOMString()
return self
+ elif self.type.isString() and type.isByteString():
+ # Allow ByteStrings to use default value just like
+ # DOMString. No coercion is required here.
+ assert self.type.isDOMString()
+ return self
raise WebIDLError("Cannot coerce type %s to type %s." %
(self.type, type), [location])
@@ -5759,6 +5764,14 @@ class Parser(Tokenizer):
booleanType = BuiltinTypes[IDLBuiltinType.Types.boolean]
p[0] = IDLValue(location, booleanType, p[1])
+ def p_ConstValueByteString(self, p):
+ """
+ ConstValue : BYTESTRING
+ """
+ location = self.getLocation(p, 1)
+ bytestringType = BuiltinTypes[IDLBuiltinType.Types.bytestring]
+ p[0] = IDLValue(location, bytestringType, p[1])
+
def p_ConstValueInteger(self, p):
"""
ConstValue : INTEGER