aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/window.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2014-12-29 11:57:45 -0700
committerbors-servo <metajack+bors@gmail.com>2014-12-29 11:57:45 -0700
commit2c259f477c41331e66beab8bda865971982a1ff4 (patch)
tree12b1b56eec1482d6b6e31e85383a309856a39dc7 /components/script/dom/window.rs
parentf76a460c53dfddef74262eceaf4b163b551adc08 (diff)
parent9a7cd3113403fe44a8919f049720b67bfa92c9f1 (diff)
downloadservo-2c259f477c41331e66beab8bda865971982a1ff4.tar.gz
servo-2c259f477c41331e66beab8bda865971982a1ff4.zip
auto merge of #4057 : jdm/servo/refcountdom, r=Ms2ger
This replaces the specialized TrustedXHRAddress and TrustedWorkerAddress code that was used for the same purpose. A non-zero refcount pins the given DOM object's reflector and prevents it from being GCed even when there are no other outstanding references visible to SpiderMonkey. This will enable us to implement asynchronous operations that refer to particular DOM objects (such as "queue a task to fire a simple event named load at the iframe element" from the spec) safely and conveniently, and paves the way for things like asynchronous network responses. Some concerns about the resulting size of XHR progress messages have been expressed, but I believe optimizations to reduce that can be implemented in subsequent PRs. r? @Ms2ger - note in particular the changes to the worker lifetime code. I couldn't figure out how to achieve an identical lifetime to the previous addref/release pairing, and I also was having trouble figuring out why the existing setup was safe. The new implementation now holds the main script task Worker object alive via the TrustedWorkerAddress field in the dedicated worker global scope, which is a significant difference.
Diffstat (limited to 'components/script/dom/window.rs')
-rw-r--r--components/script/dom/window.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 21afb9e59af..7b7cc679461 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -52,7 +52,7 @@ use time;
#[dom_struct]
pub struct Window {
eventtarget: EventTarget,
- script_chan: ScriptChan,
+ script_chan: Box<ScriptChan+Send>,
control_chan: ScriptControlChan,
console: MutNullableJS<Console>,
location: MutNullableJS<Location>,
@@ -75,8 +75,8 @@ impl Window {
(*js_info.as_ref().unwrap().js_context).ptr
}
- pub fn script_chan<'a>(&'a self) -> &'a ScriptChan {
- &self.script_chan
+ pub fn script_chan(&self) -> Box<ScriptChan+Send> {
+ self.script_chan.clone()
}
pub fn control_chan<'a>(&'a self) -> &'a ScriptControlChan {
@@ -189,8 +189,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
}
fn Close(self) {
- let ScriptChan(ref chan) = self.script_chan;
- chan.send(ScriptMsg::ExitWindow(self.page.id.clone()));
+ self.script_chan.send(ScriptMsg::ExitWindow(self.page.id.clone()));
}
fn Document(self) -> Temporary<Document> {
@@ -342,11 +341,10 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
let url = UrlParser::new().base_url(&base_url).parse(href.as_slice());
// FIXME: handle URL parse errors more gracefully.
let url = url.unwrap();
- let ScriptChan(ref script_chan) = self.script_chan;
if href.as_slice().starts_with("#") {
- script_chan.send(ScriptMsg::TriggerFragment(self.page.id, url));
+ self.script_chan.send(ScriptMsg::TriggerFragment(self.page.id, url));
} else {
- script_chan.send(ScriptMsg::TriggerLoad(self.page.id, LoadData::new(url)));
+ self.script_chan.send(ScriptMsg::TriggerLoad(self.page.id, LoadData::new(url)));
}
}
@@ -359,7 +357,7 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
impl Window {
pub fn new(cx: *mut JSContext,
page: Rc<Page>,
- script_chan: ScriptChan,
+ script_chan: Box<ScriptChan+Send>,
control_chan: ScriptControlChan,
compositor: Box<ScriptListener+'static>,
image_cache_task: ImageCacheTask)