mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Upgrade to SM 39
This commit is contained in:
parent
a256f39796
commit
675267b782
205 changed files with 6546 additions and 5340 deletions
|
@ -5,7 +5,7 @@
|
|||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::callback::ExceptionHandling::Report;
|
||||
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||
use dom::bindings::js::JSRef;
|
||||
use dom::bindings::global::global_object_for_js_object;
|
||||
use dom::bindings::utils::Reflectable;
|
||||
|
||||
use dom::window::ScriptHelpers;
|
||||
|
@ -16,7 +16,8 @@ use horribly_inefficient_timers;
|
|||
use util::task::spawn_named;
|
||||
use util::str::DOMString;
|
||||
|
||||
use js::jsval::JSVal;
|
||||
use js::jsapi::{RootedValue, HandleValue, Heap};
|
||||
use js::jsval::{JSVal, UndefinedValue};
|
||||
|
||||
use std::borrow::ToOwned;
|
||||
use std::cell::Cell;
|
||||
|
@ -25,6 +26,8 @@ use std::collections::HashMap;
|
|||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::sync::mpsc::Select;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::rc::Rc;
|
||||
use std::default::Default;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
#[jstraceable]
|
||||
|
@ -43,7 +46,7 @@ struct TimerHandle {
|
|||
#[derive(Clone)]
|
||||
pub enum TimerCallback {
|
||||
StringTimerCallback(DOMString),
|
||||
FunctionTimerCallback(Function)
|
||||
FunctionTimerCallback(Rc<Function>)
|
||||
}
|
||||
|
||||
impl Hash for TimerId {
|
||||
|
@ -104,11 +107,10 @@ pub enum TimerControlMsg {
|
|||
// TODO: Handle rooting during fire_timer when movable GC is turned on
|
||||
#[jstraceable]
|
||||
#[privatize]
|
||||
#[derive(Clone)]
|
||||
struct TimerData {
|
||||
is_interval: IsInterval,
|
||||
callback: TimerCallback,
|
||||
args: Vec<JSVal>
|
||||
args: Vec<Heap<JSVal>>
|
||||
}
|
||||
|
||||
impl TimerManager {
|
||||
|
@ -133,7 +135,7 @@ impl TimerManager {
|
|||
#[allow(unsafe_code)]
|
||||
pub fn set_timeout_or_interval(&self,
|
||||
callback: TimerCallback,
|
||||
arguments: Vec<JSVal>,
|
||||
arguments: Vec<HandleValue>,
|
||||
timeout: i32,
|
||||
is_interval: IsInterval,
|
||||
source: TimerSource,
|
||||
|
@ -205,10 +207,21 @@ impl TimerManager {
|
|||
data: TimerData {
|
||||
is_interval: is_interval,
|
||||
callback: callback,
|
||||
args: arguments
|
||||
args: Vec::with_capacity(arguments.len())
|
||||
}
|
||||
};
|
||||
self.active_timers.borrow_mut().insert(timer_id, timer);
|
||||
|
||||
// This is a bit complicated, but this ensures that the vector's
|
||||
// buffer isn't reallocated (and moved) after setting the Heap values
|
||||
let mut timers = self.active_timers.borrow_mut();
|
||||
let mut timer = timers.get_mut(&timer_id).unwrap();
|
||||
for _ in 0..arguments.len() {
|
||||
timer.data.args.push(Heap::default());
|
||||
}
|
||||
for i in 0..arguments.len() {
|
||||
timer.data.args.get_mut(i).unwrap().set(arguments[i].get());
|
||||
}
|
||||
handle
|
||||
}
|
||||
|
||||
|
@ -220,24 +233,31 @@ impl TimerManager {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fire_timer<T: Reflectable>(&self, timer_id: TimerId, this: JSRef<T>) {
|
||||
pub fn fire_timer<T: Reflectable>(&self, timer_id: TimerId, this: &T) {
|
||||
|
||||
let data = match self.active_timers.borrow().get(&timer_id) {
|
||||
None => return,
|
||||
Some(timer_handle) => timer_handle.data.clone(),
|
||||
};
|
||||
let (is_interval, callback, args): (IsInterval, TimerCallback, Vec<JSVal>) =
|
||||
match self.active_timers.borrow().get(&timer_id) {
|
||||
Some(timer_handle) =>
|
||||
(timer_handle.data.is_interval,
|
||||
timer_handle.data.callback.clone(),
|
||||
timer_handle.data.args.iter().map(|arg| arg.get()).collect()),
|
||||
None => return,
|
||||
};
|
||||
|
||||
// TODO: Must handle rooting of funval and args when movable GC is turned on
|
||||
match data.callback {
|
||||
match callback {
|
||||
TimerCallback::FunctionTimerCallback(function) => {
|
||||
let _ = function.Call_(this, data.args, Report);
|
||||
let arg_handles = args.iter().by_ref().map(|arg| HandleValue { ptr: arg }).collect();
|
||||
let _ = function.Call_(this, arg_handles, Report);
|
||||
}
|
||||
TimerCallback::StringTimerCallback(code_str) => {
|
||||
this.evaluate_js_on_global_with_result(&code_str);
|
||||
let proxy = this.reflector().get_jsobject();
|
||||
let cx = global_object_for_js_object(proxy.get()).r().get_cx();
|
||||
let mut rval = RootedValue::new(cx, UndefinedValue());
|
||||
this.evaluate_js_on_global_with_result(&code_str, rval.handle_mut());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if data.is_interval == IsInterval::NonInterval {
|
||||
if is_interval == IsInterval::NonInterval {
|
||||
self.active_timers.borrow_mut().remove(&timer_id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue