mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Introduce RootedVec<JS<T>>::r()
This commit is contained in:
parent
658c3d05ae
commit
389a9ff643
4 changed files with 24 additions and 20 deletions
|
@ -70,6 +70,7 @@ use std::collections::hash_state::HashState;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::intrinsics::return_address;
|
use std::intrinsics::return_address;
|
||||||
|
use std::mem;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -482,6 +483,13 @@ impl<T: JSTraceable + Reflectable> RootedVec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: JSTraceable + Reflectable> RootedVec<JS<T>> {
|
||||||
|
/// Obtain a safe slice of references that can't outlive that RootedVec.
|
||||||
|
pub fn r(&self) -> &[&T] {
|
||||||
|
unsafe { mem::transmute(&*self.v) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: JSTraceable + Reflectable> Drop for RootedVec<T> {
|
impl<T: JSTraceable + Reflectable> Drop for RootedVec<T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
RootedTraceableSet::remove(self);
|
RootedTraceableSet::remove(self);
|
||||||
|
|
|
@ -733,15 +733,13 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
|
||||||
// Set hover state for any elements in the current mouse over list.
|
// Set hover state for any elements in the current mouse over list.
|
||||||
// Check if any of them changed state to determine whether to
|
// Check if any of them changed state to determine whether to
|
||||||
// force a reflow below.
|
// force a reflow below.
|
||||||
for target in mouse_over_targets.iter() {
|
for target in mouse_over_targets.r() {
|
||||||
let target = target.root();
|
if !target.get_hover_state() {
|
||||||
let target_ref = target.r();
|
target.set_hover_state(true);
|
||||||
if !target_ref.get_hover_state() {
|
|
||||||
target_ref.set_hover_state(true);
|
|
||||||
|
|
||||||
let target = EventTargetCast::from_ref(target_ref);
|
let target = EventTargetCast::from_ref(*target);
|
||||||
|
|
||||||
self.fire_mouse_event(point, &target, "mouseover".to_owned());
|
self.fire_mouse_event(point, target, "mouseover".to_owned());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -865,9 +865,9 @@ impl<'a> AttributeHandlers for &'a Element {
|
||||||
fn get_attribute(self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
|
fn get_attribute(self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
|
||||||
let mut attributes = RootedVec::new();
|
let mut attributes = RootedVec::new();
|
||||||
self.get_attributes(local_name, &mut attributes);
|
self.get_attributes(local_name, &mut attributes);
|
||||||
attributes.iter()
|
attributes.r().iter()
|
||||||
.map(|attr| attr.root())
|
.find(|attr| attr.namespace() == namespace)
|
||||||
.find(|attr| attr.r().namespace() == namespace)
|
.map(|attr| Root::from_ref(*attr))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
||||||
|
|
|
@ -41,14 +41,13 @@ pub fn dispatch_event<'a, 'b>(target: &'a EventTarget,
|
||||||
//FIXME: The "callback this value" should be currentTarget
|
//FIXME: The "callback this value" should be currentTarget
|
||||||
|
|
||||||
/* capturing */
|
/* capturing */
|
||||||
for cur_target in chain.iter().rev() {
|
for cur_target in chain.r().iter().rev() {
|
||||||
let cur_target = cur_target.root();
|
let stopped = match cur_target.get_listeners_for(&type_, ListenerPhase::Capturing) {
|
||||||
let stopped = match cur_target.r().get_listeners_for(&type_, ListenerPhase::Capturing) {
|
|
||||||
Some(listeners) => {
|
Some(listeners) => {
|
||||||
event.set_current_target(cur_target.r());
|
event.set_current_target(cur_target);
|
||||||
for listener in listeners.iter() {
|
for listener in listeners.iter() {
|
||||||
// Explicitly drop any exception on the floor.
|
// Explicitly drop any exception on the floor.
|
||||||
let _ = listener.HandleEvent_(cur_target.r(), event, Report);
|
let _ = listener.HandleEvent_(*cur_target, event, Report);
|
||||||
|
|
||||||
if event.stop_immediate() {
|
if event.stop_immediate() {
|
||||||
break;
|
break;
|
||||||
|
@ -87,14 +86,13 @@ pub fn dispatch_event<'a, 'b>(target: &'a EventTarget,
|
||||||
if event.bubbles() && !event.stop_propagation() {
|
if event.bubbles() && !event.stop_propagation() {
|
||||||
event.set_phase(EventPhase::Bubbling);
|
event.set_phase(EventPhase::Bubbling);
|
||||||
|
|
||||||
for cur_target in chain.iter() {
|
for cur_target in chain.r() {
|
||||||
let cur_target = cur_target.root();
|
let stopped = match cur_target.get_listeners_for(&type_, ListenerPhase::Bubbling) {
|
||||||
let stopped = match cur_target.r().get_listeners_for(&type_, ListenerPhase::Bubbling) {
|
|
||||||
Some(listeners) => {
|
Some(listeners) => {
|
||||||
event.set_current_target(cur_target.r());
|
event.set_current_target(cur_target);
|
||||||
for listener in listeners.iter() {
|
for listener in listeners.iter() {
|
||||||
// Explicitly drop any exception on the floor.
|
// Explicitly drop any exception on the floor.
|
||||||
let _ = listener.HandleEvent_(cur_target.r(), event, Report);
|
let _ = listener.HandleEvent_(*cur_target, event, Report);
|
||||||
|
|
||||||
if event.stop_immediate() {
|
if event.stop_immediate() {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue