aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchickenleaf <lashwinib@gmail.com>2024-10-15 10:00:48 +0530
committerGitHub <noreply@github.com>2024-10-15 04:30:48 +0000
commit1e39787573e180801ed70c3f708ebb22631eeeb9 (patch)
treec2acdf18ac3cdee828cc86d1bcf7e8963698eeb9
parent2f1862aaf5771c3a8416d524c4a6dca1cac4d99e (diff)
downloadservo-1e39787573e180801ed70c3f708ebb22631eeeb9.tar.gz
servo-1e39787573e180801ed70c3f708ebb22631eeeb9.zip
CanGc fixes and checks in multiple files (#33836)
* CanGc fixes and checks in multiple files Signed-off-by: L Ashwin B <lashwinib@gmail.com> * CanGc fixes in storageevent.rs Signed-off-by: L Ashwin B <lashwinib@gmail.com> --------- Signed-off-by: L Ashwin B <lashwinib@gmail.com>
-rw-r--r--components/script/dom/bindings/codegen/Bindings.conf1
-rw-r--r--components/script/dom/document.rs6
-rw-r--r--components/script/dom/history.rs5
-rw-r--r--components/script/dom/popstateevent.rs18
-rw-r--r--components/script/dom/rtcpeerconnection.rs4
-rw-r--r--components/script/dom/storageevent.rs8
-rw-r--r--components/script/dom/uievent.rs14
-rw-r--r--components/script/script_thread.rs27
-rw-r--r--components/script/webdriver_handlers.rs58
9 files changed, 78 insertions, 63 deletions
diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf
index 1316b444e5b..9b38ddb4bc2 100644
--- a/components/script/dom/bindings/codegen/Bindings.conf
+++ b/components/script/dom/bindings/codegen/Bindings.conf
@@ -183,6 +183,7 @@ DOMInterfaces = {
'RTCPeerConnection': {
'inRealms': ['AddIceCandidate', 'CreateAnswer', 'CreateOffer', 'SetLocalDescription', 'SetRemoteDescription'],
+ 'canGc': ['Close'],
},
'Range': {
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index e9b97d1c1a4..bc0f8c1b8e6 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -4645,6 +4645,7 @@ impl DocumentMethods for Document {
"storageevent" => Ok(DomRoot::upcast(StorageEvent::new_uninitialized(
&self.window,
"".into(),
+ can_gc,
))),
"touchevent" => Ok(DomRoot::upcast(TouchEvent::new_uninitialized(
&self.window,
@@ -4652,7 +4653,10 @@ impl DocumentMethods for Document {
&TouchList::new(&self.window, &[]),
&TouchList::new(&self.window, &[]),
))),
- "uievent" | "uievents" => Ok(DomRoot::upcast(UIEvent::new_uninitialized(&self.window))),
+ "uievent" | "uievents" => Ok(DomRoot::upcast(UIEvent::new_uninitialized(
+ &self.window,
+ can_gc,
+ ))),
_ => Err(Error::NotSupported),
}
}
diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs
index f0be9b8ceac..b9d0a3231cb 100644
--- a/components/script/dom/history.rs
+++ b/components/script/dom/history.rs
@@ -31,7 +31,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::hashchangeevent::HashChangeEvent;
use crate::dom::popstateevent::PopStateEvent;
use crate::dom::window::Window;
-use crate::script_runtime::JSContext;
+use crate::script_runtime::{CanGc, JSContext};
enum PushOrReplace {
Push,
@@ -83,7 +83,7 @@ impl History {
/// <https://html.spec.whatwg.org/multipage/#history-traversal>
/// Steps 5-16
#[allow(unsafe_code)]
- pub fn activate_state(&self, state_id: Option<HistoryStateId>, url: ServoUrl) {
+ pub fn activate_state(&self, state_id: Option<HistoryStateId>, url: ServoUrl, can_gc: CanGc) {
// Steps 5
let document = self.window.Document();
let old_url = document.url().clone();
@@ -139,6 +139,7 @@ impl History {
self.window.upcast::<EventTarget>(),
&self.window,
unsafe { HandleValue::from_raw(self.state.handle()) },
+ can_gc,
);
}
diff --git a/components/script/dom/popstateevent.rs b/components/script/dom/popstateevent.rs
index bfd388ded45..ff24a1f1028 100644
--- a/components/script/dom/popstateevent.rs
+++ b/components/script/dom/popstateevent.rs
@@ -69,16 +69,14 @@ impl PopStateEvent {
ev
}
- pub fn dispatch_jsval(target: &EventTarget, window: &Window, state: HandleValue) {
- let event = PopStateEvent::new(
- window,
- None,
- atom!("popstate"),
- false,
- false,
- state,
- CanGc::note(),
- );
+ pub fn dispatch_jsval(
+ target: &EventTarget,
+ window: &Window,
+ state: HandleValue,
+ can_gc: CanGc,
+ ) {
+ let event =
+ PopStateEvent::new(window, None, atom!("popstate"), false, false, state, can_gc);
event.upcast::<Event>().fire(target);
}
}
diff --git a/components/script/dom/rtcpeerconnection.rs b/components/script/dom/rtcpeerconnection.rs
index 9f2827b8c32..7582444b948 100644
--- a/components/script/dom/rtcpeerconnection.rs
+++ b/components/script/dom/rtcpeerconnection.rs
@@ -749,7 +749,7 @@ impl RTCPeerConnectionMethods for RTCPeerConnection {
}
/// <https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close>
- fn Close(&self) {
+ fn Close(&self, can_gc: CanGc) {
// Step 1
if self.closed.get() {
return;
@@ -765,7 +765,7 @@ impl RTCPeerConnectionMethods for RTCPeerConnection {
// Step 6
for (_, val) in self.data_channels.borrow().iter() {
- val.on_state_change(DataChannelState::Closed, CanGc::note());
+ val.on_state_change(DataChannelState::Closed, can_gc);
}
// Step 7-10
diff --git a/components/script/dom/storageevent.rs b/components/script/dom/storageevent.rs
index ee7d48d70ff..d9e32705c3a 100644
--- a/components/script/dom/storageevent.rs
+++ b/components/script/dom/storageevent.rs
@@ -49,8 +49,12 @@ impl StorageEvent {
}
}
- pub fn new_uninitialized(window: &Window, url: DOMString) -> DomRoot<StorageEvent> {
- Self::new_uninitialized_with_proto(window, None, url, CanGc::note())
+ pub fn new_uninitialized(
+ window: &Window,
+ url: DOMString,
+ can_gc: CanGc,
+ ) -> DomRoot<StorageEvent> {
+ Self::new_uninitialized_with_proto(window, None, url, can_gc)
}
fn new_uninitialized_with_proto(
diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs
index dc729233bf0..b9da7792908 100644
--- a/components/script/dom/uievent.rs
+++ b/components/script/dom/uievent.rs
@@ -38,8 +38,8 @@ impl UIEvent {
}
}
- pub fn new_uninitialized(window: &Window) -> DomRoot<UIEvent> {
- Self::new_uninitialized_with_proto(window, None, CanGc::note())
+ pub fn new_uninitialized(window: &Window, can_gc: CanGc) -> DomRoot<UIEvent> {
+ Self::new_uninitialized_with_proto(window, None, can_gc)
}
fn new_uninitialized_with_proto(
@@ -57,16 +57,10 @@ impl UIEvent {
cancelable: EventCancelable,
view: Option<&Window>,
detail: i32,
+ can_gc: CanGc,
) -> DomRoot<UIEvent> {
Self::new_with_proto(
- window,
- None,
- type_,
- can_bubble,
- cancelable,
- view,
- detail,
- CanGc::note(),
+ window, None, type_, can_bubble, cancelable, view, detail, can_gc,
)
}
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 7030285ab60..29a762ba80d 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -1463,9 +1463,10 @@ impl ScriptThread {
id: PipelineId,
size: WindowSizeData,
size_type: WindowSizeType,
+ can_gc: CanGc,
) {
self.profile_event(ScriptThreadEventCategory::Resize, Some(id), || {
- self.handle_resize_event(id, size, size_type);
+ self.handle_resize_event(id, size, size_type, can_gc);
});
}
@@ -1694,7 +1695,7 @@ impl ScriptThread {
if let Some((size, size_type)) = document.window().take_unhandled_resize_event() {
// Resize steps.
- self.run_the_resize_steps(pipeline_id, size, size_type);
+ self.run_the_resize_steps(pipeline_id, size, size_type, can_gc);
// Evaluate media queries and report changes.
document
@@ -2366,7 +2367,7 @@ impl ScriptThread {
can_gc,
),
ConstellationControlMsg::UpdateHistoryState(pipeline_id, history_state_id, url) => {
- self.handle_update_history_state_msg(pipeline_id, history_state_id, url)
+ self.handle_update_history_state_msg(pipeline_id, history_state_id, url, can_gc)
},
ConstellationControlMsg::RemoveHistoryStates(pipeline_id, history_states) => {
self.handle_remove_history_states(pipeline_id, history_states)
@@ -2375,7 +2376,7 @@ impl ScriptThread {
self.handle_focus_iframe_msg(parent_pipeline_id, frame_id)
},
ConstellationControlMsg::WebDriverScriptCommand(pipeline_id, msg) => {
- self.handle_webdriver_msg(pipeline_id, msg)
+ self.handle_webdriver_msg(pipeline_id, msg, can_gc)
},
ConstellationControlMsg::WebFontLoaded(pipeline_id, success) => {
self.handle_web_font_loaded(pipeline_id, success)
@@ -2630,7 +2631,12 @@ impl ScriptThread {
}
}
- fn handle_webdriver_msg(&self, pipeline_id: PipelineId, msg: WebDriverScriptCommand) {
+ fn handle_webdriver_msg(
+ &self,
+ pipeline_id: PipelineId,
+ msg: WebDriverScriptCommand,
+ can_gc: CanGc,
+ ) {
// https://github.com/servo/servo/issues/23535
// These two messages need different treatment since the JS script might mutate
// `self.documents`, which would conflict with the immutable borrow of it that
@@ -2777,7 +2783,7 @@ impl ScriptThread {
webdriver_handlers::handle_get_active_element(&documents, pipeline_id, reply)
},
WebDriverScriptCommand::GetPageSource(reply) => {
- webdriver_handlers::handle_get_page_source(&documents, pipeline_id, reply)
+ webdriver_handlers::handle_get_page_source(&documents, pipeline_id, reply, can_gc)
},
WebDriverScriptCommand::GetCookies(reply) => {
webdriver_handlers::handle_get_cookies(&documents, pipeline_id, reply)
@@ -2818,6 +2824,7 @@ impl ScriptThread {
pipeline_id,
node_id,
reply,
+ can_gc,
)
},
WebDriverScriptCommand::GetElementText(node_id, reply) => {
@@ -2829,6 +2836,7 @@ impl ScriptThread {
pipeline_id,
node_id,
reply,
+ can_gc,
)
},
WebDriverScriptCommand::GetBrowsingContextId(webdriver_frame_id, reply) => {
@@ -3125,6 +3133,7 @@ impl ScriptThread {
pipeline_id: PipelineId,
history_state_id: Option<HistoryStateId>,
url: ServoUrl,
+ can_gc: CanGc,
) {
let window = self.documents.borrow().find_window(pipeline_id);
match window {
@@ -3134,7 +3143,9 @@ impl ScriptThread {
pipeline_id
);
},
- Some(window) => window.History().activate_state(history_state_id, url),
+ Some(window) => window
+ .History()
+ .activate_state(history_state_id, url, can_gc),
}
}
@@ -4018,6 +4029,7 @@ impl ScriptThread {
pipeline_id: PipelineId,
new_size: WindowSizeData,
size_type: WindowSizeType,
+ can_gc: CanGc,
) {
let document = match self.documents.borrow().find_document(pipeline_id) {
Some(document) => document,
@@ -4046,6 +4058,7 @@ impl ScriptThread {
EventCancelable::NotCancelable,
Some(window),
0i32,
+ can_gc,
);
uievent.upcast::<Event>().fire(window.upcast());
}
diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs
index e43c2047490..cbe74aa1263 100644
--- a/components/script/webdriver_handlers.rs
+++ b/components/script/webdriver_handlers.rs
@@ -374,7 +374,7 @@ pub fn handle_get_browsing_context_id(
}
// https://w3c.github.io/webdriver/#dfn-center-point
-fn get_element_in_view_center_point(element: &Element) -> Option<Point2D<i64>> {
+fn get_element_in_view_center_point(element: &Element, can_gc: CanGc) -> Option<Point2D<i64>> {
window_from_node(element.upcast::<Node>())
.Document()
.GetBody()
@@ -382,31 +382,28 @@ fn get_element_in_view_center_point(element: &Element) -> Option<Point2D<i64>> {
.and_then(|body| {
// Step 1: Let rectangle be the first element of the DOMRect sequence
// returned by calling getClientRects() on element.
- element
- .GetClientRects(CanGc::note())
- .first()
- .map(|rectangle| {
- let x = rectangle.X().round() as i64;
- let y = rectangle.Y().round() as i64;
- let width = rectangle.Width().round() as i64;
- let height = rectangle.Height().round() as i64;
-
- let client_width = body.ClientWidth() as i64;
- let client_height = body.ClientHeight() as i64;
-
- // Steps 2 - 5
- let left = cmp::max(0, cmp::min(x, x + width));
- let right = cmp::min(client_width, cmp::max(x, x + width));
- let top = cmp::max(0, cmp::min(y, y + height));
- let bottom = cmp::min(client_height, cmp::max(y, y + height));
-
- // Steps 6 - 7
- let x = (left + right) / 2;
- let y = (top + bottom) / 2;
-
- // Step 8
- Point2D::new(x, y)
- })
+ element.GetClientRects(can_gc).first().map(|rectangle| {
+ let x = rectangle.X().round() as i64;
+ let y = rectangle.Y().round() as i64;
+ let width = rectangle.Width().round() as i64;
+ let height = rectangle.Height().round() as i64;
+
+ let client_width = body.ClientWidth() as i64;
+ let client_height = body.ClientHeight() as i64;
+
+ // Steps 2 - 5
+ let left = cmp::max(0, cmp::min(x, x + width));
+ let right = cmp::min(client_width, cmp::max(x, x + width));
+ let top = cmp::max(0, cmp::min(y, y + height));
+ let bottom = cmp::min(client_height, cmp::max(y, y + height));
+
+ // Steps 6 - 7
+ let x = (left + right) / 2;
+ let y = (top + bottom) / 2;
+
+ // Step 8
+ Point2D::new(x, y)
+ })
})
}
@@ -415,11 +412,12 @@ pub fn handle_get_element_in_view_center_point(
pipeline: PipelineId,
element_id: String,
reply: IpcSender<Result<Option<(i64, i64)>, ErrorStatus>>,
+ can_gc: CanGc,
) {
reply
.send(
find_node_by_unique_id(documents, pipeline, element_id).map(|node| {
- get_element_in_view_center_point(node.downcast::<Element>().unwrap())
+ get_element_in_view_center_point(node.downcast::<Element>().unwrap(), can_gc)
.map(|point| (point.x, point.y))
}),
)
@@ -715,6 +713,7 @@ pub fn handle_get_page_source(
documents: &Documents,
pipeline: PipelineId,
reply: IpcSender<Result<String, ErrorStatus>>,
+ can_gc: CanGc,
) {
reply
.send(
@@ -725,7 +724,7 @@ pub fn handle_get_page_source(
Some(element) => match element.GetOuterHTML() {
Ok(source) => Ok(source.to_string()),
Err(_) => {
- match XMLSerializer::new(document.window(), None, CanGc::note())
+ match XMLSerializer::new(document.window(), None, can_gc)
.SerializeToString(element.upcast::<Node>())
{
Ok(source) => Ok(source.to_string()),
@@ -926,6 +925,7 @@ pub fn handle_get_bounding_client_rect(
pipeline: PipelineId,
element_id: String,
reply: IpcSender<Result<Rect<f32>, ErrorStatus>>,
+ can_gc: CanGc,
) {
reply
.send(
@@ -933,7 +933,7 @@ pub fn handle_get_bounding_client_rect(
.downcast::<Element>(
) {
Some(element) => {
- let rect = element.GetBoundingClientRect(CanGc::note());
+ let rect = element.GetBoundingClientRect(can_gc);
Ok(Rect::new(
Point2D::new(rect.X() as f32, rect.Y() as f32),
Size2D::new(rect.Width() as f32, rect.Height() as f32),