Repository navigation
Implement Deref<Target=T> for JS<T> where T: Reflectable - #8060
Conversation
We can only borrow JS<T> from rooted things, so it's safe to deref it. The only types that provide mutable JS<T> things are MutHeap<JS<T>> and MutNullableHeap<JS<T>>, which don't actually expose that they contain JS<T> values.
That isn't completely true. For example, servo/components/script/script_task.rs Line 409 in e31ad01 mouse_over_targets: DOMRefCell<Vec<JS<Node>>>,).
I'd be much more comfortable with this if we unified |
|
The case you point out isn't unsafe in terms of Rust, in the sense that only a panic will happen if we try to drop it while borrowed, AFAIK. |
|
The way Deref makes the problem worse is that if you write something like |
|
Unwrapping the result should make @Manishearth's lint complain, because it puts |
|
Yes, the lint is probably good enough that it isn't a big deal, just a minor thing to try and watch for when reviewing DOM code. |
|
We should perhaps disallow cloning |
|
@Manishearth I thought we had removed that with |
|
Isn't |
|
That's what I'm saying, I thought we had removed |
|
We can't remove |
There was a problem hiding this comment.
let compositor = self.window().compositor() and remove the above line and FIXME?
|
@bors-servo r+ Reviewed 23 of 23 files at r1. Comments from the review on Reviewable.io |
|
📌 Commit 6dc42dd has been approved by |
Implement Deref<Target=T> for JS<T> where T: Reflectable We can only borrow `JS<T>` from rooted things, so it's safe to deref it. The only types that provide mutable `JS<T>` things are `MutHeap<JS<T>>` and `MutNullableHeap<JS<T>>`, which don't actually expose that they contain `JS<T>` values. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8060) <!-- Reviewable:end -->
|
⛄ The build was interrupted to prioritize another pull request. |
|
⚡ Previous build results for gonk, linux-dev, mac-dev-ref-unit are reusable. Rebuilding only android, linux-rel, mac-rel-css, mac-rel-wpt... |
|
💔 Test failed - mac-rel-wpt |
|
@bors-servo retry #7731 |
Implement Deref<Target=T> for JS<T> where T: Reflectable We can only borrow `JS<T>` from rooted things, so it's safe to deref it. The only types that provide mutable `JS<T>` things are `MutHeap<JS<T>>` and `MutNullableHeap<JS<T>>`, which don't actually expose that they contain `JS<T>` values. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8060) <!-- Reviewable:end -->
|
☀️ Test successful - android, gonk, linux-dev, linux-rel, mac-dev-ref-unit, mac-rel-css, mac-rel-wpt |
We can only borrow
JS<T>from rooted things, so it's safe to deref it.The only types that provide mutable
JS<T>things areMutHeap<JS<T>>andMutNullableHeap<JS<T>>, which don't actually expose that they containJS<T>values.