mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #28129 - teymour-aldridge:make-unsafe, r=jdm
Make unsafe <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #16868 (GitHub issue number if applicable) (maybe – I'm not sure) <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
1610bd2bc8
6 changed files with 37 additions and 60 deletions
|
@ -125,7 +125,7 @@ impl Animations {
|
|||
pub(crate) fn do_post_reflow_update(&self, window: &Window, now: f64) {
|
||||
let pipeline_id = window.pipeline_id();
|
||||
let mut sets = self.sets.sets.write();
|
||||
self.root_newly_animating_dom_nodes(&sets, window);
|
||||
self.root_newly_animating_dom_nodes(&sets);
|
||||
|
||||
for (key, set) in sets.iter_mut() {
|
||||
self.handle_canceled_animations(key, set, now, pipeline_id);
|
||||
|
@ -305,9 +305,7 @@ impl Animations {
|
|||
fn root_newly_animating_dom_nodes(
|
||||
&self,
|
||||
sets: &FxHashMap<AnimationSetKey, ElementAnimationSet>,
|
||||
window: &Window,
|
||||
) {
|
||||
let js_runtime = window.get_js_runtime().as_ref().unwrap().rt();
|
||||
let mut rooted_nodes = self.rooted_nodes.borrow_mut();
|
||||
for (key, set) in sets.iter() {
|
||||
let opaque_node = key.node;
|
||||
|
@ -322,7 +320,7 @@ impl Animations {
|
|||
unsafe {
|
||||
rooted_nodes.insert(
|
||||
opaque_node,
|
||||
Dom::from_ref(&*from_untrusted_node_address(js_runtime, address)),
|
||||
Dom::from_ref(&*from_untrusted_node_address(address)),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ use euclid::default::{Point2D, Rect, Size2D};
|
|||
use html5ever::{LocalName, Namespace, QualName};
|
||||
use hyper_serde::Serde;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use js::jsapi::{JSObject, JSRuntime};
|
||||
use js::jsapi::JSObject;
|
||||
use keyboard_types::{Code, Key, KeyState};
|
||||
use metrics::{
|
||||
InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory,
|
||||
|
@ -1185,9 +1185,8 @@ impl Document {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn handle_mouse_event(
|
||||
pub unsafe fn handle_mouse_event(
|
||||
&self,
|
||||
js_runtime: *mut JSRuntime,
|
||||
button: MouseButton,
|
||||
client_point: Point2D<f32>,
|
||||
mouse_event_type: MouseEventType,
|
||||
|
@ -1203,7 +1202,7 @@ impl Document {
|
|||
debug!("{}: at {:?}", mouse_event_type_string, client_point);
|
||||
|
||||
let el = node_address.and_then(|address| {
|
||||
let node = unsafe { node::from_untrusted_node_address(js_runtime, address) };
|
||||
let node = node::from_untrusted_node_address(address);
|
||||
node.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<Element>)
|
||||
.next()
|
||||
|
@ -1389,16 +1388,15 @@ impl Document {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn handle_mouse_move_event(
|
||||
pub unsafe fn handle_mouse_move_event(
|
||||
&self,
|
||||
js_runtime: *mut JSRuntime,
|
||||
client_point: Point2D<f32>,
|
||||
prev_mouse_over_target: &MutNullableDom<Element>,
|
||||
node_address: Option<UntrustedNodeAddress>,
|
||||
pressed_mouse_buttons: u16,
|
||||
) {
|
||||
let maybe_new_target = node_address.and_then(|address| {
|
||||
let node = unsafe { node::from_untrusted_node_address(js_runtime, address) };
|
||||
let node = node::from_untrusted_node_address(address);
|
||||
node.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<Element>)
|
||||
.next()
|
||||
|
@ -1562,9 +1560,8 @@ impl Document {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn handle_wheel_event(
|
||||
pub unsafe fn handle_wheel_event(
|
||||
&self,
|
||||
js_runtime: *mut JSRuntime,
|
||||
delta: WheelDelta,
|
||||
client_point: Point2D<f32>,
|
||||
node_address: Option<UntrustedNodeAddress>,
|
||||
|
@ -1573,7 +1570,7 @@ impl Document {
|
|||
debug!("{}: at {:?}", wheel_event_type_string, client_point);
|
||||
|
||||
let el = node_address.and_then(|address| {
|
||||
let node = unsafe { node::from_untrusted_node_address(js_runtime, address) };
|
||||
let node = node::from_untrusted_node_address(address);
|
||||
node.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<Element>)
|
||||
.next()
|
||||
|
@ -1609,9 +1606,8 @@ impl Document {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn handle_touch_event(
|
||||
pub unsafe fn handle_touch_event(
|
||||
&self,
|
||||
js_runtime: *mut JSRuntime,
|
||||
event_type: TouchEventType,
|
||||
touch_id: TouchId,
|
||||
point: Point2D<f32>,
|
||||
|
@ -1627,7 +1623,7 @@ impl Document {
|
|||
};
|
||||
|
||||
let el = node_address.and_then(|address| {
|
||||
let node = unsafe { node::from_untrusted_node_address(js_runtime, address) };
|
||||
let node = node::from_untrusted_node_address(address);
|
||||
node.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<Element>)
|
||||
.next()
|
||||
|
|
|
@ -14,7 +14,6 @@ use crate::dom::node::{self, Node, VecPreOrderInsertionHelper};
|
|||
use crate::dom::window::Window;
|
||||
use crate::stylesheet_set::StylesheetSetRef;
|
||||
use euclid::default::Point2D;
|
||||
use js::jsapi::JS_GetRuntime;
|
||||
use script_layout_interface::message::{NodesFromPointQueryType, QueryMsg};
|
||||
use script_traits::UntrustedNodeAddress;
|
||||
use servo_arc::Arc;
|
||||
|
@ -131,8 +130,7 @@ impl DocumentOrShadowRoot {
|
|||
.first()
|
||||
{
|
||||
Some(address) => {
|
||||
let js_runtime = unsafe { JS_GetRuntime(*self.window.get_cx()) };
|
||||
let node = unsafe { node::from_untrusted_node_address(js_runtime, *address) };
|
||||
let node = unsafe { node::from_untrusted_node_address(*address) };
|
||||
let parent_node = node.GetParentNode().unwrap();
|
||||
let element_ref = node
|
||||
.downcast::<Element>()
|
||||
|
@ -167,16 +165,12 @@ impl DocumentOrShadowRoot {
|
|||
return vec![];
|
||||
}
|
||||
|
||||
let js_runtime = unsafe { JS_GetRuntime(*self.window.get_cx()) };
|
||||
|
||||
// Step 1 and Step 3
|
||||
let nodes = self.nodes_from_point(point, NodesFromPointQueryType::All);
|
||||
let mut elements: Vec<DomRoot<Element>> = nodes
|
||||
.iter()
|
||||
.flat_map(|&untrusted_node_address| {
|
||||
let node = unsafe {
|
||||
node::from_untrusted_node_address(js_runtime, untrusted_node_address)
|
||||
};
|
||||
let node = unsafe { node::from_untrusted_node_address(untrusted_node_address) };
|
||||
DomRoot::downcast::<Element>(node)
|
||||
})
|
||||
.collect();
|
||||
|
|
|
@ -69,7 +69,7 @@ use devtools_traits::NodeInfo;
|
|||
use dom_struct::dom_struct;
|
||||
use euclid::default::{Point2D, Rect, Size2D, Vector2D};
|
||||
use html5ever::{Namespace, Prefix, QualName};
|
||||
use js::jsapi::{JSObject, JSRuntime};
|
||||
use js::jsapi::JSObject;
|
||||
use libc::{self, c_void, uintptr_t};
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
use msg::constellation_msg::{BrowsingContextId, PipelineId};
|
||||
|
@ -1321,10 +1321,7 @@ where
|
|||
/// If the given untrusted node address represents a valid DOM node in the given runtime,
|
||||
/// returns it.
|
||||
#[allow(unsafe_code)]
|
||||
pub unsafe fn from_untrusted_node_address(
|
||||
_runtime: *mut JSRuntime,
|
||||
candidate: UntrustedNodeAddress,
|
||||
) -> DomRoot<Node> {
|
||||
pub unsafe fn from_untrusted_node_address(candidate: UntrustedNodeAddress) -> DomRoot<Node> {
|
||||
// https://github.com/servo/servo/issues/6383
|
||||
let candidate: uintptr_t = mem::transmute(candidate.0);
|
||||
// let object: *mut JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime,
|
||||
|
|
|
@ -1755,9 +1755,7 @@ impl Window {
|
|||
|
||||
for image in complete.pending_images {
|
||||
let id = image.id;
|
||||
let js_runtime = self.js_runtime.borrow();
|
||||
let js_runtime = js_runtime.as_ref().unwrap();
|
||||
let node = unsafe { from_untrusted_node_address(js_runtime.rt(), image.node) };
|
||||
let node = unsafe { from_untrusted_node_address(image.node) };
|
||||
|
||||
if let PendingImageState::Unrequested(ref url) = image.state {
|
||||
fetch_image_for_layout(url.clone(), &*node, id, self.image_cache.clone());
|
||||
|
@ -1988,10 +1986,8 @@ impl Window {
|
|||
// FIXME(nox): Layout can reply with a garbage value which doesn't
|
||||
// actually correspond to an element, that's unsound.
|
||||
let response = self.layout_rpc.offset_parent();
|
||||
let js_runtime = self.js_runtime.borrow();
|
||||
let js_runtime = js_runtime.as_ref().unwrap();
|
||||
let element = response.node_address.and_then(|parent_node_address| {
|
||||
let node = unsafe { from_untrusted_node_address(js_runtime.rt(), parent_node_address) };
|
||||
let node = unsafe { from_untrusted_node_address(parent_node_address) };
|
||||
DomRoot::downcast(node)
|
||||
});
|
||||
(element, response.rect)
|
||||
|
|
|
@ -3525,13 +3525,14 @@ impl ScriptThread {
|
|||
// Get the previous target temporarily
|
||||
let prev_mouse_over_target = self.topmost_mouse_over_target.get();
|
||||
|
||||
document.handle_mouse_move_event(
|
||||
self.js_runtime.rt(),
|
||||
point,
|
||||
&self.topmost_mouse_over_target,
|
||||
node_address,
|
||||
pressed_mouse_buttons,
|
||||
);
|
||||
unsafe {
|
||||
document.handle_mouse_move_event(
|
||||
point,
|
||||
&self.topmost_mouse_over_target,
|
||||
node_address,
|
||||
pressed_mouse_buttons,
|
||||
)
|
||||
}
|
||||
|
||||
// Short-circuit if nothing changed
|
||||
if self.topmost_mouse_over_target.get() == prev_mouse_over_target {
|
||||
|
@ -3650,15 +3651,16 @@ impl ScriptThread {
|
|||
Some(document) => document,
|
||||
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
|
||||
};
|
||||
document.handle_mouse_event(
|
||||
self.js_runtime.rt(),
|
||||
button,
|
||||
point,
|
||||
mouse_event_type,
|
||||
node_address,
|
||||
point_in_node,
|
||||
pressed_mouse_buttons,
|
||||
);
|
||||
unsafe {
|
||||
document.handle_mouse_event(
|
||||
button,
|
||||
point,
|
||||
mouse_event_type,
|
||||
node_address,
|
||||
point_in_node,
|
||||
pressed_mouse_buttons,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_touch_event(
|
||||
|
@ -3676,13 +3678,7 @@ impl ScriptThread {
|
|||
return TouchEventResult::Processed(true);
|
||||
},
|
||||
};
|
||||
document.handle_touch_event(
|
||||
self.js_runtime.rt(),
|
||||
event_type,
|
||||
identifier,
|
||||
point,
|
||||
node_address,
|
||||
)
|
||||
unsafe { document.handle_touch_event(event_type, identifier, point, node_address) }
|
||||
}
|
||||
|
||||
fn handle_wheel_event(
|
||||
|
@ -3696,7 +3692,7 @@ impl ScriptThread {
|
|||
Some(document) => document,
|
||||
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
|
||||
};
|
||||
document.handle_wheel_event(self.js_runtime.rt(), wheel_delta, point, node_address);
|
||||
unsafe { document.handle_wheel_event(wheel_delta, point, node_address) };
|
||||
}
|
||||
|
||||
/// Handle a "navigate an iframe" message from the constellation.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue