aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdit Balint <edbalint@inf.u-szeged.hu>2014-07-16 11:36:18 +0200
committerEdit Balint <edbalint@inf.u-szeged.hu>2014-07-16 11:36:18 +0200
commit0b5a1b2ad9932ed709cae65abbdc104d8e61045c (patch)
treefb521568717eabd9cd42b54a52d9338b7d6f8760 /src
parente8996d5ce57c473c33b3bf5c140f7e91dd811e91 (diff)
downloadservo-0b5a1b2ad9932ed709cae65abbdc104d8e61045c.tar.gz
servo-0b5a1b2ad9932ed709cae65abbdc104d8e61045c.zip
Move timer firing implemention into Window #1992
Diffstat (limited to 'src')
-rw-r--r--src/components/script/dom/window.rs27
-rw-r--r--src/components/script/script_task.rs25
2 files changed, 28 insertions, 24 deletions
diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs
index a92daa312d7..b8a1bb8dce5 100644
--- a/src/components/script/dom/window.rs
+++ b/src/components/script/dom/window.rs
@@ -26,9 +26,12 @@ use servo_util::str::DOMString;
use servo_util::task::{spawn_named};
use servo_util::url::parse_url;
+use js::jsapi::JS_CallFunctionValue;
use js::jsapi::JSContext;
use js::jsapi::{JS_GC, JS_GetRuntime};
use js::jsval::JSVal;
+use js::jsval::NullValue;
+use js::rust::with_compartment;
use std::collections::hashmap::HashMap;
use std::cell::{Cell, RefCell};
@@ -37,6 +40,7 @@ use std::comm::{channel, Sender};
use std::comm::Select;
use std::hash::{Hash, sip};
use std::io::timer::Timer;
+use std::ptr;
use std::rc::Rc;
use time;
@@ -284,6 +288,7 @@ pub trait WindowHelpers {
fn wait_until_safe_to_modify_dom(&self);
fn init_browser_context(&self, doc: &JSRef<Document>);
fn load_url(&self, href: DOMString);
+ fn handle_fire_timer(&self, timer_id: TimerId, cx: *mut JSContext);
}
trait PrivateWindowHelpers {
@@ -321,6 +326,28 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
script_chan.send(TriggerLoadMsg(self.page.id, url));
}
}
+
+ fn handle_fire_timer(&self, timer_id: TimerId, cx: *mut JSContext) {
+ let this_value = self.reflector().get_jsobject();
+
+ let data = match self.active_timers.deref().borrow().find(&timer_id) {
+ None => return,
+ Some(timer_handle) => timer_handle.data,
+ };
+
+ // TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`.
+ with_compartment(cx, this_value, || {
+ let mut rval = NullValue();
+ unsafe {
+ JS_CallFunctionValue(cx, this_value, *data.funval,
+ 0, ptr::mut_null(), &mut rval);
+ }
+ });
+
+ if !data.is_interval {
+ self.active_timers.deref().borrow_mut().remove(&timer_id);
+ }
+ }
}
impl<'a> PrivateWindowHelpers for JSRef<'a, Window> {
diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs
index 5551e9d6869..d1d1d315e50 100644
--- a/src/components/script/script_task.rs
+++ b/src/components/script/script_task.rs
@@ -32,10 +32,8 @@ use layout_interface;
use page::{Page, IterablePage, Frame};
use geom::point::Point2D;
-use js::jsapi::JS_CallFunctionValue;
use js::jsapi::{JS_SetWrapObjectCallbacks, JS_SetGCZeal, JS_DEFAULT_ZEAL_FREQ, JS_GC};
use js::jsapi::{JSContext, JSRuntime};
-use js::jsval::NullValue;
use js::rust::{Cx, RtUtils};
use js::rust::with_compartment;
use js;
@@ -51,7 +49,6 @@ use servo_util::task::send_on_failure;
use std::cell::RefCell;
use std::comm::{channel, Sender, Receiver};
use std::mem::replace;
-use std::ptr;
use std::rc::Rc;
use std::task::TaskBuilder;
use url::Url;
@@ -416,27 +413,7 @@ impl ScriptTask {
pipeline ID not associated with this script task. This is a bug.");
let frame = page.frame();
let window = frame.get_ref().window.root();
-
- let this_value = window.deref().reflector().get_jsobject();
-
- let data = match window.deref().active_timers.deref().borrow().find(&timer_id) {
- None => return,
- Some(timer_handle) => timer_handle.data,
- };
-
- // TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`.
- let cx = self.get_cx();
- with_compartment(cx, this_value, || {
- let mut rval = NullValue();
- unsafe {
- JS_CallFunctionValue(cx, this_value, *data.funval,
- 0, ptr::mut_null(), &mut rval);
- }
- });
-
- if !data.is_interval {
- window.deref().active_timers.deref().borrow_mut().remove(&timer_id);
- }
+ window.handle_fire_timer(timer_id, self.get_cx());
}
/// Handles a notification that reflow completed.