Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Deref<Target=T> for JS<T> where T: Reflectable #8060

Merged
merged 21 commits into from Oct 19, 2015

Conversation

@nox
Copy link
Member

nox commented Oct 17, 2015

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.

Review on Reviewable

nox added 3 commits Oct 16, 2015
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.
@highfive
Copy link

highfive commented Oct 17, 2015

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
@eefriedman
Copy link
Contributor

eefriedman commented Oct 18, 2015

The only types that provide mutable JS things are MutHeap<JS<T>> and
MutNullableHeap<JS<T>>

That isn't completely true. For example,

mouse_over_targets: DOMRefCell<Vec<JS<Node>>>,
(mouse_over_targets: DOMRefCell<Vec<JS<Node>>>,).

I'd be much more comfortable with this if we unified JS<T> and Root<T> along the lines of http://manishearth.github.io/blog/2015/09/01/designing-a-gc-in-rust/ .

@nox
Copy link
Member Author

nox commented Oct 18, 2015

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.

@eefriedman
Copy link
Contributor

eefriedman commented Oct 18, 2015

The way Deref makes the problem worse is that if you write something like mouse_over_targets.borrow_mut().pop().unwrap(), you can access the contents without realizing you forgot to root it. Might not be worth worrying about?

@nox
Copy link
Member Author

nox commented Oct 18, 2015

Unwrapping the result should make @Manishearth's lint complain, because it puts JS<T> on the stack.

@eefriedman
Copy link
Contributor

eefriedman commented Oct 18, 2015

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.

@Manishearth
Copy link
Member

Manishearth commented Oct 18, 2015

We should perhaps disallow cloning JS<T>?

@nox
Copy link
Member Author

nox commented Oct 18, 2015

@Manishearth I thought we had removed that with Copy, will look into it.

@Manishearth
Copy link
Member

Manishearth commented Oct 18, 2015

Isn't Copy worse?

@nox
Copy link
Member Author

nox commented Oct 18, 2015

That's what I'm saying, I thought we had removed Clone at the same time we removed Copy.

@nox
Copy link
Member Author

nox commented Oct 18, 2015

We can't remove Clone, Sink heavily rely on it. But I don't think it's a problem, for the same reason as @eefriedman's example isn't.

@@ -549,7 +549,6 @@ impl Document {
pub fn send_title_to_compositor(&self) {
let window = self.window();
// FIXME(https://github.com/rust-lang/rust/issues/23338)
let window = window.r();

This comment has been minimized.

@dzbarsky

dzbarsky Oct 18, 2015

Member

let compositor = self.window().compositor() and remove the above line and FIXME?

This comment has been minimized.

@nox

nox Oct 19, 2015

Author Member

Good catch.

@nox nox force-pushed the nox:deref-js branch from 19f9f4b to 6dc42dd Oct 19, 2015
@Ms2ger
Copy link
Contributor

Ms2ger commented Oct 19, 2015

@bors-servo r+
-S-awaiting-review +S-awaiting-merge


Reviewed 23 of 23 files at r1.
Review status: all files reviewed at latest revision, all discussions resolved, some commit checks pending.


Comments from the review on Reviewable.io

@bors-servo
Copy link
Contributor

bors-servo commented Oct 19, 2015

📌 Commit 6dc42dd has been approved by Ms2ger

@bors-servo
Copy link
Contributor

bors-servo commented Oct 19, 2015

Testing commit 6dc42dd with merge 8ff3897...

bors-servo pushed a commit that referenced this pull request Oct 19, 2015
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 -->
@bors-servo
Copy link
Contributor

bors-servo commented Oct 19, 2015

The build was interrupted to prioritize another pull request.

@bors-servo
Copy link
Contributor

bors-servo commented Oct 19, 2015

Previous build results for gonk, linux-dev, mac-dev-ref-unit are reusable. Rebuilding only android, linux-rel, mac-rel-css, mac-rel-wpt...

@bors-servo
Copy link
Contributor

bors-servo commented Oct 19, 2015

💔 Test failed - mac-rel-wpt

@nox
Copy link
Member Author

nox commented Oct 19, 2015

@nox nox added S-awaiting-merge and removed S-tests-failed labels Oct 19, 2015
@bors-servo
Copy link
Contributor

bors-servo commented Oct 19, 2015

Testing commit 6dc42dd with merge 1a376aa...

bors-servo pushed a commit that referenced this pull request Oct 19, 2015
bors-servo
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 -->
@bors-servo
Copy link
Contributor

bors-servo commented Oct 19, 2015

@bors-servo bors-servo merged commit 6dc42dd into servo:master Oct 19, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@nox nox deleted the nox:deref-js branch Oct 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.