mirror of
https://github.com/servo/servo.git
synced 2025-08-01 19:50:30 +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"
|
" Err(_) => { %s },\n"
|
||||||
"}" % exceptionCode)
|
"}" % 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():
|
if type.nullable():
|
||||||
declType = CGWrapper(declType, pre="Option<", post=">")
|
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():
|
if type.isEnum():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
|
|
@ -3391,6 +3391,11 @@ class IDLValue(IDLObject):
|
||||||
# extra normalization step.
|
# extra normalization step.
|
||||||
assert self.type.isDOMString()
|
assert self.type.isDOMString()
|
||||||
return self
|
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." %
|
raise WebIDLError("Cannot coerce type %s to type %s." %
|
||||||
(self.type, type), [location])
|
(self.type, type), [location])
|
||||||
|
|
||||||
|
@ -5759,6 +5764,14 @@ class Parser(Tokenizer):
|
||||||
booleanType = BuiltinTypes[IDLBuiltinType.Types.boolean]
|
booleanType = BuiltinTypes[IDLBuiltinType.Types.boolean]
|
||||||
p[0] = IDLValue(location, booleanType, p[1])
|
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):
|
def p_ConstValueInteger(self, p):
|
||||||
"""
|
"""
|
||||||
ConstValue : INTEGER
|
ConstValue : INTEGER
|
||||||
|
|
|
@ -312,6 +312,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
UnrestrictedDoubleValue: 0.0,
|
UnrestrictedDoubleValue: 0.0,
|
||||||
anyValue: NullValue(),
|
anyValue: NullValue(),
|
||||||
booleanValue: false,
|
booleanValue: false,
|
||||||
|
bytestringValue: ByteString::new(vec![]),
|
||||||
byteValue: 0,
|
byteValue: 0,
|
||||||
doubleValue: Finite::new(1.0).unwrap(),
|
doubleValue: Finite::new(1.0).unwrap(),
|
||||||
enumValue: TestEnum::Foo,
|
enumValue: TestEnum::Foo,
|
||||||
|
@ -319,6 +320,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
longLongValue: 54,
|
longLongValue: 54,
|
||||||
longValue: 12,
|
longValue: 12,
|
||||||
nullableBooleanValue: None,
|
nullableBooleanValue: None,
|
||||||
|
nullableBytestringValue: None,
|
||||||
nullableByteValue: None,
|
nullableByteValue: None,
|
||||||
nullableDoubleValue: None,
|
nullableDoubleValue: None,
|
||||||
nullableFloatValue: None,
|
nullableFloatValue: None,
|
||||||
|
@ -506,6 +508,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn PassOptionalUnsignedLongLongWithDefault(&self, _: u64) {}
|
fn PassOptionalUnsignedLongLongWithDefault(&self, _: u64) {}
|
||||||
fn PassOptionalStringWithDefault(&self, _: DOMString) {}
|
fn PassOptionalStringWithDefault(&self, _: DOMString) {}
|
||||||
fn PassOptionalUsvstringWithDefault(&self, _: USVString) {}
|
fn PassOptionalUsvstringWithDefault(&self, _: USVString) {}
|
||||||
|
fn PassOptionalBytestringWithDefault(&self, _: ByteString) {}
|
||||||
fn PassOptionalEnumWithDefault(&self, _: TestEnum) {}
|
fn PassOptionalEnumWithDefault(&self, _: TestEnum) {}
|
||||||
|
|
||||||
fn PassOptionalNullableBooleanWithDefault(&self, _: Option<bool>) {}
|
fn PassOptionalNullableBooleanWithDefault(&self, _: Option<bool>) {}
|
||||||
|
|
|
@ -53,6 +53,7 @@ dictionary TestDictionaryDefaults {
|
||||||
float floatValue = 7.0;
|
float floatValue = 7.0;
|
||||||
unrestricted double UnrestrictedDoubleValue = 7.0;
|
unrestricted double UnrestrictedDoubleValue = 7.0;
|
||||||
double doubleValue = 7.0;
|
double doubleValue = 7.0;
|
||||||
|
ByteString bytestringValue = "foo";
|
||||||
DOMString stringValue = "foo";
|
DOMString stringValue = "foo";
|
||||||
USVString usvstringValue = "foo";
|
USVString usvstringValue = "foo";
|
||||||
TestEnum enumValue = "bar";
|
TestEnum enumValue = "bar";
|
||||||
|
@ -71,6 +72,7 @@ dictionary TestDictionaryDefaults {
|
||||||
float? nullableFloatValue = 7.0;
|
float? nullableFloatValue = 7.0;
|
||||||
unrestricted double? nullableUnrestrictedDoubleValue = 7.0;
|
unrestricted double? nullableUnrestrictedDoubleValue = 7.0;
|
||||||
double? nullableDoubleValue = 7.0;
|
double? nullableDoubleValue = 7.0;
|
||||||
|
ByteString? nullableBytestringValue = "foo";
|
||||||
DOMString? nullableStringValue = "foo";
|
DOMString? nullableStringValue = "foo";
|
||||||
USVString? nullableUsvstringValue = "foo";
|
USVString? nullableUsvstringValue = "foo";
|
||||||
// TestEnum? nullableEnumValue = "bar";
|
// TestEnum? nullableEnumValue = "bar";
|
||||||
|
@ -344,6 +346,7 @@ interface TestBinding {
|
||||||
void passOptionalUnsignedLongWithDefault(optional unsigned long arg = 6);
|
void passOptionalUnsignedLongWithDefault(optional unsigned long arg = 6);
|
||||||
void passOptionalLongLongWithDefault(optional long long arg = -12);
|
void passOptionalLongLongWithDefault(optional long long arg = -12);
|
||||||
void passOptionalUnsignedLongLongWithDefault(optional unsigned long long arg = 17);
|
void passOptionalUnsignedLongLongWithDefault(optional unsigned long long arg = 17);
|
||||||
|
void passOptionalBytestringWithDefault(optional ByteString arg = "x");
|
||||||
void passOptionalStringWithDefault(optional DOMString arg = "x");
|
void passOptionalStringWithDefault(optional DOMString arg = "x");
|
||||||
void passOptionalUsvstringWithDefault(optional USVString arg = "x");
|
void passOptionalUsvstringWithDefault(optional USVString arg = "x");
|
||||||
void passOptionalEnumWithDefault(optional TestEnum arg = "foo");
|
void passOptionalEnumWithDefault(optional TestEnum arg = "foo");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue