Files
servo/components/script/dom
bors-servo e597cd9e1a 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 -->
2018-03-14 12:04:23 -04:00
..
2018-03-13 22:47:36 +01:00
2017-08-23 21:38:44 +02:00
2018-01-26 01:18:54 +08:00
2017-10-16 17:16:20 +02:00
2017-09-26 09:49:10 +02:00
2017-10-16 17:16:20 +02:00
2017-10-16 17:16:20 +02:00
2017-10-16 17:16:20 +02:00
2017-10-16 17:16:20 +02:00
2017-10-16 17:16:20 +02:00
2017-10-16 17:16:20 +02:00
2018-02-22 21:34:53 +05:30
2018-02-13 09:40:06 +01:00
2017-10-16 17:16:20 +02:00
2017-09-26 09:49:10 +02:00
2018-02-11 08:02:39 +01:00
2017-08-23 17:16:30 +02:00
2018-02-13 09:12:00 +01:00
2017-09-06 13:33:30 +02:00
2017-09-06 13:33:30 +02:00
2017-09-26 09:49:10 +02:00
2017-11-16 13:36:22 +08:00
2017-10-16 17:16:20 +02:00
2017-10-16 17:16:20 +02:00
2017-10-16 17:16:20 +02:00
2017-03-13 21:57:50 +08:00
2017-10-16 17:16:20 +02:00
2017-10-27 12:53:11 +02:00
2018-02-22 21:34:53 +05:30
2018-02-13 09:40:06 +01:00