diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-03-23 13:06:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-23 13:06:01 -0400 |
commit | 18ef5874dd3e11551e2f9503746540847eeb974c (patch) | |
tree | ae1fa73e8c0a2a1807e98990afdc038c9d788a59 /components/script/timers.rs | |
parent | 4a6453ac9ad956502ec6d39093b83820d94a409e (diff) | |
parent | f7c039516ce946b6dfe99a6936cf7f8ece72802b (diff) | |
download | servo-18ef5874dd3e11551e2f9503746540847eeb974c.tar.gz servo-18ef5874dd3e11551e2f9503746540847eeb974c.zip |
Auto merge of #20399 - Xanewok:remove-heap-handle-mut, r=jdm
Sanitize Heap::handle(_mut) functions
<!-- Please describe your changes on the following line: -->
Complementary to https://github.com/servo/rust-mozjs/pull/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 -->
Diffstat (limited to 'components/script/timers.rs')
-rw-r--r-- | components/script/timers.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/components/script/timers.rs b/components/script/timers.rs index 4bc4bf37fff..a5e7020095f 100644 --- a/components/script/timers.rs +++ b/components/script/timers.rs @@ -500,7 +500,7 @@ impl JsTimerTask { code_str, rval.handle_mut()); }, InternalTimerCallback::FunctionTimerCallback(ref function, ref arguments) => { - let arguments = arguments.iter().map(|arg| arg.handle()).collect(); + let arguments = self.collect_heap_args(arguments); let _ = function.Call_(this, arguments, Report); }, }; @@ -516,4 +516,11 @@ impl JsTimerTask { timers.initialize_and_schedule(&this.global(), self); } } + + // 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> { + args.iter().map(|arg| unsafe { arg.handle() }).collect() + } } |