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:
Josh Matthews 2025-01-10 03:19:19 -05:00 committed by GitHub
parent f220d6d3a5
commit c94d909a86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
585 changed files with 5411 additions and 5013 deletions

View file

@ -42,7 +42,7 @@ use crate::script_thread::ScriptThread;
#[dom_struct]
#[crown::unrooted_must_root_lint::allow_unrooted_in_rc]
pub struct Promise {
pub(crate) struct Promise {
reflector: Reflector,
/// Since Promise values are natively reference counted without the knowledge of
/// the SpiderMonkey GC, an explicit root for the reflector is stored while any
@ -86,13 +86,13 @@ impl Drop for Promise {
}
impl Promise {
pub fn new(global: &GlobalScope, can_gc: CanGc) -> Rc<Promise> {
pub(crate) fn new(global: &GlobalScope, can_gc: CanGc) -> Rc<Promise> {
let realm = enter_realm(global);
let comp = InRealm::Entered(&realm);
Promise::new_in_current_realm(comp, can_gc)
}
pub fn new_in_current_realm(_comp: InRealm, can_gc: CanGc) -> Rc<Promise> {
pub(crate) fn new_in_current_realm(_comp: InRealm, can_gc: CanGc) -> Rc<Promise> {
let cx = GlobalScope::get_cx();
rooted!(in(*cx) let mut obj = ptr::null_mut::<JSObject>());
Promise::create_js_promise(cx, obj.handle_mut(), can_gc);
@ -100,13 +100,13 @@ impl Promise {
}
#[allow(unsafe_code)]
pub fn duplicate(&self) -> Rc<Promise> {
pub(crate) fn duplicate(&self) -> Rc<Promise> {
let cx = GlobalScope::get_cx();
Promise::new_with_js_promise(self.reflector().get_jsobject(), cx)
}
#[allow(unsafe_code, crown::unrooted_must_root)]
pub fn new_with_js_promise(obj: HandleObject, cx: SafeJSContext) -> Rc<Promise> {
pub(crate) fn new_with_js_promise(obj: HandleObject, cx: SafeJSContext) -> Rc<Promise> {
unsafe {
assert!(IsPromiseObject(obj));
let promise = Promise {
@ -147,7 +147,7 @@ impl Promise {
}
#[allow(crown::unrooted_must_root, unsafe_code)]
pub fn new_resolved(
pub(crate) fn new_resolved(
global: &GlobalScope,
cx: SafeJSContext,
value: impl ToJSValConvertible,
@ -163,7 +163,7 @@ impl Promise {
}
#[allow(crown::unrooted_must_root, unsafe_code)]
pub fn new_rejected(
pub(crate) fn new_rejected(
global: &GlobalScope,
cx: SafeJSContext,
value: impl ToJSValConvertible,
@ -179,7 +179,7 @@ impl Promise {
}
#[allow(unsafe_code)]
pub fn resolve_native<T>(&self, val: &T)
pub(crate) fn resolve_native<T>(&self, val: &T)
where
T: ToJSValConvertible,
{
@ -193,7 +193,7 @@ impl Promise {
}
#[allow(crown::unrooted_must_root, unsafe_code)]
pub fn resolve(&self, cx: SafeJSContext, value: HandleValue) {
pub(crate) fn resolve(&self, cx: SafeJSContext, value: HandleValue) {
unsafe {
if !ResolvePromise(*cx, self.promise_obj(), value) {
JS_ClearPendingException(*cx);
@ -202,7 +202,7 @@ impl Promise {
}
#[allow(unsafe_code)]
pub fn reject_native<T>(&self, val: &T)
pub(crate) fn reject_native<T>(&self, val: &T)
where
T: ToJSValConvertible,
{
@ -216,7 +216,7 @@ impl Promise {
}
#[allow(unsafe_code)]
pub fn reject_error(&self, error: Error) {
pub(crate) fn reject_error(&self, error: Error) {
let cx = GlobalScope::get_cx();
let _ac = enter_realm(self);
rooted!(in(*cx) let mut v = UndefinedValue());
@ -227,7 +227,7 @@ impl Promise {
}
#[allow(crown::unrooted_must_root, unsafe_code)]
pub fn reject(&self, cx: SafeJSContext, value: HandleValue) {
pub(crate) fn reject(&self, cx: SafeJSContext, value: HandleValue) {
unsafe {
if !RejectPromise(*cx, self.promise_obj(), value) {
JS_ClearPendingException(*cx);
@ -236,25 +236,25 @@ impl Promise {
}
#[allow(unsafe_code)]
pub fn is_fulfilled(&self) -> bool {
pub(crate) fn is_fulfilled(&self) -> bool {
let state = unsafe { GetPromiseState(self.promise_obj()) };
matches!(state, PromiseState::Rejected | PromiseState::Fulfilled)
}
#[allow(unsafe_code)]
pub fn is_rejected(&self) -> bool {
pub(crate) fn is_rejected(&self) -> bool {
let state = unsafe { GetPromiseState(self.promise_obj()) };
matches!(state, PromiseState::Rejected)
}
#[allow(unsafe_code)]
pub fn is_pending(&self) -> bool {
pub(crate) fn is_pending(&self) -> bool {
let state = unsafe { GetPromiseState(self.promise_obj()) };
matches!(state, PromiseState::Pending)
}
#[allow(unsafe_code)]
pub fn promise_obj(&self) -> HandleObject {
pub(crate) fn promise_obj(&self) -> HandleObject {
let obj = self.reflector().get_jsobject();
unsafe {
assert!(IsPromiseObject(obj));
@ -263,7 +263,7 @@ impl Promise {
}
#[allow(unsafe_code)]
pub fn append_native_handler(
pub(crate) fn append_native_handler(
&self,
handler: &PromiseNativeHandler,
_comp: InRealm,
@ -295,12 +295,12 @@ impl Promise {
}
#[allow(unsafe_code)]
pub fn get_promise_is_handled(&self) -> bool {
pub(crate) fn get_promise_is_handled(&self) -> bool {
unsafe { GetPromiseIsHandled(self.reflector().get_jsobject()) }
}
#[allow(unsafe_code)]
pub fn set_promise_is_handled(&self) -> bool {
pub(crate) fn set_promise_is_handled(&self) -> bool {
let cx = GlobalScope::get_cx();
unsafe { SetAnyPromiseIsHandled(*cx, self.reflector().get_jsobject()) }
}