diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-09-26 14:25:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-26 14:25:20 -0500 |
commit | 0160aaeeea848f685ba090b4541646b0429a37e1 (patch) | |
tree | 41c9d55d3725169c213c7aee04a36023158b88cd /components/script/dom/bindings/root.rs | |
parent | 68533ac46b48b2d9b61f04a4e86b9c6a4fd6af77 (diff) | |
parent | 9ea645481b62b52c638c5fe3ccebb2518509ce37 (diff) | |
download | servo-0160aaeeea848f685ba090b4541646b0429a37e1.tar.gz servo-0160aaeeea848f685ba090b4541646b0429a37e1.zip |
Auto merge of #18641 - servo:ROOT-ALL-THE-THINGS, r=SimonSapin
Improve DomRoot<T>
<!-- 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/18641)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/root.rs')
-rw-r--r-- | components/script/dom/bindings/root.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index 1a81965fef9..251b17c3054 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -558,10 +558,11 @@ pub unsafe fn trace_roots(tracer: *mut JSTracer) { /// are additive, so this object's destruction will not invalidate other roots /// for the same JS value. `Root`s cannot outlive the associated /// `RootCollection` object. +#[allow(unrooted_must_root)] #[allow_unrooted_interior] pub struct DomRoot<T: DomObject> { /// Reference to rooted value that must not outlive this container - ptr: NonZero<*const T>, + ptr: Dom<T>, /// List that ensures correct dynamic root ordering root_list: *const RootCollection, } @@ -591,11 +592,12 @@ impl<T: DomObject> DomRoot<T> { /// Create a new stack-bounded root for the provided JS-owned value. /// It cannot outlive its associated `RootCollection`, and it gives /// out references which cannot outlive this new `Root`. - pub fn new(unrooted: NonZero<*const T>) -> DomRoot<T> { + #[allow(unrooted_must_root)] + unsafe fn new(unrooted: Dom<T>) -> DomRoot<T> { debug_assert!(thread_state::get().is_script()); STACK_ROOTS.with(|ref collection| { let RootCollectionPtr(collection) = collection.get().unwrap(); - unsafe { (*collection).root(&*(*unrooted.get()).reflector()) } + (*collection).root(unrooted.reflector()); DomRoot { ptr: unrooted, root_list: collection, @@ -605,7 +607,7 @@ impl<T: DomObject> DomRoot<T> { /// Generate a new root from a reference pub fn from_ref(unrooted: &T) -> DomRoot<T> { - DomRoot::new(unsafe { NonZero::new_unchecked(unrooted) }) + unsafe { DomRoot::new(Dom::from_ref(unrooted)) } } } @@ -620,7 +622,7 @@ impl<T: DomObject> Deref for DomRoot<T> { type Target = T; fn deref(&self) -> &T { debug_assert!(thread_state::get().is_script()); - unsafe { &*self.ptr.get() } + &self.ptr } } |