Skip to content
Permalink
Browse files

Simplify RootedReference and make it specifically about slicesIt's no…

…w called DomSlice<T>.
  • Loading branch information...
nox committed Mar 10, 2019
1 parent 1744a42 commit 4d527b20eef23422d52e8f097a98b9ae00723fc3
@@ -5899,7 +5899,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'crate::dom::bindings::root::Dom',
'crate::dom::bindings::root::DomRoot',
'crate::dom::bindings::root::OptionalHeapSetter',
'crate::dom::bindings::root::RootedReference',
'crate::dom::bindings::root::DomSlice',
'crate::dom::bindings::utils::AsVoidPtr',
'crate::dom::bindings::utils::DOMClass',
'crate::dom::bindings::utils::DOMJSClass',
@@ -256,18 +256,23 @@ pub unsafe fn trace_roots(tracer: *mut JSTracer) {
});
}

/// Get a reference out of a rooted value.
pub trait RootedReference<'root> {
/// The type of the reference.
type Ref: 'root;
/// Obtain a reference out of the rooted value.
fn r(&'root self) -> Self::Ref;
}

impl<'root, T: JSTraceable + DomObject + 'root> RootedReference<'root> for [Dom<T>] {
type Ref = &'root [&'root T];
fn r(&'root self) -> &'root [&'root T] {
unsafe { mem::transmute(self) }
/// Get a slice of references to DOM objects.
pub trait DomSlice<T>
where
T: JSTraceable + DomObject,
{
/// Returns the slice of `T` references.
fn r(&self) -> &[&T];
}

impl<T> DomSlice<T> for [Dom<T>]
where
T: JSTraceable + DomObject,
{
#[inline]
fn r(&self) -> &[&T] {
let _ = mem::transmute::<Dom<T>, &T>;
unsafe { &*(self as *const [Dom<T>] as *const [&T]) }
}
}

@@ -29,7 +29,7 @@ use crate::dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementType
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom, RootedReference};
use crate::dom::bindings::root::{Dom, DomRoot, DomSlice, LayoutDom, MutNullableDom};
use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::bindings::xmlname::XMLName::InvalidXMLName;
use crate::dom::bindings::xmlname::{
@@ -10,7 +10,7 @@ use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::refcounted::Trusted;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{DomRoot, MutNullableDom, RootedReference};
use crate::dom::bindings::root::{DomRoot, DomSlice, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::eventtarget::{CompiledEventListener, EventTarget, ListenerPhase};
@@ -5,7 +5,7 @@
use crate::dom::bindings::codegen::Bindings::GamepadButtonListBinding;
use crate::dom::bindings::codegen::Bindings::GamepadButtonListBinding::GamepadButtonListMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot, RootedReference};
use crate::dom::bindings::root::{Dom, DomRoot, DomSlice};
use crate::dom::gamepadbutton::GamepadButton;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
@@ -21,7 +21,7 @@ use crate::dom::bindings::inheritance::{Castable, CharacterDataTypeId, ElementTy
use crate::dom::bindings::inheritance::{EventTargetTypeId, HTMLElementTypeId, NodeTypeId};
use crate::dom::bindings::inheritance::{SVGElementTypeId, SVGGraphicsElementTypeId};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom, RootedReference};
use crate::dom::bindings::root::{Dom, DomRoot, DomSlice, LayoutDom, MutNullableDom};
use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::bindings::xmlname::namespace_from_domstring;
use crate::dom::characterdata::{CharacterData, LayoutCharacterDataHelpers};

0 comments on commit 4d527b2

Please sign in to comment.
You can’t perform that action at this time.