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

Sanitize Heap::handle(_mut) functions #20399

Merged
merged 3 commits into from Mar 23, 2018

Conversation

@Xanewok
Copy link
Contributor

Xanewok commented Mar 23, 2018

Complementary to servo/rust-mozjs#404.

Removing Heap::handle_mut didn't warrant any changes on Servo side, and so the changes here are only to fix compilation with Heap::handle being now marked as unsafe.

The main idea is that we can't hand out handles to heap values themselves, since they're not guaranteed to be rooted, but it's safe to do when we are - hence why the safe impl on RootedTraceableBox<Heap<T>> and why it's safe to use inside structs that hold a Heap and are #[must_root].


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because the compiler forces correctness here.

This change is Reviewable

@highfive
Copy link

highfive commented Mar 23, 2018

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/timers.rs, components/script/dom/customelementregistry.rs, components/script/Cargo.toml, components/script/dom/bindings/reflector.rs, components/script/dom/bindings/trace.rs
  • @fitzgen: components/script/timers.rs, components/script/dom/customelementregistry.rs, components/script/Cargo.toml, components/script/dom/bindings/reflector.rs, components/script/dom/bindings/trace.rs
  • @KiChjang: components/script/timers.rs, components/script/dom/customelementregistry.rs, components/script/Cargo.toml, components/script/dom/bindings/reflector.rs, components/script/dom/bindings/trace.rs
@highfive
Copy link

highfive commented Mar 23, 2018

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify script code, but no tests are modified. Please consider adding a test!
@Xanewok
Copy link
Contributor Author

Xanewok commented Mar 23, 2018

r? @jdm

@highfive highfive assigned jdm and unassigned pcwalton Mar 23, 2018
// Returning Handles directly from Heap values is inherently unsafe, but here it's
// always done via rooted JsTimers, which is safe.
#[allow(unsafe_code)]
fn collect_heap_args(&self, args: &[Heap<JSVal>]) -> Vec<HandleValue> {

This comment has been minimized.

@Xanewok

Xanewok Mar 23, 2018

Author Contributor

Separated into another function, since I couldn't use the inline unsafe { ... } block due to #[deny(unsafe_code)] in script (and &self to tie it symbolically to JsTimerTask, which can only receive the Heap-wrapped arguments, which are rooted)

@jdm
jdm approved these changes Mar 23, 2018
@Xanewok Xanewok force-pushed the Xanewok:remove-heap-handle-mut branch from fa1c7c0 to f7c0395 Mar 23, 2018
@jdm
Copy link
Member

jdm commented Mar 23, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Mar 23, 2018

📌 Commit f7c0395 has been approved by jdm

bors-servo added a commit that referenced this pull request Mar 23, 2018
Sanitize Heap::handle(_mut) functions

<!-- Please describe your changes on the following line: -->
Complementary to servo/rust-mozjs#404.

Removing `Heap::handle_mut` didn't warrant any changes on Servo side, and so the changes here are only to fix compilation with `Heap::handle` being now marked as `unsafe`.

The main idea is that we can't hand out handles to heap values themselves, since they're not guaranteed to be rooted, but it's safe to do when we are - hence why the safe impl on `RootedTraceableBox<Heap<T>>` and why it's safe to use inside structs that hold a Heap and are `#[must_root]`.

---
<!-- 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 #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because the compiler forces correctness here.

<!-- 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/20399)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Mar 23, 2018

Testing commit f7c0395 with merge 18ef587...

@bors-servo
Copy link
Contributor

bors-servo commented Mar 23, 2018

@bors-servo bors-servo merged commit f7c0395 into servo:master Mar 23, 2018
1 of 2 checks passed
1 of 2 checks passed
continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
homu Test successful
Details
@Xanewok Xanewok deleted the Xanewok:remove-heap-handle-mut branch Mar 23, 2018
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

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