Skip to content

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

Merged
bors-servo merged 21 commits into
servo:masterfrom
nox:deref-js
Oct 19, 2015
Merged

bors-servo merged 21 commits into
servo:masterfrom
nox:deref-js

Conversation

@nox

@nox nox commented Oct 17, 2015

Copy link
Copy Markdown
Contributor

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 October 17, 2015 01:58
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 highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 17, 2015
@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@eefriedman

Copy link
Copy Markdown
Contributor

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

nox commented Oct 18, 2015

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor

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

nox commented Oct 18, 2015

Copy link
Copy Markdown
Contributor Author

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

@eefriedman

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

We should perhaps disallow cloning JS<T>?

@nox

nox commented Oct 18, 2015

Copy link
Copy Markdown
Contributor Author

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

@Manishearth

Copy link
Copy Markdown
Member

Isn't Copy worse?

@nox

nox commented Oct 18, 2015

Copy link
Copy Markdown
Contributor Author

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

@Manishearth

Copy link
Copy Markdown
Member

@nox

nox commented Oct 18, 2015

Copy link
Copy Markdown
Contributor Author

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.

Comment thread components/script/dom/document.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@Ms2ger Ms2ger added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Oct 19, 2015
@Ms2ger

Ms2ger commented Oct 19, 2015

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor

📌 Commit 6dc42dd has been approved by Ms2ger

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ 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
Copy Markdown
Contributor

⛄ The build was interrupted to prioritize another pull request.

@bors-servo

Copy link
Copy Markdown
Contributor

⚡ 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
Copy Markdown
Contributor

💔 Test failed - mac-rel-wpt

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Oct 19, 2015
@nox

nox commented Oct 19, 2015

Copy link
Copy Markdown
Contributor Author

@bors-servo retry #7731

@nox nox added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Oct 19, 2015
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 6dc42dd with merge 1a376aa...

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
Copy Markdown
Contributor

☀️ Test successful - android, gonk, linux-dev, linux-rel, mac-dev-ref-unit, mac-rel-css, mac-rel-wpt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants