diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-03-14 12:04:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-14 12:04:23 -0400 |
commit | e597cd9e1adc23ae30587ff6bffc05119ac33fb9 (patch) | |
tree | 5d602d36a92a0183b0c2d2568d056e18d791ad98 /components/script/dom/webglrenderingcontext.rs | |
parent | 148beb4ea5f8f1680e694ac48045a632da58269c (diff) | |
parent | 712812d44191bfb916ceaeeada5dc15c2f0dc83d (diff) | |
download | servo-e597cd9e1adc23ae30587ff6bffc05119ac33fb9.tar.gz servo-e597cd9e1adc23ae30587ff6bffc05119ac33fb9.zip |
Auto merge of #20265 - Xanewok:fix-js-objects-in-unions, r=jdm
Fix JS object conversion in unions
<!-- Please describe your changes on the following line: -->
Requires safe `Heap::boxed` constructor from https://github.com/servo/rust-mozjs/pull/395 (more info on it is in the PR).
Since unions currently assume that their respective members root themselves and can be stored on heap, I modified the union member object conversion branch to convert to a `RootedTraceableBox<Heap<*mut JSObject>>` (which is the currently generated type for objects in said unions).
I did it only for Unions and not dictionaries, since some dictionaries had bare `*mut JSObject` members - is this a mistake and something that needs further fixing?
Does this need a test, e.g. passing a union with object to a function that returns said object, and comparing the results for equality?
r? @jdm
Generated code with this patch (for `StringOrObject`):
```rust
impl FromJSValConvertible for StringOrObject {
type Config = ();
unsafe fn from_jsval(cx: *mut JSContext,
value: HandleValue,
_option: ())
-> Result<ConversionResult<StringOrObject>, ()> {
if value.get().is_object() {
match StringOrObject::TryConvertToObject(cx, value) {
Err(_) => return Err(()),
Ok(Some(value)) => return Ok(ConversionResult::Success(StringOrObject::Object(value))),
Ok(None) => (),
}
}
// (...)
}
}
impl StringOrObject {
// (...)
unsafe fn TryConvertToObject(cx: *mut JSContext, value: HandleValue) -> Result<Option<RootedTraceableBox<Heap<*mut JSObject>>>, ()> {
Ok(Some(RootedTraceableBox::from_box(Heap::boxed(value.get().to_object()))))
}
}
```
---
<!-- 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
- [ ] These changes fix #17011 (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- 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/20265)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
0 files changed, 0 insertions, 0 deletions