mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
bindings generator: support default ByteString values in dictionary
This commit is contained in:
parent
8cd4b772e9
commit
7fd65affab
4 changed files with 34 additions and 4 deletions
|
@ -866,11 +866,22 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
" Err(_) => { %s },\n"
|
||||
"}" % exceptionCode)
|
||||
|
||||
declType = CGGeneric("ByteString")
|
||||
if type.nullable():
|
||||
declType = CGWrapper(declType, pre="Option<", post=">")
|
||||
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
|
||||
|
||||
return handleOptional(conversionCode, declType, handleDefaultNull("None"))
|
||||
declType = "ByteString"
|
||||
if type.nullable():
|
||||
declType = "Option<%s>" % declType
|
||||
|
||||
return handleOptional(conversionCode, CGGeneric(declType), default)
|
||||
|
||||
if type.isEnum():
|
||||
assert not isEnforceRange and not isClamp
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue