diff --git a/components/script/animation_timeline.rs b/components/script/animation_timeline.rs index 6cae2640cfa..108a90e85e4 100644 --- a/components/script/animation_timeline.rs +++ b/components/script/animation_timeline.rs @@ -21,7 +21,7 @@ pub(crate) struct AnimationTimeline { impl AnimationTimeline { /// Creates a new "normal" timeline, i.e., a "Current" mode timer. #[inline] - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { current_value: SystemTime::now() .duration_since(UNIX_EPOCH) @@ -32,17 +32,17 @@ impl AnimationTimeline { /// Creates a new "test mode" timeline, with initial time 0. #[inline] - pub fn new_for_testing() -> Self { + pub(crate) fn new_for_testing() -> Self { Self { current_value: 0. } } /// Returns the current value of the timeline in seconds. - pub fn current_value(&self) -> f64 { + pub(crate) fn current_value(&self) -> f64 { self.current_value } /// Updates the value of the `AnimationTimeline` to the current clock time. - pub fn update(&mut self) { + pub(crate) fn update(&mut self) { self.current_value = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap_or_default() @@ -51,7 +51,7 @@ impl AnimationTimeline { /// Increments the current value of the timeline by a specific number of seconds. /// This is used for testing. - pub fn advance_specific(&mut self, by: f64) { + pub(crate) fn advance_specific(&mut self, by: f64) { self.current_value += by; } } diff --git a/components/script/animations.rs b/components/script/animations.rs index 380333bf251..09a0eb4b8eb 100644 --- a/components/script/animations.rs +++ b/components/script/animations.rs @@ -41,7 +41,7 @@ use crate::script_runtime::CanGc; pub(crate) struct Animations { /// The map of nodes to their animation states. #[no_trace] - pub sets: DocumentAnimationSet, + pub(crate) sets: DocumentAnimationSet, /// Whether or not we have animations that are running. has_running_animations: Cell, @@ -550,7 +550,7 @@ impl Animations { /// The type of transition event to trigger. These are defined by /// CSS Transitions § 6.1 and CSS Animations § 4.2 #[derive(Clone, Debug, Deserialize, JSTraceable, MallocSizeOf, Serialize)] -pub enum TransitionOrAnimationEventType { +pub(crate) enum TransitionOrAnimationEventType { /// "The transitionrun event occurs when a transition is created (i.e., when it /// is added to the set of running transitions)." TransitionRun, @@ -577,7 +577,7 @@ pub enum TransitionOrAnimationEventType { impl TransitionOrAnimationEventType { /// Whether or not this event is a transition-related event. - pub fn is_transition_event(&self) -> bool { + pub(crate) fn is_transition_event(&self) -> bool { match *self { Self::TransitionRun | Self::TransitionEnd | @@ -593,21 +593,21 @@ impl TransitionOrAnimationEventType { #[derive(Deserialize, JSTraceable, MallocSizeOf, Serialize)] /// A transition or animation event. -pub struct TransitionOrAnimationEvent { +pub(crate) struct TransitionOrAnimationEvent { /// The pipeline id of the layout task that sent this message. #[no_trace] - pub pipeline_id: PipelineId, + pub(crate) pipeline_id: PipelineId, /// The type of transition event this should trigger. - pub event_type: TransitionOrAnimationEventType, + pub(crate) event_type: TransitionOrAnimationEventType, /// The address of the node which owns this transition. #[no_trace] - pub node: OpaqueNode, + pub(crate) node: OpaqueNode, /// The pseudo element for this transition or animation, if applicable. #[no_trace] - pub pseudo_element: Option, + pub(crate) pseudo_element: Option, /// The name of the property that is transitioning (in the case of a transition) /// or the name of the animation (in the case of an animation). - pub property_or_animation_name: String, + pub(crate) property_or_animation_name: String, /// The elapsed time property to send with this transition event. - pub elapsed_time: f64, + pub(crate) elapsed_time: f64, } diff --git a/components/script/body.rs b/components/script/body.rs index 5ce1a9294f0..5f02a599e77 100644 --- a/components/script/body.rs +++ b/components/script/body.rs @@ -45,7 +45,7 @@ use crate::task_source::SendableTaskSource; /// The Dom object, or ReadableStream, that is the source of a body. /// #[derive(Clone, PartialEq)] -pub enum BodySource { +pub(crate) enum BodySource { /// A ReadableStream comes with a null-source. Null, /// Another Dom object as source, @@ -79,7 +79,7 @@ struct TransmitBodyConnectHandler { } impl TransmitBodyConnectHandler { - pub fn new( + pub(crate) fn new( stream: Trusted, task_source: SendableTaskSource, control_sender: IpcSender, @@ -99,7 +99,7 @@ impl TransmitBodyConnectHandler { /// Reset `in_memory_done`, called when a stream is /// re-extracted from the source to support a re-direct. - pub fn reset_in_memory_done(&mut self) { + pub(crate) fn reset_in_memory_done(&mut self) { self.in_memory_done = false; } @@ -337,11 +337,11 @@ impl Callback for TransmitBodyPromiseRejectionHandler { } /// The result of -pub struct ExtractedBody { - pub stream: DomRoot, - pub source: BodySource, - pub total_bytes: Option, - pub content_type: Option, +pub(crate) struct ExtractedBody { + pub(crate) stream: DomRoot, + pub(crate) source: BodySource, + pub(crate) total_bytes: Option, + pub(crate) content_type: Option, } impl ExtractedBody { @@ -356,7 +356,7 @@ impl ExtractedBody { /// /// Transmitting a body over fetch, and consuming it in script, /// are mutually exclusive operations, since each will lock the stream to a reader. - pub fn into_net_request_body(self) -> (RequestBody, DomRoot) { + pub(crate) fn into_net_request_body(self) -> (RequestBody, DomRoot) { let ExtractedBody { stream, total_bytes, @@ -423,13 +423,13 @@ impl ExtractedBody { } /// Is the data of the stream of this extracted body available in memory? - pub fn in_memory(&self) -> bool { + pub(crate) fn in_memory(&self) -> bool { self.stream.in_memory() } } /// -pub trait Extractable { +pub(crate) trait Extractable { fn extract(&self, global: &GlobalScope, can_gc: CanGc) -> Fallible; } @@ -570,7 +570,7 @@ impl Extractable for URLSearchParams { } #[derive(Clone, Copy, JSTraceable, MallocSizeOf)] -pub enum BodyType { +pub(crate) enum BodyType { Blob, FormData, Json, @@ -578,7 +578,7 @@ pub enum BodyType { ArrayBuffer, } -pub enum FetchedData { +pub(crate) enum FetchedData { Text(String), Json(RootedTraceableBox>), BlobData(DomRoot), @@ -712,7 +712,7 @@ impl Callback for ConsumeBodyPromiseHandler { // https://fetch.spec.whatwg.org/#concept-body-consume-body #[allow(crown::unrooted_must_root)] -pub fn consume_body( +pub(crate) fn consume_body( object: &T, body_type: BodyType, can_gc: CanGc, @@ -889,7 +889,10 @@ fn run_form_data_algorithm( } #[allow(unsafe_code)] -pub fn run_array_buffer_data_algorithm(cx: JSContext, bytes: Vec) -> Fallible { +pub(crate) fn run_array_buffer_data_algorithm( + cx: JSContext, + bytes: Vec, +) -> Fallible { rooted!(in(*cx) let mut array_buffer_ptr = ptr::null_mut::()); let arraybuffer = unsafe { ArrayBuffer::create( @@ -906,7 +909,7 @@ pub fn run_array_buffer_data_algorithm(cx: JSContext, bytes: Vec) -> Fallibl } /// -pub trait BodyMixin { +pub(crate) trait BodyMixin { /// fn is_disturbed(&self) -> bool; /// diff --git a/components/script/build.rs b/components/script/build.rs index e6962d6b3ac..c7a905fa832 100644 --- a/components/script/build.rs +++ b/components/script/build.rs @@ -47,7 +47,7 @@ fn main() { let mut phf = File::create(phf).unwrap(); writeln!( &mut phf, - "pub static MAP: phf::Map<&'static [u8], fn(JSContext, HandleObject)> = {};", + "pub(crate) static MAP: phf::Map<&'static [u8], fn(JSContext, HandleObject)> = {};", map.build(), ) .unwrap(); diff --git a/components/script/canvas_state.rs b/components/script/canvas_state.rs index 0641a108244..6a7a6283bf4 100644 --- a/components/script/canvas_state.rs +++ b/components/script/canvas_state.rs @@ -196,40 +196,40 @@ impl CanvasState { } } - pub fn get_ipc_renderer(&self) -> &IpcSender { + pub(crate) fn get_ipc_renderer(&self) -> &IpcSender { &self.ipc_renderer } - pub fn get_missing_image_urls(&self) -> &DomRefCell> { + pub(crate) fn get_missing_image_urls(&self) -> &DomRefCell> { &self.missing_image_urls } - pub fn get_canvas_id(&self) -> CanvasId { + pub(crate) fn get_canvas_id(&self) -> CanvasId { self.canvas_id } - pub fn send_canvas_2d_msg(&self, msg: Canvas2dMsg) { + pub(crate) fn send_canvas_2d_msg(&self, msg: Canvas2dMsg) { self.ipc_renderer .send(CanvasMsg::Canvas2d(msg, self.get_canvas_id())) .unwrap() } // https://html.spec.whatwg.org/multipage/#concept-canvas-set-bitmap-dimensions - pub fn set_bitmap_dimensions(&self, size: Size2D) { + pub(crate) fn set_bitmap_dimensions(&self, size: Size2D) { self.reset_to_initial_state(); self.ipc_renderer .send(CanvasMsg::Recreate(Some(size), self.get_canvas_id())) .unwrap(); } - pub fn reset(&self) { + pub(crate) fn reset(&self) { self.reset_to_initial_state(); self.ipc_renderer .send(CanvasMsg::Recreate(None, self.get_canvas_id())) .unwrap(); } - pub fn reset_to_initial_state(&self) { + pub(crate) fn reset_to_initial_state(&self) { self.saved_states.borrow_mut().clear(); *self.state.borrow_mut() = CanvasContextState::new(); } @@ -249,7 +249,7 @@ impl CanvasState { )) } - pub fn origin_is_clean(&self) -> bool { + pub(crate) fn origin_is_clean(&self) -> bool { self.origin_clean.get() } @@ -311,7 +311,7 @@ impl CanvasState { } } - pub fn get_rect(&self, canvas_size: Size2D, rect: Rect) -> Vec { + pub(crate) fn get_rect(&self, canvas_size: Size2D, rect: Rect) -> Vec { assert!(self.origin_is_clean()); assert!(Rect::from_size(canvas_size).contains_rect(&rect)); @@ -589,7 +589,7 @@ impl CanvasState { Ok(()) } - pub fn mark_as_dirty(&self, canvas: Option<&HTMLCanvasElement>) { + pub(crate) fn mark_as_dirty(&self, canvas: Option<&HTMLCanvasElement>) { if let Some(canvas) = canvas { canvas.upcast::().dirty(NodeDamage::OtherNodeDamage); } @@ -665,7 +665,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-fillrect - pub fn fill_rect(&self, x: f64, y: f64, width: f64, height: f64) { + pub(crate) fn fill_rect(&self, x: f64, y: f64, width: f64, height: f64) { if let Some(rect) = self.create_drawable_rect(x, y, width, height) { let style = self.state.borrow().fill_style.to_fill_or_stroke_style(); self.send_canvas_2d_msg(Canvas2dMsg::FillRect(rect, style)); @@ -673,14 +673,14 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-clearrect - pub fn clear_rect(&self, x: f64, y: f64, width: f64, height: f64) { + pub(crate) fn clear_rect(&self, x: f64, y: f64, width: f64, height: f64) { if let Some(rect) = self.create_drawable_rect(x, y, width, height) { self.send_canvas_2d_msg(Canvas2dMsg::ClearRect(rect)); } } // https://html.spec.whatwg.org/multipage/#dom-context-2d-strokerect - pub fn stroke_rect(&self, x: f64, y: f64, width: f64, height: f64) { + pub(crate) fn stroke_rect(&self, x: f64, y: f64, width: f64, height: f64) { if let Some(rect) = self.create_drawable_rect(x, y, width, height) { let style = self.state.borrow().stroke_style.to_fill_or_stroke_style(); self.send_canvas_2d_msg(Canvas2dMsg::StrokeRect(rect, style)); @@ -688,12 +688,12 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsetx - pub fn shadow_offset_x(&self) -> f64 { + pub(crate) fn shadow_offset_x(&self) -> f64 { self.state.borrow().shadow_offset_x } // https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsetx - pub fn set_shadow_offset_x(&self, value: f64) { + pub(crate) fn set_shadow_offset_x(&self, value: f64) { if !value.is_finite() || value == self.state.borrow().shadow_offset_x { return; } @@ -702,12 +702,12 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsety - pub fn shadow_offset_y(&self) -> f64 { + pub(crate) fn shadow_offset_y(&self) -> f64 { self.state.borrow().shadow_offset_y } // https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsety - pub fn set_shadow_offset_y(&self, value: f64) { + pub(crate) fn set_shadow_offset_y(&self, value: f64) { if !value.is_finite() || value == self.state.borrow().shadow_offset_y { return; } @@ -716,12 +716,12 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowblur - pub fn shadow_blur(&self) -> f64 { + pub(crate) fn shadow_blur(&self) -> f64 { self.state.borrow().shadow_blur } // https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowblur - pub fn set_shadow_blur(&self, value: f64) { + pub(crate) fn set_shadow_blur(&self, value: f64) { if !value.is_finite() || value < 0f64 || value == self.state.borrow().shadow_blur { return; } @@ -730,14 +730,14 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor - pub fn shadow_color(&self) -> DOMString { + pub(crate) fn shadow_color(&self) -> DOMString { let mut result = String::new(); serialize(&self.state.borrow().shadow_color, &mut result).unwrap(); DOMString::from(result) } // https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor - pub fn set_shadow_color( + pub(crate) fn set_shadow_color( &self, canvas: Option<&HTMLCanvasElement>, value: DOMString, @@ -750,7 +750,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle - pub fn stroke_style(&self) -> StringOrCanvasGradientOrCanvasPattern { + pub(crate) fn stroke_style(&self) -> StringOrCanvasGradientOrCanvasPattern { match self.state.borrow().stroke_style { CanvasFillOrStrokeStyle::Color(ref rgba) => { let mut result = String::new(); @@ -767,7 +767,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle - pub fn set_stroke_style( + pub(crate) fn set_stroke_style( &self, canvas: Option<&HTMLCanvasElement>, value: StringOrCanvasGradientOrCanvasPattern, @@ -794,7 +794,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle - pub fn fill_style(&self) -> StringOrCanvasGradientOrCanvasPattern { + pub(crate) fn fill_style(&self) -> StringOrCanvasGradientOrCanvasPattern { match self.state.borrow().fill_style { CanvasFillOrStrokeStyle::Color(ref rgba) => { let mut result = String::new(); @@ -811,7 +811,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle - pub fn set_fill_style( + pub(crate) fn set_fill_style( &self, canvas: Option<&HTMLCanvasElement>, value: StringOrCanvasGradientOrCanvasPattern, @@ -838,7 +838,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-createlineargradient - pub fn create_linear_gradient( + pub(crate) fn create_linear_gradient( &self, global: &GlobalScope, x0: Finite, @@ -854,7 +854,7 @@ impl CanvasState { /// #[allow(clippy::too_many_arguments)] - pub fn create_radial_gradient( + pub(crate) fn create_radial_gradient( &self, global: &GlobalScope, x0: Finite, @@ -883,7 +883,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-createpattern - pub fn create_pattern( + pub(crate) fn create_pattern( &self, global: &GlobalScope, image: CanvasImageSource, @@ -943,7 +943,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-save - pub fn save(&self) { + pub(crate) fn save(&self) { self.saved_states .borrow_mut() .push(self.state.borrow().clone()); @@ -952,7 +952,7 @@ impl CanvasState { #[allow(crown::unrooted_must_root)] // https://html.spec.whatwg.org/multipage/#dom-context-2d-restore - pub fn restore(&self) { + pub(crate) fn restore(&self) { let mut saved_states = self.saved_states.borrow_mut(); if let Some(state) = saved_states.pop() { self.state.borrow_mut().clone_from(&state); @@ -961,12 +961,12 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha - pub fn global_alpha(&self) -> f64 { + pub(crate) fn global_alpha(&self) -> f64 { self.state.borrow().global_alpha } // https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha - pub fn set_global_alpha(&self, alpha: f64) { + pub(crate) fn set_global_alpha(&self, alpha: f64) { if !alpha.is_finite() || !(0.0..=1.0).contains(&alpha) { return; } @@ -976,7 +976,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation - pub fn global_composite_operation(&self) -> DOMString { + pub(crate) fn global_composite_operation(&self) -> DOMString { match self.state.borrow().global_composition { CompositionOrBlending::Composition(op) => DOMString::from(op.to_str()), CompositionOrBlending::Blending(op) => DOMString::from(op.to_str()), @@ -984,7 +984,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation - pub fn set_global_composite_operation(&self, op_str: DOMString) { + pub(crate) fn set_global_composite_operation(&self, op_str: DOMString) { if let Ok(op) = CompositionOrBlending::from_str(&op_str) { self.state.borrow_mut().global_composition = op; self.send_canvas_2d_msg(Canvas2dMsg::SetGlobalComposition(op)) @@ -992,17 +992,17 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled - pub fn image_smoothing_enabled(&self) -> bool { + pub(crate) fn image_smoothing_enabled(&self) -> bool { self.state.borrow().image_smoothing_enabled } // https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled - pub fn set_image_smoothing_enabled(&self, value: bool) { + pub(crate) fn set_image_smoothing_enabled(&self, value: bool) { self.state.borrow_mut().image_smoothing_enabled = value; } // https://html.spec.whatwg.org/multipage/#dom-context-2d-filltext - pub fn fill_text( + pub(crate) fn fill_text( &self, canvas: Option<&HTMLCanvasElement>, text: DOMString, @@ -1043,7 +1043,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#textmetrics - pub fn measure_text( + pub(crate) fn measure_text( &self, global: &GlobalScope, canvas: Option<&HTMLCanvasElement>, @@ -1080,7 +1080,12 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-font - pub fn set_font(&self, canvas: Option<&HTMLCanvasElement>, value: DOMString, can_gc: CanGc) { + pub(crate) fn set_font( + &self, + canvas: Option<&HTMLCanvasElement>, + value: DOMString, + can_gc: CanGc, + ) { let canvas = match canvas { Some(element) => element, None => return, // offscreen canvas doesn't have a placeholder canvas @@ -1097,7 +1102,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-font - pub fn font(&self) -> DOMString { + pub(crate) fn font(&self) -> DOMString { self.state.borrow().font_style.as_ref().map_or_else( || CanvasContextState::DEFAULT_FONT_STYLE.into(), |style| { @@ -1109,7 +1114,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign - pub fn text_align(&self) -> CanvasTextAlign { + pub(crate) fn text_align(&self) -> CanvasTextAlign { match self.state.borrow().text_align { TextAlign::Start => CanvasTextAlign::Start, TextAlign::End => CanvasTextAlign::End, @@ -1120,7 +1125,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign - pub fn set_text_align(&self, value: CanvasTextAlign) { + pub(crate) fn set_text_align(&self, value: CanvasTextAlign) { let text_align = match value { CanvasTextAlign::Start => TextAlign::Start, CanvasTextAlign::End => TextAlign::End, @@ -1132,7 +1137,7 @@ impl CanvasState { self.send_canvas_2d_msg(Canvas2dMsg::SetTextAlign(text_align)); } - pub fn text_baseline(&self) -> CanvasTextBaseline { + pub(crate) fn text_baseline(&self) -> CanvasTextBaseline { match self.state.borrow().text_baseline { TextBaseline::Top => CanvasTextBaseline::Top, TextBaseline::Hanging => CanvasTextBaseline::Hanging, @@ -1143,7 +1148,7 @@ impl CanvasState { } } - pub fn set_text_baseline(&self, value: CanvasTextBaseline) { + pub(crate) fn set_text_baseline(&self, value: CanvasTextBaseline) { let text_baseline = match value { CanvasTextBaseline::Top => TextBaseline::Top, CanvasTextBaseline::Hanging => TextBaseline::Hanging, @@ -1157,7 +1162,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-direction - pub fn direction(&self) -> CanvasDirection { + pub(crate) fn direction(&self) -> CanvasDirection { match self.state.borrow().direction { Direction::Ltr => CanvasDirection::Ltr, Direction::Rtl => CanvasDirection::Rtl, @@ -1166,7 +1171,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-direction - pub fn set_direction(&self, value: CanvasDirection) { + pub(crate) fn set_direction(&self, value: CanvasDirection) { let direction = match value { CanvasDirection::Ltr => Direction::Ltr, CanvasDirection::Rtl => Direction::Rtl, @@ -1176,12 +1181,12 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth - pub fn line_width(&self) -> f64 { + pub(crate) fn line_width(&self) -> f64 { self.state.borrow().line_width } // https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth - pub fn set_line_width(&self, width: f64) { + pub(crate) fn set_line_width(&self, width: f64) { if !width.is_finite() || width <= 0.0 { return; } @@ -1191,7 +1196,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap - pub fn line_cap(&self) -> CanvasLineCap { + pub(crate) fn line_cap(&self) -> CanvasLineCap { match self.state.borrow().line_cap { LineCapStyle::Butt => CanvasLineCap::Butt, LineCapStyle::Round => CanvasLineCap::Round, @@ -1200,7 +1205,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap - pub fn set_line_cap(&self, cap: CanvasLineCap) { + pub(crate) fn set_line_cap(&self, cap: CanvasLineCap) { let line_cap = match cap { CanvasLineCap::Butt => LineCapStyle::Butt, CanvasLineCap::Round => LineCapStyle::Round, @@ -1211,7 +1216,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin - pub fn line_join(&self) -> CanvasLineJoin { + pub(crate) fn line_join(&self) -> CanvasLineJoin { match self.state.borrow().line_join { LineJoinStyle::Round => CanvasLineJoin::Round, LineJoinStyle::Bevel => CanvasLineJoin::Bevel, @@ -1220,7 +1225,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin - pub fn set_line_join(&self, join: CanvasLineJoin) { + pub(crate) fn set_line_join(&self, join: CanvasLineJoin) { let line_join = match join { CanvasLineJoin::Round => LineJoinStyle::Round, CanvasLineJoin::Bevel => LineJoinStyle::Bevel, @@ -1231,12 +1236,12 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit - pub fn miter_limit(&self) -> f64 { + pub(crate) fn miter_limit(&self) -> f64 { self.state.borrow().miter_limit } // https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit - pub fn set_miter_limit(&self, limit: f64) { + pub(crate) fn set_miter_limit(&self, limit: f64) { if !limit.is_finite() || limit <= 0.0 { return; } @@ -1246,7 +1251,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata - pub fn create_image_data( + pub(crate) fn create_image_data( &self, global: &GlobalScope, sw: i32, @@ -1260,7 +1265,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata - pub fn create_image_data_( + pub(crate) fn create_image_data_( &self, global: &GlobalScope, imagedata: &ImageData, @@ -1271,7 +1276,7 @@ impl CanvasState { // https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata #[allow(clippy::too_many_arguments)] - pub fn get_image_data( + pub(crate) fn get_image_data( &self, canvas_size: Size2D, global: &GlobalScope, @@ -1311,7 +1316,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata - pub fn put_image_data( + pub(crate) fn put_image_data( &self, canvas_size: Size2D, imagedata: &ImageData, @@ -1332,7 +1337,7 @@ impl CanvasState { /// #[allow(unsafe_code, clippy::too_many_arguments)] - pub fn put_image_data_( + pub(crate) fn put_image_data_( &self, canvas_size: Size2D, imagedata: &ImageData, @@ -1385,7 +1390,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage - pub fn draw_image( + pub(crate) fn draw_image( &self, canvas: Option<&HTMLCanvasElement>, image: CanvasImageSource, @@ -1400,7 +1405,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage - pub fn draw_image_( + pub(crate) fn draw_image_( &self, canvas: Option<&HTMLCanvasElement>, image: CanvasImageSource, @@ -1429,7 +1434,7 @@ impl CanvasState { /// #[allow(clippy::too_many_arguments)] - pub fn draw_image__( + pub(crate) fn draw_image__( &self, canvas: Option<&HTMLCanvasElement>, image: CanvasImageSource, @@ -1469,31 +1474,31 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-beginpath - pub fn begin_path(&self) { + pub(crate) fn begin_path(&self) { self.send_canvas_2d_msg(Canvas2dMsg::BeginPath); } // https://html.spec.whatwg.org/multipage/#dom-context-2d-fill - pub fn fill(&self, _fill_rule: CanvasFillRule) { + pub(crate) fn fill(&self, _fill_rule: CanvasFillRule) { // TODO: Process fill rule let style = self.state.borrow().fill_style.to_fill_or_stroke_style(); self.send_canvas_2d_msg(Canvas2dMsg::Fill(style)); } // https://html.spec.whatwg.org/multipage/#dom-context-2d-stroke - pub fn stroke(&self) { + pub(crate) fn stroke(&self) { let style = self.state.borrow().stroke_style.to_fill_or_stroke_style(); self.send_canvas_2d_msg(Canvas2dMsg::Stroke(style)); } // https://html.spec.whatwg.org/multipage/#dom-context-2d-clip - pub fn clip(&self, _fill_rule: CanvasFillRule) { + pub(crate) fn clip(&self, _fill_rule: CanvasFillRule) { // TODO: Process fill rule self.send_canvas_2d_msg(Canvas2dMsg::Clip); } // https://html.spec.whatwg.org/multipage/#dom-context-2d-ispointinpath - pub fn is_point_in_path( + pub(crate) fn is_point_in_path( &self, global: &GlobalScope, x: f64, @@ -1515,7 +1520,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-scale - pub fn scale(&self, x: f64, y: f64) { + pub(crate) fn scale(&self, x: f64, y: f64) { if !(x.is_finite() && y.is_finite()) { return; } @@ -1526,7 +1531,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-rotate - pub fn rotate(&self, angle: f64) { + pub(crate) fn rotate(&self, angle: f64) { if angle == 0.0 || !angle.is_finite() { return; } @@ -1540,7 +1545,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-translate - pub fn translate(&self, x: f64, y: f64) { + pub(crate) fn translate(&self, x: f64, y: f64) { if !(x.is_finite() && y.is_finite()) { return; } @@ -1551,7 +1556,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-transform - pub fn transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) { + pub(crate) fn transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) { if !(a.is_finite() && b.is_finite() && c.is_finite() && @@ -1570,7 +1575,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform - pub fn get_transform(&self, global: &GlobalScope, can_gc: CanGc) -> DomRoot { + pub(crate) fn get_transform(&self, global: &GlobalScope, can_gc: CanGc) -> DomRoot { let (sender, receiver) = ipc::channel::>().unwrap(); self.send_canvas_2d_msg(Canvas2dMsg::GetTransform(sender)); let transform = receiver.recv().unwrap(); @@ -1579,7 +1584,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform - pub fn set_transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) { + pub(crate) fn set_transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) { if !(a.is_finite() && b.is_finite() && c.is_finite() && @@ -1596,18 +1601,18 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-resettransform - pub fn reset_transform(&self) { + pub(crate) fn reset_transform(&self) { self.state.borrow_mut().transform = Transform2D::identity(); self.update_transform() } // https://html.spec.whatwg.org/multipage/#dom-context-2d-closepath - pub fn close_path(&self) { + pub(crate) fn close_path(&self) { self.send_canvas_2d_msg(Canvas2dMsg::ClosePath); } // https://html.spec.whatwg.org/multipage/#dom-context-2d-moveto - pub fn move_to(&self, x: f64, y: f64) { + pub(crate) fn move_to(&self, x: f64, y: f64) { if !(x.is_finite() && y.is_finite()) { return; } @@ -1615,7 +1620,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-lineto - pub fn line_to(&self, x: f64, y: f64) { + pub(crate) fn line_to(&self, x: f64, y: f64) { if !(x.is_finite() && y.is_finite()) { return; } @@ -1623,7 +1628,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-rect - pub fn rect(&self, x: f64, y: f64, width: f64, height: f64) { + pub(crate) fn rect(&self, x: f64, y: f64, width: f64, height: f64) { if [x, y, width, height].iter().all(|val| val.is_finite()) { let rect = Rect::new( Point2D::new(x as f32, y as f32), @@ -1634,7 +1639,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-quadraticcurveto - pub fn quadratic_curve_to(&self, cpx: f64, cpy: f64, x: f64, y: f64) { + pub(crate) fn quadratic_curve_to(&self, cpx: f64, cpy: f64, x: f64, y: f64) { if !(cpx.is_finite() && cpy.is_finite() && x.is_finite() && y.is_finite()) { return; } @@ -1645,7 +1650,15 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-beziercurveto - pub fn bezier_curve_to(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, x: f64, y: f64) { + pub(crate) fn bezier_curve_to( + &self, + cp1x: f64, + cp1y: f64, + cp2x: f64, + cp2y: f64, + x: f64, + y: f64, + ) { if !(cp1x.is_finite() && cp1y.is_finite() && cp2x.is_finite() && @@ -1663,7 +1676,15 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-arc - pub fn arc(&self, x: f64, y: f64, r: f64, start: f64, end: f64, ccw: bool) -> ErrorResult { + pub(crate) fn arc( + &self, + x: f64, + y: f64, + r: f64, + start: f64, + end: f64, + ccw: bool, + ) -> ErrorResult { if !([x, y, r, start, end].iter().all(|x| x.is_finite())) { return Ok(()); } @@ -1683,7 +1704,7 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-arcto - pub fn arc_to(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, r: f64) -> ErrorResult { + pub(crate) fn arc_to(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, r: f64) -> ErrorResult { if !([cp1x, cp1y, cp2x, cp2y, r].iter().all(|x| x.is_finite())) { return Ok(()); } @@ -1701,7 +1722,7 @@ impl CanvasState { /// #[allow(clippy::too_many_arguments)] - pub fn ellipse( + pub(crate) fn ellipse( &self, x: f64, y: f64, @@ -1735,7 +1756,7 @@ impl CanvasState { } } -pub fn parse_color( +pub(crate) fn parse_color( canvas: Option<&HTMLCanvasElement>, string: &str, can_gc: CanGc, @@ -1784,12 +1805,12 @@ pub fn parse_color( // Used by drawImage to determine if a source or destination rectangle is valid // Origin coordinates and size cannot be negative. Size has to be greater than zero -pub fn is_rect_valid(rect: Rect) -> bool { +pub(crate) fn is_rect_valid(rect: Rect) -> bool { rect.size.width > 0.0 && rect.size.height > 0.0 } // https://html.spec.whatwg.org/multipage/#serialisation-of-a-color -pub fn serialize(color: &AbsoluteColor, dest: &mut W) -> fmt::Result +pub(crate) fn serialize(color: &AbsoluteColor, dest: &mut W) -> fmt::Result where W: fmt::Write, { @@ -1819,7 +1840,7 @@ where } } -pub fn adjust_size_sign( +pub(crate) fn adjust_size_sign( mut origin: Point2D, mut size: Size2D, ) -> (Point2D, Size2D) { diff --git a/components/script/conversions.rs b/components/script/conversions.rs index c9cd43f5e58..7bb5059831b 100644 --- a/components/script/conversions.rs +++ b/components/script/conversions.rs @@ -6,7 +6,7 @@ /// to convert between two types that are not defined in the script crate. /// This is intended to be used on dict/enum types generated from WebIDL once /// those types are moved out of the script crate. -pub trait Convert { +pub(crate) trait Convert { fn convert(self) -> T; } @@ -14,7 +14,7 @@ pub trait Convert { /// to convert between two types that are not defined in the script crate. /// This is intended to be used on dict/enum types generated from WebIDL once /// those types are moved out of the script crate. -pub trait TryConvert { +pub(crate) trait TryConvert { type Error; fn try_convert(self) -> Result; diff --git a/components/script/devtools.rs b/components/script/devtools.rs index 00b6f767a24..5635cbcfd0d 100644 --- a/components/script/devtools.rs +++ b/components/script/devtools.rs @@ -44,7 +44,7 @@ use crate::script_module::ScriptFetchOptions; use crate::script_runtime::CanGc; #[allow(unsafe_code)] -pub fn handle_evaluate_js( +pub(crate) fn handle_evaluate_js( global: &GlobalScope, eval: String, reply: IpcSender, @@ -97,7 +97,7 @@ pub fn handle_evaluate_js( reply.send(result).unwrap(); } -pub fn handle_get_root_node( +pub(crate) fn handle_get_root_node( documents: &DocumentCollection, pipeline: PipelineId, reply: IpcSender>, @@ -108,7 +108,7 @@ pub fn handle_get_root_node( reply.send(info).unwrap(); } -pub fn handle_get_document_element( +pub(crate) fn handle_get_document_element( documents: &DocumentCollection, pipeline: PipelineId, reply: IpcSender>, @@ -133,7 +133,7 @@ fn find_node_by_unique_id( }) } -pub fn handle_get_children( +pub(crate) fn handle_get_children( documents: &DocumentCollection, pipeline: PipelineId, node_id: String, @@ -185,7 +185,7 @@ pub fn handle_get_children( }; } -pub fn handle_get_attribute_style( +pub(crate) fn handle_get_attribute_style( documents: &DocumentCollection, pipeline: PipelineId, node_id: String, @@ -217,7 +217,7 @@ pub fn handle_get_attribute_style( } #[allow(crown::unrooted_must_root)] -pub fn handle_get_stylesheet_style( +pub(crate) fn handle_get_stylesheet_style( documents: &DocumentCollection, pipeline: PipelineId, node_id: String, @@ -264,7 +264,7 @@ pub fn handle_get_stylesheet_style( } #[allow(crown::unrooted_must_root)] -pub fn handle_get_selectors( +pub(crate) fn handle_get_selectors( documents: &DocumentCollection, pipeline: PipelineId, node_id: String, @@ -300,7 +300,7 @@ pub fn handle_get_selectors( reply.send(msg).unwrap(); } -pub fn handle_get_computed_style( +pub(crate) fn handle_get_computed_style( documents: &DocumentCollection, pipeline: PipelineId, node_id: String, @@ -334,7 +334,7 @@ pub fn handle_get_computed_style( reply.send(Some(msg)).unwrap(); } -pub fn handle_get_layout( +pub(crate) fn handle_get_layout( documents: &DocumentCollection, pipeline: PipelineId, node_id: String, @@ -395,7 +395,7 @@ fn determine_auto_margins(node: &Node, can_gc: CanGc) -> AutoMargins { } } -pub fn handle_modify_attribute( +pub(crate) fn handle_modify_attribute( documents: &DocumentCollection, pipeline: PipelineId, node_id: String, @@ -435,7 +435,7 @@ pub fn handle_modify_attribute( } } -pub fn handle_modify_rule( +pub(crate) fn handle_modify_rule( documents: &DocumentCollection, pipeline: PipelineId, node_id: String, @@ -469,11 +469,11 @@ pub fn handle_modify_rule( } } -pub fn handle_wants_live_notifications(global: &GlobalScope, send_notifications: bool) { +pub(crate) fn handle_wants_live_notifications(global: &GlobalScope, send_notifications: bool) { global.set_devtools_wants_updates(send_notifications); } -pub fn handle_set_timeline_markers( +pub(crate) fn handle_set_timeline_markers( documents: &DocumentCollection, pipeline: PipelineId, marker_types: Vec, @@ -485,7 +485,7 @@ pub fn handle_set_timeline_markers( } } -pub fn handle_drop_timeline_markers( +pub(crate) fn handle_drop_timeline_markers( documents: &DocumentCollection, pipeline: PipelineId, marker_types: Vec, @@ -495,7 +495,7 @@ pub fn handle_drop_timeline_markers( } } -pub fn handle_request_animation_frame( +pub(crate) fn handle_request_animation_frame( documents: &DocumentCollection, id: PipelineId, actor_name: String, @@ -505,13 +505,13 @@ pub fn handle_request_animation_frame( } } -pub fn handle_reload(documents: &DocumentCollection, id: PipelineId, can_gc: CanGc) { +pub(crate) fn handle_reload(documents: &DocumentCollection, id: PipelineId, can_gc: CanGc) { if let Some(win) = documents.find_window(id) { win.Location().reload_without_origin_check(can_gc); } } -pub fn handle_get_css_database(reply: IpcSender>) { +pub(crate) fn handle_get_css_database(reply: IpcSender>) { let database: HashMap<_, _> = ENABLED_LONGHAND_PROPERTIES .iter() .map(|l| { diff --git a/components/script/document_collection.rs b/components/script/document_collection.rs index bcff897910e..66563b55513 100644 --- a/components/script/document_collection.rs +++ b/components/script/document_collection.rs @@ -24,33 +24,33 @@ pub(crate) struct DocumentCollection { } impl DocumentCollection { - pub fn insert(&mut self, pipeline_id: PipelineId, doc: &Document) { + pub(crate) fn insert(&mut self, pipeline_id: PipelineId, doc: &Document) { self.map.insert(pipeline_id, Dom::from_ref(doc)); } - pub fn remove(&mut self, pipeline_id: PipelineId) -> Option> { + pub(crate) fn remove(&mut self, pipeline_id: PipelineId) -> Option> { self.map .remove(&pipeline_id) .map(|ref doc| DomRoot::from_ref(&**doc)) } - pub fn find_document(&self, pipeline_id: PipelineId) -> Option> { + pub(crate) fn find_document(&self, pipeline_id: PipelineId) -> Option> { self.map .get(&pipeline_id) .map(|doc| DomRoot::from_ref(&**doc)) } - pub fn find_window(&self, pipeline_id: PipelineId) -> Option> { + pub(crate) fn find_window(&self, pipeline_id: PipelineId) -> Option> { self.find_document(pipeline_id) .map(|doc| DomRoot::from_ref(doc.window())) } - pub fn find_global(&self, pipeline_id: PipelineId) -> Option> { + pub(crate) fn find_global(&self, pipeline_id: PipelineId) -> Option> { self.find_window(pipeline_id) .map(|window| DomRoot::from_ref(window.upcast())) } - pub fn find_iframe( + pub(crate) fn find_iframe( &self, pipeline_id: PipelineId, browsing_context_id: BrowsingContextId, @@ -63,7 +63,7 @@ impl DocumentCollection { }) } - pub fn iter(&self) -> DocumentsIter<'_> { + pub(crate) fn iter(&self) -> DocumentsIter<'_> { DocumentsIter { iter: self.map.iter(), } @@ -101,7 +101,7 @@ impl Default for DocumentCollection { } #[allow(crown::unrooted_must_root)] -pub struct DocumentsIter<'a> { +pub(crate) struct DocumentsIter<'a> { iter: hash_map::Iter<'a, PipelineId, Dom>, } diff --git a/components/script/document_loader.rs b/components/script/document_loader.rs index 5d07cea0930..25624c62c1e 100644 --- a/components/script/document_loader.rs +++ b/components/script/document_loader.rs @@ -18,7 +18,7 @@ use crate::fetch::FetchCanceller; use crate::script_runtime::CanGc; #[derive(Clone, Debug, JSTraceable, MallocSizeOf, PartialEq)] -pub enum LoadType { +pub(crate) enum LoadType { Image(#[no_trace] ServoUrl), Script(#[no_trace] ServoUrl), Subframe(#[no_trace] ServoUrl), @@ -32,7 +32,7 @@ pub enum LoadType { /// that the owner is destroyed. #[derive(JSTraceable, MallocSizeOf)] #[crown::unrooted_must_root_lint::must_root] -pub struct LoadBlocker { +pub(crate) struct LoadBlocker { /// The document whose load event is blocked by this object existing. doc: Dom, /// The load that is blocking the document's load event. @@ -41,7 +41,7 @@ pub struct LoadBlocker { impl LoadBlocker { /// Mark the document's load event as blocked on this new load. - pub fn new(doc: &Document, load: LoadType) -> LoadBlocker { + pub(crate) fn new(doc: &Document, load: LoadType) -> LoadBlocker { doc.loader_mut().add_blocking_load(load.clone()); LoadBlocker { doc: Dom::from_ref(doc), @@ -50,7 +50,7 @@ impl LoadBlocker { } /// Remove this load from the associated document's list of blocking loads. - pub fn terminate(blocker: &DomRefCell>, can_gc: CanGc) { + pub(crate) fn terminate(blocker: &DomRefCell>, can_gc: CanGc) { if let Some(this) = blocker.borrow().as_ref() { let load_data = this.load.clone().unwrap(); this.doc.finish_load(load_data, can_gc); @@ -68,7 +68,7 @@ impl Drop for LoadBlocker { } #[derive(JSTraceable, MallocSizeOf)] -pub struct DocumentLoader { +pub(crate) struct DocumentLoader { #[no_trace] resource_threads: ResourceThreads, blocking_loads: Vec, @@ -77,11 +77,11 @@ pub struct DocumentLoader { } impl DocumentLoader { - pub fn new(existing: &DocumentLoader) -> DocumentLoader { + pub(crate) fn new(existing: &DocumentLoader) -> DocumentLoader { DocumentLoader::new_with_threads(existing.resource_threads.clone(), None) } - pub fn new_with_threads( + pub(crate) fn new_with_threads( resource_threads: ResourceThreads, initial_load: Option, ) -> DocumentLoader { @@ -96,7 +96,7 @@ impl DocumentLoader { } } - pub fn cancel_all_loads(&mut self) -> bool { + pub(crate) fn cancel_all_loads(&mut self) -> bool { let canceled_any = !self.cancellers.is_empty(); // Associated fetches will be canceled when dropping the canceller. self.cancellers.clear(); @@ -114,7 +114,7 @@ impl DocumentLoader { } /// Initiate a new fetch given a response callback. - pub fn fetch_async_with_callback( + pub(crate) fn fetch_async_with_callback( &mut self, load: LoadType, request: RequestBuilder, @@ -125,7 +125,7 @@ impl DocumentLoader { } /// Initiate a new fetch that does not block the document load event. - pub fn fetch_async_background( + pub(crate) fn fetch_async_background( &mut self, request: RequestBuilder, callback: BoxedFetchCallback, @@ -147,7 +147,7 @@ impl DocumentLoader { } /// Mark an in-progress network request complete. - pub fn finish_load(&mut self, load: &LoadType) { + pub(crate) fn finish_load(&mut self, load: &LoadType) { debug!( "Removing blocking load {:?} ({}).", load, @@ -165,26 +165,26 @@ impl DocumentLoader { } } - pub fn is_blocked(&self) -> bool { + pub(crate) fn is_blocked(&self) -> bool { // TODO: Ensure that we report blocked if parsing is still ongoing. !self.blocking_loads.is_empty() } - pub fn is_only_blocked_by_iframes(&self) -> bool { + pub(crate) fn is_only_blocked_by_iframes(&self) -> bool { self.blocking_loads .iter() .all(|load| matches!(*load, LoadType::Subframe(_))) } - pub fn inhibit_events(&mut self) { + pub(crate) fn inhibit_events(&mut self) { self.events_inhibited = true; } - pub fn events_inhibited(&self) -> bool { + pub(crate) fn events_inhibited(&self) -> bool { self.events_inhibited } - pub fn resource_threads(&self) -> &ResourceThreads { + pub(crate) fn resource_threads(&self) -> &ResourceThreads { &self.resource_threads } } diff --git a/components/script/dom/abortcontroller.rs b/components/script/dom/abortcontroller.rs index a7282ca7f4d..448e1654158 100644 --- a/components/script/dom/abortcontroller.rs +++ b/components/script/dom/abortcontroller.rs @@ -13,7 +13,7 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::{CanGc, JSContext}; #[dom_struct] -pub struct AbortController { +pub(crate) struct AbortController { reflector_: Reflector, } diff --git a/components/script/dom/abstractrange.rs b/components/script/dom/abstractrange.rs index c16a6434d5b..80cd64a0df5 100644 --- a/components/script/dom/abstractrange.rs +++ b/components/script/dom/abstractrange.rs @@ -17,14 +17,14 @@ use crate::dom::node::{Node, ShadowIncluding}; use crate::script_runtime::CanGc; #[dom_struct] -pub struct AbstractRange { +pub(crate) struct AbstractRange { reflector_: Reflector, start: BoundaryPoint, end: BoundaryPoint, } impl AbstractRange { - pub fn new_inherited( + pub(crate) fn new_inherited( start_container: &Node, start_offset: u32, end_container: &Node, @@ -37,7 +37,7 @@ impl AbstractRange { } } - pub fn new( + pub(crate) fn new( document: &Document, start_container: &Node, start_offset: u32, @@ -57,11 +57,11 @@ impl AbstractRange { abstractrange } - pub fn start(&self) -> &BoundaryPoint { + pub(crate) fn start(&self) -> &BoundaryPoint { &self.start } - pub fn end(&self) -> &BoundaryPoint { + pub(crate) fn end(&self) -> &BoundaryPoint { &self.end } } @@ -95,7 +95,7 @@ impl AbstractRangeMethods for AbstractRange { #[derive(DenyPublicFields, JSTraceable, MallocSizeOf)] #[crown::unrooted_must_root_lint::must_root] -pub struct BoundaryPoint { +pub(crate) struct BoundaryPoint { node: MutDom, offset: Cell, } @@ -109,16 +109,16 @@ impl BoundaryPoint { } } - pub fn set(&self, node: &Node, offset: u32) { + pub(crate) fn set(&self, node: &Node, offset: u32) { self.node.set(node); self.set_offset(offset); } - pub fn set_offset(&self, offset: u32) { + pub(crate) fn set_offset(&self, offset: u32) { self.offset.set(offset); } - pub fn node(&self) -> &MutDom { + pub(crate) fn node(&self) -> &MutDom { &self.node } } @@ -143,7 +143,12 @@ impl PartialEq for BoundaryPoint { } /// -pub fn bp_position(a_node: &Node, a_offset: u32, b_node: &Node, b_offset: u32) -> Option { +pub(crate) fn bp_position( + a_node: &Node, + a_offset: u32, + b_node: &Node, + b_offset: u32, +) -> Option { if std::ptr::eq(a_node, b_node) { // Step 1. return Some(a_offset.cmp(&b_offset)); diff --git a/components/script/dom/abstractworker.rs b/components/script/dom/abstractworker.rs index 3803089b0b3..887457e9a3b 100644 --- a/components/script/dom/abstractworker.rs +++ b/components/script/dom/abstractworker.rs @@ -10,7 +10,7 @@ use crate::dom::bindings::reflector::DomObject; use crate::messaging::CommonScriptMsg; /// Messages used to control the worker event loops -pub enum WorkerScriptMsg { +pub(crate) enum WorkerScriptMsg { /// Common variants associated with the script messages Common(CommonScriptMsg), /// Message sent through Worker.postMessage @@ -20,12 +20,12 @@ pub enum WorkerScriptMsg { }, } -pub struct SimpleWorkerErrorHandler { - pub addr: Trusted, +pub(crate) struct SimpleWorkerErrorHandler { + pub(crate) addr: Trusted, } impl SimpleWorkerErrorHandler { - pub fn new(addr: Trusted) -> SimpleWorkerErrorHandler { + pub(crate) fn new(addr: Trusted) -> SimpleWorkerErrorHandler { SimpleWorkerErrorHandler { addr } } } diff --git a/components/script/dom/abstractworkerglobalscope.rs b/components/script/dom/abstractworkerglobalscope.rs index 383df363ebf..c5c5f3b6b0e 100644 --- a/components/script/dom/abstractworkerglobalscope.rs +++ b/components/script/dom/abstractworkerglobalscope.rs @@ -15,7 +15,7 @@ use crate::realms::enter_realm; use crate::script_runtime::CanGc; use crate::task_queue::{QueuedTaskConversion, TaskQueue}; -pub trait WorkerEventLoopMethods { +pub(crate) trait WorkerEventLoopMethods { type WorkerMsg: QueuedTaskConversion + Send; type ControlMsg; type Event; @@ -30,7 +30,7 @@ pub trait WorkerEventLoopMethods { } // https://html.spec.whatwg.org/multipage/#worker-event-loop -pub fn run_worker_event_loop( +pub(crate) fn run_worker_event_loop( worker_scope: &T, worker: Option<&TrustedWorkerAddress>, can_gc: CanGc, diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs index 2d78f505214..25f67397cc9 100644 --- a/components/script/dom/activation.rs +++ b/components/script/dom/activation.rs @@ -9,7 +9,7 @@ use crate::dom::htmlinputelement::InputActivationState; use crate::script_runtime::CanGc; /// Trait for elements with defined activation behavior -pub trait Activatable { +pub(crate) trait Activatable { fn as_element(&self) -> ∈ // Is this particular instance of the element activatable? diff --git a/components/script/dom/analysernode.rs b/components/script/dom/analysernode.rs index 9b8d6457959..6d447e0a9f6 100644 --- a/components/script/dom/analysernode.rs +++ b/components/script/dom/analysernode.rs @@ -29,7 +29,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct AnalyserNode { +pub(crate) struct AnalyserNode { node: AudioNode, #[ignore_malloc_size_of = "Defined in servo-media"] #[no_trace] @@ -38,7 +38,7 @@ pub struct AnalyserNode { impl AnalyserNode { #[allow(crown::unrooted_must_root)] - pub fn new_inherited( + pub(crate) fn new_inherited( _: &Window, context: &BaseAudioContext, options: &AnalyserOptions, @@ -91,7 +91,7 @@ impl AnalyserNode { )) } - pub fn new( + pub(crate) fn new( window: &Window, context: &BaseAudioContext, options: &AnalyserOptions, @@ -101,7 +101,7 @@ impl AnalyserNode { } #[allow(crown::unrooted_must_root)] - pub fn new_with_proto( + pub(crate) fn new_with_proto( window: &Window, proto: Option, context: &BaseAudioContext, @@ -130,7 +130,7 @@ impl AnalyserNode { Ok(object) } - pub fn push_block(&self, block: Block) { + pub(crate) fn push_block(&self, block: Block) { self.engine.borrow_mut().push(block) } } diff --git a/components/script/dom/animationevent.rs b/components/script/dom/animationevent.rs index 673db954bb0..10902a9e012 100644 --- a/components/script/dom/animationevent.rs +++ b/components/script/dom/animationevent.rs @@ -20,7 +20,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct AnimationEvent { +pub(crate) struct AnimationEvent { event: Event, #[no_trace] animation_name: Atom, @@ -38,7 +38,7 @@ impl AnimationEvent { } } - pub fn new( + pub(crate) fn new( window: &Window, type_: Atom, init: &AnimationEventInit, diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 701175b0fac..63c1e635dad 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -28,7 +28,7 @@ use crate::script_thread::ScriptThread; // https://dom.spec.whatwg.org/#interface-attr #[dom_struct] -pub struct Attr { +pub(crate) struct Attr { node_: Node, #[no_trace] identifier: AttrIdentifier, @@ -62,7 +62,7 @@ impl Attr { } } #[allow(clippy::too_many_arguments)] - pub fn new( + pub(crate) fn new( document: &Document, local_name: LocalName, value: AttrValue, @@ -82,17 +82,17 @@ impl Attr { } #[inline] - pub fn name(&self) -> &LocalName { + pub(crate) fn name(&self) -> &LocalName { &self.identifier.name.0 } #[inline] - pub fn namespace(&self) -> &Namespace { + pub(crate) fn namespace(&self) -> &Namespace { &self.identifier.namespace.0 } #[inline] - pub fn prefix(&self) -> Option<&Prefix> { + pub(crate) fn prefix(&self) -> Option<&Prefix> { Some(&self.identifier.prefix.as_ref()?.0) } } @@ -152,7 +152,7 @@ impl AttrMethods for Attr { } impl Attr { - pub fn set_value(&self, mut value: AttrValue, owner: &Element) { + pub(crate) fn set_value(&self, mut value: AttrValue, owner: &Element) { let name = self.local_name().clone(); let namespace = self.namespace().clone(); let old_value = DOMString::from(&**self.value()); @@ -185,25 +185,25 @@ impl Attr { } /// Used to swap the attribute's value without triggering mutation events - pub fn swap_value(&self, value: &mut AttrValue) { + pub(crate) fn swap_value(&self, value: &mut AttrValue) { mem::swap(&mut *self.value.borrow_mut(), value); } - pub fn identifier(&self) -> &AttrIdentifier { + pub(crate) fn identifier(&self) -> &AttrIdentifier { &self.identifier } - pub fn value(&self) -> Ref { + pub(crate) fn value(&self) -> Ref { self.value.borrow() } - pub fn local_name(&self) -> &LocalName { + pub(crate) fn local_name(&self) -> &LocalName { &self.identifier.local_name } /// Sets the owner element. Should be called after the attribute is added /// or removed from its older parent. - pub fn set_owner(&self, owner: Option<&Element>) { + pub(crate) fn set_owner(&self, owner: Option<&Element>) { let ns = self.namespace(); match (self.owner(), owner) { (Some(old), None) => { @@ -220,11 +220,11 @@ impl Attr { self.owner.set(owner); } - pub fn owner(&self) -> Option> { + pub(crate) fn owner(&self) -> Option> { self.owner.get() } - pub fn summarize(&self) -> AttrInfo { + pub(crate) fn summarize(&self) -> AttrInfo { AttrInfo { namespace: (**self.namespace()).to_owned(), name: String::from(self.Name()), @@ -232,7 +232,7 @@ impl Attr { } } - pub fn qualified_name(&self) -> DOMString { + pub(crate) fn qualified_name(&self) -> DOMString { match self.prefix() { Some(ref prefix) => DOMString::from(format!("{}:{}", prefix, &**self.local_name())), None => DOMString::from(&**self.local_name()), @@ -241,7 +241,7 @@ impl Attr { } #[allow(unsafe_code)] -pub trait AttrHelpersForLayout<'dom> { +pub(crate) trait AttrHelpersForLayout<'dom> { fn value(self) -> &'dom AttrValue; fn as_str(&self) -> &'dom str; fn to_tokens(self) -> Option<&'dom [Atom]>; diff --git a/components/script/dom/audiobuffer.rs b/components/script/dom/audiobuffer.rs index 5fc2acdbf4d..1fbdc771f2e 100644 --- a/components/script/dom/audiobuffer.rs +++ b/components/script/dom/audiobuffer.rs @@ -26,8 +26,8 @@ use crate::script_runtime::{CanGc, JSContext}; // Spec mandates at least [8000, 96000], we use [8000, 192000] to match Firefox // https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer -pub const MIN_SAMPLE_RATE: f32 = 8000.; -pub const MAX_SAMPLE_RATE: f32 = 192000.; +pub(crate) const MIN_SAMPLE_RATE: f32 = 8000.; +pub(crate) const MAX_SAMPLE_RATE: f32 = 192000.; /// The AudioBuffer keeps its data either in js_channels /// or in shared_channels if js_channels buffers are detached. @@ -38,7 +38,7 @@ pub const MAX_SAMPLE_RATE: f32 = 192000.; /// to know in which situations js_channels buffers must be detached. /// #[dom_struct] -pub struct AudioBuffer { +pub(crate) struct AudioBuffer { reflector_: Reflector, /// Float32Arrays returned by calls to GetChannelData. #[ignore_malloc_size_of = "mozjs"] @@ -60,7 +60,11 @@ pub struct AudioBuffer { impl AudioBuffer { #[allow(crown::unrooted_must_root)] - pub fn new_inherited(number_of_channels: u32, length: u32, sample_rate: f32) -> AudioBuffer { + pub(crate) fn new_inherited( + number_of_channels: u32, + length: u32, + sample_rate: f32, + ) -> AudioBuffer { let vec = (0..number_of_channels) .map(|_| HeapBufferSource::default()) .collect(); @@ -75,7 +79,7 @@ impl AudioBuffer { } } - pub fn new( + pub(crate) fn new( global: &Window, number_of_channels: u32, length: u32, @@ -172,7 +176,7 @@ impl AudioBuffer { Some(result) } - pub fn get_channels(&self) -> Ref> { + pub(crate) fn get_channels(&self) -> Ref> { if self.shared_channels.borrow().is_none() { let channels = self.acquire_contents(); if channels.is_some() { diff --git a/components/script/dom/audiobuffersourcenode.rs b/components/script/dom/audiobuffersourcenode.rs index 3f559457b7c..72b857a727f 100644 --- a/components/script/dom/audiobuffersourcenode.rs +++ b/components/script/dom/audiobuffersourcenode.rs @@ -31,7 +31,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct AudioBufferSourceNode { +pub(crate) struct AudioBufferSourceNode { source_node: AudioScheduledSourceNode, buffer: MutNullableDom, buffer_set: Cell, @@ -96,7 +96,7 @@ impl AudioBufferSourceNode { Ok(node) } - pub fn new( + pub(crate) fn new( window: &Window, context: &BaseAudioContext, options: &AudioBufferSourceOptions, diff --git a/components/script/dom/audiocontext.rs b/components/script/dom/audiocontext.rs index 247a88a31b9..20987944d8e 100644 --- a/components/script/dom/audiocontext.rs +++ b/components/script/dom/audiocontext.rs @@ -37,7 +37,7 @@ use crate::realms::InRealm; use crate::script_runtime::CanGc; #[dom_struct] -pub struct AudioContext { +pub(crate) struct AudioContext { context: BaseAudioContext, latency_hint: AudioContextLatencyCategory, /// @@ -104,7 +104,7 @@ impl AudioContext { } } - pub fn base(&self) -> DomRoot { + pub(crate) fn base(&self) -> DomRoot { DomRoot::from_ref(&self.context) } } diff --git a/components/script/dom/audiodestinationnode.rs b/components/script/dom/audiodestinationnode.rs index 34f29a8fec3..908303085a5 100644 --- a/components/script/dom/audiodestinationnode.rs +++ b/components/script/dom/audiodestinationnode.rs @@ -16,7 +16,7 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::CanGc; #[dom_struct] -pub struct AudioDestinationNode { +pub(crate) struct AudioDestinationNode { node: AudioNode, } @@ -39,7 +39,7 @@ impl AudioDestinationNode { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( global: &GlobalScope, context: &BaseAudioContext, options: &AudioNodeOptions, diff --git a/components/script/dom/audiolistener.rs b/components/script/dom/audiolistener.rs index 27382b80757..2baf410d6c0 100644 --- a/components/script/dom/audiolistener.rs +++ b/components/script/dom/audiolistener.rs @@ -22,7 +22,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct AudioListener { +pub(crate) struct AudioListener { reflector_: Reflector, position_x: Dom, position_y: Dom, @@ -154,7 +154,7 @@ impl AudioListener { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, context: &BaseAudioContext, can_gc: CanGc, diff --git a/components/script/dom/audionode.rs b/components/script/dom/audionode.rs index 65823798e5d..7a4d13c04d6 100644 --- a/components/script/dom/audionode.rs +++ b/components/script/dom/audionode.rs @@ -28,10 +28,10 @@ use crate::dom::eventtarget::EventTarget; // 32 is the minimum required by the spec for createBuffer() and the deprecated // createScriptProcessor() and matches what is used by Blink and Gecko. // The limit protects against large memory allocations. -pub const MAX_CHANNEL_COUNT: u32 = 32; +pub(crate) const MAX_CHANNEL_COUNT: u32 = 32; #[dom_struct] -pub struct AudioNode { +pub(crate) struct AudioNode { eventtarget: EventTarget, #[ignore_malloc_size_of = "servo_media"] #[no_trace] @@ -45,7 +45,7 @@ pub struct AudioNode { } impl AudioNode { - pub fn new_inherited( + pub(crate) fn new_inherited( node_type: AudioNodeInit, context: &BaseAudioContext, options: UnwrappedAudioNodeOptions, @@ -75,7 +75,7 @@ impl AudioNode { )) } - pub fn new_inherited_for_id( + pub(crate) fn new_inherited_for_id( node_id: NodeId, context: &BaseAudioContext, options: UnwrappedAudioNodeOptions, @@ -94,7 +94,7 @@ impl AudioNode { } } - pub fn message(&self, message: AudioNodeMessage) { + pub(crate) fn message(&self, message: AudioNodeMessage) { self.context .audio_context_impl() .lock() @@ -102,7 +102,7 @@ impl AudioNode { .message_node(self.node_id, message); } - pub fn node_id(&self) -> NodeId { + pub(crate) fn node_id(&self) -> NodeId { self.node_id } } @@ -388,7 +388,7 @@ impl Convert for ChannelInterpretation { } impl AudioNodeOptions { - pub fn unwrap_or( + pub(crate) fn unwrap_or( &self, count: u32, mode: ChannelCountMode, @@ -404,10 +404,10 @@ impl AudioNodeOptions { /// Each node has a set of defaults, so this lets us work with them /// easily without having to deal with the Options -pub struct UnwrappedAudioNodeOptions { - pub count: u32, - pub mode: ChannelCountMode, - pub interpretation: ChannelInterpretation, +pub(crate) struct UnwrappedAudioNodeOptions { + pub(crate) count: u32, + pub(crate) mode: ChannelCountMode, + pub(crate) interpretation: ChannelInterpretation, } impl Default for UnwrappedAudioNodeOptions { diff --git a/components/script/dom/audioparam.rs b/components/script/dom/audioparam.rs index 44925883b20..3b3b65d55ee 100644 --- a/components/script/dom/audioparam.rs +++ b/components/script/dom/audioparam.rs @@ -23,7 +23,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct AudioParam { +pub(crate) struct AudioParam { reflector_: Reflector, context: Dom, #[ignore_malloc_size_of = "servo_media"] @@ -43,7 +43,7 @@ pub struct AudioParam { impl AudioParam { #[allow(clippy::too_many_arguments)] - pub fn new_inherited( + pub(crate) fn new_inherited( context: &BaseAudioContext, node: NodeId, node_type: AudioNodeType, @@ -67,7 +67,7 @@ impl AudioParam { } #[allow(crown::unrooted_must_root, clippy::too_many_arguments)] - pub fn new( + pub(crate) fn new( window: &Window, context: &BaseAudioContext, node: NodeId, @@ -99,15 +99,15 @@ impl AudioParam { .message_node(self.node, message); } - pub fn context(&self) -> &BaseAudioContext { + pub(crate) fn context(&self) -> &BaseAudioContext { &self.context } - pub fn node_id(&self) -> NodeId { + pub(crate) fn node_id(&self) -> NodeId { self.node } - pub fn param_type(&self) -> ParamType { + pub(crate) fn param_type(&self) -> ParamType { self.param } } diff --git a/components/script/dom/audioscheduledsourcenode.rs b/components/script/dom/audioscheduledsourcenode.rs index 24f76b274ad..d29c188c476 100644 --- a/components/script/dom/audioscheduledsourcenode.rs +++ b/components/script/dom/audioscheduledsourcenode.rs @@ -19,7 +19,7 @@ use crate::dom::bindings::refcounted::Trusted; use crate::dom::bindings::reflector::DomObject; #[dom_struct] -pub struct AudioScheduledSourceNode { +pub(crate) struct AudioScheduledSourceNode { node: AudioNode, has_start: Cell, has_stop: Cell, @@ -27,7 +27,7 @@ pub struct AudioScheduledSourceNode { impl AudioScheduledSourceNode { #[allow(crown::unrooted_must_root)] - pub fn new_inherited( + pub(crate) fn new_inherited( node_type: AudioNodeInit, context: &BaseAudioContext, options: UnwrappedAudioNodeOptions, @@ -47,11 +47,11 @@ impl AudioScheduledSourceNode { }) } - pub fn node(&self) -> &AudioNode { + pub(crate) fn node(&self) -> &AudioNode { &self.node } - pub fn has_start(&self) -> bool { + pub(crate) fn has_start(&self) -> bool { self.has_start.get() } } diff --git a/components/script/dom/audiotrack.rs b/components/script/dom/audiotrack.rs index 56a2fc15251..1b3960c444f 100644 --- a/components/script/dom/audiotrack.rs +++ b/components/script/dom/audiotrack.rs @@ -16,7 +16,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct AudioTrack { +pub(crate) struct AudioTrack { reflector_: Reflector, id: DOMString, kind: DOMString, @@ -27,7 +27,7 @@ pub struct AudioTrack { } impl AudioTrack { - pub fn new_inherited( + pub(crate) fn new_inherited( id: DOMString, kind: DOMString, label: DOMString, @@ -45,7 +45,7 @@ impl AudioTrack { } } - pub fn new( + pub(crate) fn new( window: &Window, id: DOMString, kind: DOMString, @@ -62,27 +62,27 @@ impl AudioTrack { ) } - pub fn id(&self) -> DOMString { + pub(crate) fn id(&self) -> DOMString { self.id.clone() } - pub fn kind(&self) -> DOMString { + pub(crate) fn kind(&self) -> DOMString { self.kind.clone() } - pub fn enabled(&self) -> bool { + pub(crate) fn enabled(&self) -> bool { self.enabled.get() } - pub fn set_enabled(&self, value: bool) { + pub(crate) fn set_enabled(&self, value: bool) { self.enabled.set(value); } - pub fn add_track_list(&self, track_list: &AudioTrackList) { + pub(crate) fn add_track_list(&self, track_list: &AudioTrackList) { *self.track_list.borrow_mut() = Some(Dom::from_ref(track_list)); } - pub fn remove_track_list(&self) { + pub(crate) fn remove_track_list(&self) { *self.track_list.borrow_mut() = None; } } diff --git a/components/script/dom/audiotracklist.rs b/components/script/dom/audiotracklist.rs index 405c687fb2a..a34efd60cf2 100644 --- a/components/script/dom/audiotracklist.rs +++ b/components/script/dom/audiotracklist.rs @@ -18,14 +18,14 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct AudioTrackList { +pub(crate) struct AudioTrackList { eventtarget: EventTarget, tracks: DomRefCell>>, media_element: Option>, } impl AudioTrackList { - pub fn new_inherited( + pub(crate) fn new_inherited( tracks: &[&AudioTrack], media_element: Option<&HTMLMediaElement>, ) -> AudioTrackList { @@ -36,7 +36,7 @@ impl AudioTrackList { } } - pub fn new( + pub(crate) fn new( window: &Window, tracks: &[&AudioTrack], media_element: Option<&HTMLMediaElement>, @@ -48,29 +48,29 @@ impl AudioTrackList { ) } - pub fn len(&self) -> usize { + pub(crate) fn len(&self) -> usize { self.tracks.borrow().len() } - pub fn find(&self, track: &AudioTrack) -> Option { + pub(crate) fn find(&self, track: &AudioTrack) -> Option { self.tracks.borrow().iter().position(|t| &**t == track) } - pub fn item(&self, idx: usize) -> Option> { + pub(crate) fn item(&self, idx: usize) -> Option> { self.tracks .borrow() .get(idx) .map(|track| DomRoot::from_ref(&**track)) } - pub fn enabled_index(&self) -> Option { + pub(crate) fn enabled_index(&self) -> Option { self.tracks .borrow() .iter() .position(|track| track.enabled()) } - pub fn set_enabled(&self, idx: usize, value: bool) { + pub(crate) fn set_enabled(&self, idx: usize, value: bool) { let track = match self.item(idx) { Some(t) => t, None => return, @@ -96,12 +96,12 @@ impl AudioTrackList { })); } - pub fn add(&self, track: &AudioTrack) { + pub(crate) fn add(&self, track: &AudioTrack) { self.tracks.borrow_mut().push(Dom::from_ref(track)); track.add_track_list(self); } - pub fn clear(&self) { + pub(crate) fn clear(&self) { self.tracks .borrow() .iter() diff --git a/components/script/dom/baseaudiocontext.rs b/components/script/dom/baseaudiocontext.rs index 16d975134fb..3c9e36a4ec3 100644 --- a/components/script/dom/baseaudiocontext.rs +++ b/components/script/dom/baseaudiocontext.rs @@ -69,22 +69,22 @@ use crate::realms::InRealm; use crate::script_runtime::CanGc; #[allow(dead_code)] -pub enum BaseAudioContextOptions { +pub(crate) enum BaseAudioContextOptions { AudioContext(RealTimeAudioContextOptions), OfflineAudioContext(OfflineAudioContextOptions), } #[derive(JSTraceable)] struct DecodeResolver { - pub promise: Rc, - pub success_callback: Option>, - pub error_callback: Option>, + pub(crate) promise: Rc, + pub(crate) success_callback: Option>, + pub(crate) error_callback: Option>, } type BoxedSliceOfPromises = Box<[Rc]>; #[dom_struct] -pub struct BaseAudioContext { +pub(crate) struct BaseAudioContext { eventtarget: EventTarget, #[ignore_malloc_size_of = "servo_media"] #[no_trace] @@ -113,7 +113,7 @@ pub struct BaseAudioContext { impl BaseAudioContext { #[allow(crown::unrooted_must_root)] - pub fn new_inherited( + pub(crate) fn new_inherited( options: BaseAudioContextOptions, pipeline_id: PipelineId, ) -> Fallible { @@ -146,24 +146,24 @@ impl BaseAudioContext { } /// Tells whether this is an OfflineAudioContext or not. - pub fn is_offline(&self) -> bool { + pub(crate) fn is_offline(&self) -> bool { false } - pub fn audio_context_impl(&self) -> Arc> { + pub(crate) fn audio_context_impl(&self) -> Arc> { self.audio_context_impl.clone() } - pub fn destination_node(&self) -> NodeId { + pub(crate) fn destination_node(&self) -> NodeId { self.audio_context_impl.lock().unwrap().dest_node() } - pub fn listener(&self) -> NodeId { + pub(crate) fn listener(&self) -> NodeId { self.audio_context_impl.lock().unwrap().listener() } // https://webaudio.github.io/web-audio-api/#allowed-to-start - pub fn is_allowed_to_start(&self) -> bool { + pub(crate) fn is_allowed_to_start(&self) -> bool { self.state.get() == AudioContextState::Suspended } @@ -219,16 +219,16 @@ impl BaseAudioContext { } /// Control thread processing state - pub fn control_thread_state(&self) -> ProcessingState { + pub(crate) fn control_thread_state(&self) -> ProcessingState { self.audio_context_impl.lock().unwrap().state() } /// Set audio context state - pub fn set_state_attribute(&self, state: AudioContextState) { + pub(crate) fn set_state_attribute(&self, state: AudioContextState) { self.state.set(state); } - pub fn resume(&self) { + pub(crate) fn resume(&self) { let this = Trusted::new(self); // Set the rendering thread state to 'running' and start // rendering the audio graph. @@ -264,7 +264,7 @@ impl BaseAudioContext { } } - pub fn channel_count(&self) -> u32 { + pub(crate) fn channel_count(&self) -> u32 { self.channel_count } } diff --git a/components/script/dom/beforeunloadevent.rs b/components/script/dom/beforeunloadevent.rs index 7e020752a23..de4bd8703b3 100644 --- a/components/script/dom/beforeunloadevent.rs +++ b/components/script/dom/beforeunloadevent.rs @@ -20,7 +20,7 @@ use crate::script_runtime::CanGc; // https://html.spec.whatwg.org/multipage/#beforeunloadevent #[dom_struct] -pub struct BeforeUnloadEvent { +pub(crate) struct BeforeUnloadEvent { event: Event, return_value: DomRefCell, } @@ -33,7 +33,7 @@ impl BeforeUnloadEvent { } } - pub fn new_uninitialized(window: &Window) -> DomRoot { + pub(crate) fn new_uninitialized(window: &Window) -> DomRoot { reflect_dom_object( Box::new(BeforeUnloadEvent::new_inherited()), window, @@ -41,7 +41,7 @@ impl BeforeUnloadEvent { ) } - pub fn new( + pub(crate) fn new( window: &Window, type_: Atom, bubbles: EventBubbles, diff --git a/components/script/dom/bindings/buffer_source.rs b/components/script/dom/bindings/buffer_source.rs index 5af00da3a45..3e095a1e617 100644 --- a/components/script/dom/bindings/buffer_source.rs +++ b/components/script/dom/bindings/buffer_source.rs @@ -25,7 +25,7 @@ use crate::script_runtime::JSContext; /// #[allow(dead_code)] -pub enum BufferSource { +pub(crate) enum BufferSource { Int8Array(Box>), Int16Array(Box>), Int32Array(Box>), @@ -42,7 +42,7 @@ pub enum BufferSource { Default(Box>), } -pub struct HeapBufferSource { +pub(crate) struct HeapBufferSource { buffer_source: BufferSource, phantom: PhantomData, } @@ -71,7 +71,7 @@ unsafe impl crate::dom::bindings::trace::JSTraceable for HeapBufferSource } } -pub fn new_initialized_heap_buffer_source( +pub(crate) fn new_initialized_heap_buffer_source( init: HeapTypedArrayInit, ) -> Result, ()> where @@ -116,7 +116,7 @@ where Ok(heap_buffer_source) } -pub enum HeapTypedArrayInit { +pub(crate) enum HeapTypedArrayInit { Buffer(BufferSource), Info { len: u32, cx: JSContext }, } @@ -126,14 +126,14 @@ where T: TypedArrayElement + TypedArrayElementCreator, T::Element: Clone + Copy, { - pub fn default() -> HeapBufferSource { + pub(crate) fn default() -> HeapBufferSource { HeapBufferSource { buffer_source: BufferSource::Default(Box::default()), phantom: PhantomData, } } - pub fn set_data(&self, cx: JSContext, data: &[T::Element]) -> Result<(), ()> { + pub(crate) fn set_data(&self, cx: JSContext, data: &[T::Element]) -> Result<(), ()> { rooted!(in (*cx) let mut array = ptr::null_mut::()); let _: TypedArray = create_buffer_source(cx, data, array.handle_mut())?; @@ -158,7 +158,7 @@ where Ok(()) } - pub fn acquire_data(&self, cx: JSContext) -> Result, ()> { + pub(crate) fn acquire_data(&self, cx: JSContext) -> Result, ()> { assert!(self.is_initialized()); typedarray!(in(*cx) let array: TypedArray = match &self.buffer_source { @@ -211,7 +211,7 @@ where } /// - pub fn detach_buffer(&self, cx: JSContext) -> bool { + pub(crate) fn detach_buffer(&self, cx: JSContext) -> bool { match &self.buffer_source { BufferSource::Int8Array(buffer) | BufferSource::Int16Array(buffer) | @@ -247,7 +247,7 @@ where } } - pub fn copy_data_to( + pub(crate) fn copy_data_to( &self, cx: JSContext, dest: &mut [T::Element], @@ -285,7 +285,7 @@ where Ok(()) } - pub fn copy_data_from( + pub(crate) fn copy_data_from( &self, cx: JSContext, source: CustomAutoRooterGuard>, @@ -324,7 +324,7 @@ where Ok(()) } - pub fn is_initialized(&self) -> bool { + pub(crate) fn is_initialized(&self) -> bool { match &self.buffer_source { BufferSource::Int8Array(buffer) | BufferSource::Int16Array(buffer) | @@ -343,7 +343,7 @@ where } } - pub fn get_buffer(&self) -> Result, ()> { + pub(crate) fn get_buffer(&self) -> Result, ()> { TypedArray::from(match &self.buffer_source { BufferSource::Int8Array(buffer) | BufferSource::Int16Array(buffer) | @@ -362,7 +362,7 @@ where }) } - pub fn buffer_to_option(&self) -> Option> { + pub(crate) fn buffer_to_option(&self) -> Option> { if self.is_initialized() { Some(self.get_buffer().expect("Failed to get buffer.")) } else { @@ -373,7 +373,7 @@ where } /// -pub fn create_buffer_source( +pub(crate) fn create_buffer_source( cx: JSContext, data: &[T::Element], dest: MutableHandleObject, @@ -408,7 +408,7 @@ where } #[derive(JSTraceable, MallocSizeOf)] -pub struct DataBlock { +pub(crate) struct DataBlock { #[ignore_malloc_size_of = "Arc"] data: Arc>, /// Data views (mutable subslices of data) @@ -422,7 +422,7 @@ fn range_overlap(range1: &Range, range2: &Range) } impl DataBlock { - pub fn new_zeroed(size: usize) -> Self { + pub(crate) fn new_zeroed(size: usize) -> Self { let data = vec![0; size]; Self { data: Arc::new(data.into_boxed_slice()), @@ -431,23 +431,23 @@ impl DataBlock { } /// Panics if there is any active view or src data is not same length - pub fn load(&mut self, src: &[u8]) { + pub(crate) fn load(&mut self, src: &[u8]) { // `Arc::get_mut` ensures there are no views Arc::get_mut(&mut self.data).unwrap().clone_from_slice(src) } /// Panics if there is any active view - pub fn data(&mut self) -> &mut [u8] { + pub(crate) fn data(&mut self) -> &mut [u8] { // `Arc::get_mut` ensures there are no views Arc::get_mut(&mut self.data).unwrap() } - pub fn clear_views(&mut self) { + pub(crate) fn clear_views(&mut self) { self.data_views.clear() } /// Returns error if requested range is already mapped - pub fn view(&mut self, range: Range) -> Result<&DataView, ()> { + pub(crate) fn view(&mut self, range: Range) -> Result<&DataView, ()> { if self .data_views .iter() @@ -485,7 +485,7 @@ impl DataBlock { } #[derive(JSTraceable, MallocSizeOf)] -pub struct DataView { +pub(crate) struct DataView { #[no_trace] range: Range, #[ignore_malloc_size_of = "defined in mozjs"] @@ -493,7 +493,7 @@ pub struct DataView { } impl DataView { - pub fn array_buffer(&self) -> ArrayBuffer { + pub(crate) fn array_buffer(&self) -> ArrayBuffer { unsafe { ArrayBuffer::from(self.buffer.underlying_object().get()).unwrap() } } } diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index b59db051de5..22aa6ea3e9c 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -31,7 +31,7 @@ use crate::script_runtime::{CanGc, JSContext}; /// The exception handling used for a call. #[derive(Clone, Copy, PartialEq)] -pub enum ExceptionHandling { +pub(crate) enum ExceptionHandling { /// Report any exception and don't throw it to the caller code. Report, /// Throw any exception to the caller code. @@ -42,7 +42,7 @@ pub enum ExceptionHandling { /// callback interface types. #[derive(JSTraceable)] #[crown::unrooted_must_root_lint::must_root] -pub struct CallbackObject { +pub(crate) struct CallbackObject { /// The underlying `JSObject`. callback: Heap<*mut JSObject>, permanent_js_root: Heap, @@ -73,7 +73,7 @@ impl CallbackObject { } } - pub fn get(&self) -> *mut JSObject { + pub(crate) fn get(&self) -> *mut JSObject { self.callback.get() } @@ -108,7 +108,7 @@ impl PartialEq for CallbackObject { /// A trait to be implemented by concrete IDL callback function and /// callback interface types. -pub trait CallbackContainer { +pub(crate) trait CallbackContainer { /// Create a new CallbackContainer object for the given `JSObject`. unsafe fn new(cx: JSContext, callback: *mut JSObject) -> Rc; /// Returns the underlying `CallbackObject`. @@ -129,7 +129,7 @@ pub trait CallbackContainer { /// A common base class for representing IDL callback function types. #[derive(JSTraceable, PartialEq)] #[crown::unrooted_must_root_lint::must_root] -pub struct CallbackFunction { +pub(crate) struct CallbackFunction { object: CallbackObject, } @@ -138,20 +138,20 @@ impl CallbackFunction { #[allow(crown::unrooted_must_root)] // These are used by the bindings and do not need `default()` functions. #[allow(clippy::new_without_default)] - pub fn new() -> CallbackFunction { + pub(crate) fn new() -> CallbackFunction { CallbackFunction { object: CallbackObject::new(), } } /// Returns the underlying `CallbackObject`. - pub fn callback_holder(&self) -> &CallbackObject { + pub(crate) fn callback_holder(&self) -> &CallbackObject { &self.object } /// Initialize the callback function with a value. /// Should be called once this object is done moving. - pub unsafe fn init(&mut self, cx: JSContext, callback: *mut JSObject) { + pub(crate) unsafe fn init(&mut self, cx: JSContext, callback: *mut JSObject) { self.object.init(cx, callback); } } @@ -159,7 +159,7 @@ impl CallbackFunction { /// A common base class for representing IDL callback interface types. #[derive(JSTraceable, PartialEq)] #[crown::unrooted_must_root_lint::must_root] -pub struct CallbackInterface { +pub(crate) struct CallbackInterface { object: CallbackObject, } @@ -167,26 +167,26 @@ impl CallbackInterface { /// Create a new CallbackInterface object for the given `JSObject`. // These are used by the bindings and do not need `default()` functions. #[allow(clippy::new_without_default)] - pub fn new() -> CallbackInterface { + pub(crate) fn new() -> CallbackInterface { CallbackInterface { object: CallbackObject::new(), } } /// Returns the underlying `CallbackObject`. - pub fn callback_holder(&self) -> &CallbackObject { + pub(crate) fn callback_holder(&self) -> &CallbackObject { &self.object } /// Initialize the callback function with a value. /// Should be called once this object is done moving. - pub unsafe fn init(&mut self, cx: JSContext, callback: *mut JSObject) { + pub(crate) unsafe fn init(&mut self, cx: JSContext, callback: *mut JSObject) { self.object.init(cx, callback); } /// Returns the property with the given `name`, if it is a callable object, /// or an error otherwise. - pub fn get_callable_property(&self, cx: JSContext, name: &str) -> Fallible { + pub(crate) fn get_callable_property(&self, cx: JSContext, name: &str) -> Fallible { rooted!(in(*cx) let mut callable = UndefinedValue()); rooted!(in(*cx) let obj = self.callback_holder().get()); unsafe { @@ -206,7 +206,7 @@ impl CallbackInterface { } } -pub trait ThisReflector { +pub(crate) trait ThisReflector { fn jsobject(&self) -> *mut JSObject; } @@ -223,7 +223,7 @@ impl ThisReflector for HandleObject<'_> { } /// Wraps the reflector for `p` into the realm of `cx`. -pub fn wrap_call_this_object( +pub(crate) fn wrap_call_this_object( cx: JSContext, p: &T, mut rval: MutableHandleObject, @@ -240,7 +240,7 @@ pub fn wrap_call_this_object( /// A class that performs whatever setup we need to safely make a call while /// this class is on the stack. After `new` returns, the call is safe to make. -pub struct CallSetup { +pub(crate) struct CallSetup { /// The global for reporting exceptions. This is the global object of the /// (possibly wrapped) callback object. exception_global: DomRoot, @@ -261,7 +261,10 @@ pub struct CallSetup { impl CallSetup { /// Performs the setup needed to make a call. #[allow(crown::unrooted_must_root)] - pub fn new(callback: &T, handling: ExceptionHandling) -> CallSetup { + pub(crate) fn new( + callback: &T, + handling: ExceptionHandling, + ) -> CallSetup { let global = unsafe { GlobalScope::from_object(callback.callback()) }; if let Some(window) = global.downcast::() { window.Document().ensure_safe_to_run_script_or_layout(); @@ -281,7 +284,7 @@ impl CallSetup { } /// Returns the `JSContext` used for the call. - pub fn get_context(&self) -> JSContext { + pub(crate) fn get_context(&self) -> JSContext { self.cx } } diff --git a/components/script/dom/bindings/cell.rs b/components/script/dom/bindings/cell.rs index 60f3225eee3..df0ca84b060 100644 --- a/components/script/dom/bindings/cell.rs +++ b/components/script/dom/bindings/cell.rs @@ -6,12 +6,12 @@ use std::cell::{BorrowError, BorrowMutError}; #[cfg(not(feature = "refcell_backtrace"))] -pub use std::cell::{Ref, RefCell, RefMut}; +pub(crate) use std::cell::{Ref, RefCell, RefMut}; #[cfg(feature = "refcell_backtrace")] -pub use accountable_refcell::{ref_filter_map, Ref, RefCell, RefMut}; +pub(crate) use accountable_refcell::{ref_filter_map, Ref, RefCell, RefMut}; #[cfg(not(feature = "refcell_backtrace"))] -pub use ref_filter_map::ref_filter_map; +pub(crate) use ref_filter_map::ref_filter_map; use crate::dom::bindings::root::{assert_in_layout, assert_in_script}; @@ -20,7 +20,7 @@ use crate::dom::bindings::root::{assert_in_layout, assert_in_script}; /// This extends the API of `std::cell::RefCell` to allow unsafe access in /// certain situations, with dynamic checking in debug builds. #[derive(Clone, Debug, Default, MallocSizeOf, PartialEq)] -pub struct DomRefCell { +pub(crate) struct DomRefCell { value: RefCell, } @@ -42,7 +42,7 @@ impl DomRefCell { /// /// Panics if the value is currently mutably borrowed. #[allow(unsafe_code)] - pub unsafe fn borrow_for_layout(&self) -> &T { + pub(crate) unsafe fn borrow_for_layout(&self) -> &T { assert_in_layout(); self.value .try_borrow_unguarded() @@ -61,7 +61,7 @@ impl DomRefCell { /// /// Panics if this is called from anywhere other than the script thread. #[allow(unsafe_code, clippy::mut_from_ref)] - pub unsafe fn borrow_for_script_deallocation(&self) -> &mut T { + pub(crate) unsafe fn borrow_for_script_deallocation(&self) -> &mut T { assert_in_script(); &mut *self.value.as_ptr() } @@ -79,7 +79,7 @@ impl DomRefCell { /// /// Panics if this is called from anywhere other than the layout thread. #[allow(unsafe_code, clippy::mut_from_ref)] - pub unsafe fn borrow_mut_for_layout(&self) -> &mut T { + pub(crate) unsafe fn borrow_mut_for_layout(&self) -> &mut T { assert_in_layout(); &mut *self.value.as_ptr() } @@ -89,7 +89,7 @@ impl DomRefCell { // =================================================== impl DomRefCell { /// Create a new `DomRefCell` containing `value`. - pub fn new(value: T) -> DomRefCell { + pub(crate) fn new(value: T) -> DomRefCell { DomRefCell { value: RefCell::new(value), } @@ -104,7 +104,7 @@ impl DomRefCell { /// /// Panics if the value is currently mutably borrowed. #[track_caller] - pub fn borrow(&self) -> Ref { + pub(crate) fn borrow(&self) -> Ref { self.value.borrow() } @@ -117,7 +117,7 @@ impl DomRefCell { /// /// Panics if the value is currently borrowed. #[track_caller] - pub fn borrow_mut(&self) -> RefMut { + pub(crate) fn borrow_mut(&self) -> RefMut { self.value.borrow_mut() } @@ -131,7 +131,7 @@ impl DomRefCell { /// # Panics /// /// Panics if this is called off the script thread. - pub fn try_borrow(&self) -> Result, BorrowError> { + pub(crate) fn try_borrow(&self) -> Result, BorrowError> { assert_in_script(); self.value.try_borrow() } @@ -146,7 +146,7 @@ impl DomRefCell { /// # Panics /// /// Panics if this is called off the script thread. - pub fn try_borrow_mut(&self) -> Result, BorrowMutError> { + pub(crate) fn try_borrow_mut(&self) -> Result, BorrowMutError> { assert_in_script(); self.value.try_borrow_mut() } diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 5236a8529a2..e9ee8617187 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2281,7 +2281,7 @@ class CGTemplatedType(CGWrapper): class CGNamespace(CGWrapper): def __init__(self, namespace, child, public=False): - pub = "pub " if public else "" + pub = "pub(crate) " if public else "" pre = f"{pub}mod {namespace} {{\n" post = f"}} // mod {namespace}" CGWrapper.__init__(self, child, pre=pre, post=post) @@ -2656,7 +2656,7 @@ def DomTypes(descriptors, descriptorProvider, dictionaries, callbacks, typedefs, "Sized", ] joinedTraits = ' + '.join(traits) - elements = [CGGeneric(f"pub trait DomTypes: {joinedTraits} where Self: 'static {{\n")] + elements = [CGGeneric(f"pub(crate) trait DomTypes: {joinedTraits} where Self: 'static {{\n")] for descriptor in descriptors: iface_name = descriptor.interface.identifier.name traits = [] @@ -2737,7 +2737,7 @@ def DomTypeHolder(descriptors, descriptorProvider, dictionaries, callbacks, type elements = [ CGGeneric( "#[derive(JSTraceable, MallocSizeOf, PartialEq)]\n" - "pub struct DomTypeHolder;\n" + "pub(crate) struct DomTypeHolder;\n" "impl crate::DomTypes for DomTypeHolder {\n" ), ] @@ -4882,7 +4882,7 @@ class CGEnum(CGThing): decl = f""" #[repr(usize)] #[derive({derives})] -pub enum {ident} {{ +pub(crate) enum {ident} {{ {enums} }} """ @@ -4900,12 +4900,12 @@ use js::rust::HandleValue; use js::rust::MutableHandleValue; use js::jsval::JSVal; -pub const pairs: &[(&str, super::{ident})] = &[ +pub(crate) const pairs: &[(&str, super::{ident})] = &[ {pairs}, ]; impl super::{ident} {{ - pub fn as_str(&self) -> &'static str {{ + pub(crate) fn as_str(&self) -> &'static str {{ pairs[*self as usize].0 }} }} @@ -4994,7 +4994,7 @@ class CGConstant(CGThing): elif tag == IDLType.Tags.double: const_type = "f64" - return f"pub const {name}: {const_type} = {value};\n" + return f"pub(crate) const {name}: {const_type} = {value};\n" def getUnionTypeTemplateVars(type, descriptorProvider): @@ -5093,7 +5093,7 @@ class CGUnionStruct(CGThing): derives = ["JSTraceable"] + self.derives return f""" #[derive({", ".join(derives)})] -pub enum {self.type} {{ +pub(crate) enum {self.type} {{ {joinedEnumValues} }} @@ -5468,7 +5468,7 @@ class ClassConstructor(ClassItem): body = f' {{\n{body}}}' return f""" -pub unsafe fn {self.getDecorators(True)}new({args}) -> Rc<{cgClass.getNameString()}>{body} +pub(crate) unsafe fn {self.getDecorators(True)}new({args}) -> Rc<{cgClass.getNameString()}>{body} """ def define(self, cgClass): @@ -5560,7 +5560,7 @@ class CGClass(CGThing): myself = '' if self.decorators != '': myself += f'{self.decorators}\n' - myself += f'{self.indent}pub struct {self.name}{specialization}' + myself += f'{self.indent}pub(crate) struct {self.name}{specialization}' result += myself assert len(self.bases) == 1 # XXjdm Can we support multiple inheritance? @@ -5568,7 +5568,7 @@ class CGClass(CGThing): result += ' {\n' if self.bases: - self.members = [ClassMember("parent", self.bases[0].name, "pub")] + self.members + self.members = [ClassMember("parent", self.bases[0].name, "pub(crate)")] + self.members result += CGIndenter(CGGeneric(self.extradeclarations), len(self.indent)).define() @@ -6628,8 +6628,9 @@ class CGInterfaceTrait(CGThing): methods.append(CGGeneric("fn Length(&self) -> u32;\n")) if methods: + name = descriptor.interface.identifier.name self.cgRoot = CGWrapper(CGIndenter(CGList(methods, "")), - pre=f"pub trait {descriptor.interface.identifier.name}Methods {{\n", + pre=f"pub(crate) trait {name}Methods {{\n", post="}") else: self.cgRoot = CGGeneric("") @@ -6950,7 +6951,8 @@ class CGDescriptor(CGThing): if reexports: reexports = ', '.join([reexportedName(name) for name in reexports]) - cgThings = CGList([CGGeneric(f'pub use self::{toBindingNamespace(descriptor.name)}::{{{reexports}}};'), + namespace = toBindingNamespace(descriptor.name) + cgThings = CGList([CGGeneric(f'pub(crate) use self::{namespace}::{{{reexports}}};'), cgThings], '\n') self.cgRoot = cgThings @@ -6972,7 +6974,7 @@ class CGNonNamespacedEnum(CGThing): # Build the enum body. joinedEntries = ',\n'.join(entries) - enumstr = f"{comment}pub enum {enumName} {{\n{joinedEntries}\n}}\n" + enumstr = f"{comment}pub(crate) enum {enumName} {{\n{joinedEntries}\n}}\n" if repr: enumstr = f"#[repr({repr})]\n{enumstr}" if deriving: @@ -7025,10 +7027,10 @@ class CGDictionary(CGThing): typeName = f"{self.makeModuleName(d.parent)}::{self.makeClassName(d.parent)}" if type_needs_tracing(d.parent): typeName = f"RootedTraceableBox<{typeName}>" - inheritance = f" pub parent: {typeName},\n" + inheritance = f" pub(crate) parent: {typeName},\n" else: inheritance = "" - memberDecls = [f" pub {self.makeMemberName(m[0].identifier.name)}: {self.getMemberType(m)}," + memberDecls = [f" pub(crate) {self.makeMemberName(m[0].identifier.name)}: {self.getMemberType(m)}," for m in self.memberInfo] derive = ["JSTraceable"] + self.derives @@ -7069,7 +7071,7 @@ class CGDictionary(CGThing): return ( f"#[derive({', '.join(derive)})]\n" f"{mustRoot}" - f"pub struct {self.makeClassName(d)} {{\n" + f"pub(crate) struct {self.makeClassName(d)} {{\n" f"{inheritance}" f"{joinedMemberDecls}\n" "}\n" @@ -7142,7 +7144,7 @@ class CGDictionary(CGThing): return ( f"impl {selfName} {{\n" f"{CGIndenter(CGGeneric(self.makeEmpty()), indentLevel=4).define()}\n" - " pub fn new(cx: SafeJSContext, val: HandleValue) \n" + " pub(crate) fn new(cx: SafeJSContext, val: HandleValue) \n" f" -> Result, ()> {{\n" f" {unsafe_if_necessary} {{\n" " let object = if val.get().is_null_or_undefined() {\n" @@ -7246,7 +7248,7 @@ class CGDictionary(CGThing): parentTemplate = "parent: %s::%s::empty(),\n" fieldTemplate = "%s: %s,\n" functionTemplate = ( - "pub fn empty() -> Self {\n" + "pub(crate) fn empty() -> Self {\n" " Self {\n" "%s" " }\n" @@ -7256,7 +7258,7 @@ class CGDictionary(CGThing): parentTemplate = "dictionary.parent = %s::%s::empty();\n" fieldTemplate = "dictionary.%s = %s;\n" functionTemplate = ( - "pub fn empty() -> RootedTraceableBox {\n" + "pub(crate) fn empty() -> RootedTraceableBox {\n" " let mut dictionary = RootedTraceableBox::new(Self::default());\n" "%s" " dictionary\n" @@ -7341,14 +7343,14 @@ class CGRegisterProxyHandlers(CGThing): def __init__(self, config): descriptors = config.getDescriptors(proxy=True) body = "".join( - f" pub static {desc.name}: std::sync::atomic::AtomicPtr =\n" + f" pub(crate) static {desc.name}: std::sync::atomic::AtomicPtr =\n" " std::sync::atomic::AtomicPtr::new(std::ptr::null_mut());\n" for desc in descriptors ) self.root = CGList([ CGGeneric( "#[allow(non_upper_case_globals)]\n" - "pub mod proxy_handlers {\n" + "pub(crate) mod proxy_handlers {\n" f"{body}}}\n" ), CGRegisterProxyHandlersMethod(descriptors), @@ -7400,9 +7402,9 @@ class CGBindingRoot(CGThing): if t.innerType.isUnion() and not t.innerType.nullable(): # Allow using the typedef's name for accessing variants. - typeDefinition = f"pub use self::{type} as {name};" + typeDefinition = f"pub(crate) use self::{type} as {name};" else: - typeDefinition = f"pub type {name} = {type};" + typeDefinition = f"pub(crate) type {name} = {type};" cgthings.append(CGGeneric(typeDefinition)) @@ -8207,7 +8209,6 @@ class GlobalGenRoots(): "crate::dom::bindings::codegen", "crate::script_runtime::JSContext", "js::rust::HandleObject", - "phf", ] imports = CGList([CGGeneric(f"use {mod};") for mod in mods], "\n") @@ -8220,7 +8221,7 @@ class GlobalGenRoots(): global_flags = CGWrapper(CGIndenter(CGList([ CGGeneric(f"const {args[0]} = {args[1]};") for args in flags - ], "\n")), pre="#[derive(Clone, Copy)]\npub struct Globals: u8 {\n", post="\n}") + ], "\n")), pre="#[derive(Clone, Copy)]\npub(crate) struct Globals: u8 {\n", post="\n}") globals_ = CGWrapper(CGIndenter(global_flags), pre="bitflags::bitflags! {\n", post="\n}") phf = CGGeneric("include!(concat!(env!(\"OUT_DIR\"), \"/InterfaceObjectMapPhf.rs\"));") @@ -8262,9 +8263,9 @@ class GlobalGenRoots(): return CGList([ CGGeneric(AUTOGENERATED_WARNING_COMMENT), - CGGeneric(f"pub const PROTO_OR_IFACE_LENGTH: usize = {len(protos) + len(constructors)};\n"), - CGGeneric(f"pub const MAX_PROTO_CHAIN_LENGTH: usize = {config.maxProtoChainLength};\n\n"), - CGGeneric("#[allow(clippy::enum_variant_names)]"), + CGGeneric(f"pub(crate) const PROTO_OR_IFACE_LENGTH: usize = {len(protos) + len(constructors)};\n"), + CGGeneric(f"pub(crate) const MAX_PROTO_CHAIN_LENGTH: usize = {config.maxProtoChainLength};\n\n"), + CGGeneric("#[allow(clippy::enum_variant_names, dead_code)]"), CGNonNamespacedEnum('ID', protos, 0, deriving="PartialEq, Copy, Clone", repr="u16"), CGNonNamespacedEnum('Constructor', constructors, len(protos), deriving="PartialEq, Copy, Clone", repr="u16"), @@ -8273,7 +8274,7 @@ class GlobalGenRoots(): indentLevel=4), pre=f"static INTERFACES: [&str; {len(protos)}] = [\n", post="\n];\n\n"), - CGGeneric("pub fn proto_id_to_name(proto_id: u16) -> &'static str {\n" + CGGeneric("pub(crate) fn proto_id_to_name(proto_id: u16) -> &'static str {\n" " debug_assert!(proto_id < ID::Last as u16);\n" " INTERFACES[proto_id as usize]\n" "}\n\n"), @@ -8296,7 +8297,7 @@ class GlobalGenRoots(): for d in config.getDescriptors(register=True, isCallback=False, isIteratorInterface=False)]) - curr = CGList([CGGeneric(f"pub use crate::dom::{name.lower()}::{MakeNativeName(name)};\n") + curr = CGList([CGGeneric(f"pub(crate) use crate::dom::{name.lower()}::{MakeNativeName(name)};\n") for name in descriptors]) curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT) return curr @@ -8313,7 +8314,7 @@ class GlobalGenRoots(): | set(leafModule(d) for d in config.getDictionaries())) curr = CGList([CGGeneric( "#[allow(clippy::derivable_impls)]\n" - f"pub mod {name};\n" + f"pub(crate) mod {name};\n" ) for name in sorted(descriptors)]) curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT) return curr @@ -8360,17 +8361,17 @@ class GlobalGenRoots(): typeIdCode = [] topTypeVariants = [ - ("ID used by abstract interfaces.", "pub abstract_: ()"), - ("ID used by interfaces that are not castable.", "pub alone: ()"), + ("ID used by abstract interfaces.", "pub(crate) abstract_: ()"), + ("ID used by interfaces that are not castable.", "pub(crate) alone: ()"), ] topTypeVariants += [ (f"ID used by interfaces that derive from {typeName}.", - f"pub {typeName.lower()}: {typeName}TypeId") + f"pub(crate) {typeName.lower()}: {typeName}TypeId") for typeName in topTypes ] topTypeVariantsAsStrings = [CGGeneric(f"/// {variant[0]}\n{variant[1]},") for variant in topTypeVariants] typeIdCode.append(CGWrapper(CGIndenter(CGList(topTypeVariantsAsStrings, "\n"), 4), - pre="#[derive(Copy)]\npub union TopTypeId {\n", + pre="#[derive(Copy)]\npub(crate) union TopTypeId {\n", post="\n}\n\n")) typeIdCode.append(CGGeneric("""\ @@ -8393,12 +8394,12 @@ impl Clone for TopTypeId { variants += [CGGeneric(type_id_variant(derivedName)) for derivedName in derived] derives = "Clone, Copy, Debug, PartialEq" typeIdCode.append(CGWrapper(CGIndenter(CGList(variants, ",\n"), 4), - pre=f"#[derive({derives})]\npub enum {base}TypeId {{\n", + pre=f"#[derive({derives})]\npub(crate) enum {base}TypeId {{\n", post="\n}\n\n")) if base in topTypes: typeIdCode.append(CGGeneric(f""" impl {base} {{ - pub fn type_id(&self) -> &'static {base}TypeId {{ + pub(crate) fn type_id(&self) -> &'static {base}TypeId {{ unsafe {{ &get_dom_class(self.reflector().get_jsobject().get()) .unwrap() diff --git a/components/script/dom/bindings/constant.rs b/components/script/dom/bindings/constant.rs index ced01176aea..7364ee2086d 100644 --- a/components/script/dom/bindings/constant.rs +++ b/components/script/dom/bindings/constant.rs @@ -15,17 +15,17 @@ use crate::script_runtime::JSContext; /// Representation of an IDL constant. #[derive(Clone)] -pub struct ConstantSpec { +pub(crate) struct ConstantSpec { /// name of the constant. - pub name: &'static CStr, + pub(crate) name: &'static CStr, /// value of the constant. - pub value: ConstantVal, + pub(crate) value: ConstantVal, } /// Representation of an IDL constant value. #[derive(Clone)] #[allow(dead_code)] -pub enum ConstantVal { +pub(crate) enum ConstantVal { /// `long` constant. Int(i32), /// `unsigned long` constant. @@ -40,7 +40,7 @@ pub enum ConstantVal { impl ConstantSpec { /// Returns a `JSVal` that represents the value of this `ConstantSpec`. - pub fn get_value(&self) -> JSVal { + pub(crate) fn get_value(&self) -> JSVal { match self.value { ConstantVal::Null => NullValue(), ConstantVal::Int(i) => Int32Value(i), @@ -53,7 +53,7 @@ impl ConstantSpec { /// Defines constants on `obj`. /// Fails on JSAPI failure. -pub fn define_constants(cx: JSContext, obj: HandleObject, constants: &[ConstantSpec]) { +pub(crate) fn define_constants(cx: JSContext, obj: HandleObject, constants: &[ConstantSpec]) { for spec in constants { rooted!(in(*cx) let value = spec.get_value()); unsafe { diff --git a/components/script/dom/bindings/constructor.rs b/components/script/dom/bindings/constructor.rs index f5ba6b8c2c7..891145a342f 100644 --- a/components/script/dom/bindings/constructor.rs +++ b/components/script/dom/bindings/constructor.rs @@ -226,7 +226,7 @@ unsafe fn html_constructor( /// given local name. This list should only include elements marked with the /// [HTMLConstructor](https://html.spec.whatwg.org/multipage/#htmlconstructor) /// extended attribute. -pub fn get_constructor_object_from_local_name( +pub(crate) fn get_constructor_object_from_local_name( name: LocalName, cx: JSContext, global: HandleObject, @@ -370,15 +370,15 @@ pub fn get_constructor_object_from_local_name( } } -pub fn pop_current_element_queue(can_gc: CanGc) { +pub(crate) fn pop_current_element_queue(can_gc: CanGc) { ScriptThread::pop_current_element_queue(can_gc); } -pub fn push_new_element_queue() { +pub(crate) fn push_new_element_queue() { ScriptThread::push_new_element_queue(); } -pub unsafe fn call_html_constructor + DomObject>( +pub(crate) unsafe fn call_html_constructor + DomObject>( cx: JSContext, args: &CallArgs, global: &GlobalScope, @@ -402,7 +402,7 @@ pub unsafe fn call_html_constructor + DomObject>( .is_ok() } -pub unsafe fn call_default_constructor( +pub(crate) unsafe fn call_default_constructor( cx: JSContext, args: &CallArgs, global: &GlobalScope, diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index df29575b2e6..33707ae75fb 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -35,7 +35,7 @@ use std::{char, ffi, ptr, slice}; use js::conversions::latin1_to_string; -pub use js::conversions::{ +pub(crate) use js::conversions::{ ConversionBehavior, ConversionResult, FromJSValConvertible, ToJSValConvertible, }; use js::error::throw_type_error; @@ -70,13 +70,13 @@ use crate::dom::nodelist::NodeList; use crate::dom::windowproxy::WindowProxy; /// A trait to check whether a given `JSObject` implements an IDL interface. -pub trait IDLInterface { +pub(crate) trait IDLInterface { /// Returns whether the given DOM class derives that interface. fn derives(_: &'static DOMClass) -> bool; } /// A trait to mark an IDL interface as deriving from another one. -pub trait DerivedFrom: Castable {} +pub(crate) trait DerivedFrom: Castable {} impl ToJSValConvertible for Finite { #[inline] @@ -160,7 +160,7 @@ where /// integer. /// /// Handling of invalid UTF-16 in strings depends on the relevant option. -pub unsafe fn jsid_to_string(cx: *mut JSContext, id: HandleId) -> Option { +pub(crate) unsafe fn jsid_to_string(cx: *mut JSContext, id: HandleId) -> Option { let id_raw = *id; if id_raw.is_string() { let jsstr = std::ptr::NonNull::new(id_raw.to_string()).unwrap(); @@ -221,7 +221,7 @@ impl FromJSValConvertible for DOMString { /// Convert the given `JSString` to a `DOMString`. Fails if the string does not /// contain valid UTF-16. -pub unsafe fn jsstring_to_str(cx: *mut JSContext, s: ptr::NonNull) -> DOMString { +pub(crate) unsafe fn jsstring_to_str(cx: *mut JSContext, s: ptr::NonNull) -> DOMString { let latin1 = JS_DeprecatedStringHasLatin1Chars(s.as_ptr()); DOMString::from_string(if latin1 { latin1_to_string(cx, s.as_ptr()) @@ -355,7 +355,7 @@ impl ToJSValConvertible for Reflector { } /// Returns whether `obj` is a DOM object implemented as a proxy. -pub fn is_dom_proxy(obj: *mut JSObject) -> bool { +pub(crate) fn is_dom_proxy(obj: *mut JSObject) -> bool { use js::glue::IsProxyHandlerFamily; unsafe { let clasp = get_object_class(obj); @@ -367,10 +367,10 @@ pub fn is_dom_proxy(obj: *mut JSObject) -> bool { /// stored for non-proxy bindings. // We use slot 0 for holding the raw object. This is safe for both // globals and non-globals. -pub const DOM_OBJECT_SLOT: u32 = 0; +pub(crate) const DOM_OBJECT_SLOT: u32 = 0; /// Get the private pointer of a DOM object from a given reflector. -pub unsafe fn private_from_object(obj: *mut JSObject) -> *const libc::c_void { +pub(crate) unsafe fn private_from_object(obj: *mut JSObject) -> *const libc::c_void { let mut value = UndefinedValue(); if is_dom_object(obj) { JS_GetReservedSlot(obj, DOM_OBJECT_SLOT, &mut value); @@ -386,7 +386,7 @@ pub unsafe fn private_from_object(obj: *mut JSObject) -> *const libc::c_void { } /// Get the `DOMClass` from `obj`, or `Err(())` if `obj` is not a DOM object. -pub unsafe fn get_dom_class(obj: *mut JSObject) -> Result<&'static DOMClass, ()> { +pub(crate) unsafe fn get_dom_class(obj: *mut JSObject) -> Result<&'static DOMClass, ()> { use js::glue::GetProxyHandlerExtra; use crate::dom::bindings::utils::DOMJSClass; @@ -478,7 +478,7 @@ unsafe fn private_from_proto_check_static( } /// Get a `*const T` for a DOM object accessible from a `JSObject`. -pub fn native_from_object(obj: *mut JSObject, cx: *mut JSContext) -> Result<*const T, ()> +pub(crate) fn native_from_object(obj: *mut JSObject, cx: *mut JSContext) -> Result<*const T, ()> where T: DomObject + IDLInterface, { @@ -490,7 +490,7 @@ where /// Get a `*const T` for a DOM object accessible from a `JSObject`, where the DOM object /// is guaranteed not to be a wrapper. -pub fn native_from_object_static(obj: *mut JSObject) -> Result<*const T, ()> +pub(crate) fn native_from_object_static(obj: *mut JSObject) -> Result<*const T, ()> where T: DomObject + IDLInterface, { @@ -503,7 +503,7 @@ where /// Returns Err(()) if `obj` is an opaque security wrapper or if the object is /// not a reflector for a DOM object of the given type (as defined by the /// proto_id and proto_depth). -pub fn root_from_object(obj: *mut JSObject, cx: *mut JSContext) -> Result, ()> +pub(crate) fn root_from_object(obj: *mut JSObject, cx: *mut JSContext) -> Result, ()> where T: DomObject + IDLInterface, { @@ -516,7 +516,7 @@ where /// Returns Err(()) if `obj` is an opaque security wrapper or if the object is /// not a reflector for a DOM object of the given type (as defined by the /// proto_id and proto_depth). -pub fn root_from_object_static(obj: *mut JSObject) -> Result, ()> +pub(crate) fn root_from_object_static(obj: *mut JSObject) -> Result, ()> where T: DomObject + IDLInterface, { @@ -525,7 +525,7 @@ where /// Get a `*const T` for a DOM object accessible from a `HandleValue`. /// Caller is responsible for throwing a JS exception if needed in case of error. -pub fn native_from_handlevalue(v: HandleValue, cx: *mut JSContext) -> Result<*const T, ()> +pub(crate) fn native_from_handlevalue(v: HandleValue, cx: *mut JSContext) -> Result<*const T, ()> where T: DomObject + IDLInterface, { @@ -537,7 +537,7 @@ where /// Get a `DomRoot` for a DOM object accessible from a `HandleValue`. /// Caller is responsible for throwing a JS exception if needed in case of error. -pub fn root_from_handlevalue(v: HandleValue, cx: *mut JSContext) -> Result, ()> +pub(crate) fn root_from_handlevalue(v: HandleValue, cx: *mut JSContext) -> Result, ()> where T: DomObject + IDLInterface, { @@ -548,7 +548,10 @@ where } /// Get a `DomRoot` for a DOM object accessible from a `HandleObject`. -pub fn root_from_handleobject(obj: HandleObject, cx: *mut JSContext) -> Result, ()> +pub(crate) fn root_from_handleobject( + obj: HandleObject, + cx: *mut JSContext, +) -> Result, ()> where T: DomObject + IDLInterface, { @@ -564,7 +567,7 @@ impl ToJSValConvertible for DomRoot { /// Returns whether `value` is an array-like object (Array, FileList, /// HTMLCollection, HTMLFormControlsCollection, HTMLOptionsCollection, /// NodeList). -pub unsafe fn is_array_like(cx: *mut JSContext, value: HandleValue) -> bool { +pub(crate) unsafe fn is_array_like(cx: *mut JSContext, value: HandleValue) -> bool { let mut is_array = false; assert!(IsArrayObject(cx, value, &mut is_array)); if is_array { @@ -596,7 +599,7 @@ pub unsafe fn is_array_like(cx: *mut JSContext, value: HandleValue) -> bool { } /// Get a property from a JS object. -pub unsafe fn get_property_jsval( +pub(crate) unsafe fn get_property_jsval( cx: *mut JSContext, object: HandleObject, name: &str, @@ -622,7 +625,7 @@ pub unsafe fn get_property_jsval( } /// Get a property from a JS object, and convert it to a Rust value. -pub unsafe fn get_property( +pub(crate) unsafe fn get_property( cx: *mut JSContext, object: HandleObject, name: &str, @@ -648,7 +651,7 @@ where /// Get a `DomRoot` for a WindowProxy accessible from a `HandleValue`. /// Caller is responsible for throwing a JS exception if needed in case of error. -pub unsafe fn windowproxy_from_handlevalue( +pub(crate) unsafe fn windowproxy_from_handlevalue( v: HandleValue, _cx: *mut JSContext, ) -> Result, ()> { diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs index d2c0b534f3b..f7efb14b694 100644 --- a/components/script/dom/bindings/error.rs +++ b/components/script/dom/bindings/error.rs @@ -40,7 +40,7 @@ thread_local! { /// DOM exceptions that can be thrown by a native DOM method. #[derive(Clone, Debug, MallocSizeOf)] -pub enum Error { +pub(crate) enum Error { /// IndexSizeError DOMException IndexSize, /// NotFoundError DOMException @@ -100,14 +100,14 @@ pub enum Error { } /// The return type for IDL operations that can throw DOM exceptions. -pub type Fallible = Result; +pub(crate) type Fallible = Result; /// The return type for IDL operations that can throw DOM exceptions and /// return `()`. -pub type ErrorResult = Fallible<()>; +pub(crate) type ErrorResult = Fallible<()>; /// Set a pending exception for the given `result` on `cx`. -pub fn throw_dom_exception(cx: SafeJSContext, global: &GlobalScope, result: Error) { +pub(crate) fn throw_dom_exception(cx: SafeJSContext, global: &GlobalScope, result: Error) { #[cfg(feature = "js_backtrace")] unsafe { capture_stack!(in(*cx) let stack); @@ -170,15 +170,15 @@ pub fn throw_dom_exception(cx: SafeJSContext, global: &GlobalScope, result: Erro /// A struct encapsulating information about a runtime script error. #[derive(Default)] -pub struct ErrorInfo { +pub(crate) struct ErrorInfo { /// The error message. - pub message: String, + pub(crate) message: String, /// The file name. - pub filename: String, + pub(crate) filename: String, /// The line number. - pub lineno: c_uint, + pub(crate) lineno: c_uint, /// The column number. - pub column: c_uint, + pub(crate) column: c_uint, } impl ErrorInfo { @@ -267,7 +267,7 @@ impl ErrorInfo { /// /// The `dispatch_event` argument is temporary and non-standard; passing false /// prevents dispatching the `error` event. -pub unsafe fn report_pending_exception( +pub(crate) unsafe fn report_pending_exception( cx: *mut JSContext, dispatch_event: bool, realm: InRealm, @@ -310,7 +310,7 @@ pub unsafe fn report_pending_exception( /// Throw an exception to signal that a `JSObject` can not be converted to a /// given DOM type. -pub unsafe fn throw_invalid_this(cx: *mut JSContext, proto_id: u16) { +pub(crate) unsafe fn throw_invalid_this(cx: *mut JSContext, proto_id: u16) { debug_assert!(!JS_IsExceptionPending(cx)); let error = format!( "\"this\" object does not implement interface {}.", @@ -319,7 +319,7 @@ pub unsafe fn throw_invalid_this(cx: *mut JSContext, proto_id: u16) { throw_type_error(cx, &error); } -pub unsafe fn throw_constructor_without_new(cx: *mut JSContext, name: &str) { +pub(crate) unsafe fn throw_constructor_without_new(cx: *mut JSContext, name: &str) { debug_assert!(!JS_IsExceptionPending(cx)); let error = format!("{} constructor: 'new' is required", name); throw_type_error(cx, &error); @@ -328,7 +328,7 @@ pub unsafe fn throw_constructor_without_new(cx: *mut JSContext, name: &str) { impl Error { /// Convert this error value to a JS value, consuming it in the process. #[allow(clippy::wrong_self_convention)] - pub unsafe fn to_jsval( + pub(crate) unsafe fn to_jsval( self, cx: *mut JSContext, global: &GlobalScope, diff --git a/components/script/dom/bindings/finalize.rs b/components/script/dom/bindings/finalize.rs index 2a1ff930fac..dd379431af3 100644 --- a/components/script/dom/bindings/finalize.rs +++ b/components/script/dom/bindings/finalize.rs @@ -14,7 +14,7 @@ use js::jsval::UndefinedValue; use crate::dom::bindings::utils::finalize_global as do_finalize_global; use crate::dom::bindings::weakref::{WeakBox, WeakReferenceable, DOM_WEAK_SLOT}; -pub unsafe fn finalize_common(this: *const T) { +pub(crate) unsafe fn finalize_common(this: *const T) { if !this.is_null() { // The pointer can be null if the object is the unforgeable holder of that interface. let _ = Box::from_raw(this as *mut T); @@ -22,12 +22,12 @@ pub unsafe fn finalize_common(this: *const T) { debug!("{} finalize: {:p}", type_name::(), this); } -pub unsafe fn finalize_global(obj: *mut JSObject, this: *const T) { +pub(crate) unsafe fn finalize_global(obj: *mut JSObject, this: *const T) { do_finalize_global(obj); finalize_common::(this); } -pub unsafe fn finalize_weak_referenceable( +pub(crate) unsafe fn finalize_weak_referenceable( obj: *mut JSObject, this: *const T, ) { diff --git a/components/script/dom/bindings/frozenarray.rs b/components/script/dom/bindings/frozenarray.rs index 5f2e6e395ad..44cc0bd4085 100644 --- a/components/script/dom/bindings/frozenarray.rs +++ b/components/script/dom/bindings/frozenarray.rs @@ -12,18 +12,18 @@ use crate::dom::bindings::utils::to_frozen_array; use crate::script_runtime::JSContext; #[derive(JSTraceable)] -pub struct CachedFrozenArray { +pub(crate) struct CachedFrozenArray { frozen_value: DomRefCell>>, } impl CachedFrozenArray { - pub fn new() -> CachedFrozenArray { + pub(crate) fn new() -> CachedFrozenArray { CachedFrozenArray { frozen_value: DomRefCell::new(None), } } - pub fn get_or_init Vec, T: ToJSValConvertible>( + pub(crate) fn get_or_init Vec, T: ToJSValConvertible>( &self, f: F, cx: JSContext, @@ -46,7 +46,7 @@ impl CachedFrozenArray { .set(retval.get()); } - pub fn clear(&self) { + pub(crate) fn clear(&self) { *self.frozen_value.borrow_mut() = None; } } diff --git a/components/script/dom/bindings/guard.rs b/components/script/dom/bindings/guard.rs index 883d3067214..45e4473d821 100644 --- a/components/script/dom/bindings/guard.rs +++ b/components/script/dom/bindings/guard.rs @@ -14,21 +14,26 @@ use crate::realms::{AlreadyInRealm, InRealm}; use crate::script_runtime::JSContext; /// A container with a list of conditions. -pub struct Guard { +pub(crate) struct Guard { conditions: &'static [Condition], value: T, } impl Guard { /// Construct a new guarded value. - pub const fn new(conditions: &'static [Condition], value: T) -> Self { + pub(crate) const fn new(conditions: &'static [Condition], value: T) -> Self { Guard { conditions, value } } /// Expose the value if the conditions are satisfied. /// /// The passed handle is the object on which the value may be exposed. - pub fn expose(&self, cx: JSContext, obj: HandleObject, global: HandleObject) -> Option { + pub(crate) fn expose( + &self, + cx: JSContext, + obj: HandleObject, + global: HandleObject, + ) -> Option { let mut exposed_on_global = false; let conditions_satisfied = self.conditions.iter().all(|c| match c { Condition::Satisfied => { @@ -53,7 +58,7 @@ impl Guard { /// A condition to expose things. #[derive(Clone, Copy)] -pub enum Condition { +pub(crate) enum Condition { /// The condition is satisfied if the function returns true. Func(fn(JSContext, HandleObject) -> bool), /// The condition is satisfied if the preference is set. @@ -73,7 +78,12 @@ fn is_secure_context(cx: JSContext) -> bool { } impl Condition { - pub fn is_satisfied(&self, cx: JSContext, obj: HandleObject, global: HandleObject) -> bool { + pub(crate) fn is_satisfied( + &self, + cx: JSContext, + obj: HandleObject, + global: HandleObject, + ) -> bool { match *self { Condition::Pref(name) => prefs::pref_map().get(name).as_bool().unwrap_or(false), Condition::Func(f) => f(cx, obj), diff --git a/components/script/dom/bindings/import.rs b/components/script/dom/bindings/import.rs index c4586b43905..b4337419a6e 100644 --- a/components/script/dom/bindings/import.rs +++ b/components/script/dom/bindings/import.rs @@ -3,60 +3,60 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #[allow(unused_imports)] -pub mod base { - pub use std::ptr; - pub use std::rc::Rc; +pub(crate) mod base { + pub(crate) use std::ptr; + pub(crate) use std::rc::Rc; - pub use js::error::throw_type_error; - pub use js::jsapi::{ + pub(crate) use js::error::throw_type_error; + pub(crate) use js::jsapi::{ CurrentGlobalOrNull, HandleValue as RawHandleValue, HandleValueArray, Heap, IsCallable, JSContext, JSObject, JS_NewObject, }; - pub use js::jsval::{JSVal, NullValue, ObjectOrNullValue, ObjectValue, UndefinedValue}; - pub use js::panic::maybe_resume_unwind; - pub use js::rust::wrappers::{JS_CallFunctionValue, JS_WrapValue}; - pub use js::rust::{HandleObject, HandleValue, MutableHandleObject, MutableHandleValue}; + pub(crate) use js::jsval::{JSVal, NullValue, ObjectOrNullValue, ObjectValue, UndefinedValue}; + pub(crate) use js::panic::maybe_resume_unwind; + pub(crate) use js::rust::wrappers::{JS_CallFunctionValue, JS_WrapValue}; + pub(crate) use js::rust::{HandleObject, HandleValue, MutableHandleObject, MutableHandleValue}; - pub use crate::dom::bindings::callback::{ + pub(crate) use crate::dom::bindings::callback::{ wrap_call_this_object, CallSetup, CallbackContainer, CallbackFunction, CallbackInterface, CallbackObject, ExceptionHandling, ThisReflector, }; - pub use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ + pub(crate) use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ ChannelCountMode, ChannelCountModeValues, ChannelInterpretation, ChannelInterpretationValues, }; - pub use crate::dom::bindings::codegen::DomTypes::DomTypes; - pub use crate::dom::bindings::codegen::UnionTypes; - pub use crate::dom::bindings::conversions::{ + pub(crate) use crate::dom::bindings::codegen::DomTypes::DomTypes; + pub(crate) use crate::dom::bindings::codegen::UnionTypes; + pub(crate) use crate::dom::bindings::conversions::{ root_from_handlevalue, ConversionBehavior, ConversionResult, FromJSValConvertible, StringificationBehavior, ToJSValConvertible, }; - pub use crate::dom::bindings::error::Error::JSFailed; - pub use crate::dom::bindings::error::{throw_dom_exception, Fallible}; - pub use crate::dom::bindings::num::Finite; - pub use crate::dom::bindings::proxyhandler::CrossOriginProperties; - pub use crate::dom::bindings::reflector::DomObject; - pub use crate::dom::bindings::root::DomRoot; - pub use crate::dom::bindings::str::{ByteString, DOMString, USVString}; - pub use crate::dom::bindings::trace::RootedTraceableBox; - pub use crate::dom::bindings::utils::{ + pub(crate) use crate::dom::bindings::error::Error::JSFailed; + pub(crate) use crate::dom::bindings::error::{throw_dom_exception, Fallible}; + pub(crate) use crate::dom::bindings::num::Finite; + pub(crate) use crate::dom::bindings::proxyhandler::CrossOriginProperties; + pub(crate) use crate::dom::bindings::reflector::DomObject; + pub(crate) use crate::dom::bindings::root::DomRoot; + pub(crate) use crate::dom::bindings::str::{ByteString, DOMString, USVString}; + pub(crate) use crate::dom::bindings::trace::RootedTraceableBox; + pub(crate) use crate::dom::bindings::utils::{ get_dictionary_property, set_dictionary_property, ThreadUnsafeOnceLock, }; - pub use crate::dom::globalscope::GlobalScope; - pub use crate::script_runtime::JSContext as SafeJSContext; + pub(crate) use crate::dom::globalscope::GlobalScope; + pub(crate) use crate::script_runtime::JSContext as SafeJSContext; } #[allow(unused_imports)] -pub mod module { - pub use std::cmp; - pub use std::ffi::CString; - pub use std::ptr::NonNull; +pub(crate) mod module { + pub(crate) use std::cmp; + pub(crate) use std::ffi::CString; + pub(crate) use std::ptr::NonNull; - pub use js::glue::{ + pub(crate) use js::glue::{ CreateProxyHandler, GetProxyReservedSlot, JS_GetReservedSlot, ProxyTraps, SetProxyReservedSlot, }; - pub use js::jsapi::{ + pub(crate) use js::jsapi::{ JSJitInfo_OpType, JSJitInfo__bindgen_ty_1, JSJitInfo__bindgen_ty_2, JSJitInfo__bindgen_ty_3, JSJitMethodCallArgs, JSJitSetterCallArgs, JSNativeWrapper, JSPropertySpec, JSPropertySpec_Accessor, JSPropertySpec_AccessorsOrValue, @@ -76,79 +76,87 @@ pub mod module { JSCLASS_FOREGROUND_FINALIZE, JSCLASS_RESERVED_SLOTS_SHIFT, JSITER_HIDDEN, JSITER_OWNONLY, JSITER_SYMBOLS, JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY, }; - pub use js::jsval::PrivateValue; - pub use js::panic::wrap_panic; - pub use js::rust::wrappers::{ + pub(crate) use js::jsval::PrivateValue; + pub(crate) use js::panic::wrap_panic; + pub(crate) use js::rust::wrappers::{ int_to_jsid, AppendToIdVector, Call, GetPropertyKeys, JS_CopyOwnPropertiesAndPrivateFields, JS_DefineProperty, JS_DefinePropertyById2, JS_GetProperty, JS_InitializePropertiesFromCompatibleNativeObject, JS_NewObjectWithGivenProto, JS_NewObjectWithoutMetadata, JS_SetImmutablePrototype, JS_SetProperty, JS_SetPrototype, JS_WrapObject, NewProxyObject, RUST_INTERNED_STRING_TO_JSID, RUST_SYMBOL_TO_JSID, }; - pub use js::rust::{ + pub(crate) use js::rust::{ get_context_realm, get_object_class, get_object_realm, CustomAutoRooterGuard, GCMethods, Handle, MutableHandle, }; - pub use js::typedarray::{ + pub(crate) use js::typedarray::{ ArrayBuffer, ArrayBufferView, Float32Array, Float64Array, Uint8Array, Uint8ClampedArray, }; - pub use js::{ + pub(crate) use js::{ jsapi, typedarray, JSCLASS_GLOBAL_SLOT_COUNT, JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_MASK, JS_CALLEE, }; - pub use servo_config::pref; + pub(crate) use servo_config::pref; - pub use super::base::*; - pub use crate::dom::bindings::codegen::Bindings::AnalyserNodeBinding::AnalyserOptions; - pub use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ + pub(crate) use super::base::*; + pub(crate) use crate::dom::bindings::codegen::Bindings::AnalyserNodeBinding::AnalyserOptions; + pub(crate) use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ AudioNode_Binding, ChannelCountMode, ChannelCountModeValues, ChannelInterpretation, ChannelInterpretationValues, }; - pub use crate::dom::bindings::codegen::Bindings::EventTargetBinding::EventTarget_Binding; - pub use crate::dom::bindings::codegen::{InterfaceObjectMap, PrototypeList, RegisterBindings}; - pub use crate::dom::bindings::constant::{ConstantSpec, ConstantVal}; - pub use crate::dom::bindings::constructor::{ + pub(crate) use crate::dom::bindings::codegen::Bindings::EventTargetBinding::EventTarget_Binding; + pub(crate) use crate::dom::bindings::codegen::{ + InterfaceObjectMap, PrototypeList, RegisterBindings, + }; + pub(crate) use crate::dom::bindings::constant::{ConstantSpec, ConstantVal}; + pub(crate) use crate::dom::bindings::constructor::{ call_default_constructor, call_html_constructor, pop_current_element_queue, push_new_element_queue, }; - pub use crate::dom::bindings::conversions::{ + pub(crate) use crate::dom::bindings::conversions::{ is_array_like, jsid_to_string, native_from_handlevalue, native_from_object_static, IDLInterface, StringificationBehavior, ToJSValConvertible, DOM_OBJECT_SLOT, }; - pub use crate::dom::bindings::error::{throw_constructor_without_new, Error, ErrorResult}; - pub use crate::dom::bindings::finalize::{ + pub(crate) use crate::dom::bindings::error::{ + throw_constructor_without_new, Error, ErrorResult, + }; + pub(crate) use crate::dom::bindings::finalize::{ finalize_common, finalize_global, finalize_weak_referenceable, }; - pub use crate::dom::bindings::guard::{Condition, Guard}; - pub use crate::dom::bindings::inheritance::Castable; - pub use crate::dom::bindings::interface::{ + pub(crate) use crate::dom::bindings::guard::{Condition, Guard}; + pub(crate) use crate::dom::bindings::inheritance::Castable; + pub(crate) use crate::dom::bindings::interface::{ create_callback_interface_object, create_global_object, create_interface_prototype_object, create_named_constructors, create_noncallback_interface_object, define_dom_interface, define_guarded_methods, define_guarded_properties, get_desired_proto, get_per_interface_object_handle, is_exposed_in, ConstructorClassHook, InterfaceConstructorBehavior, NonCallbackInterfaceObjectClass, ProtoOrIfaceIndex, }; - pub use crate::dom::bindings::iterable::{Iterable, IteratorType}; - pub use crate::dom::bindings::like::{Maplike, Setlike}; - pub use crate::dom::bindings::namespace::{create_namespace_object, NamespaceObjectClass}; - pub use crate::dom::bindings::proxyhandler; - pub use crate::dom::bindings::proxyhandler::{ + pub(crate) use crate::dom::bindings::iterable::{Iterable, IteratorType}; + pub(crate) use crate::dom::bindings::like::{Maplike, Setlike}; + pub(crate) use crate::dom::bindings::namespace::{ + create_namespace_object, NamespaceObjectClass, + }; + pub(crate) use crate::dom::bindings::proxyhandler; + pub(crate) use crate::dom::bindings::proxyhandler::{ ensure_expando_object, get_expando_object, set_property_descriptor, }; - pub use crate::dom::bindings::record::Record; - pub use crate::dom::bindings::reflector::{DomObjectIteratorWrap, DomObjectWrap, Reflector}; - pub use crate::dom::bindings::root::{Dom, DomSlice, MaybeUnreflectedDom, Root}; - pub use crate::dom::bindings::trace::JSTraceable; - pub use crate::dom::bindings::utils::{ + pub(crate) use crate::dom::bindings::record::Record; + pub(crate) use crate::dom::bindings::reflector::{ + DomObjectIteratorWrap, DomObjectWrap, Reflector, + }; + pub(crate) use crate::dom::bindings::root::{Dom, DomSlice, MaybeUnreflectedDom, Root}; + pub(crate) use crate::dom::bindings::trace::JSTraceable; + pub(crate) use crate::dom::bindings::utils::{ enumerate_global, exception_to_promise, generic_getter, generic_lenient_getter, generic_lenient_setter, generic_method, generic_setter, generic_static_promise_method, get_array_index_from_id, get_property_on_prototype, has_property_on_prototype, resolve_global, trace_global, AsVoidPtr, DOMClass, DOMJSClass, ProtoOrIfaceArray, DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, JSCLASS_DOM_GLOBAL, }; - pub use crate::dom::bindings::weakref::{WeakReferenceable, DOM_WEAK_SLOT}; - pub use crate::dom::types::{AnalyserNode, AudioNode, BaseAudioContext, EventTarget}; - pub use crate::mem::malloc_size_of_including_raw_self; - pub use crate::realms::{AlreadyInRealm, InRealm}; - pub use crate::script_runtime::CanGc; + pub(crate) use crate::dom::bindings::weakref::{WeakReferenceable, DOM_WEAK_SLOT}; + pub(crate) use crate::dom::types::{AnalyserNode, AudioNode, BaseAudioContext, EventTarget}; + pub(crate) use crate::mem::malloc_size_of_including_raw_self; + pub(crate) use crate::realms::{AlreadyInRealm, InRealm}; + pub(crate) use crate::script_runtime::CanGc; } diff --git a/components/script/dom/bindings/inheritance.rs b/components/script/dom/bindings/inheritance.rs index f580aaf61b5..7c5ca4f7a27 100644 --- a/components/script/dom/bindings/inheritance.rs +++ b/components/script/dom/bindings/inheritance.rs @@ -6,14 +6,14 @@ use std::mem; -pub use crate::dom::bindings::codegen::InheritTypes::*; +pub(crate) use crate::dom::bindings::codegen::InheritTypes::*; use crate::dom::bindings::conversions::{get_dom_class, DerivedFrom, IDLInterface}; use crate::dom::bindings::reflector::DomObject; use crate::script_runtime::runtime_is_alive; /// A trait to hold the cast functions of IDL interfaces that either derive /// or are derived from other interfaces. -pub trait Castable: IDLInterface + DomObject + Sized { +pub(crate) trait Castable: IDLInterface + DomObject + Sized { /// Check whether a DOM object implements one of its deriving interfaces. fn is(&self) -> bool where @@ -54,7 +54,7 @@ pub trait Castable: IDLInterface + DomObject + Sized { } #[allow(missing_docs)] -pub trait HasParent { +pub(crate) trait HasParent { #[crown::unrooted_must_root_lint::must_root] type Parent; fn as_parent(&self) -> &Self::Parent; diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs index bf2fc6faa87..168abfc1503 100644 --- a/components/script/dom/bindings/interface.rs +++ b/components/script/dom/bindings/interface.rs @@ -46,22 +46,22 @@ use crate::script_runtime::JSContext as SafeJSContext; /// The class of a non-callback interface object. #[derive(Clone, Copy)] -pub struct NonCallbackInterfaceObjectClass { +pub(crate) struct NonCallbackInterfaceObjectClass { /// The SpiderMonkey class structure. - pub _class: JSClass, + pub(crate) _class: JSClass, /// The prototype id of that interface, used in the hasInstance hook. - pub _proto_id: PrototypeList::ID, + pub(crate) _proto_id: PrototypeList::ID, /// The prototype depth of that interface, used in the hasInstance hook. - pub _proto_depth: u16, + pub(crate) _proto_depth: u16, /// The string representation of the object. - pub representation: &'static [u8], + pub(crate) representation: &'static [u8], } unsafe impl Sync for NonCallbackInterfaceObjectClass {} impl NonCallbackInterfaceObjectClass { /// Create a new `NonCallbackInterfaceObjectClass` structure. - pub const fn new( + pub(crate) const fn new( constructor_behavior: &'static InterfaceConstructorBehavior, string_rep: &'static [u8], proto_id: PrototypeList::ID, @@ -83,21 +83,21 @@ impl NonCallbackInterfaceObjectClass { } /// cast own reference to `JSClass` reference - pub fn as_jsclass(&self) -> &JSClass { + pub(crate) fn as_jsclass(&self) -> &JSClass { unsafe { &*(self as *const _ as *const JSClass) } } } /// A constructor class hook. -pub type ConstructorClassHook = +pub(crate) type ConstructorClassHook = unsafe extern "C" fn(cx: *mut JSContext, argc: u32, vp: *mut Value) -> bool; /// The constructor behavior of a non-callback interface object. -pub struct InterfaceConstructorBehavior(JSClassOps); +pub(crate) struct InterfaceConstructorBehavior(JSClassOps); impl InterfaceConstructorBehavior { /// An interface constructor that unconditionally throws a type error. - pub const fn throw() -> Self { + pub(crate) const fn throw() -> Self { InterfaceConstructorBehavior(JSClassOps { addProperty: None, delProperty: None, @@ -113,7 +113,7 @@ impl InterfaceConstructorBehavior { } /// An interface constructor that calls a native Rust function. - pub const fn call(hook: ConstructorClassHook) -> Self { + pub(crate) const fn call(hook: ConstructorClassHook) -> Self { InterfaceConstructorBehavior(JSClassOps { addProperty: None, delProperty: None, @@ -130,10 +130,10 @@ impl InterfaceConstructorBehavior { } /// A trace hook. -pub type TraceHook = unsafe extern "C" fn(trc: *mut JSTracer, obj: *mut JSObject); +pub(crate) type TraceHook = unsafe extern "C" fn(trc: *mut JSTracer, obj: *mut JSObject); /// Create a global object with the given class. -pub unsafe fn create_global_object( +pub(crate) unsafe fn create_global_object( cx: SafeJSContext, class: &'static JSClass, private: *const libc::c_void, @@ -210,7 +210,7 @@ fn select_compartment(cx: SafeJSContext, options: &mut RealmOptions) { } /// Create and define the interface object of a callback interface. -pub fn create_callback_interface_object( +pub(crate) fn create_callback_interface_object( cx: SafeJSContext, global: HandleObject, constants: &[Guard<&[ConstantSpec]>], @@ -229,7 +229,7 @@ pub fn create_callback_interface_object( /// Create the interface prototype object of a non-callback interface. #[allow(clippy::too_many_arguments)] -pub fn create_interface_prototype_object( +pub(crate) fn create_interface_prototype_object( cx: SafeJSContext, global: HandleObject, proto: HandleObject, @@ -274,7 +274,7 @@ pub fn create_interface_prototype_object( /// Create and define the interface object of a non-callback interface. #[allow(clippy::too_many_arguments)] -pub fn create_noncallback_interface_object( +pub(crate) fn create_noncallback_interface_object( cx: SafeJSContext, global: HandleObject, proto: HandleObject, @@ -317,7 +317,7 @@ pub fn create_noncallback_interface_object( } /// Create and define the named constructors of a non-callback interface. -pub fn create_named_constructors( +pub(crate) fn create_named_constructors( cx: SafeJSContext, global: HandleObject, named_constructors: &[(ConstructorClassHook, &CStr, u32)], @@ -347,7 +347,7 @@ pub fn create_named_constructors( /// Create a new object with a unique type. #[allow(clippy::too_many_arguments)] -pub fn create_object( +pub(crate) fn create_object( cx: SafeJSContext, global: HandleObject, proto: HandleObject, @@ -367,7 +367,7 @@ pub fn create_object( } /// Conditionally define constants on an object. -pub fn define_guarded_constants( +pub(crate) fn define_guarded_constants( cx: SafeJSContext, obj: HandleObject, constants: &[Guard<&[ConstantSpec]>], @@ -381,7 +381,7 @@ pub fn define_guarded_constants( } /// Conditionally define methods on an object. -pub fn define_guarded_methods( +pub(crate) fn define_guarded_methods( cx: SafeJSContext, obj: HandleObject, methods: &[Guard<&'static [JSFunctionSpec]>], @@ -397,7 +397,7 @@ pub fn define_guarded_methods( } /// Conditionally define properties on an object. -pub fn define_guarded_properties( +pub(crate) fn define_guarded_properties( cx: SafeJSContext, obj: HandleObject, properties: &[Guard<&'static [JSPropertySpec]>], @@ -414,7 +414,7 @@ pub fn define_guarded_properties( /// Returns whether an interface with exposure set given by `globals` should /// be exposed in the global object `obj`. -pub fn is_exposed_in(object: HandleObject, globals: Globals) -> bool { +pub(crate) fn is_exposed_in(object: HandleObject, globals: Globals) -> bool { unsafe { let unwrapped = UncheckedUnwrapObject(object.get(), /* stopAtWindowProxy = */ false); let dom_class = get_dom_class(unwrapped).unwrap(); @@ -424,7 +424,7 @@ pub fn is_exposed_in(object: HandleObject, globals: Globals) -> bool { /// Define a property with a given name on the global object. Should be called /// through the resolve hook. -pub fn define_on_global_object( +pub(crate) fn define_on_global_object( cx: SafeJSContext, global: HandleObject, name: &CStr, @@ -529,7 +529,7 @@ unsafe extern "C" fn non_new_constructor( false } -pub enum ProtoOrIfaceIndex { +pub(crate) enum ProtoOrIfaceIndex { ID(PrototypeList::ID), Constructor(PrototypeList::Constructor), } @@ -543,7 +543,7 @@ impl From for usize { } } -pub fn get_per_interface_object_handle( +pub(crate) fn get_per_interface_object_handle( cx: SafeJSContext, global: HandleObject, id: ProtoOrIfaceIndex, @@ -567,7 +567,7 @@ pub fn get_per_interface_object_handle( } } -pub fn define_dom_interface( +pub(crate) fn define_dom_interface( cx: SafeJSContext, global: HandleObject, id: ProtoOrIfaceIndex, @@ -597,7 +597,7 @@ fn get_proto_id_for_new_target(new_target: HandleObject) -> Option { +pub(crate) struct IterableIterator { reflector: Reflector, iterable: Dom, type_: IteratorType, @@ -65,7 +65,7 @@ pub struct IterableIterator { impl IterableIterator { /// Create a new iterator instance for the provided iterable DOM interface. - pub fn new(iterable: &T, type_: IteratorType) -> DomRoot { + pub(crate) fn new(iterable: &T, type_: IteratorType) -> DomRoot { let iterator = Box::new(IterableIterator { reflector: Reflector::new(), type_, @@ -77,7 +77,7 @@ impl IterableIterator { /// Return the next value from the iterable object. #[allow(non_snake_case)] - pub fn Next(&self, cx: JSContext) -> Fallible> { + pub(crate) fn Next(&self, cx: JSContext) -> Fallible> { let index = self.index.get(); rooted!(in(*cx) let mut value = UndefinedValue()); rooted!(in(*cx) let mut rval = ptr::null_mut::()); diff --git a/components/script/dom/bindings/like.rs b/components/script/dom/bindings/like.rs index 9aaefd48a53..23e075629b8 100644 --- a/components/script/dom/bindings/like.rs +++ b/components/script/dom/bindings/like.rs @@ -20,7 +20,7 @@ use crate::dom::bindings::cell::DomRefCell; /// /// In case you use a type that implements Setlike as underlying storage it's recommended to use `setlike` macro. // In webidl: `setlike` -pub trait Setlike { +pub(crate) trait Setlike { /// The type of the key of the set. type Key: ToJSValConvertible + Clone; // clone is for impl Maplike for T @@ -111,7 +111,7 @@ where /// Usage: /// ```rust -/// pub struct TestBindingSetlike { +/// pub(crate) struct TestBindingSetlike { /// // setlike /// internal: DomRefCell>, /// } @@ -161,7 +161,7 @@ macro_rules! setlike { /// /// In case you use a type that implements Maplike as underlying storage it's recommended to use `maplike` macro. // In webidl: `maplike` -pub trait Maplike { +pub(crate) trait Maplike { /// The type of the key of the map. type Key: ToJSValConvertible; /// The type of the value of the map. @@ -248,7 +248,7 @@ where /// Usage: /// ```rust -/// pub struct TestBindingMaplike { +/// pub(crate) struct TestBindingMaplike { /// // maplike /// internal: DomRefCell>, /// } diff --git a/components/script/dom/bindings/mod.rs b/components/script/dom/bindings/mod.rs index 633763f1ba6..62d99487bbd 100644 --- a/components/script/dom/bindings/mod.rs +++ b/components/script/dom/bindings/mod.rs @@ -134,65 +134,67 @@ #![deny(missing_docs)] #![deny(non_snake_case)] -pub mod buffer_source; -pub mod callback; -pub mod cell; -pub mod constant; -pub mod constructor; -pub mod conversions; -pub mod error; -pub mod finalize; -pub mod frozenarray; -pub mod function; -pub mod guard; -pub mod import; -pub mod inheritance; -pub mod interface; -pub mod iterable; -pub mod like; -pub mod namespace; -pub mod num; -pub mod principals; -pub mod proxyhandler; -pub mod record; -pub mod refcounted; -pub mod reflector; -pub mod root; -pub mod serializable; -pub mod settings_stack; -pub mod str; -pub mod structuredclone; -pub mod trace; -pub mod transferable; -pub mod utils; -pub mod weakref; -pub mod xmlname; +pub(crate) mod buffer_source; +pub(crate) mod callback; +#[allow(dead_code)] +pub(crate) mod cell; +pub(crate) mod constant; +pub(crate) mod constructor; +pub(crate) mod conversions; +pub(crate) mod error; +pub(crate) mod finalize; +pub(crate) mod frozenarray; +pub(crate) mod function; +pub(crate) mod guard; +pub(crate) mod import; +pub(crate) mod inheritance; +pub(crate) mod interface; +pub(crate) mod iterable; +pub(crate) mod like; +pub(crate) mod namespace; +pub(crate) mod num; +pub(crate) mod principals; +pub(crate) mod proxyhandler; +pub(crate) mod record; +pub(crate) mod refcounted; +pub(crate) mod reflector; +pub(crate) mod root; +pub(crate) mod serializable; +pub(crate) mod settings_stack; +#[allow(dead_code)] +pub(crate) mod str; +pub(crate) mod structuredclone; +pub(crate) mod trace; +pub(crate) mod transferable; +pub(crate) mod utils; +pub(crate) mod weakref; +pub(crate) mod xmlname; /// Generated JS-Rust bindings. #[allow(missing_docs, non_snake_case)] -pub mod codegen { - pub mod DomTypeHolder { +pub(crate) mod codegen { + pub(crate) mod DomTypeHolder { include!(concat!(env!("OUT_DIR"), "/DomTypeHolder.rs")); } - pub mod DomTypes { + pub(crate) mod DomTypes { include!(concat!(env!("OUT_DIR"), "/DomTypes.rs")); } #[allow(dead_code)] - pub mod Bindings { + pub(crate) mod Bindings { include!(concat!(env!("OUT_DIR"), "/Bindings/mod.rs")); } - pub mod InterfaceObjectMap { + pub(crate) mod InterfaceObjectMap { include!(concat!(env!("OUT_DIR"), "/InterfaceObjectMap.rs")); } #[allow(dead_code, unused_imports, clippy::enum_variant_names)] - pub mod InheritTypes { + pub(crate) mod InheritTypes { include!(concat!(env!("OUT_DIR"), "/InheritTypes.rs")); } #[allow(clippy::upper_case_acronyms)] - pub mod PrototypeList { + pub(crate) mod PrototypeList { include!(concat!(env!("OUT_DIR"), "/PrototypeList.rs")); } - pub mod RegisterBindings { + pub(crate) mod RegisterBindings { include!(concat!(env!("OUT_DIR"), "/RegisterBindings.rs")); } #[allow( @@ -203,7 +205,7 @@ pub mod codegen { clippy::upper_case_acronyms, clippy::enum_variant_names )] - pub mod UnionTypes { + pub(crate) mod UnionTypes { include!(concat!(env!("OUT_DIR"), "/UnionTypes.rs")); } } diff --git a/components/script/dom/bindings/namespace.rs b/components/script/dom/bindings/namespace.rs index 1afd62b4978..3f5e9d846d5 100644 --- a/components/script/dom/bindings/namespace.rs +++ b/components/script/dom/bindings/namespace.rs @@ -17,13 +17,13 @@ use crate::script_runtime::JSContext; /// The class of a namespace object. #[derive(Clone, Copy)] -pub struct NamespaceObjectClass(JSClass); +pub(crate) struct NamespaceObjectClass(JSClass); unsafe impl Sync for NamespaceObjectClass {} impl NamespaceObjectClass { /// Create a new `NamespaceObjectClass` structure. - pub const unsafe fn new(name: &'static CStr) -> Self { + pub(crate) const unsafe fn new(name: &'static CStr) -> Self { NamespaceObjectClass(JSClass { name: name.as_ptr(), flags: 0, @@ -37,7 +37,7 @@ impl NamespaceObjectClass { /// Create a new namespace object. #[allow(clippy::too_many_arguments)] -pub fn create_namespace_object( +pub(crate) fn create_namespace_object( cx: JSContext, global: HandleObject, proto: HandleObject, diff --git a/components/script/dom/bindings/num.rs b/components/script/dom/bindings/num.rs index 58b12f6cb7f..59b89a29e3e 100644 --- a/components/script/dom/bindings/num.rs +++ b/components/script/dom/bindings/num.rs @@ -12,11 +12,11 @@ use num_traits::Float; /// Encapsulates the IDL restricted float type. #[derive(Clone, Copy, Eq, JSTraceable, PartialEq)] -pub struct Finite(T); +pub(crate) struct Finite(T); impl Finite { /// Create a new `Finite` safely. - pub fn new(value: T) -> Option> { + pub(crate) fn new(value: T) -> Option> { if value.is_finite() { Some(Finite(value)) } else { @@ -26,7 +26,7 @@ impl Finite { /// Create a new `Finite`. #[inline] - pub fn wrap(value: T) -> Finite { + pub(crate) fn wrap(value: T) -> Finite { assert!( value.is_finite(), "Finite doesn't encapsulate unrestricted value." diff --git a/components/script/dom/bindings/principals.rs b/components/script/dom/bindings/principals.rs index 30d309a6e37..d6f3e10981c 100644 --- a/components/script/dom/bindings/principals.rs +++ b/components/script/dom/bindings/principals.rs @@ -22,10 +22,10 @@ use super::structuredclone::StructuredCloneTags; /// An owned reference to Servo's `JSPrincipals` instance. #[repr(transparent)] -pub struct ServoJSPrincipals(NonNull); +pub(crate) struct ServoJSPrincipals(NonNull); impl ServoJSPrincipals { - pub fn new(origin: &MutableOrigin) -> Self { + pub(crate) fn new(origin: &MutableOrigin) -> Self { unsafe { let private: Box = Box::new(origin.clone()); let raw = CreateRustJSPrincipals(&PRINCIPALS_CALLBACKS, Box::into_raw(private) as _); @@ -38,24 +38,24 @@ impl ServoJSPrincipals { /// Construct `Self` from a raw `*mut JSPrincipals`, incrementing its /// reference count. #[inline] - pub unsafe fn from_raw_nonnull(raw: NonNull) -> Self { + pub(crate) unsafe fn from_raw_nonnull(raw: NonNull) -> Self { JS_HoldPrincipals(raw.as_ptr()); Self(raw) } #[inline] - pub unsafe fn origin(&self) -> MutableOrigin { + pub(crate) unsafe fn origin(&self) -> MutableOrigin { let origin = GetRustJSPrincipalsPrivate(self.0.as_ptr()) as *mut MutableOrigin; (*origin).clone() } #[inline] - pub fn as_raw_nonnull(&self) -> NonNull { + pub(crate) fn as_raw_nonnull(&self) -> NonNull { self.0 } #[inline] - pub fn as_raw(&self) -> *mut JSPrincipals { + pub(crate) fn as_raw(&self) -> *mut JSPrincipals { self.0.as_ptr() } } @@ -78,7 +78,7 @@ impl Drop for ServoJSPrincipals { /// A borrowed reference to Servo's `JSPrincipals` instance. Does not update the /// reference count on creation and deletion. -pub struct ServoJSPrincipalsRef<'a>(ManuallyDrop, PhantomData<&'a ()>); +pub(crate) struct ServoJSPrincipalsRef<'a>(ManuallyDrop, PhantomData<&'a ()>); impl ServoJSPrincipalsRef<'_> { /// Construct `Self` from a raw `NonNull`. @@ -90,7 +90,7 @@ impl ServoJSPrincipalsRef<'_> { /// returned `ServoJSPrincipalsRef` object or any clones are not used past /// the lifetime of the wrapped object. #[inline] - pub unsafe fn from_raw_nonnull(raw: NonNull) -> Self { + pub(crate) unsafe fn from_raw_nonnull(raw: NonNull) -> Self { // Don't use `ServoJSPrincipals::from_raw_nonnull`; we don't want to // update the reference count Self(ManuallyDrop::new(ServoJSPrincipals(raw)), PhantomData) @@ -103,7 +103,7 @@ impl ServoJSPrincipalsRef<'_> { /// The behavior is undefined if `raw` is null. See also /// [`Self::from_raw_nonnull`]. #[inline] - pub unsafe fn from_raw_unchecked(raw: *mut JSPrincipals) -> Self { + pub(crate) unsafe fn from_raw_unchecked(raw: *mut JSPrincipals) -> Self { Self::from_raw_nonnull(NonNull::new_unchecked(raw)) } } @@ -125,12 +125,12 @@ impl Deref for ServoJSPrincipalsRef<'_> { } #[allow(unused)] -pub unsafe extern "C" fn destroy_servo_jsprincipal(principals: *mut JSPrincipals) { +pub(crate) unsafe extern "C" fn destroy_servo_jsprincipal(principals: *mut JSPrincipals) { Box::from_raw(GetRustJSPrincipalsPrivate(principals) as *mut MutableOrigin); DestroyRustJSPrincipals(principals); } -pub unsafe extern "C" fn write_jsprincipal( +pub(crate) unsafe extern "C" fn write_jsprincipal( principal: *mut JSPrincipals, _cx: *mut JSContext, writer: *mut JSStructuredCloneWriter, @@ -155,7 +155,7 @@ pub unsafe extern "C" fn write_jsprincipal( true } -pub unsafe extern "C" fn read_jsprincipal( +pub(crate) unsafe extern "C" fn read_jsprincipal( _cx: *mut JSContext, reader: *mut JSStructuredCloneReader, principals: *mut *mut JSPrincipals, @@ -192,7 +192,7 @@ unsafe extern "C" fn principals_is_system_or_addon_principal(_: *mut JSPrincipal } //TODO is same_origin_domain equivalent to subsumes for our purposes -pub unsafe extern "C" fn subsumes(obj: *mut JSPrincipals, other: *mut JSPrincipals) -> bool { +pub(crate) unsafe extern "C" fn subsumes(obj: *mut JSPrincipals, other: *mut JSPrincipals) -> bool { match (NonNull::new(obj), NonNull::new(other)) { (Some(obj), Some(other)) => { let obj = ServoJSPrincipalsRef::from_raw_nonnull(obj); diff --git a/components/script/dom/bindings/proxyhandler.rs b/components/script/dom/bindings/proxyhandler.rs index c3520c6d8ca..0111dc27509 100644 --- a/components/script/dom/bindings/proxyhandler.rs +++ b/components/script/dom/bindings/proxyhandler.rs @@ -47,7 +47,7 @@ use crate::realms::{AlreadyInRealm, InRealm}; use crate::script_runtime::JSContext as SafeJSContext; /// Determine if this id shadows any existing properties for this proxy. -pub unsafe extern "C" fn shadow_check_callback( +pub(crate) unsafe extern "C" fn shadow_check_callback( cx: *mut JSContext, object: RawHandleObject, id: RawHandleId, @@ -74,7 +74,7 @@ pub unsafe extern "C" fn shadow_check_callback( } /// Initialize the infrastructure for DOM proxy objects. -pub unsafe fn init() { +pub(crate) unsafe fn init() { SetDOMProxyInformation( GetProxyHandlerFamily(), Some(shadow_check_callback), @@ -83,7 +83,7 @@ pub unsafe fn init() { } /// Defines an expando on the given `proxy`. -pub unsafe extern "C" fn define_property( +pub(crate) unsafe extern "C" fn define_property( cx: *mut JSContext, proxy: RawHandleObject, id: RawHandleId, @@ -96,7 +96,7 @@ pub unsafe extern "C" fn define_property( } /// Deletes an expando off the given `proxy`. -pub unsafe extern "C" fn delete( +pub(crate) unsafe extern "C" fn delete( cx: *mut JSContext, proxy: RawHandleObject, id: RawHandleId, @@ -113,7 +113,7 @@ pub unsafe extern "C" fn delete( } /// Controls whether the Extensible bit can be changed -pub unsafe extern "C" fn prevent_extensions( +pub(crate) unsafe extern "C" fn prevent_extensions( _cx: *mut JSContext, _proxy: RawHandleObject, result: *mut ObjectOpResult, @@ -123,7 +123,7 @@ pub unsafe extern "C" fn prevent_extensions( } /// Reports whether the object is Extensible -pub unsafe extern "C" fn is_extensible( +pub(crate) unsafe extern "C" fn is_extensible( _cx: *mut JSContext, _proxy: RawHandleObject, succeeded: *mut bool, @@ -141,7 +141,7 @@ pub unsafe extern "C" fn is_extensible( /// This implementation always handles the case of the ordinary /// `[[GetPrototypeOf]]` behavior. An alternative implementation will be /// necessary for maybe-cross-origin objects. -pub unsafe extern "C" fn get_prototype_if_ordinary( +pub(crate) unsafe extern "C" fn get_prototype_if_ordinary( _: *mut JSContext, proxy: RawHandleObject, is_ordinary: *mut bool, @@ -153,7 +153,7 @@ pub unsafe extern "C" fn get_prototype_if_ordinary( } /// Get the expando object, or null if there is none. -pub unsafe fn get_expando_object(obj: RawHandleObject, mut expando: MutableHandleObject) { +pub(crate) unsafe fn get_expando_object(obj: RawHandleObject, mut expando: MutableHandleObject) { assert!(is_dom_proxy(obj.get())); let val = &mut UndefinedValue(); GetProxyPrivate(obj.get(), val); @@ -166,7 +166,7 @@ pub unsafe fn get_expando_object(obj: RawHandleObject, mut expando: MutableHandl /// Get the expando object, or create it if it doesn't exist yet. /// Fails on JSAPI failure. -pub unsafe fn ensure_expando_object( +pub(crate) unsafe fn ensure_expando_object( cx: *mut JSContext, obj: RawHandleObject, mut expando: MutableHandleObject, @@ -187,7 +187,7 @@ pub unsafe fn ensure_expando_object( /// Set the property descriptor's object to `obj` and set it to enumerable, /// and writable if `readonly` is true. -pub fn set_property_descriptor( +pub(crate) fn set_property_descriptor( desc: MutableHandle, value: HandleValue, attrs: u32, @@ -200,7 +200,10 @@ pub fn set_property_descriptor( } /// -pub unsafe fn is_platform_object_same_origin(cx: SafeJSContext, obj: RawHandleObject) -> bool { +pub(crate) unsafe fn is_platform_object_same_origin( + cx: SafeJSContext, + obj: RawHandleObject, +) -> bool { let subject_realm = get_context_realm(*cx); let obj_realm = GetObjectRealmOrNull(*obj); assert!(!obj_realm.is_null()); @@ -236,7 +239,11 @@ pub unsafe fn is_platform_object_same_origin(cx: SafeJSContext, obj: RawHandleOb /// What this function does corresponds to the operations in /// denoted as /// "Throw a `SecurityError` DOMException". -pub unsafe fn report_cross_origin_denial(cx: SafeJSContext, id: RawHandleId, access: &str) -> bool { +pub(crate) unsafe fn report_cross_origin_denial( + cx: SafeJSContext, + id: RawHandleId, + access: &str, +) -> bool { debug!( "permission denied to {} property {} on cross-origin object", access, @@ -267,9 +274,9 @@ unsafe fn id_to_source(cx: SafeJSContext, id: RawHandleId) -> Option /// [`CrossOriginProperties(O)`]. /// /// [`CrossOriginProperties(O)`]: https://html.spec.whatwg.org/multipage/#crossoriginproperties-(-o-) -pub struct CrossOriginProperties { - pub attributes: &'static [JSPropertySpec], - pub methods: &'static [JSFunctionSpec], +pub(crate) struct CrossOriginProperties { + pub(crate) attributes: &'static [JSPropertySpec], + pub(crate) methods: &'static [JSFunctionSpec], } impl CrossOriginProperties { @@ -287,7 +294,7 @@ impl CrossOriginProperties { /// Implementation of [`CrossOriginOwnPropertyKeys`]. /// /// [`CrossOriginOwnPropertyKeys`]: https://html.spec.whatwg.org/multipage/#crossoriginownpropertykeys-(-o-) -pub unsafe fn cross_origin_own_property_keys( +pub(crate) unsafe fn cross_origin_own_property_keys( cx: SafeJSContext, _proxy: RawHandleObject, cross_origin_properties: &'static CrossOriginProperties, @@ -312,7 +319,7 @@ pub unsafe fn cross_origin_own_property_keys( /// Implementation of `[[Set]]` for [`Location`]. /// /// [`Location`]: https://html.spec.whatwg.org/multipage/#location-set -pub unsafe extern "C" fn maybe_cross_origin_set_rawcx( +pub(crate) unsafe extern "C" fn maybe_cross_origin_set_rawcx( cx: *mut JSContext, proxy: RawHandleObject, id: RawHandleId, @@ -355,7 +362,7 @@ pub unsafe extern "C" fn maybe_cross_origin_set_rawcx( ) } -pub unsafe extern "C" fn maybe_cross_origin_get_prototype_if_ordinary_rawcx( +pub(crate) unsafe extern "C" fn maybe_cross_origin_get_prototype_if_ordinary_rawcx( _: *mut JSContext, _proxy: RawHandleObject, is_ordinary: *mut bool, @@ -369,7 +376,7 @@ pub unsafe extern "C" fn maybe_cross_origin_get_prototype_if_ordinary_rawcx( /// Implementation of `[[GetPrototypeOf]]` for [`Location`]. /// /// [`Location`]: https://html.spec.whatwg.org/multipage/#location-getprototypeof -pub unsafe fn maybe_cross_origin_get_prototype( +pub(crate) unsafe fn maybe_cross_origin_get_prototype( cx: SafeJSContext, proxy: RawHandleObject, get_proto_object: unsafe fn(cx: SafeJSContext, global: HandleObject, rval: MutableHandleObject), @@ -396,7 +403,7 @@ pub unsafe fn maybe_cross_origin_get_prototype( /// /// [`Location`]: https://html.spec.whatwg.org/multipage/#location-setprototypeof /// [`WindowProxy`]: https://html.spec.whatwg.org/multipage/#windowproxy-setprototypeof -pub unsafe extern "C" fn maybe_cross_origin_set_prototype_rawcx( +pub(crate) unsafe extern "C" fn maybe_cross_origin_set_prototype_rawcx( cx: *mut JSContext, proxy: RawHandleObject, proto: RawHandleObject, @@ -431,7 +438,7 @@ pub unsafe extern "C" fn maybe_cross_origin_set_prototype_rawcx( /// for a maybe-cross-origin object. /// /// [`CrossOriginGet`]: https://html.spec.whatwg.org/multipage/#crossoriginget-(-o,-p,-receiver-) -pub unsafe fn cross_origin_get( +pub(crate) unsafe fn cross_origin_get( cx: SafeJSContext, proxy: RawHandleObject, receiver: RawHandleValue, @@ -497,7 +504,7 @@ pub unsafe fn cross_origin_get( /// for a maybe-cross-origin object. /// /// [`CrossOriginSet`]: https://html.spec.whatwg.org/multipage/#crossoriginset-(-o,-p,-v,-receiver-) -pub unsafe fn cross_origin_set( +pub(crate) unsafe fn cross_origin_set( cx: SafeJSContext, proxy: RawHandleObject, id: RawHandleId, @@ -588,7 +595,7 @@ fn is_data_descriptor(d: &PropertyDescriptor) -> bool { /// /// `cx` and `proxy` are expected to be different-Realm here. `proxy` is a proxy /// for a maybe-cross-origin object. -pub unsafe fn cross_origin_has_own( +pub(crate) unsafe fn cross_origin_has_own( cx: SafeJSContext, _proxy: RawHandleObject, cross_origin_properties: &'static CrossOriginProperties, @@ -614,7 +621,7 @@ pub unsafe fn cross_origin_has_own( /// for a maybe-cross-origin object. /// /// [`CrossOriginGetOwnPropertyHelper`]: https://html.spec.whatwg.org/multipage/#crossorigingetownpropertyhelper-(-o,-p-) -pub unsafe fn cross_origin_get_own_property_helper( +pub(crate) unsafe fn cross_origin_get_own_property_helper( cx: SafeJSContext, proxy: RawHandleObject, cross_origin_properties: &'static CrossOriginProperties, @@ -640,7 +647,7 @@ pub unsafe fn cross_origin_get_own_property_helper( /// for a maybe-cross-origin object. /// /// [`CrossOriginPropertyFallback`]: https://html.spec.whatwg.org/multipage/#crossoriginpropertyfallback-(-p-) -pub unsafe fn cross_origin_property_fallback( +pub(crate) unsafe fn cross_origin_property_fallback( cx: SafeJSContext, _proxy: RawHandleObject, id: RawHandleId, diff --git a/components/script/dom/bindings/record.rs b/components/script/dom/bindings/record.rs index c437b8955f7..32388c9e187 100644 --- a/components/script/dom/bindings/record.rs +++ b/components/script/dom/bindings/record.rs @@ -23,7 +23,7 @@ use js::rust::{HandleId, HandleValue, IdVector, MutableHandleValue}; use crate::dom::bindings::conversions::jsid_to_string; use crate::dom::bindings::str::{ByteString, DOMString, USVString}; -pub trait RecordKey: Eq + Hash + Sized { +pub(crate) trait RecordKey: Eq + Hash + Sized { fn to_utf16_vec(&self) -> Vec; unsafe fn from_id(cx: *mut JSContext, id: HandleId) -> Result, ()>; } @@ -71,14 +71,14 @@ impl RecordKey for ByteString { /// The `Record` (open-ended dictionary) type. #[derive(Clone, JSTraceable)] -pub struct Record { +pub(crate) struct Record { #[custom_trace] map: IndexMap, } impl Record { /// Create an empty `Record`. - pub fn new() -> Self { + pub(crate) fn new() -> Self { Record { map: IndexMap::new(), } diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index 97a181f1c2f..d3f55012534 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -47,10 +47,10 @@ mod dummy { use std::rc::Rc; use super::LiveDOMReferences; - thread_local!(pub static LIVE_REFERENCES: Rc>> = + thread_local!(pub(crate) static LIVE_REFERENCES: Rc>> = Rc::new(RefCell::new(None))); } -pub use self::dummy::LIVE_REFERENCES; +pub(crate) use self::dummy::LIVE_REFERENCES; /// A pointer to a Rust DOM object that needs to be destroyed. #[derive(MallocSizeOf)] @@ -84,7 +84,7 @@ impl TrustedPromise { /// be prevented from being GCed for the duration of the resulting `TrustedPromise` object's /// lifetime. #[allow(crown::unrooted_must_root)] - pub fn new(promise: Rc) -> TrustedPromise { + pub(crate) fn new(promise: Rc) -> TrustedPromise { LIVE_REFERENCES.with(|r| { let r = r.borrow(); let live_references = r.as_ref().unwrap(); @@ -100,7 +100,7 @@ impl TrustedPromise { /// Obtain a usable DOM Promise from a pinned `TrustedPromise` value. Fails if used on /// a different thread than the original value from which this `TrustedPromise` was /// obtained. - pub fn root(self) -> Rc { + pub(crate) fn root(self) -> Rc { LIVE_REFERENCES.with(|r| { let r = r.borrow(); let live_references = r.as_ref().unwrap(); @@ -134,7 +134,7 @@ impl TrustedPromise { /// A task which will reject the promise. #[allow(crown::unrooted_must_root)] - pub fn reject_task(self, error: Error) -> impl TaskOnce { + pub(crate) fn reject_task(self, error: Error) -> impl TaskOnce { let this = self; task!(reject_promise: move || { debug!("Rejecting promise."); @@ -144,7 +144,7 @@ impl TrustedPromise { /// A task which will resolve the promise. #[allow(crown::unrooted_must_root)] - pub fn resolve_task(self, value: T) -> impl TaskOnce + pub(crate) fn resolve_task(self, value: T) -> impl TaskOnce where T: ToJSValConvertible + Send, { @@ -162,7 +162,7 @@ impl TrustedPromise { /// `Trusted` instance. #[crown::unrooted_must_root_lint::allow_unrooted_interior] #[derive(MallocSizeOf)] -pub struct Trusted { +pub(crate) struct Trusted { /// A pointer to the Rust DOM object of type T, but void to allow /// sending `Trusted` between threads, regardless of T's sendability. #[conditional_malloc_size_of] @@ -178,7 +178,7 @@ impl Trusted { /// Create a new `Trusted` instance from an existing DOM pointer. The DOM object will /// be prevented from being GCed for the duration of the resulting `Trusted` object's /// lifetime. - pub fn new(ptr: &T) -> Trusted { + pub(crate) fn new(ptr: &T) -> Trusted { fn add_live_reference( ptr: *const libc::c_void, ) -> (Arc, *const LiveDOMReferences) { @@ -201,7 +201,7 @@ impl Trusted { /// Obtain a usable DOM pointer from a pinned `Trusted` value. Fails if used on /// a different thread than the original value from which this `Trusted` was /// obtained. - pub fn root(&self) -> DomRoot { + pub(crate) fn root(&self) -> DomRoot { fn validate(owner_thread: *const LiveDOMReferences) { assert!(LIVE_REFERENCES.with(|r| { let r = r.borrow(); @@ -227,7 +227,7 @@ impl Clone for Trusted { /// The set of live, pinned DOM objects that are currently prevented /// from being garbage collected due to outstanding references. #[allow(crown::unrooted_must_root)] -pub struct LiveDOMReferences { +pub(crate) struct LiveDOMReferences { // keyed on pointer to Rust DOM object reflectable_table: RefCell>>, promise_table: RefCell>>>, @@ -235,7 +235,7 @@ pub struct LiveDOMReferences { impl LiveDOMReferences { /// Set up the thread-local data required for storing the outstanding DOM references. - pub fn initialize() { + pub(crate) fn initialize() { LIVE_REFERENCES.with(|r| { *r.borrow_mut() = Some(LiveDOMReferences { reflectable_table: RefCell::new(HashMap::new()), @@ -244,7 +244,7 @@ impl LiveDOMReferences { }); } - pub fn destruct() { + pub(crate) fn destruct() { LIVE_REFERENCES.with(|r| { *r.borrow_mut() = None; }); @@ -302,7 +302,7 @@ fn remove_nulls(table: &mut HashMap>) { /// A JSTraceDataOp for tracing reflectors held in LIVE_REFERENCES #[allow(crown::unrooted_must_root)] -pub unsafe fn trace_refcounted_objects(tracer: *mut JSTracer) { +pub(crate) unsafe fn trace_refcounted_objects(tracer: *mut JSTracer) { trace!("tracing live refcounted references"); LIVE_REFERENCES.with(|r| { let r = r.borrow(); diff --git a/components/script/dom/bindings/reflector.rs b/components/script/dom/bindings/reflector.rs index 3a3743a07c0..eb15172aaaa 100644 --- a/components/script/dom/bindings/reflector.rs +++ b/components/script/dom/bindings/reflector.rs @@ -19,7 +19,7 @@ use crate::script_runtime::{CanGc, JSContext}; /// Create the reflector for a new DOM object and yield ownership to the /// reflector. -pub fn reflect_dom_object(obj: Box, global: &U, can_gc: CanGc) -> DomRoot +pub(crate) fn reflect_dom_object(obj: Box, global: &U, can_gc: CanGc) -> DomRoot where T: DomObject + DomObjectWrap, U: DerivedFrom, @@ -28,7 +28,7 @@ where unsafe { T::WRAP(GlobalScope::get_cx(), global_scope, None, obj, can_gc) } } -pub fn reflect_dom_object_with_proto( +pub(crate) fn reflect_dom_object_with_proto( obj: Box, global: &U, proto: Option, @@ -47,7 +47,7 @@ where #[derive(MallocSizeOf)] #[crown::unrooted_must_root_lint::must_root] // If you're renaming or moving this field, update the path in plugins::reflector as well -pub struct Reflector { +pub(crate) struct Reflector { #[ignore_malloc_size_of = "defined and measured in rust-mozjs"] object: Heap<*mut JSObject>, } @@ -62,7 +62,7 @@ impl PartialEq for Reflector { impl Reflector { /// Get the reflector. #[inline] - pub fn get_jsobject(&self) -> HandleObject { + pub(crate) fn get_jsobject(&self) -> HandleObject { // We're rooted, so it's safe to hand out a handle to object in Heap unsafe { HandleObject::from_raw(self.object.handle()) } } @@ -72,7 +72,7 @@ impl Reflector { /// # Safety /// /// The provided [`JSObject`] pointer must point to a valid [`JSObject`]. - pub unsafe fn set_jsobject(&self, object: *mut JSObject) { + pub(crate) unsafe fn set_jsobject(&self, object: *mut JSObject) { assert!(self.object.get().is_null()); assert!(!object.is_null()); self.object.set(object); @@ -81,14 +81,14 @@ impl Reflector { /// Return a pointer to the memory location at which the JS reflector /// object is stored. Used to root the reflector, as /// required by the JSAPI rooting APIs. - pub fn rootable(&self) -> &Heap<*mut JSObject> { + pub(crate) fn rootable(&self) -> &Heap<*mut JSObject> { &self.object } /// Create an uninitialized `Reflector`. // These are used by the bindings and do not need `default()` functions. #[allow(clippy::new_without_default)] - pub fn new() -> Reflector { + pub(crate) fn new() -> Reflector { Reflector { object: Heap::default(), } @@ -96,7 +96,7 @@ impl Reflector { } /// A trait to provide access to the `Reflector` for a DOM object. -pub trait DomObject: JSTraceable + 'static { +pub(crate) trait DomObject: JSTraceable + 'static { /// Returns the receiver's reflector. fn reflector(&self) -> &Reflector; @@ -119,7 +119,7 @@ impl DomObject for Reflector { } /// A trait to initialize the `Reflector` for a DOM object. -pub trait MutDomObject: DomObject { +pub(crate) trait MutDomObject: DomObject { /// Initializes the Reflector /// /// # Safety @@ -135,7 +135,7 @@ impl MutDomObject for Reflector { } /// A trait to provide a function pointer to wrap function for DOM objects. -pub trait DomObjectWrap: Sized + DomObject { +pub(crate) trait DomObjectWrap: Sized + DomObject { /// Function pointer to the general wrap function type #[allow(clippy::type_complexity)] const WRAP: unsafe fn( @@ -149,7 +149,7 @@ pub trait DomObjectWrap: Sized + DomObject { /// A trait to provide a function pointer to wrap function for /// DOM iterator interfaces. -pub trait DomObjectIteratorWrap: DomObjectWrap + JSTraceable + Iterable { +pub(crate) trait DomObjectIteratorWrap: DomObjectWrap + JSTraceable + Iterable { /// Function pointer to the wrap function for `IterableIterator` #[allow(clippy::type_complexity)] const ITER_WRAP: unsafe fn( diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index c934dae7fbf..b182c917b98 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -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 { +pub(crate) struct Root { /// 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 = Root>; +pub(crate) type DomRoot = Root>; impl DomRoot { /// Cast a DOM object root upwards to one of the interfaces it derives from. - pub fn upcast(root: DomRoot) -> DomRoot + pub(crate) fn upcast(root: DomRoot) -> DomRoot where U: Castable, T: DerivedFrom, @@ -173,7 +173,7 @@ impl DomRoot { } /// Cast a DOM object root downwards to one of the interfaces it might implement. - pub fn downcast(root: DomRoot) -> Option> + pub(crate) fn downcast(root: DomRoot) -> Option> where U: DerivedFrom, { @@ -187,7 +187,7 @@ impl DomRoot { impl DomRoot { /// Generate a new root from a reference - pub fn from_ref(unrooted: &T) -> DomRoot { + pub(crate) fn from_ref(unrooted: &T) -> DomRoot { 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>, } thread_local!(static STACK_ROOTS: Cell> = 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 +pub(crate) trait DomSlice 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 { +pub(crate) struct Dom { ptr: ptr::NonNull, } @@ -354,7 +354,7 @@ impl Dom { /// # Safety /// /// The `self` parameter to this method must meet all the requirements of [`ptr::NonNull::as_ref`]. - pub unsafe fn to_layout(&self) -> LayoutDom { + pub(crate) unsafe fn to_layout(&self) -> LayoutDom { assert_in_layout(); LayoutDom { value: self.ptr.as_ref(), @@ -365,7 +365,7 @@ impl Dom { impl Dom { /// Create a `Dom` from a `&T` #[allow(crown::unrooted_must_root)] - pub fn from_ref(obj: &T) -> Dom { + pub(crate) fn from_ref(obj: &T) -> Dom { assert_in_script(); Dom { ptr: ptr::NonNull::from(obj), @@ -404,7 +404,7 @@ unsafe impl JSTraceable for Dom { /// A traced reference to a DOM object that may not be reflected yet. #[crown::unrooted_must_root_lint::must_root] -pub struct MaybeUnreflectedDom { +pub(crate) struct MaybeUnreflectedDom { ptr: ptr::NonNull, } @@ -413,7 +413,7 @@ where T: DomObject, { #[allow(crown::unrooted_must_root)] - pub unsafe fn from_box(value: Box) -> Self { + pub(crate) unsafe fn from_box(value: Box) -> Self { Self { ptr: Box::leak(value).into(), } @@ -424,7 +424,7 @@ impl Root> 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 Root> where T: MutDomObject, { - pub unsafe fn reflect_with(self, obj: *mut JSObject) -> DomRoot { + pub(crate) unsafe fn reflect_with(self, obj: *mut JSObject) -> DomRoot { 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(&self) -> LayoutDom<'dom, U> + pub(crate) fn upcast(&self) -> LayoutDom<'dom, U> where U: Castable, T: DerivedFrom, @@ -466,7 +466,7 @@ where } /// Cast a DOM object downwards to one of the interfaces it might implement. - pub fn downcast(&self) -> Option> + pub(crate) fn downcast(&self) -> Option> where U: DerivedFrom, { @@ -475,7 +475,7 @@ where } /// Returns whether this inner object is a U. - pub fn is(&self) -> bool + pub(crate) fn is(&self) -> bool where U: DerivedFrom, { @@ -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 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`. #[crown::unrooted_must_root_lint::must_root] #[derive(JSTraceable)] -pub struct MutDom { +pub(crate) struct MutDom { val: UnsafeCell>, } impl MutDom { /// Create a new `MutDom`. - pub fn new(initial: &T) -> MutDom { + pub(crate) fn new(initial: &T) -> MutDom { assert_in_script(); MutDom { val: UnsafeCell::new(Dom::from_ref(initial)), @@ -582,7 +582,7 @@ impl MutDom { } /// 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 MutDom { } /// Get the value in this `MutDom`. - pub fn get(&self) -> DomRoot { + pub(crate) fn get(&self) -> DomRoot { assert_in_script(); unsafe { DomRoot::from_ref(&*ptr::read(self.val.get())) } } @@ -631,13 +631,13 @@ pub(crate) fn assert_in_layout() { /// on `Dom`. #[crown::unrooted_must_root_lint::must_root] #[derive(JSTraceable)] -pub struct MutNullableDom { +pub(crate) struct MutNullableDom { ptr: UnsafeCell>>, } impl MutNullableDom { /// Create a new `MutNullableDom`. - pub fn new(initial: Option<&T>) -> MutNullableDom { + pub(crate) fn new(initial: Option<&T>) -> MutNullableDom { assert_in_script(); MutNullableDom { ptr: UnsafeCell::new(initial.map(Dom::from_ref)), @@ -646,7 +646,7 @@ impl MutNullableDom { /// 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(&self, cb: F) -> DomRoot + pub(crate) fn or_init(&self, cb: F) -> DomRoot where F: FnOnce() -> DomRoot, { @@ -664,20 +664,20 @@ impl MutNullableDom { /// Retrieve a copy of the inner optional `Dom` as `LayoutDom`. /// 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> { + pub(crate) unsafe fn get_inner_as_layout(&self) -> Option> { 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> { + pub(crate) fn get(&self) -> Option> { 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 MutNullableDom { } /// Gets the current value out of this object and sets it to `None`. - pub fn take(&self) -> Option> { + pub(crate) fn take(&self) -> Option> { let value = self.get(); self.set(None); value @@ -728,7 +728,7 @@ impl MallocSizeOf for MutNullableDom { /// This should only be used as a field in other DOM objects; see warning /// on `Dom`. #[crown::unrooted_must_root_lint::must_root] -pub struct DomOnceCell { +pub(crate) struct DomOnceCell { ptr: OnceCell>, } @@ -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(&self, cb: F) -> &T + pub(crate) fn init_once(&self, cb: F) -> &T where F: FnOnce() -> DomRoot, { @@ -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` into a slice of `LayoutDom`. // FIXME(nox): This should probably be done through a ToLayout trait. - pub unsafe fn to_layout_slice(slice: &'dom [Dom]) -> &'dom [LayoutDom<'dom, T>] { + pub(crate) unsafe fn to_layout_slice(slice: &'dom [Dom]) -> &'dom [LayoutDom<'dom, T>] { // This doesn't compile if Dom and LayoutDom don't have the same // representation. let _ = mem::transmute::, LayoutDom>; diff --git a/components/script/dom/bindings/serializable.rs b/components/script/dom/bindings/serializable.rs index 46c6a7b5b5b..edc3b07652c 100644 --- a/components/script/dom/bindings/serializable.rs +++ b/components/script/dom/bindings/serializable.rs @@ -13,14 +13,14 @@ use crate::script_runtime::CanGc; /// The key corresponding to the storage location /// of a serialized platform object stored in a StructuredDataHolder. #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] -pub struct StorageKey { - pub index: u32, - pub name_space: u32, +pub(crate) struct StorageKey { + pub(crate) index: u32, + pub(crate) name_space: u32, } /// Interface for serializable platform objects. /// -pub trait Serializable: DomObject { +pub(crate) trait Serializable: DomObject { /// fn serialize(&self, sc_writer: &mut StructuredDataWriter) -> Result; /// diff --git a/components/script/dom/bindings/settings_stack.rs b/components/script/dom/bindings/settings_stack.rs index 3c9f57b7458..c12c48f3c35 100644 --- a/components/script/dom/bindings/settings_stack.rs +++ b/components/script/dom/bindings/settings_stack.rs @@ -29,18 +29,18 @@ struct StackEntry { } /// Traces the script settings stack. -pub unsafe fn trace(tracer: *mut JSTracer) { +pub(crate) unsafe fn trace(tracer: *mut JSTracer) { STACK.with(|stack| { stack.borrow().trace(tracer); }) } -pub fn is_execution_stack_empty() -> bool { +pub(crate) fn is_execution_stack_empty() -> bool { STACK.with(|stack| stack.borrow().is_empty()) } /// RAII struct that pushes and pops entries from the script settings stack. -pub struct AutoEntryScript { +pub(crate) struct AutoEntryScript { global: DomRoot, #[cfg(feature = "tracing")] span: tracing::span::EnteredSpan, @@ -48,7 +48,7 @@ pub struct AutoEntryScript { impl AutoEntryScript { /// - pub fn new(global: &GlobalScope) -> Self { + pub(crate) fn new(global: &GlobalScope) -> Self { STACK.with(|stack| { trace!("Prepare to run script with {:p}", global); let mut stack = stack.borrow_mut(); @@ -94,7 +94,7 @@ impl Drop for AutoEntryScript { /// Returns the ["entry"] global object. /// /// ["entry"]: https://html.spec.whatwg.org/multipage/#entry -pub fn entry_global() -> DomRoot { +pub(crate) fn entry_global() -> DomRoot { STACK .with(|stack| { stack @@ -108,13 +108,13 @@ pub fn entry_global() -> DomRoot { } /// RAII struct that pushes and pops entries from the script settings stack. -pub struct AutoIncumbentScript { +pub(crate) struct AutoIncumbentScript { global: usize, } impl AutoIncumbentScript { /// - pub fn new(global: &GlobalScope) -> Self { + pub(crate) fn new(global: &GlobalScope) -> Self { // Step 2-3. unsafe { let cx = @@ -166,7 +166,7 @@ impl Drop for AutoIncumbentScript { /// Returns the ["incumbent"] global object. /// /// ["incumbent"]: https://html.spec.whatwg.org/multipage/#incumbent -pub fn incumbent_global() -> Option> { +pub(crate) fn incumbent_global() -> Option> { // https://html.spec.whatwg.org/multipage/#incumbent-settings-object // Step 1, 3: See what the JS engine has to say. If we've got a scripted diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index 44e8466adda..64f180951cf 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -31,22 +31,22 @@ impl ByteString { /// Returns `self` as a string, if it encodes valid UTF-8, and `None` /// otherwise. - pub fn as_str(&self) -> Option<&str> { + pub(crate) fn as_str(&self) -> Option<&str> { str::from_utf8(&self.0).ok() } /// Returns the length. - pub fn len(&self) -> usize { + pub(crate) fn len(&self) -> usize { self.0.len() } /// Checks if the ByteString is empty. - pub fn is_empty(&self) -> bool { + pub(crate) fn is_empty(&self) -> bool { self.0.is_empty() } /// Returns `self` with A–Z replaced by a–z. - pub fn to_lower(&self) -> ByteString { + pub(crate) fn to_lower(&self) -> ByteString { ByteString::new(self.0.to_ascii_lowercase()) } } @@ -80,7 +80,7 @@ impl ops::Deref for ByteString { /// A string that is constructed from a UCS-2 buffer by replacing invalid code /// points with the replacement character. #[derive(Clone, Default, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd)] -pub struct USVString(pub String); +pub(crate) struct USVString(pub(crate) String); impl Borrow for USVString { #[inline] @@ -138,7 +138,7 @@ impl From for USVString { /// Returns whether `s` is a `token`, as defined by /// [RFC 2616](http://tools.ietf.org/html/rfc2616#page-17). -pub fn is_token(s: &[u8]) -> bool { +pub(crate) fn is_token(s: &[u8]) -> bool { if s.is_empty() { return false; // A token must be at least a single character } @@ -195,43 +195,43 @@ pub struct DOMString(String, PhantomData<*const ()>); impl DOMString { /// Creates a new `DOMString`. - pub fn new() -> DOMString { + pub(crate) fn new() -> DOMString { DOMString(String::new(), PhantomData) } /// Creates a new `DOMString` from a `String`. - pub fn from_string(s: String) -> DOMString { + pub(crate) fn from_string(s: String) -> DOMString { DOMString(s, PhantomData) } /// Get the internal `&str` value of this [`DOMString`]. - pub fn str(&self) -> &str { + pub(crate) fn str(&self) -> &str { &self.0 } /// Appends a given string slice onto the end of this String. - pub fn push_str(&mut self, string: &str) { + pub(crate) fn push_str(&mut self, string: &str) { self.0.push_str(string) } /// Clears this `DOMString`, removing all contents. - pub fn clear(&mut self) { + pub(crate) fn clear(&mut self) { self.0.clear() } /// Shortens this String to the specified length. - pub fn truncate(&mut self, new_len: usize) { + pub(crate) fn truncate(&mut self, new_len: usize) { self.0.truncate(new_len); } /// Removes newline characters according to . - pub fn strip_newlines(&mut self) { + pub(crate) fn strip_newlines(&mut self) { self.0.retain(|c| c != '\r' && c != '\n'); } /// Removes leading and trailing ASCII whitespaces according to /// . - pub fn strip_leading_and_trailing_ascii_whitespace(&mut self) { + pub(crate) fn strip_leading_and_trailing_ascii_whitespace(&mut self) { if self.0.is_empty() { return; } @@ -250,7 +250,7 @@ impl DOMString { } /// - pub fn is_valid_floating_point_number_string(&self) -> bool { + pub(crate) fn is_valid_floating_point_number_string(&self) -> bool { static RE: LazyLock = LazyLock::new(|| { Regex::new(r"^-?(?:\d+\.\d+|\d+|\.\d+)(?:(e|E)(\+|\-)?\d+)?$").unwrap() }); @@ -259,7 +259,7 @@ impl DOMString { } /// - pub fn parse_floating_point_number(&self) -> Option { + pub(crate) fn parse_floating_point_number(&self) -> Option { // Steps 15-16 are telling us things about IEEE rounding modes // for floating-point significands; this code assumes the Rust // compiler already matches them in any cases where @@ -286,7 +286,7 @@ impl DOMString { /// /// /// - pub fn set_best_representation_of_the_floating_point_number(&mut self) { + pub(crate) fn set_best_representation_of_the_floating_point_number(&mut self) { if let Some(val) = self.parse_floating_point_number() { // [tc39] Step 2: If x is either +0 or -0, return "0". let parsed_value = if val.is_zero() { 0.0_f64 } else { val }; diff --git a/components/script/dom/bindings/structuredclone.rs b/components/script/dom/bindings/structuredclone.rs index 39ba918e383..b05abf2b9e9 100644 --- a/components/script/dom/bindings/structuredclone.rs +++ b/components/script/dom/bindings/structuredclone.rs @@ -255,32 +255,32 @@ static STRUCTURED_CLONE_CALLBACKS: JSStructuredCloneCallbacks = JSStructuredClon /// Reader and writer structs for results from, and inputs to, structured-data read/write operations. /// -pub struct StructuredDataReader { +pub(crate) struct StructuredDataReader { /// A map of deserialized blobs, stored temporarily here to keep them rooted. - pub blobs: Option>>, + pub(crate) blobs: Option>>, /// A vec of transfer-received DOM ports, /// to be made available to script through a message event. - pub message_ports: Option>>, + pub(crate) message_ports: Option>>, /// A map of port implementations, /// used as part of the "transfer-receiving" steps of ports, /// to produce the DOM ports stored in `message_ports` above. - pub port_impls: Option>, + pub(crate) port_impls: Option>, /// A map of blob implementations, /// used as part of the "deserialize" steps of blobs, /// to produce the DOM blobs stored in `blobs` above. - pub blob_impls: Option>, + pub(crate) blob_impls: Option>, } /// A data holder for transferred and serialized objects. -pub struct StructuredDataWriter { +pub(crate) struct StructuredDataWriter { /// Transferred ports. - pub ports: Option>, + pub(crate) ports: Option>, /// Serialized blobs. - pub blobs: Option>, + pub(crate) blobs: Option>, } /// Writes a structured clone. Returns a `DataClone` error if that fails. -pub fn write( +pub(crate) fn write( cx: SafeJSContext, message: HandleValue, transfer: Option>>, @@ -339,7 +339,7 @@ pub fn write( /// Read structured serialized data, possibly containing transferred objects. /// Returns a vec of rooted transfer-received ports, or an error. -pub fn read( +pub(crate) fn read( global: &GlobalScope, mut data: StructuredSerializedData, rval: MutableHandleValue, diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 0132a688085..b94dba3fc7d 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -40,8 +40,8 @@ use std::ops::{Deref, DerefMut}; use crossbeam_channel::Sender; use indexmap::IndexMap; /// A trait to allow tracing (only) DOM objects. -pub use js::gc::Traceable as JSTraceable; -pub use js::gc::{RootableVec, RootedVec}; +pub(crate) use js::gc::Traceable as JSTraceable; +pub(crate) use js::gc::{RootableVec, RootedVec}; use js::glue::{CallObjectTracer, CallScriptTracer, CallStringTracer, CallValueTracer}; use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSScript, JSString, JSTracer, TraceKind}; use js::jsval::JSVal; @@ -76,7 +76,7 @@ use crate::task::TaskBox; /// /// This trait is unsafe; if it is implemented incorrectly, the GC may end up collecting objects /// that are still reachable. -pub unsafe trait CustomTraceable { +pub(crate) unsafe trait CustomTraceable { /// Trace `self`. /// /// # Safety @@ -117,7 +117,7 @@ unsafe impl CustomTraceable for Sender { /// SAFETY: Inner type must not impl JSTraceable #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] #[crown::trace_in_no_trace_lint::must_not_have_traceable] -pub struct NoTrace(pub T); +pub(crate) struct NoTrace(pub(crate) T); impl Display for NoTrace { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -148,7 +148,7 @@ impl MallocSizeOf for NoTrace { /// Not all methods are reexposed, but you can access inner type via .0 #[crown::trace_in_no_trace_lint::must_not_have_traceable(0)] #[derive(Clone, Debug)] -pub struct HashMapTracedValues(pub HashMap); +pub(crate) struct HashMapTracedValues(pub(crate) HashMap); impl Default for HashMapTracedValues { fn default() -> Self { @@ -160,24 +160,24 @@ impl HashMapTracedValues { /// Wrapper for HashMap::new() #[inline] #[must_use] - pub fn new() -> HashMapTracedValues { + pub(crate) fn new() -> HashMapTracedValues { Self(HashMap::new()) } } impl HashMapTracedValues { #[inline] - pub fn iter(&self) -> std::collections::hash_map::Iter<'_, K, V> { + pub(crate) fn iter(&self) -> std::collections::hash_map::Iter<'_, K, V> { self.0.iter() } #[inline] - pub fn drain(&mut self) -> std::collections::hash_map::Drain<'_, K, V> { + pub(crate) fn drain(&mut self) -> std::collections::hash_map::Drain<'_, K, V> { self.0.drain() } #[inline] - pub fn is_empty(&self) -> bool { + pub(crate) fn is_empty(&self) -> bool { self.0.is_empty() } } @@ -188,12 +188,12 @@ where S: BuildHasher, { #[inline] - pub fn insert(&mut self, k: K, v: V) -> Option { + pub(crate) fn insert(&mut self, k: K, v: V) -> Option { self.0.insert(k, v) } #[inline] - pub fn get(&self, k: &Q) -> Option<&V> + pub(crate) fn get(&self, k: &Q) -> Option<&V> where K: std::borrow::Borrow, Q: Hash + Eq + ?Sized, @@ -202,7 +202,7 @@ where } #[inline] - pub fn get_mut(&mut self, k: &Q) -> Option<&mut V> + pub(crate) fn get_mut(&mut self, k: &Q) -> Option<&mut V> where K: std::borrow::Borrow, { @@ -210,7 +210,7 @@ where } #[inline] - pub fn contains_key(&self, k: &Q) -> bool + pub(crate) fn contains_key(&self, k: &Q) -> bool where K: std::borrow::Borrow, { @@ -218,7 +218,7 @@ where } #[inline] - pub fn remove(&mut self, k: &Q) -> Option + pub(crate) fn remove(&mut self, k: &Q) -> Option where K: std::borrow::Borrow, { @@ -226,7 +226,7 @@ where } #[inline] - pub fn entry(&mut self, key: K) -> std::collections::hash_map::Entry<'_, K, V> { + pub(crate) fn entry(&mut self, key: K) -> std::collections::hash_map::Entry<'_, K, V> { self.0.entry(key) } } @@ -260,7 +260,7 @@ unsafe_no_jsmanaged_fields!(Reflector); #[allow(dead_code)] /// Trace a `JSScript`. -pub fn trace_script(tracer: *mut JSTracer, description: &str, script: &Heap<*mut JSScript>) { +pub(crate) fn trace_script(tracer: *mut JSTracer, description: &str, script: &Heap<*mut JSScript>) { unsafe { trace!("tracing {}", description); CallScriptTracer( @@ -273,7 +273,7 @@ pub fn trace_script(tracer: *mut JSTracer, description: &str, script: &Heap<*mut #[allow(dead_code)] /// Trace a `JSVal`. -pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: &Heap) { +pub(crate) fn trace_jsval(tracer: *mut JSTracer, description: &str, val: &Heap) { unsafe { if !val.get().is_markable() { return; @@ -290,13 +290,13 @@ pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: &Heap) /// Trace the `JSObject` held by `reflector`. #[allow(crown::unrooted_must_root)] -pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) { +pub(crate) fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) { trace!("tracing reflector {}", description); trace_object(tracer, description, reflector.rootable()) } /// Trace a `JSObject`. -pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: &Heap<*mut JSObject>) { +pub(crate) fn trace_object(tracer: *mut JSTracer, description: &str, obj: &Heap<*mut JSObject>) { unsafe { trace!("tracing {}", description); CallObjectTracer( @@ -309,7 +309,7 @@ pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: &Heap<*mut JS #[allow(dead_code)] /// Trace a `JSString`. -pub fn trace_string(tracer: *mut JSTracer, description: &str, s: &Heap<*mut JSString>) { +pub(crate) fn trace_string(tracer: *mut JSTracer, description: &str, s: &Heap<*mut JSString>) { unsafe { trace!("tracing {}", description); CallStringTracer( @@ -491,7 +491,7 @@ where /// If you have an arbitrary number of DomObjects to root, use rooted_vec!. /// If you know what you're doing, use this. #[crown::unrooted_must_root_lint::allow_unrooted_interior] -pub struct RootedTraceableBox(js::gc::RootedTraceableBox); +pub(crate) struct RootedTraceableBox(js::gc::RootedTraceableBox); unsafe impl JSTraceable for RootedTraceableBox { unsafe fn trace(&self, tracer: *mut JSTracer) { @@ -501,12 +501,12 @@ unsafe impl JSTraceable for RootedTraceableBox { impl RootedTraceableBox { /// DomRoot a JSTraceable thing for the life of this RootedTraceableBox - pub fn new(traceable: T) -> RootedTraceableBox { + pub(crate) fn new(traceable: T) -> RootedTraceableBox { Self(js::gc::RootedTraceableBox::new(traceable)) } /// Consumes a boxed JSTraceable and roots it for the life of this RootedTraceableBox. - pub fn from_box(boxed_traceable: Box) -> RootedTraceableBox { + pub(crate) fn from_box(boxed_traceable: Box) -> RootedTraceableBox { Self(js::gc::RootedTraceableBox::from_box(boxed_traceable)) } } @@ -516,7 +516,7 @@ where Heap: JSTraceable + 'static, T: GCMethods + Copy, { - pub fn handle(&self) -> Handle { + pub(crate) fn handle(&self) -> Handle { self.0.handle() } } diff --git a/components/script/dom/bindings/transferable.rs b/components/script/dom/bindings/transferable.rs index d97fc28eb52..674d652119b 100644 --- a/components/script/dom/bindings/transferable.rs +++ b/components/script/dom/bindings/transferable.rs @@ -11,7 +11,7 @@ use crate::dom::bindings::reflector::DomObject; use crate::dom::bindings::structuredclone::{StructuredDataReader, StructuredDataWriter}; use crate::dom::globalscope::GlobalScope; -pub trait Transferable: DomObject { +pub(crate) trait Transferable: DomObject { fn transfer(&self, sc_writer: &mut StructuredDataWriter) -> Result; fn transfer_receive( owner: &GlobalScope, diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 2817803504b..da583b2881b 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -55,15 +55,15 @@ use crate::script_runtime::JSContext as SafeJSContext; /// This is needed to allow using JS API types (which usually involve raw pointers) in static initializers, /// when Servo guarantees through the use of OnceLock that only one thread will ever initialize /// the value. -pub struct ThreadUnsafeOnceLock(OnceLock); +pub(crate) struct ThreadUnsafeOnceLock(OnceLock); impl ThreadUnsafeOnceLock { - pub const fn new() -> Self { + pub(crate) const fn new() -> Self { Self(OnceLock::new()) } /// Initialize the value inside this lock. Panics if the lock has been previously initialized. - pub fn set(&self, val: T) { + pub(crate) fn set(&self, val: T) { assert!(self.0.set(val).is_ok()); } @@ -72,7 +72,7 @@ impl ThreadUnsafeOnceLock { /// SAFETY: /// The caller must ensure that it does not mutate value contained inside this lock /// (using interior mutability). - pub unsafe fn get(&self) -> &T { + pub(crate) unsafe fn get(&self) -> &T { self.0.get().unwrap() } } @@ -82,15 +82,15 @@ unsafe impl Send for ThreadUnsafeOnceLock {} #[derive(JSTraceable, MallocSizeOf)] /// Static data associated with a global object. -pub struct GlobalStaticData { +pub(crate) struct GlobalStaticData { #[ignore_malloc_size_of = "WindowProxyHandler does not properly implement it anyway"] /// The WindowProxy proxy handler for this global. - pub windowproxy_handler: &'static WindowProxyHandler, + pub(crate) windowproxy_handler: &'static WindowProxyHandler, } impl GlobalStaticData { /// Creates a new GlobalStaticData. - pub fn new() -> GlobalStaticData { + pub(crate) fn new() -> GlobalStaticData { GlobalStaticData { windowproxy_handler: WindowProxyHandler::proxy_handler(), } @@ -99,47 +99,47 @@ impl GlobalStaticData { /// The index of the slot where the object holder of that interface's /// unforgeable members are defined. -pub const DOM_PROTO_UNFORGEABLE_HOLDER_SLOT: u32 = 0; +pub(crate) const DOM_PROTO_UNFORGEABLE_HOLDER_SLOT: u32 = 0; /// The index of the slot that contains a reference to the ProtoOrIfaceArray. // All DOM globals must have a slot at DOM_PROTOTYPE_SLOT. -pub const DOM_PROTOTYPE_SLOT: u32 = js::JSCLASS_GLOBAL_SLOT_COUNT; +pub(crate) const DOM_PROTOTYPE_SLOT: u32 = js::JSCLASS_GLOBAL_SLOT_COUNT; /// The flag set on the `JSClass`es for DOM global objects. // NOTE: This is baked into the Ion JIT as 0 in codegen for LGetDOMProperty and // LSetDOMProperty. Those constants need to be changed accordingly if this value // changes. -pub const JSCLASS_DOM_GLOBAL: u32 = js::JSCLASS_USERBIT1; +pub(crate) const JSCLASS_DOM_GLOBAL: u32 = js::JSCLASS_USERBIT1; /// The struct that holds inheritance information for DOM object reflectors. #[derive(Clone, Copy)] -pub struct DOMClass { +pub(crate) struct DOMClass { /// A list of interfaces that this object implements, in order of decreasing /// derivedness. - pub interface_chain: [PrototypeList::ID; MAX_PROTO_CHAIN_LENGTH], + pub(crate) interface_chain: [PrototypeList::ID; MAX_PROTO_CHAIN_LENGTH], /// The last valid index of `interface_chain`. - pub depth: u8, + pub(crate) depth: u8, /// The type ID of that interface. - pub type_id: TopTypeId, + pub(crate) type_id: TopTypeId, /// The MallocSizeOf function wrapper for that interface. - pub malloc_size_of: unsafe fn(ops: &mut MallocSizeOfOps, *const c_void) -> usize, + pub(crate) malloc_size_of: unsafe fn(ops: &mut MallocSizeOfOps, *const c_void) -> usize, /// The `Globals` flag for this global interface, if any. - pub global: InterfaceObjectMap::Globals, + pub(crate) global: InterfaceObjectMap::Globals, } unsafe impl Sync for DOMClass {} /// The JSClass used for DOM object reflectors. #[derive(Copy)] #[repr(C)] -pub struct DOMJSClass { +pub(crate) struct DOMJSClass { /// The actual JSClass. - pub base: js::jsapi::JSClass, + pub(crate) base: js::jsapi::JSClass, /// Associated data for DOM object reflectors. - pub dom_class: DOMClass, + pub(crate) dom_class: DOMClass, } impl Clone for DOMJSClass { fn clone(&self) -> DOMJSClass { @@ -149,7 +149,7 @@ impl Clone for DOMJSClass { unsafe impl Sync for DOMJSClass {} /// Returns a JSVal representing the frozen JavaScript array -pub fn to_frozen_array( +pub(crate) fn to_frozen_array( convertibles: &[T], cx: SafeJSContext, rval: MutableHandleValue, @@ -162,7 +162,7 @@ pub fn to_frozen_array( /// Returns the ProtoOrIfaceArray for the given global object. /// Fails if `global` is not a DOM global object. -pub fn get_proto_or_iface_array(global: *mut JSObject) -> *mut ProtoOrIfaceArray { +pub(crate) fn get_proto_or_iface_array(global: *mut JSObject) -> *mut ProtoOrIfaceArray { unsafe { assert_ne!(((*get_object_class(global)).flags & JSCLASS_DOM_GLOBAL), 0); let mut slot = UndefinedValue(); @@ -172,13 +172,13 @@ pub fn get_proto_or_iface_array(global: *mut JSObject) -> *mut ProtoOrIfaceArray } /// An array of *mut JSObject of size PROTO_OR_IFACE_LENGTH. -pub type ProtoOrIfaceArray = [*mut JSObject; PROTO_OR_IFACE_LENGTH]; +pub(crate) type ProtoOrIfaceArray = [*mut JSObject; PROTO_OR_IFACE_LENGTH]; /// Gets the property `id` on `proxy`'s prototype. If it exists, `*found` is /// set to true and `*vp` to the value, otherwise `*found` is set to false. /// /// Returns false on JSAPI failure. -pub unsafe fn get_property_on_prototype( +pub(crate) unsafe fn get_property_on_prototype( cx: *mut JSContext, proxy: HandleObject, receiver: HandleValue, @@ -205,7 +205,7 @@ pub unsafe fn get_property_on_prototype( /// Get an array index from the given `jsid`. Returns `None` if the given /// `jsid` is not an integer. -pub unsafe fn get_array_index_from_id(_cx: *mut JSContext, id: HandleId) -> Option { +pub(crate) unsafe fn get_array_index_from_id(_cx: *mut JSContext, id: HandleId) -> Option { let raw_id = *id; if raw_id.is_int() { return Some(raw_id.to_int() as u32); @@ -266,7 +266,7 @@ pub unsafe fn get_array_index_from_id(_cx: *mut JSContext, id: HandleId) -> Opti /// Find the enum equivelent of a string given by `v` in `pairs`. /// Returns `Err(())` on JSAPI failure (there is a pending exception), and /// `Ok((None, value))` if there was no matching string. -pub unsafe fn find_enum_value<'a, T>( +pub(crate) unsafe fn find_enum_value<'a, T>( cx: *mut JSContext, v: HandleValue, pairs: &'a [(&'static str, T)], @@ -289,7 +289,7 @@ pub unsafe fn find_enum_value<'a, T>( /// Returns wether `obj` is a platform object using dynamic unwrap /// #[allow(dead_code)] -pub fn is_platform_object_dynamic(obj: *mut JSObject, cx: *mut JSContext) -> bool { +pub(crate) fn is_platform_object_dynamic(obj: *mut JSObject, cx: *mut JSContext) -> bool { is_platform_object(obj, &|o| unsafe { UnwrapObjectDynamic(o, cx, /* stopAtWindowProxy = */ false) }) @@ -297,7 +297,7 @@ pub fn is_platform_object_dynamic(obj: *mut JSObject, cx: *mut JSContext) -> boo /// Returns wether `obj` is a platform object using static unwrap /// -pub fn is_platform_object_static(obj: *mut JSObject) -> bool { +pub(crate) fn is_platform_object_static(obj: *mut JSObject) -> bool { is_platform_object(obj, &|o| unsafe { UnwrapObjectStatic(o) }) } @@ -327,7 +327,7 @@ fn is_platform_object( /// Get the property with name `property` from `object`. /// Returns `Err(())` on JSAPI failure (there is a pending exception), and /// `Ok(false)` if there was no property with the given name. -pub fn get_dictionary_property( +pub(crate) fn get_dictionary_property( cx: *mut JSContext, object: HandleObject, property: &str, @@ -374,7 +374,7 @@ pub fn get_dictionary_property( /// Set the property with name `property` from `object`. /// Returns `Err(())` on JSAPI failure, or null object, /// and Ok(()) otherwise -pub fn set_dictionary_property( +pub(crate) fn set_dictionary_property( cx: *mut JSContext, object: HandleObject, property: &str, @@ -395,7 +395,7 @@ pub fn set_dictionary_property( } /// Returns whether `proxy` has a property `id` on its prototype. -pub unsafe fn has_property_on_prototype( +pub(crate) unsafe fn has_property_on_prototype( cx: *mut JSContext, proxy: HandleObject, id: HandleId, @@ -410,7 +410,7 @@ pub unsafe fn has_property_on_prototype( } /// Drop the resources held by reserved slots of a global object -pub unsafe fn finalize_global(obj: *mut JSObject) { +pub(crate) unsafe fn finalize_global(obj: *mut JSObject) { let protolist = get_proto_or_iface_array(obj); let list = (*protolist).as_mut_ptr(); for idx in 0..PROTO_OR_IFACE_LENGTH as isize { @@ -422,7 +422,7 @@ pub unsafe fn finalize_global(obj: *mut JSObject) { } /// Trace the resources held by reserved slots of a global object -pub unsafe fn trace_global(tracer: *mut JSTracer, obj: *mut JSObject) { +pub(crate) unsafe fn trace_global(tracer: *mut JSTracer, obj: *mut JSObject) { let array = get_proto_or_iface_array(obj); for proto in (*array).iter() { if !proto.is_null() { @@ -436,7 +436,7 @@ pub unsafe fn trace_global(tracer: *mut JSTracer, obj: *mut JSObject) { } /// Enumerate lazy properties of a global object. -pub unsafe extern "C" fn enumerate_global( +pub(crate) unsafe extern "C" fn enumerate_global( cx: *mut JSContext, obj: RawHandleObject, _props: RawMutableHandleIdVector, @@ -453,7 +453,7 @@ pub unsafe extern "C" fn enumerate_global( } /// Resolve a lazy global property, for interface objects and named constructors. -pub unsafe extern "C" fn resolve_global( +pub(crate) unsafe extern "C" fn resolve_global( cx: *mut JSContext, obj: RawHandleObject, id: RawHandleId, @@ -491,7 +491,7 @@ pub unsafe extern "C" fn resolve_global( } /// Deletes the property `id` from `object`. -pub unsafe fn delete_property_by_id( +pub(crate) unsafe fn delete_property_by_id( cx: *mut JSContext, object: HandleObject, id: HandleId, @@ -564,7 +564,7 @@ unsafe fn generic_call( } /// Generic method of IDL interface. -pub unsafe extern "C" fn generic_method( +pub(crate) unsafe extern "C" fn generic_method( cx: *mut JSContext, argc: libc::c_uint, vp: *mut JSVal, @@ -573,7 +573,7 @@ pub unsafe extern "C" fn generic_method( } /// Generic getter of IDL interface. -pub unsafe extern "C" fn generic_getter( +pub(crate) unsafe extern "C" fn generic_getter( cx: *mut JSContext, argc: libc::c_uint, vp: *mut JSVal, @@ -582,7 +582,7 @@ pub unsafe extern "C" fn generic_getter( } /// Generic lenient getter of IDL interface. -pub unsafe extern "C" fn generic_lenient_getter( +pub(crate) unsafe extern "C" fn generic_lenient_getter( cx: *mut JSContext, argc: libc::c_uint, vp: *mut JSVal, @@ -606,7 +606,7 @@ unsafe extern "C" fn call_setter( } /// Generic setter of IDL interface. -pub unsafe extern "C" fn generic_setter( +pub(crate) unsafe extern "C" fn generic_setter( cx: *mut JSContext, argc: libc::c_uint, vp: *mut JSVal, @@ -615,7 +615,7 @@ pub unsafe extern "C" fn generic_setter( } /// Generic lenient setter of IDL interface. -pub unsafe extern "C" fn generic_lenient_setter( +pub(crate) unsafe extern "C" fn generic_lenient_setter( cx: *mut JSContext, argc: libc::c_uint, vp: *mut JSVal, @@ -634,12 +634,12 @@ unsafe extern "C" fn instance_class_has_proto_at_depth( } #[allow(missing_docs)] // FIXME -pub const DOM_CALLBACKS: DOMCallbacks = DOMCallbacks { +pub(crate) const DOM_CALLBACKS: DOMCallbacks = DOMCallbacks { instanceClassMatchesProto: Some(instance_class_has_proto_at_depth), }; // Generic method for returning libc::c_void from caller -pub trait AsVoidPtr { +pub(crate) trait AsVoidPtr { fn as_void_ptr(&self) -> *const libc::c_void; } impl AsVoidPtr for T { @@ -649,7 +649,7 @@ impl AsVoidPtr for T { } // Generic method for returning c_char from caller -pub trait AsCCharPtrPtr { +pub(crate) trait AsCCharPtrPtr { fn as_c_char_ptr(&self) -> *const c_char; } @@ -660,7 +660,7 @@ impl AsCCharPtrPtr for [u8] { } /// -pub unsafe extern "C" fn generic_static_promise_method( +pub(crate) unsafe extern "C" fn generic_static_promise_method( cx: *mut JSContext, argc: libc::c_uint, vp: *mut JSVal, @@ -681,7 +681,7 @@ pub unsafe extern "C" fn generic_static_promise_method( /// Coverts exception to promise rejection /// /// -pub unsafe fn exception_to_promise(cx: *mut JSContext, rval: RawMutableHandleValue) -> bool { +pub(crate) unsafe fn exception_to_promise(cx: *mut JSContext, rval: RawMutableHandleValue) -> bool { rooted!(in(cx) let mut exception = UndefinedValue()); if !JS_GetPendingException(cx, exception.handle_mut()) { return false; diff --git a/components/script/dom/bindings/weakref.rs b/components/script/dom/bindings/weakref.rs index 57bf219de4f..949da64b987 100644 --- a/components/script/dom/bindings/weakref.rs +++ b/components/script/dom/bindings/weakref.rs @@ -30,27 +30,27 @@ use crate::dom::bindings::trace::JSTraceable; /// stored for weak-referenceable bindings. We use slot 1 for holding it, /// this is unsafe for globals, we disallow weak-referenceable globals /// directly in codegen. -pub const DOM_WEAK_SLOT: u32 = 1; +pub(crate) const DOM_WEAK_SLOT: u32 = 1; /// A weak reference to a JS-managed DOM object. #[allow(crown::unrooted_must_root)] #[crown::unrooted_must_root_lint::allow_unrooted_interior] -pub struct WeakRef { +pub(crate) struct WeakRef { ptr: ptr::NonNull>, } /// The inner box of weak references, public for the finalization in codegen. #[crown::unrooted_must_root_lint::must_root] -pub struct WeakBox { +pub(crate) struct WeakBox { /// The reference count. When it reaches zero, the `value` field should /// have already been set to `None`. The pointee contributes one to the count. - pub count: Cell, + pub(crate) count: Cell, /// The pointer to the JS-managed object, set to None when it is collected. - pub value: Cell>>, + pub(crate) value: Cell>>, } /// Trait implemented by weak-referenceable interfaces. -pub trait WeakReferenceable: DomObject + Sized { +pub(crate) trait WeakReferenceable: DomObject + Sized { /// Downgrade a DOM object reference to a weak one. fn downgrade(&self) -> WeakRef { unsafe { @@ -87,12 +87,12 @@ impl WeakRef { /// Create a new weak reference from a `WeakReferenceable` interface instance. /// This is just a convenience wrapper around `::downgrade` /// to not have to import `WeakReferenceable`. - pub fn new(value: &T) -> Self { + pub(crate) fn new(value: &T) -> Self { value.downgrade() } /// DomRoot a weak reference. Returns `None` if the object was already collected. - pub fn root(&self) -> Option> { + pub(crate) fn root(&self) -> Option> { unsafe { &*self.ptr.as_ptr() } .value .get() @@ -100,7 +100,7 @@ impl WeakRef { } /// Return whether the weakly-referenced object is still alive. - pub fn is_alive(&self) -> bool { + pub(crate) fn is_alive(&self) -> bool { unsafe { &*self.ptr.as_ptr() }.value.get().is_some() } } @@ -169,20 +169,20 @@ impl Drop for WeakRef { /// A mutable weak reference to a JS-managed DOM object. On tracing, /// the contained weak reference is dropped if the pointee was already /// collected. -pub struct MutableWeakRef { +pub(crate) struct MutableWeakRef { cell: UnsafeCell>>, } impl MutableWeakRef { /// Create a new mutable weak reference. - pub fn new(value: Option<&T>) -> MutableWeakRef { + pub(crate) fn new(value: Option<&T>) -> MutableWeakRef { MutableWeakRef { cell: UnsafeCell::new(value.map(WeakRef::new)), } } /// Set the pointee of a mutable weak reference. - pub fn set(&self, value: Option<&T>) { + pub(crate) fn set(&self, value: Option<&T>) { unsafe { *self.cell.get() = value.map(WeakRef::new); } @@ -190,7 +190,7 @@ impl MutableWeakRef { /// DomRoot a mutable weak reference. Returns `None` if the object /// was already collected. - pub fn root(&self) -> Option> { + pub(crate) fn root(&self) -> Option> { unsafe { &*self.cell.get() } .as_ref() .and_then(WeakRef::root) @@ -220,19 +220,19 @@ unsafe impl JSTraceable for MutableWeakRef { /// only references which still point to live objects. #[crown::unrooted_must_root_lint::allow_unrooted_interior] #[derive(MallocSizeOf)] -pub struct WeakRefVec { +pub(crate) struct WeakRefVec { vec: Vec>, } impl WeakRefVec { /// Create a new vector of weak references. - pub fn new() -> Self { + pub(crate) fn new() -> Self { WeakRefVec { vec: vec![] } } /// Calls a function on each reference which still points to a /// live object. The order of the references isn't preserved. - pub fn update)>(&mut self, mut f: F) { + pub(crate) fn update)>(&mut self, mut f: F) { let mut i = 0; while i < self.vec.len() { if self.vec[i].is_alive() { @@ -247,7 +247,7 @@ impl WeakRefVec { } /// Clears the vector of its dead references. - pub fn retain_alive(&mut self) { + pub(crate) fn retain_alive(&mut self) { self.update(|_| ()); } } @@ -269,14 +269,14 @@ impl DerefMut for WeakRefVec { /// An entry of a vector of weak references. Passed to the closure /// given to `WeakRefVec::update`. #[crown::unrooted_must_root_lint::allow_unrooted_interior] -pub struct WeakRefEntry<'a, T: WeakReferenceable> { +pub(crate) struct WeakRefEntry<'a, T: WeakReferenceable> { vec: &'a mut WeakRefVec, index: &'a mut usize, } impl<'a, T: WeakReferenceable + 'a> WeakRefEntry<'a, T> { /// Remove the entry from the underlying vector of weak references. - pub fn remove(self) -> WeakRef { + pub(crate) fn remove(self) -> WeakRef { let ref_ = self.vec.swap_remove(*self.index); mem::forget(self); ref_ @@ -298,22 +298,22 @@ impl<'a, T: WeakReferenceable + 'a> Drop for WeakRefEntry<'a, T> { } #[derive(MallocSizeOf)] -pub struct DOMTracker { +pub(crate) struct DOMTracker { dom_objects: DomRefCell>, } impl DOMTracker { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { dom_objects: DomRefCell::new(WeakRefVec::new()), } } - pub fn track(&self, dom_object: &T) { + pub(crate) fn track(&self, dom_object: &T) { self.dom_objects.borrow_mut().push(WeakRef::new(dom_object)); } - pub fn for_each)>(&self, mut f: F) { + pub(crate) fn for_each)>(&self, mut f: F) { self.dom_objects.borrow_mut().update(|weak_ref| { let root = weak_ref.root().unwrap(); f(root); diff --git a/components/script/dom/bindings/xmlname.rs b/components/script/dom/bindings/xmlname.rs index 5c938690904..6a859f2e5eb 100644 --- a/components/script/dom/bindings/xmlname.rs +++ b/components/script/dom/bindings/xmlname.rs @@ -10,7 +10,7 @@ use crate::dom::bindings::error::{Error, ErrorResult, Fallible}; use crate::dom::bindings::str::DOMString; /// Validate a qualified name. See for details. -pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult { +pub(crate) fn validate_qualified_name(qualified_name: &str) -> ErrorResult { // Step 2. match xml_name_type(qualified_name) { XMLName::Invalid => Err(Error::InvalidCharacter), @@ -21,7 +21,7 @@ pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult { /// Validate a namespace and qualified name and extract their parts. /// See for details. -pub fn validate_and_extract( +pub(crate) fn validate_and_extract( namespace: Option, qualified_name: &str, ) -> Fallible<(Namespace, Option, LocalName)> { @@ -80,7 +80,7 @@ pub fn validate_and_extract( /// Results of `xml_name_type`. #[derive(PartialEq)] #[allow(missing_docs)] -pub enum XMLName { +pub(crate) enum XMLName { QName, Name, Invalid, @@ -88,7 +88,7 @@ pub enum XMLName { /// Check if an element name is valid. See /// for details. -pub fn xml_name_type(name: &str) -> XMLName { +pub(crate) fn xml_name_type(name: &str) -> XMLName { fn is_valid_start(c: char) -> bool { matches!(c, ':' | 'A'..='Z' | @@ -163,7 +163,7 @@ pub fn xml_name_type(name: &str) -> XMLName { /// Convert a possibly-null URL to a namespace. /// /// If the URL is None, returns the empty namespace. -pub fn namespace_from_domstring(url: Option) -> Namespace { +pub(crate) fn namespace_from_domstring(url: Option) -> Namespace { match url { None => ns!(), Some(s) => Namespace::from(s), diff --git a/components/script/dom/biquadfilternode.rs b/components/script/dom/biquadfilternode.rs index 4734e2921fa..160c7279cae 100644 --- a/components/script/dom/biquadfilternode.rs +++ b/components/script/dom/biquadfilternode.rs @@ -31,7 +31,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct BiquadFilterNode { +pub(crate) struct BiquadFilterNode { node: AudioNode, gain: Dom, frequency: Dom, @@ -42,7 +42,7 @@ pub struct BiquadFilterNode { impl BiquadFilterNode { #[allow(crown::unrooted_must_root)] - pub fn new_inherited( + pub(crate) fn new_inherited( window: &Window, context: &BaseAudioContext, options: &BiquadFilterOptions, @@ -114,7 +114,7 @@ impl BiquadFilterNode { }) } - pub fn new( + pub(crate) fn new( window: &Window, context: &BaseAudioContext, options: &BiquadFilterOptions, diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs index 5ab139f3528..d57772a523b 100644 --- a/components/script/dom/blob.rs +++ b/components/script/dom/blob.rs @@ -32,14 +32,14 @@ use crate::script_runtime::CanGc; // https://w3c.github.io/FileAPI/#blob #[dom_struct] -pub struct Blob { +pub(crate) struct Blob { reflector_: Reflector, #[no_trace] blob_id: BlobId, } impl Blob { - pub fn new(global: &GlobalScope, blob_impl: BlobImpl, can_gc: CanGc) -> DomRoot { + pub(crate) fn new(global: &GlobalScope, blob_impl: BlobImpl, can_gc: CanGc) -> DomRoot { Self::new_with_proto(global, None, blob_impl, can_gc) } @@ -60,7 +60,7 @@ impl Blob { } #[allow(crown::unrooted_must_root)] - pub fn new_inherited(blob_impl: &BlobImpl) -> Blob { + pub(crate) fn new_inherited(blob_impl: &BlobImpl) -> Blob { Blob { reflector_: Reflector::new(), blob_id: blob_impl.blob_id(), @@ -68,23 +68,23 @@ impl Blob { } /// Get a slice to inner data, this might incur synchronous read and caching - pub fn get_bytes(&self) -> Result, ()> { + pub(crate) fn get_bytes(&self) -> Result, ()> { self.global().get_blob_bytes(&self.blob_id) } /// Get a copy of the type_string - pub fn type_string(&self) -> String { + pub(crate) fn type_string(&self) -> String { self.global().get_blob_type_string(&self.blob_id) } /// Get a FileID representing the Blob content, /// used by URL.createObjectURL - pub fn get_blob_url_id(&self) -> Uuid { + pub(crate) fn get_blob_url_id(&self) -> Uuid { self.global().get_blob_url_id(&self.blob_id) } /// - pub fn get_stream(&self, can_gc: CanGc) -> Fallible> { + pub(crate) fn get_stream(&self, can_gc: CanGc) -> Fallible> { self.global().get_blob_stream(&self.blob_id, can_gc) } } @@ -162,7 +162,7 @@ impl Serializable for Blob { /// Extract bytes from BlobParts, used by Blob and File constructor /// #[allow(unsafe_code)] -pub fn blob_parts_to_bytes( +pub(crate) fn blob_parts_to_bytes( mut blobparts: Vec, ) -> Result, ()> { let mut ret = vec![]; @@ -302,7 +302,7 @@ impl BlobMethods for Blob { /// XXX: We will relax the restriction here, /// since the spec has some problem over this part. /// see -pub fn normalize_type_string(s: &str) -> String { +pub(crate) fn normalize_type_string(s: &str) -> String { if is_ascii_printable(s) { s.to_ascii_lowercase() // match s_lower.parse() as Result { diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index 539e800814c..bcffa8493d2 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -66,24 +66,24 @@ const BT_DESC_CONVERSION_ERROR: &str = #[derive(JSTraceable, MallocSizeOf)] #[allow(non_snake_case)] -pub struct AllowedBluetoothDevice { - pub deviceId: DOMString, - pub mayUseGATT: bool, +pub(crate) struct AllowedBluetoothDevice { + pub(crate) deviceId: DOMString, + pub(crate) mayUseGATT: bool, } #[derive(JSTraceable, MallocSizeOf)] -pub struct BluetoothExtraPermissionData { +pub(crate) struct BluetoothExtraPermissionData { allowed_devices: DomRefCell>, } impl BluetoothExtraPermissionData { - pub fn new() -> BluetoothExtraPermissionData { + pub(crate) fn new() -> BluetoothExtraPermissionData { BluetoothExtraPermissionData { allowed_devices: DomRefCell::new(Vec::new()), } } - pub fn add_new_allowed_device(&self, allowed_device: AllowedBluetoothDevice) { + pub(crate) fn add_new_allowed_device(&self, allowed_device: AllowedBluetoothDevice) { self.allowed_devices.borrow_mut().push(allowed_device); } @@ -91,7 +91,7 @@ impl BluetoothExtraPermissionData { self.allowed_devices.borrow() } - pub fn allowed_devices_contains_id(&self, id: DOMString) -> bool { + pub(crate) fn allowed_devices_contains_id(&self, id: DOMString) -> bool { self.allowed_devices .borrow() .iter() @@ -110,7 +110,7 @@ struct BluetoothContext { receiver: Trusted, } -pub trait AsyncBluetoothListener { +pub(crate) trait AsyncBluetoothListener { fn handle_response(&self, result: BluetoothResponse, promise: &Rc, can_gc: CanGc); } @@ -138,20 +138,20 @@ where // https://webbluetoothcg.github.io/web-bluetooth/#bluetooth #[dom_struct] -pub struct Bluetooth { +pub(crate) struct Bluetooth { eventtarget: EventTarget, device_instance_map: DomRefCell>>, } impl Bluetooth { - pub fn new_inherited() -> Bluetooth { + pub(crate) fn new_inherited() -> Bluetooth { Bluetooth { eventtarget: EventTarget::new_inherited(), device_instance_map: DomRefCell::new(HashMap::new()), } } - pub fn new(global: &GlobalScope) -> DomRoot { + pub(crate) fn new(global: &GlobalScope) -> DomRoot { reflect_dom_object(Box::new(Bluetooth::new_inherited()), global, CanGc::note()) } @@ -159,7 +159,7 @@ impl Bluetooth { self.global().as_window().bluetooth_thread() } - pub fn get_device_map(&self) -> &DomRefCell>> { + pub(crate) fn get_device_map(&self) -> &DomRefCell>> { &self.device_instance_map } @@ -239,7 +239,7 @@ impl Bluetooth { } } -pub fn response_async( +pub(crate) fn response_async( promise: &Rc, receiver: &T, ) -> IpcSender { @@ -284,7 +284,7 @@ pub fn response_async( // https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren #[allow(clippy::too_many_arguments)] -pub fn get_gatt_children( +pub(crate) fn get_gatt_children( attribute: &T, single: bool, uuid_canonicalizer: F, diff --git a/components/script/dom/bluetoothadvertisingevent.rs b/components/script/dom/bluetoothadvertisingevent.rs index a8287fef086..b33f1e17323 100644 --- a/components/script/dom/bluetoothadvertisingevent.rs +++ b/components/script/dom/bluetoothadvertisingevent.rs @@ -23,7 +23,7 @@ use crate::script_runtime::CanGc; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothadvertisingevent #[dom_struct] -pub struct BluetoothAdvertisingEvent { +pub(crate) struct BluetoothAdvertisingEvent { event: Event, device: Dom, name: Option, @@ -34,7 +34,7 @@ pub struct BluetoothAdvertisingEvent { #[allow(non_snake_case)] impl BluetoothAdvertisingEvent { - pub fn new_inherited( + pub(crate) fn new_inherited( device: &BluetoothDevice, name: Option, appearance: Option, diff --git a/components/script/dom/bluetoothcharacteristicproperties.rs b/components/script/dom/bluetoothcharacteristicproperties.rs index dd7be6e2beb..992bdac6a9f 100644 --- a/components/script/dom/bluetoothcharacteristicproperties.rs +++ b/components/script/dom/bluetoothcharacteristicproperties.rs @@ -12,7 +12,7 @@ use crate::script_runtime::CanGc; // https://webbluetoothcg.github.io/web-bluetooth/#characteristicproperties #[dom_struct] -pub struct BluetoothCharacteristicProperties { +pub(crate) struct BluetoothCharacteristicProperties { reflector_: Reflector, broadcast: bool, read: bool, @@ -28,7 +28,7 @@ pub struct BluetoothCharacteristicProperties { #[allow(non_snake_case)] impl BluetoothCharacteristicProperties { #[allow(clippy::too_many_arguments)] - pub fn new_inherited( + pub(crate) fn new_inherited( broadcast: bool, read: bool, write_without_response: bool, @@ -54,7 +54,7 @@ impl BluetoothCharacteristicProperties { } #[allow(clippy::too_many_arguments)] - pub fn new( + pub(crate) fn new( global: &GlobalScope, broadcast: bool, read: bool, diff --git a/components/script/dom/bluetoothdevice.rs b/components/script/dom/bluetoothdevice.rs index 2848a57dd84..2906260f93f 100644 --- a/components/script/dom/bluetoothdevice.rs +++ b/components/script/dom/bluetoothdevice.rs @@ -45,7 +45,7 @@ struct AttributeInstanceMap { // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice #[dom_struct] -pub struct BluetoothDevice { +pub(crate) struct BluetoothDevice { eventtarget: EventTarget, id: DOMString, name: Option, @@ -56,7 +56,7 @@ pub struct BluetoothDevice { } impl BluetoothDevice { - pub fn new_inherited( + pub(crate) fn new_inherited( id: DOMString, name: Option, context: &Bluetooth, @@ -76,7 +76,7 @@ impl BluetoothDevice { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, id: DOMString, name: Option, @@ -89,7 +89,7 @@ impl BluetoothDevice { ) } - pub fn get_gatt(&self) -> DomRoot { + pub(crate) fn get_gatt(&self) -> DomRoot { self.gatt .or_init(|| BluetoothRemoteGATTServer::new(&self.global(), self)) } @@ -98,7 +98,7 @@ impl BluetoothDevice { DomRoot::from_ref(&self.context) } - pub fn get_or_create_service( + pub(crate) fn get_or_create_service( &self, service: &BluetoothServiceMsg, server: &BluetoothRemoteGATTServer, @@ -119,7 +119,7 @@ impl BluetoothDevice { bt_service } - pub fn get_or_create_characteristic( + pub(crate) fn get_or_create_characteristic( &self, characteristic: &BluetoothCharacteristicMsg, service: &BluetoothRemoteGATTService, @@ -155,7 +155,7 @@ impl BluetoothDevice { bt_characteristic } - pub fn is_represented_device_null(&self) -> bool { + pub(crate) fn is_represented_device_null(&self) -> bool { let (sender, receiver) = ipc::channel(self.global().time_profiler_chan().clone()).unwrap(); self.get_bluetooth_thread() .send(BluetoothRequest::IsRepresentedDeviceNull( @@ -166,7 +166,7 @@ impl BluetoothDevice { receiver.recv().unwrap() } - pub fn get_or_create_descriptor( + pub(crate) fn get_or_create_descriptor( &self, descriptor: &BluetoothDescriptorMsg, characteristic: &BluetoothRemoteGATTCharacteristic, @@ -195,7 +195,7 @@ impl BluetoothDevice { // https://webbluetoothcg.github.io/web-bluetooth/#clean-up-the-disconnected-device #[allow(crown::unrooted_must_root)] - pub fn clean_up_disconnected_device(&self, can_gc: CanGc) { + pub(crate) fn clean_up_disconnected_device(&self, can_gc: CanGc) { // Step 1. self.get_gatt().set_connected(false); @@ -231,7 +231,7 @@ impl BluetoothDevice { // https://webbluetoothcg.github.io/web-bluetooth/#garbage-collect-the-connection #[allow(crown::unrooted_must_root)] - pub fn garbage_collect_the_connection(&self) -> ErrorResult { + pub(crate) fn garbage_collect_the_connection(&self) -> ErrorResult { // Step 1: TODO: Check if other systems using this device. // Step 2. diff --git a/components/script/dom/bluetoothpermissionresult.rs b/components/script/dom/bluetoothpermissionresult.rs index d4ee404fea1..d5817e7c901 100644 --- a/components/script/dom/bluetoothpermissionresult.rs +++ b/components/script/dom/bluetoothpermissionresult.rs @@ -29,7 +29,7 @@ use crate::script_runtime::CanGc; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothpermissionresult #[dom_struct] -pub struct BluetoothPermissionResult { +pub(crate) struct BluetoothPermissionResult { status: PermissionStatus, devices: DomRefCell>>, } @@ -45,7 +45,7 @@ impl BluetoothPermissionResult { result } - pub fn new( + pub(crate) fn new( global: &GlobalScope, status: &PermissionStatus, ) -> DomRoot { @@ -56,28 +56,28 @@ impl BluetoothPermissionResult { ) } - pub fn get_bluetooth(&self) -> DomRoot { + pub(crate) fn get_bluetooth(&self) -> DomRoot { self.global().as_window().Navigator().Bluetooth() } - pub fn get_bluetooth_thread(&self) -> IpcSender { + pub(crate) fn get_bluetooth_thread(&self) -> IpcSender { self.global().as_window().bluetooth_thread() } - pub fn get_query(&self) -> PermissionName { + pub(crate) fn get_query(&self) -> PermissionName { self.status.get_query() } - pub fn set_state(&self, state: PermissionState) { + pub(crate) fn set_state(&self, state: PermissionState) { self.status.set_state(state) } - pub fn get_state(&self) -> PermissionState { + pub(crate) fn get_state(&self) -> PermissionState { self.status.State() } #[allow(crown::unrooted_must_root)] - pub fn set_devices(&self, devices: Vec>) { + pub(crate) fn set_devices(&self, devices: Vec>) { *self.devices.borrow_mut() = devices; } } diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs index 86f50eb464a..9792cd446f4 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetoothremotegattcharacteristic.rs @@ -34,11 +34,11 @@ use crate::script_runtime::CanGc; // Maximum length of an attribute value. // https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=286439 (Vol. 3, page 2169) -pub const MAXIMUM_ATTRIBUTE_LENGTH: usize = 512; +pub(crate) const MAXIMUM_ATTRIBUTE_LENGTH: usize = 512; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic #[dom_struct] -pub struct BluetoothRemoteGATTCharacteristic { +pub(crate) struct BluetoothRemoteGATTCharacteristic { eventtarget: EventTarget, service: Dom, uuid: DOMString, @@ -48,7 +48,7 @@ pub struct BluetoothRemoteGATTCharacteristic { } impl BluetoothRemoteGATTCharacteristic { - pub fn new_inherited( + pub(crate) fn new_inherited( service: &BluetoothRemoteGATTService, uuid: DOMString, properties: &BluetoothCharacteristicProperties, @@ -64,7 +64,7 @@ impl BluetoothRemoteGATTCharacteristic { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, service: &BluetoothRemoteGATTService, uuid: DOMString, diff --git a/components/script/dom/bluetoothremotegattdescriptor.rs b/components/script/dom/bluetoothremotegattdescriptor.rs index d0b810fd1e4..ffdaa22ad19 100644 --- a/components/script/dom/bluetoothremotegattdescriptor.rs +++ b/components/script/dom/bluetoothremotegattdescriptor.rs @@ -30,7 +30,7 @@ use crate::script_runtime::CanGc; // http://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattdescriptor #[dom_struct] -pub struct BluetoothRemoteGATTDescriptor { +pub(crate) struct BluetoothRemoteGATTDescriptor { reflector_: Reflector, characteristic: Dom, uuid: DOMString, @@ -39,7 +39,7 @@ pub struct BluetoothRemoteGATTDescriptor { } impl BluetoothRemoteGATTDescriptor { - pub fn new_inherited( + pub(crate) fn new_inherited( characteristic: &BluetoothRemoteGATTCharacteristic, uuid: DOMString, instance_id: String, @@ -53,7 +53,7 @@ impl BluetoothRemoteGATTDescriptor { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, characteristic: &BluetoothRemoteGATTCharacteristic, uuid: DOMString, diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetoothremotegattserver.rs index bbcead3cbe1..ac08035fe91 100644 --- a/components/script/dom/bluetoothremotegattserver.rs +++ b/components/script/dom/bluetoothremotegattserver.rs @@ -24,14 +24,14 @@ use crate::script_runtime::CanGc; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattserver #[dom_struct] -pub struct BluetoothRemoteGATTServer { +pub(crate) struct BluetoothRemoteGATTServer { reflector_: Reflector, device: Dom, connected: Cell, } impl BluetoothRemoteGATTServer { - pub fn new_inherited(device: &BluetoothDevice) -> BluetoothRemoteGATTServer { + pub(crate) fn new_inherited(device: &BluetoothDevice) -> BluetoothRemoteGATTServer { BluetoothRemoteGATTServer { reflector_: Reflector::new(), device: Dom::from_ref(device), @@ -39,7 +39,7 @@ impl BluetoothRemoteGATTServer { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, device: &BluetoothDevice, ) -> DomRoot { @@ -54,7 +54,7 @@ impl BluetoothRemoteGATTServer { self.global().as_window().bluetooth_thread() } - pub fn set_connected(&self, connected: bool) { + pub(crate) fn set_connected(&self, connected: bool) { self.connected.set(connected); } } diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetoothremotegattservice.rs index 223aaf0c0fe..014f78d2669 100644 --- a/components/script/dom/bluetoothremotegattservice.rs +++ b/components/script/dom/bluetoothremotegattservice.rs @@ -23,7 +23,7 @@ use crate::script_runtime::CanGc; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice #[dom_struct] -pub struct BluetoothRemoteGATTService { +pub(crate) struct BluetoothRemoteGATTService { eventtarget: EventTarget, device: Dom, uuid: DOMString, @@ -32,7 +32,7 @@ pub struct BluetoothRemoteGATTService { } impl BluetoothRemoteGATTService { - pub fn new_inherited( + pub(crate) fn new_inherited( device: &BluetoothDevice, uuid: DOMString, is_primary: bool, @@ -48,7 +48,7 @@ impl BluetoothRemoteGATTService { } #[allow(non_snake_case)] - pub fn new( + pub(crate) fn new( global: &GlobalScope, device: &BluetoothDevice, uuid: DOMString, diff --git a/components/script/dom/bluetoothuuid.rs b/components/script/dom/bluetoothuuid.rs index e39937d3b3d..719625eb659 100644 --- a/components/script/dom/bluetoothuuid.rs +++ b/components/script/dom/bluetoothuuid.rs @@ -14,14 +14,14 @@ use crate::dom::bindings::str::DOMString; use crate::dom::window::Window; #[allow(clippy::upper_case_acronyms)] -pub type UUID = DOMString; -pub type BluetoothServiceUUID = StringOrUnsignedLong; -pub type BluetoothCharacteristicUUID = StringOrUnsignedLong; -pub type BluetoothDescriptorUUID = StringOrUnsignedLong; +pub(crate) type UUID = DOMString; +pub(crate) type BluetoothServiceUUID = StringOrUnsignedLong; +pub(crate) type BluetoothCharacteristicUUID = StringOrUnsignedLong; +pub(crate) type BluetoothDescriptorUUID = StringOrUnsignedLong; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothuuid #[dom_struct] -pub struct BluetoothUUID { +pub(crate) struct BluetoothUUID { reflector_: Reflector, } @@ -607,11 +607,11 @@ impl BluetoothUUIDMethods for BluetoothUUID { } impl BluetoothUUID { - pub fn service(name: BluetoothServiceUUID) -> Fallible { + pub(crate) fn service(name: BluetoothServiceUUID) -> Fallible { resolve_uuid_name(name, BLUETOOTH_ASSIGNED_SERVICES, SERVICE_PREFIX) } - pub fn characteristic(name: BluetoothCharacteristicUUID) -> Fallible { + pub(crate) fn characteristic(name: BluetoothCharacteristicUUID) -> Fallible { resolve_uuid_name( name, BLUETOOTH_ASSIGNED_CHARCTERISTICS, @@ -619,7 +619,7 @@ impl BluetoothUUID { ) } - pub fn descriptor(name: BluetoothDescriptorUUID) -> Fallible { + pub(crate) fn descriptor(name: BluetoothDescriptorUUID) -> Fallible { resolve_uuid_name(name, BLUETOOTH_ASSIGNED_DESCRIPTORS, DESCRIPTOR_PREFIX) } } diff --git a/components/script/dom/broadcastchannel.rs b/components/script/dom/broadcastchannel.rs index dd0699ff895..632825b1412 100644 --- a/components/script/dom/broadcastchannel.rs +++ b/components/script/dom/broadcastchannel.rs @@ -20,7 +20,7 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::{CanGc, JSContext as SafeJSContext}; #[dom_struct] -pub struct BroadcastChannel { +pub(crate) struct BroadcastChannel { eventtarget: EventTarget, name: DOMString, closed: Cell, @@ -45,7 +45,7 @@ impl BroadcastChannel { channel } - pub fn new_inherited(name: DOMString) -> BroadcastChannel { + pub(crate) fn new_inherited(name: DOMString) -> BroadcastChannel { BroadcastChannel { eventtarget: EventTarget::new_inherited(), name, @@ -56,12 +56,12 @@ impl BroadcastChannel { /// The unique Id of this channel. /// Used for filtering out the sender from the local broadcast. - pub fn id(&self) -> &Uuid { + pub(crate) fn id(&self) -> &Uuid { &self.id } /// Is this channel closed? - pub fn closed(&self) -> bool { + pub(crate) fn closed(&self) -> bool { self.closed.get() } } diff --git a/components/script/dom/bytelengthqueuingstrategy.rs b/components/script/dom/bytelengthqueuingstrategy.rs index 55b8e4e8815..ad4375edc35 100644 --- a/components/script/dom/bytelengthqueuingstrategy.rs +++ b/components/script/dom/bytelengthqueuingstrategy.rs @@ -22,20 +22,20 @@ use crate::native_fn; use crate::script_runtime::CanGc; #[dom_struct] -pub struct ByteLengthQueuingStrategy { +pub(crate) struct ByteLengthQueuingStrategy { reflector_: Reflector, high_water_mark: f64, } impl ByteLengthQueuingStrategy { - pub fn new_inherited(init: f64) -> Self { + pub(crate) fn new_inherited(init: f64) -> Self { Self { reflector_: Reflector::new(), high_water_mark: init, } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, proto: Option, init: f64, @@ -85,7 +85,7 @@ impl ByteLengthQueuingStrategyMethods for ByteLengthQueuin /// #[allow(unsafe_code)] -pub unsafe fn byte_length_queuing_strategy_size( +pub(crate) unsafe fn byte_length_queuing_strategy_size( cx: *mut JSContext, argc: u32, vp: *mut JSVal, diff --git a/components/script/dom/canvasgradient.rs b/components/script/dom/canvasgradient.rs index 2d7d1789026..690ac2fcc2c 100644 --- a/components/script/dom/canvasgradient.rs +++ b/components/script/dom/canvasgradient.rs @@ -20,7 +20,7 @@ use crate::script_runtime::CanGc; // https://html.spec.whatwg.org/multipage/#canvasgradient #[dom_struct] -pub struct CanvasGradient { +pub(crate) struct CanvasGradient { reflector_: Reflector, style: CanvasGradientStyle, #[no_trace] @@ -28,7 +28,7 @@ pub struct CanvasGradient { } #[derive(Clone, JSTraceable, MallocSizeOf)] -pub enum CanvasGradientStyle { +pub(crate) enum CanvasGradientStyle { Linear(#[no_trace] LinearGradientStyle), Radial(#[no_trace] RadialGradientStyle), } @@ -42,7 +42,7 @@ impl CanvasGradient { } } - pub fn new(global: &GlobalScope, style: CanvasGradientStyle) -> DomRoot { + pub(crate) fn new(global: &GlobalScope, style: CanvasGradientStyle) -> DomRoot { reflect_dom_object( Box::new(CanvasGradient::new_inherited(style)), global, @@ -71,7 +71,7 @@ impl CanvasGradientMethods for CanvasGradient { } } -pub trait ToFillOrStrokeStyle { +pub(crate) trait ToFillOrStrokeStyle { fn to_fill_or_stroke_style(self) -> FillOrStrokeStyle; } diff --git a/components/script/dom/canvaspattern.rs b/components/script/dom/canvaspattern.rs index 238c561e880..d8e59a2d7eb 100644 --- a/components/script/dom/canvaspattern.rs +++ b/components/script/dom/canvaspattern.rs @@ -14,7 +14,7 @@ use crate::script_runtime::CanGc; // https://html.spec.whatwg.org/multipage/#canvaspattern #[dom_struct] -pub struct CanvasPattern { +pub(crate) struct CanvasPattern { reflector_: Reflector, surface_data: Vec, #[no_trace] @@ -47,7 +47,7 @@ impl CanvasPattern { origin_clean, } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, surface_data: Vec, surface_size: Size2D, @@ -65,7 +65,7 @@ impl CanvasPattern { CanGc::note(), ) } - pub fn origin_is_clean(&self) -> bool { + pub(crate) fn origin_is_clean(&self) -> bool { self.origin_clean } } diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index 889068dff96..b91680545df 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -30,7 +30,7 @@ use crate::script_runtime::CanGc; // https://html.spec.whatwg.org/multipage/#canvasrenderingcontext2d #[dom_struct] -pub struct CanvasRenderingContext2D { +pub(crate) struct CanvasRenderingContext2D { reflector_: Reflector, /// For rendering contexts created by an HTML canvas element, this is Some, /// for ones created by a paint worklet, this is None. @@ -39,7 +39,7 @@ pub struct CanvasRenderingContext2D { } impl CanvasRenderingContext2D { - pub fn new_inherited( + pub(crate) fn new_inherited( global: &GlobalScope, canvas: Option<&HTMLCanvasElement>, size: Size2D, @@ -54,7 +54,7 @@ impl CanvasRenderingContext2D { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, canvas: &HTMLCanvasElement, size: Size2D, @@ -68,7 +68,7 @@ impl CanvasRenderingContext2D { } // https://html.spec.whatwg.org/multipage/#concept-canvas-set-bitmap-dimensions - pub fn set_bitmap_dimensions(&self, size: Size2D) { + pub(crate) fn set_bitmap_dimensions(&self, size: Size2D) { self.reset_to_initial_state(); self.canvas_state .get_ipc_renderer() @@ -84,36 +84,36 @@ impl CanvasRenderingContext2D { self.canvas_state.reset_to_initial_state(); } - pub fn set_canvas_bitmap_dimensions(&self, size: Size2D) { + pub(crate) fn set_canvas_bitmap_dimensions(&self, size: Size2D) { self.canvas_state.set_bitmap_dimensions(size); } - pub fn mark_as_dirty(&self) { + pub(crate) fn mark_as_dirty(&self) { self.canvas_state.mark_as_dirty(self.canvas.as_deref()) } - pub fn take_missing_image_urls(&self) -> Vec { + pub(crate) fn take_missing_image_urls(&self) -> Vec { std::mem::take(&mut self.canvas_state.get_missing_image_urls().borrow_mut()) } - pub fn get_canvas_id(&self) -> CanvasId { + pub(crate) fn get_canvas_id(&self) -> CanvasId { self.canvas_state.get_canvas_id() } - pub fn send_canvas_2d_msg(&self, msg: Canvas2dMsg) { + pub(crate) fn send_canvas_2d_msg(&self, msg: Canvas2dMsg) { self.canvas_state.send_canvas_2d_msg(msg) } // TODO: Remove this - pub fn get_ipc_renderer(&self) -> IpcSender { + pub(crate) fn get_ipc_renderer(&self) -> IpcSender { self.canvas_state.get_ipc_renderer().clone() } - pub fn origin_is_clean(&self) -> bool { + pub(crate) fn origin_is_clean(&self) -> bool { self.canvas_state.origin_is_clean() } - pub fn get_rect(&self, rect: Rect) -> Vec { + pub(crate) fn get_rect(&self, rect: Rect) -> Vec { let rect = Rect::new( Point2D::new(rect.origin.x as u64, rect.origin.y as u64), Size2D::new(rect.size.width as u64, rect.size.height as u64), @@ -127,7 +127,7 @@ impl CanvasRenderingContext2D { } } -pub trait LayoutCanvasRenderingContext2DHelpers { +pub(crate) trait LayoutCanvasRenderingContext2DHelpers { fn get_ipc_renderer(self) -> IpcSender; fn get_canvas_id(self) -> CanvasId; } diff --git a/components/script/dom/cdatasection.rs b/components/script/dom/cdatasection.rs index 29151354044..1250eb939fc 100644 --- a/components/script/dom/cdatasection.rs +++ b/components/script/dom/cdatasection.rs @@ -12,7 +12,7 @@ use crate::dom::text::Text; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CDATASection { +pub(crate) struct CDATASection { text: Text, } @@ -23,7 +23,11 @@ impl CDATASection { } } - pub fn new(text: DOMString, document: &Document, can_gc: CanGc) -> DomRoot { + pub(crate) fn new( + text: DOMString, + document: &Document, + can_gc: CanGc, + ) -> DomRoot { Node::reflect_node( Box::new(CDATASection::new_inherited(text, document)), document, diff --git a/components/script/dom/channelmergernode.rs b/components/script/dom/channelmergernode.rs index db9cb5c7e55..a22d36eae91 100644 --- a/components/script/dom/channelmergernode.rs +++ b/components/script/dom/channelmergernode.rs @@ -22,13 +22,13 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct ChannelMergerNode { +pub(crate) struct ChannelMergerNode { node: AudioNode, } impl ChannelMergerNode { #[allow(crown::unrooted_must_root)] - pub fn new_inherited( + pub(crate) fn new_inherited( _: &Window, context: &BaseAudioContext, options: &ChannelMergerOptions, @@ -57,7 +57,7 @@ impl ChannelMergerNode { Ok(ChannelMergerNode { node }) } - pub fn new( + pub(crate) fn new( window: &Window, context: &BaseAudioContext, options: &ChannelMergerOptions, diff --git a/components/script/dom/channelsplitternode.rs b/components/script/dom/channelsplitternode.rs index a058a898c85..97f881113d9 100644 --- a/components/script/dom/channelsplitternode.rs +++ b/components/script/dom/channelsplitternode.rs @@ -21,13 +21,13 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct ChannelSplitterNode { +pub(crate) struct ChannelSplitterNode { node: AudioNode, } impl ChannelSplitterNode { #[allow(crown::unrooted_must_root)] - pub fn new_inherited( + pub(crate) fn new_inherited( _: &Window, context: &BaseAudioContext, options: &ChannelSplitterOptions, @@ -59,7 +59,7 @@ impl ChannelSplitterNode { Ok(ChannelSplitterNode { node }) } - pub fn new( + pub(crate) fn new( window: &Window, context: &BaseAudioContext, options: &ChannelSplitterOptions, diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs index cc523e13964..381f7e4e59b 100644 --- a/components/script/dom/characterdata.rs +++ b/components/script/dom/characterdata.rs @@ -29,20 +29,20 @@ use crate::script_runtime::CanGc; // https://dom.spec.whatwg.org/#characterdata #[dom_struct] -pub struct CharacterData { +pub(crate) struct CharacterData { node: Node, data: DomRefCell, } impl CharacterData { - pub fn new_inherited(data: DOMString, document: &Document) -> CharacterData { + pub(crate) fn new_inherited(data: DOMString, document: &Document) -> CharacterData { CharacterData { node: Node::new_inherited(document), data: DomRefCell::new(data), } } - pub fn clone_with_data( + pub(crate) fn clone_with_data( &self, data: DOMString, document: &Document, @@ -72,12 +72,12 @@ impl CharacterData { } #[inline] - pub fn data(&self) -> Ref { + pub(crate) fn data(&self) -> Ref { self.data.borrow() } #[inline] - pub fn append_data(&self, data: &str) { + pub(crate) fn append_data(&self, data: &str) { self.queue_mutation_record(); self.data.borrow_mut().push_str(data); self.content_changed(); @@ -291,7 +291,7 @@ impl CharacterDataMethods for CharacterData { } } -pub trait LayoutCharacterDataHelpers<'dom> { +pub(crate) trait LayoutCharacterDataHelpers<'dom> { fn data_for_layout(self) -> &'dom str; } diff --git a/components/script/dom/client.rs b/components/script/dom/client.rs index b0bdd872722..8fefc650325 100644 --- a/components/script/dom/client.rs +++ b/components/script/dom/client.rs @@ -17,7 +17,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct Client { +pub(crate) struct Client { reflector_: Reflector, active_worker: MutNullableDom, #[no_trace] @@ -39,7 +39,7 @@ impl Client { } } - pub fn new(window: &Window) -> DomRoot { + pub(crate) fn new(window: &Window) -> DomRoot { reflect_dom_object( Box::new(Client::new_inherited(window.get_url())), window, @@ -47,16 +47,16 @@ impl Client { ) } - pub fn creation_url(&self) -> ServoUrl { + pub(crate) fn creation_url(&self) -> ServoUrl { self.url.clone() } - pub fn get_controller(&self) -> Option> { + pub(crate) fn get_controller(&self) -> Option> { self.active_worker.get() } #[allow(dead_code)] - pub fn set_controller(&self, worker: &ServiceWorker) { + pub(crate) fn set_controller(&self, worker: &ServiceWorker) { self.active_worker.set(Some(worker)); } } diff --git a/components/script/dom/closeevent.rs b/components/script/dom/closeevent.rs index 3b7faf97356..3237f953f69 100644 --- a/components/script/dom/closeevent.rs +++ b/components/script/dom/closeevent.rs @@ -19,7 +19,7 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CloseEvent { +pub(crate) struct CloseEvent { event: Event, was_clean: bool, code: u16, @@ -28,7 +28,7 @@ pub struct CloseEvent { #[allow(non_snake_case)] impl CloseEvent { - pub fn new_inherited(was_clean: bool, code: u16, reason: DOMString) -> CloseEvent { + pub(crate) fn new_inherited(was_clean: bool, code: u16, reason: DOMString) -> CloseEvent { CloseEvent { event: Event::new_inherited(), was_clean, @@ -38,7 +38,7 @@ impl CloseEvent { } #[allow(clippy::too_many_arguments)] - pub fn new( + pub(crate) fn new( global: &GlobalScope, type_: Atom, bubbles: EventBubbles, diff --git a/components/script/dom/comment.rs b/components/script/dom/comment.rs index a5b9fd4c43a..cfd75e08ae4 100644 --- a/components/script/dom/comment.rs +++ b/components/script/dom/comment.rs @@ -18,7 +18,7 @@ use crate::script_runtime::CanGc; /// An HTML comment. #[dom_struct] -pub struct Comment { +pub(crate) struct Comment { characterdata: CharacterData, } @@ -29,7 +29,7 @@ impl Comment { } } - pub fn new( + pub(crate) fn new( text: DOMString, document: &Document, proto: Option, diff --git a/components/script/dom/compositionevent.rs b/components/script/dom/compositionevent.rs index 067b23ec529..65c3c0da0c2 100644 --- a/components/script/dom/compositionevent.rs +++ b/components/script/dom/compositionevent.rs @@ -18,20 +18,20 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CompositionEvent { +pub(crate) struct CompositionEvent { uievent: UIEvent, data: DOMString, } impl CompositionEvent { - pub fn new_inherited() -> CompositionEvent { + pub(crate) fn new_inherited() -> CompositionEvent { CompositionEvent { uievent: UIEvent::new_inherited(), data: DOMString::new(), } } - pub fn new_uninitialized(window: &Window) -> DomRoot { + pub(crate) fn new_uninitialized(window: &Window) -> DomRoot { reflect_dom_object( Box::new(CompositionEvent::new_inherited()), window, @@ -40,7 +40,7 @@ impl CompositionEvent { } #[allow(clippy::too_many_arguments)] - pub fn new( + pub(crate) fn new( window: &Window, type_: DOMString, can_bubble: bool, @@ -81,7 +81,7 @@ impl CompositionEvent { ev } - pub fn data(&self) -> &str { + pub(crate) fn data(&self) -> &str { &self.data } } diff --git a/components/script/dom/console.rs b/components/script/dom/console.rs index b45d65d210d..ae9ac12af3f 100644 --- a/components/script/dom/console.rs +++ b/components/script/dom/console.rs @@ -31,7 +31,7 @@ const MAX_LOG_DEPTH: usize = 10; const MAX_LOG_CHILDREN: usize = 15; /// -pub struct Console; +pub(crate) struct Console; impl Console { #[allow(unsafe_code)] @@ -86,7 +86,7 @@ impl Console { } // Directly logs a DOMString, without processing the message - pub fn internal_warn(global: &GlobalScope, message: DOMString) { + pub(crate) fn internal_warn(global: &GlobalScope, message: DOMString) { Console::send_string_message(global, LogLevel::Warn, String::from(message.clone())); console_message(global, message); } diff --git a/components/script/dom/constantsourcenode.rs b/components/script/dom/constantsourcenode.rs index 76735093d39..63ee0ac5dcb 100644 --- a/components/script/dom/constantsourcenode.rs +++ b/components/script/dom/constantsourcenode.rs @@ -24,7 +24,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct ConstantSourceNode { +pub(crate) struct ConstantSourceNode { source_node: AudioScheduledSourceNode, offset: Dom, } @@ -63,7 +63,7 @@ impl ConstantSourceNode { }) } - pub fn new( + pub(crate) fn new( window: &Window, context: &BaseAudioContext, options: &ConstantSourceOptions, diff --git a/components/script/dom/countqueuingstrategy.rs b/components/script/dom/countqueuingstrategy.rs index 73552c57b5b..474a17d93c3 100644 --- a/components/script/dom/countqueuingstrategy.rs +++ b/components/script/dom/countqueuingstrategy.rs @@ -20,20 +20,20 @@ use crate::script_runtime::CanGc; use crate::{native_fn, native_raw_obj_fn}; #[dom_struct] -pub struct CountQueuingStrategy { +pub(crate) struct CountQueuingStrategy { reflector_: Reflector, high_water_mark: f64, } impl CountQueuingStrategy { - pub fn new_inherited(init: f64) -> Self { + pub(crate) fn new_inherited(init: f64) -> Self { Self { reflector_: Reflector::new(), high_water_mark: init, } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, proto: Option, init: f64, @@ -84,7 +84,11 @@ impl CountQueuingStrategyMethods for CountQueuingStrategy /// #[allow(unsafe_code)] -pub unsafe fn count_queuing_strategy_size(_cx: *mut JSContext, argc: u32, vp: *mut JSVal) -> bool { +pub(crate) unsafe fn count_queuing_strategy_size( + _cx: *mut JSContext, + argc: u32, + vp: *mut JSVal, +) -> bool { let args = CallArgs::from_vp(vp, argc); // Step 1.1. Return 1. args.rval().set(Int32Value(1)); @@ -95,7 +99,10 @@ pub unsafe fn count_queuing_strategy_size(_cx: *mut JSContext, argc: u32, vp: *m /// If the high water mark is not set, return the default value. /// /// -pub fn extract_high_water_mark(strategy: &QueuingStrategy, default_hwm: f64) -> Result { +pub(crate) fn extract_high_water_mark( + strategy: &QueuingStrategy, + default_hwm: f64, +) -> Result { if strategy.highWaterMark.is_none() { return Ok(default_hwm); } @@ -114,7 +121,7 @@ pub fn extract_high_water_mark(strategy: &QueuingStrategy, default_hwm: f64) -> /// If the size algorithm is not set, return a fallback function which always returns 1. /// /// -pub fn extract_size_algorithm(strategy: &QueuingStrategy) -> Rc { +pub(crate) fn extract_size_algorithm(strategy: &QueuingStrategy) -> Rc { if strategy.size.is_none() { let cx = GlobalScope::get_cx(); let fun_obj = native_raw_obj_fn!(cx, count_queuing_strategy_size, c"size", 0, 0); diff --git a/components/script/dom/create.rs b/components/script/dom/create.rs index df04898908f..7f3dfdac540 100644 --- a/components/script/dom/create.rs +++ b/components/script/dom/create.rs @@ -221,7 +221,7 @@ fn create_html_element( result } -pub fn create_native_html_element( +pub(crate) fn create_native_html_element( name: QualName, prefix: Option, document: &Document, @@ -394,7 +394,7 @@ pub fn create_native_html_element( } } -pub fn create_element( +pub(crate) fn create_element( name: QualName, is: Option, document: &Document, diff --git a/components/script/dom/crypto.rs b/components/script/dom/crypto.rs index f15146aaec5..fa758c06efa 100644 --- a/components/script/dom/crypto.rs +++ b/components/script/dom/crypto.rs @@ -21,7 +21,7 @@ use crate::script_runtime::{CanGc, JSContext}; // https://developer.mozilla.org/en-US/docs/Web/API/Crypto #[dom_struct] -pub struct Crypto { +pub(crate) struct Crypto { reflector_: Reflector, #[no_trace] rng: DomRefCell, @@ -37,7 +37,7 @@ impl Crypto { } } - pub fn new(global: &GlobalScope) -> DomRoot { + pub(crate) fn new(global: &GlobalScope) -> DomRoot { reflect_dom_object(Box::new(Crypto::new_inherited()), global, CanGc::note()) } } diff --git a/components/script/dom/cryptokey.rs b/components/script/dom/cryptokey.rs index 45fc70814bd..1e149c6773e 100644 --- a/components/script/dom/cryptokey.rs +++ b/components/script/dom/cryptokey.rs @@ -22,7 +22,7 @@ use crate::script_runtime::{CanGc, JSContext}; /// The underlying cryptographic data this key represents #[allow(dead_code)] #[derive(MallocSizeOf)] -pub enum Handle { +pub(crate) enum Handle { Aes128(Vec), Aes192(Vec), Aes256(Vec), @@ -33,7 +33,7 @@ pub enum Handle { /// #[dom_struct] -pub struct CryptoKey { +pub(crate) struct CryptoKey { reflector_: Reflector, /// @@ -78,7 +78,7 @@ impl CryptoKey { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, key_type: KeyType, extractable: bool, @@ -104,15 +104,15 @@ impl CryptoKey { object } - pub fn algorithm(&self) -> String { + pub(crate) fn algorithm(&self) -> String { self.algorithm.to_string() } - pub fn usages(&self) -> &[KeyUsage] { + pub(crate) fn usages(&self) -> &[KeyUsage] { &self.usages } - pub fn handle(&self) -> &Handle { + pub(crate) fn handle(&self) -> &Handle { &self.handle } } @@ -145,7 +145,7 @@ impl CryptoKeyMethods for CryptoKey { } impl Handle { - pub fn as_bytes(&self) -> &[u8] { + pub(crate) fn as_bytes(&self) -> &[u8] { match self { Self::Aes128(bytes) => bytes, Self::Aes192(bytes) => bytes, diff --git a/components/script/dom/css.rs b/components/script/dom/css.rs index 6105ce80629..f7fdee79350 100644 --- a/components/script/dom/css.rs +++ b/components/script/dom/css.rs @@ -21,7 +21,7 @@ use crate::dom::worklet::Worklet; #[dom_struct] #[allow(clippy::upper_case_acronyms)] -pub struct CSS { +pub(crate) struct CSS { reflector_: Reflector, } diff --git a/components/script/dom/cssconditionrule.rs b/components/script/dom/cssconditionrule.rs index 78d7cfa2524..ce1e652aa1a 100644 --- a/components/script/dom/cssconditionrule.rs +++ b/components/script/dom/cssconditionrule.rs @@ -16,12 +16,12 @@ use crate::dom::cssstylesheet::CSSStyleSheet; use crate::dom::csssupportsrule::CSSSupportsRule; #[dom_struct] -pub struct CSSConditionRule { +pub(crate) struct CSSConditionRule { cssgroupingrule: CSSGroupingRule, } impl CSSConditionRule { - pub fn new_inherited( + pub(crate) fn new_inherited( parent_stylesheet: &CSSStyleSheet, rules: Arc>, ) -> CSSConditionRule { @@ -30,11 +30,11 @@ impl CSSConditionRule { } } - pub fn parent_stylesheet(&self) -> &CSSStyleSheet { + pub(crate) fn parent_stylesheet(&self) -> &CSSStyleSheet { self.cssgroupingrule.parent_stylesheet() } - pub fn shared_lock(&self) -> &SharedRwLock { + pub(crate) fn shared_lock(&self) -> &SharedRwLock { self.cssgroupingrule.shared_lock() } } diff --git a/components/script/dom/cssfontfacerule.rs b/components/script/dom/cssfontfacerule.rs index d0eee47ea91..da63e604e60 100644 --- a/components/script/dom/cssfontfacerule.rs +++ b/components/script/dom/cssfontfacerule.rs @@ -16,7 +16,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CSSFontFaceRule { +pub(crate) struct CSSFontFaceRule { cssrule: CSSRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] @@ -35,7 +35,7 @@ impl CSSFontFaceRule { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, fontfacerule: Arc>, diff --git a/components/script/dom/cssgroupingrule.rs b/components/script/dom/cssgroupingrule.rs index 8dbfd4ac7cc..1c357121e85 100644 --- a/components/script/dom/cssgroupingrule.rs +++ b/components/script/dom/cssgroupingrule.rs @@ -18,7 +18,7 @@ use crate::dom::cssrulelist::{CSSRuleList, RulesSource}; use crate::dom::cssstylesheet::CSSStyleSheet; #[dom_struct] -pub struct CSSGroupingRule { +pub(crate) struct CSSGroupingRule { cssrule: CSSRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] @@ -27,7 +27,7 @@ pub struct CSSGroupingRule { } impl CSSGroupingRule { - pub fn new_inherited( + pub(crate) fn new_inherited( parent_stylesheet: &CSSStyleSheet, rules: Arc>, ) -> CSSGroupingRule { @@ -49,11 +49,11 @@ impl CSSGroupingRule { }) } - pub fn parent_stylesheet(&self) -> &CSSStyleSheet { + pub(crate) fn parent_stylesheet(&self) -> &CSSStyleSheet { self.cssrule.parent_stylesheet() } - pub fn shared_lock(&self) -> &SharedRwLock { + pub(crate) fn shared_lock(&self) -> &SharedRwLock { self.cssrule.shared_lock() } } diff --git a/components/script/dom/cssimportrule.rs b/components/script/dom/cssimportrule.rs index da63ab7df0e..f70e6182fd1 100644 --- a/components/script/dom/cssimportrule.rs +++ b/components/script/dom/cssimportrule.rs @@ -19,7 +19,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CSSImportRule { +pub(crate) struct CSSImportRule { cssrule: CSSRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] @@ -38,7 +38,7 @@ impl CSSImportRule { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, import_rule: Arc>, diff --git a/components/script/dom/csskeyframerule.rs b/components/script/dom/csskeyframerule.rs index ae0097ab7a9..36b14e96df6 100644 --- a/components/script/dom/csskeyframerule.rs +++ b/components/script/dom/csskeyframerule.rs @@ -20,7 +20,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CSSKeyframeRule { +pub(crate) struct CSSKeyframeRule { cssrule: CSSRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] @@ -41,7 +41,7 @@ impl CSSKeyframeRule { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, keyframerule: Arc>, diff --git a/components/script/dom/csskeyframesrule.rs b/components/script/dom/csskeyframesrule.rs index 1312dfe4eaa..f7fa24940f7 100644 --- a/components/script/dom/csskeyframesrule.rs +++ b/components/script/dom/csskeyframesrule.rs @@ -24,7 +24,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CSSKeyframesRule { +pub(crate) struct CSSKeyframesRule { cssrule: CSSRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] @@ -45,7 +45,7 @@ impl CSSKeyframesRule { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, keyframesrule: Arc>, diff --git a/components/script/dom/csslayerblockrule.rs b/components/script/dom/csslayerblockrule.rs index a3d691c563e..b9db7dbd406 100644 --- a/components/script/dom/csslayerblockrule.rs +++ b/components/script/dom/csslayerblockrule.rs @@ -19,7 +19,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CSSLayerBlockRule { +pub(crate) struct CSSLayerBlockRule { cssgroupingrule: CSSGroupingRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] @@ -27,7 +27,7 @@ pub struct CSSLayerBlockRule { } impl CSSLayerBlockRule { - pub fn new_inherited( + pub(crate) fn new_inherited( parent_stylesheet: &CSSStyleSheet, layerblockrule: Arc, ) -> CSSLayerBlockRule { @@ -41,7 +41,7 @@ impl CSSLayerBlockRule { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, layerblockrule: Arc, diff --git a/components/script/dom/csslayerstatementrule.rs b/components/script/dom/csslayerstatementrule.rs index b4859a49b83..df14579ee61 100644 --- a/components/script/dom/csslayerstatementrule.rs +++ b/components/script/dom/csslayerstatementrule.rs @@ -20,7 +20,7 @@ use crate::dom::window::Window; use crate::script_runtime::{CanGc, JSContext as SafeJSContext}; #[dom_struct] -pub struct CSSLayerStatementRule { +pub(crate) struct CSSLayerStatementRule { cssrule: CSSRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] @@ -28,7 +28,7 @@ pub struct CSSLayerStatementRule { } impl CSSLayerStatementRule { - pub fn new_inherited( + pub(crate) fn new_inherited( parent_stylesheet: &CSSStyleSheet, layerstatementrule: Arc, ) -> CSSLayerStatementRule { @@ -39,7 +39,7 @@ impl CSSLayerStatementRule { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, layerstatementrule: Arc, diff --git a/components/script/dom/cssmediarule.rs b/components/script/dom/cssmediarule.rs index 02753bf3b60..a4f48554cdd 100644 --- a/components/script/dom/cssmediarule.rs +++ b/components/script/dom/cssmediarule.rs @@ -20,7 +20,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CSSMediaRule { +pub(crate) struct CSSMediaRule { cssconditionrule: CSSConditionRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] @@ -39,7 +39,7 @@ impl CSSMediaRule { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, mediarule: Arc, @@ -62,7 +62,7 @@ impl CSSMediaRule { } /// - pub fn get_condition_text(&self) -> DOMString { + pub(crate) fn get_condition_text(&self) -> DOMString { let guard = self.cssconditionrule.shared_lock().read(); let list = self.mediarule.media_queries.read_with(&guard); list.to_css_string().into() diff --git a/components/script/dom/cssnamespacerule.rs b/components/script/dom/cssnamespacerule.rs index df4fcce690b..4285df722f3 100644 --- a/components/script/dom/cssnamespacerule.rs +++ b/components/script/dom/cssnamespacerule.rs @@ -17,7 +17,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CSSNamespaceRule { +pub(crate) struct CSSNamespaceRule { cssrule: CSSRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] @@ -36,7 +36,7 @@ impl CSSNamespaceRule { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, namespacerule: Arc, diff --git a/components/script/dom/cssrule.rs b/components/script/dom/cssrule.rs index 6f688d5363e..5cbc002114d 100644 --- a/components/script/dom/cssrule.rs +++ b/components/script/dom/cssrule.rs @@ -27,7 +27,7 @@ use crate::dom::csssupportsrule::CSSSupportsRule; use crate::dom::window::Window; #[dom_struct] -pub struct CSSRule { +pub(crate) struct CSSRule { reflector_: Reflector, parent_stylesheet: Dom, @@ -39,7 +39,7 @@ pub struct CSSRule { impl CSSRule { #[allow(crown::unrooted_must_root)] - pub fn new_inherited(parent_stylesheet: &CSSStyleSheet) -> CSSRule { + pub(crate) fn new_inherited(parent_stylesheet: &CSSStyleSheet) -> CSSRule { CSSRule { reflector_: Reflector::new(), parent_stylesheet: Dom::from_ref(parent_stylesheet), @@ -47,7 +47,7 @@ impl CSSRule { } } - pub fn as_specific(&self) -> &dyn SpecificCSSRule { + pub(crate) fn as_specific(&self) -> &dyn SpecificCSSRule { if let Some(rule) = self.downcast::() { rule as &dyn SpecificCSSRule } else if let Some(rule) = self.downcast::() { @@ -75,7 +75,7 @@ impl CSSRule { // Given a StyleCssRule, create a new instance of a derived class of // CSSRule based on which rule it is - pub fn new_specific( + pub(crate) fn new_specific( window: &Window, parent_stylesheet: &CSSStyleSheet, rule: StyleCssRule, @@ -125,13 +125,13 @@ impl CSSRule { } /// Sets owner sheet/rule to null - pub fn detach(&self) { + pub(crate) fn detach(&self) { self.deparent(); // should set parent rule to None when we add parent rule support } /// Sets owner sheet to null (and does the same for all children) - pub fn deparent(&self) { + pub(crate) fn deparent(&self) { self.parent_stylesheet_removed.set(true); // https://github.com/w3c/csswg-drafts/issues/722 // Spec doesn't ask us to do this, but it makes sense @@ -139,11 +139,11 @@ impl CSSRule { self.as_specific().deparent_children(); } - pub fn parent_stylesheet(&self) -> &CSSStyleSheet { + pub(crate) fn parent_stylesheet(&self) -> &CSSStyleSheet { &self.parent_stylesheet } - pub fn shared_lock(&self) -> &SharedRwLock { + pub(crate) fn shared_lock(&self) -> &SharedRwLock { &self.parent_stylesheet.style_stylesheet().shared_lock } } @@ -181,7 +181,7 @@ impl CSSRuleMethods for CSSRule { } } -pub trait SpecificCSSRule { +pub(crate) trait SpecificCSSRule { fn ty(&self) -> CssRuleType; fn get_css(&self) -> DOMString; /// Remove parentStylesheet from all transitive children diff --git a/components/script/dom/cssrulelist.rs b/components/script/dom/cssrulelist.rs index 92cfead1c53..6420982973c 100644 --- a/components/script/dom/cssrulelist.rs +++ b/components/script/dom/cssrulelist.rs @@ -39,7 +39,7 @@ impl From for Error { } #[dom_struct] -pub struct CSSRuleList { +pub(crate) struct CSSRuleList { reflector_: Reflector, parent_stylesheet: Dom, #[ignore_malloc_size_of = "Arc"] @@ -47,14 +47,17 @@ pub struct CSSRuleList { dom_rules: DomRefCell>>, } -pub enum RulesSource { +pub(crate) enum RulesSource { Rules(Arc>), Keyframes(Arc>), } impl CSSRuleList { #[allow(crown::unrooted_must_root)] - pub fn new_inherited(parent_stylesheet: &CSSStyleSheet, rules: RulesSource) -> CSSRuleList { + pub(crate) fn new_inherited( + parent_stylesheet: &CSSStyleSheet, + rules: RulesSource, + ) -> CSSRuleList { let guard = parent_stylesheet.shared_lock().read(); let dom_rules = match rules { RulesSource::Rules(ref rules) => rules @@ -80,7 +83,7 @@ impl CSSRuleList { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, rules: RulesSource, @@ -94,7 +97,7 @@ impl CSSRuleList { /// Should only be called for CssRules-backed rules. Use append_lazy_rule /// for keyframes-backed rules. - pub fn insert_rule( + pub(crate) fn insert_rule( &self, rule: &str, idx: u32, @@ -139,7 +142,7 @@ impl CSSRuleList { } /// In case of a keyframe rule, index must be valid. - pub fn remove_rule(&self, index: u32) -> ErrorResult { + pub(crate) fn remove_rule(&self, index: u32) -> ErrorResult { let index = index as usize; let mut guard = self.parent_stylesheet.shared_lock().write(); @@ -167,7 +170,7 @@ impl CSSRuleList { } /// Remove parent stylesheets from all children - pub fn deparent_all(&self) { + pub(crate) fn deparent_all(&self) { for rule in self.dom_rules.borrow().iter() { if let Some(r) = rule.get() { DomRoot::upcast(r).deparent() @@ -175,7 +178,7 @@ impl CSSRuleList { } } - pub fn item(&self, idx: u32) -> Option> { + pub(crate) fn item(&self, idx: u32) -> Option> { self.dom_rules.borrow().get(idx as usize).map(|rule| { rule.or_init(|| { let parent_stylesheet = &self.parent_stylesheet; @@ -201,7 +204,7 @@ impl CSSRuleList { /// /// Should only be called for keyframes-backed rules, use insert_rule /// for CssRules-backed rules - pub fn append_lazy_dom_rule(&self) { + pub(crate) fn append_lazy_dom_rule(&self) { if let RulesSource::Rules(..) = self.rules { panic!("Can only call append_lazy_rule with keyframes-backed CSSRules"); } diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index 464938aa9da..c91ec72da68 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -34,7 +34,7 @@ use crate::script_runtime::CanGc; // http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface #[dom_struct] -pub struct CSSStyleDeclaration { +pub(crate) struct CSSStyleDeclaration { reflector_: Reflector, owner: CSSStyleOwner, readonly: bool, @@ -44,7 +44,7 @@ pub struct CSSStyleDeclaration { #[derive(JSTraceable, MallocSizeOf)] #[crown::unrooted_must_root_lint::must_root] -pub enum CSSStyleOwner { +pub(crate) enum CSSStyleOwner { Element(Dom), CSSRule( Dom, @@ -178,7 +178,7 @@ impl CSSStyleOwner { } #[derive(MallocSizeOf, PartialEq)] -pub enum CSSModificationAccess { +pub(crate) enum CSSModificationAccess { ReadWrite, Readonly, } @@ -216,7 +216,7 @@ fn remove_property(decls: &mut PropertyDeclarationBlock, id: &PropertyId) -> boo impl CSSStyleDeclaration { #[allow(crown::unrooted_must_root)] - pub fn new_inherited( + pub(crate) fn new_inherited( owner: CSSStyleOwner, pseudo: Option, modification_access: CSSModificationAccess, @@ -230,7 +230,7 @@ impl CSSStyleDeclaration { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( global: &Window, owner: CSSStyleOwner, pseudo: Option, @@ -356,7 +356,7 @@ impl CSSStyleDeclaration { } } -pub static ENABLED_LONGHAND_PROPERTIES: LazyLock> = LazyLock::new(|| { +pub(crate) static ENABLED_LONGHAND_PROPERTIES: LazyLock> = LazyLock::new(|| { // The 'all' shorthand contains all the enabled longhands with 2 exceptions: // 'direction' and 'unicode-bidi', so these must be added afterward. let mut enabled_longhands: Vec = ShorthandId::All.longhands().collect(); diff --git a/components/script/dom/cssstylerule.rs b/components/script/dom/cssstylerule.rs index 669c1c6779e..f0052fda1ef 100644 --- a/components/script/dom/cssstylerule.rs +++ b/components/script/dom/cssstylerule.rs @@ -25,7 +25,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CSSStyleRule { +pub(crate) struct CSSStyleRule { cssrule: CSSRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] @@ -46,7 +46,7 @@ impl CSSStyleRule { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, stylerule: Arc>, diff --git a/components/script/dom/cssstylesheet.rs b/components/script/dom/cssstylesheet.rs index 4b32453f73b..0212ea16e99 100644 --- a/components/script/dom/cssstylesheet.rs +++ b/components/script/dom/cssstylesheet.rs @@ -23,7 +23,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CSSStyleSheet { +pub(crate) struct CSSStyleSheet { stylesheet: StyleSheet, owner: MutNullableDom, rulelist: MutNullableDom, @@ -51,7 +51,7 @@ impl CSSStyleSheet { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, owner: &Element, type_: DOMString, @@ -75,15 +75,15 @@ impl CSSStyleSheet { }) } - pub fn disabled(&self) -> bool { + pub(crate) fn disabled(&self) -> bool { self.style_stylesheet.disabled() } - pub fn get_owner(&self) -> Option> { + pub(crate) fn get_owner(&self) -> Option> { self.owner.get() } - pub fn set_disabled(&self, disabled: bool) { + pub(crate) fn set_disabled(&self, disabled: bool) { if self.style_stylesheet.set_disabled(disabled) && self.get_owner().is_some() { self.get_owner() .unwrap() @@ -92,23 +92,23 @@ impl CSSStyleSheet { } } - pub fn set_owner(&self, value: Option<&Element>) { + pub(crate) fn set_owner(&self, value: Option<&Element>) { self.owner.set(value); } - pub fn shared_lock(&self) -> &SharedRwLock { + pub(crate) fn shared_lock(&self) -> &SharedRwLock { &self.style_stylesheet.shared_lock } - pub fn style_stylesheet(&self) -> &StyleStyleSheet { + pub(crate) fn style_stylesheet(&self) -> &StyleStyleSheet { &self.style_stylesheet } - pub fn set_origin_clean(&self, origin_clean: bool) { + pub(crate) fn set_origin_clean(&self, origin_clean: bool) { self.origin_clean.set(origin_clean); } - pub fn medialist(&self) -> DomRoot { + pub(crate) fn medialist(&self) -> DomRoot { MediaList::new( self.global().as_window(), self, diff --git a/components/script/dom/cssstylevalue.rs b/components/script/dom/cssstylevalue.rs index 1a303634ec6..7068a33642e 100644 --- a/components/script/dom/cssstylevalue.rs +++ b/components/script/dom/cssstylevalue.rs @@ -14,7 +14,7 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CSSStyleValue { +pub(crate) struct CSSStyleValue { reflector: Reflector, value: String, } @@ -27,7 +27,7 @@ impl CSSStyleValue { } } - pub fn new(global: &GlobalScope, value: String) -> DomRoot { + pub(crate) fn new(global: &GlobalScope, value: String) -> DomRoot { reflect_dom_object( Box::new(CSSStyleValue::new_inherited(value)), global, @@ -48,7 +48,7 @@ impl CSSStyleValue { /// TODO: This should really always be an absolute URL, but we currently /// return relative URLs for computed values, so we pass in a base. /// - pub fn get_url(&self, base_url: ServoUrl) -> Option { + pub(crate) fn get_url(&self, base_url: ServoUrl) -> Option { let mut input = ParserInput::new(&self.value); let mut parser = Parser::new(&mut input); parser diff --git a/components/script/dom/csssupportsrule.rs b/components/script/dom/csssupportsrule.rs index ea7d734ea1f..f387daba95e 100644 --- a/components/script/dom/csssupportsrule.rs +++ b/components/script/dom/csssupportsrule.rs @@ -18,7 +18,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct CSSSupportsRule { +pub(crate) struct CSSSupportsRule { cssconditionrule: CSSConditionRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] @@ -38,7 +38,7 @@ impl CSSSupportsRule { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, supportsrule: Arc, @@ -54,7 +54,7 @@ impl CSSSupportsRule { } /// - pub fn get_condition_text(&self) -> DOMString { + pub(crate) fn get_condition_text(&self) -> DOMString { self.supportsrule.condition.to_css_string().into() } } diff --git a/components/script/dom/customelementregistry.rs b/components/script/dom/customelementregistry.rs index 0ef3ac99598..9ca7b756e06 100644 --- a/components/script/dom/customelementregistry.rs +++ b/components/script/dom/customelementregistry.rs @@ -53,7 +53,7 @@ use crate::script_thread::ScriptThread; /// #[derive(Clone, Copy, Default, Eq, JSTraceable, MallocSizeOf, PartialEq)] -pub enum CustomElementState { +pub(crate) enum CustomElementState { Undefined, Failed, #[default] @@ -63,7 +63,7 @@ pub enum CustomElementState { /// #[dom_struct] -pub struct CustomElementRegistry { +pub(crate) struct CustomElementRegistry { reflector_: Reflector, window: Dom, @@ -88,7 +88,7 @@ impl CustomElementRegistry { } } - pub fn new(window: &Window) -> DomRoot { + pub(crate) fn new(window: &Window) -> DomRoot { reflect_dom_object( Box::new(CustomElementRegistry::new_inherited(window)), window, @@ -98,12 +98,12 @@ impl CustomElementRegistry { /// Cleans up any active promises /// - pub fn teardown(&self) { + pub(crate) fn teardown(&self) { self.when_defined.borrow_mut().0.clear() } /// - pub fn lookup_definition( + pub(crate) fn lookup_definition( &self, local_name: &LocalName, is: Option<&LocalName>, @@ -120,7 +120,7 @@ impl CustomElementRegistry { .cloned() } - pub fn lookup_definition_by_constructor( + pub(crate) fn lookup_definition_by_constructor( &self, constructor: HandleObject, ) -> Option> { @@ -622,7 +622,7 @@ impl CustomElementRegistryMethods for CustomElementRegistr } #[derive(Clone, JSTraceable, MallocSizeOf)] -pub struct LifecycleCallbacks { +pub(crate) struct LifecycleCallbacks { #[ignore_malloc_size_of = "Rc"] connected_callback: Option>, @@ -649,34 +649,34 @@ pub struct LifecycleCallbacks { } #[derive(Clone, JSTraceable, MallocSizeOf)] -pub enum ConstructionStackEntry { +pub(crate) enum ConstructionStackEntry { Element(DomRoot), AlreadyConstructedMarker, } /// #[derive(Clone, JSTraceable, MallocSizeOf)] -pub struct CustomElementDefinition { +pub(crate) struct CustomElementDefinition { #[no_trace] - pub name: LocalName, + pub(crate) name: LocalName, #[no_trace] - pub local_name: LocalName, + pub(crate) local_name: LocalName, #[ignore_malloc_size_of = "Rc"] - pub constructor: Rc, + pub(crate) constructor: Rc, - pub observed_attributes: Vec, + pub(crate) observed_attributes: Vec, - pub callbacks: LifecycleCallbacks, + pub(crate) callbacks: LifecycleCallbacks, - pub construction_stack: DomRefCell>, + pub(crate) construction_stack: DomRefCell>, - pub form_associated: bool, + pub(crate) form_associated: bool, - pub disable_internals: bool, + pub(crate) disable_internals: bool, - pub disable_shadow: bool, + pub(crate) disable_shadow: bool, } impl CustomElementDefinition { @@ -705,13 +705,13 @@ impl CustomElementDefinition { } /// - pub fn is_autonomous(&self) -> bool { + pub(crate) fn is_autonomous(&self) -> bool { self.name == self.local_name } /// Step 6.1 #[allow(unsafe_code)] - pub fn create_element( + pub(crate) fn create_element( &self, document: &Document, prefix: Option, @@ -781,7 +781,11 @@ impl CustomElementDefinition { /// #[allow(unsafe_code)] -pub fn upgrade_element(definition: Rc, element: &Element, can_gc: CanGc) { +pub(crate) fn upgrade_element( + definition: Rc, + element: &Element, + can_gc: CanGc, +) { // Step 1 let state = element.get_custom_element_state(); if state != CustomElementState::Undefined && state != CustomElementState::Uncustomized { @@ -954,7 +958,7 @@ fn run_upgrade_constructor( } /// -pub fn try_upgrade_element(element: &Element) { +pub(crate) fn try_upgrade_element(element: &Element) { // Step 1 let document = element.owner_document(); let namespace = element.namespace(); @@ -970,7 +974,7 @@ pub fn try_upgrade_element(element: &Element) { #[derive(JSTraceable, MallocSizeOf)] #[crown::unrooted_must_root_lint::must_root] -pub enum CustomElementReaction { +pub(crate) enum CustomElementReaction { Upgrade(#[ignore_malloc_size_of = "Rc"] Rc), Callback( #[ignore_malloc_size_of = "Rc"] Rc, @@ -981,7 +985,7 @@ pub enum CustomElementReaction { impl CustomElementReaction { /// #[allow(unsafe_code)] - pub fn invoke(&self, element: &Element, can_gc: CanGc) { + pub(crate) fn invoke(&self, element: &Element, can_gc: CanGc) { // Step 2.1 match *self { CustomElementReaction::Upgrade(ref definition) => { @@ -1005,7 +1009,7 @@ impl CustomElementReaction { } } -pub enum CallbackReaction { +pub(crate) enum CallbackReaction { Connected, Disconnected, Adopted(DomRoot, DomRoot), @@ -1025,14 +1029,14 @@ enum BackupElementQueueFlag { /// #[derive(JSTraceable, MallocSizeOf)] #[crown::unrooted_must_root_lint::must_root] -pub struct CustomElementReactionStack { +pub(crate) struct CustomElementReactionStack { stack: DomRefCell>, backup_queue: ElementQueue, processing_backup_element_queue: Cell, } impl CustomElementReactionStack { - pub fn new() -> CustomElementReactionStack { + pub(crate) fn new() -> CustomElementReactionStack { CustomElementReactionStack { stack: DomRefCell::new(Vec::new()), backup_queue: ElementQueue::new(), @@ -1040,11 +1044,11 @@ impl CustomElementReactionStack { } } - pub fn push_new_element_queue(&self) { + pub(crate) fn push_new_element_queue(&self) { self.stack.borrow_mut().push(ElementQueue::new()); } - pub fn pop_current_element_queue(&self, can_gc: CanGc) { + pub(crate) fn pop_current_element_queue(&self, can_gc: CanGc) { rooted_vec!(let mut stack); mem::swap(&mut *stack, &mut *self.stack.borrow_mut()); @@ -1059,7 +1063,7 @@ impl CustomElementReactionStack { /// /// Step 4 - pub fn invoke_backup_element_queue(&self, can_gc: CanGc) { + pub(crate) fn invoke_backup_element_queue(&self, can_gc: CanGc) { // Step 4.1 self.backup_queue.invoke_reactions(can_gc); @@ -1069,7 +1073,7 @@ impl CustomElementReactionStack { } /// - pub fn enqueue_element(&self, element: &Element) { + pub(crate) fn enqueue_element(&self, element: &Element) { if let Some(current_queue) = self.stack.borrow().last() { // Step 2 current_queue.append_element(element); @@ -1093,7 +1097,7 @@ impl CustomElementReactionStack { /// #[allow(unsafe_code)] - pub fn enqueue_callback_reaction( + pub(crate) fn enqueue_callback_reaction( &self, element: &Element, reaction: CallbackReaction, @@ -1215,7 +1219,7 @@ impl CustomElementReactionStack { } /// - pub fn enqueue_upgrade_reaction( + pub(crate) fn enqueue_upgrade_reaction( &self, element: &Element, definition: Rc, @@ -1264,7 +1268,7 @@ impl ElementQueue { } /// -pub fn is_valid_custom_element_name(name: &str) -> bool { +pub(crate) fn is_valid_custom_element_name(name: &str) -> bool { // Custom elment names must match: // PotentialCustomElementName ::= [a-z] (PCENChar)* '-' (PCENChar)* diff --git a/components/script/dom/customevent.rs b/components/script/dom/customevent.rs index 4b82f335643..c64ff183c87 100644 --- a/components/script/dom/customevent.rs +++ b/components/script/dom/customevent.rs @@ -22,7 +22,7 @@ use crate::script_runtime::{CanGc, JSContext}; // https://dom.spec.whatwg.org/#interface-customevent #[dom_struct] -pub struct CustomEvent { +pub(crate) struct CustomEvent { event: Event, #[ignore_malloc_size_of = "Defined in rust-mozjs"] detail: Heap, @@ -36,7 +36,7 @@ impl CustomEvent { } } - pub fn new_uninitialized(global: &GlobalScope, can_gc: CanGc) -> DomRoot { + pub(crate) fn new_uninitialized(global: &GlobalScope, can_gc: CanGc) -> DomRoot { Self::new_uninitialized_with_proto(global, None, can_gc) } diff --git a/components/script/dom/datatransfer.rs b/components/script/dom/datatransfer.rs index f28d538ebd1..001d036919b 100644 --- a/components/script/dom/datatransfer.rs +++ b/components/script/dom/datatransfer.rs @@ -36,7 +36,7 @@ const VALID_EFFECTS_ALLOWED: [&str; 9] = [ ]; #[dom_struct] -pub struct DataTransfer { +pub(crate) struct DataTransfer { reflector_: Reflector, drop_effect: DomRefCell, effect_allowed: DomRefCell, @@ -60,7 +60,7 @@ impl DataTransfer { } } - pub fn new_with_proto( + pub(crate) fn new_with_proto( window: &Window, proto: Option, can_gc: CanGc, diff --git a/components/script/dom/datatransferitem.rs b/components/script/dom/datatransferitem.rs index b1d5e1d4480..c498d1f145b 100644 --- a/components/script/dom/datatransferitem.rs +++ b/components/script/dom/datatransferitem.rs @@ -19,7 +19,7 @@ use crate::drag_data_store::Kind; use crate::script_runtime::CanGc; #[dom_struct] -pub struct DataTransferItem { +pub(crate) struct DataTransferItem { reflector_: Reflector, #[ignore_malloc_size_of = "TODO"] #[no_trace] @@ -34,7 +34,7 @@ impl DataTransferItem { } } - pub fn new(global: &GlobalScope, item: Kind) -> DomRoot { + pub(crate) fn new(global: &GlobalScope, item: Kind) -> DomRoot { reflect_dom_object( Box::new(DataTransferItem::new_inherited(item)), global, diff --git a/components/script/dom/datatransferitemlist.rs b/components/script/dom/datatransferitemlist.rs index 0a0c44c5e04..a52ecae3b65 100644 --- a/components/script/dom/datatransferitemlist.rs +++ b/components/script/dom/datatransferitemlist.rs @@ -21,7 +21,7 @@ use crate::drag_data_store::{Binary, DragDataStore, Kind, Mode, PlainString}; use crate::script_runtime::{CanGc, JSContext}; #[dom_struct] -pub struct DataTransferItemList { +pub(crate) struct DataTransferItemList { reflector_: Reflector, #[ignore_malloc_size_of = "Rc"] #[no_trace] @@ -39,7 +39,7 @@ impl DataTransferItemList { } } - pub fn new( + pub(crate) fn new( window: &Window, data_store: Rc>>, ) -> DomRoot { @@ -50,7 +50,7 @@ impl DataTransferItemList { ) } - pub fn frozen_types(&self, cx: JSContext, retval: MutableHandleValue) { + pub(crate) fn frozen_types(&self, cx: JSContext, retval: MutableHandleValue) { self.frozen_types.get_or_init( || { self.data_store @@ -63,7 +63,7 @@ impl DataTransferItemList { ); } - pub fn invalidate_frozen_types(&self) { + pub(crate) fn invalidate_frozen_types(&self) { self.frozen_types.clear(); } } diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 6981b806d8f..f170f8fb82c 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -61,7 +61,7 @@ use crate::task_source::{SendableTaskSource, TaskSourceName}; /// value for the duration of this object's lifetime. This ensures that the related Worker /// object only lives as long as necessary (ie. while events are being executed), while /// providing a reference that can be cloned freely. -pub struct AutoWorkerReset<'a> { +pub(crate) struct AutoWorkerReset<'a> { workerscope: &'a DedicatedWorkerGlobalScope, old_worker: Option, } @@ -87,19 +87,19 @@ impl Drop for AutoWorkerReset<'_> { } /// Messages sent from the owning global. -pub enum DedicatedWorkerControlMsg { +pub(crate) enum DedicatedWorkerControlMsg { /// Shutdown the worker. Exit, } -pub enum DedicatedWorkerScriptMsg { +pub(crate) enum DedicatedWorkerScriptMsg { /// Standard message from a worker. CommonWorker(TrustedWorkerAddress, WorkerScriptMsg), /// Wake-up call from the task queue. WakeUp, } -pub enum MixedMessage { +pub(crate) enum MixedMessage { Worker(DedicatedWorkerScriptMsg), Devtools(DevtoolScriptControlMsg), Control(DedicatedWorkerControlMsg), @@ -174,7 +174,7 @@ unsafe_no_jsmanaged_fields!(TaskQueue); // https://html.spec.whatwg.org/multipage/#dedicatedworkerglobalscope #[dom_struct] -pub struct DedicatedWorkerGlobalScope { +pub(crate) struct DedicatedWorkerGlobalScope { workerglobalscope: WorkerGlobalScope, #[ignore_malloc_size_of = "Defined in std"] task_queue: TaskQueue, @@ -516,7 +516,7 @@ impl DedicatedWorkerGlobalScope { old_worker } - pub fn image_cache(&self) -> Arc { + pub(crate) fn image_cache(&self) -> Arc { self.image_cache.clone() } @@ -594,7 +594,7 @@ impl DedicatedWorkerGlobalScope { // https://html.spec.whatwg.org/multipage/#runtime-script-errors-2 #[allow(unsafe_code)] - pub fn forward_error_to_worker_object(&self, error_info: ErrorInfo) { + pub(crate) fn forward_error_to_worker_object(&self, error_info: ErrorInfo) { let worker = self.worker.borrow().as_ref().unwrap().clone(); let pipeline_id = self.upcast::().pipeline_id(); let task = Box::new(task!(forward_error_to_worker_object: move || { diff --git a/components/script/dom/defaultteereadrequest.rs b/components/script/dom/defaultteereadrequest.rs index dfe5b22d045..93667b44f30 100644 --- a/components/script/dom/defaultteereadrequest.rs +++ b/components/script/dom/defaultteereadrequest.rs @@ -25,21 +25,21 @@ use crate::script_runtime::CanGc; #[derive(JSTraceable, MallocSizeOf)] #[allow(crown::unrooted_must_root)] -pub struct DefaultTeeReadRequestMicrotask { +pub(crate) struct DefaultTeeReadRequestMicrotask { #[ignore_malloc_size_of = "mozjs"] chunk: Box>, tee_read_request: Dom, } impl DefaultTeeReadRequestMicrotask { - pub fn microtask_chunk_steps(&self, can_gc: CanGc) { + pub(crate) fn microtask_chunk_steps(&self, can_gc: CanGc) { self.tee_read_request.chunk_steps(&self.chunk, can_gc) } } #[dom_struct] /// -pub struct DefaultTeeReadRequest { +pub(crate) struct DefaultTeeReadRequest { reflector_: Reflector, stream: Dom, branch_1: Dom, @@ -61,7 +61,7 @@ pub struct DefaultTeeReadRequest { impl DefaultTeeReadRequest { #[allow(clippy::too_many_arguments)] #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( stream: &ReadableStream, branch_1: &ReadableStream, branch_2: &ReadableStream, @@ -94,12 +94,12 @@ impl DefaultTeeReadRequest { } /// Call into cancel of the stream, /// - pub fn stream_cancel(&self, reason: SafeHandleValue, can_gc: CanGc) { + pub(crate) fn stream_cancel(&self, reason: SafeHandleValue, can_gc: CanGc) { self.stream.cancel(reason, can_gc); } /// Enqueue a microtask to perform the chunk steps /// - pub fn enqueue_chunk_steps(&self, chunk: RootedTraceableBox>) { + pub(crate) fn enqueue_chunk_steps(&self, chunk: RootedTraceableBox>) { // Queue a microtask to perform the following steps: let tee_read_request_chunk = DefaultTeeReadRequestMicrotask { chunk: Heap::boxed(*chunk.handle()), @@ -116,7 +116,7 @@ impl DefaultTeeReadRequest { /// #[allow(unsafe_code)] #[allow(clippy::borrowed_box)] - pub fn chunk_steps(&self, chunk: &Box>, can_gc: CanGc) { + pub(crate) fn chunk_steps(&self, chunk: &Box>, can_gc: CanGc) { // Set readAgain to false. self.read_again.set(false); // Let chunk1 and chunk2 be chunk. @@ -181,7 +181,7 @@ impl DefaultTeeReadRequest { } } /// - pub fn close_steps(&self) { + pub(crate) fn close_steps(&self) { // Set reading to false. self.reading.set(false); // If canceled_1 is false, perform ! ReadableStreamDefaultControllerClose(branch_1.[[controller]]). @@ -198,7 +198,7 @@ impl DefaultTeeReadRequest { } } /// - pub fn error_steps(&self) { + pub(crate) fn error_steps(&self) { // Set reading to false. self.reading.set(false); } @@ -232,7 +232,7 @@ impl DefaultTeeReadRequest { stream.get_default_controller().error(error); } - pub fn pull_algorithm(&self, can_gc: CanGc) { + pub(crate) fn pull_algorithm(&self, can_gc: CanGc) { self.tee_underlying_source.pull_algorithm(can_gc); } } diff --git a/components/script/dom/defaultteeunderlyingsource.rs b/components/script/dom/defaultteeunderlyingsource.rs index 902f0986eb8..565659d7bae 100644 --- a/components/script/dom/defaultteeunderlyingsource.rs +++ b/components/script/dom/defaultteeunderlyingsource.rs @@ -22,14 +22,14 @@ use crate::dom::readablestreamdefaultreader::ReadRequest; use crate::script_runtime::CanGc; #[derive(JSTraceable, MallocSizeOf)] -pub enum TeeCancelAlgorithm { +pub(crate) enum TeeCancelAlgorithm { Cancel1Algorithm, Cancel2Algorithm, } #[dom_struct] /// -pub struct DefaultTeeUnderlyingSource { +pub(crate) struct DefaultTeeUnderlyingSource { reflector_: Reflector, reader: Dom, stream: Dom, @@ -60,7 +60,7 @@ impl DefaultTeeUnderlyingSource { #[allow(clippy::too_many_arguments)] #[allow(clippy::redundant_allocation)] #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( reader: &ReadableStreamDefaultReader, stream: &ReadableStream, reading: Rc>, @@ -96,18 +96,18 @@ impl DefaultTeeUnderlyingSource { ) } - pub fn set_branch_1(&self, stream: &ReadableStream) { + pub(crate) fn set_branch_1(&self, stream: &ReadableStream) { self.branch_1.set(Some(stream)); } - pub fn set_branch_2(&self, stream: &ReadableStream) { + pub(crate) fn set_branch_2(&self, stream: &ReadableStream) { self.branch_2.set(Some(stream)); } /// /// Let pullAlgorithm be the following steps: #[allow(crown::unrooted_must_root)] - pub fn pull_algorithm(&self, can_gc: CanGc) -> Option, Error>> { + pub(crate) fn pull_algorithm(&self, can_gc: CanGc) -> Option, Error>> { // If reading is true, if self.reading.get() { // Set readAgain to true. @@ -163,7 +163,7 @@ impl DefaultTeeUnderlyingSource { /// and /// Let cancel2Algorithm be the following steps, taking a reason argument #[allow(unsafe_code)] - pub fn cancel_algorithm( + pub(crate) fn cancel_algorithm( &self, reason: SafeHandleValue, can_gc: CanGc, diff --git a/components/script/dom/dissimilaroriginlocation.rs b/components/script/dom/dissimilaroriginlocation.rs index 12b309d140c..dd108e5b2ad 100644 --- a/components/script/dom/dissimilaroriginlocation.rs +++ b/components/script/dom/dissimilaroriginlocation.rs @@ -19,7 +19,7 @@ use crate::script_runtime::CanGc; /// still need to function. #[dom_struct] -pub struct DissimilarOriginLocation { +pub(crate) struct DissimilarOriginLocation { /// The reflector. Once we have XOWs, this will have a cross-origin /// wrapper placed around it. reflector: Reflector, @@ -37,7 +37,7 @@ impl DissimilarOriginLocation { } } - pub fn new(window: &DissimilarOriginWindow) -> DomRoot { + pub(crate) fn new(window: &DissimilarOriginWindow) -> DomRoot { reflect_dom_object( Box::new(DissimilarOriginLocation::new_inherited(window)), window, diff --git a/components/script/dom/dissimilaroriginwindow.rs b/components/script/dom/dissimilaroriginwindow.rs index 6ec1956cc2b..bb1dd317978 100644 --- a/components/script/dom/dissimilaroriginwindow.rs +++ b/components/script/dom/dissimilaroriginwindow.rs @@ -33,7 +33,7 @@ use crate::script_runtime::JSContext; /// that throws security exceptions for most accessors. This is not a replacement /// for XOWs, but provides belt-and-braces security. #[dom_struct] -pub struct DissimilarOriginWindow { +pub(crate) struct DissimilarOriginWindow { /// The global for this window. globalscope: GlobalScope, @@ -46,7 +46,10 @@ pub struct DissimilarOriginWindow { impl DissimilarOriginWindow { #[allow(unsafe_code)] - pub fn new(global_to_clone_from: &GlobalScope, window_proxy: &WindowProxy) -> DomRoot { + pub(crate) fn new( + global_to_clone_from: &GlobalScope, + window_proxy: &WindowProxy, + ) -> DomRoot { let cx = GlobalScope::get_cx(); let win = Box::new(Self { globalscope: GlobalScope::new_inherited( @@ -74,7 +77,7 @@ impl DissimilarOriginWindow { unsafe { DissimilarOriginWindowBinding::Wrap(cx, win) } } - pub fn window_proxy(&self) -> DomRoot { + pub(crate) fn window_proxy(&self) -> DomRoot { DomRoot::from_ref(&*self.window_proxy) } } @@ -211,7 +214,7 @@ impl DissimilarOriginWindow { } /// - pub fn post_message( + pub(crate) fn post_message( &self, target_origin: &USVString, data: StructuredSerializedData, diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index a8a5bef65b5..fa0eaf7053e 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -203,13 +203,13 @@ const SPURIOUS_ANIMATION_FRAME_THRESHOLD: u8 = 5; /// The amount of time between fake `requestAnimationFrame()`s. const FAKE_REQUEST_ANIMATION_FRAME_DELAY: u64 = 16; -pub enum TouchEventResult { +pub(crate) enum TouchEventResult { Processed(bool), Forwarded, } #[derive(Clone, Copy, PartialEq)] -pub enum FireMouseEventType { +pub(crate) enum FireMouseEventType { Move, Over, Out, @@ -218,7 +218,7 @@ pub enum FireMouseEventType { } impl FireMouseEventType { - pub fn as_str(&self) -> &str { + pub(crate) fn as_str(&self) -> &str { match *self { FireMouseEventType::Move => "mousemove", FireMouseEventType::Over => "mouseover", @@ -230,7 +230,7 @@ impl FireMouseEventType { } #[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)] -pub enum IsHTMLDocument { +pub(crate) enum IsHTMLDocument { HTMLDocument, NonHTMLDocument, } @@ -247,7 +247,7 @@ enum FocusTransaction { /// Information about a declarative refresh #[derive(JSTraceable, MallocSizeOf)] -pub enum DeclarativeRefresh { +pub(crate) enum DeclarativeRefresh { PendingLoad { #[no_trace] url: ServoUrl, @@ -261,7 +261,7 @@ pub(crate) type WebGPUContextsMap = /// #[dom_struct] -pub struct Document { +pub(crate) struct Document { node: Node, document_or_shadow_root: DocumentOrShadowRoot, window: Dom, @@ -503,7 +503,7 @@ pub struct Document { #[allow(non_snake_case)] impl Document { - pub fn note_node_with_dirty_descendants(&self, node: &Node) { + pub(crate) fn note_node_with_dirty_descendants(&self, node: &Node) { debug_assert!(*node.owner_doc() == *self); if !node.is_connected() { return; @@ -606,28 +606,28 @@ impl Document { .set(Some(new_dirty_root.downcast::().unwrap())); } - pub fn take_dirty_root(&self) -> Option> { + pub(crate) fn take_dirty_root(&self) -> Option> { self.dirty_root.take() } #[inline] - pub fn loader(&self) -> Ref { + pub(crate) fn loader(&self) -> Ref { self.loader.borrow() } #[inline] - pub fn loader_mut(&self) -> RefMut { + pub(crate) fn loader_mut(&self) -> RefMut { self.loader.borrow_mut() } #[inline] - pub fn has_browsing_context(&self) -> bool { + pub(crate) fn has_browsing_context(&self) -> bool { self.has_browsing_context } /// #[inline] - pub fn browsing_context(&self) -> Option> { + pub(crate) fn browsing_context(&self) -> Option> { if self.has_browsing_context { self.window.undiscarded_window_proxy() } else { @@ -636,34 +636,34 @@ impl Document { } #[inline] - pub fn window(&self) -> &Window { + pub(crate) fn window(&self) -> &Window { &self.window } #[inline] - pub fn is_html_document(&self) -> bool { + pub(crate) fn is_html_document(&self) -> bool { self.is_html_document } - pub fn is_xhtml_document(&self) -> bool { + pub(crate) fn is_xhtml_document(&self) -> bool { self.content_type.type_() == mime::APPLICATION && self.content_type.subtype().as_str() == "xhtml" && self.content_type.suffix() == Some(mime::XML) } - pub fn set_https_state(&self, https_state: HttpsState) { + pub(crate) fn set_https_state(&self, https_state: HttpsState) { self.https_state.set(https_state); } - pub fn is_fully_active(&self) -> bool { + pub(crate) fn is_fully_active(&self) -> bool { self.activity.get() == DocumentActivity::FullyActive } - pub fn is_active(&self) -> bool { + pub(crate) fn is_active(&self) -> bool { self.activity.get() != DocumentActivity::Inactive } - pub fn set_activity(&self, activity: DocumentActivity) { + pub(crate) fn set_activity(&self, activity: DocumentActivity) { // This function should only be called on documents with a browsing context assert!(self.has_browsing_context); if activity == self.activity.get() { @@ -726,21 +726,21 @@ impl Document { })) } - pub fn origin(&self) -> &MutableOrigin { + pub(crate) fn origin(&self) -> &MutableOrigin { &self.origin } /// - pub fn url(&self) -> ServoUrl { + pub(crate) fn url(&self) -> ServoUrl { self.url.borrow().clone() } - pub fn set_url(&self, url: ServoUrl) { + pub(crate) fn set_url(&self, url: ServoUrl) { *self.url.borrow_mut() = url; } /// - pub fn fallback_base_url(&self) -> ServoUrl { + pub(crate) fn fallback_base_url(&self) -> ServoUrl { let document_url = self.url(); if let Some(browsing_context) = self.browsing_context() { // Step 1: If document is an iframe srcdoc document, then return the @@ -765,7 +765,7 @@ impl Document { } /// - pub fn base_url(&self) -> ServoUrl { + pub(crate) fn base_url(&self) -> ServoUrl { match self.base_element() { // Step 1. None => self.fallback_base_url(), @@ -778,7 +778,7 @@ impl Document { self.needs_paint.set(value) } - pub fn needs_reflow(&self) -> Option { + pub(crate) fn needs_reflow(&self) -> Option { // FIXME: This should check the dirty bit on the document, // not the document element. Needs some layout changes to make // that workable. @@ -803,13 +803,13 @@ impl Document { } /// Returns the first `base` element in the DOM that has an `href` attribute. - pub fn base_element(&self) -> Option> { + pub(crate) fn base_element(&self) -> Option> { self.base_element.get() } /// Refresh the cached first base element in the DOM. /// - pub fn refresh_base_element(&self) { + pub(crate) fn refresh_base_element(&self) { let base = self .upcast::() .traverse_preorder(ShadowIncluding::No) @@ -822,27 +822,27 @@ impl Document { self.base_element.set(base.as_deref()); } - pub fn dom_count(&self) -> u32 { + pub(crate) fn dom_count(&self) -> u32 { self.dom_count.get() } /// This is called by `bind_to_tree` when a node is added to the DOM. /// The internal count is used by layout to determine whether to be sequential or parallel. /// (it's sequential for small DOMs) - pub fn increment_dom_count(&self) { + pub(crate) fn increment_dom_count(&self) { self.dom_count.set(self.dom_count.get() + 1); } /// This is called by `unbind_from_tree` when a node is removed from the DOM. - pub fn decrement_dom_count(&self) { + pub(crate) fn decrement_dom_count(&self) { self.dom_count.set(self.dom_count.get() - 1); } - pub fn quirks_mode(&self) -> QuirksMode { + pub(crate) fn quirks_mode(&self) -> QuirksMode { self.quirks_mode.get() } - pub fn set_quirks_mode(&self, new_mode: QuirksMode) { + pub(crate) fn set_quirks_mode(&self, new_mode: QuirksMode) { let old_mode = self.quirks_mode.replace(new_mode); if old_mode != new_mode { @@ -850,15 +850,15 @@ impl Document { } } - pub fn encoding(&self) -> &'static Encoding { + pub(crate) fn encoding(&self) -> &'static Encoding { self.encoding.get() } - pub fn set_encoding(&self, encoding: &'static Encoding) { + pub(crate) fn set_encoding(&self, encoding: &'static Encoding) { self.encoding.set(encoding); } - pub fn content_and_heritage_changed(&self, node: &Node) { + pub(crate) fn content_and_heritage_changed(&self, node: &Node) { if node.is_connected() { node.note_dirty_descendants(); } @@ -869,14 +869,14 @@ impl Document { } /// Remove any existing association between the provided id and any elements in this document. - pub fn unregister_element_id(&self, to_unregister: &Element, id: Atom) { + pub(crate) fn unregister_element_id(&self, to_unregister: &Element, id: Atom) { self.document_or_shadow_root .unregister_named_element(&self.id_map, to_unregister, &id); self.reset_form_owner_for_listeners(&id); } /// Associate an element present in this document with the provided id. - pub fn register_element_id(&self, element: &Element, id: Atom) { + pub(crate) fn register_element_id(&self, element: &Element, id: Atom) { let root = self.GetDocumentElement().expect( "The element is in the document, so there must be a document \ element.", @@ -891,13 +891,13 @@ impl Document { } /// Remove any existing association between the provided name and any elements in this document. - pub fn unregister_element_name(&self, to_unregister: &Element, name: Atom) { + pub(crate) fn unregister_element_name(&self, to_unregister: &Element, name: Atom) { self.document_or_shadow_root .unregister_named_element(&self.name_map, to_unregister, &name); } /// Associate an element present in this document with the provided name. - pub fn register_element_name(&self, element: &Element, name: Atom) { + pub(crate) fn register_element_name(&self, element: &Element, name: Atom) { let root = self.GetDocumentElement().expect( "The element is in the document, so there must be a document \ element.", @@ -910,14 +910,18 @@ impl Document { ); } - pub fn register_form_id_listener(&self, id: DOMString, listener: &T) { + pub(crate) fn register_form_id_listener( + &self, + id: DOMString, + listener: &T, + ) { let mut map = self.form_id_listener_map.borrow_mut(); let listener = listener.to_element(); let set = map.entry(Atom::from(id)).or_default(); set.insert(Dom::from_ref(listener)); } - pub fn unregister_form_id_listener( + pub(crate) fn unregister_form_id_listener( &self, id: DOMString, listener: &T, @@ -935,7 +939,7 @@ impl Document { /// Attempt to find a named element in this page's document. /// - pub fn find_fragment_node(&self, fragid: &str) -> Option> { + pub(crate) fn find_fragment_node(&self, fragid: &str) -> Option> { // Step 1 is not handled here; the fragid is already obtained by the calling function // Step 2: Simply use None to indicate the top of the document. // Step 3 & 4 @@ -952,7 +956,7 @@ impl Document { /// Scroll to the target element, and when we do not find a target /// and the fragment is empty or "top", scroll to the top. /// - pub fn check_and_scroll_fragment(&self, fragment: &str, can_gc: CanGc) { + pub(crate) fn check_and_scroll_fragment(&self, fragment: &str, can_gc: CanGc) { let target = self.find_fragment_node(fragment); // Step 1 @@ -1006,7 +1010,7 @@ impl Document { } // https://html.spec.whatwg.org/multipage/#current-document-readiness - pub fn set_ready_state(&self, state: DocumentReadyState, can_gc: CanGc) { + pub(crate) fn set_ready_state(&self, state: DocumentReadyState, can_gc: CanGc) { match state { DocumentReadyState::Loading => { if self.window().is_top_level() { @@ -1030,13 +1034,13 @@ impl Document { } /// Return whether scripting is enabled or not - pub fn is_scripting_enabled(&self) -> bool { + pub(crate) fn is_scripting_enabled(&self) -> bool { self.scripting_enabled } /// Return the element that currently has focus. // https://w3c.github.io/uievents/#events-focusevent-doc-focus - pub fn get_focused_element(&self) -> Option> { + pub(crate) fn get_focused_element(&self) -> Option> { self.focused.get() } @@ -1158,7 +1162,7 @@ impl Document { } /// Handles any updates when the document's title has changed. - pub fn title_changed(&self) { + pub(crate) fn title_changed(&self) { if self.browsing_context().is_some() { self.send_title_to_embedder(); let title = String::from(self.Title()); @@ -1204,7 +1208,7 @@ impl Document { } /// Sends this document's title to the constellation. - pub fn send_title_to_embedder(&self) { + pub(crate) fn send_title_to_embedder(&self) { let window = self.window(); if window.is_top_level() { let title = self.title().map(String::from); @@ -1217,7 +1221,7 @@ impl Document { window.send_to_embedder(msg); } - pub fn dirty_all_nodes(&self) { + pub(crate) fn dirty_all_nodes(&self) { let root = match self.GetDocumentElement() { Some(root) => root, None => return, @@ -1232,7 +1236,7 @@ impl Document { #[allow(unsafe_code)] #[allow(clippy::too_many_arguments)] - pub unsafe fn handle_mouse_button_event( + pub(crate) unsafe fn handle_mouse_button_event( &self, button: MouseButton, client_point: Point2D, @@ -1401,7 +1405,7 @@ impl Document { } #[allow(clippy::too_many_arguments)] - pub fn fire_mouse_event( + pub(crate) fn fire_mouse_event( &self, client_point: Point2D, target: &EventTarget, @@ -1440,7 +1444,7 @@ impl Document { } #[allow(unsafe_code)] - pub unsafe fn handle_mouse_move_event( + pub(crate) unsafe fn handle_mouse_move_event( &self, client_point: Point2D, prev_mouse_over_target: &MutNullableDom, @@ -1618,7 +1622,7 @@ impl Document { } #[allow(unsafe_code)] - pub unsafe fn handle_wheel_event( + pub(crate) unsafe fn handle_wheel_event( &self, delta: WheelDelta, client_point: Point2D, @@ -1666,7 +1670,7 @@ impl Document { } #[allow(unsafe_code)] - pub unsafe fn handle_touch_event( + pub(crate) unsafe fn handle_touch_event( &self, event_type: TouchEventType, touch_id: TouchId, @@ -1774,7 +1778,7 @@ impl Document { } /// The entry point for all key processing for web content - pub fn dispatch_key_event( + pub(crate) fn dispatch_key_event( &self, keyboard_event: ::keyboard_types::KeyboardEvent, can_gc: CanGc, @@ -1858,7 +1862,7 @@ impl Document { } } - pub fn ime_dismissed(&self, can_gc: CanGc) { + pub(crate) fn ime_dismissed(&self, can_gc: CanGc) { self.request_focus( self.GetBody().as_ref().map(|e| e.upcast()), FocusType::Element, @@ -1866,7 +1870,7 @@ impl Document { ) } - pub fn dispatch_composition_event( + pub(crate) fn dispatch_composition_event( &self, composition_event: ::keyboard_types::CompositionEvent, can_gc: CanGc, @@ -1900,7 +1904,7 @@ impl Document { } // https://dom.spec.whatwg.org/#converting-nodes-into-a-node - pub fn node_from_nodes_and_strings( + pub(crate) fn node_from_nodes_and_strings( &self, mut nodes: Vec, can_gc: CanGc, @@ -1931,7 +1935,7 @@ impl Document { } } - pub fn get_body_attribute(&self, local_name: &LocalName) -> DOMString { + pub(crate) fn get_body_attribute(&self, local_name: &LocalName) -> DOMString { match self .GetBody() .and_then(DomRoot::downcast::) @@ -1941,7 +1945,12 @@ impl Document { } } - pub fn set_body_attribute(&self, local_name: &LocalName, value: DOMString, can_gc: CanGc) { + pub(crate) fn set_body_attribute( + &self, + local_name: &LocalName, + value: DOMString, + can_gc: CanGc, + ) { if let Some(ref body) = self .GetBody() .and_then(DomRoot::downcast::) @@ -1952,26 +1961,26 @@ impl Document { } } - pub fn set_current_script(&self, script: Option<&HTMLScriptElement>) { + pub(crate) fn set_current_script(&self, script: Option<&HTMLScriptElement>) { self.current_script.set(script); } - pub fn get_script_blocking_stylesheets_count(&self) -> u32 { + pub(crate) fn get_script_blocking_stylesheets_count(&self) -> u32 { self.script_blocking_stylesheets_count.get() } - pub fn increment_script_blocking_stylesheet_count(&self) { + pub(crate) fn increment_script_blocking_stylesheet_count(&self) { let count_cell = &self.script_blocking_stylesheets_count; count_cell.set(count_cell.get() + 1); } - pub fn decrement_script_blocking_stylesheet_count(&self) { + pub(crate) fn decrement_script_blocking_stylesheet_count(&self) { let count_cell = &self.script_blocking_stylesheets_count; assert!(count_cell.get() > 0); count_cell.set(count_cell.get() - 1); } - pub fn invalidate_stylesheets(&self) { + pub(crate) fn invalidate_stylesheets(&self) { self.stylesheets.borrow_mut().force_dirty(OriginSet::all()); // Mark the document element dirty so a reflow will be performed. @@ -2105,7 +2114,7 @@ impl Document { } } - pub fn policy_container(&self) -> Ref { + pub(crate) fn policy_container(&self) -> Ref { self.policy_container.borrow() } @@ -2158,7 +2167,7 @@ impl Document { // https://html.spec.whatwg.org/multipage/#the-end // https://html.spec.whatwg.org/multipage/#delay-the-load-event - pub fn finish_load(&self, load: LoadType, can_gc: CanGc) { + pub(crate) fn finish_load(&self, load: LoadType, can_gc: CanGc) { // This does not delay the load event anymore. debug!("Document got finish_load: {:?}", load); self.loader.borrow_mut().finish_load(&load); @@ -2210,7 +2219,7 @@ impl Document { } // https://html.spec.whatwg.org/multipage/#prompt-to-unload-a-document - pub fn prompt_to_unload(&self, recursive_flag: bool, can_gc: CanGc) -> bool { + pub(crate) fn prompt_to_unload(&self, recursive_flag: bool, can_gc: CanGc) -> bool { // TODO: Step 1, increase the event loop's termination nesting level by 1. // Step 2 self.incr_ignore_opens_during_unload_counter(); @@ -2269,7 +2278,7 @@ impl Document { } // https://html.spec.whatwg.org/multipage/#unload-a-document - pub fn unload(&self, recursive_flag: bool, can_gc: CanGc) { + pub(crate) fn unload(&self, recursive_flag: bool, can_gc: CanGc) { // TODO: Step 1, increase the event loop's termination nesting level by 1. // Step 2 self.incr_ignore_opens_during_unload_counter(); @@ -2350,7 +2359,7 @@ impl Document { } // https://html.spec.whatwg.org/multipage/#the-end - pub fn maybe_queue_document_completion(&self) { + pub(crate) fn maybe_queue_document_completion(&self) { // https://html.spec.whatwg.org/multipage/#delaying-load-events-mode let is_in_delaying_load_events_mode = match self.window.undiscarded_window_proxy() { Some(window_proxy) => window_proxy.is_delaying_load_events_mode(), @@ -2497,12 +2506,12 @@ impl Document { } } - pub fn completely_loaded(&self) -> bool { + pub(crate) fn completely_loaded(&self) -> bool { self.completely_loaded.get() } // https://html.spec.whatwg.org/multipage/#pending-parsing-blocking-script - pub fn set_pending_parsing_blocking_script( + pub(crate) fn set_pending_parsing_blocking_script( &self, script: &HTMLScriptElement, load: Option, @@ -2513,12 +2522,12 @@ impl Document { } // https://html.spec.whatwg.org/multipage/#pending-parsing-blocking-script - pub fn has_pending_parsing_blocking_script(&self) -> bool { + pub(crate) fn has_pending_parsing_blocking_script(&self) -> bool { self.pending_parsing_blocking_script.borrow().is_some() } /// step 22.d. - pub fn pending_parsing_blocking_script_loaded( + pub(crate) fn pending_parsing_blocking_script_loaded( &self, element: &HTMLScriptElement, result: ScriptResult, @@ -2551,7 +2560,7 @@ impl Document { } // https://html.spec.whatwg.org/multipage/#set-of-scripts-that-will-execute-as-soon-as-possible - pub fn add_asap_script(&self, script: &HTMLScriptElement) { + pub(crate) fn add_asap_script(&self, script: &HTMLScriptElement) { self.asap_scripts_set .borrow_mut() .push(Dom::from_ref(script)); @@ -2559,7 +2568,7 @@ impl Document { /// step 5. /// step 22.d. - pub fn asap_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) { + pub(crate) fn asap_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) { { let mut scripts = self.asap_scripts_set.borrow_mut(); let idx = scripts @@ -2572,13 +2581,17 @@ impl Document { } // https://html.spec.whatwg.org/multipage/#list-of-scripts-that-will-execute-in-order-as-soon-as-possible - pub fn push_asap_in_order_script(&self, script: &HTMLScriptElement) { + pub(crate) fn push_asap_in_order_script(&self, script: &HTMLScriptElement) { self.asap_in_order_scripts_list.push(script); } /// step 5. /// step> 22.c. - pub fn asap_in_order_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) { + pub(crate) fn asap_in_order_script_loaded( + &self, + element: &HTMLScriptElement, + result: ScriptResult, + ) { self.asap_in_order_scripts_list.loaded(element, result); while let Some((element, result)) = self .asap_in_order_scripts_list @@ -2589,13 +2602,13 @@ impl Document { } // https://html.spec.whatwg.org/multipage/#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing - pub fn add_deferred_script(&self, script: &HTMLScriptElement) { + pub(crate) fn add_deferred_script(&self, script: &HTMLScriptElement) { self.deferred_scripts.push(script); } /// step 3. /// step 22.d. - pub fn deferred_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) { + pub(crate) fn deferred_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) { self.deferred_scripts.loaded(element, result); self.process_deferred_scripts(); } @@ -2624,7 +2637,7 @@ impl Document { } // https://html.spec.whatwg.org/multipage/#the-end step 4. - pub fn maybe_dispatch_dom_content_loaded(&self) { + pub(crate) fn maybe_dispatch_dom_content_loaded(&self) { if self.domcontentloaded_dispatched.get() { return; } @@ -2660,7 +2673,7 @@ impl Document { } // https://html.spec.whatwg.org/multipage/#abort-a-document - pub fn abort(&self, can_gc: CanGc) { + pub(crate) fn abort(&self, can_gc: CanGc) { // We need to inhibit the loader before anything else. self.loader.borrow_mut().inhibit_events(); @@ -2702,15 +2715,15 @@ impl Document { } } - pub fn notify_constellation_load(&self) { + pub(crate) fn notify_constellation_load(&self) { self.window().send_to_constellation(ScriptMsg::LoadComplete); } - pub fn set_current_parser(&self, script: Option<&ServoParser>) { + pub(crate) fn set_current_parser(&self, script: Option<&ServoParser>) { self.current_parser.set(script); } - pub fn get_current_parser(&self) -> Option> { + pub(crate) fn get_current_parser(&self) -> Option> { self.current_parser.get() } @@ -2728,57 +2741,57 @@ impl Document { self.iframes.borrow_mut() } - pub fn get_dom_interactive(&self) -> Option { + pub(crate) fn get_dom_interactive(&self) -> Option { self.dom_interactive.get() } - pub fn set_navigation_start(&self, navigation_start: CrossProcessInstant) { + pub(crate) fn set_navigation_start(&self, navigation_start: CrossProcessInstant) { self.interactive_time .borrow_mut() .set_navigation_start(navigation_start); } - pub fn get_interactive_metrics(&self) -> Ref { + pub(crate) fn get_interactive_metrics(&self) -> Ref { self.interactive_time.borrow() } - pub fn has_recorded_tti_metric(&self) -> bool { + pub(crate) fn has_recorded_tti_metric(&self) -> bool { self.get_interactive_metrics().get_tti().is_some() } - pub fn get_dom_content_loaded_event_start(&self) -> Option { + pub(crate) fn get_dom_content_loaded_event_start(&self) -> Option { self.dom_content_loaded_event_start.get() } - pub fn get_dom_content_loaded_event_end(&self) -> Option { + pub(crate) fn get_dom_content_loaded_event_end(&self) -> Option { self.dom_content_loaded_event_end.get() } - pub fn get_dom_complete(&self) -> Option { + pub(crate) fn get_dom_complete(&self) -> Option { self.dom_complete.get() } - pub fn get_top_level_dom_complete(&self) -> Option { + pub(crate) fn get_top_level_dom_complete(&self) -> Option { self.top_level_dom_complete.get() } - pub fn get_load_event_start(&self) -> Option { + pub(crate) fn get_load_event_start(&self) -> Option { self.load_event_start.get() } - pub fn get_load_event_end(&self) -> Option { + pub(crate) fn get_load_event_end(&self) -> Option { self.load_event_end.get() } - pub fn get_unload_event_start(&self) -> Option { + pub(crate) fn get_unload_event_start(&self) -> Option { self.unload_event_start.get() } - pub fn get_unload_event_end(&self) -> Option { + pub(crate) fn get_unload_event_end(&self) -> Option { self.unload_event_end.get() } - pub fn start_tti(&self) { + pub(crate) fn start_tti(&self) { if self.get_interactive_metrics().needs_tti() { self.tti_window.borrow_mut().start_window(); } @@ -2787,7 +2800,7 @@ impl Document { /// check tti for this document /// if it's been 10s since this doc encountered a task over 50ms, then we consider the /// main thread available and try to set tti - pub fn record_tti_if_necessary(&self) { + pub(crate) fn record_tti_if_necessary(&self) { if self.has_recorded_tti_metric() { return; } @@ -2828,12 +2841,12 @@ impl Document { } /// - pub fn is_cookie_averse(&self) -> bool { + pub(crate) fn is_cookie_averse(&self) -> bool { !self.has_browsing_context || !url_has_network_scheme(&self.url()) } /// - pub fn lookup_custom_element_definition( + pub(crate) fn lookup_custom_element_definition( &self, namespace: &Namespace, local_name: &LocalName, @@ -2859,29 +2872,29 @@ impl Document { registry.lookup_definition(local_name, is) } - pub fn increment_throw_on_dynamic_markup_insertion_counter(&self) { + pub(crate) fn increment_throw_on_dynamic_markup_insertion_counter(&self) { let counter = self.throw_on_dynamic_markup_insertion_counter.get(); self.throw_on_dynamic_markup_insertion_counter .set(counter + 1); } - pub fn decrement_throw_on_dynamic_markup_insertion_counter(&self) { + pub(crate) fn decrement_throw_on_dynamic_markup_insertion_counter(&self) { let counter = self.throw_on_dynamic_markup_insertion_counter.get(); self.throw_on_dynamic_markup_insertion_counter .set(counter - 1); } - pub fn react_to_environment_changes(&self) { + pub(crate) fn react_to_environment_changes(&self) { for image in self.responsive_images.borrow().iter() { image.react_to_environment_changes(); } } - pub fn register_responsive_image(&self, img: &HTMLImageElement) { + pub(crate) fn register_responsive_image(&self, img: &HTMLImageElement) { self.responsive_images.borrow_mut().push(Dom::from_ref(img)); } - pub fn unregister_responsive_image(&self, img: &HTMLImageElement) { + pub(crate) fn unregister_responsive_image(&self, img: &HTMLImageElement) { let index = self .responsive_images .borrow() @@ -2892,7 +2905,7 @@ impl Document { } } - pub fn register_media_controls(&self, controls: &ShadowRoot) -> String { + pub(crate) fn register_media_controls(&self, controls: &ShadowRoot) -> String { let id = Uuid::new_v4().to_string(); self.media_controls .borrow_mut() @@ -2900,7 +2913,7 @@ impl Document { id } - pub fn unregister_media_controls(&self, id: &str) { + pub(crate) fn unregister_media_controls(&self, id: &str) { if let Some(ref media_controls) = self.media_controls.borrow_mut().remove(id) { let media_controls = DomRoot::from_ref(&**media_controls); media_controls.Host().detach_shadow(); @@ -2909,14 +2922,14 @@ impl Document { } } - pub fn add_dirty_webgl_canvas(&self, context: &WebGLRenderingContext) { + pub(crate) fn add_dirty_webgl_canvas(&self, context: &WebGLRenderingContext) { self.dirty_webgl_contexts .borrow_mut() .entry(context.context_id()) .or_insert_with(|| Dom::from_ref(context)); } - pub fn flush_dirty_webgl_canvases(&self) { + pub(crate) fn flush_dirty_webgl_canvases(&self) { let dirty_context_ids: Vec<_> = self .dirty_webgl_contexts .borrow_mut() @@ -2941,13 +2954,13 @@ impl Document { } #[cfg(feature = "webgpu")] - pub fn webgpu_contexts(&self) -> WebGPUContextsMap { + pub(crate) fn webgpu_contexts(&self) -> WebGPUContextsMap { self.webgpu_contexts.clone() } #[allow(crown::unrooted_must_root)] #[cfg(feature = "webgpu")] - pub fn update_rendering_of_webgpu_canvases(&self) { + pub(crate) fn update_rendering_of_webgpu_canvases(&self) { self.webgpu_contexts .borrow_mut() .iter() @@ -2956,11 +2969,11 @@ impl Document { .for_each(|context| context.update_rendering_of_webgpu_canvas()); } - pub fn id_map(&self) -> Ref>>> { + pub(crate) fn id_map(&self) -> Ref>>> { self.id_map.borrow() } - pub fn name_map(&self) -> Ref>>> { + pub(crate) fn name_map(&self) -> Ref>>> { self.name_map.borrow() } @@ -3033,7 +3046,7 @@ impl Document { } /// - pub fn encoding_parse_a_url(&self, url: &str) -> Result { + pub(crate) fn encoding_parse_a_url(&self, url: &str) -> Result { // NOTE: This algorithm is defined for both Document and environment settings objects. // This implementation is only for documents. @@ -3062,13 +3075,13 @@ fn is_character_value_key(key: &Key) -> bool { } #[derive(MallocSizeOf, PartialEq)] -pub enum DocumentSource { +pub(crate) enum DocumentSource { FromParser, NotFromParser, } #[allow(unsafe_code)] -pub trait LayoutDocumentHelpers<'dom> { +pub(crate) trait LayoutDocumentHelpers<'dom> { fn is_html_document_for_layout(&self) -> bool; fn quirks_mode(self) -> QuirksMode; fn style_shared_lock(self) -> &'dom StyleSharedRwLock; @@ -3178,14 +3191,14 @@ fn url_has_network_scheme(url: &ServoUrl) -> bool { } #[derive(Clone, Copy, Eq, JSTraceable, MallocSizeOf, PartialEq)] -pub enum HasBrowsingContext { +pub(crate) enum HasBrowsingContext { No, Yes, } impl Document { #[allow(clippy::too_many_arguments)] - pub fn new_inherited( + pub(crate) fn new_inherited( window: &Window, has_browsing_context: HasBrowsingContext, url: Option, @@ -3353,7 +3366,7 @@ impl Document { } /// Note a pending compositor event, to be processed at the next `update_the_rendering` task. - pub fn note_pending_compositor_event(&self, event: CompositorEvent) { + pub(crate) fn note_pending_compositor_event(&self, event: CompositorEvent) { let mut pending_compositor_events = self.pending_compositor_events.borrow_mut(); if matches!(event, CompositorEvent::MouseMoveEvent { .. }) { // First try to replace any existing mouse move event. @@ -3373,22 +3386,22 @@ impl Document { } /// Get pending compositor events, for processing within an `update_the_rendering` task. - pub fn take_pending_compositor_events(&self) -> Vec { + pub(crate) fn take_pending_compositor_events(&self) -> Vec { // Reset the mouse event index. *self.mouse_move_event_index.borrow_mut() = None; mem::take(&mut *self.pending_compositor_events.borrow_mut()) } - pub fn set_csp_list(&self, csp_list: Option) { + pub(crate) fn set_csp_list(&self, csp_list: Option) { self.policy_container.borrow_mut().set_csp_list(csp_list); } - pub fn get_csp_list(&self) -> Option { + pub(crate) fn get_csp_list(&self) -> Option { self.policy_container.borrow().csp_list.clone() } /// - pub fn should_elements_inline_type_behavior_be_blocked( + pub(crate) fn should_elements_inline_type_behavior_be_blocked( &self, el: &Element, type_: csp::InlineCheckType, @@ -3414,7 +3427,7 @@ impl Document { /// web content. Any attempts to invoke content JS or query layout during /// that time will trigger a panic. `add_delayed_task` will cause the /// provided task to be executed as soon as the last blocker is removed. - pub fn add_script_and_layout_blocker(&self) { + pub(crate) fn add_script_and_layout_blocker(&self) { self.script_and_layout_blockers .set(self.script_and_layout_blockers.get() + 1); } @@ -3422,7 +3435,7 @@ impl Document { /// Terminate the period in which JS or layout is disallowed from running. /// If no further blockers remain, any delayed tasks in the queue will /// be executed in queue order until the queue is empty. - pub fn remove_script_and_layout_blocker(&self) { + pub(crate) fn remove_script_and_layout_blocker(&self) { assert!(self.script_and_layout_blockers.get() > 0); self.script_and_layout_blockers .set(self.script_and_layout_blockers.get() - 1); @@ -3434,13 +3447,13 @@ impl Document { } /// Enqueue a task to run as soon as any JS and layout blockers are removed. - pub fn add_delayed_task(&self, task: T) { + pub(crate) fn add_delayed_task(&self, task: T) { self.delayed_tasks.borrow_mut().push(Box::new(task)); } /// Assert that the DOM is in a state that will allow running content JS or /// performing a layout operation. - pub fn ensure_safe_to_run_script_or_layout(&self) { + pub(crate) fn ensure_safe_to_run_script_or_layout(&self) { assert_eq!( self.script_and_layout_blockers.get(), 0, @@ -3449,7 +3462,7 @@ impl Document { } #[allow(clippy::too_many_arguments)] - pub fn new( + pub(crate) fn new( window: &Window, has_browsing_context: HasBrowsingContext, url: Option, @@ -3533,22 +3546,26 @@ impl Document { document } - pub fn get_redirect_count(&self) -> u16 { + pub(crate) fn get_redirect_count(&self) -> u16 { self.redirect_count.get() } - pub fn set_redirect_count(&self, count: u16) { + pub(crate) fn set_redirect_count(&self, count: u16) { self.redirect_count.set(count) } - pub fn elements_by_name_count(&self, name: &DOMString) -> u32 { + pub(crate) fn elements_by_name_count(&self, name: &DOMString) -> u32 { if name.is_empty() { return 0; } self.count_node_list(|n| Document::is_element_in_get_by_name(n, name)) } - pub fn nth_element_by_name(&self, index: u32, name: &DOMString) -> Option> { + pub(crate) fn nth_element_by_name( + &self, + index: u32, + name: &DOMString, + ) -> Option> { if name.is_empty() { return None; } @@ -3598,12 +3615,12 @@ impl Document { } /// Return a reference to the per-document shared lock used in stylesheets. - pub fn style_shared_lock(&self) -> &StyleSharedRwLock { + pub(crate) fn style_shared_lock(&self) -> &StyleSharedRwLock { &self.style_shared_lock } /// Flushes the stylesheet list, and returns whether any stylesheet changed. - pub fn flush_stylesheets_for_reflow(&self) -> bool { + pub(crate) fn flush_stylesheets_for_reflow(&self) -> bool { // NOTE(emilio): The invalidation machinery is used on the replicated // list in layout. // @@ -3616,12 +3633,15 @@ impl Document { have_changed } - pub fn salvageable(&self) -> bool { + pub(crate) fn salvageable(&self) -> bool { self.salvageable.get() } /// - pub fn appropriate_template_contents_owner_document(&self, can_gc: CanGc) -> DomRoot { + pub(crate) fn appropriate_template_contents_owner_document( + &self, + can_gc: CanGc, + ) -> DomRoot { self.appropriate_template_contents_owner_document .or_init(|| { let doctype = if self.is_html_document { @@ -3654,14 +3674,14 @@ impl Document { }) } - pub fn get_element_by_id(&self, id: &Atom) -> Option> { + pub(crate) fn get_element_by_id(&self, id: &Atom) -> Option> { self.id_map .borrow() .get(id) .map(|elements| DomRoot::from_ref(&*elements[0])) } - pub fn ensure_pending_restyle(&self, el: &Element) -> RefMut { + pub(crate) fn ensure_pending_restyle(&self, el: &Element) -> RefMut { let map = self.pending_restyles.borrow_mut(); RefMut::map(map, |m| { &mut m @@ -3671,7 +3691,7 @@ impl Document { }) } - pub fn element_state_will_change(&self, el: &Element) { + pub(crate) fn element_state_will_change(&self, el: &Element) { let mut entry = self.ensure_pending_restyle(el); if entry.snapshot.is_none() { entry.snapshot = Some(Snapshot::new()); @@ -3682,7 +3702,7 @@ impl Document { } } - pub fn element_attr_will_change(&self, el: &Element, attr: &Attr) { + pub(crate) fn element_attr_will_change(&self, el: &Element, attr: &Attr) { // FIXME(emilio): Kind of a shame we have to duplicate this. // // I'm getting rid of the whole hashtable soon anyway, since all it does @@ -3728,17 +3748,17 @@ impl Document { } } - pub fn set_referrer_policy(&self, policy: ReferrerPolicy) { + pub(crate) fn set_referrer_policy(&self, policy: ReferrerPolicy) { self.policy_container .borrow_mut() .set_referrer_policy(policy); } - pub fn get_referrer_policy(&self) -> ReferrerPolicy { + pub(crate) fn get_referrer_policy(&self) -> ReferrerPolicy { self.policy_container.borrow().get_referrer_policy() } - pub fn set_target_element(&self, node: Option<&Element>) { + pub(crate) fn set_target_element(&self, node: Option<&Element>) { if let Some(ref element) = self.target_element.get() { element.set_target_state(false); } @@ -3750,17 +3770,17 @@ impl Document { } } - pub fn incr_ignore_destructive_writes_counter(&self) { + pub(crate) fn incr_ignore_destructive_writes_counter(&self) { self.ignore_destructive_writes_counter .set(self.ignore_destructive_writes_counter.get() + 1); } - pub fn decr_ignore_destructive_writes_counter(&self) { + pub(crate) fn decr_ignore_destructive_writes_counter(&self) { self.ignore_destructive_writes_counter .set(self.ignore_destructive_writes_counter.get() - 1); } - pub fn is_prompting_or_unloading(&self) -> bool { + pub(crate) fn is_prompting_or_unloading(&self) -> bool { self.ignore_opens_during_unload_counter.get() > 0 } @@ -3781,7 +3801,7 @@ impl Document { } // https://fullscreen.spec.whatwg.org/#dom-element-requestfullscreen - pub fn enter_fullscreen(&self, pending: &Element, can_gc: CanGc) -> Rc { + pub(crate) fn enter_fullscreen(&self, pending: &Element, can_gc: CanGc) -> Rc { // Step 1 let in_realm_proof = AlreadyInRealm::assert(); let promise = Promise::new_in_current_realm(InRealm::Already(&in_realm_proof), can_gc); @@ -3848,7 +3868,7 @@ impl Document { } // https://fullscreen.spec.whatwg.org/#exit-fullscreen - pub fn exit_fullscreen(&self, can_gc: CanGc) -> Rc { + pub(crate) fn exit_fullscreen(&self, can_gc: CanGc) -> Rc { let global = self.global(); // Step 1 let in_realm_proof = AlreadyInRealm::assert(); @@ -3887,11 +3907,11 @@ impl Document { promise } - pub fn set_fullscreen_element(&self, element: Option<&Element>) { + pub(crate) fn set_fullscreen_element(&self, element: Option<&Element>) { self.fullscreen_element.set(element); } - pub fn get_allow_fullscreen(&self) -> bool { + pub(crate) fn get_allow_fullscreen(&self) -> bool { // https://html.spec.whatwg.org/multipage/#allowed-to-use match self.browsing_context() { // Step 1 @@ -3923,38 +3943,38 @@ impl Document { } } - pub fn register_shadow_root(&self, shadow_root: &ShadowRoot) { + pub(crate) fn register_shadow_root(&self, shadow_root: &ShadowRoot) { self.shadow_roots .borrow_mut() .insert(Dom::from_ref(shadow_root)); self.invalidate_shadow_roots_stylesheets(); } - pub fn unregister_shadow_root(&self, shadow_root: &ShadowRoot) { + pub(crate) fn unregister_shadow_root(&self, shadow_root: &ShadowRoot) { let mut shadow_roots = self.shadow_roots.borrow_mut(); shadow_roots.remove(&Dom::from_ref(shadow_root)); } - pub fn invalidate_shadow_roots_stylesheets(&self) { + pub(crate) fn invalidate_shadow_roots_stylesheets(&self) { self.shadow_roots_styles_changed.set(true); } - pub fn shadow_roots_styles_changed(&self) -> bool { + pub(crate) fn shadow_roots_styles_changed(&self) -> bool { self.shadow_roots_styles_changed.get() } - pub fn flush_shadow_roots_stylesheets(&self) { + pub(crate) fn flush_shadow_roots_stylesheets(&self) { if !self.shadow_roots_styles_changed.get() { return; } self.shadow_roots_styles_changed.set(false); } - pub fn stylesheet_count(&self) -> usize { + pub(crate) fn stylesheet_count(&self) -> usize { self.stylesheets.borrow().len() } - pub fn stylesheet_at(&self, index: usize) -> Option> { + pub(crate) fn stylesheet_at(&self, index: usize) -> Option> { let stylesheets = self.stylesheets.borrow(); stylesheets @@ -3965,7 +3985,7 @@ impl Document { /// Add a stylesheet owned by `owner` to the list of document sheets, in the /// correct tree position. #[allow(crown::unrooted_must_root)] // Owner needs to be rooted already necessarily. - pub fn add_stylesheet(&self, owner: &Element, sheet: Arc) { + pub(crate) fn add_stylesheet(&self, owner: &Element, sheet: Arc) { let stylesheets = &mut *self.stylesheets.borrow_mut(); let insertion_point = stylesheets .iter() @@ -3994,7 +4014,7 @@ impl Document { } /// Given a stylesheet, load all web fonts from it in Layout. - pub fn load_web_fonts_from_stylesheet(&self, stylesheet: Arc) { + pub(crate) fn load_web_fonts_from_stylesheet(&self, stylesheet: Arc) { self.window .layout() .load_web_fonts_from_stylesheet(stylesheet); @@ -4002,7 +4022,7 @@ impl Document { /// Remove a stylesheet owned by `owner` from the list of document sheets. #[allow(crown::unrooted_must_root)] // Owner needs to be rooted already necessarily. - pub fn remove_stylesheet(&self, owner: &Element, stylesheet: &Arc) { + pub(crate) fn remove_stylesheet(&self, owner: &Element, stylesheet: &Arc) { let cloned_stylesheet = stylesheet.clone(); self.window .layout_mut() @@ -4015,20 +4035,20 @@ impl Document { ) } - pub fn get_elements_with_id(&self, id: &Atom) -> Ref<[Dom]> { + pub(crate) fn get_elements_with_id(&self, id: &Atom) -> Ref<[Dom]> { Ref::map(self.id_map.borrow(), |map| { map.get(id).map(|vec| &**vec).unwrap_or_default() }) } - pub fn get_elements_with_name(&self, name: &Atom) -> Ref<[Dom]> { + pub(crate) fn get_elements_with_name(&self, name: &Atom) -> Ref<[Dom]> { Ref::map(self.name_map.borrow(), |map| { map.get(name).map(|vec| &**vec).unwrap_or_default() }) } #[allow(crown::unrooted_must_root)] - pub fn drain_pending_restyles(&self) -> Vec<(TrustedNodeAddress, PendingRestyle)> { + pub(crate) fn drain_pending_restyles(&self) -> Vec<(TrustedNodeAddress, PendingRestyle)> { self.pending_restyles .borrow_mut() .drain() @@ -4168,7 +4188,7 @@ impl Document { } /// - pub fn is_initial_about_blank(&self) -> bool { + pub(crate) fn is_initial_about_blank(&self) -> bool { self.is_initial_about_blank.get() } } @@ -5584,7 +5604,7 @@ fn update_with_current_instant(marker: &Cell>) { } /// -pub fn determine_policy_for_token(token: &str) -> ReferrerPolicy { +pub(crate) fn determine_policy_for_token(token: &str) -> ReferrerPolicy { match_ignore_ascii_case! { token, "never" | "no-referrer" => ReferrerPolicy::NoReferrer, "no-referrer-when-downgrade" => ReferrerPolicy::NoReferrerWhenDowngrade, @@ -5600,13 +5620,13 @@ pub fn determine_policy_for_token(token: &str) -> ReferrerPolicy { /// Specifies the type of focus event that is sent to a pipeline #[derive(Clone, Copy, PartialEq)] -pub enum FocusType { +pub(crate) enum FocusType { Element, // The first focus message - focus the element itself Parent, // Focusing a parent element (an iframe) } /// Focus events -pub enum FocusEventType { +pub(crate) enum FocusEventType { Focus, // Element gained focus. Doesn't bubble. Blur, // Element lost focus. Doesn't bubble. } @@ -5618,14 +5638,14 @@ pub enum FocusEventType { /// without mutating the DOM), then we fall back to simple timeouts to save energy over video /// refresh. #[derive(JSTraceable, MallocSizeOf)] -pub struct FakeRequestAnimationFrameCallback { +pub(crate) struct FakeRequestAnimationFrameCallback { /// The document. #[ignore_malloc_size_of = "non-owning"] document: Trusted, } impl FakeRequestAnimationFrameCallback { - pub fn invoke(self, can_gc: CanGc) { + pub(crate) fn invoke(self, can_gc: CanGc) { // TODO: Once there is a more generic mechanism to trigger `update_the_rendering` when // not driven by the compositor, it should be used here. self.document @@ -5636,7 +5656,7 @@ impl FakeRequestAnimationFrameCallback { } #[derive(JSTraceable, MallocSizeOf)] -pub enum AnimationFrameCallback { +pub(crate) enum AnimationFrameCallback { DevtoolsFramerateTick { actor_name: String, }, @@ -5737,7 +5757,7 @@ impl PendingScript { } #[derive(Clone, Copy, Debug, PartialEq)] -pub enum ReflowTriggerCondition { +pub(crate) enum ReflowTriggerCondition { StylesheetsChanged, DirtyDescendants, PendingRestyles, diff --git a/components/script/dom/documentfragment.rs b/components/script/dom/documentfragment.rs index 0dc7eb53227..b418d095b91 100644 --- a/components/script/dom/documentfragment.rs +++ b/components/script/dom/documentfragment.rs @@ -26,7 +26,7 @@ use crate::script_runtime::CanGc; // https://dom.spec.whatwg.org/#documentfragment #[dom_struct] -pub struct DocumentFragment { +pub(crate) struct DocumentFragment { node: Node, /// Caches for the getElement methods id_map: DomRefCell>>>, @@ -34,14 +34,14 @@ pub struct DocumentFragment { impl DocumentFragment { /// Creates a new DocumentFragment. - pub fn new_inherited(document: &Document) -> DocumentFragment { + pub(crate) fn new_inherited(document: &Document) -> DocumentFragment { DocumentFragment { node: Node::new_inherited(document), id_map: DomRefCell::new(HashMapTracedValues::new()), } } - pub fn new(document: &Document, can_gc: CanGc) -> DomRoot { + pub(crate) fn new(document: &Document, can_gc: CanGc) -> DomRoot { Self::new_with_proto(document, None, can_gc) } @@ -58,7 +58,7 @@ impl DocumentFragment { ) } - pub fn id_map(&self) -> &DomRefCell>>> { + pub(crate) fn id_map(&self) -> &DomRefCell>>> { &self.id_map } } diff --git a/components/script/dom/documentorshadowroot.rs b/components/script/dom/documentorshadowroot.rs index 37464a2f1d4..29713ee0d50 100644 --- a/components/script/dom/documentorshadowroot.rs +++ b/components/script/dom/documentorshadowroot.rs @@ -30,11 +30,11 @@ use crate::stylesheet_set::StylesheetSetRef; #[derive(Clone, JSTraceable, MallocSizeOf)] #[crown::unrooted_must_root_lint::must_root] -pub struct StyleSheetInDocument { +pub(crate) struct StyleSheetInDocument { #[ignore_malloc_size_of = "Arc"] #[no_trace] - pub sheet: Arc, - pub owner: Dom, + pub(crate) sheet: Arc, + pub(crate) owner: Dom, } // This is necessary because this type is contained within a Stylo type which needs @@ -84,18 +84,18 @@ impl ::style::stylesheets::StylesheetInDocument for StyleSheetInDocument { // https://w3c.github.io/webcomponents/spec/shadow/#extensions-to-the-documentorshadowroot-mixin #[crown::unrooted_must_root_lint::must_root] #[derive(JSTraceable, MallocSizeOf)] -pub struct DocumentOrShadowRoot { +pub(crate) struct DocumentOrShadowRoot { window: Dom, } impl DocumentOrShadowRoot { - pub fn new(window: &Window) -> Self { + pub(crate) fn new(window: &Window) -> Self { Self { window: Dom::from_ref(window), } } - pub fn nodes_from_point( + pub(crate) fn nodes_from_point( &self, client_point: &Point2D, query_type: NodesFromPointQueryType, @@ -115,7 +115,7 @@ impl DocumentOrShadowRoot { #[allow(unsafe_code)] // https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint - pub fn element_from_point( + pub(crate) fn element_from_point( &self, x: Finite, y: Finite, @@ -155,7 +155,7 @@ impl DocumentOrShadowRoot { #[allow(unsafe_code)] // https://drafts.csswg.org/cssom-view/#dom-document-elementsfrompoint - pub fn elements_from_point( + pub(crate) fn elements_from_point( &self, x: Finite, y: Finite, @@ -199,7 +199,7 @@ impl DocumentOrShadowRoot { } // https://html.spec.whatwg.org/multipage/#dom-document-activeelement - pub fn get_active_element( + pub(crate) fn get_active_element( &self, focused_element: Option>, body: Option>, @@ -219,7 +219,7 @@ impl DocumentOrShadowRoot { /// Remove a stylesheet owned by `owner` from the list of document sheets. #[allow(crown::unrooted_must_root)] // Owner needs to be rooted already necessarily. - pub fn remove_stylesheet( + pub(crate) fn remove_stylesheet( owner: &Element, s: &Arc, mut stylesheets: StylesheetSetRef, @@ -240,7 +240,7 @@ impl DocumentOrShadowRoot { /// Add a stylesheet owned by `owner` to the list of document sheets, in the /// correct tree position. #[allow(crown::unrooted_must_root)] // Owner needs to be rooted already necessarily. - pub fn add_stylesheet( + pub(crate) fn add_stylesheet( owner: &Element, mut stylesheets: StylesheetSetRef, sheet: Arc, @@ -267,7 +267,7 @@ impl DocumentOrShadowRoot { } /// Remove any existing association between the provided id/name and any elements in this document. - pub fn unregister_named_element( + pub(crate) fn unregister_named_element( &self, id_map: &DomRefCell>>>, to_unregister: &Element, @@ -295,7 +295,7 @@ impl DocumentOrShadowRoot { } /// Associate an element present in this document with the provided id/name. - pub fn register_named_element( + pub(crate) fn register_named_element( &self, id_map: &DomRefCell>>>, element: &Element, diff --git a/components/script/dom/documenttype.rs b/components/script/dom/documenttype.rs index a9b6d696f97..7499d7fbaae 100644 --- a/components/script/dom/documenttype.rs +++ b/components/script/dom/documenttype.rs @@ -17,7 +17,7 @@ use crate::script_runtime::CanGc; // https://dom.spec.whatwg.org/#documenttype /// The `DOCTYPE` tag. #[dom_struct] -pub struct DocumentType { +pub(crate) struct DocumentType { node: Node, name: DOMString, public_id: DOMString, @@ -39,7 +39,7 @@ impl DocumentType { } } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( name: DOMString, public_id: Option, system_id: Option, @@ -56,17 +56,17 @@ impl DocumentType { } #[inline] - pub fn name(&self) -> &DOMString { + pub(crate) fn name(&self) -> &DOMString { &self.name } #[inline] - pub fn public_id(&self) -> &DOMString { + pub(crate) fn public_id(&self) -> &DOMString { &self.public_id } #[inline] - pub fn system_id(&self) -> &DOMString { + pub(crate) fn system_id(&self) -> &DOMString { &self.system_id } } diff --git a/components/script/dom/domexception.rs b/components/script/dom/domexception.rs index 925b35e30db..454f3a75637 100644 --- a/components/script/dom/domexception.rs +++ b/components/script/dom/domexception.rs @@ -20,7 +20,7 @@ use crate::script_runtime::CanGc; #[repr(u16)] #[allow(clippy::enum_variant_names)] #[derive(Clone, Copy, Debug, Eq, JSTraceable, MallocSizeOf, Ord, PartialEq, PartialOrd)] -pub enum DOMErrorName { +pub(crate) enum DOMErrorName { IndexSizeError = DOMExceptionConstants::INDEX_SIZE_ERR, HierarchyRequestError = DOMExceptionConstants::HIERARCHY_REQUEST_ERR, WrongDocumentError = DOMExceptionConstants::WRONG_DOCUMENT_ERR, @@ -50,7 +50,7 @@ pub enum DOMErrorName { } impl DOMErrorName { - pub fn from(s: &DOMString) -> Option { + pub(crate) fn from(s: &DOMString) -> Option { match s.as_ref() { "IndexSizeError" => Some(DOMErrorName::IndexSizeError), "HierarchyRequestError" => Some(DOMErrorName::HierarchyRequestError), @@ -84,7 +84,7 @@ impl DOMErrorName { } #[dom_struct] -pub struct DOMException { +pub(crate) struct DOMException { reflector_: Reflector, message: DOMString, name: DOMString, @@ -137,7 +137,7 @@ impl DOMException { ) } - pub fn new_inherited(message: DOMString, name: DOMString) -> DOMException { + pub(crate) fn new_inherited(message: DOMString, name: DOMString) -> DOMException { DOMException { reflector_: Reflector::new(), message, @@ -145,7 +145,7 @@ impl DOMException { } } - pub fn new(global: &GlobalScope, code: DOMErrorName) -> DomRoot { + pub(crate) fn new(global: &GlobalScope, code: DOMErrorName) -> DomRoot { let (message, name) = DOMException::get_error_data_by_code(code); reflect_dom_object( @@ -156,7 +156,7 @@ impl DOMException { } // not an IDL stringifier, used internally - pub fn stringifier(&self) -> DOMString { + pub(crate) fn stringifier(&self) -> DOMString { DOMString::from(format!("{}: {}", self.name, self.message)) } } diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index 513b784a475..b9f0a2c29a9 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -32,7 +32,7 @@ use crate::script_runtime::CanGc; // https://dom.spec.whatwg.org/#domimplementation #[dom_struct] -pub struct DOMImplementation { +pub(crate) struct DOMImplementation { reflector_: Reflector, document: Dom, } @@ -45,7 +45,7 @@ impl DOMImplementation { } } - pub fn new(document: &Document) -> DomRoot { + pub(crate) fn new(document: &Document) -> DomRoot { let window = document.window(); reflect_dom_object( Box::new(DOMImplementation::new_inherited(document)), diff --git a/components/script/dom/dommatrix.rs b/components/script/dom/dommatrix.rs index b4a6f72b6d1..f84f3b500d4 100644 --- a/components/script/dom/dommatrix.rs +++ b/components/script/dom/dommatrix.rs @@ -23,13 +23,13 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct DOMMatrix { +pub(crate) struct DOMMatrix { parent: DOMMatrixReadOnly, } #[allow(non_snake_case)] impl DOMMatrix { - pub fn new( + pub(crate) fn new( global: &GlobalScope, is2D: bool, matrix: Transform3D, @@ -50,13 +50,13 @@ impl DOMMatrix { reflect_dom_object_with_proto(Box::new(dommatrix), global, proto, can_gc) } - pub fn new_inherited(is2D: bool, matrix: Transform3D) -> Self { + pub(crate) fn new_inherited(is2D: bool, matrix: Transform3D) -> Self { DOMMatrix { parent: DOMMatrixReadOnly::new_inherited(is2D, matrix), } } - pub fn from_readonly( + pub(crate) fn from_readonly( global: &GlobalScope, ro: &DOMMatrixReadOnly, can_gc: CanGc, diff --git a/components/script/dom/dommatrixreadonly.rs b/components/script/dom/dommatrixreadonly.rs index f5d5ea4b2d9..fb6e6fbf48b 100644 --- a/components/script/dom/dommatrixreadonly.rs +++ b/components/script/dom/dommatrixreadonly.rs @@ -37,7 +37,7 @@ use crate::script_runtime::{CanGc, JSContext}; #[dom_struct] #[allow(non_snake_case)] -pub struct DOMMatrixReadOnly { +pub(crate) struct DOMMatrixReadOnly { reflector_: Reflector, #[no_trace] matrix: DomRefCell>, @@ -46,7 +46,7 @@ pub struct DOMMatrixReadOnly { #[allow(non_snake_case)] impl DOMMatrixReadOnly { - pub fn new( + pub(crate) fn new( global: &GlobalScope, is2D: bool, matrix: Transform3D, @@ -67,7 +67,7 @@ impl DOMMatrixReadOnly { reflect_dom_object_with_proto(Box::new(dommatrix), global, proto, can_gc) } - pub fn new_inherited(is2D: bool, matrix: Transform3D) -> Self { + pub(crate) fn new_inherited(is2D: bool, matrix: Transform3D) -> Self { DOMMatrixReadOnly { reflector_: Reflector::new(), matrix: DomRefCell::new(matrix), @@ -75,26 +75,26 @@ impl DOMMatrixReadOnly { } } - pub fn matrix(&self) -> Ref> { + pub(crate) fn matrix(&self) -> Ref> { self.matrix.borrow() } - pub fn is2D(&self) -> bool { + pub(crate) fn is2D(&self) -> bool { self.is2D.get() } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m11 - pub fn set_m11(&self, value: f64) { + pub(crate) fn set_m11(&self, value: f64) { self.matrix.borrow_mut().m11 = value; } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m12 - pub fn set_m12(&self, value: f64) { + pub(crate) fn set_m12(&self, value: f64) { self.matrix.borrow_mut().m12 = value; } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m13 - pub fn set_m13(&self, value: f64) { + pub(crate) fn set_m13(&self, value: f64) { // For the DOMMatrix interface, setting the m13 attribute must set the // m13 element to the new value and, if the new value is not 0 or -0, set is 2D to false. @@ -105,7 +105,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m14 - pub fn set_m14(&self, value: f64) { + pub(crate) fn set_m14(&self, value: f64) { // For the DOMMatrix interface, setting the m14 attribute must set the // m14 element to the new value and, if the new value is not 0 or -0, set is 2D to false. self.matrix.borrow_mut().m14 = value; @@ -116,17 +116,17 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m21 - pub fn set_m21(&self, value: f64) { + pub(crate) fn set_m21(&self, value: f64) { self.matrix.borrow_mut().m21 = value; } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m22 - pub fn set_m22(&self, value: f64) { + pub(crate) fn set_m22(&self, value: f64) { self.matrix.borrow_mut().m22 = value; } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m23 - pub fn set_m23(&self, value: f64) { + pub(crate) fn set_m23(&self, value: f64) { // For the DOMMatrix interface, setting the m23 attribute must set the // m23 element to the new value and, if the new value is not 0 or -0, set is 2D to false. self.matrix.borrow_mut().m23 = value; @@ -137,7 +137,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m24 - pub fn set_m24(&self, value: f64) { + pub(crate) fn set_m24(&self, value: f64) { // For the DOMMatrix interface, setting the m24 attribute must set the // m24 element to the new value and, if the new value is not 0 or -0, set is 2D to false. self.matrix.borrow_mut().m24 = value; @@ -148,7 +148,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m31 - pub fn set_m31(&self, value: f64) { + pub(crate) fn set_m31(&self, value: f64) { // For the DOMMatrix interface, setting the m31 attribute must set the // m31 element to the new value and, if the new value is not 0 or -0, set is 2D to false. self.matrix.borrow_mut().m31 = value; @@ -159,7 +159,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m32 - pub fn set_m32(&self, value: f64) { + pub(crate) fn set_m32(&self, value: f64) { // For the DOMMatrix interface, setting the m32 attribute must set the // m32 element to the new value and, if the new value is not 0 or -0, set is 2D to false. self.matrix.borrow_mut().m32 = value; @@ -170,7 +170,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m33 - pub fn set_m33(&self, value: f64) { + pub(crate) fn set_m33(&self, value: f64) { // For the DOMMatrix interface, setting the m33 attribute must set the // m33 element to the new value and, if the new value is not 1, set is 2D to false. self.matrix.borrow_mut().m33 = value; @@ -181,7 +181,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m34 - pub fn set_m34(&self, value: f64) { + pub(crate) fn set_m34(&self, value: f64) { // For the DOMMatrix interface, setting the m34 attribute must set the // m34 element to the new value and, if the new value is not 0 or -0, set is 2D to false. self.matrix.borrow_mut().m34 = value; @@ -192,17 +192,17 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m41 - pub fn set_m41(&self, value: f64) { + pub(crate) fn set_m41(&self, value: f64) { self.matrix.borrow_mut().m41 = value; } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m42 - pub fn set_m42(&self, value: f64) { + pub(crate) fn set_m42(&self, value: f64) { self.matrix.borrow_mut().m42 = value; } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m43 - pub fn set_m43(&self, value: f64) { + pub(crate) fn set_m43(&self, value: f64) { // For the DOMMatrix interface, setting the m43 attribute must set the // m43 element to the new value and, if the new value is not 0 or -0, set is 2D to false. self.matrix.borrow_mut().m43 = value; @@ -213,7 +213,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m44 - pub fn set_m44(&self, value: f64) { + pub(crate) fn set_m44(&self, value: f64) { // For the DOMMatrix interface, setting the m44 attribute must set the // m44 element to the new value and, if the new value is not 1, set is 2D to false. self.matrix.borrow_mut().m44 = value; @@ -224,7 +224,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-multiplyself - pub fn multiply_self(&self, other: &DOMMatrixInit) -> Fallible<()> { + pub(crate) fn multiply_self(&self, other: &DOMMatrixInit) -> Fallible<()> { // Step 1. dommatrixinit_to_matrix(other).map(|(is2D, other_matrix)| { // Step 2. @@ -239,7 +239,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-premultiplyself - pub fn pre_multiply_self(&self, other: &DOMMatrixInit) -> Fallible<()> { + pub(crate) fn pre_multiply_self(&self, other: &DOMMatrixInit) -> Fallible<()> { // Step 1. dommatrixinit_to_matrix(other).map(|(is2D, other_matrix)| { // Step 2. @@ -254,7 +254,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-translateself - pub fn translate_self(&self, tx: f64, ty: f64, tz: f64) { + pub(crate) fn translate_self(&self, tx: f64, ty: f64, tz: f64) { // Step 1. let translation = Transform3D::translation(tx, ty, tz); let mut matrix = self.matrix.borrow_mut(); @@ -267,7 +267,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-scaleself - pub fn scale_self( + pub(crate) fn scale_self( &self, scaleX: f64, scaleY: Option, @@ -300,7 +300,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-scale3dself - pub fn scale_3d_self(&self, scale: f64, originX: f64, originY: f64, originZ: f64) { + pub(crate) fn scale_3d_self(&self, scale: f64, originX: f64, originY: f64, originZ: f64) { // Step 1. self.translate_self(originX, originY, originZ); // Step 2. @@ -319,7 +319,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-rotateself - pub fn rotate_self(&self, mut rotX: f64, mut rotY: Option, mut rotZ: Option) { + pub(crate) fn rotate_self(&self, mut rotX: f64, mut rotY: Option, mut rotZ: Option) { // Step 1. if rotY.is_none() && rotZ.is_none() { rotZ = Some(rotX); @@ -356,7 +356,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-rotatefromvectorself - pub fn rotate_from_vector_self(&self, x: f64, y: f64) { + pub(crate) fn rotate_from_vector_self(&self, x: f64, y: f64) { // don't do anything when the rotation angle is zero or undefined if y != 0.0 || x < 0.0 { // Step 1. @@ -369,7 +369,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-rotateaxisangleself - pub fn rotate_axis_angle_self(&self, x: f64, y: f64, z: f64, angle: f64) { + pub(crate) fn rotate_axis_angle_self(&self, x: f64, y: f64, z: f64, angle: f64) { // Step 1. let (norm_x, norm_y, norm_z) = normalize_point(x, y, z); // Beware: pass negated value until https://github.com/servo/euclid/issues/354 @@ -385,7 +385,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-skewxself - pub fn skew_x_self(&self, sx: f64) { + pub(crate) fn skew_x_self(&self, sx: f64) { // Step 1. let skew = Transform3D::skew(Angle::radians(sx.to_radians()), Angle::radians(0.0)); let mut matrix = self.matrix.borrow_mut(); @@ -394,7 +394,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-skewyself - pub fn skew_y_self(&self, sy: f64) { + pub(crate) fn skew_y_self(&self, sy: f64) { // Step 1. let skew = Transform3D::skew(Angle::radians(0.0), Angle::radians(sy.to_radians())); let mut matrix = self.matrix.borrow_mut(); @@ -403,7 +403,7 @@ impl DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-invertself - pub fn invert_self(&self) { + pub(crate) fn invert_self(&self) { let mut matrix = self.matrix.borrow_mut(); // Step 1. *matrix = matrix.inverse().unwrap_or_else(|| { @@ -950,7 +950,7 @@ fn create_3d_matrix(entries: &[f64]) -> Transform3D { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-dommatrixreadonly-numbersequence -pub fn entries_to_matrix(entries: &[f64]) -> Fallible<(bool, Transform3D)> { +pub(crate) fn entries_to_matrix(entries: &[f64]) -> Fallible<(bool, Transform3D)> { if entries.len() == 6 { Ok((true, create_2d_matrix(entries))) } else if entries.len() == 16 { @@ -962,7 +962,7 @@ pub fn entries_to_matrix(entries: &[f64]) -> Fallible<(bool, Transform3D)> } // https://drafts.fxtf.org/geometry-1/#validate-and-fixup -pub fn dommatrixinit_to_matrix(dict: &DOMMatrixInit) -> Fallible<(bool, Transform3D)> { +pub(crate) fn dommatrixinit_to_matrix(dict: &DOMMatrixInit) -> Fallible<(bool, Transform3D)> { // Step 1. if dict.parent.a.is_some() && dict.parent.m11.is_some() && @@ -1047,7 +1047,7 @@ fn normalize_point(x: f64, y: f64, z: f64) -> (f64, f64, f64) { } } -pub fn transform_to_matrix(value: String) -> Fallible<(bool, Transform3D)> { +pub(crate) fn transform_to_matrix(value: String) -> Fallible<(bool, Transform3D)> { use style::properties::longhands::transform; let mut input = ParserInput::new(&value); diff --git a/components/script/dom/domparser.rs b/components/script/dom/domparser.rs index 38b44bfdde7..ece1360d466 100644 --- a/components/script/dom/domparser.rs +++ b/components/script/dom/domparser.rs @@ -24,7 +24,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct DOMParser { +pub(crate) struct DOMParser { reflector_: Reflector, window: Dom, // XXXjdm Document instead? } diff --git a/components/script/dom/dompoint.rs b/components/script/dom/dompoint.rs index 4be2c2cdf8b..4e90ffa3db6 100644 --- a/components/script/dom/dompoint.rs +++ b/components/script/dom/dompoint.rs @@ -16,7 +16,7 @@ use crate::script_runtime::CanGc; // http://dev.w3.org/fxtf/geometry/Overview.html#dompoint #[dom_struct] -pub struct DOMPoint { +pub(crate) struct DOMPoint { point: DOMPointReadOnly, } @@ -28,7 +28,7 @@ impl DOMPoint { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, x: f64, y: f64, @@ -56,7 +56,7 @@ impl DOMPoint { ) } - pub fn new_from_init( + pub(crate) fn new_from_init( global: &GlobalScope, p: &DOMPointInit, can_gc: CanGc, diff --git a/components/script/dom/dompointreadonly.rs b/components/script/dom/dompointreadonly.rs index bb926511b96..ed29b9f7513 100644 --- a/components/script/dom/dompointreadonly.rs +++ b/components/script/dom/dompointreadonly.rs @@ -17,7 +17,7 @@ use crate::script_runtime::CanGc; // http://dev.w3.org/fxtf/geometry/Overview.html#dompointreadonly #[dom_struct] -pub struct DOMPointReadOnly { +pub(crate) struct DOMPointReadOnly { reflector_: Reflector, x: Cell, y: Cell, @@ -27,7 +27,7 @@ pub struct DOMPointReadOnly { #[allow(non_snake_case)] impl DOMPointReadOnly { - pub fn new_inherited(x: f64, y: f64, z: f64, w: f64) -> DOMPointReadOnly { + pub(crate) fn new_inherited(x: f64, y: f64, z: f64, w: f64) -> DOMPointReadOnly { DOMPointReadOnly { x: Cell::new(x), y: Cell::new(y), @@ -37,7 +37,7 @@ impl DOMPointReadOnly { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, x: f64, y: f64, @@ -110,7 +110,7 @@ impl DOMPointReadOnlyMethods for DOMPointReadOnly { } #[allow(non_snake_case)] -pub trait DOMPointWriteMethods { +pub(crate) trait DOMPointWriteMethods { fn SetX(&self, value: f64); fn SetY(&self, value: f64); fn SetZ(&self, value: f64); diff --git a/components/script/dom/domquad.rs b/components/script/dom/domquad.rs index 86888845485..cdbe99842bb 100644 --- a/components/script/dom/domquad.rs +++ b/components/script/dom/domquad.rs @@ -18,7 +18,7 @@ use crate::script_runtime::CanGc; /// #[dom_struct] -pub struct DOMQuad { +pub(crate) struct DOMQuad { reflector_: Reflector, p1: Dom, p2: Dom, @@ -37,7 +37,7 @@ impl DOMQuad { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, p1: &DOMPoint, p2: &DOMPoint, diff --git a/components/script/dom/domrect.rs b/components/script/dom/domrect.rs index e78b9fdfcbd..40ebd42f036 100644 --- a/components/script/dom/domrect.rs +++ b/components/script/dom/domrect.rs @@ -17,7 +17,7 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::CanGc; #[dom_struct] -pub struct DOMRect { +pub(crate) struct DOMRect { rect: DOMRectReadOnly, } @@ -28,7 +28,7 @@ impl DOMRect { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, x: f64, y: f64, diff --git a/components/script/dom/domrectlist.rs b/components/script/dom/domrectlist.rs index 94e00c2c0c4..93427bceac7 100644 --- a/components/script/dom/domrectlist.rs +++ b/components/script/dom/domrectlist.rs @@ -12,7 +12,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct DOMRectList { +pub(crate) struct DOMRectList { reflector_: Reflector, rects: DomRefCell>>, } @@ -30,7 +30,7 @@ impl DOMRectList { } } - pub fn new( + pub(crate) fn new( window: &Window, rects: Vec>, can_gc: CanGc, @@ -43,7 +43,7 @@ impl DOMRectList { ) } - pub fn first(&self) -> Option> { + pub(crate) fn first(&self) -> Option> { self.rects.borrow().first().map(Dom::as_rooted) } } diff --git a/components/script/dom/domrectreadonly.rs b/components/script/dom/domrectreadonly.rs index 2a04bd3596e..f9e71db51ba 100644 --- a/components/script/dom/domrectreadonly.rs +++ b/components/script/dom/domrectreadonly.rs @@ -19,7 +19,7 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::CanGc; #[dom_struct] -pub struct DOMRectReadOnly { +pub(crate) struct DOMRectReadOnly { reflector_: Reflector, x: Cell, y: Cell, @@ -28,7 +28,7 @@ pub struct DOMRectReadOnly { } impl DOMRectReadOnly { - pub fn new_inherited(x: f64, y: f64, width: f64, height: f64) -> DOMRectReadOnly { + pub(crate) fn new_inherited(x: f64, y: f64, width: f64, height: f64) -> DOMRectReadOnly { DOMRectReadOnly { x: Cell::new(x), y: Cell::new(y), @@ -38,7 +38,7 @@ impl DOMRectReadOnly { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, proto: Option, x: f64, @@ -55,19 +55,19 @@ impl DOMRectReadOnly { ) } - pub fn set_x(&self, value: f64) { + pub(crate) fn set_x(&self, value: f64) { self.x.set(value); } - pub fn set_y(&self, value: f64) { + pub(crate) fn set_y(&self, value: f64) { self.y.set(value); } - pub fn set_width(&self, value: f64) { + pub(crate) fn set_width(&self, value: f64) { self.width.set(value); } - pub fn set_height(&self, value: f64) { + pub(crate) fn set_height(&self, value: f64) { self.height.set(value); } } diff --git a/components/script/dom/domstringlist.rs b/components/script/dom/domstringlist.rs index aa83e81db93..ec6b7225d34 100644 --- a/components/script/dom/domstringlist.rs +++ b/components/script/dom/domstringlist.rs @@ -12,14 +12,14 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct DOMStringList { +pub(crate) struct DOMStringList { reflector_: Reflector, strings: Vec, } impl DOMStringList { #[allow(unused)] - pub fn new_inherited(strings: Vec) -> DOMStringList { + pub(crate) fn new_inherited(strings: Vec) -> DOMStringList { DOMStringList { reflector_: Reflector::new(), strings, @@ -27,7 +27,7 @@ impl DOMStringList { } #[allow(unused)] - pub fn new(window: &Window, strings: Vec) -> DomRoot { + pub(crate) fn new(window: &Window, strings: Vec) -> DomRoot { reflect_dom_object( Box::new(DOMStringList::new_inherited(strings)), window, diff --git a/components/script/dom/domstringmap.rs b/components/script/dom/domstringmap.rs index 2d72a9d4597..7e7a7ca596a 100644 --- a/components/script/dom/domstringmap.rs +++ b/components/script/dom/domstringmap.rs @@ -14,7 +14,7 @@ use crate::dom::node::NodeTraits; use crate::script_runtime::CanGc; #[dom_struct] -pub struct DOMStringMap { +pub(crate) struct DOMStringMap { reflector_: Reflector, element: Dom, } @@ -27,7 +27,7 @@ impl DOMStringMap { } } - pub fn new(element: &HTMLElement) -> DomRoot { + pub(crate) fn new(element: &HTMLElement) -> DomRoot { reflect_dom_object( Box::new(DOMStringMap::new_inherited(element)), &*element.owner_window(), diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index 7465649b056..e0762c41f53 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -18,7 +18,7 @@ use crate::dom::node::NodeTraits; use crate::script_runtime::CanGc; #[dom_struct] -pub struct DOMTokenList { +pub(crate) struct DOMTokenList { reflector_: Reflector, element: Dom, #[no_trace] @@ -28,7 +28,7 @@ pub struct DOMTokenList { } impl DOMTokenList { - pub fn new_inherited( + pub(crate) fn new_inherited( element: &Element, local_name: LocalName, supported_tokens: Option>, @@ -41,7 +41,7 @@ impl DOMTokenList { } } - pub fn new( + pub(crate) fn new( element: &Element, local_name: &LocalName, supported_tokens: Option>, diff --git a/components/script/dom/dynamicmoduleowner.rs b/components/script/dom/dynamicmoduleowner.rs index 1a0f3fdb8bf..1ad75a2323f 100644 --- a/components/script/dom/dynamicmoduleowner.rs +++ b/components/script/dom/dynamicmoduleowner.rs @@ -16,10 +16,10 @@ use crate::script_runtime::CanGc; /// An unique id for dynamic module #[derive(Clone, Copy, Debug, Eq, Hash, JSTraceable, PartialEq)] -pub struct DynamicModuleId(#[no_trace] pub Uuid); +pub(crate) struct DynamicModuleId(#[no_trace] pub(crate) Uuid); #[dom_struct] -pub struct DynamicModuleOwner { +pub(crate) struct DynamicModuleOwner { reflector_: Reflector, #[ignore_malloc_size_of = "Rc"] @@ -41,7 +41,11 @@ impl DynamicModuleOwner { } #[allow(crown::unrooted_must_root)] - pub fn new(global: &GlobalScope, promise: Rc, id: DynamicModuleId) -> DomRoot { + pub(crate) fn new( + global: &GlobalScope, + promise: Rc, + id: DynamicModuleId, + ) -> DomRoot { reflect_dom_object( Box::new(DynamicModuleOwner::new_inherited(promise, id)), global, diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index daae203bd52..df22722e1d5 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -159,7 +159,7 @@ use crate::task::TaskOnce; // https://html.spec.whatwg.org/multipage/#selector-focus #[dom_struct] -pub struct Element { +pub(crate) struct Element { node: Node, #[no_trace] local_name: LocalName, @@ -207,24 +207,24 @@ impl fmt::Debug for DomRoot { } #[derive(MallocSizeOf, PartialEq)] -pub enum ElementCreator { +pub(crate) enum ElementCreator { ParserCreated(u64), ScriptCreated, } -pub enum CustomElementCreationMode { +pub(crate) enum CustomElementCreationMode { Synchronous, Asynchronous, } impl ElementCreator { - pub fn is_parser_created(&self) -> bool { + pub(crate) fn is_parser_created(&self) -> bool { match *self { ElementCreator::ParserCreated(_) => true, ElementCreator::ScriptCreated => false, } } - pub fn return_line_number(&self) -> u64 { + pub(crate) fn return_line_number(&self) -> u64 { match *self { ElementCreator::ParserCreated(l) => l, ElementCreator::ScriptCreated => 1, @@ -232,7 +232,7 @@ impl ElementCreator { } } -pub enum AdjacentPosition { +pub(crate) enum AdjacentPosition { BeforeBegin, AfterEnd, AfterBegin, @@ -257,7 +257,7 @@ impl FromStr for AdjacentPosition { // Element methods // impl Element { - pub fn create( + pub(crate) fn create( name: QualName, is: Option, document: &Document, @@ -269,7 +269,7 @@ impl Element { create_element(name, is, document, creator, mode, proto, can_gc) } - pub fn new_inherited( + pub(crate) fn new_inherited( local_name: LocalName, namespace: Namespace, prefix: Option, @@ -284,7 +284,7 @@ impl Element { ) } - pub fn new_inherited_with_state( + pub(crate) fn new_inherited_with_state( state: ElementState, local_name: LocalName, namespace: Namespace, @@ -309,7 +309,7 @@ impl Element { } } - pub fn new( + pub(crate) fn new( local_name: LocalName, namespace: Namespace, prefix: Option, @@ -329,7 +329,7 @@ impl Element { impl_rare_data!(ElementRareData); - pub fn restyle(&self, damage: NodeDamage) { + pub(crate) fn restyle(&self, damage: NodeDamage) { let doc = self.node.owner_doc(); let mut restyle = doc.ensure_pending_restyle(self); @@ -343,16 +343,16 @@ impl Element { } } - pub fn set_is(&self, is: LocalName) { + pub(crate) fn set_is(&self, is: LocalName) { *self.is.borrow_mut() = Some(is); } - pub fn get_is(&self) -> Option { + pub(crate) fn get_is(&self) -> Option { self.is.borrow().clone() } /// - pub fn set_custom_element_state(&self, state: CustomElementState) { + pub(crate) fn set_custom_element_state(&self, state: CustomElementState) { // no need to inflate rare data for uncustomized if state != CustomElementState::Uncustomized || self.rare_data().is_some() { self.ensure_rare_data().custom_element_state = state; @@ -365,44 +365,44 @@ impl Element { self.set_state(ElementState::DEFINED, in_defined_state) } - pub fn get_custom_element_state(&self) -> CustomElementState { + pub(crate) fn get_custom_element_state(&self) -> CustomElementState { if let Some(rare_data) = self.rare_data().as_ref() { return rare_data.custom_element_state; } CustomElementState::Uncustomized } - pub fn set_custom_element_definition(&self, definition: Rc) { + pub(crate) fn set_custom_element_definition(&self, definition: Rc) { self.ensure_rare_data().custom_element_definition = Some(definition); } - pub fn get_custom_element_definition(&self) -> Option> { + pub(crate) fn get_custom_element_definition(&self) -> Option> { self.rare_data().as_ref()?.custom_element_definition.clone() } - pub fn clear_custom_element_definition(&self) { + pub(crate) fn clear_custom_element_definition(&self) { self.ensure_rare_data().custom_element_definition = None; } - pub fn push_callback_reaction(&self, function: Rc, args: Box<[Heap]>) { + pub(crate) fn push_callback_reaction(&self, function: Rc, args: Box<[Heap]>) { self.ensure_rare_data() .custom_element_reaction_queue .push(CustomElementReaction::Callback(function, args)); } - pub fn push_upgrade_reaction(&self, definition: Rc) { + pub(crate) fn push_upgrade_reaction(&self, definition: Rc) { self.ensure_rare_data() .custom_element_reaction_queue .push(CustomElementReaction::Upgrade(definition)); } - pub fn clear_reaction_queue(&self) { + pub(crate) fn clear_reaction_queue(&self) { if let Some(ref mut rare_data) = *self.rare_data_mut() { rare_data.custom_element_reaction_queue.clear(); } } - pub fn invoke_reactions(&self, can_gc: CanGc) { + pub(crate) fn invoke_reactions(&self, can_gc: CanGc) { loop { rooted_vec!(let mut reactions); match *self.rare_data_mut() { @@ -426,12 +426,12 @@ impl Element { /// style will be `None` for elements in a `display: none` subtree. otherwise, the element has a /// layout box iff it doesn't have `display: none`. - pub fn style(&self, can_gc: CanGc) -> Option> { + pub(crate) fn style(&self, can_gc: CanGc) -> Option> { self.upcast::().style(can_gc) } // https://drafts.csswg.org/cssom-view/#css-layout-box - pub fn has_css_layout_box(&self, can_gc: CanGc) -> bool { + pub(crate) fn has_css_layout_box(&self, can_gc: CanGc) -> bool { self.style(can_gc) .is_some_and(|s| !s.get_box().clone_display().is_none()) } @@ -499,12 +499,12 @@ impl Element { .map(|sr| DomRoot::from_ref(&**sr)) } - pub fn is_shadow_host(&self) -> bool { + pub(crate) fn is_shadow_host(&self) -> bool { self.shadow_root().is_some() } /// - pub fn attach_shadow( + pub(crate) fn attach_shadow( &self, // TODO: remove is_ua_widget argument is_ua_widget: IsUserAgentWidget, @@ -556,7 +556,7 @@ impl Element { Ok(shadow_root) } - pub fn detach_shadow(&self) { + pub(crate) fn detach_shadow(&self) { let Some(ref shadow_root) = self.shadow_root() else { unreachable!("Trying to detach a non-attached shadow root"); }; @@ -570,7 +570,7 @@ impl Element { } // https://html.spec.whatwg.org/multipage/#translation-mode - pub fn is_translate_enabled(&self) -> bool { + pub(crate) fn is_translate_enabled(&self) -> bool { let name = &html5ever::local_name!("translate"); if self.has_attribute(name) { match_ignore_ascii_case! { &*self.get_string_attribute(name), @@ -588,7 +588,7 @@ impl Element { } // https://html.spec.whatwg.org/multipage/#the-directionality - pub fn directionality(&self) -> String { + pub(crate) fn directionality(&self) -> String { self.downcast::() .and_then(|html_element| html_element.directionality()) .unwrap_or_else(|| { @@ -607,7 +607,7 @@ impl Element { /// #[inline] -pub fn is_valid_shadow_host_name(name: &LocalName) -> bool { +pub(crate) fn is_valid_shadow_host_name(name: &LocalName) -> bool { // > A valid shadow host name is: // > - a valid custom element name if is_valid_custom_element_name(name) { @@ -640,7 +640,7 @@ pub fn is_valid_shadow_host_name(name: &LocalName) -> bool { } #[inline] -pub fn get_attr_for_layout<'dom>( +pub(crate) fn get_attr_for_layout<'dom>( elem: LayoutDom<'dom, Element>, namespace: &Namespace, name: &LocalName, @@ -651,7 +651,7 @@ pub fn get_attr_for_layout<'dom>( .cloned() } -pub trait LayoutElementHelpers<'dom> { +pub(crate) trait LayoutElementHelpers<'dom> { fn attrs(self) -> &'dom [LayoutDom<'dom, Attr>]; fn has_class_for_layout(self, name: &AtomIdent, case_sensitivity: CaseSensitivity) -> bool; fn get_classes_for_layout(self) -> Option<&'dom [Atom]>; @@ -1216,43 +1216,43 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> { } impl Element { - pub fn is_html_element(&self) -> bool { + pub(crate) fn is_html_element(&self) -> bool { self.namespace == ns!(html) } - pub fn html_element_in_html_document(&self) -> bool { + pub(crate) fn html_element_in_html_document(&self) -> bool { self.is_html_element() && self.upcast::().is_in_html_doc() } - pub fn local_name(&self) -> &LocalName { + pub(crate) fn local_name(&self) -> &LocalName { &self.local_name } - pub fn parsed_name(&self, mut name: DOMString) -> LocalName { + pub(crate) fn parsed_name(&self, mut name: DOMString) -> LocalName { if self.html_element_in_html_document() { name.make_ascii_lowercase(); } LocalName::from(name) } - pub fn namespace(&self) -> &Namespace { + pub(crate) fn namespace(&self) -> &Namespace { &self.namespace } - pub fn prefix(&self) -> Ref> { + pub(crate) fn prefix(&self) -> Ref> { self.prefix.borrow() } - pub fn set_prefix(&self, prefix: Option) { + pub(crate) fn set_prefix(&self, prefix: Option) { *self.prefix.borrow_mut() = prefix; } - pub fn attrs(&self) -> Ref<[Dom]> { + pub(crate) fn attrs(&self) -> Ref<[Dom]> { Ref::map(self.attrs.borrow(), |attrs| &**attrs) } // Element branch of https://dom.spec.whatwg.org/#locate-a-namespace - pub fn locate_namespace(&self, prefix: Option) -> Namespace { + pub(crate) fn locate_namespace(&self, prefix: Option) -> Namespace { let namespace_prefix = prefix.clone().map(|s| Prefix::from(&*s)); // "1. If prefix is "xml", then return the XML namespace." @@ -1310,15 +1310,17 @@ impl Element { ns!() } - pub fn name_attribute(&self) -> Option { + pub(crate) fn name_attribute(&self) -> Option { self.rare_data().as_ref()?.name_attribute.clone() } - pub fn style_attribute(&self) -> &DomRefCell>>> { + pub(crate) fn style_attribute( + &self, + ) -> &DomRefCell>>> { &self.style_attribute } - pub fn summarize(&self) -> Vec { + pub(crate) fn summarize(&self) -> Vec { self.attrs .borrow() .iter() @@ -1326,7 +1328,7 @@ impl Element { .collect() } - pub fn is_void(&self) -> bool { + pub(crate) fn is_void(&self) -> bool { if self.namespace != ns!(html) { return false; } @@ -1355,7 +1357,7 @@ impl Element { } } - pub fn root_element(&self) -> DomRoot { + pub(crate) fn root_element(&self) -> DomRoot { if self.node.is_in_a_document_tree() { self.upcast::() .owner_doc() @@ -1371,7 +1373,7 @@ impl Element { } // https://dom.spec.whatwg.org/#locate-a-namespace-prefix - pub fn lookup_prefix(&self, namespace: Namespace) -> Option { + pub(crate) fn lookup_prefix(&self, namespace: Namespace) -> Option { for node in self .upcast::() .inclusive_ancestors(ShadowIncluding::No) @@ -1397,7 +1399,7 @@ impl Element { } // Returns the kind of IME control needed for a focusable element, if any. - pub fn input_method_type(&self) -> Option { + pub(crate) fn input_method_type(&self) -> Option { if !self.is_focusable_area() { return None; } @@ -1412,7 +1414,7 @@ impl Element { } } - pub fn is_focusable_area(&self) -> bool { + pub(crate) fn is_focusable_area(&self) -> bool { if self.is_actually_disabled() { return false; } @@ -1436,7 +1438,7 @@ impl Element { ) } - pub fn is_actually_disabled(&self) -> bool { + pub(crate) fn is_actually_disabled(&self) -> bool { let node = self.upcast::(); match node.type_id() { NodeTypeId::Element(ElementTypeId::HTMLElement( @@ -1468,7 +1470,7 @@ impl Element { } } - pub fn push_new_attribute( + pub(crate) fn push_new_attribute( &self, local_name: LocalName, value: AttrValue, @@ -1490,7 +1492,7 @@ impl Element { self.push_attribute(&attr); } - pub fn push_attribute(&self, attr: &Attr) { + pub(crate) fn push_attribute(&self, attr: &Attr) { let name = attr.local_name().clone(); let namespace = attr.namespace().clone(); let mutation = Mutation::Attribute { @@ -1515,7 +1517,7 @@ impl Element { } } - pub fn get_attribute( + pub(crate) fn get_attribute( &self, namespace: &Namespace, local_name: &LocalName, @@ -1528,7 +1530,7 @@ impl Element { } /// - pub fn get_attribute_by_name(&self, name: DOMString) -> Option> { + pub(crate) fn get_attribute_by_name(&self, name: DOMString) -> Option> { let name = &self.parsed_name(name); let maybe_attribute = self .attrs @@ -1550,7 +1552,7 @@ impl Element { maybe_attribute } - pub fn set_attribute_from_parser( + pub(crate) fn set_attribute_from_parser( &self, qname: QualName, value: DOMString, @@ -1578,7 +1580,7 @@ impl Element { self.push_new_attribute(qname.local, value, name, qname.ns, prefix, can_gc); } - pub fn set_attribute(&self, name: &LocalName, value: AttrValue, can_gc: CanGc) { + pub(crate) fn set_attribute(&self, name: &LocalName, value: AttrValue, can_gc: CanGc) { assert!(name == &name.to_ascii_lowercase()); assert!(!name.contains(':')); @@ -1594,7 +1596,7 @@ impl Element { } // https://html.spec.whatwg.org/multipage/#attr-data-* - pub fn set_custom_attribute( + pub(crate) fn set_custom_attribute( &self, name: DOMString, value: DOMString, @@ -1646,7 +1648,7 @@ impl Element { }; } - pub fn parse_attribute( + pub(crate) fn parse_attribute( &self, namespace: &Namespace, local_name: &LocalName, @@ -1659,7 +1661,7 @@ impl Element { } } - pub fn remove_attribute( + pub(crate) fn remove_attribute( &self, namespace: &Namespace, local_name: &LocalName, @@ -1669,7 +1671,7 @@ impl Element { }) } - pub fn remove_attribute_by_name(&self, name: &LocalName) -> Option> { + pub(crate) fn remove_attribute_by_name(&self, name: &LocalName) -> Option> { self.remove_first_matching_attribute(|attr| attr.name() == name) } @@ -1706,7 +1708,7 @@ impl Element { }) } - pub fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool { + pub(crate) fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool { self.get_attribute(&ns!(), &local_name!("class")) .is_some_and(|attr| { attr.value() @@ -1716,13 +1718,18 @@ impl Element { }) } - pub fn set_atomic_attribute(&self, local_name: &LocalName, value: DOMString, can_gc: CanGc) { + pub(crate) fn set_atomic_attribute( + &self, + local_name: &LocalName, + value: DOMString, + can_gc: CanGc, + ) { assert!(*local_name == local_name.to_ascii_lowercase()); let value = AttrValue::from_atomic(value.into()); self.set_attribute(local_name, value, can_gc); } - pub fn has_attribute(&self, local_name: &LocalName) -> bool { + pub(crate) fn has_attribute(&self, local_name: &LocalName) -> bool { assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b)); self.attrs .borrow() @@ -1730,7 +1737,7 @@ impl Element { .any(|attr| attr.local_name() == local_name && attr.namespace() == &ns!()) } - pub fn set_bool_attribute(&self, local_name: &LocalName, value: bool, can_gc: CanGc) { + pub(crate) fn set_bool_attribute(&self, local_name: &LocalName, value: bool, can_gc: CanGc) { if self.has_attribute(local_name) == value { return; } @@ -1741,7 +1748,7 @@ impl Element { } } - pub fn get_url_attribute(&self, local_name: &LocalName) -> USVString { + pub(crate) fn get_url_attribute(&self, local_name: &LocalName) -> USVString { assert!(*local_name == local_name.to_ascii_lowercase()); let attr = match self.get_attribute(&ns!(), local_name) { Some(attr) => attr, @@ -1756,19 +1763,29 @@ impl Element { .unwrap_or_else(|_| USVString(value.to_owned())) } - pub fn set_url_attribute(&self, local_name: &LocalName, value: USVString, can_gc: CanGc) { + pub(crate) fn set_url_attribute( + &self, + local_name: &LocalName, + value: USVString, + can_gc: CanGc, + ) { assert!(*local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::String(value.to_string()), can_gc); } - pub fn get_string_attribute(&self, local_name: &LocalName) -> DOMString { + pub(crate) fn get_string_attribute(&self, local_name: &LocalName) -> DOMString { match self.get_attribute(&ns!(), local_name) { Some(x) => x.Value(), None => DOMString::new(), } } - pub fn set_string_attribute(&self, local_name: &LocalName, value: DOMString, can_gc: CanGc) { + pub(crate) fn set_string_attribute( + &self, + local_name: &LocalName, + value: DOMString, + can_gc: CanGc, + ) { assert!(*local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::String(value.into()), can_gc); } @@ -1801,13 +1818,18 @@ impl Element { } } - pub fn get_tokenlist_attribute(&self, local_name: &LocalName) -> Vec { + pub(crate) fn get_tokenlist_attribute(&self, local_name: &LocalName) -> Vec { self.get_attribute(&ns!(), local_name) .map(|attr| attr.value().as_tokens().to_vec()) .unwrap_or_default() } - pub fn set_tokenlist_attribute(&self, local_name: &LocalName, value: DOMString, can_gc: CanGc) { + pub(crate) fn set_tokenlist_attribute( + &self, + local_name: &LocalName, + value: DOMString, + can_gc: CanGc, + ) { assert!(*local_name == local_name.to_ascii_lowercase()); self.set_attribute( local_name, @@ -1816,7 +1838,7 @@ impl Element { ); } - pub fn set_atomic_tokenlist_attribute( + pub(crate) fn set_atomic_tokenlist_attribute( &self, local_name: &LocalName, tokens: Vec, @@ -1826,7 +1848,7 @@ impl Element { self.set_attribute(local_name, AttrValue::from_atomic_tokens(tokens), can_gc); } - pub fn get_int_attribute(&self, local_name: &LocalName, default: i32) -> i32 { + pub(crate) fn get_int_attribute(&self, local_name: &LocalName, default: i32) -> i32 { // TODO: Is this assert necessary? assert!(local_name .chars() @@ -1845,12 +1867,12 @@ impl Element { } } - pub fn set_int_attribute(&self, local_name: &LocalName, value: i32, can_gc: CanGc) { + pub(crate) fn set_int_attribute(&self, local_name: &LocalName, value: i32, can_gc: CanGc) { assert!(*local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::Int(value.to_string(), value), can_gc); } - pub fn get_uint_attribute(&self, local_name: &LocalName, default: u32) -> u32 { + pub(crate) fn get_uint_attribute(&self, local_name: &LocalName, default: u32) -> u32 { assert!(local_name .chars() .all(|ch| !ch.is_ascii() || ch.to_ascii_lowercase() == ch)); @@ -1863,7 +1885,7 @@ impl Element { None => default, } } - pub fn set_uint_attribute(&self, local_name: &LocalName, value: u32, can_gc: CanGc) { + pub(crate) fn set_uint_attribute(&self, local_name: &LocalName, value: u32, can_gc: CanGc) { assert!(*local_name == local_name.to_ascii_lowercase()); self.set_attribute( local_name, @@ -1872,13 +1894,13 @@ impl Element { ); } - pub fn will_mutate_attr(&self, attr: &Attr) { + pub(crate) fn will_mutate_attr(&self, attr: &Attr) { let node = self.upcast::(); node.owner_doc().element_attr_will_change(self, attr); } // https://dom.spec.whatwg.org/#insert-adjacent - pub fn insert_adjacent( + pub(crate) fn insert_adjacent( &self, where_: AdjacentPosition, node: &Node, @@ -1907,7 +1929,7 @@ impl Element { } // https://drafts.csswg.org/cssom-view/#dom-element-scroll - pub fn scroll(&self, x_: f64, y_: f64, behavior: ScrollBehavior, can_gc: CanGc) { + pub(crate) fn scroll(&self, x_: f64, y_: f64, behavior: ScrollBehavior, can_gc: CanGc) { // Step 1.2 or 2.3 let x = if x_.is_finite() { x_ } else { 0.0f64 }; let y = if y_.is_finite() { y_ } else { 0.0f64 }; @@ -1959,7 +1981,7 @@ impl Element { } /// - pub fn parse_fragment( + pub(crate) fn parse_fragment( &self, markup: DOMString, can_gc: CanGc, @@ -1985,7 +2007,7 @@ impl Element { Ok(fragment) } - pub fn fragment_parsing_context( + pub(crate) fn fragment_parsing_context( owner_doc: &Document, element: Option<&Self>, can_gc: CanGc, @@ -2008,7 +2030,7 @@ impl Element { } // https://fullscreen.spec.whatwg.org/#fullscreen-element-ready-check - pub fn fullscreen_element_ready_check(&self) -> bool { + pub(crate) fn fullscreen_element_ready_check(&self) -> bool { if !self.is_connected() { return false; } @@ -2016,7 +2038,7 @@ impl Element { } // https://html.spec.whatwg.org/multipage/#home-subtree - pub fn is_in_same_home_subtree(&self, other: &T) -> bool + pub(crate) fn is_in_same_home_subtree(&self, other: &T) -> bool where T: DerivedFrom + DomObject, { @@ -2024,11 +2046,11 @@ impl Element { self.root_element() == other.root_element() } - pub fn get_id(&self) -> Option { + pub(crate) fn get_id(&self) -> Option { self.id_attribute.borrow().clone() } - pub fn get_name(&self) -> Option { + pub(crate) fn get_name(&self) -> Option { self.rare_data().as_ref()?.name_attribute.clone() } @@ -2092,7 +2114,7 @@ impl Element { } } - pub fn get_element_internals(&self) -> Option> { + pub(crate) fn get_element_internals(&self) -> Option> { self.rare_data() .as_ref()? .element_internals @@ -2100,7 +2122,7 @@ impl Element { .map(|sr| DomRoot::from_ref(&**sr)) } - pub fn ensure_element_internals(&self) -> DomRoot { + pub(crate) fn ensure_element_internals(&self) -> DomRoot { let mut rare_data = self.ensure_rare_data(); DomRoot::from_ref(rare_data.element_internals.get_or_insert_with(|| { let elem = self @@ -4011,7 +4033,7 @@ impl Element { rect } - pub fn as_maybe_activatable(&self) -> Option<&dyn Activatable> { + pub(crate) fn as_maybe_activatable(&self) -> Option<&dyn Activatable> { let element = match self.upcast::().type_id() { NodeTypeId::Element(ElementTypeId::HTMLElement( HTMLElementTypeId::HTMLInputElement, @@ -4052,7 +4074,7 @@ impl Element { }) } - pub fn as_stylesheet_owner(&self) -> Option<&dyn StylesheetOwner> { + pub(crate) fn as_stylesheet_owner(&self) -> Option<&dyn StylesheetOwner> { if let Some(s) = self.downcast::() { return Some(s as &dyn StylesheetOwner); } @@ -4065,7 +4087,7 @@ impl Element { } // https://html.spec.whatwg.org/multipage/#category-submit - pub fn as_maybe_validatable(&self) -> Option<&dyn Validatable> { + pub(crate) fn as_maybe_validatable(&self) -> Option<&dyn Validatable> { let element = match self.upcast::().type_id() { NodeTypeId::Element(ElementTypeId::HTMLElement( HTMLElementTypeId::HTMLInputElement, @@ -4114,7 +4136,7 @@ impl Element { element } - pub fn is_invalid(&self, needs_update: bool) -> bool { + pub(crate) fn is_invalid(&self, needs_update: bool) -> bool { if let Some(validatable) = self.as_maybe_validatable() { if needs_update { validatable @@ -4130,7 +4152,7 @@ impl Element { false } - pub fn is_instance_validatable(&self) -> bool { + pub(crate) fn is_instance_validatable(&self) -> bool { if let Some(validatable) = self.as_maybe_validatable() { return validatable.is_instance_validatable(); } @@ -4140,23 +4162,23 @@ impl Element { false } - pub fn init_state_for_internals(&self) { + pub(crate) fn init_state_for_internals(&self) { self.set_enabled_state(true); self.set_state(ElementState::VALID, true); self.set_state(ElementState::INVALID, false); } - pub fn click_in_progress(&self) -> bool { + pub(crate) fn click_in_progress(&self) -> bool { self.upcast::().get_flag(NodeFlags::CLICK_IN_PROGRESS) } - pub fn set_click_in_progress(&self, click: bool) { + pub(crate) fn set_click_in_progress(&self, click: bool) { self.upcast::() .set_flag(NodeFlags::CLICK_IN_PROGRESS, click) } // https://html.spec.whatwg.org/multipage/#nearest-activatable-element - pub fn nearest_activable_element(&self) -> Option> { + pub(crate) fn nearest_activable_element(&self) -> Option> { match self.as_maybe_activatable() { Some(el) => Some(DomRoot::from_ref(el.as_element())), None => { @@ -4174,7 +4196,7 @@ impl Element { } // https://html.spec.whatwg.org/multipage/#language - pub fn get_lang(&self) -> String { + pub(crate) fn get_lang(&self) -> String { self.upcast::() .inclusive_ancestors(ShadowIncluding::Yes) .filter_map(|node| { @@ -4190,11 +4212,11 @@ impl Element { .unwrap_or(String::new()) } - pub fn state(&self) -> ElementState { + pub(crate) fn state(&self) -> ElementState { self.state.get() } - pub fn set_state(&self, which: ElementState, value: bool) { + pub(crate) fn set_state(&self, which: ElementState, value: bool) { let mut state = self.state.get(); if state.contains(which) == value { return; @@ -4210,7 +4232,7 @@ impl Element { } /// - pub fn set_active_state(&self, value: bool) { + pub(crate) fn set_active_state(&self, value: bool) { self.set_state(ElementState::ACTIVE, value); if let Some(parent) = self.upcast::().GetParentElement() { @@ -4218,73 +4240,73 @@ impl Element { } } - pub fn focus_state(&self) -> bool { + pub(crate) fn focus_state(&self) -> bool { self.state.get().contains(ElementState::FOCUS) } - pub fn set_focus_state(&self, value: bool) { + pub(crate) fn set_focus_state(&self, value: bool) { self.set_state(ElementState::FOCUS, value); self.upcast::().dirty(NodeDamage::OtherNodeDamage); } - pub fn hover_state(&self) -> bool { + pub(crate) fn hover_state(&self) -> bool { self.state.get().contains(ElementState::HOVER) } - pub fn set_hover_state(&self, value: bool) { + pub(crate) fn set_hover_state(&self, value: bool) { self.set_state(ElementState::HOVER, value) } - pub fn enabled_state(&self) -> bool { + pub(crate) fn enabled_state(&self) -> bool { self.state.get().contains(ElementState::ENABLED) } - pub fn set_enabled_state(&self, value: bool) { + pub(crate) fn set_enabled_state(&self, value: bool) { self.set_state(ElementState::ENABLED, value) } - pub fn disabled_state(&self) -> bool { + pub(crate) fn disabled_state(&self) -> bool { self.state.get().contains(ElementState::DISABLED) } - pub fn set_disabled_state(&self, value: bool) { + pub(crate) fn set_disabled_state(&self, value: bool) { self.set_state(ElementState::DISABLED, value) } - pub fn read_write_state(&self) -> bool { + pub(crate) fn read_write_state(&self) -> bool { self.state.get().contains(ElementState::READWRITE) } - pub fn set_read_write_state(&self, value: bool) { + pub(crate) fn set_read_write_state(&self, value: bool) { self.set_state(ElementState::READWRITE, value) } - pub fn placeholder_shown_state(&self) -> bool { + pub(crate) fn placeholder_shown_state(&self) -> bool { self.state.get().contains(ElementState::PLACEHOLDER_SHOWN) } - pub fn set_placeholder_shown_state(&self, value: bool) { + pub(crate) fn set_placeholder_shown_state(&self, value: bool) { if self.placeholder_shown_state() != value { self.set_state(ElementState::PLACEHOLDER_SHOWN, value); self.upcast::().dirty(NodeDamage::OtherNodeDamage); } } - pub fn set_target_state(&self, value: bool) { + pub(crate) fn set_target_state(&self, value: bool) { self.set_state(ElementState::URLTARGET, value) } - pub fn set_fullscreen_state(&self, value: bool) { + pub(crate) fn set_fullscreen_state(&self, value: bool) { self.set_state(ElementState::FULLSCREEN, value) } /// - pub fn is_connected(&self) -> bool { + pub(crate) fn is_connected(&self) -> bool { self.upcast::().is_connected() } // https://html.spec.whatwg.org/multipage/#cannot-navigate - pub fn cannot_navigate(&self) -> bool { + pub(crate) fn cannot_navigate(&self) -> bool { let document = self.owner_document(); // Step 1. @@ -4297,7 +4319,7 @@ impl Element { } impl Element { - pub fn check_ancestors_disabled_state_for_form_control(&self) { + pub(crate) fn check_ancestors_disabled_state_for_form_control(&self) { let node = self.upcast::(); if self.disabled_state() { return; @@ -4326,7 +4348,7 @@ impl Element { } } - pub fn check_parent_disabled_state_for_option(&self) { + pub(crate) fn check_parent_disabled_state_for_option(&self) { if self.disabled_state() { return; } @@ -4341,20 +4363,20 @@ impl Element { } } - pub fn check_disabled_attribute(&self) { + pub(crate) fn check_disabled_attribute(&self) { let has_disabled_attrib = self.has_attribute(&local_name!("disabled")); self.set_disabled_state(has_disabled_attrib); self.set_enabled_state(!has_disabled_attrib); } - pub fn update_read_write_state_from_readonly_attribute(&self) { + pub(crate) fn update_read_write_state_from_readonly_attribute(&self) { let has_readonly_attribute = self.has_attribute(&local_name!("readonly")); self.set_read_write_state(has_readonly_attribute); } } #[derive(Clone, Copy)] -pub enum AttributeMutation<'a> { +pub(crate) enum AttributeMutation<'a> { /// The attribute is set, keep track of old value. /// Set(Option<&'a AttrValue>), @@ -4365,14 +4387,14 @@ pub enum AttributeMutation<'a> { } impl AttributeMutation<'_> { - pub fn is_removal(&self) -> bool { + pub(crate) fn is_removal(&self) -> bool { match *self { AttributeMutation::Removed => true, AttributeMutation::Set(..) => false, } } - pub fn new_value<'b>(&self, attr: &'b Attr) -> Option> { + pub(crate) fn new_value<'b>(&self, attr: &'b Attr) -> Option> { match *self { AttributeMutation::Set(_) => Some(attr.value()), AttributeMutation::Removed => None, @@ -4419,14 +4441,14 @@ impl TagName { } } -pub struct ElementPerformFullscreenEnter { +pub(crate) struct ElementPerformFullscreenEnter { element: Trusted, promise: TrustedPromise, error: bool, } impl ElementPerformFullscreenEnter { - pub fn new( + pub(crate) fn new( element: Trusted, promise: TrustedPromise, error: bool, @@ -4470,13 +4492,13 @@ impl TaskOnce for ElementPerformFullscreenEnter { } } -pub struct ElementPerformFullscreenExit { +pub(crate) struct ElementPerformFullscreenExit { element: Trusted, promise: TrustedPromise, } impl ElementPerformFullscreenExit { - pub fn new( + pub(crate) fn new( element: Trusted, promise: TrustedPromise, ) -> Box { @@ -4504,7 +4526,7 @@ impl TaskOnce for ElementPerformFullscreenExit { } } -pub fn reflect_cross_origin_attribute(element: &Element) -> Option { +pub(crate) fn reflect_cross_origin_attribute(element: &Element) -> Option { let attr = element.get_attribute(&ns!(), &local_name!("crossorigin")); if let Some(mut val) = attr.map(|v| v.Value()) { @@ -4517,7 +4539,11 @@ pub fn reflect_cross_origin_attribute(element: &Element) -> Option { None } -pub fn set_cross_origin_attribute(element: &Element, value: Option, can_gc: CanGc) { +pub(crate) fn set_cross_origin_attribute( + element: &Element, + value: Option, + can_gc: CanGc, +) { match value { Some(val) => element.set_string_attribute(&local_name!("crossorigin"), val, can_gc), None => { @@ -4526,7 +4552,7 @@ pub fn set_cross_origin_attribute(element: &Element, value: Option, c } } -pub fn reflect_referrer_policy_attribute(element: &Element) -> DOMString { +pub(crate) fn reflect_referrer_policy_attribute(element: &Element) -> DOMString { let attr = element.get_attribute_by_name(DOMString::from_string(String::from("referrerpolicy"))); diff --git a/components/script/dom/elementinternals.rs b/components/script/dom/elementinternals.rs index bb717e9e419..4156a5a725b 100644 --- a/components/script/dom/elementinternals.rs +++ b/components/script/dom/elementinternals.rs @@ -53,7 +53,7 @@ impl From> for SubmissionValue { } #[dom_struct] -pub struct ElementInternals { +pub(crate) struct ElementInternals { reflector_: Reflector, /// If `attached` is false, we're using this to hold form-related state /// on an element for which `attachInternals()` wasn't called yet; this is @@ -87,7 +87,7 @@ impl ElementInternals { } } - pub fn new(element: &HTMLElement) -> DomRoot { + pub(crate) fn new(element: &HTMLElement) -> DomRoot { let global = element.owner_window(); reflect_dom_object( Box::new(ElementInternals::new_inherited(element)), @@ -116,23 +116,23 @@ impl ElementInternals { *self.state.borrow_mut() = value; } - pub fn set_form_owner(&self, form: Option<&HTMLFormElement>) { + pub(crate) fn set_form_owner(&self, form: Option<&HTMLFormElement>) { self.form_owner.set(form); } - pub fn form_owner(&self) -> Option> { + pub(crate) fn form_owner(&self) -> Option> { self.form_owner.get() } - pub fn set_attached(&self) { + pub(crate) fn set_attached(&self) { self.attached.set(true); } - pub fn attached(&self) -> bool { + pub(crate) fn attached(&self) -> bool { self.attached.get() } - pub fn perform_entry_construction(&self, entry_list: &mut Vec) { + pub(crate) fn perform_entry_construction(&self, entry_list: &mut Vec) { if self .target_element .upcast::() @@ -180,7 +180,7 @@ impl ElementInternals { } } - pub fn is_invalid(&self) -> bool { + pub(crate) fn is_invalid(&self) -> bool { self.is_target_form_associated() && self.is_instance_validatable() && !self.satisfies_constraints() diff --git a/components/script/dom/errorevent.rs b/components/script/dom/errorevent.rs index f2075f90708..eb81c6a630f 100644 --- a/components/script/dom/errorevent.rs +++ b/components/script/dom/errorevent.rs @@ -25,7 +25,7 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::{CanGc, JSContext}; #[dom_struct] -pub struct ErrorEvent { +pub(crate) struct ErrorEvent { event: Event, message: DomRefCell, filename: DomRefCell, @@ -56,7 +56,7 @@ impl ErrorEvent { } #[allow(clippy::too_many_arguments)] - pub fn new( + pub(crate) fn new( global: &GlobalScope, type_: Atom, bubbles: EventBubbles, diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index 5db7ee679d9..05a58274414 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -42,7 +42,7 @@ use crate::task::TaskOnce; /// #[dom_struct] -pub struct Event { +pub(crate) struct Event { reflector_: Reflector, /// @@ -96,7 +96,7 @@ pub struct Event { /// An element on an [event path](https://dom.spec.whatwg.org/#event-path) #[derive(JSTraceable, MallocSizeOf)] #[crown::unrooted_must_root_lint::must_root] -pub struct EventPathSegment { +pub(crate) struct EventPathSegment { /// invocation_target: Dom, @@ -876,7 +876,7 @@ impl EventMethods for Event { } #[derive(Clone, Copy, MallocSizeOf, PartialEq)] -pub enum EventBubbles { +pub(crate) enum EventBubbles { Bubbles, DoesNotBubble, } @@ -901,7 +901,7 @@ impl From for bool { } #[derive(Clone, Copy, MallocSizeOf, PartialEq)] -pub enum EventCancelable { +pub(crate) enum EventCancelable { Cancelable, NotCancelable, } @@ -928,7 +928,7 @@ impl From for bool { #[derive(Clone, Copy, Debug, Eq, JSTraceable, PartialEq)] #[repr(u16)] #[derive(MallocSizeOf)] -pub enum EventPhase { +pub(crate) enum EventPhase { None = EventConstants::NONE, Capturing = EventConstants::CAPTURING_PHASE, AtTarget = EventConstants::AT_TARGET, @@ -947,7 +947,7 @@ pub enum EventPhase { /// [msg]: https://doc.servo.org/compositing/enum.ConstellationMsg.html#variant.KeyEvent /// #[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)] -pub enum EventDefault { +pub(crate) enum EventDefault { /// The default action of the event is allowed (constructor's default) Allowed, /// The default action has been prevented by calling `PreventDefault` @@ -958,17 +958,17 @@ pub enum EventDefault { } #[derive(PartialEq)] -pub enum EventStatus { +pub(crate) enum EventStatus { Canceled, NotCanceled, } /// -pub struct EventTask { - pub target: Trusted, - pub name: Atom, - pub bubbles: EventBubbles, - pub cancelable: EventCancelable, +pub(crate) struct EventTask { + pub(crate) target: Trusted, + pub(crate) name: Atom, + pub(crate) bubbles: EventBubbles, + pub(crate) cancelable: EventCancelable, } impl TaskOnce for EventTask { @@ -981,9 +981,9 @@ impl TaskOnce for EventTask { } /// -pub struct SimpleEventTask { - pub target: Trusted, - pub name: Atom, +pub(crate) struct SimpleEventTask { + pub(crate) target: Trusted, + pub(crate) name: Atom, } impl TaskOnce for SimpleEventTask { diff --git a/components/script/dom/eventsource.rs b/components/script/dom/eventsource.rs index d247f0696e4..39adc36332c 100644 --- a/components/script/dom/eventsource.rs +++ b/components/script/dom/eventsource.rs @@ -24,7 +24,6 @@ use net_traits::{ }; use servo_atoms::Atom; use servo_url::ServoUrl; -use utf8; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::EventSourceBinding::{ @@ -61,7 +60,7 @@ enum ReadyState { } #[dom_struct] -pub struct EventSource { +pub(crate) struct EventSource { eventtarget: EventTarget, #[no_trace] url: ServoUrl, @@ -482,13 +481,13 @@ impl EventSource { } // https://html.spec.whatwg.org/multipage/#sse-processing-model:fail-the-connection-3 - pub fn cancel(&self) { + pub(crate) fn cancel(&self) { self.canceller.borrow_mut().cancel(); self.fail_the_connection(); } /// - pub fn fail_the_connection(&self) { + pub(crate) fn fail_the_connection(&self) { let global = self.global(); let event_source = Trusted::new(self); global.task_manager().remote_event_task_source().queue( @@ -502,11 +501,11 @@ impl EventSource { ); } - pub fn request(&self) -> RequestBuilder { + pub(crate) fn request(&self) -> RequestBuilder { self.request.borrow().clone().unwrap() } - pub fn url(&self) -> &ServoUrl { + pub(crate) fn url(&self) -> &ServoUrl { &self.url } } @@ -649,7 +648,7 @@ impl EventSourceMethods for EventSource { } #[derive(JSTraceable, MallocSizeOf)] -pub struct EventSourceTimeoutCallback { +pub(crate) struct EventSourceTimeoutCallback { #[ignore_malloc_size_of = "Because it is non-owning"] event_source: Trusted, #[ignore_malloc_size_of = "Because it is non-owning"] @@ -659,7 +658,7 @@ pub struct EventSourceTimeoutCallback { impl EventSourceTimeoutCallback { // https://html.spec.whatwg.org/multipage/#reestablish-the-connection - pub fn invoke(self) { + pub(crate) fn invoke(self) { let event_source = self.event_source.root(); let global = event_source.global(); // Step 5.1 diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 306320d1a32..b5404890160 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -66,7 +66,7 @@ use crate::script_runtime::CanGc; #[derive(Clone, JSTraceable, MallocSizeOf, PartialEq)] #[allow(clippy::enum_variant_names)] -pub enum CommonEventHandler { +pub(crate) enum CommonEventHandler { EventHandler(#[ignore_malloc_size_of = "Rc"] Rc), ErrorEventHandler(#[ignore_malloc_size_of = "Rc"] Rc), @@ -85,7 +85,7 @@ impl CommonEventHandler { } #[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)] -pub enum ListenerPhase { +pub(crate) enum ListenerPhase { Capturing, Bubbling, } @@ -159,14 +159,14 @@ impl EventListenerType { /// A representation of an EventListener/EventHandler object that has previously /// been compiled successfully, if applicable. -pub enum CompiledEventListener { +pub(crate) enum CompiledEventListener { Listener(Rc), Handler(CommonEventHandler), } impl CompiledEventListener { #[allow(unsafe_code)] - pub fn associated_global(&self) -> DomRoot { + pub(crate) fn associated_global(&self) -> DomRoot { let obj = match self { CompiledEventListener::Listener(listener) => listener.callback(), CompiledEventListener::Handler(CommonEventHandler::EventHandler(handler)) => { @@ -183,7 +183,7 @@ impl CompiledEventListener { } // https://html.spec.whatwg.org/multipage/#the-event-handler-processing-algorithm - pub fn call_or_handle_event( + pub(crate) fn call_or_handle_event( &self, object: &EventTarget, event: &Event, @@ -368,13 +368,13 @@ impl EventListeners { } #[dom_struct] -pub struct EventTarget { +pub(crate) struct EventTarget { reflector_: Reflector, handlers: DomRefCell>>, } impl EventTarget { - pub fn new_inherited() -> EventTarget { + pub(crate) fn new_inherited() -> EventTarget { EventTarget { reflector_: Reflector::new(), handlers: DomRefCell::new(Default::default()), @@ -396,14 +396,14 @@ impl EventTarget { /// Determine if there are any listeners for a given event type. /// See . - pub fn has_listeners_for(&self, type_: &Atom) -> bool { + pub(crate) fn has_listeners_for(&self, type_: &Atom) -> bool { match self.handlers.borrow().get(type_) { Some(listeners) => listeners.has_listeners(), None => false, } } - pub fn get_listeners_for( + pub(crate) fn get_listeners_for( &self, type_: &Atom, specific_phase: Option, @@ -417,11 +417,11 @@ impl EventTarget { }) } - pub fn dispatch_event(&self, event: &Event, can_gc: CanGc) -> EventStatus { + pub(crate) fn dispatch_event(&self, event: &Event, can_gc: CanGc) -> EventStatus { event.dispatch(self, false, can_gc) } - pub fn remove_all_listeners(&self) { + pub(crate) fn remove_all_listeners(&self) { *self.handlers.borrow_mut() = Default::default(); } @@ -460,7 +460,7 @@ impl EventTarget { } } - pub fn remove_listener_if_once(&self, ty: &Atom, listener: &Rc) { + pub(crate) fn remove_listener_if_once(&self, ty: &Atom, listener: &Rc) { let mut handlers = self.handlers.borrow_mut(); let listener = EventListenerType::Additive(listener.clone()); @@ -478,7 +478,7 @@ impl EventTarget { /// Store the raw uncompiled event handler for on-demand compilation later. /// - pub fn set_event_handler_uncompiled( + pub(crate) fn set_event_handler_uncompiled( &self, url: ServoUrl, line: usize, @@ -612,7 +612,7 @@ impl EventTarget { } #[allow(unsafe_code)] - pub fn set_event_handler_common( + pub(crate) fn set_event_handler_common( &self, ty: &str, listener: Option>, @@ -628,7 +628,11 @@ impl EventTarget { } #[allow(unsafe_code)] - pub fn set_error_event_handler(&self, ty: &str, listener: Option>) { + pub(crate) fn set_error_event_handler( + &self, + ty: &str, + listener: Option>, + ) { let cx = GlobalScope::get_cx(); let event_listener = listener.map(|listener| { @@ -640,7 +644,7 @@ impl EventTarget { } #[allow(unsafe_code)] - pub fn set_beforeunload_event_handler( + pub(crate) fn set_beforeunload_event_handler( &self, ty: &str, listener: Option>, @@ -656,7 +660,7 @@ impl EventTarget { } #[allow(unsafe_code)] - pub fn get_event_handler_common( + pub(crate) fn get_event_handler_common( &self, ty: &str, can_gc: CanGc, @@ -670,12 +674,12 @@ impl EventTarget { } } - pub fn has_handlers(&self) -> bool { + pub(crate) fn has_handlers(&self) -> bool { !self.handlers.borrow().is_empty() } // https://dom.spec.whatwg.org/#concept-event-fire - pub fn fire_event(&self, name: Atom, can_gc: CanGc) -> DomRoot { + pub(crate) fn fire_event(&self, name: Atom, can_gc: CanGc) -> DomRoot { self.fire_event_with_params( name, EventBubbles::DoesNotBubble, @@ -685,7 +689,7 @@ impl EventTarget { } // https://dom.spec.whatwg.org/#concept-event-fire - pub fn fire_bubbling_event(&self, name: Atom, can_gc: CanGc) -> DomRoot { + pub(crate) fn fire_bubbling_event(&self, name: Atom, can_gc: CanGc) -> DomRoot { self.fire_event_with_params( name, EventBubbles::Bubbles, @@ -695,7 +699,7 @@ impl EventTarget { } // https://dom.spec.whatwg.org/#concept-event-fire - pub fn fire_cancelable_event(&self, name: Atom, can_gc: CanGc) -> DomRoot { + pub(crate) fn fire_cancelable_event(&self, name: Atom, can_gc: CanGc) -> DomRoot { self.fire_event_with_params( name, EventBubbles::DoesNotBubble, @@ -705,7 +709,11 @@ impl EventTarget { } // https://dom.spec.whatwg.org/#concept-event-fire - pub fn fire_bubbling_cancelable_event(&self, name: Atom, can_gc: CanGc) -> DomRoot { + pub(crate) fn fire_bubbling_cancelable_event( + &self, + name: Atom, + can_gc: CanGc, + ) -> DomRoot { self.fire_event_with_params( name, EventBubbles::Bubbles, @@ -715,7 +723,7 @@ impl EventTarget { } // https://dom.spec.whatwg.org/#concept-event-fire - pub fn fire_event_with_params( + pub(crate) fn fire_event_with_params( &self, name: Atom, bubbles: EventBubbles, @@ -727,7 +735,7 @@ impl EventTarget { event } // https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener - pub fn add_event_listener( + pub(crate) fn add_event_listener( &self, ty: DOMString, listener: Option>, @@ -759,7 +767,7 @@ impl EventTarget { } // https://dom.spec.whatwg.org/#dom-eventtarget-removeeventlistener - pub fn remove_event_listener( + pub(crate) fn remove_event_listener( &self, ty: DOMString, listener: Option>, diff --git a/components/script/dom/extendableevent.rs b/components/script/dom/extendableevent.rs index 1bec9c8cf25..87c5485f0f8 100644 --- a/components/script/dom/extendableevent.rs +++ b/components/script/dom/extendableevent.rs @@ -21,21 +21,21 @@ use crate::script_runtime::{CanGc, JSContext}; // https://w3c.github.io/ServiceWorker/#extendable-event #[dom_struct] -pub struct ExtendableEvent { +pub(crate) struct ExtendableEvent { event: Event, extensions_allowed: bool, } #[allow(non_snake_case)] impl ExtendableEvent { - pub fn new_inherited() -> ExtendableEvent { + pub(crate) fn new_inherited() -> ExtendableEvent { ExtendableEvent { event: Event::new_inherited(), extensions_allowed: true, } } - pub fn new( + pub(crate) fn new( worker: &ServiceWorkerGlobalScope, type_: Atom, bubbles: bool, diff --git a/components/script/dom/extendablemessageevent.rs b/components/script/dom/extendablemessageevent.rs index 484fa06cf84..d05488e7f52 100644 --- a/components/script/dom/extendablemessageevent.rs +++ b/components/script/dom/extendablemessageevent.rs @@ -28,7 +28,7 @@ use crate::script_runtime::{CanGc, JSContext}; #[dom_struct] #[allow(non_snake_case)] -pub struct ExtendableMessageEvent { +pub(crate) struct ExtendableMessageEvent { /// event: ExtendableEvent, /// @@ -46,7 +46,7 @@ pub struct ExtendableMessageEvent { #[allow(non_snake_case)] impl ExtendableMessageEvent { - pub fn new_inherited( + pub(crate) fn new_inherited( origin: DOMString, lastEventId: DOMString, ports: Vec>, @@ -65,7 +65,7 @@ impl ExtendableMessageEvent { } #[allow(clippy::too_many_arguments)] - pub fn new( + pub(crate) fn new( global: &GlobalScope, type_: Atom, bubbles: bool, @@ -121,7 +121,7 @@ impl ExtendableMessageEvent { #[allow(non_snake_case)] impl ExtendableMessageEvent { - pub fn dispatch_jsval( + pub(crate) fn dispatch_jsval( target: &EventTarget, scope: &GlobalScope, message: HandleValue, @@ -144,7 +144,7 @@ impl ExtendableMessageEvent { .fire(target, can_gc); } - pub fn dispatch_error(target: &EventTarget, scope: &GlobalScope, can_gc: CanGc) { + pub(crate) fn dispatch_error(target: &EventTarget, scope: &GlobalScope, can_gc: CanGc) { let init = ExtendableMessageEventBinding::ExtendableMessageEventInit::empty(); let ExtendableMsgEvent = ExtendableMessageEvent::new( scope, diff --git a/components/script/dom/file.rs b/components/script/dom/file.rs index 7863ea5bf59..f3f78fe2c7f 100644 --- a/components/script/dom/file.rs +++ b/components/script/dom/file.rs @@ -24,7 +24,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct File { +pub(crate) struct File { blob: Blob, name: DOMString, modified: SystemTime, @@ -41,7 +41,7 @@ impl File { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, blob_impl: BlobImpl, name: DOMString, @@ -71,7 +71,7 @@ impl File { } // Construct from selected file message from file manager thread - pub fn new_from_selected( + pub(crate) fn new_from_selected( window: &Window, selected: SelectedFile, can_gc: CanGc, @@ -97,15 +97,15 @@ impl File { ) } - pub fn file_bytes(&self) -> Result, ()> { + pub(crate) fn file_bytes(&self) -> Result, ()> { self.blob.get_bytes() } - pub fn name(&self) -> &DOMString { + pub(crate) fn name(&self) -> &DOMString { &self.name } - pub fn file_type(&self) -> String { + pub(crate) fn file_type(&self) -> String { self.blob.type_string() } } diff --git a/components/script/dom/filelist.rs b/components/script/dom/filelist.rs index 25f463f8dde..f3e077aa3fe 100644 --- a/components/script/dom/filelist.rs +++ b/components/script/dom/filelist.rs @@ -15,7 +15,7 @@ use crate::script_runtime::CanGc; // https://w3c.github.io/FileAPI/#dfn-filelist #[dom_struct] -pub struct FileList { +pub(crate) struct FileList { reflector_: Reflector, list: Vec>, } @@ -30,7 +30,7 @@ impl FileList { } #[allow(crown::unrooted_must_root)] - pub fn new(window: &Window, files: Vec>) -> DomRoot { + pub(crate) fn new(window: &Window, files: Vec>) -> DomRoot { reflect_dom_object( Box::new(FileList::new_inherited( files.iter().map(|r| Dom::from_ref(&**r)).collect(), @@ -40,7 +40,7 @@ impl FileList { ) } - pub fn iter_files(&self) -> Iter> { + pub(crate) fn iter_files(&self) -> Iter> { self.list.iter() } } diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs index d2b6d864d3d..269ee4913e6 100644 --- a/components/script/dom/filereader.rs +++ b/components/script/dom/filereader.rs @@ -39,7 +39,7 @@ use crate::script_runtime::{CanGc, JSContext}; use crate::task::TaskOnce; #[allow(dead_code)] -pub enum FileReadingTask { +pub(crate) enum FileReadingTask { ProcessRead(TrustedFileReader, GenerationId), ProcessReadData(TrustedFileReader, GenerationId), ProcessReadError(TrustedFileReader, GenerationId, DOMErrorName), @@ -53,7 +53,7 @@ impl TaskOnce for FileReadingTask { } impl FileReadingTask { - pub fn handle_task(self, can_gc: CanGc) { + pub(crate) fn handle_task(self, can_gc: CanGc) { use self::FileReadingTask::*; match self { @@ -71,23 +71,23 @@ impl FileReadingTask { } } #[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)] -pub enum FileReaderFunction { +pub(crate) enum FileReaderFunction { Text, DataUrl, ArrayBuffer, } -pub type TrustedFileReader = Trusted; +pub(crate) type TrustedFileReader = Trusted; #[derive(Clone, MallocSizeOf)] -pub struct ReadMetaData { - pub blobtype: String, - pub label: Option, - pub function: FileReaderFunction, +pub(crate) struct ReadMetaData { + pub(crate) blobtype: String, + pub(crate) label: Option, + pub(crate) function: FileReaderFunction, } impl ReadMetaData { - pub fn new( + pub(crate) fn new( blobtype: String, label: Option, function: FileReaderFunction, @@ -101,26 +101,26 @@ impl ReadMetaData { } #[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)] -pub struct GenerationId(u32); +pub(crate) struct GenerationId(u32); #[repr(u16)] #[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)] -pub enum FileReaderReadyState { +pub(crate) enum FileReaderReadyState { Empty = FileReaderConstants::EMPTY, Loading = FileReaderConstants::LOADING, Done = FileReaderConstants::DONE, } #[derive(JSTraceable, MallocSizeOf)] -pub enum FileReaderResult { +pub(crate) enum FileReaderResult { ArrayBuffer(#[ignore_malloc_size_of = "mozjs"] Heap), String(DOMString), } -pub struct FileReaderSharedFunctionality; +pub(crate) struct FileReaderSharedFunctionality; impl FileReaderSharedFunctionality { - pub fn dataurl_format(blob_contents: &[u8], blob_type: String) -> DOMString { + pub(crate) fn dataurl_format(blob_contents: &[u8], blob_type: String) -> DOMString { let base64 = base64::engine::general_purpose::STANDARD.encode(blob_contents); let dataurl = if blob_type.is_empty() { @@ -132,7 +132,7 @@ impl FileReaderSharedFunctionality { DOMString::from(dataurl) } - pub fn text_decode( + pub(crate) fn text_decode( blob_contents: &[u8], blob_type: &str, blob_label: &Option, @@ -165,7 +165,7 @@ impl FileReaderSharedFunctionality { } #[dom_struct] -pub struct FileReader { +pub(crate) struct FileReader { eventtarget: EventTarget, ready_state: Cell, error: MutNullableDom, @@ -174,7 +174,7 @@ pub struct FileReader { } impl FileReader { - pub fn new_inherited() -> FileReader { + pub(crate) fn new_inherited() -> FileReader { FileReader { eventtarget: EventTarget::new_inherited(), ready_state: Cell::new(FileReaderReadyState::Empty), @@ -193,7 +193,7 @@ impl FileReader { } //https://w3c.github.io/FileAPI/#dfn-error-steps - pub fn process_read_error( + pub(crate) fn process_read_error( filereader: TrustedFileReader, gen_id: GenerationId, error: DOMErrorName, @@ -227,7 +227,11 @@ impl FileReader { } // https://w3c.github.io/FileAPI/#dfn-readAsText - pub fn process_read_data(filereader: TrustedFileReader, gen_id: GenerationId, can_gc: CanGc) { + pub(crate) fn process_read_data( + filereader: TrustedFileReader, + gen_id: GenerationId, + can_gc: CanGc, + ) { let fr = filereader.root(); macro_rules! return_on_abort( @@ -243,7 +247,7 @@ impl FileReader { } // https://w3c.github.io/FileAPI/#dfn-readAsText - pub fn process_read(filereader: TrustedFileReader, gen_id: GenerationId, can_gc: CanGc) { + pub(crate) fn process_read(filereader: TrustedFileReader, gen_id: GenerationId, can_gc: CanGc) { let fr = filereader.root(); macro_rules! return_on_abort( @@ -259,7 +263,7 @@ impl FileReader { } // https://w3c.github.io/FileAPI/#dfn-readAsText - pub fn process_read_eof( + pub(crate) fn process_read_eof( filereader: TrustedFileReader, gen_id: GenerationId, data: ReadMetaData, diff --git a/components/script/dom/filereadersync.rs b/components/script/dom/filereadersync.rs index fa312532eb9..312b667fcef 100644 --- a/components/script/dom/filereadersync.rs +++ b/components/script/dom/filereadersync.rs @@ -22,12 +22,12 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::{CanGc, JSContext}; #[dom_struct] -pub struct FileReaderSync { +pub(crate) struct FileReaderSync { reflector: Reflector, } impl FileReaderSync { - pub fn new_inherited() -> FileReaderSync { + pub(crate) fn new_inherited() -> FileReaderSync { FileReaderSync { reflector: Reflector::new(), } diff --git a/components/script/dom/focusevent.rs b/components/script/dom/focusevent.rs index 0f9eced513c..a90756918ac 100644 --- a/components/script/dom/focusevent.rs +++ b/components/script/dom/focusevent.rs @@ -22,7 +22,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct FocusEvent { +pub(crate) struct FocusEvent { uievent: UIEvent, related_target: MutNullableDom, } @@ -35,11 +35,11 @@ impl FocusEvent { } } - pub fn new_uninitialized(window: &Window, can_gc: CanGc) -> DomRoot { + pub(crate) fn new_uninitialized(window: &Window, can_gc: CanGc) -> DomRoot { Self::new_uninitialized_with_proto(window, None, can_gc) } - pub fn new_uninitialized_with_proto( + pub(crate) fn new_uninitialized_with_proto( window: &Window, proto: Option, can_gc: CanGc, @@ -48,7 +48,7 @@ impl FocusEvent { } #[allow(clippy::too_many_arguments)] - pub fn new( + pub(crate) fn new( window: &Window, type_: DOMString, can_bubble: EventBubbles, diff --git a/components/script/dom/fontfaceset.rs b/components/script/dom/fontfaceset.rs index ac8cd1baa78..dfaaf553b10 100644 --- a/components/script/dom/fontfaceset.rs +++ b/components/script/dom/fontfaceset.rs @@ -17,21 +17,25 @@ use crate::realms::enter_realm; use crate::script_runtime::CanGc; #[dom_struct] -pub struct FontFaceSet { +pub(crate) struct FontFaceSet { target: EventTarget, #[ignore_malloc_size_of = "Rc"] promise: Rc, } impl FontFaceSet { - pub fn new_inherited(global: &GlobalScope, can_gc: CanGc) -> Self { + pub(crate) fn new_inherited(global: &GlobalScope, can_gc: CanGc) -> Self { FontFaceSet { target: EventTarget::new_inherited(), promise: Promise::new(global, can_gc), } } - pub fn new(global: &GlobalScope, proto: Option, can_gc: CanGc) -> DomRoot { + pub(crate) fn new( + global: &GlobalScope, + proto: Option, + can_gc: CanGc, + ) -> DomRoot { reflect_dom_object_with_proto( Box::new(FontFaceSet::new_inherited(global, can_gc)), global, @@ -40,7 +44,7 @@ impl FontFaceSet { ) } - pub fn fulfill_ready_promise_if_needed(&self) { + pub(crate) fn fulfill_ready_promise_if_needed(&self) { if !self.promise.is_fulfilled() { let _ac = enter_realm(&*self.promise); self.promise.resolve_native(self); diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index bcc0f8156c1..d8c2de5a561 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -24,7 +24,7 @@ use crate::dom::htmlformelement::{FormDatum, FormDatumValue, HTMLFormElement}; use crate::script_runtime::CanGc; #[dom_struct] -pub struct FormData { +pub(crate) struct FormData { reflector_: Reflector, data: DomRefCell, FormDatum)>>, } @@ -45,7 +45,7 @@ impl FormData { } } - pub fn new( + pub(crate) fn new( form_datums: Option>, global: &GlobalScope, can_gc: CanGc, @@ -242,7 +242,7 @@ impl FormData { ) } - pub fn datums(&self) -> Vec { + pub(crate) fn datums(&self) -> Vec { self.data .borrow() .iter() diff --git a/components/script/dom/formdataevent.rs b/components/script/dom/formdataevent.rs index fc1134f0f80..cb3b91dbf5b 100644 --- a/components/script/dom/formdataevent.rs +++ b/components/script/dom/formdataevent.rs @@ -21,13 +21,13 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct FormDataEvent { +pub(crate) struct FormDataEvent { event: Event, form_data: Dom, } impl FormDataEvent { - pub fn new( + pub(crate) fn new( global: &GlobalScope, type_: Atom, can_bubble: EventBubbles, diff --git a/components/script/dom/gainnode.rs b/components/script/dom/gainnode.rs index e8f81904fcc..31184925616 100644 --- a/components/script/dom/gainnode.rs +++ b/components/script/dom/gainnode.rs @@ -25,14 +25,14 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct GainNode { +pub(crate) struct GainNode { node: AudioNode, gain: Dom, } impl GainNode { #[allow(crown::unrooted_must_root)] - pub fn new_inherited( + pub(crate) fn new_inherited( window: &Window, context: &BaseAudioContext, options: &GainOptions, @@ -65,7 +65,7 @@ impl GainNode { }) } - pub fn new( + pub(crate) fn new( window: &Window, context: &BaseAudioContext, options: &GainOptions, diff --git a/components/script/dom/gamepad.rs b/components/script/dom/gamepad.rs index ae3d75f6030..45328e61494 100644 --- a/components/script/dom/gamepad.rs +++ b/components/script/dom/gamepad.rs @@ -33,7 +33,7 @@ const AXIS_TILT_THRESHOLD: f64 = 0.5; const BUTTON_PRESS_THRESHOLD: f64 = 30.0 / 255.0; #[dom_struct] -pub struct Gamepad { +pub(crate) struct Gamepad { reflector_: Reflector, gamepad_id: u32, id: String, @@ -89,7 +89,7 @@ impl Gamepad { } #[allow(clippy::too_many_arguments)] - pub fn new( + pub(crate) fn new( global: &GlobalScope, gamepad_id: u32, id: String, @@ -212,11 +212,11 @@ impl GamepadMethods for Gamepad { #[allow(dead_code)] impl Gamepad { - pub fn gamepad_id(&self) -> u32 { + pub(crate) fn gamepad_id(&self) -> u32 { self.gamepad_id } - pub fn update_connected(&self, connected: bool, has_gesture: bool, can_gc: CanGc) { + pub(crate) fn update_connected(&self, connected: bool, has_gesture: bool, can_gc: CanGc) { if self.connected.get() == connected { return; } @@ -233,19 +233,19 @@ impl Gamepad { } } - pub fn index(&self) -> i32 { + pub(crate) fn index(&self) -> i32 { self.index.get() } - pub fn update_index(&self, index: i32) { + pub(crate) fn update_index(&self, index: i32) { self.index.set(index); } - pub fn update_timestamp(&self, timestamp: f64) { + pub(crate) fn update_timestamp(&self, timestamp: f64) { self.timestamp.set(timestamp); } - pub fn notify_event(&self, event_type: GamepadEventType, can_gc: CanGc) { + pub(crate) fn notify_event(&self, event_type: GamepadEventType, can_gc: CanGc) { let event = GamepadEvent::new_with_type(&self.global(), event_type, self, can_gc); event .upcast::() @@ -268,7 +268,7 @@ impl Gamepad { #[allow(unsafe_code)] /// - pub fn map_and_normalize_axes(&self, axis_index: usize, value: f64) { + pub(crate) fn map_and_normalize_axes(&self, axis_index: usize, value: f64) { // Let normalizedValue be 2 (logicalValue − logicalMinimum) / (logicalMaximum − logicalMinimum) − 1. let numerator = value - self.axis_bounds.0; let denominator = self.axis_bounds.1 - self.axis_bounds.0; @@ -291,7 +291,7 @@ impl Gamepad { } /// - pub fn map_and_normalize_buttons(&self, button_index: usize, value: f64) { + pub(crate) fn map_and_normalize_buttons(&self, button_index: usize, value: f64) { // Let normalizedValue be (logicalValue − logicalMinimum) / (logicalMaximum − logicalMinimum). let numerator = value - self.button_bounds.0; let denominator = self.button_bounds.1 - self.button_bounds.0; @@ -312,22 +312,22 @@ impl Gamepad { } /// - pub fn exposed(&self) -> bool { + pub(crate) fn exposed(&self) -> bool { self.exposed.get() } /// - pub fn set_exposed(&self, exposed: bool) { + pub(crate) fn set_exposed(&self, exposed: bool) { self.exposed.set(exposed); } - pub fn vibration_actuator(&self) -> &GamepadHapticActuator { + pub(crate) fn vibration_actuator(&self) -> &GamepadHapticActuator { &self.vibration_actuator } } /// -pub fn contains_user_gesture(update_type: GamepadUpdateType) -> bool { +pub(crate) fn contains_user_gesture(update_type: GamepadUpdateType) -> bool { match update_type { GamepadUpdateType::Axis(_, value) => value.abs() > AXIS_TILT_THRESHOLD, GamepadUpdateType::Button(_, value) => value > BUTTON_PRESS_THRESHOLD, diff --git a/components/script/dom/gamepadbutton.rs b/components/script/dom/gamepadbutton.rs index 4605983ae6a..7a66654e5e6 100644 --- a/components/script/dom/gamepadbutton.rs +++ b/components/script/dom/gamepadbutton.rs @@ -14,7 +14,7 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::CanGc; #[dom_struct] -pub struct GamepadButton { +pub(crate) struct GamepadButton { reflector_: Reflector, pressed: Cell, touched: Cell, @@ -22,7 +22,7 @@ pub struct GamepadButton { } impl GamepadButton { - pub fn new_inherited(pressed: bool, touched: bool) -> GamepadButton { + pub(crate) fn new_inherited(pressed: bool, touched: bool) -> GamepadButton { Self { reflector_: Reflector::new(), pressed: Cell::new(pressed), @@ -31,7 +31,11 @@ impl GamepadButton { } } - pub fn new(global: &GlobalScope, pressed: bool, touched: bool) -> DomRoot { + pub(crate) fn new( + global: &GlobalScope, + pressed: bool, + touched: bool, + ) -> DomRoot { reflect_dom_object( Box::new(GamepadButton::new_inherited(pressed, touched)), global, @@ -58,7 +62,7 @@ impl GamepadButtonMethods for GamepadButton { } impl GamepadButton { - pub fn update(&self, pressed: bool, touched: bool, value: f64) { + pub(crate) fn update(&self, pressed: bool, touched: bool, value: f64) { self.pressed.set(pressed); self.touched.set(touched); self.value.set(value); diff --git a/components/script/dom/gamepadbuttonlist.rs b/components/script/dom/gamepadbuttonlist.rs index 1d95eecc1a2..caf25661184 100644 --- a/components/script/dom/gamepadbuttonlist.rs +++ b/components/script/dom/gamepadbuttonlist.rs @@ -13,7 +13,7 @@ use crate::script_runtime::CanGc; // https://w3c.github.io/gamepad/#gamepadbutton-interface #[dom_struct] -pub struct GamepadButtonList { +pub(crate) struct GamepadButtonList { reflector_: Reflector, list: Vec>, } @@ -27,7 +27,7 @@ impl GamepadButtonList { } } - pub fn new(global: &GlobalScope, list: &[&GamepadButton]) -> DomRoot { + pub(crate) fn new(global: &GlobalScope, list: &[&GamepadButton]) -> DomRoot { reflect_dom_object( Box::new(GamepadButtonList::new_inherited(list)), global, @@ -58,7 +58,7 @@ impl GamepadButtonListMethods for GamepadButtonList { impl GamepadButtonList { /// Initialize the number of buttons in the "standard" gamepad mapping. /// - pub fn init_buttons(global: &GlobalScope) -> DomRoot { + pub(crate) fn init_buttons(global: &GlobalScope) -> DomRoot { let standard_buttons = &[ GamepadButton::new(global, false, false), // Bottom button in right cluster GamepadButton::new(global, false, false), // Right button in right cluster diff --git a/components/script/dom/gamepadevent.rs b/components/script/dom/gamepadevent.rs index ad835e9f1e5..7b849db3738 100644 --- a/components/script/dom/gamepadevent.rs +++ b/components/script/dom/gamepadevent.rs @@ -21,12 +21,12 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct GamepadEvent { +pub(crate) struct GamepadEvent { event: Event, gamepad: Dom, } -pub enum GamepadEventType { +pub(crate) enum GamepadEventType { Connected, Disconnected, } @@ -39,7 +39,7 @@ impl GamepadEvent { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, type_: Atom, bubbles: bool, @@ -72,7 +72,7 @@ impl GamepadEvent { ev } - pub fn new_with_type( + pub(crate) fn new_with_type( global: &GlobalScope, event_type: GamepadEventType, gamepad: &Gamepad, diff --git a/components/script/dom/gamepadhapticactuator.rs b/components/script/dom/gamepadhapticactuator.rs index ebf45694f45..efd0c370176 100644 --- a/components/script/dom/gamepadhapticactuator.rs +++ b/components/script/dom/gamepadhapticactuator.rs @@ -56,7 +56,7 @@ impl HapticEffectListener { /// #[dom_struct] -pub struct GamepadHapticActuator { +pub(crate) struct GamepadHapticActuator { reflector_: Reflector, gamepad_index: u32, /// @@ -98,7 +98,7 @@ impl GamepadHapticActuator { } } - pub fn new( + pub(crate) fn new( global: &GlobalScope, gamepad_index: u32, supported_haptic_effects: GamepadSupportedHapticEffects, @@ -299,7 +299,7 @@ impl GamepadHapticActuatorMethods for GamepadHapticActuato impl GamepadHapticActuator { /// /// We are in the task queued by the "in-parallel" steps. - pub fn handle_haptic_effect_completed(&self, completed_successfully: bool) { + pub(crate) fn handle_haptic_effect_completed(&self, completed_successfully: bool) { if self.effect_sequence_id.get() != self.sequence_id.get() || !completed_successfully { return; } @@ -312,7 +312,7 @@ impl GamepadHapticActuator { /// /// We are in the task queued by the "in-parallel" steps. - pub fn handle_haptic_effect_stopped(&self, stopped_successfully: bool) { + pub(crate) fn handle_haptic_effect_stopped(&self, stopped_successfully: bool) { if !stopped_successfully { return; } @@ -338,7 +338,7 @@ impl GamepadHapticActuator { } /// - pub fn handle_visibility_change(&self) { + pub(crate) fn handle_visibility_change(&self) { if self.playing_effect_promise.borrow().is_none() { return; } diff --git a/components/script/dom/gamepadpose.rs b/components/script/dom/gamepadpose.rs index 4b6005a93f9..7780f034f15 100644 --- a/components/script/dom/gamepadpose.rs +++ b/components/script/dom/gamepadpose.rs @@ -13,7 +13,7 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::{CanGc, JSContext}; #[dom_struct] -pub struct GamepadPose { +pub(crate) struct GamepadPose { reflector_: Reflector, #[ignore_malloc_size_of = "mozjs"] position: HeapBufferSource, @@ -44,7 +44,7 @@ impl GamepadPose { } } - pub fn new(global: &GlobalScope) -> DomRoot { + pub(crate) fn new(global: &GlobalScope) -> DomRoot { reflect_dom_object( Box::new(GamepadPose::new_inherited()), global, diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 60e768f3dc8..97d31ade46d 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -144,7 +144,7 @@ use crate::timers::{ use crate::unminify::unminified_path; #[derive(JSTraceable)] -pub struct AutoCloseWorker { +pub(crate) struct AutoCloseWorker { /// closing: Arc, /// A handle to join on the worker thread. @@ -189,7 +189,7 @@ impl Drop for AutoCloseWorker { } #[dom_struct] -pub struct GlobalScope { +pub(crate) struct GlobalScope { eventtarget: EventTarget, crypto: MutNullableDom, @@ -408,7 +408,7 @@ enum FileListenerState { #[derive(JSTraceable, MallocSizeOf)] /// A holder of a weak reference for a DOM blob or file. -pub enum BlobTracker { +pub(crate) enum BlobTracker { /// A weak ref to a DOM file. File(WeakRef), /// A weak ref to a DOM blob. @@ -417,7 +417,7 @@ pub enum BlobTracker { #[derive(JSTraceable, MallocSizeOf)] /// The info pertaining to a blob managed by this global. -pub struct BlobInfo { +pub(crate) struct BlobInfo { /// The weak ref to the corresponding DOM object. tracker: BlobTracker, /// The data and logic backing the DOM object. @@ -430,7 +430,7 @@ pub struct BlobInfo { /// State representing whether this global is currently managing blobs. #[derive(JSTraceable, MallocSizeOf)] -pub enum BlobState { +pub(crate) enum BlobState { /// A map of managed blobs. Managed(HashMapTracedValues), /// This global is not managing any blobs at this time. @@ -448,7 +448,7 @@ enum BlobResult { /// Data representing a message-port managed by this global. #[derive(JSTraceable, MallocSizeOf)] #[crown::unrooted_must_root_lint::must_root] -pub struct ManagedMessagePort { +pub(crate) struct ManagedMessagePort { /// The DOM port. dom_port: Dom, /// The logic and data backing the DOM port. @@ -468,7 +468,7 @@ pub struct ManagedMessagePort { /// State representing whether this global is currently managing broadcast channels. #[derive(JSTraceable, MallocSizeOf)] #[crown::unrooted_must_root_lint::must_root] -pub enum BroadcastChannelState { +pub(crate) enum BroadcastChannelState { /// The broadcast-channel router id for this global, and a queue of managed channels. /// Step 9, "sort destinations" /// of @@ -485,7 +485,7 @@ pub enum BroadcastChannelState { /// State representing whether this global is currently managing messageports. #[derive(JSTraceable, MallocSizeOf)] #[crown::unrooted_must_root_lint::must_root] -pub enum MessagePortState { +pub(crate) enum MessagePortState { /// The message-port router id for this global, and a map of managed ports. Managed( #[no_trace] MessagePortRouterId, @@ -701,7 +701,7 @@ impl FileListener { impl GlobalScope { #[allow(clippy::too_many_arguments)] - pub fn new_inherited( + pub(crate) fn new_inherited( pipeline_id: PipelineId, devtools_chan: Option>, mem_profiler_chan: profile_mem::ProfilerChan, @@ -788,7 +788,7 @@ impl GlobalScope { } /// - pub fn get_serviceworker_registration( + pub(crate) fn get_serviceworker_registration( &self, script_url: &ServoUrl, scope: &ServoUrl, @@ -826,7 +826,7 @@ impl GlobalScope { } /// - pub fn get_serviceworker( + pub(crate) fn get_serviceworker( &self, script_url: &ServoUrl, scope: &ServoUrl, @@ -881,7 +881,7 @@ impl GlobalScope { } /// Clean-up DOM related resources - pub fn perform_a_dom_garbage_collection_checkpoint(&self) { + pub(crate) fn perform_a_dom_garbage_collection_checkpoint(&self) { self.perform_a_message_port_garbage_collection_checkpoint(); self.perform_a_blob_garbage_collection_checkpoint(); self.perform_a_broadcast_channel_garbage_collection_checkpoint(); @@ -889,7 +889,7 @@ impl GlobalScope { /// Remove the routers for ports and broadcast-channels. /// Drain the list of workers. - pub fn remove_web_messaging_and_dedicated_workers_infra(&self) { + pub(crate) fn remove_web_messaging_and_dedicated_workers_infra(&self) { self.remove_message_ports_router(); self.remove_broadcast_channel_router(); @@ -932,7 +932,7 @@ impl GlobalScope { } /// - pub fn entangle_ports(&self, port1: MessagePortId, port2: MessagePortId) { + pub(crate) fn entangle_ports(&self, port1: MessagePortId, port2: MessagePortId) { if let MessagePortState::Managed(_id, message_ports) = &mut *self.message_port_state.borrow_mut() { @@ -961,7 +961,7 @@ impl GlobalScope { } /// Note that the entangled port of `port_id` has been removed in another global. - pub fn note_entangled_port_removed(&self, port_id: &MessagePortId) { + pub(crate) fn note_entangled_port_removed(&self, port_id: &MessagePortId) { // Note: currently this is a no-op, // as we only use the `close` method to manage the local lifecyle of a port. // This could be used as part of lifecyle management to determine a port can be GC'ed. @@ -973,7 +973,7 @@ impl GlobalScope { } /// Handle the transfer of a port in the current task. - pub fn mark_port_as_transferred(&self, port_id: &MessagePortId) -> MessagePortImpl { + pub(crate) fn mark_port_as_transferred(&self, port_id: &MessagePortId) -> MessagePortImpl { if let MessagePortState::Managed(_id, message_ports) = &mut *self.message_port_state.borrow_mut() { @@ -997,7 +997,7 @@ impl GlobalScope { } /// - pub fn start_message_port(&self, port_id: &MessagePortId) { + pub(crate) fn start_message_port(&self, port_id: &MessagePortId) { if let MessagePortState::Managed(_id, message_ports) = &mut *self.message_port_state.borrow_mut() { @@ -1029,7 +1029,7 @@ impl GlobalScope { } /// - pub fn close_message_port(&self, port_id: &MessagePortId) { + pub(crate) fn close_message_port(&self, port_id: &MessagePortId) { if let MessagePortState::Managed(_id, message_ports) = &mut *self.message_port_state.borrow_mut() { @@ -1051,7 +1051,7 @@ impl GlobalScope { /// // Steps 6 and 7 - pub fn post_messageport_msg(&self, port_id: MessagePortId, task: PortMessageTask) { + pub(crate) fn post_messageport_msg(&self, port_id: MessagePortId, task: PortMessageTask) { if let MessagePortState::Managed(_id, message_ports) = &mut *self.message_port_state.borrow_mut() { @@ -1092,7 +1092,7 @@ impl GlobalScope { /// /// Step 7 and following steps. - pub fn schedule_broadcast(&self, msg: BroadcastMsg, channel_id: &Uuid) { + pub(crate) fn schedule_broadcast(&self, msg: BroadcastMsg, channel_id: &Uuid) { // First, broadcast locally. self.broadcast_message_event(msg.clone(), Some(channel_id)); @@ -1113,7 +1113,7 @@ impl GlobalScope { /// /// Step 7 and following steps. - pub fn broadcast_message_event(&self, event: BroadcastMsg, channel_id: Option<&Uuid>) { + pub(crate) fn broadcast_message_event(&self, event: BroadcastMsg, channel_id: Option<&Uuid>) { if let BroadcastChannelState::Managed(_, channels) = &*self.broadcast_channel_state.borrow() { let BroadcastMsg { @@ -1200,7 +1200,12 @@ impl GlobalScope { } /// Route the task to be handled by the relevant port. - pub fn route_task_to_port(&self, port_id: MessagePortId, task: PortMessageTask, can_gc: CanGc) { + pub(crate) fn route_task_to_port( + &self, + port_id: MessagePortId, + task: PortMessageTask, + can_gc: CanGc, + ) { let should_dispatch = if let MessagePortState::Managed(_id, message_ports) = &mut *self.message_port_state.borrow_mut() { @@ -1250,7 +1255,7 @@ impl GlobalScope { /// Check all ports that have been transfer-received in the previous task, /// and complete their transfer if they haven't been re-transferred. - pub fn maybe_add_pending_ports(&self) { + pub(crate) fn maybe_add_pending_ports(&self) { if let MessagePortState::Managed(router_id, message_ports) = &mut *self.message_port_state.borrow_mut() { @@ -1285,7 +1290,7 @@ impl GlobalScope { } /// - pub fn perform_a_message_port_garbage_collection_checkpoint(&self) { + pub(crate) fn perform_a_message_port_garbage_collection_checkpoint(&self) { let is_empty = if let MessagePortState::Managed(_id, message_ports) = &mut *self.message_port_state.borrow_mut() { @@ -1319,7 +1324,7 @@ impl GlobalScope { /// Remove broadcast-channels that are closed. /// TODO: Also remove them if they do not have an event-listener. /// see - pub fn perform_a_broadcast_channel_garbage_collection_checkpoint(&self) { + pub(crate) fn perform_a_broadcast_channel_garbage_collection_checkpoint(&self) { let is_empty = if let BroadcastChannelState::Managed(router_id, ref mut channels) = &mut *self.broadcast_channel_state.borrow_mut() { @@ -1348,7 +1353,7 @@ impl GlobalScope { } /// Start tracking a broadcast-channel. - pub fn track_broadcast_channel(&self, dom_channel: &BroadcastChannel) { + pub(crate) fn track_broadcast_channel(&self, dom_channel: &BroadcastChannel) { let mut current_state = self.broadcast_channel_state.borrow_mut(); if let BroadcastChannelState::UnManaged = &*current_state { @@ -1396,7 +1401,11 @@ impl GlobalScope { } /// Start tracking a message-port - pub fn track_message_port(&self, dom_port: &MessagePort, port_impl: Option) { + pub(crate) fn track_message_port( + &self, + dom_port: &MessagePort, + port_impl: Option, + ) { let mut current_state = self.message_port_state.borrow_mut(); if let MessagePortState::UnManaged = &*current_state { @@ -1476,7 +1485,7 @@ impl GlobalScope { /// /// defined at . /// Get the snapshot state and underlying bytes of the blob. - pub fn serialize_blob(&self, blob_id: &BlobId) -> BlobImpl { + pub(crate) fn serialize_blob(&self, blob_id: &BlobId) -> BlobImpl { // Note: we combine the snapshot state and underlying bytes into one call, // which seems spec compliant. // See https://w3c.github.io/FileAPI/#snapshot-state @@ -1505,7 +1514,7 @@ impl GlobalScope { } /// Start tracking a blob - pub fn track_blob(&self, dom_blob: &Blob, blob_impl: BlobImpl) { + pub(crate) fn track_blob(&self, dom_blob: &Blob, blob_impl: BlobImpl) { let blob_id = blob_impl.blob_id(); let blob_info = BlobInfo { @@ -1518,7 +1527,7 @@ impl GlobalScope { } /// Start tracking a file - pub fn track_file(&self, file: &File, blob_impl: BlobImpl) { + pub(crate) fn track_file(&self, file: &File, blob_impl: BlobImpl) { let blob_id = blob_impl.blob_id(); let blob_info = BlobInfo { @@ -1558,7 +1567,7 @@ impl GlobalScope { /// Clean-up all file related resources on document unload. /// - pub fn clean_up_all_file_resources(&self) { + pub(crate) fn clean_up_all_file_resources(&self) { let mut blob_state = self.blob_state.borrow_mut(); if let BlobState::Managed(blobs_map) = &mut *blob_state { blobs_map.drain().for_each(|(_id, blob_info)| { @@ -1582,7 +1591,7 @@ impl GlobalScope { /// Get a slice to the inner data of a Blob, /// In the case of a File-backed blob, this might incur synchronous read and caching. - pub fn get_blob_bytes(&self, blob_id: &BlobId) -> Result, ()> { + pub(crate) fn get_blob_bytes(&self, blob_id: &BlobId) -> Result, ()> { let parent = { let blob_state = self.blob_state.borrow(); if let BlobState::Managed(blobs_map) = &*blob_state { @@ -1702,7 +1711,7 @@ impl GlobalScope { } /// Get a copy of the type_string of a blob. - pub fn get_blob_type_string(&self, blob_id: &BlobId) -> String { + pub(crate) fn get_blob_type_string(&self, blob_id: &BlobId) -> String { let blob_state = self.blob_state.borrow(); if let BlobState::Managed(blobs_map) = &*blob_state { let blob_info = blobs_map @@ -1715,7 +1724,7 @@ impl GlobalScope { } /// - pub fn get_blob_size(&self, blob_id: &BlobId) -> u64 { + pub(crate) fn get_blob_size(&self, blob_id: &BlobId) -> u64 { let blob_state = self.blob_state.borrow(); if let BlobState::Managed(blobs_map) = &*blob_state { let parent = { @@ -1755,7 +1764,7 @@ impl GlobalScope { } } - pub fn get_blob_url_id(&self, blob_id: &BlobId) -> Uuid { + pub(crate) fn get_blob_url_id(&self, blob_id: &BlobId) -> Uuid { let mut blob_state = self.blob_state.borrow_mut(); if let BlobState::Managed(blobs_map) = &mut *blob_state { let parent = { @@ -1842,7 +1851,7 @@ impl GlobalScope { /// 2. File-based: If set_valid, then activate the FileID so it can serve as URL /// Depending on set_valid, the returned FileID can be part of /// valid or invalid Blob URL. - pub fn promote(&self, blob_info: &mut BlobInfo, set_valid: bool) -> Uuid { + pub(crate) fn promote(&self, blob_info: &mut BlobInfo, set_valid: bool) -> Uuid { let mut bytes = vec![]; let global_url = self.get_url(); @@ -1905,7 +1914,7 @@ impl GlobalScope { } /// - pub fn get_blob_stream( + pub(crate) fn get_blob_stream( &self, blob_id: &BlobId, can_gc: CanGc, @@ -1944,7 +1953,12 @@ impl GlobalScope { Ok(stream) } - pub fn read_file_async(&self, id: Uuid, promise: Rc, callback: FileListenerCallback) { + pub(crate) fn read_file_async( + &self, + id: Uuid, + promise: Rc, + callback: FileListenerCallback, + ) { let recv = self.send_msg(id); let trusted_promise = TrustedPromise::new(promise); @@ -1994,13 +2008,13 @@ impl GlobalScope { } } - pub fn permission_state_invocation_results( + pub(crate) fn permission_state_invocation_results( &self, ) -> &DomRefCell> { &self.permission_state_invocation_results } - pub fn track_worker( + pub(crate) fn track_worker( &self, closing: Arc, join_handle: JoinHandle<()>, @@ -2017,11 +2031,11 @@ impl GlobalScope { }); } - pub fn track_event_source(&self, event_source: &EventSource) { + pub(crate) fn track_event_source(&self, event_source: &EventSource) { self.event_source_tracker.track(event_source); } - pub fn close_event_sources(&self) -> bool { + pub(crate) fn close_event_sources(&self) -> bool { let mut canceled_any_fetch = false; self.event_source_tracker .for_each( @@ -2039,13 +2053,16 @@ impl GlobalScope { /// Returns the global scope of the realm that the given DOM object's reflector /// was created in. #[allow(unsafe_code)] - pub fn from_reflector(reflector: &T, _realm: &AlreadyInRealm) -> DomRoot { + pub(crate) fn from_reflector( + reflector: &T, + _realm: &AlreadyInRealm, + ) -> DomRoot { unsafe { GlobalScope::from_object(*reflector.reflector().get_jsobject()) } } /// Returns the global scope of the realm that the given JS object was created in. #[allow(unsafe_code)] - pub unsafe fn from_object(obj: *mut JSObject) -> DomRoot { + pub(crate) unsafe fn from_object(obj: *mut JSObject) -> DomRoot { assert!(!obj.is_null()); let global = GetNonCCWObjectGlobal(obj); global_scope_from_global_static(global) @@ -2053,7 +2070,7 @@ impl GlobalScope { /// Returns the global scope for the given JSContext #[allow(unsafe_code)] - pub unsafe fn from_context(cx: *mut JSContext, _realm: InRealm) -> DomRoot { + pub(crate) unsafe fn from_context(cx: *mut JSContext, _realm: InRealm) -> DomRoot { let global = CurrentGlobalOrNull(cx); assert!(!global.is_null()); global_scope_from_global(global, cx) @@ -2061,14 +2078,14 @@ impl GlobalScope { /// Returns the global scope for the given SafeJSContext #[allow(unsafe_code)] - pub fn from_safe_context(cx: SafeJSContext, realm: InRealm) -> DomRoot { + pub(crate) fn from_safe_context(cx: SafeJSContext, realm: InRealm) -> DomRoot { unsafe { Self::from_context(*cx, realm) } } /// Returns the global object of the realm that the given JS object /// was created in, after unwrapping any wrappers. #[allow(unsafe_code)] - pub unsafe fn from_object_maybe_wrapped( + pub(crate) unsafe fn from_object_maybe_wrapped( mut obj: *mut JSObject, cx: *mut JSContext, ) -> DomRoot { @@ -2079,13 +2096,13 @@ impl GlobalScope { GlobalScope::from_object(obj) } - pub fn add_uncaught_rejection(&self, rejection: HandleObject) { + pub(crate) fn add_uncaught_rejection(&self, rejection: HandleObject) { self.uncaught_rejections .borrow_mut() .push(Heap::boxed(rejection.get())); } - pub fn remove_uncaught_rejection(&self, rejection: HandleObject) { + pub(crate) fn remove_uncaught_rejection(&self, rejection: HandleObject) { let mut uncaught_rejections = self.uncaught_rejections.borrow_mut(); if let Some(index) = uncaught_rejections @@ -2099,17 +2116,17 @@ impl GlobalScope { // `Heap` values must stay boxed, as they need semantics like `Pin` // (that is, they cannot be moved). #[allow(clippy::vec_box)] - pub fn get_uncaught_rejections(&self) -> &DomRefCell>>> { + pub(crate) fn get_uncaught_rejections(&self) -> &DomRefCell>>> { &self.uncaught_rejections } - pub fn add_consumed_rejection(&self, rejection: HandleObject) { + pub(crate) fn add_consumed_rejection(&self, rejection: HandleObject) { self.consumed_rejections .borrow_mut() .push(Heap::boxed(rejection.get())); } - pub fn remove_consumed_rejection(&self, rejection: HandleObject) { + pub(crate) fn remove_consumed_rejection(&self, rejection: HandleObject) { let mut consumed_rejections = self.consumed_rejections.borrow_mut(); if let Some(index) = consumed_rejections @@ -2123,49 +2140,51 @@ impl GlobalScope { // `Heap` values must stay boxed, as they need semantics like `Pin` // (that is, they cannot be moved). #[allow(clippy::vec_box)] - pub fn get_consumed_rejections(&self) -> &DomRefCell>>> { + pub(crate) fn get_consumed_rejections(&self) -> &DomRefCell>>> { &self.consumed_rejections } - pub fn set_module_map(&self, url: ServoUrl, module: ModuleTree) { + pub(crate) fn set_module_map(&self, url: ServoUrl, module: ModuleTree) { self.module_map.borrow_mut().insert(url, Rc::new(module)); } - pub fn get_module_map(&self) -> &DomRefCell>> { + pub(crate) fn get_module_map( + &self, + ) -> &DomRefCell>> { &self.module_map } - pub fn set_inline_module_map(&self, script_id: ScriptId, module: ModuleTree) { + pub(crate) fn set_inline_module_map(&self, script_id: ScriptId, module: ModuleTree) { self.inline_module_map .borrow_mut() .insert(script_id, Rc::new(module)); } - pub fn get_inline_module_map(&self) -> &DomRefCell>> { + pub(crate) fn get_inline_module_map(&self) -> &DomRefCell>> { &self.inline_module_map } #[allow(unsafe_code)] - pub fn get_cx() -> SafeJSContext { + pub(crate) fn get_cx() -> SafeJSContext { let cx = Runtime::get() .expect("Can't obtain context after runtime shutdown") .as_ptr(); unsafe { SafeJSContext::from_ptr(cx) } } - pub fn crypto(&self) -> DomRoot { + pub(crate) fn crypto(&self) -> DomRoot { self.crypto.or_init(|| Crypto::new(self)) } - pub fn live_devtools_updates(&self) -> bool { + pub(crate) fn live_devtools_updates(&self) -> bool { self.devtools_wants_updates.get() } - pub fn set_devtools_wants_updates(&self, value: bool) { + pub(crate) fn set_devtools_wants_updates(&self, value: bool) { self.devtools_wants_updates.set(value); } - pub fn time(&self, label: DOMString) -> Result<(), ()> { + pub(crate) fn time(&self, label: DOMString) -> Result<(), ()> { let mut timers = self.console_timers.borrow_mut(); if timers.len() >= 10000 { return Err(()); @@ -2182,7 +2201,7 @@ impl GlobalScope { /// Computes the delta time since a label has been created /// /// Returns an error if the label does not exist. - pub fn time_log(&self, label: &str) -> Result { + pub(crate) fn time_log(&self, label: &str) -> Result { self.console_timers .borrow() .get(label) @@ -2194,7 +2213,7 @@ impl GlobalScope { /// tracking the label. /// /// Returns an error if the label does not exist. - pub fn time_end(&self, label: &str) -> Result { + pub(crate) fn time_end(&self, label: &str) -> Result { self.console_timers .borrow_mut() .remove(label) @@ -2204,11 +2223,11 @@ impl GlobalScope { /// Get an `&IpcSender` to send messages /// to the devtools thread when available. - pub fn devtools_chan(&self) -> Option<&IpcSender> { + pub(crate) fn devtools_chan(&self) -> Option<&IpcSender> { self.devtools_chan.as_ref() } - pub fn issue_page_warning(&self, warning: &str) { + pub(crate) fn issue_page_warning(&self, warning: &str) { if let Some(ref chan) = self.devtools_chan { let _ = chan.send(ScriptToDevtoolsControlMsg::ReportPageError( self.pipeline_id, @@ -2235,44 +2254,44 @@ impl GlobalScope { } /// Get a sender to the memory profiler thread. - pub fn mem_profiler_chan(&self) -> &profile_mem::ProfilerChan { + pub(crate) fn mem_profiler_chan(&self) -> &profile_mem::ProfilerChan { &self.mem_profiler_chan } /// Get a sender to the time profiler thread. - pub fn time_profiler_chan(&self) -> &profile_time::ProfilerChan { + pub(crate) fn time_profiler_chan(&self) -> &profile_time::ProfilerChan { &self.time_profiler_chan } /// Get a sender to the constellation thread. - pub fn script_to_constellation_chan(&self) -> &ScriptToConstellationChan { + pub(crate) fn script_to_constellation_chan(&self) -> &ScriptToConstellationChan { &self.script_to_constellation_chan } - pub fn send_to_embedder(&self, msg: EmbedderMsg) { + pub(crate) fn send_to_embedder(&self, msg: EmbedderMsg) { self.send_to_constellation(ScriptMsg::ForwardToEmbedder(msg)); } - pub fn send_to_constellation(&self, msg: ScriptMsg) { + pub(crate) fn send_to_constellation(&self, msg: ScriptMsg) { self.script_to_constellation_chan().send(msg).unwrap(); } /// Get the `PipelineId` for this global scope. - pub fn pipeline_id(&self) -> PipelineId { + pub(crate) fn pipeline_id(&self) -> PipelineId { self.pipeline_id } /// Get the origin for this global scope - pub fn origin(&self) -> &MutableOrigin { + pub(crate) fn origin(&self) -> &MutableOrigin { &self.origin } /// Get the creation_url for this global scope - pub fn creation_url(&self) -> &Option { + pub(crate) fn creation_url(&self) -> &Option { &self.creation_url } - pub fn image_cache(&self) -> Arc { + pub(crate) fn image_cache(&self) -> Arc { if let Some(window) = self.downcast::() { return window.image_cache(); } @@ -2296,7 +2315,7 @@ impl GlobalScope { } /// - pub fn policy_container(&self) -> PolicyContainer { + pub(crate) fn policy_container(&self) -> PolicyContainer { if let Some(window) = self.downcast::() { return window.Document().policy_container().to_owned(); } @@ -2308,7 +2327,7 @@ impl GlobalScope { /// Get the [base url](https://html.spec.whatwg.org/multipage/#api-base-url) /// for this global scope. - pub fn api_base_url(&self) -> ServoUrl { + pub(crate) fn api_base_url(&self) -> ServoUrl { if let Some(window) = self.downcast::() { // https://html.spec.whatwg.org/multipage/#script-settings-for-browsing-contexts:api-base-url return window.Document().base_url(); @@ -2325,7 +2344,7 @@ impl GlobalScope { } /// Get the URL for this global scope. - pub fn get_url(&self) -> ServoUrl { + pub(crate) fn get_url(&self) -> ServoUrl { if let Some(window) = self.downcast::() { return window.get_url(); } @@ -2340,7 +2359,7 @@ impl GlobalScope { } /// Get the Referrer Policy for this global scope. - pub fn get_referrer_policy(&self) -> ReferrerPolicy { + pub(crate) fn get_referrer_policy(&self) -> ReferrerPolicy { if let Some(window) = self.downcast::() { let document = window.Document(); @@ -2355,7 +2374,7 @@ impl GlobalScope { } /// Determine the Referrer for a request whose Referrer is "client" - pub fn get_referrer(&self) -> Referrer { + pub(crate) fn get_referrer(&self) -> Referrer { // Step 3 of https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer if let Some(window) = self.downcast::() { // Substep 3.1 @@ -2396,12 +2415,12 @@ impl GlobalScope { } /// Extract a `Window`, panic if the global object is not a `Window`. - pub fn as_window(&self) -> &Window { + pub(crate) fn as_window(&self) -> &Window { self.downcast::().expect("expected a Window scope") } /// - pub fn report_an_error(&self, error_info: ErrorInfo, value: HandleValue, can_gc: CanGc) { + pub(crate) fn report_an_error(&self, error_info: ErrorInfo, value: HandleValue, can_gc: CanGc) { // Step 1. if self.in_error_reporting_mode.get() { return; @@ -2467,12 +2486,12 @@ impl GlobalScope { } /// Get the `&ResourceThreads` for this global scope. - pub fn resource_threads(&self) -> &ResourceThreads { + pub(crate) fn resource_threads(&self) -> &ResourceThreads { &self.resource_threads } /// Get the `CoreResourceThread` for this global scope. - pub fn core_resource_thread(&self) -> CoreResourceThread { + pub(crate) fn core_resource_thread(&self) -> CoreResourceThread { self.resource_threads().sender() } @@ -2509,7 +2528,7 @@ impl GlobalScope { } /// Evaluate JS code on this global scope. - pub fn evaluate_js_on_global_with_result( + pub(crate) fn evaluate_js_on_global_with_result( &self, code: &str, rval: MutableHandleValue, @@ -2532,7 +2551,7 @@ impl GlobalScope { /// Evaluate a JS script on this global scope. #[allow(unsafe_code)] #[allow(clippy::too_many_arguments)] - pub fn evaluate_script_on_global_with_result( + pub(crate) fn evaluate_script_on_global_with_result( &self, code: &SourceCode, filename: &str, @@ -2621,7 +2640,7 @@ impl GlobalScope { } /// - pub fn schedule_callback( + pub(crate) fn schedule_callback( &self, callback: OneshotTimerCallback, duration: Duration, @@ -2630,12 +2649,12 @@ impl GlobalScope { .schedule_callback(callback, duration, self.timer_source()) } - pub fn unschedule_callback(&self, handle: OneshotTimerHandle) { + pub(crate) fn unschedule_callback(&self, handle: OneshotTimerHandle) { self.timers().unschedule_callback(handle); } /// - pub fn set_timeout_or_interval( + pub(crate) fn set_timeout_or_interval( &self, callback: TimerCallback, arguments: Vec, @@ -2652,11 +2671,11 @@ impl GlobalScope { ) } - pub fn clear_timeout_or_interval(&self, handle: i32) { + pub(crate) fn clear_timeout_or_interval(&self, handle: i32) { self.timers().clear_timeout_or_interval(self, handle); } - pub fn queue_function_as_microtask(&self, callback: Rc) { + pub(crate) fn queue_function_as_microtask(&self, callback: Rc) { self.enqueue_microtask(Microtask::User(UserMicrotask { callback, pipeline: self.pipeline_id(), @@ -2664,7 +2683,7 @@ impl GlobalScope { } #[allow(unsafe_code)] - pub fn is_js_evaluation_allowed(&self, cx: SafeJSContext) -> bool { + pub(crate) fn is_js_evaluation_allowed(&self, cx: SafeJSContext) -> bool { let Some(csp_list) = self.get_csp_list() else { return true; }; @@ -2694,7 +2713,7 @@ impl GlobalScope { is_js_evaluation_allowed } - pub fn create_image_bitmap( + pub(crate) fn create_image_bitmap( &self, image: ImageBitmapSource, options: &ImageBitmapOptions, @@ -2759,23 +2778,23 @@ impl GlobalScope { } } - pub fn fire_timer(&self, handle: TimerEventId, can_gc: CanGc) { + pub(crate) fn fire_timer(&self, handle: TimerEventId, can_gc: CanGc) { self.timers().fire_timer(handle, self, can_gc); } - pub fn resume(&self) { + pub(crate) fn resume(&self) { self.timers().resume(); } - pub fn suspend(&self) { + pub(crate) fn suspend(&self) { self.timers().suspend(); } - pub fn slow_down_timers(&self) { + pub(crate) fn slow_down_timers(&self) { self.timers().slow_down(); } - pub fn speed_up_timers(&self) { + pub(crate) fn speed_up_timers(&self) { self.timers().speed_up(); } @@ -2791,7 +2810,7 @@ impl GlobalScope { /// Returns a boolean indicating whether the event-loop /// where this global is running on can continue running JS. - pub fn can_continue_running(&self) -> bool { + pub(crate) fn can_continue_running(&self) -> bool { if self.is::() { return ScriptThread::can_continue_running(); } @@ -2804,7 +2823,7 @@ impl GlobalScope { } /// Perform a microtask checkpoint. - pub fn perform_a_microtask_checkpoint(&self, can_gc: CanGc) { + pub(crate) fn perform_a_microtask_checkpoint(&self, can_gc: CanGc) { // Only perform the checkpoint if we're not shutting down. if self.can_continue_running() { self.microtask_queue.checkpoint( @@ -2817,7 +2836,7 @@ impl GlobalScope { } /// Enqueue a microtask for subsequent execution. - pub fn enqueue_microtask(&self, job: Microtask) { + pub(crate) fn enqueue_microtask(&self, job: Microtask) { self.microtask_queue.enqueue(job, GlobalScope::get_cx()); } @@ -2835,14 +2854,14 @@ impl GlobalScope { } /// Returns the microtask queue of this global. - pub fn microtask_queue(&self) -> &Rc { + pub(crate) fn microtask_queue(&self) -> &Rc { &self.microtask_queue } /// Process a single event as if it were the next event /// in the queue for the event-loop where this global scope is running on. /// Returns a boolean indicating whether further events should be processed. - pub fn process_event(&self, msg: CommonScriptMsg) -> bool { + pub(crate) fn process_event(&self, msg: CommonScriptMsg) -> bool { if self.is::() { return ScriptThread::process_event(msg); } @@ -2852,7 +2871,7 @@ impl GlobalScope { unreachable!(); } - pub fn runtime_handle(&self) -> ParentRuntime { + pub(crate) fn runtime_handle(&self) -> ParentRuntime { if self.is::() { ScriptThread::runtime_handle() } else if let Some(worker) = self.downcast::() { @@ -2866,7 +2885,7 @@ impl GlobalScope { /// /// ["current"]: https://html.spec.whatwg.org/multipage/#current #[allow(unsafe_code)] - pub fn current() -> Option> { + pub(crate) fn current() -> Option> { let cx = Runtime::get()?; unsafe { let global = CurrentGlobalOrNull(cx.as_ptr()); @@ -2881,18 +2900,18 @@ impl GlobalScope { /// Returns the ["entry"] global object. /// /// ["entry"]: https://html.spec.whatwg.org/multipage/#entry - pub fn entry() -> DomRoot { + pub(crate) fn entry() -> DomRoot { entry_global() } /// Returns the ["incumbent"] global object. /// /// ["incumbent"]: https://html.spec.whatwg.org/multipage/#incumbent - pub fn incumbent() -> Option> { + pub(crate) fn incumbent() -> Option> { incumbent_global() } - pub fn performance(&self) -> DomRoot { + pub(crate) fn performance(&self) -> DomRoot { if let Some(window) = self.downcast::() { return window.Performance(); } @@ -2903,7 +2922,11 @@ impl GlobalScope { } /// - pub fn supported_performance_entry_types(&self, cx: SafeJSContext, retval: MutableHandleValue) { + pub(crate) fn supported_performance_entry_types( + &self, + cx: SafeJSContext, + retval: MutableHandleValue, + ) { self.frozen_supported_performance_entry_types.get_or_init( || { VALID_ENTRY_TYPES @@ -2916,23 +2939,23 @@ impl GlobalScope { ); } - pub fn is_headless(&self) -> bool { + pub(crate) fn is_headless(&self) -> bool { self.is_headless } - pub fn get_user_agent(&self) -> Cow<'static, str> { + pub(crate) fn get_user_agent(&self) -> Cow<'static, str> { self.user_agent.clone() } - pub fn get_https_state(&self) -> HttpsState { + pub(crate) fn get_https_state(&self) -> HttpsState { self.https_state.get() } - pub fn set_https_state(&self, https_state: HttpsState) { + pub(crate) fn set_https_state(&self, https_state: HttpsState) { self.https_state.set(https_state); } - pub fn is_secure_context(&self) -> bool { + pub(crate) fn is_secure_context(&self) -> bool { if Some(false) == self.inherited_secure_context { return false; } @@ -2946,7 +2969,7 @@ impl GlobalScope { } /// - pub fn get_csp_list(&self) -> Option { + pub(crate) fn get_csp_list(&self) -> Option { if self.downcast::().is_some() { return self.policy_container().csp_list; } @@ -2954,7 +2977,7 @@ impl GlobalScope { None } - pub fn status_code(&self) -> Option { + pub(crate) fn status_code(&self) -> Option { if let Some(window) = self.downcast::() { return window.Document().status_code(); } @@ -2962,19 +2985,19 @@ impl GlobalScope { } #[cfg(feature = "webgpu")] - pub fn wgpu_id_hub(&self) -> Arc { + pub(crate) fn wgpu_id_hub(&self) -> Arc { self.gpu_id_hub.clone() } #[cfg(feature = "webgpu")] - pub fn add_gpu_device(&self, device: &GPUDevice) { + pub(crate) fn add_gpu_device(&self, device: &GPUDevice) { self.gpu_devices .borrow_mut() .insert(device.id(), WeakRef::new(device)); } #[cfg(feature = "webgpu")] - pub fn remove_gpu_device(&self, device: WebGPUDevice) { + pub(crate) fn remove_gpu_device(&self, device: WebGPUDevice) { let device = self .gpu_devices .borrow_mut() @@ -2984,7 +3007,12 @@ impl GlobalScope { } #[cfg(feature = "webgpu")] - pub fn gpu_device_lost(&self, device: WebGPUDevice, reason: DeviceLostReason, msg: String) { + pub(crate) fn gpu_device_lost( + &self, + device: WebGPUDevice, + reason: DeviceLostReason, + msg: String, + ) { let reason = match reason { DeviceLostReason::Unknown => GPUDeviceLostReason::Unknown, DeviceLostReason::Destroyed => GPUDeviceLostReason::Destroyed, @@ -3002,7 +3030,7 @@ impl GlobalScope { } #[cfg(feature = "webgpu")] - pub fn handle_uncaptured_gpu_error( + pub(crate) fn handle_uncaptured_gpu_error( &self, device: WebGPUDevice, error: webgpu::Error, @@ -3020,7 +3048,7 @@ impl GlobalScope { } } - pub fn handle_gamepad_event(&self, gamepad_event: GamepadEvent) { + pub(crate) fn handle_gamepad_event(&self, gamepad_event: GamepadEvent) { match gamepad_event { GamepadEvent::Connected(index, name, bounds, supported_haptic_effects) => { self.handle_gamepad_connect( @@ -3080,7 +3108,7 @@ impl GlobalScope { } /// - pub fn handle_gamepad_disconnect(&self, index: usize) { + pub(crate) fn handle_gamepad_disconnect(&self, index: usize) { let this = Trusted::new(self); self.task_manager() .gamepad_task_source() @@ -3099,7 +3127,11 @@ impl GlobalScope { } /// - pub fn receive_new_gamepad_button_or_axis(&self, index: usize, update_type: GamepadUpdateType) { + pub(crate) fn receive_new_gamepad_button_or_axis( + &self, + index: usize, + update_type: GamepadUpdateType, + ) { let this = Trusted::new(self); // @@ -3235,7 +3267,7 @@ impl GlobalScope { ); } - pub fn unminified_js_dir(&self) -> Option { + pub(crate) fn unminified_js_dir(&self) -> Option { self.unminified_js_dir.clone() } diff --git a/components/script/dom/gpucanvascontext.rs b/components/script/dom/gpucanvascontext.rs index 42848825adf..da59058fde7 100644 --- a/components/script/dom/gpucanvascontext.rs +++ b/components/script/dom/gpucanvascontext.rs @@ -13,7 +13,7 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::htmlcanvaselement::{HTMLCanvasElement, LayoutCanvasRenderingContextHelpers}; #[dom_struct] -pub struct GPUCanvasContext { +pub(crate) struct GPUCanvasContext { reflector_: Reflector, } @@ -23,7 +23,7 @@ impl GPUCanvasContext { unimplemented!() } - pub fn new(_global: &GlobalScope, _canvas: &HTMLCanvasElement) -> DomRoot { + pub(crate) fn new(_global: &GlobalScope, _canvas: &HTMLCanvasElement) -> DomRoot { unimplemented!() } } diff --git a/components/script/dom/hashchangeevent.rs b/components/script/dom/hashchangeevent.rs index 001eb6497cf..b8ddd7e8306 100644 --- a/components/script/dom/hashchangeevent.rs +++ b/components/script/dom/hashchangeevent.rs @@ -20,7 +20,7 @@ use crate::script_runtime::CanGc; // https://html.spec.whatwg.org/multipage/#hashchangeevent #[dom_struct] -pub struct HashChangeEvent { +pub(crate) struct HashChangeEvent { event: Event, old_url: String, new_url: String, @@ -35,7 +35,7 @@ impl HashChangeEvent { } } - pub fn new_uninitialized(window: &Window, can_gc: CanGc) -> DomRoot { + pub(crate) fn new_uninitialized(window: &Window, can_gc: CanGc) -> DomRoot { Self::new_uninitialized_with_proto(window, None, can_gc) } @@ -52,7 +52,7 @@ impl HashChangeEvent { ) } - pub fn new( + pub(crate) fn new( window: &Window, type_: Atom, bubbles: bool, diff --git a/components/script/dom/headers.rs b/components/script/dom/headers.rs index 65e82393274..7024f7b8cb5 100644 --- a/components/script/dom/headers.rs +++ b/components/script/dom/headers.rs @@ -25,7 +25,7 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::CanGc; #[dom_struct] -pub struct Headers { +pub(crate) struct Headers { reflector_: Reflector, guard: Cell, #[ignore_malloc_size_of = "Defined in hyper"] @@ -35,7 +35,7 @@ pub struct Headers { // https://fetch.spec.whatwg.org/#concept-headers-guard #[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)] -pub enum Guard { +pub(crate) enum Guard { Immutable, Request, RequestNoCors, @@ -44,7 +44,7 @@ pub enum Guard { } impl Headers { - pub fn new_inherited() -> Headers { + pub(crate) fn new_inherited() -> Headers { Headers { reflector_: Reflector::new(), guard: Cell::new(Guard::None), @@ -52,7 +52,7 @@ impl Headers { } } - pub fn new(global: &GlobalScope, can_gc: CanGc) -> DomRoot { + pub(crate) fn new(global: &GlobalScope, can_gc: CanGc) -> DomRoot { Self::new_with_proto(global, None, can_gc) } @@ -250,7 +250,7 @@ impl HeadersMethods for Headers { } impl Headers { - pub fn copy_from_headers(&self, headers: DomRoot) -> ErrorResult { + pub(crate) fn copy_from_headers(&self, headers: DomRoot) -> ErrorResult { for (name, value) in headers.header_list.borrow().iter() { self.Append( ByteString::new(Vec::from(name.as_str())), @@ -261,7 +261,7 @@ impl Headers { } // https://fetch.spec.whatwg.org/#concept-headers-fill - pub fn fill(&self, filler: Option) -> ErrorResult { + pub(crate) fn fill(&self, filler: Option) -> ErrorResult { match filler { Some(HeadersInit::ByteStringSequenceSequence(v)) => { for mut seq in v { @@ -287,41 +287,41 @@ impl Headers { } } - pub fn for_request(global: &GlobalScope, can_gc: CanGc) -> DomRoot { + pub(crate) fn for_request(global: &GlobalScope, can_gc: CanGc) -> DomRoot { let headers_for_request = Headers::new(global, can_gc); headers_for_request.guard.set(Guard::Request); headers_for_request } - pub fn for_response(global: &GlobalScope, can_gc: CanGc) -> DomRoot { + pub(crate) fn for_response(global: &GlobalScope, can_gc: CanGc) -> DomRoot { let headers_for_response = Headers::new(global, can_gc); headers_for_response.guard.set(Guard::Response); headers_for_response } - pub fn set_guard(&self, new_guard: Guard) { + pub(crate) fn set_guard(&self, new_guard: Guard) { self.guard.set(new_guard) } - pub fn get_guard(&self) -> Guard { + pub(crate) fn get_guard(&self) -> Guard { self.guard.get() } - pub fn set_headers(&self, hyper_headers: HyperHeaders) { + pub(crate) fn set_headers(&self, hyper_headers: HyperHeaders) { *self.header_list.borrow_mut() = hyper_headers; } - pub fn get_headers_list(&self) -> HyperHeaders { + pub(crate) fn get_headers_list(&self) -> HyperHeaders { self.header_list.borrow_mut().clone() } // https://fetch.spec.whatwg.org/#concept-header-extract-mime-type - pub fn extract_mime_type(&self) -> Vec { + pub(crate) fn extract_mime_type(&self) -> Vec { extract_mime_type(&self.header_list.borrow()).unwrap_or_default() } // https://fetch.spec.whatwg.org/#concept-header-list-sort-and-combine - pub fn sort_and_combine(&self) -> Vec<(String, Vec)> { + pub(crate) fn sort_and_combine(&self) -> Vec<(String, Vec)> { let borrowed_header_list = self.header_list.borrow(); let mut header_vec = vec![]; @@ -341,7 +341,7 @@ impl Headers { } // https://fetch.spec.whatwg.org/#ref-for-privileged-no-cors-request-header-name - pub fn remove_privileged_no_cors_request_headers(&self) { + pub(crate) fn remove_privileged_no_cors_request_headers(&self) { // https://fetch.spec.whatwg.org/#privileged-no-cors-request-header-name self.header_list.borrow_mut().remove("range"); } @@ -373,7 +373,7 @@ impl Iterable for Headers { /// before calling is not necessary /// /// -pub fn is_forbidden_request_header(name: &str, value: &[u8]) -> bool { +pub(crate) fn is_forbidden_request_header(name: &str, value: &[u8]) -> bool { let forbidden_header_names = [ "accept-charset", "accept-encoding", @@ -555,12 +555,12 @@ fn is_legal_header_value(value: &ByteString) -> bool { } // https://tools.ietf.org/html/rfc5234#appendix-B.1 -pub fn is_vchar(x: u8) -> bool { +pub(crate) fn is_vchar(x: u8) -> bool { matches!(x, 0x21..=0x7E) } // http://tools.ietf.org/html/rfc7230#section-3.2.6 -pub fn is_obs_text(x: u8) -> bool { +pub(crate) fn is_obs_text(x: u8) -> bool { matches!(x, 0x80..=0xFF) } @@ -568,7 +568,7 @@ pub fn is_obs_text(x: u8) -> bool { // This function uses data_url::Mime to parse the MIME Type because // mime::Mime does not provide a parser following the Fetch spec // see https://github.com/hyperium/mime/issues/106 -pub fn extract_mime_type(headers: &HyperHeaders) -> Option> { +pub(crate) fn extract_mime_type(headers: &HyperHeaders) -> Option> { let mut charset: Option = None; let mut essence: String = "".to_string(); let mut mime_type: Option = None; diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 7ca64bde6f5..ff56442af86 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -40,7 +40,7 @@ enum PushOrReplace { /// #[dom_struct] -pub struct History { +pub(crate) struct History { reflector_: Reflector, window: Dom, #[ignore_malloc_size_of = "mozjs"] @@ -50,7 +50,7 @@ pub struct History { } impl History { - pub fn new_inherited(window: &Window) -> History { + pub(crate) fn new_inherited(window: &Window) -> History { let state = Heap::default(); state.set(NullValue()); History { @@ -61,7 +61,7 @@ impl History { } } - pub fn new(window: &Window) -> DomRoot { + pub(crate) fn new(window: &Window) -> DomRoot { reflect_dom_object( Box::new(History::new_inherited(window)), window, @@ -87,7 +87,12 @@ impl History { /// /// Steps 5-16 #[allow(unsafe_code)] - pub fn activate_state(&self, state_id: Option, url: ServoUrl, can_gc: CanGc) { + pub(crate) fn activate_state( + &self, + state_id: Option, + url: ServoUrl, + can_gc: CanGc, + ) { // Steps 5 let document = self.window.Document(); let old_url = document.url().clone(); @@ -165,7 +170,7 @@ impl History { } } - pub fn remove_states(&self, states: Vec) { + pub(crate) fn remove_states(&self, states: Vec) { let _ = self .window .as_global_scope() diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index 6c15ff4bc23..b3e5563bdd4 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -37,7 +37,7 @@ use crate::links::{follow_hyperlink, LinkRelations}; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLAnchorElement { +pub(crate) struct HTMLAnchorElement { htmlelement: HTMLElement, rel_list: MutNullableDom, @@ -62,7 +62,7 @@ impl HTMLAnchorElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs index 1523ae285d8..b8b668f94e0 100644 --- a/components/script/dom/htmlareaelement.rs +++ b/components/script/dom/htmlareaelement.rs @@ -205,7 +205,7 @@ impl Area { } } - pub fn absolute_coords(&self, p: Point2D) -> Area { + pub(crate) fn absolute_coords(&self, p: Point2D) -> Area { match *self { Area::Rectangle { top_left, @@ -237,7 +237,7 @@ impl Area { } #[dom_struct] -pub struct HTMLAreaElement { +pub(crate) struct HTMLAreaElement { htmlelement: HTMLElement, rel_list: MutNullableDom, @@ -259,7 +259,7 @@ impl HTMLAreaElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, @@ -274,7 +274,7 @@ impl HTMLAreaElement { ) } - pub fn get_shape_from_coords(&self) -> Option { + pub(crate) fn get_shape_from_coords(&self) -> Option { let elem = self.upcast::(); let shape = elem.get_string_attribute(&"shape".into()); let shp: Shape = match_ignore_ascii_case! { &shape, diff --git a/components/script/dom/htmlaudioelement.rs b/components/script/dom/htmlaudioelement.rs index 288782550c2..44258d73f66 100644 --- a/components/script/dom/htmlaudioelement.rs +++ b/components/script/dom/htmlaudioelement.rs @@ -21,7 +21,7 @@ use crate::dom::window::Window; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLAudioElement { +pub(crate) struct HTMLAudioElement { htmlmediaelement: HTMLMediaElement, } @@ -37,7 +37,7 @@ impl HTMLAudioElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, diff --git a/components/script/dom/htmlbaseelement.rs b/components/script/dom/htmlbaseelement.rs index 3af35ab3e45..24957bd1e94 100644 --- a/components/script/dom/htmlbaseelement.rs +++ b/components/script/dom/htmlbaseelement.rs @@ -20,7 +20,7 @@ use crate::dom::virtualmethods::VirtualMethods; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLBaseElement { +pub(crate) struct HTMLBaseElement { htmlelement: HTMLElement, } @@ -36,7 +36,7 @@ impl HTMLBaseElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, @@ -52,7 +52,7 @@ impl HTMLBaseElement { } /// - pub fn frozen_base_url(&self) -> ServoUrl { + pub(crate) fn frozen_base_url(&self) -> ServoUrl { let href = self .upcast::() .get_attribute(&ns!(), &local_name!("href")) @@ -68,7 +68,7 @@ impl HTMLBaseElement { /// Update the cached base element in response to binding or unbinding from /// a tree. - pub fn bind_unbind(&self, tree_in_doc: bool) { + pub(crate) fn bind_unbind(&self, tree_in_doc: bool) { if !tree_in_doc || self.upcast::().containing_shadow_root().is_some() { return; } diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index 93a9ad0d73f..3a15d4c3afa 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -25,7 +25,7 @@ use crate::dom::virtualmethods::VirtualMethods; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLBodyElement { +pub(crate) struct HTMLBodyElement { htmlelement: HTMLElement, } @@ -41,7 +41,7 @@ impl HTMLBodyElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, @@ -57,7 +57,7 @@ impl HTMLBodyElement { } /// - pub fn is_the_html_body_element(&self) -> bool { + pub(crate) fn is_the_html_body_element(&self) -> bool { let self_node = self.upcast::(); let root_elem = self.upcast::().root_element(); let root_node = root_elem.upcast::(); @@ -96,7 +96,7 @@ impl HTMLBodyElementMethods for HTMLBodyElement { window_event_handlers!(ForwardToWindow); } -pub trait HTMLBodyElementLayoutHelpers { +pub(crate) trait HTMLBodyElementLayoutHelpers { fn get_background_color(self) -> Option; fn get_color(self) -> Option; fn get_background(self) -> Option; diff --git a/components/script/dom/htmlbrelement.rs b/components/script/dom/htmlbrelement.rs index 7f968c27574..4f299c832c7 100644 --- a/components/script/dom/htmlbrelement.rs +++ b/components/script/dom/htmlbrelement.rs @@ -13,7 +13,7 @@ use crate::dom::node::Node; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLBRElement { +pub(crate) struct HTMLBRElement { htmlelement: HTMLElement, } @@ -29,7 +29,7 @@ impl HTMLBRElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index 793a6a212da..62bd6a964de 100644 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -41,7 +41,7 @@ enum ButtonType { } #[dom_struct] -pub struct HTMLButtonElement { +pub(crate) struct HTMLButtonElement { htmlelement: HTMLElement, button_type: Cell, form_owner: MutNullableDom, @@ -70,7 +70,7 @@ impl HTMLButtonElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, @@ -88,7 +88,7 @@ impl HTMLButtonElement { } #[inline] - pub fn is_submit_button(&self) -> bool { + pub(crate) fn is_submit_button(&self) -> bool { self.button_type.get() == ButtonType::Submit } } @@ -207,7 +207,7 @@ impl HTMLButtonElementMethods for HTMLButtonElement { impl HTMLButtonElement { /// /// Steps range from 3.1 to 3.7 (specific to HTMLButtonElement) - pub fn form_datum(&self, submitter: Option) -> Option { + pub(crate) fn form_datum(&self, submitter: Option) -> Option { // Step 3.1: disabled state check is in get_unclean_dataset // Step 3.1: only run steps if this is the submitter diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index e61358325ae..5e30743aeba 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -62,7 +62,7 @@ const DEFAULT_HEIGHT: u32 = 150; #[crown::unrooted_must_root_lint::must_root] #[derive(Clone, JSTraceable, MallocSizeOf)] -pub enum CanvasContext { +pub(crate) enum CanvasContext { Context2d(Dom), WebGL(Dom), WebGL2(Dom), @@ -71,7 +71,7 @@ pub enum CanvasContext { } #[dom_struct] -pub struct HTMLCanvasElement { +pub(crate) struct HTMLCanvasElement { htmlelement: HTMLElement, context: DomRefCell>, } @@ -89,7 +89,7 @@ impl HTMLCanvasElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, @@ -121,11 +121,11 @@ impl HTMLCanvasElement { } } - pub fn get_size(&self) -> Size2D { + pub(crate) fn get_size(&self) -> Size2D { Size2D::new(self.Width(), self.Height()) } - pub fn origin_is_clean(&self) -> bool { + pub(crate) fn origin_is_clean(&self) -> bool { match *self.context.borrow() { Some(CanvasContext::Context2d(ref context)) => context.origin_is_clean(), _ => true, @@ -133,11 +133,11 @@ impl HTMLCanvasElement { } } -pub trait LayoutCanvasRenderingContextHelpers { +pub(crate) trait LayoutCanvasRenderingContextHelpers { fn canvas_data_source(self) -> HTMLCanvasDataSource; } -pub trait LayoutHTMLCanvasElementHelpers { +pub(crate) trait LayoutHTMLCanvasElementHelpers { fn data(self) -> HTMLCanvasData; fn get_canvas_id_for_layout(self) -> CanvasId; } @@ -187,7 +187,7 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> { } impl HTMLCanvasElement { - pub fn context(&self) -> Option> { + pub(crate) fn context(&self) -> Option> { ref_filter_map(self.context.borrow(), |ctx| ctx.as_ref()) } @@ -288,7 +288,7 @@ impl HTMLCanvasElement { } /// Gets the base WebGLRenderingContext for WebGL or WebGL 2, if exists. - pub fn get_base_webgl_context(&self) -> Option> { + pub(crate) fn get_base_webgl_context(&self) -> Option> { match *self.context.borrow() { Some(CanvasContext::WebGL(ref context)) => Some(DomRoot::from_ref(context)), Some(CanvasContext::WebGL2(ref context)) => Some(context.base_context()), @@ -313,11 +313,11 @@ impl HTMLCanvasElement { } } - pub fn is_valid(&self) -> bool { + pub(crate) fn is_valid(&self) -> bool { self.Height() != 0 && self.Width() != 0 } - pub fn fetch_all_data(&self) -> Option<(Option, Size2D)> { + pub(crate) fn fetch_all_data(&self) -> Option<(Option, Size2D)> { let size = self.get_size(); if size.width == 0 || size.height == 0 { @@ -563,14 +563,14 @@ impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { } } -pub mod utils { +pub(crate) mod utils { use net_traits::image_cache::ImageResponse; use net_traits::request::CorsSettings; use servo_url::ServoUrl; use crate::dom::window::Window; - pub fn request_image_from_cache( + pub(crate) fn request_image_from_cache( window: &Window, url: ServoUrl, cors_setting: Option, diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index 6294c9b93d9..4b3ad216e19 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -22,7 +22,7 @@ use crate::dom::node::{Node, NodeTraits}; use crate::dom::window::Window; use crate::script_runtime::CanGc; -pub trait CollectionFilter: JSTraceable { +pub(crate) trait CollectionFilter: JSTraceable { fn filter<'a>(&self, elem: &'a Element, root: &'a Node) -> bool; } @@ -54,7 +54,7 @@ impl OptionU32 { } #[dom_struct] -pub struct HTMLCollection { +pub(crate) struct HTMLCollection { reflector_: Reflector, root: Dom, #[ignore_malloc_size_of = "Trait object (Box) cannot be sized"] @@ -70,7 +70,7 @@ pub struct HTMLCollection { impl HTMLCollection { #[allow(crown::unrooted_must_root)] - pub fn new_inherited( + pub(crate) fn new_inherited( root: &Node, filter: Box, ) -> HTMLCollection { @@ -87,7 +87,7 @@ impl HTMLCollection { } /// Returns a collection which is always empty. - pub fn always_empty(window: &Window, root: &Node) -> DomRoot { + pub(crate) fn always_empty(window: &Window, root: &Node) -> DomRoot { #[derive(JSTraceable)] struct NoFilter; impl CollectionFilter for NoFilter { @@ -100,7 +100,7 @@ impl HTMLCollection { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( window: &Window, root: &Node, filter: Box, @@ -174,7 +174,7 @@ impl HTMLCollection { } /// - pub fn by_qualified_name( + pub(crate) fn by_qualified_name( window: &Window, root: &Node, qualified_name: LocalName, @@ -228,7 +228,7 @@ impl HTMLCollection { } } - pub fn by_tag_name_ns( + pub(crate) fn by_tag_name_ns( window: &Window, root: &Node, tag: DOMString, @@ -240,7 +240,7 @@ impl HTMLCollection { HTMLCollection::by_qual_tag_name(window, root, qname) } - pub fn by_qual_tag_name( + pub(crate) fn by_qual_tag_name( window: &Window, root: &Node, qname: QualName, @@ -261,7 +261,7 @@ impl HTMLCollection { HTMLCollection::create(window, root, Box::new(filter)) } - pub fn by_class_name( + pub(crate) fn by_class_name( window: &Window, root: &Node, classes: DOMString, @@ -270,7 +270,7 @@ impl HTMLCollection { HTMLCollection::by_atomic_class_name(window, root, class_atoms) } - pub fn by_atomic_class_name( + pub(crate) fn by_atomic_class_name( window: &Window, root: &Node, classes: Vec, @@ -301,13 +301,13 @@ impl HTMLCollection { HTMLCollection::create(window, root, Box::new(filter)) } - pub fn children(window: &Window, root: &Node) -> DomRoot { + pub(crate) fn children(window: &Window, root: &Node) -> DomRoot { HTMLCollection::new_with_filter_fn(window, root, |element, root| { root.is_parent_of(element.upcast()) }) } - pub fn elements_iter_after<'a>( + pub(crate) fn elements_iter_after<'a>( &'a self, after: &'a Node, ) -> impl Iterator> + 'a { @@ -318,12 +318,12 @@ impl HTMLCollection { .filter(move |element| self.filter.filter(element, &self.root)) } - pub fn elements_iter(&self) -> impl Iterator> + '_ { + pub(crate) fn elements_iter(&self) -> impl Iterator> + '_ { // Iterate forwards from the root. self.elements_iter_after(&self.root) } - pub fn elements_iter_before<'a>( + pub(crate) fn elements_iter_before<'a>( &'a self, before: &'a Node, ) -> impl Iterator> + 'a { @@ -334,7 +334,7 @@ impl HTMLCollection { .filter(move |element| self.filter.filter(element, &self.root)) } - pub fn root_node(&self) -> DomRoot { + pub(crate) fn root_node(&self) -> DomRoot { DomRoot::from_ref(&self.root) } } diff --git a/components/script/dom/htmldataelement.rs b/components/script/dom/htmldataelement.rs index 5aadd1c8e3a..101bf713810 100644 --- a/components/script/dom/htmldataelement.rs +++ b/components/script/dom/htmldataelement.rs @@ -15,7 +15,7 @@ use crate::dom::node::Node; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLDataElement { +pub(crate) struct HTMLDataElement { htmlelement: HTMLElement, } @@ -31,7 +31,7 @@ impl HTMLDataElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, diff --git a/components/script/dom/htmldatalistelement.rs b/components/script/dom/htmldatalistelement.rs index 105f6e2225d..efa20a67604 100644 --- a/components/script/dom/htmldatalistelement.rs +++ b/components/script/dom/htmldatalistelement.rs @@ -17,7 +17,7 @@ use crate::dom::node::{Node, NodeTraits}; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLDataListElement { +pub(crate) struct HTMLDataListElement { htmlelement: HTMLElement, } @@ -33,7 +33,7 @@ impl HTMLDataListElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, diff --git a/components/script/dom/htmldetailselement.rs b/components/script/dom/htmldetailselement.rs index f951ef39aa0..5e24031b823 100644 --- a/components/script/dom/htmldetailselement.rs +++ b/components/script/dom/htmldetailselement.rs @@ -22,7 +22,7 @@ use crate::dom::virtualmethods::VirtualMethods; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLDetailsElement { +pub(crate) struct HTMLDetailsElement { htmlelement: HTMLElement, toggle_counter: Cell, } @@ -40,7 +40,7 @@ impl HTMLDetailsElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, @@ -57,7 +57,7 @@ impl HTMLDetailsElement { ) } - pub fn toggle(&self) { + pub(crate) fn toggle(&self) { self.SetOpen(!self.Open()); } } diff --git a/components/script/dom/htmldialogelement.rs b/components/script/dom/htmldialogelement.rs index 70a57749add..078f47ad1fc 100644 --- a/components/script/dom/htmldialogelement.rs +++ b/components/script/dom/htmldialogelement.rs @@ -19,7 +19,7 @@ use crate::dom::node::{Node, NodeTraits}; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLDialogElement { +pub(crate) struct HTMLDialogElement { htmlelement: HTMLElement, return_value: DomRefCell, } @@ -37,7 +37,7 @@ impl HTMLDialogElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, diff --git a/components/script/dom/htmldirectoryelement.rs b/components/script/dom/htmldirectoryelement.rs index d06b622e5c9..d355caca58e 100644 --- a/components/script/dom/htmldirectoryelement.rs +++ b/components/script/dom/htmldirectoryelement.rs @@ -13,7 +13,7 @@ use crate::dom::node::Node; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLDirectoryElement { +pub(crate) struct HTMLDirectoryElement { htmlelement: HTMLElement, } @@ -29,7 +29,7 @@ impl HTMLDirectoryElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, diff --git a/components/script/dom/htmldivelement.rs b/components/script/dom/htmldivelement.rs index 4bb69f863d2..afaacef03e3 100644 --- a/components/script/dom/htmldivelement.rs +++ b/components/script/dom/htmldivelement.rs @@ -15,7 +15,7 @@ use crate::dom::node::Node; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLDivElement { +pub(crate) struct HTMLDivElement { htmlelement: HTMLElement, } @@ -31,7 +31,7 @@ impl HTMLDivElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, diff --git a/components/script/dom/htmldlistelement.rs b/components/script/dom/htmldlistelement.rs index 1e51328fe96..d13b6de1601 100644 --- a/components/script/dom/htmldlistelement.rs +++ b/components/script/dom/htmldlistelement.rs @@ -13,7 +13,7 @@ use crate::dom::node::Node; use crate::script_runtime::CanGc; #[dom_struct] -pub struct HTMLDListElement { +pub(crate) struct HTMLDListElement { htmlelement: HTMLElement, } @@ -29,7 +29,7 @@ impl HTMLDListElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 1c69482c0e4..070522d216e 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -53,14 +53,14 @@ use crate::script_runtime::CanGc; use crate::script_thread::ScriptThread; #[dom_struct] -pub struct HTMLElement { +pub(crate) struct HTMLElement { element: Element, style_decl: MutNullableDom, dataset: MutNullableDom, } impl HTMLElement { - pub fn new_inherited( + pub(crate) fn new_inherited( tag_name: LocalName, prefix: Option, document: &Document, @@ -68,7 +68,7 @@ impl HTMLElement { HTMLElement::new_inherited_with_state(ElementState::empty(), tag_name, prefix, document) } - pub fn new_inherited_with_state( + pub(crate) fn new_inherited_with_state( state: ElementState, tag_name: LocalName, prefix: Option, @@ -88,7 +88,7 @@ impl HTMLElement { } #[allow(crown::unrooted_must_root)] - pub fn new( + pub(crate) fn new( local_name: LocalName, prefix: Option, document: &Document, @@ -708,7 +708,12 @@ fn to_camel_case(name: &str) -> Option { } impl HTMLElement { - pub fn set_custom_attr(&self, name: DOMString, value: DOMString, can_gc: CanGc) -> ErrorResult { + pub(crate) fn set_custom_attr( + &self, + name: DOMString, + value: DOMString, + can_gc: CanGc, + ) -> ErrorResult { if name .chars() .skip_while(|&ch| ch != '\u{2d}') @@ -721,7 +726,7 @@ impl HTMLElement { .set_custom_attribute(to_snake_case(name), value, can_gc) } - pub fn get_custom_attr(&self, local_name: DOMString) -> Option { + pub(crate) fn get_custom_attr(&self, local_name: DOMString) -> Option { // FIXME(ajeffrey): Convert directly from DOMString to LocalName let local_name = LocalName::from(to_snake_case(local_name)); self.as_element() @@ -731,14 +736,14 @@ impl HTMLElement { }) } - pub fn delete_custom_attr(&self, local_name: DOMString) { + pub(crate) fn delete_custom_attr(&self, local_name: DOMString) { // FIXME(ajeffrey): Convert directly from DOMString to LocalName let local_name = LocalName::from(to_snake_case(local_name)); self.as_element().remove_attribute(&ns!(), &local_name); } /// - pub fn is_labelable_element(&self) -> bool { + pub(crate) fn is_labelable_element(&self) -> bool { match self.upcast::().type_id() { NodeTypeId::Element(ElementTypeId::HTMLElement(type_id)) => match type_id { HTMLElementTypeId::HTMLInputElement => { @@ -757,7 +762,7 @@ impl HTMLElement { } /// - pub fn is_form_associated_custom_element(&self) -> bool { + pub(crate) fn is_form_associated_custom_element(&self) -> bool { if let Some(definition) = self.as_element().get_custom_element_definition() { definition.is_autonomous() && definition.form_associated } else { @@ -766,7 +771,7 @@ impl HTMLElement { } /// - pub fn is_listed_element(&self) -> bool { + pub(crate) fn is_listed_element(&self) -> bool { match self.upcast::().type_id() { NodeTypeId::Element(ElementTypeId::HTMLElement(type_id)) => match type_id { HTMLElementTypeId::HTMLButtonElement | @@ -783,7 +788,7 @@ impl HTMLElement { } /// - pub fn is_submittable_element(&self) -> bool { + pub(crate) fn is_submittable_element(&self) -> bool { match self.upcast::().type_id() { NodeTypeId::Element(ElementTypeId::HTMLElement(type_id)) => match type_id { HTMLElementTypeId::HTMLButtonElement | @@ -796,7 +801,7 @@ impl HTMLElement { } } - pub fn supported_prop_names_custom_attr(&self) -> Vec { + pub(crate) fn supported_prop_names_custom_attr(&self) -> Vec { let element = self.as_element(); element .attrs() @@ -810,7 +815,7 @@ impl HTMLElement { // https://html.spec.whatwg.org/multipage/#dom-lfe-labels // This gets the nth label in tree order. - pub fn label_at(&self, index: u32) -> Option> { + pub(crate) fn label_at(&self, index: u32) -> Option> { let element = self.as_element(); // Traverse entire tree for