mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
script: Limit public exports. (#34915)
* script: Restrict reexport visibility of DOM types. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Mass pub->pub(crate) conversion. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Hide existing dead code warnings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix clippy warnings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix unit tests. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix clippy. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * More formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
f220d6d3a5
commit
c94d909a86
585 changed files with 5411 additions and 5013 deletions
|
@ -45,7 +45,7 @@ use crate::dom::node::Node;
|
|||
/// A rooted value.
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
|
||||
pub struct Root<T: StableTraceObject> {
|
||||
pub(crate) struct Root<T: StableTraceObject> {
|
||||
/// The value to root.
|
||||
value: T,
|
||||
/// List that ensures correct dynamic root ordering
|
||||
|
@ -60,7 +60,7 @@ where
|
|||
/// It cannot outlive its associated `RootCollection`, and it gives
|
||||
/// out references which cannot outlive this new `Root`.
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
pub unsafe fn new(value: T) -> Self {
|
||||
pub(crate) unsafe fn new(value: T) -> Self {
|
||||
unsafe fn add_to_root_list(object: *const dyn JSTraceable) -> *const RootCollection {
|
||||
assert_in_script();
|
||||
STACK_ROOTS.with(|root_list| {
|
||||
|
@ -85,7 +85,7 @@ where
|
|||
/// owned and referenced objects, so that the garbage collector can accurately determine which
|
||||
/// objects are still in use. Failing to adhere to this contract may result in undefined behavior,
|
||||
/// such as use-after-free errors.
|
||||
pub unsafe trait StableTraceObject {
|
||||
pub(crate) unsafe trait StableTraceObject {
|
||||
/// Returns a stable trace object which address won't change for the whole
|
||||
/// lifetime of the value.
|
||||
fn stable_trace_object(&self) -> *const dyn JSTraceable;
|
||||
|
@ -160,11 +160,11 @@ where
|
|||
}
|
||||
|
||||
/// A rooted reference to a DOM object.
|
||||
pub type DomRoot<T> = Root<Dom<T>>;
|
||||
pub(crate) type DomRoot<T> = Root<Dom<T>>;
|
||||
|
||||
impl<T: Castable> DomRoot<T> {
|
||||
/// Cast a DOM object root upwards to one of the interfaces it derives from.
|
||||
pub fn upcast<U>(root: DomRoot<T>) -> DomRoot<U>
|
||||
pub(crate) fn upcast<U>(root: DomRoot<T>) -> DomRoot<U>
|
||||
where
|
||||
U: Castable,
|
||||
T: DerivedFrom<U>,
|
||||
|
@ -173,7 +173,7 @@ impl<T: Castable> DomRoot<T> {
|
|||
}
|
||||
|
||||
/// Cast a DOM object root downwards to one of the interfaces it might implement.
|
||||
pub fn downcast<U>(root: DomRoot<T>) -> Option<DomRoot<U>>
|
||||
pub(crate) fn downcast<U>(root: DomRoot<T>) -> Option<DomRoot<U>>
|
||||
where
|
||||
U: DerivedFrom<T>,
|
||||
{
|
||||
|
@ -187,7 +187,7 @@ impl<T: Castable> DomRoot<T> {
|
|||
|
||||
impl<T: DomObject> DomRoot<T> {
|
||||
/// Generate a new root from a reference
|
||||
pub fn from_ref(unrooted: &T) -> DomRoot<T> {
|
||||
pub(crate) fn from_ref(unrooted: &T) -> DomRoot<T> {
|
||||
unsafe { DomRoot::new(Dom::from_ref(unrooted)) }
|
||||
}
|
||||
|
||||
|
@ -245,16 +245,16 @@ where
|
|||
/// See also [*Exact Stack Rooting - Storing a GCPointer on the CStack*][cstack].
|
||||
///
|
||||
/// [cstack]: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Internals/GC/Exact_Stack_Rooting
|
||||
pub struct RootCollection {
|
||||
pub(crate) struct RootCollection {
|
||||
roots: UnsafeCell<Vec<*const dyn JSTraceable>>,
|
||||
}
|
||||
|
||||
thread_local!(static STACK_ROOTS: Cell<Option<*const RootCollection>> = const { Cell::new(None) });
|
||||
|
||||
pub struct ThreadLocalStackRoots<'a>(PhantomData<&'a u32>);
|
||||
pub(crate) struct ThreadLocalStackRoots<'a>(PhantomData<&'a u32>);
|
||||
|
||||
impl<'a> ThreadLocalStackRoots<'a> {
|
||||
pub fn new(roots: &'a RootCollection) -> Self {
|
||||
pub(crate) fn new(roots: &'a RootCollection) -> Self {
|
||||
STACK_ROOTS.with(|r| r.set(Some(roots)));
|
||||
ThreadLocalStackRoots(PhantomData)
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ impl Drop for ThreadLocalStackRoots<'_> {
|
|||
|
||||
impl RootCollection {
|
||||
/// Create an empty collection of roots
|
||||
pub fn new() -> RootCollection {
|
||||
pub(crate) fn new() -> RootCollection {
|
||||
assert_in_script();
|
||||
RootCollection {
|
||||
roots: UnsafeCell::new(vec![]),
|
||||
|
@ -298,7 +298,7 @@ impl RootCollection {
|
|||
}
|
||||
|
||||
/// SM Callback that traces the rooted reflectors
|
||||
pub unsafe fn trace_roots(tracer: *mut JSTracer) {
|
||||
pub(crate) unsafe fn trace_roots(tracer: *mut JSTracer) {
|
||||
trace!("tracing stack roots");
|
||||
STACK_ROOTS.with(|collection| {
|
||||
let collection = &*(*collection.get().unwrap()).roots.get();
|
||||
|
@ -309,7 +309,7 @@ pub unsafe fn trace_roots(tracer: *mut JSTracer) {
|
|||
}
|
||||
|
||||
/// Get a slice of references to DOM objects.
|
||||
pub trait DomSlice<T>
|
||||
pub(crate) trait DomSlice<T>
|
||||
where
|
||||
T: JSTraceable + DomObject,
|
||||
{
|
||||
|
@ -336,7 +336,7 @@ where
|
|||
///
|
||||
/// This should only be used as a field in other DOM objects.
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
pub struct Dom<T> {
|
||||
pub(crate) struct Dom<T> {
|
||||
ptr: ptr::NonNull<T>,
|
||||
}
|
||||
|
||||
|
@ -354,7 +354,7 @@ impl<T> Dom<T> {
|
|||
/// # Safety
|
||||
///
|
||||
/// The `self` parameter to this method must meet all the requirements of [`ptr::NonNull::as_ref`].
|
||||
pub unsafe fn to_layout(&self) -> LayoutDom<T> {
|
||||
pub(crate) unsafe fn to_layout(&self) -> LayoutDom<T> {
|
||||
assert_in_layout();
|
||||
LayoutDom {
|
||||
value: self.ptr.as_ref(),
|
||||
|
@ -365,7 +365,7 @@ impl<T> Dom<T> {
|
|||
impl<T: DomObject> Dom<T> {
|
||||
/// Create a `Dom<T>` from a `&T`
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
pub fn from_ref(obj: &T) -> Dom<T> {
|
||||
pub(crate) fn from_ref(obj: &T) -> Dom<T> {
|
||||
assert_in_script();
|
||||
Dom {
|
||||
ptr: ptr::NonNull::from(obj),
|
||||
|
@ -404,7 +404,7 @@ unsafe impl<T: DomObject> JSTraceable for Dom<T> {
|
|||
|
||||
/// A traced reference to a DOM object that may not be reflected yet.
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
pub struct MaybeUnreflectedDom<T> {
|
||||
pub(crate) struct MaybeUnreflectedDom<T> {
|
||||
ptr: ptr::NonNull<T>,
|
||||
}
|
||||
|
||||
|
@ -413,7 +413,7 @@ where
|
|||
T: DomObject,
|
||||
{
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
pub unsafe fn from_box(value: Box<T>) -> Self {
|
||||
pub(crate) unsafe fn from_box(value: Box<T>) -> Self {
|
||||
Self {
|
||||
ptr: Box::leak(value).into(),
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ impl<T> Root<MaybeUnreflectedDom<T>>
|
|||
where
|
||||
T: DomObject,
|
||||
{
|
||||
pub fn as_ptr(&self) -> *const T {
|
||||
pub(crate) fn as_ptr(&self) -> *const T {
|
||||
self.value.ptr.as_ptr()
|
||||
}
|
||||
}
|
||||
|
@ -433,7 +433,7 @@ impl<T> Root<MaybeUnreflectedDom<T>>
|
|||
where
|
||||
T: MutDomObject,
|
||||
{
|
||||
pub unsafe fn reflect_with(self, obj: *mut JSObject) -> DomRoot<T> {
|
||||
pub(crate) unsafe fn reflect_with(self, obj: *mut JSObject) -> DomRoot<T> {
|
||||
let ptr = self.as_ptr();
|
||||
drop(self);
|
||||
let root = DomRoot::from_ref(&*ptr);
|
||||
|
@ -445,7 +445,7 @@ where
|
|||
/// An unrooted reference to a DOM object for use in layout. `Layout*Helpers`
|
||||
/// traits must be implemented on this.
|
||||
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
|
||||
pub struct LayoutDom<'dom, T> {
|
||||
pub(crate) struct LayoutDom<'dom, T> {
|
||||
value: &'dom T,
|
||||
}
|
||||
|
||||
|
@ -454,7 +454,7 @@ where
|
|||
T: Castable,
|
||||
{
|
||||
/// Cast a DOM object root upwards to one of the interfaces it derives from.
|
||||
pub fn upcast<U>(&self) -> LayoutDom<'dom, U>
|
||||
pub(crate) fn upcast<U>(&self) -> LayoutDom<'dom, U>
|
||||
where
|
||||
U: Castable,
|
||||
T: DerivedFrom<U>,
|
||||
|
@ -466,7 +466,7 @@ where
|
|||
}
|
||||
|
||||
/// Cast a DOM object downwards to one of the interfaces it might implement.
|
||||
pub fn downcast<U>(&self) -> Option<LayoutDom<'dom, U>>
|
||||
pub(crate) fn downcast<U>(&self) -> Option<LayoutDom<'dom, U>>
|
||||
where
|
||||
U: DerivedFrom<T>,
|
||||
{
|
||||
|
@ -475,7 +475,7 @@ where
|
|||
}
|
||||
|
||||
/// Returns whether this inner object is a U.
|
||||
pub fn is<U>(&self) -> bool
|
||||
pub(crate) fn is<U>(&self) -> bool
|
||||
where
|
||||
U: DerivedFrom<T>,
|
||||
{
|
||||
|
@ -489,7 +489,7 @@ where
|
|||
T: DomObject,
|
||||
{
|
||||
/// Get the reflector.
|
||||
pub unsafe fn get_jsobject(&self) -> *mut JSObject {
|
||||
pub(crate) unsafe fn get_jsobject(&self) -> *mut JSObject {
|
||||
assert_in_layout();
|
||||
self.value.reflector().get_jsobject().get()
|
||||
}
|
||||
|
@ -552,7 +552,7 @@ impl<T> Clone for LayoutDom<'_, T> {
|
|||
impl LayoutDom<'_, Node> {
|
||||
/// Create a new JS-owned value wrapped from an address known to be a
|
||||
/// `Node` pointer.
|
||||
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> Self {
|
||||
pub(crate) unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> Self {
|
||||
assert_in_layout();
|
||||
let TrustedNodeAddress(addr) = inner;
|
||||
LayoutDom {
|
||||
|
@ -568,13 +568,13 @@ impl LayoutDom<'_, Node> {
|
|||
/// on `Dom<T>`.
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
#[derive(JSTraceable)]
|
||||
pub struct MutDom<T: DomObject> {
|
||||
pub(crate) struct MutDom<T: DomObject> {
|
||||
val: UnsafeCell<Dom<T>>,
|
||||
}
|
||||
|
||||
impl<T: DomObject> MutDom<T> {
|
||||
/// Create a new `MutDom`.
|
||||
pub fn new(initial: &T) -> MutDom<T> {
|
||||
pub(crate) fn new(initial: &T) -> MutDom<T> {
|
||||
assert_in_script();
|
||||
MutDom {
|
||||
val: UnsafeCell::new(Dom::from_ref(initial)),
|
||||
|
@ -582,7 +582,7 @@ impl<T: DomObject> MutDom<T> {
|
|||
}
|
||||
|
||||
/// Set this `MutDom` to the given value.
|
||||
pub fn set(&self, val: &T) {
|
||||
pub(crate) fn set(&self, val: &T) {
|
||||
assert_in_script();
|
||||
unsafe {
|
||||
*self.val.get() = Dom::from_ref(val);
|
||||
|
@ -590,7 +590,7 @@ impl<T: DomObject> MutDom<T> {
|
|||
}
|
||||
|
||||
/// Get the value in this `MutDom`.
|
||||
pub fn get(&self) -> DomRoot<T> {
|
||||
pub(crate) fn get(&self) -> DomRoot<T> {
|
||||
assert_in_script();
|
||||
unsafe { DomRoot::from_ref(&*ptr::read(self.val.get())) }
|
||||
}
|
||||
|
@ -631,13 +631,13 @@ pub(crate) fn assert_in_layout() {
|
|||
/// on `Dom<T>`.
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
#[derive(JSTraceable)]
|
||||
pub struct MutNullableDom<T: DomObject> {
|
||||
pub(crate) struct MutNullableDom<T: DomObject> {
|
||||
ptr: UnsafeCell<Option<Dom<T>>>,
|
||||
}
|
||||
|
||||
impl<T: DomObject> MutNullableDom<T> {
|
||||
/// Create a new `MutNullableDom`.
|
||||
pub fn new(initial: Option<&T>) -> MutNullableDom<T> {
|
||||
pub(crate) fn new(initial: Option<&T>) -> MutNullableDom<T> {
|
||||
assert_in_script();
|
||||
MutNullableDom {
|
||||
ptr: UnsafeCell::new(initial.map(Dom::from_ref)),
|
||||
|
@ -646,7 +646,7 @@ impl<T: DomObject> MutNullableDom<T> {
|
|||
|
||||
/// Retrieve a copy of the current inner value. If it is `None`, it is
|
||||
/// initialized with the result of `cb` first.
|
||||
pub fn or_init<F>(&self, cb: F) -> DomRoot<T>
|
||||
pub(crate) fn or_init<F>(&self, cb: F) -> DomRoot<T>
|
||||
where
|
||||
F: FnOnce() -> DomRoot<T>,
|
||||
{
|
||||
|
@ -664,20 +664,20 @@ impl<T: DomObject> MutNullableDom<T> {
|
|||
/// Retrieve a copy of the inner optional `Dom<T>` as `LayoutDom<T>`.
|
||||
/// For use by layout, which can't use safe types like Temporary.
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
pub unsafe fn get_inner_as_layout(&self) -> Option<LayoutDom<T>> {
|
||||
pub(crate) unsafe fn get_inner_as_layout(&self) -> Option<LayoutDom<T>> {
|
||||
assert_in_layout();
|
||||
(*self.ptr.get()).as_ref().map(|js| js.to_layout())
|
||||
}
|
||||
|
||||
/// Get a rooted value out of this object
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
pub fn get(&self) -> Option<DomRoot<T>> {
|
||||
pub(crate) fn get(&self) -> Option<DomRoot<T>> {
|
||||
assert_in_script();
|
||||
unsafe { ptr::read(self.ptr.get()).map(|o| DomRoot::from_ref(&*o)) }
|
||||
}
|
||||
|
||||
/// Set this `MutNullableDom` to the given value.
|
||||
pub fn set(&self, val: Option<&T>) {
|
||||
pub(crate) fn set(&self, val: Option<&T>) {
|
||||
assert_in_script();
|
||||
unsafe {
|
||||
*self.ptr.get() = val.map(|p| Dom::from_ref(p));
|
||||
|
@ -685,7 +685,7 @@ impl<T: DomObject> MutNullableDom<T> {
|
|||
}
|
||||
|
||||
/// Gets the current value out of this object and sets it to `None`.
|
||||
pub fn take(&self) -> Option<DomRoot<T>> {
|
||||
pub(crate) fn take(&self) -> Option<DomRoot<T>> {
|
||||
let value = self.get();
|
||||
self.set(None);
|
||||
value
|
||||
|
@ -728,7 +728,7 @@ impl<T: DomObject> MallocSizeOf for MutNullableDom<T> {
|
|||
/// This should only be used as a field in other DOM objects; see warning
|
||||
/// on `Dom<T>`.
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
pub struct DomOnceCell<T: DomObject> {
|
||||
pub(crate) struct DomOnceCell<T: DomObject> {
|
||||
ptr: OnceCell<Dom<T>>,
|
||||
}
|
||||
|
||||
|
@ -739,7 +739,7 @@ where
|
|||
/// Retrieve a copy of the current inner value. If it is `None`, it is
|
||||
/// initialized with the result of `cb` first.
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
pub fn init_once<F>(&self, cb: F) -> &T
|
||||
pub(crate) fn init_once<F>(&self, cb: F) -> &T
|
||||
where
|
||||
F: FnOnce() -> DomRoot<T>,
|
||||
{
|
||||
|
@ -780,14 +780,14 @@ where
|
|||
{
|
||||
/// Returns a reference to the interior of this JS object. The fact
|
||||
/// that this is unsafe is what necessitates the layout wrappers.
|
||||
pub fn unsafe_get(self) -> &'dom T {
|
||||
pub(crate) fn unsafe_get(self) -> &'dom T {
|
||||
assert_in_layout();
|
||||
self.value
|
||||
}
|
||||
|
||||
/// Transforms a slice of `Dom<T>` into a slice of `LayoutDom<T>`.
|
||||
// FIXME(nox): This should probably be done through a ToLayout trait.
|
||||
pub unsafe fn to_layout_slice(slice: &'dom [Dom<T>]) -> &'dom [LayoutDom<'dom, T>] {
|
||||
pub(crate) unsafe fn to_layout_slice(slice: &'dom [Dom<T>]) -> &'dom [LayoutDom<'dom, T>] {
|
||||
// This doesn't compile if Dom and LayoutDom don't have the same
|
||||
// representation.
|
||||
let _ = mem::transmute::<Dom<T>, LayoutDom<T>>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue