mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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>
This commit is contained in:
parent
2f1862aaf5
commit
1e39787573
9 changed files with 74 additions and 59 deletions
|
@ -183,6 +183,7 @@ DOMInterfaces = {
|
|||
|
||||
'RTCPeerConnection': {
|
||||
'inRealms': ['AddIceCandidate', 'CreateAnswer', 'CreateOffer', 'SetLocalDescription', 'SetRemoteDescription'],
|
||||
'canGc': ['Close'],
|
||||
},
|
||||
|
||||
'Range': {
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
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;
|
||||
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 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;
|
||||
// Steps 6 - 7
|
||||
let x = (left + right) / 2;
|
||||
let y = (top + bottom) / 2;
|
||||
|
||||
// Step 8
|
||||
Point2D::new(x, y)
|
||||
})
|
||||
// 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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue