Skip to content

Commit

Permalink
Convert as many of Page's RefCell fields to Cell as possible (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
gurobokum authored and Ms2ger committed May 9, 2014
1 parent eb67f69 commit 04c807d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
8 changes: 7 additions & 1 deletion src/components/script/dom/bindings/trace.rs
Expand Up @@ -10,7 +10,7 @@ use js::jsval::JSVal;

use libc;
use std::cast;
use std::cell::RefCell;
use std::cell::{Cell, RefCell};
use std::ptr;
use std::ptr::null;
use serialize::{Encodable, Encoder};
Expand Down Expand Up @@ -142,6 +142,12 @@ impl<S: Encoder<E>, E, T: Encodable<S, E>> Encodable<S, E> for Traceable<RefCell
}
}

impl<S: Encoder<E>, E, T: Encodable<S, E>+Copy> Encodable<S, E> for Traceable<Cell<T>> {
fn encode(&self, s: &mut S) -> Result<(), E> {
self.deref().get().encode(s)
}
}

impl<S: Encoder<E>, E> Encodable<S, E> for Traceable<*JSObject> {
fn encode(&self, s: &mut S) -> Result<(), E> {
trace_object(get_jstracer(s), "object", **self);
Expand Down
2 changes: 1 addition & 1 deletion src/components/script/html/hubbub_html_parser.rs
Expand Up @@ -252,7 +252,7 @@ pub fn parse_html(page: &Page,
resource_task: ResourceTask)
-> HtmlParserResult {
debug!("Hubbub: parsing {:?}", url);
let next_subpage_id: SubpageId = *page.next_subpage_id.deref().borrow();
let next_subpage_id: SubpageId = page.next_subpage_id.deref().get();
// Spawn a CSS parser to receive links to CSS style sheets.

let (discovery_chan, discovery_port) = channel();
Expand Down
52 changes: 24 additions & 28 deletions src/components/script/script_task.rs
Expand Up @@ -54,7 +54,7 @@ use servo_util::url::parse_url;
use servo_util::task::send_on_failure;
use servo_util::namespace::Null;
use std::cast;
use std::cell::{RefCell, Ref, RefMut};
use std::cell::{Cell, RefCell, Ref, RefMut};
use std::comm::{channel, Sender, Receiver, Empty, Disconnected, Data};
use std::local_data;
use std::mem::replace;
Expand Down Expand Up @@ -122,7 +122,7 @@ pub struct Page {
pub id: PipelineId,

/// Unique id for last reflow request; used for confirming completion reply.
pub last_reflow_id: Traceable<RefCell<uint>>,
pub last_reflow_id: Traceable<Cell<uint>>,

/// The outermost frame containing the document, window, and page URL.
pub frame: Traceable<RefCell<Option<Frame>>>,
Expand All @@ -137,7 +137,7 @@ pub struct Page {
pub damage: Traceable<RefCell<Option<DocumentDamage>>>,

/// The current size of the window, in pixels.
pub window_size: Untraceable<RefCell<Size2D<uint>>>,
pub window_size: Untraceable<Cell<Size2D<uint>>>,

pub js_info: Traceable<RefCell<Option<JSPageInfo>>>,

Expand All @@ -147,10 +147,10 @@ pub struct Page {
/// when reloading.
pub url: Untraceable<RefCell<Option<(Url, bool)>>>,

pub next_subpage_id: Untraceable<RefCell<SubpageId>>,
pub next_subpage_id: Untraceable<Cell<SubpageId>>,

/// Pending resize event, if any.
pub resize_event: Untraceable<RefCell<Option<Size2D<uint>>>>,
pub resize_event: Untraceable<Cell<Option<Size2D<uint>>>>,

/// Pending scroll to fragment event, if any
pub fragment_node: Traceable<RefCell<Option<JS<Element>>>>,
Expand Down Expand Up @@ -178,13 +178,13 @@ impl PageTree {
layout_chan: Untraceable::new(layout_chan),
layout_join_port: Untraceable::new(RefCell::new(None)),
damage: Traceable::new(RefCell::new(None)),
window_size: Untraceable::new(RefCell::new(window_size)),
window_size: Untraceable::new(Cell::new(window_size)),
js_info: Traceable::new(RefCell::new(None)),
url: Untraceable::new(RefCell::new(None)),
next_subpage_id: Untraceable::new(RefCell::new(SubpageId(0))),
resize_event: Untraceable::new(RefCell::new(None)),
next_subpage_id: Untraceable::new(Cell::new(SubpageId(0))),
resize_event: Untraceable::new(Cell::new(None)),
fragment_node: Traceable::new(RefCell::new(None)),
last_reflow_id: Traceable::new(RefCell::new(0)),
last_reflow_id: Traceable::new(Cell::new(0)),
resource_task: Untraceable::new(resource_task)
}),
inner: vec!(),
Expand Down Expand Up @@ -387,23 +387,23 @@ impl Page {
let mut layout_join_port = self.layout_join_port.deref().borrow_mut();
*layout_join_port = Some(join_port);

let mut last_reflow_id = self.last_reflow_id.deref().borrow_mut();
*last_reflow_id += 1;
let last_reflow_id = self.last_reflow_id.deref();
last_reflow_id.set(last_reflow_id.get() + 1);

let root: &JSRef<Node> = NodeCast::from_ref(&*root);
let mut damage = self.damage.deref().borrow_mut();
let window_size = self.window_size.deref().borrow();
let window_size = self.window_size.deref().get();

// Send new document and relevant styles to layout.
let reflow = ~Reflow {
document_root: root.to_trusted_node_address(),
url: self.get_url(),
goal: goal,
window_size: *window_size,
window_size: window_size,
script_chan: script_chan,
script_join_chan: join_chan,
damage: replace(&mut *damage, None).unwrap(),
id: *last_reflow_id,
id: last_reflow_id.get(),
};

let LayoutChan(ref chan) = *self.layout_chan;
Expand Down Expand Up @@ -708,11 +708,12 @@ impl ScriptTask {
// Only process a resize if layout is idle.
let layout_join_port = page.layout_join_port.deref().borrow();
if layout_join_port.is_none() {
let mut resize_event = page.resize_event.deref().borrow_mut();
let mut resize_event = page.resize_event.deref().get();
match resize_event.take() {
Some(size) => resizes.push((page.id, size)),
None => ()
}
page.resize_event.deref().set(None);
}
}
}
Expand All @@ -732,8 +733,7 @@ impl ScriptTask {
ResizeMsg(id, size) => {
let mut page_tree = self.page_tree.borrow_mut();
let page = page_tree.find(id).expect("resize sent to nonexistent pipeline").page();
let mut resize_event = page.resize_event.deref().borrow_mut();
*resize_event = Some(size);
page.resize_event.deref().set(Some(size));
}
_ => {
sequential.push(event);
Expand Down Expand Up @@ -779,8 +779,8 @@ impl ScriptTask {
whose parent has a PipelineId which does not correspond to a pipeline in the script
task's page tree. This is a bug.");
let new_page_tree = {
let window_size = parent_page_tree.page().window_size.deref().borrow();
PageTree::new(new_id, layout_chan, *window_size,
let window_size = parent_page_tree.page().window_size.deref().get();
PageTree::new(new_id, layout_chan, window_size,
parent_page_tree.page().resource_task.deref().clone())
};
parent_page_tree.inner.push(new_page_tree);
Expand Down Expand Up @@ -827,8 +827,8 @@ impl ScriptTask {
let page = page_tree.find(pipeline_id).expect(
"ScriptTask: received a load message for a layout channel that is not associated \
with this script task. This is a bug.").page();
let last_reflow_id = page.last_reflow_id.deref().borrow();
if *last_reflow_id == reflow_id {
let last_reflow_id = page.last_reflow_id.deref().get();
if last_reflow_id == reflow_id {
let mut layout_join_port = page.layout_join_port.deref().borrow_mut();
*layout_join_port = None;
}
Expand All @@ -847,8 +847,7 @@ impl ScriptTask {
let mut page_tree = self.page_tree.borrow_mut();
let page = page_tree.find(id).expect("Received resize message for PipelineId not associated
with a page in the page tree. This is a bug.").page();
let mut window_size = page.window_size.deref().borrow_mut();
*window_size = new_size;
page.window_size.deref().set(new_size);
let mut page_url = page.mut_url();
let last_loaded_url = replace(&mut *page_url, None);
for url in last_loaded_url.iter() {
Expand Down Expand Up @@ -977,7 +976,7 @@ impl ScriptTask {
}
Some(HtmlDiscoveredIFrame((iframe_url, subpage_id, sandboxed))) => {
let SubpageId(num) = subpage_id;
*page.next_subpage_id.deref().borrow_mut() = SubpageId(num + 1);
page.next_subpage_id.deref().set(SubpageId(num + 1));
let sandboxed = if sandboxed {
IFrameSandboxed
} else {
Expand Down Expand Up @@ -1068,10 +1067,7 @@ impl ScriptTask {
let window = {
let mut page_tree = self.page_tree.borrow_mut();
let page = get_page(&mut *page_tree, pipeline_id);
{
let mut window_size = page.window_size.deref().borrow_mut();
*window_size = Size2D(new_width, new_height);
}
page.window_size.deref().set(Size2D(new_width, new_height));

let frame = page.frame();
if frame.is_some() {
Expand Down

5 comments on commit 04c807d

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at Ms2ger@04c807d

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Ms2ger/servo/1990-Page-RefCell = 04c807d into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ms2ger/servo/1990-Page-RefCell = 04c807d merged ok, testing candidate = d985b6d

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = d985b6d

Please sign in to comment.