diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-08-11 04:36:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-11 04:36:23 -0500 |
commit | b7facf41cbc7ba727666e95fd0c390d432d862fa (patch) | |
tree | 0e74d47bb1fcdda50cb8f4c8a5f0eddea86f66ba /components/script/dom/bindings/codegen | |
parent | 9ffda4c7b33f14c291404655bd137b544969fff9 (diff) | |
parent | 7fd65affabd9ab49b254fefce968a9eafabf1fbf (diff) | |
download | servo-b7facf41cbc7ba727666e95fd0c390d432d862fa.tar.gz servo-b7facf41cbc7ba727666e95fd0c390d432d862fa.zip |
Auto merge of #12790 - malisas:malisa-bytestring-generator, r=Ms2ger
Update bindings generator to support default ByteString values in a dictionary
<!-- Please describe your changes on the following line: -->
Update bindings generator to support default ByteString values in a dictionary.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #12737 (github issue number if applicable).
<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12790)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/codegen')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 17 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/parser/WebIDL.py | 13 |
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 |