diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 17 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/parser/WebIDL.py | 13 | ||||
-rw-r--r-- | components/script/dom/testbinding.rs | 3 | ||||
-rw-r--r-- | components/script/dom/webidls/TestBinding.webidl | 3 |
4 files changed, 33 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 diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index 372055483c7..9143c8b0188 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -312,6 +312,7 @@ impl TestBindingMethods for TestBinding { UnrestrictedDoubleValue: 0.0, anyValue: NullValue(), booleanValue: false, + bytestringValue: ByteString::new(vec![]), byteValue: 0, doubleValue: Finite::new(1.0).unwrap(), enumValue: TestEnum::Foo, @@ -319,6 +320,7 @@ impl TestBindingMethods for TestBinding { longLongValue: 54, longValue: 12, nullableBooleanValue: None, + nullableBytestringValue: None, nullableByteValue: None, nullableDoubleValue: None, nullableFloatValue: None, @@ -506,6 +508,7 @@ impl TestBindingMethods for TestBinding { fn PassOptionalUnsignedLongLongWithDefault(&self, _: u64) {} fn PassOptionalStringWithDefault(&self, _: DOMString) {} fn PassOptionalUsvstringWithDefault(&self, _: USVString) {} + fn PassOptionalBytestringWithDefault(&self, _: ByteString) {} fn PassOptionalEnumWithDefault(&self, _: TestEnum) {} fn PassOptionalNullableBooleanWithDefault(&self, _: Option<bool>) {} diff --git a/components/script/dom/webidls/TestBinding.webidl b/components/script/dom/webidls/TestBinding.webidl index 9945f983ad7..392aee5963b 100644 --- a/components/script/dom/webidls/TestBinding.webidl +++ b/components/script/dom/webidls/TestBinding.webidl @@ -53,6 +53,7 @@ dictionary TestDictionaryDefaults { float floatValue = 7.0; unrestricted double UnrestrictedDoubleValue = 7.0; double doubleValue = 7.0; + ByteString bytestringValue = "foo"; DOMString stringValue = "foo"; USVString usvstringValue = "foo"; TestEnum enumValue = "bar"; @@ -71,6 +72,7 @@ dictionary TestDictionaryDefaults { float? nullableFloatValue = 7.0; unrestricted double? nullableUnrestrictedDoubleValue = 7.0; double? nullableDoubleValue = 7.0; + ByteString? nullableBytestringValue = "foo"; DOMString? nullableStringValue = "foo"; USVString? nullableUsvstringValue = "foo"; // TestEnum? nullableEnumValue = "bar"; @@ -344,6 +346,7 @@ interface TestBinding { void passOptionalUnsignedLongWithDefault(optional unsigned long arg = 6); void passOptionalLongLongWithDefault(optional long long arg = -12); void passOptionalUnsignedLongLongWithDefault(optional unsigned long long arg = 17); + void passOptionalBytestringWithDefault(optional ByteString arg = "x"); void passOptionalStringWithDefault(optional DOMString arg = "x"); void passOptionalUsvstringWithDefault(optional USVString arg = "x"); void passOptionalEnumWithDefault(optional TestEnum arg = "foo"); |