mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Removed JS::root Fixes #8251
This commit is contained in:
parent
521a87180a
commit
d8ef3809a6
25 changed files with 98 additions and 126 deletions
|
@ -230,8 +230,8 @@ impl GlobalField {
|
||||||
/// Create a stack-bounded root for this reference.
|
/// Create a stack-bounded root for this reference.
|
||||||
pub fn root(&self) -> GlobalRoot {
|
pub fn root(&self) -> GlobalRoot {
|
||||||
match *self {
|
match *self {
|
||||||
GlobalField::Window(ref window) => GlobalRoot::Window(window.root()),
|
GlobalField::Window(ref window) => GlobalRoot::Window(Root::from_ref(window)),
|
||||||
GlobalField::Worker(ref worker) => GlobalRoot::Worker(worker.root()),
|
GlobalField::Worker(ref worker) => GlobalRoot::Worker(Root::from_ref(worker)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,10 +73,6 @@ impl<T> JS<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Reflectable> JS<T> {
|
impl<T: Reflectable> JS<T> {
|
||||||
/// Root this JS-owned value to prevent its collection as garbage.
|
|
||||||
pub fn root(&self) -> Root<T> {
|
|
||||||
Root::new(self.ptr)
|
|
||||||
}
|
|
||||||
/// Create a JS<T> from a Root<T>
|
/// Create a JS<T> from a Root<T>
|
||||||
/// XXX Not a great API. Should be a call on Root<T> instead
|
/// XXX Not a great API. Should be a call on Root<T> instead
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
|
@ -291,7 +287,7 @@ impl<T: Reflectable> MutHeap<JS<T>> {
|
||||||
pub fn get(&self) -> Root<T> {
|
pub fn get(&self) -> Root<T> {
|
||||||
debug_assert!(task_state::get().is_script());
|
debug_assert!(task_state::get().is_script());
|
||||||
unsafe {
|
unsafe {
|
||||||
ptr::read(self.val.get()).root()
|
Root::from_ref(&*ptr::read(self.val.get()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,7 +365,7 @@ impl<T: Reflectable> MutNullableHeap<JS<T>> {
|
||||||
pub fn get(&self) -> Option<Root<T>> {
|
pub fn get(&self) -> Option<Root<T>> {
|
||||||
debug_assert!(task_state::get().is_script());
|
debug_assert!(task_state::get().is_script());
|
||||||
unsafe {
|
unsafe {
|
||||||
ptr::read(self.ptr.get()).map(|o| o.root())
|
ptr::read(self.ptr.get()).map(|o| Root::from_ref(&*o))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ impl CanvasRenderingContext2D {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_as_dirty(&self) {
|
fn mark_as_dirty(&self) {
|
||||||
self.canvas.root().upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
self.canvas.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_transform(&self) {
|
fn update_transform(&self) {
|
||||||
|
@ -290,7 +290,7 @@ impl CanvasRenderingContext2D {
|
||||||
let smoothing_enabled = self.state.borrow().image_smoothing_enabled;
|
let smoothing_enabled = self.state.borrow().image_smoothing_enabled;
|
||||||
|
|
||||||
// If the source and target canvas are the same
|
// If the source and target canvas are the same
|
||||||
let msg = if self.canvas.root().r() == canvas {
|
let msg = if &*self.canvas == canvas {
|
||||||
CanvasMsg::Canvas2d(Canvas2dMsg::DrawImageSelf(image_size, dest_rect, source_rect, smoothing_enabled))
|
CanvasMsg::Canvas2d(Canvas2dMsg::DrawImageSelf(image_size, dest_rect, source_rect, smoothing_enabled))
|
||||||
} else { // Source and target canvases are different
|
} else { // Source and target canvases are different
|
||||||
let context = match canvas.get_or_init_2d_context() {
|
let context = match canvas.get_or_init_2d_context() {
|
||||||
|
@ -367,8 +367,7 @@ impl CanvasRenderingContext2D {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn request_image_from_cache(&self, url: Url) -> ImageResponse {
|
fn request_image_from_cache(&self, url: Url) -> ImageResponse {
|
||||||
let canvas = self.canvas.root();
|
let window = window_from_node(&*self.canvas);
|
||||||
let window = window_from_node(canvas.r());
|
|
||||||
canvas_utils::request_image_from_cache(window.r(), url)
|
canvas_utils::request_image_from_cache(window.r(), url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +421,7 @@ impl LayoutCanvasRenderingContext2DHelpers for LayoutJS<CanvasRenderingContext2D
|
||||||
impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-canvas
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-canvas
|
||||||
fn Canvas(&self) -> Root<HTMLCanvasElement> {
|
fn Canvas(&self) -> Root<HTMLCanvasElement> {
|
||||||
self.canvas.root()
|
Root::from_ref(&*self.canvas)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-save
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-save
|
||||||
|
@ -764,7 +763,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
StringOrCanvasGradientOrCanvasPattern::eString(result)
|
StringOrCanvasGradientOrCanvasPattern::eString(result)
|
||||||
},
|
},
|
||||||
CanvasFillOrStrokeStyle::Gradient(ref gradient) => {
|
CanvasFillOrStrokeStyle::Gradient(ref gradient) => {
|
||||||
StringOrCanvasGradientOrCanvasPattern::eCanvasGradient(gradient.root())
|
StringOrCanvasGradientOrCanvasPattern::eCanvasGradient(Root::from_ref(&*gradient))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -804,7 +803,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
StringOrCanvasGradientOrCanvasPattern::eString(result)
|
StringOrCanvasGradientOrCanvasPattern::eString(result)
|
||||||
},
|
},
|
||||||
CanvasFillOrStrokeStyle::Gradient(ref gradient) => {
|
CanvasFillOrStrokeStyle::Gradient(ref gradient) => {
|
||||||
StringOrCanvasGradientOrCanvasPattern::eCanvasGradient(gradient.root())
|
StringOrCanvasGradientOrCanvasPattern::eCanvasGradient(Root::from_ref(&*gradient))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -881,7 +880,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
let (sender, receiver) = ipc::channel::<Vec<u8>>().unwrap();
|
let (sender, receiver) = ipc::channel::<Vec<u8>>().unwrap();
|
||||||
let dest_rect = Rect::new(Point2D::new(sx.to_i32().unwrap(), sy.to_i32().unwrap()),
|
let dest_rect = Rect::new(Point2D::new(sx.to_i32().unwrap(), sy.to_i32().unwrap()),
|
||||||
Size2D::new(sw as i32, sh as i32));
|
Size2D::new(sw as i32, sh as i32));
|
||||||
let canvas_size = self.canvas.root().r().get_size();
|
let canvas_size = self.canvas.get_size();
|
||||||
let canvas_size = Size2D::new(canvas_size.width as f64, canvas_size.height as f64);
|
let canvas_size = Size2D::new(canvas_size.width as f64, canvas_size.height as f64);
|
||||||
self.ipc_renderer
|
self.ipc_renderer
|
||||||
.send(CanvasMsg::Canvas2d(Canvas2dMsg::GetImageData(dest_rect, canvas_size, sender)))
|
.send(CanvasMsg::Canvas2d(Canvas2dMsg::GetImageData(dest_rect, canvas_size, sender)))
|
||||||
|
|
|
@ -391,8 +391,7 @@ impl Document {
|
||||||
None => false,
|
None => false,
|
||||||
Some(elements) => {
|
Some(elements) => {
|
||||||
let position = elements.iter()
|
let position = elements.iter()
|
||||||
.map(|elem| elem.root())
|
.position(|element| &**element == to_unregister)
|
||||||
.position(|element| element.r() == to_unregister)
|
|
||||||
.expect("This element should be in registered.");
|
.expect("This element should be in registered.");
|
||||||
elements.remove(position);
|
elements.remove(position);
|
||||||
elements.is_empty()
|
elements.is_empty()
|
||||||
|
@ -428,7 +427,7 @@ impl Document {
|
||||||
let root = root.upcast::<Node>();
|
let root = root.upcast::<Node>();
|
||||||
for node in root.traverse_preorder() {
|
for node in root.traverse_preorder() {
|
||||||
if let Some(elem) = node.downcast() {
|
if let Some(elem) = node.downcast() {
|
||||||
if (*elements)[head].root().r() == elem {
|
if &*(*elements)[head] == elem {
|
||||||
head += 1;
|
head += 1;
|
||||||
}
|
}
|
||||||
if new_node == node.r() || head == elements.len() {
|
if new_node == node.r() || head == elements.len() {
|
||||||
|
@ -685,8 +684,7 @@ impl Document {
|
||||||
// under the mouse.
|
// under the mouse.
|
||||||
for target in prev_mouse_over_targets.iter() {
|
for target in prev_mouse_over_targets.iter() {
|
||||||
if !mouse_over_targets.contains(target) {
|
if !mouse_over_targets.contains(target) {
|
||||||
let target = target.root();
|
let target_ref = &**target;
|
||||||
let target_ref = target.r();
|
|
||||||
if target_ref.get_hover_state() {
|
if target_ref.get_hover_state() {
|
||||||
target_ref.set_hover_state(false);
|
target_ref.set_hover_state(false);
|
||||||
|
|
||||||
|
@ -749,27 +747,27 @@ impl Document {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let target = el.upcast::<EventTarget>();
|
let target = el.upcast::<EventTarget>();
|
||||||
let window = self.window.root();
|
let window = &*self.window;
|
||||||
|
|
||||||
let client_x = Finite::wrap(point.x as f64);
|
let client_x = Finite::wrap(point.x as f64);
|
||||||
let client_y = Finite::wrap(point.y as f64);
|
let client_y = Finite::wrap(point.y as f64);
|
||||||
let page_x = Finite::wrap(point.x as f64 + window.PageXOffset() as f64);
|
let page_x = Finite::wrap(point.x as f64 + window.PageXOffset() as f64);
|
||||||
let page_y = Finite::wrap(point.y as f64 + window.PageYOffset() as f64);
|
let page_y = Finite::wrap(point.y as f64 + window.PageYOffset() as f64);
|
||||||
|
|
||||||
let touch = Touch::new(window.r(), identifier, target,
|
let touch = Touch::new(window, identifier, target,
|
||||||
client_x, client_y, // TODO: Get real screen coordinates?
|
client_x, client_y, // TODO: Get real screen coordinates?
|
||||||
client_x, client_y,
|
client_x, client_y,
|
||||||
page_x, page_y);
|
page_x, page_y);
|
||||||
|
|
||||||
let mut touches = RootedVec::new();
|
let mut touches = RootedVec::new();
|
||||||
touches.push(JS::from_rooted(&touch));
|
touches.push(JS::from_rooted(&touch));
|
||||||
let touches = TouchList::new(window.r(), touches.r());
|
let touches = TouchList::new(window, touches.r());
|
||||||
|
|
||||||
let event = TouchEvent::new(window.r(),
|
let event = TouchEvent::new(window,
|
||||||
event_name,
|
event_name,
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::Cancelable,
|
EventCancelable::Cancelable,
|
||||||
Some(window.r()),
|
Some(window),
|
||||||
0i32,
|
0i32,
|
||||||
&touches, &touches, &touches,
|
&touches, &touches, &touches,
|
||||||
// FIXME: modifier keys
|
// FIXME: modifier keys
|
||||||
|
@ -777,7 +775,7 @@ impl Document {
|
||||||
let event = event.upcast::<Event>();
|
let event = event.upcast::<Event>();
|
||||||
let result = event.fire(target);
|
let result = event.fire(target);
|
||||||
|
|
||||||
window.r().reflow(ReflowGoal::ForDisplay,
|
window.reflow(ReflowGoal::ForDisplay,
|
||||||
ReflowQueryType::NoQuery,
|
ReflowQueryType::NoQuery,
|
||||||
ReflowReason::MouseEvent);
|
ReflowReason::MouseEvent);
|
||||||
result
|
result
|
||||||
|
@ -1089,13 +1087,15 @@ impl Document {
|
||||||
}
|
}
|
||||||
let mut deferred_scripts = self.deferred_scripts.borrow_mut();
|
let mut deferred_scripts = self.deferred_scripts.borrow_mut();
|
||||||
while !deferred_scripts.is_empty() {
|
while !deferred_scripts.is_empty() {
|
||||||
let script = deferred_scripts[0].root();
|
{
|
||||||
|
let script = &*deferred_scripts[0];
|
||||||
// Part of substep 1.
|
// Part of substep 1.
|
||||||
if !script.is_ready_to_be_executed() {
|
if !script.is_ready_to_be_executed() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Substep 2.
|
// Substep 2.
|
||||||
script.execute();
|
script.execute();
|
||||||
|
}
|
||||||
// Substep 3.
|
// Substep 3.
|
||||||
deferred_scripts.remove(0);
|
deferred_scripts.remove(0);
|
||||||
// Substep 4 (implicit).
|
// Substep 4 (implicit).
|
||||||
|
@ -1110,7 +1110,7 @@ impl Document {
|
||||||
// Execute the first in-order asap-executed script if it's ready, repeat as required.
|
// Execute the first in-order asap-executed script if it's ready, repeat as required.
|
||||||
// Re-borrowing the list for each step because it can also be borrowed under execute.
|
// Re-borrowing the list for each step because it can also be borrowed under execute.
|
||||||
while self.asap_in_order_scripts_list.borrow().len() > 0 {
|
while self.asap_in_order_scripts_list.borrow().len() > 0 {
|
||||||
let script = self.asap_in_order_scripts_list.borrow()[0].root();
|
let script = Root::from_ref(&*self.asap_in_order_scripts_list.borrow()[0]);
|
||||||
if !script.r().is_ready_to_be_executed() {
|
if !script.r().is_ready_to_be_executed() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1121,7 +1121,7 @@ impl Document {
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
// Re-borrowing the set for each step because it can also be borrowed under execute.
|
// Re-borrowing the set for each step because it can also be borrowed under execute.
|
||||||
while idx < self.asap_scripts_set.borrow().len() {
|
while idx < self.asap_scripts_set.borrow().len() {
|
||||||
let script = self.asap_scripts_set.borrow()[idx].root();
|
let script = Root::from_ref(&*self.asap_scripts_set.borrow()[idx]);
|
||||||
if !script.r().is_ready_to_be_executed() {
|
if !script.r().is_ready_to_be_executed() {
|
||||||
idx += 1;
|
idx += 1;
|
||||||
continue;
|
continue;
|
||||||
|
@ -1332,7 +1332,7 @@ impl Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_element_by_id(&self, id: &Atom) -> Option<Root<Element>> {
|
pub fn get_element_by_id(&self, id: &Atom) -> Option<Root<Element>> {
|
||||||
self.idmap.borrow().get(&id).map(|ref elements| (*elements)[0].root())
|
self.idmap.borrow().get(&id).map(|ref elements| Root::from_ref(&*(*elements)[0]))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn record_element_state_change(&self, el: &Element, which: ElementState) {
|
pub fn record_element_state_change(&self, el: &Element, which: ElementState) {
|
||||||
|
@ -1925,7 +1925,7 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-defaultview
|
// https://html.spec.whatwg.org/multipage/#dom-document-defaultview
|
||||||
fn DefaultView(&self) -> Root<Window> {
|
fn DefaultView(&self) -> Root<Window> {
|
||||||
self.window.root()
|
Root::from_ref(&*self.window)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
|
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl DOMRectListMethods for DOMRectList {
|
||||||
fn Item(&self, index: u32) -> Option<Root<DOMRect>> {
|
fn Item(&self, index: u32) -> Option<Root<DOMRect>> {
|
||||||
let rects = &self.rects;
|
let rects = &self.rects;
|
||||||
if index < rects.len() as u32 {
|
if index < rects.len() as u32 {
|
||||||
Some(rects[index as usize].root())
|
Some(Root::from_ref(&*rects[index as usize]))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -874,16 +874,15 @@ impl Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
|
pub fn get_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
|
||||||
self.attrs.borrow().iter().map(JS::root).find(|attr| {
|
self.attrs.borrow().iter().find(|attr| {
|
||||||
attr.local_name() == local_name && attr.namespace() == namespace
|
attr.local_name() == local_name && attr.namespace() == namespace
|
||||||
})
|
}).map(|js| Root::from_ref(&**js))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
||||||
pub fn get_attribute_by_name(&self, name: DOMString) -> Option<Root<Attr>> {
|
pub fn get_attribute_by_name(&self, name: DOMString) -> Option<Root<Attr>> {
|
||||||
let name = &self.parsed_name(name);
|
let name = &self.parsed_name(name);
|
||||||
self.attrs.borrow().iter().map(JS::root)
|
self.attrs.borrow().iter().find(|a| a.name() == name).map(|js| Root::from_ref(&**js))
|
||||||
.find(|a| a.r().name() == name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_attribute_from_parser(&self,
|
pub fn set_attribute_from_parser(&self,
|
||||||
|
@ -891,8 +890,8 @@ impl Element {
|
||||||
value: DOMString,
|
value: DOMString,
|
||||||
prefix: Option<Atom>) {
|
prefix: Option<Atom>) {
|
||||||
// Don't set if the attribute already exists, so we can handle add_attrs_if_missing
|
// Don't set if the attribute already exists, so we can handle add_attrs_if_missing
|
||||||
if self.attrs.borrow().iter().map(JS::root)
|
if self.attrs.borrow().iter()
|
||||||
.any(|a| *a.r().local_name() == qname.local && *a.r().namespace() == qname.ns) {
|
.any(|a| *a.local_name() == qname.local && *a.namespace() == qname.ns) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -942,7 +941,8 @@ impl Element {
|
||||||
find: F)
|
find: F)
|
||||||
where F: Fn(&Attr)
|
where F: Fn(&Attr)
|
||||||
-> bool {
|
-> bool {
|
||||||
let attr = self.attrs.borrow().iter().map(JS::root).find(|attr| find(&attr));
|
let attr = self.attrs.borrow().iter()
|
||||||
|
.find(|attr| find(&attr)).map(|js| Root::from_ref(&**js));
|
||||||
if let Some(attr) = attr {
|
if let Some(attr) = attr {
|
||||||
attr.set_value(value, self);
|
attr.set_value(value, self);
|
||||||
} else {
|
} else {
|
||||||
|
@ -973,10 +973,10 @@ impl Element {
|
||||||
fn remove_first_matching_attribute<F>(&self, find: F) -> Option<Root<Attr>>
|
fn remove_first_matching_attribute<F>(&self, find: F) -> Option<Root<Attr>>
|
||||||
where F: Fn(&Attr) -> bool
|
where F: Fn(&Attr) -> bool
|
||||||
{
|
{
|
||||||
let idx = self.attrs.borrow().iter().map(JS::root).position(|attr| find(&attr));
|
let idx = self.attrs.borrow().iter().position(|attr| find(&attr));
|
||||||
|
|
||||||
idx.map(|idx| {
|
idx.map(|idx| {
|
||||||
let attr = (*self.attrs.borrow())[idx].root();
|
let attr = Root::from_ref(&*(*self.attrs.borrow())[idx]);
|
||||||
self.attrs.borrow_mut().remove(idx);
|
self.attrs.borrow_mut().remove(idx);
|
||||||
attr.set_owner(None);
|
attr.set_owner(None);
|
||||||
if attr.namespace() == &ns!("") {
|
if attr.namespace() == &ns!("") {
|
||||||
|
@ -1005,8 +1005,8 @@ impl Element {
|
||||||
|
|
||||||
pub fn has_attribute(&self, local_name: &Atom) -> bool {
|
pub fn has_attribute(&self, local_name: &Atom) -> bool {
|
||||||
assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b));
|
assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b));
|
||||||
self.attrs.borrow().iter().map(JS::root).any(|attr| {
|
self.attrs.borrow().iter().any(|attr| {
|
||||||
attr.r().local_name() == local_name && attr.r().namespace() == &ns!("")
|
attr.local_name() == local_name && attr.namespace() == &ns!("")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1695,7 +1695,7 @@ impl<'a> ::selectors::Element for Root<Element> {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
NamespaceConstraint::Any => {
|
NamespaceConstraint::Any => {
|
||||||
self.attrs.borrow().iter().map(JS::root).any(|attr| {
|
self.attrs.borrow().iter().any(|attr| {
|
||||||
attr.local_name() == local_name && test(&attr.value())
|
attr.local_name() == local_name && test(&attr.value())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ impl FileListMethods for FileList {
|
||||||
|
|
||||||
// https://w3c.github.io/FileAPI/#dfn-item
|
// https://w3c.github.io/FileAPI/#dfn-item
|
||||||
fn Item(&self, index: u32) -> Option<Root<File>> {
|
fn Item(&self, index: u32) -> Option<Root<File>> {
|
||||||
Some(self.list[index as usize].root())
|
Some(Root::from_ref(&*(self.list[index as usize])))
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
|
|
|
@ -90,7 +90,7 @@ impl FormDataMethods for FormData {
|
||||||
.get(&name)
|
.get(&name)
|
||||||
.map(|entry| match entry[0] {
|
.map(|entry| match entry[0] {
|
||||||
FormDatum::StringData(ref s) => eString(s.clone()),
|
FormDatum::StringData(ref s) => eString(s.clone()),
|
||||||
FormDatum::FileData(ref f) => eFile(f.root()),
|
FormDatum::FileData(ref f) => eFile(Root::from_ref(&*f)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ impl HTMLCanvasElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
match *self.context.borrow().as_ref().unwrap() {
|
match *self.context.borrow().as_ref().unwrap() {
|
||||||
CanvasContext::Context2d(ref context) => Some(context.root()),
|
CanvasContext::Context2d(ref context) => Some(Root::from_ref(&*context)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ impl HTMLCanvasElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() {
|
if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() {
|
||||||
Some(context.root())
|
Some(Root::from_ref(&*context))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ impl HTMLCollection {
|
||||||
|
|
||||||
pub fn elements_iter(&self) -> HTMLCollectionElementsIter {
|
pub fn elements_iter(&self) -> HTMLCollectionElementsIter {
|
||||||
let ref filter = self.collection.1;
|
let ref filter = self.collection.1;
|
||||||
let root = self.collection.0.root();
|
let root = Root::from_ref(&*self.collection.0);
|
||||||
let mut node_iter = root.traverse_preorder();
|
let mut node_iter = root.traverse_preorder();
|
||||||
let _ = node_iter.next(); // skip the root node
|
let _ = node_iter.next(); // skip the root node
|
||||||
HTMLCollectionElementsIter {
|
HTMLCollectionElementsIter {
|
||||||
|
|
|
@ -360,8 +360,8 @@ impl HTMLElement {
|
||||||
|
|
||||||
pub fn supported_prop_names_custom_attr(&self) -> Vec<DOMString> {
|
pub fn supported_prop_names_custom_attr(&self) -> Vec<DOMString> {
|
||||||
let element = self.upcast::<Element>();
|
let element = self.upcast::<Element>();
|
||||||
element.attrs().iter().map(JS::root).filter_map(|attr| {
|
element.attrs().iter().filter_map(|attr| {
|
||||||
let raw_name = attr.r().local_name();
|
let raw_name = attr.local_name();
|
||||||
to_camel_case(&raw_name)
|
to_camel_case(&raw_name)
|
||||||
}).collect()
|
}).collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -364,7 +364,7 @@ impl HTMLScriptElement {
|
||||||
|
|
||||||
// Step 1.
|
// Step 1.
|
||||||
let doc = document_from_node(self);
|
let doc = document_from_node(self);
|
||||||
if self.parser_inserted.get() && doc.r() != self.parser_document.root().r() {
|
if self.parser_inserted.get() && &*doc != &*self.parser_document {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl NamedNodeMapMethods for NamedNodeMap {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-namednodemap-item
|
// https://dom.spec.whatwg.org/#dom-namednodemap-item
|
||||||
fn Item(&self, index: u32) -> Option<Root<Attr>> {
|
fn Item(&self, index: u32) -> Option<Root<Attr>> {
|
||||||
self.owner.attrs().get(index as usize).map(JS::root)
|
self.owner.attrs().get(index as usize).map(|js| Root::from_ref(&**js))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-namednodemap-getnameditem
|
// https://dom.spec.whatwg.org/#dom-namednodemap-getnameditem
|
||||||
|
@ -87,7 +87,7 @@ impl NamedNodeMapMethods for NamedNodeMap {
|
||||||
|
|
||||||
// https://heycam.github.io/webidl/#dfn-supported-property-names
|
// https://heycam.github.io/webidl/#dfn-supported-property-names
|
||||||
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
|
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
|
||||||
self.owner.attrs().iter().map(JS::root).map(|attr| {
|
self.owner.attrs().iter().map(|attr| {
|
||||||
(**attr.name()).to_owned()
|
(**attr.name()).to_owned()
|
||||||
}).collect()
|
}).collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1648,7 +1648,7 @@ impl Node {
|
||||||
let node_elem = node.downcast::<Element>().unwrap();
|
let node_elem = node.downcast::<Element>().unwrap();
|
||||||
let copy_elem = copy.downcast::<Element>().unwrap();
|
let copy_elem = copy.downcast::<Element>().unwrap();
|
||||||
|
|
||||||
for attr in node_elem.attrs().iter().map(JS::root) {
|
for attr in node_elem.attrs().iter() {
|
||||||
copy_elem.push_new_attribute(attr.local_name().clone(),
|
copy_elem.push_new_attribute(attr.local_name().clone(),
|
||||||
attr.value().clone(),
|
attr.value().clone(),
|
||||||
attr.name().clone(),
|
attr.name().clone(),
|
||||||
|
@ -1719,12 +1719,10 @@ impl Node {
|
||||||
let prefix_atom = prefix.as_ref().map(|s| Atom::from_slice(s));
|
let prefix_atom = prefix.as_ref().map(|s| Atom::from_slice(s));
|
||||||
|
|
||||||
// Step 2.
|
// Step 2.
|
||||||
let namespace_attr =
|
let attrs = element.attrs();
|
||||||
element.attrs()
|
let namespace_attr = attrs.iter().find(|attr| {
|
||||||
.iter()
|
attr_defines_namespace(attr, &prefix_atom)
|
||||||
.map(|attr| attr.root())
|
});
|
||||||
.find(|attr| attr_defines_namespace(attr.r(),
|
|
||||||
&prefix_atom));
|
|
||||||
|
|
||||||
// Steps 2.1-2.
|
// Steps 2.1-2.
|
||||||
if let Some(attr) = namespace_attr {
|
if let Some(attr) = namespace_attr {
|
||||||
|
@ -2154,12 +2152,10 @@ impl NodeMethods for Node {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attrs = element.attrs();
|
let attrs = element.attrs();
|
||||||
attrs.iter().all(|attr| {
|
attrs.iter().all(|attr| {
|
||||||
let attr = attr.root();
|
|
||||||
other_element.attrs().iter().any(|other_attr| {
|
other_element.attrs().iter().any(|other_attr| {
|
||||||
let other_attr = other_attr.root();
|
(*attr.namespace() == *other_attr.namespace()) &&
|
||||||
(*attr.r().namespace() == *other_attr.r().namespace()) &&
|
(attr.local_name() == other_attr.local_name()) &&
|
||||||
(attr.r().local_name() == other_attr.r().local_name()) &&
|
(**attr.value() == **other_attr.value())
|
||||||
(**attr.r().value() == **other_attr.r().value())
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ impl NodeIterator {
|
||||||
impl NodeIteratorMethods for NodeIterator {
|
impl NodeIteratorMethods for NodeIterator {
|
||||||
// https://dom.spec.whatwg.org/#dom-nodeiterator-root
|
// https://dom.spec.whatwg.org/#dom-nodeiterator-root
|
||||||
fn Root(&self) -> Root<Node> {
|
fn Root(&self) -> Root<Node> {
|
||||||
self.root_node.root()
|
Root::from_ref(&*self.root_node)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-nodeiterator-whattoshow
|
// https://dom.spec.whatwg.org/#dom-nodeiterator-whattoshow
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl NodeListMethods for NodeList {
|
||||||
fn Item(&self, index: u32) -> Option<Root<Node>> {
|
fn Item(&self, index: u32) -> Option<Root<Node>> {
|
||||||
match self.list_type {
|
match self.list_type {
|
||||||
NodeListType::Simple(ref elems) => {
|
NodeListType::Simple(ref elems) => {
|
||||||
elems.get(index as usize).map(|node| node.root())
|
elems.get(index as usize).map(|node| Root::from_ref(&**node))
|
||||||
},
|
},
|
||||||
NodeListType::Children(ref list) => list.item(index),
|
NodeListType::Children(ref list) => list.item(index),
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl Performance {
|
||||||
impl PerformanceMethods for Performance {
|
impl PerformanceMethods for Performance {
|
||||||
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html#performance-timing-attribute
|
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html#performance-timing-attribute
|
||||||
fn Timing(&self) -> Root<PerformanceTiming> {
|
fn Timing(&self) -> Root<PerformanceTiming> {
|
||||||
self.timing.root()
|
Root::from_ref(&*self.timing)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighResolutionTime/Overview.html#dom-performance-now
|
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighResolutionTime/Overview.html#dom-performance-now
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl Sink {
|
||||||
#[allow(unrooted_must_root)] // method is only run at parse time
|
#[allow(unrooted_must_root)] // method is only run at parse time
|
||||||
pub fn get_or_create(&self, child: NodeOrText<JS<Node>>) -> Root<Node> {
|
pub fn get_or_create(&self, child: NodeOrText<JS<Node>>) -> Root<Node> {
|
||||||
match child {
|
match child {
|
||||||
NodeOrText::AppendNode(n) => n.root(),
|
NodeOrText::AppendNode(n) => Root::from_ref(&*n),
|
||||||
NodeOrText::AppendText(t) => {
|
NodeOrText::AppendText(t) => {
|
||||||
let text = Text::new(t.into(), &self.document);
|
let text = Text::new(t.into(), &self.document);
|
||||||
Root::upcast(text)
|
Root::upcast(text)
|
||||||
|
|
|
@ -38,7 +38,7 @@ impl TouchListMethods for TouchList {
|
||||||
|
|
||||||
/// https://w3c.github.io/touch-events/#widl-TouchList-item-getter-Touch-unsigned-long-index
|
/// https://w3c.github.io/touch-events/#widl-TouchList-item-getter-Touch-unsigned-long-index
|
||||||
fn Item(&self, index: u32) -> Option<Root<Touch>> {
|
fn Item(&self, index: u32) -> Option<Root<Touch>> {
|
||||||
self.touches.get(index as usize).map(JS::root)
|
self.touches.get(index as usize).map(|js| Root::from_ref(&**js))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://w3c.github.io/touch-events/#widl-TouchList-item-getter-Touch-unsigned-long-index
|
/// https://w3c.github.io/touch-events/#widl-TouchList-item-getter-Touch-unsigned-long-index
|
||||||
|
|
|
@ -65,7 +65,7 @@ impl TreeWalker {
|
||||||
impl TreeWalkerMethods for TreeWalker {
|
impl TreeWalkerMethods for TreeWalker {
|
||||||
// https://dom.spec.whatwg.org/#dom-treewalker-root
|
// https://dom.spec.whatwg.org/#dom-treewalker-root
|
||||||
fn Root(&self) -> Root<Node> {
|
fn Root(&self) -> Root<Node> {
|
||||||
self.root_node.root()
|
Root::from_ref(&*self.root_node)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-treewalker-whattoshow
|
// https://dom.spec.whatwg.org/#dom-treewalker-whattoshow
|
||||||
|
|
|
@ -153,7 +153,7 @@ impl WebGLRenderingContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_as_dirty(&self) {
|
fn mark_as_dirty(&self) {
|
||||||
self.canvas.root().upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
self.canvas.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ impl Drop for WebGLRenderingContext {
|
||||||
impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.1
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.1
|
||||||
fn Canvas(&self) -> Root<HTMLCanvasElement> {
|
fn Canvas(&self) -> Root<HTMLCanvasElement> {
|
||||||
self.canvas.root()
|
Root::from_ref(&*self.canvas)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.1
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.1
|
||||||
|
@ -848,8 +848,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let canvas = self.canvas.root();
|
let window = window_from_node(&*self.canvas);
|
||||||
let window = window_from_node(canvas.r());
|
|
||||||
|
|
||||||
let img = match canvas_utils::request_image_from_cache(window.r(), img_url) {
|
let img = match canvas_utils::request_image_from_cache(window.r(), img_url) {
|
||||||
ImageResponse::Loaded(img) => img,
|
ImageResponse::Loaded(img) => img,
|
||||||
|
|
|
@ -465,7 +465,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
||||||
|
|
||||||
// https://xhr.spec.whatwg.org/#the-upload-attribute
|
// https://xhr.spec.whatwg.org/#the-upload-attribute
|
||||||
fn Upload(&self) -> Root<XMLHttpRequestUpload> {
|
fn Upload(&self) -> Root<XMLHttpRequestUpload> {
|
||||||
self.upload.root()
|
Root::from_ref(&*self.upload)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://xhr.spec.whatwg.org/#the-send()-method
|
// https://xhr.spec.whatwg.org/#the-send()-method
|
||||||
|
|
|
@ -68,11 +68,11 @@ impl Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn window(&self) -> Root<Window> {
|
pub fn window(&self) -> Root<Window> {
|
||||||
self.frame.borrow().as_ref().unwrap().window.root()
|
Root::from_ref(&*self.frame.borrow().as_ref().unwrap().window)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn document(&self) -> Root<Document> {
|
pub fn document(&self) -> Root<Document> {
|
||||||
self.frame.borrow().as_ref().unwrap().document.root()
|
Root::from_ref(&*self.frame.borrow().as_ref().unwrap().document)
|
||||||
}
|
}
|
||||||
|
|
||||||
// must handle root case separately
|
// must handle root case separately
|
||||||
|
|
|
@ -10,8 +10,7 @@ use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateEl
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId};
|
use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId};
|
||||||
use dom::bindings::conversions::Castable;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::{JS, Root};
|
use dom::bindings::js::{JS, RootedReference};
|
||||||
use dom::bindings::js::{RootedReference};
|
|
||||||
use dom::characterdata::CharacterData;
|
use dom::characterdata::CharacterData;
|
||||||
use dom::comment::Comment;
|
use dom::comment::Comment;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
|
@ -45,11 +44,10 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
type Handle = JS<Node>;
|
type Handle = JS<Node>;
|
||||||
|
|
||||||
fn get_document(&mut self) -> JS<Node> {
|
fn get_document(&mut self) -> JS<Node> {
|
||||||
JS::from_ref(self.document.root().upcast())
|
JS::from_ref(self.document.upcast())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_template_contents(&self, target: JS<Node>) -> JS<Node> {
|
fn get_template_contents(&self, target: JS<Node>) -> JS<Node> {
|
||||||
let target = target.root();
|
|
||||||
let template = target.downcast::<HTMLTemplateElement>()
|
let template = target.downcast::<HTMLTemplateElement>()
|
||||||
.expect("tried to get template contents of non-HTMLTemplateElement in HTML parsing");
|
.expect("tried to get template contents of non-HTMLTemplateElement in HTML parsing");
|
||||||
JS::from_ref(template.Content().upcast())
|
JS::from_ref(template.Content().upcast())
|
||||||
|
@ -60,8 +58,7 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn elem_name(&self, target: JS<Node>) -> QualName {
|
fn elem_name(&self, target: JS<Node>) -> QualName {
|
||||||
let node: Root<Node> = target.root();
|
let elem = target.downcast::<Element>()
|
||||||
let elem = node.downcast::<Element>()
|
|
||||||
.expect("tried to get name of non-Element in HTML parsing");
|
.expect("tried to get name of non-Element in HTML parsing");
|
||||||
QualName {
|
QualName {
|
||||||
ns: elem.namespace().clone(),
|
ns: elem.namespace().clone(),
|
||||||
|
@ -71,8 +68,7 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
|
|
||||||
fn create_element(&mut self, name: QualName, attrs: Vec<Attribute>)
|
fn create_element(&mut self, name: QualName, attrs: Vec<Attribute>)
|
||||||
-> JS<Node> {
|
-> JS<Node> {
|
||||||
let doc = self.document.root();
|
let elem = Element::create(name, None, &*self.document,
|
||||||
let elem = Element::create(name, None, doc.r(),
|
|
||||||
ElementCreator::ParserCreated);
|
ElementCreator::ParserCreated);
|
||||||
|
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
|
@ -83,8 +79,7 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_comment(&mut self, text: StrTendril) -> JS<Node> {
|
fn create_comment(&mut self, text: StrTendril) -> JS<Node> {
|
||||||
let doc = self.document.root();
|
let comment = Comment::new(text.into(), &*self.document);
|
||||||
let comment = Comment::new(text.into(), doc.r());
|
|
||||||
JS::from_ref(comment.upcast())
|
JS::from_ref(comment.upcast())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,14 +87,13 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
sibling: JS<Node>,
|
sibling: JS<Node>,
|
||||||
new_node: NodeOrText<JS<Node>>) -> Result<(), NodeOrText<JS<Node>>> {
|
new_node: NodeOrText<JS<Node>>) -> Result<(), NodeOrText<JS<Node>>> {
|
||||||
// If there is no parent, return the node to the parser.
|
// If there is no parent, return the node to the parser.
|
||||||
let sibling: Root<Node> = sibling.root();
|
let parent = match sibling.GetParentNode() {
|
||||||
let parent = match sibling.r().GetParentNode() {
|
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => return Err(new_node),
|
None => return Err(new_node),
|
||||||
};
|
};
|
||||||
|
|
||||||
let child = self.get_or_create(new_node);
|
let child = self.get_or_create(new_node);
|
||||||
assert!(parent.r().InsertBefore(child.r(), Some(sibling.r())).is_ok());
|
assert!(parent.r().InsertBefore(child.r(), Some(&*sibling)).is_ok());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,29 +102,26 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_quirks_mode(&mut self, mode: QuirksMode) {
|
fn set_quirks_mode(&mut self, mode: QuirksMode) {
|
||||||
let doc = self.document.root();
|
self.document.set_quirks_mode(mode);
|
||||||
doc.r().set_quirks_mode(mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append(&mut self, parent: JS<Node>, child: NodeOrText<JS<Node>>) {
|
fn append(&mut self, parent: JS<Node>, child: NodeOrText<JS<Node>>) {
|
||||||
let parent: Root<Node> = parent.root();
|
|
||||||
let child = self.get_or_create(child);
|
let child = self.get_or_create(child);
|
||||||
|
|
||||||
// FIXME(#3701): Use a simpler algorithm and merge adjacent text nodes
|
// FIXME(#3701): Use a simpler algorithm and merge adjacent text nodes
|
||||||
assert!(parent.r().AppendChild(child.r()).is_ok());
|
assert!(parent.AppendChild(child.r()).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append_doctype_to_document(&mut self, name: StrTendril, public_id: StrTendril,
|
fn append_doctype_to_document(&mut self, name: StrTendril, public_id: StrTendril,
|
||||||
system_id: StrTendril) {
|
system_id: StrTendril) {
|
||||||
let doc = self.document.root();
|
let doc = &*self.document;
|
||||||
let doctype = DocumentType::new(
|
let doctype = DocumentType::new(
|
||||||
name.into(), Some(public_id.into()), Some(system_id.into()), doc.r());
|
name.into(), Some(public_id.into()), Some(system_id.into()), doc);
|
||||||
doc.upcast::<Node>().AppendChild(doctype.upcast()).expect("Appending failed");
|
doc.upcast::<Node>().AppendChild(doctype.upcast()).expect("Appending failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_attrs_if_missing(&mut self, target: JS<Node>, attrs: Vec<Attribute>) {
|
fn add_attrs_if_missing(&mut self, target: JS<Node>, attrs: Vec<Attribute>) {
|
||||||
let node: Root<Node> = target.root();
|
let elem = target.downcast::<Element>()
|
||||||
let elem = node.downcast::<Element>()
|
|
||||||
.expect("tried to set attrs on non-Element in HTML parsing");
|
.expect("tried to set attrs on non-Element in HTML parsing");
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
elem.set_attribute_from_parser(attr.name, attr.value.into(), None);
|
elem.set_attribute_from_parser(attr.name, attr.value.into(), None);
|
||||||
|
@ -138,20 +129,17 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_from_parent(&mut self, target: JS<Node>) {
|
fn remove_from_parent(&mut self, target: JS<Node>) {
|
||||||
let node = target.root();
|
if let Some(ref parent) = target.GetParentNode() {
|
||||||
if let Some(ref parent) = node.r().GetParentNode() {
|
parent.r().RemoveChild(&*target).unwrap();
|
||||||
parent.r().RemoveChild(node.r()).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_script_already_started(&mut self, node: JS<Node>) {
|
fn mark_script_already_started(&mut self, node: JS<Node>) {
|
||||||
let node: Root<Node> = node.root();
|
|
||||||
let script = node.downcast::<HTMLScriptElement>();
|
let script = node.downcast::<HTMLScriptElement>();
|
||||||
script.map(|script| script.mark_already_started());
|
script.map(|script| script.mark_already_started());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_script(&mut self, node: JS<Node>) -> NextParserState {
|
fn complete_script(&mut self, node: JS<Node>) -> NextParserState {
|
||||||
let node: Root<Node> = node.root();
|
|
||||||
let script = node.downcast::<HTMLScriptElement>();
|
let script = node.downcast::<HTMLScriptElement>();
|
||||||
if let Some(script) = script {
|
if let Some(script) = script {
|
||||||
return script.prepare();
|
return script.prepare();
|
||||||
|
@ -160,11 +148,7 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reparent_children(&mut self, node: JS<Node>, new_parent: JS<Node>) {
|
fn reparent_children(&mut self, node: JS<Node>, new_parent: JS<Node>) {
|
||||||
let new_parent = new_parent.root();
|
while let Some(ref child) = node.GetFirstChild() {
|
||||||
let new_parent = new_parent.r();
|
|
||||||
let old_parent = node.root();
|
|
||||||
let old_parent = old_parent.r();
|
|
||||||
while let Some(ref child) = old_parent.GetFirstChild() {
|
|
||||||
new_parent.AppendChild(child.r()).unwrap();
|
new_parent.AppendChild(child.r()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,11 +165,10 @@ impl<'a> Serializable for &'a Node {
|
||||||
let name = QualName::new(elem.namespace().clone(),
|
let name = QualName::new(elem.namespace().clone(),
|
||||||
elem.local_name().clone());
|
elem.local_name().clone());
|
||||||
if traversal_scope == IncludeNode {
|
if traversal_scope == IncludeNode {
|
||||||
let attrs = elem.attrs().iter().map(|at| {
|
let attrs = elem.attrs().iter().map(|attr| {
|
||||||
let attr = at.root();
|
let qname = QualName::new(attr.namespace().clone(),
|
||||||
let qname = QualName::new(attr.r().namespace().clone(),
|
attr.local_name().clone());
|
||||||
attr.r().local_name().clone());
|
let value = attr.value().clone();
|
||||||
let value = attr.r().value().clone();
|
|
||||||
(qname, value)
|
(qname, value)
|
||||||
}).collect::<Vec<_>>();
|
}).collect::<Vec<_>>();
|
||||||
let attr_refs = attrs.iter().map(|&(ref qname, ref value)| {
|
let attr_refs = attrs.iter().map(|&(ref qname, ref value)| {
|
||||||
|
|
|
@ -1747,9 +1747,8 @@ impl ScriptTask {
|
||||||
|
|
||||||
// Notify Constellation about the topmost anchor mouse over target.
|
// Notify Constellation about the topmost anchor mouse over target.
|
||||||
for target in &*mouse_over_targets {
|
for target in &*mouse_over_targets {
|
||||||
let target = target.root();
|
|
||||||
if target.upcast::<Node>().is_anchor_element() {
|
if target.upcast::<Node>().is_anchor_element() {
|
||||||
let status = target.r().get_attribute(&ns!(""), &atom!("href"))
|
let status = target.get_attribute(&ns!(""), &atom!("href"))
|
||||||
.and_then(|href| {
|
.and_then(|href| {
|
||||||
let value = href.value();
|
let value = href.value();
|
||||||
let url = document.r().url();
|
let url = document.r().url();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue