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/CodegenRust.py | |
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/CodegenRust.py')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 17 |
1 files changed, 14 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 |