aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/root.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bindings/root.rs')
-rw-r--r--components/script/dom/bindings/root.rs27
1 files changed, 20 insertions, 7 deletions
diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs
index 1fea453e35a..0ba69687dba 100644
--- a/components/script/dom/bindings/root.rs
+++ b/components/script/dom/bindings/root.rs
@@ -26,7 +26,7 @@
use crate::dom::bindings::conversions::DerivedFrom;
use crate::dom::bindings::inheritance::Castable;
-use crate::dom::bindings::reflector::{DomObject, Reflector};
+use crate::dom::bindings::reflector::{DomObject, MutDomObject, Reflector};
use crate::dom::bindings::trace::trace_reflector;
use crate::dom::bindings::trace::JSTraceable;
use crate::dom::node::Node;
@@ -262,7 +262,10 @@ impl RootCollection {
unsafe fn unroot(&self, object: *const dyn JSTraceable) {
debug_assert!(thread_state::get().is_script());
let roots = &mut *self.roots.get();
- match roots.iter().rposition(|r| *r == object) {
+ match roots
+ .iter()
+ .rposition(|r| *r as *const () == object as *const ())
+ {
Some(idx) => {
roots.remove(idx);
},
@@ -385,15 +388,25 @@ where
}
}
-impl<T> Deref for MaybeUnreflectedDom<T>
+impl<T> Root<MaybeUnreflectedDom<T>>
where
T: DomObject,
{
- type Target = T;
+ pub fn as_ptr(&self) -> *const T {
+ self.value.ptr.as_ptr()
+ }
+}
- fn deref(&self) -> &T {
- debug_assert!(thread_state::get().is_script());
- unsafe { &*self.ptr.as_ptr() }
+impl<T> Root<MaybeUnreflectedDom<T>>
+where
+ T: MutDomObject,
+{
+ pub unsafe fn reflect_with(self, obj: *mut JSObject) -> DomRoot<T> {
+ let ptr = self.as_ptr();
+ drop(self);
+ let root = DomRoot::from_ref(&*ptr);
+ root.init_reflector(obj);
+ root
}
}