Implement MutNullableJS for mutable, nullable member pointers to DOM objects.

This commit is contained in:
Josh Matthews 2014-09-30 16:39:31 +02:00 committed by Ms2ger
parent f73e508821
commit 54fcab61d6
11 changed files with 171 additions and 109 deletions

View file

@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::codegen::InheritTypes::EventTargetCast;
use dom::bindings::error::{Fallible, InvalidCharacter};
use dom::bindings::global;
use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable};
use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, OptionalSettable};
use dom::bindings::trace::{Traceable, Untraceable};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::browsercontext::BrowserContext;
@ -44,6 +44,7 @@ use std::cell::{Cell, RefCell};
use std::cmp;
use std::comm::{channel, Sender};
use std::comm::Select;
use std::default::Default;
use std::hash::{Hash, sip};
use std::io::timer::Timer;
use std::ptr;
@ -81,16 +82,16 @@ pub struct Window {
eventtarget: EventTarget,
pub script_chan: ScriptChan,
pub control_chan: ScriptControlChan,
console: Cell<Option<JS<Console>>>,
location: Cell<Option<JS<Location>>>,
navigator: Cell<Option<JS<Navigator>>>,
console: MutNullableJS<Console>,
location: MutNullableJS<Location>,
navigator: MutNullableJS<Navigator>,
pub image_cache_task: ImageCacheTask,
pub active_timers: Traceable<RefCell<HashMap<TimerId, TimerHandle>>>,
next_timer_handle: Traceable<Cell<i32>>,
pub compositor: Untraceable<Box<ScriptListener+'static>>,
pub browser_context: Traceable<RefCell<Option<BrowserContext>>>,
pub page: Rc<Page>,
performance: Cell<Option<JS<Performance>>>,
performance: MutNullableJS<Performance>,
pub navigationStart: u64,
pub navigationStartPrecise: f64,
screen: Cell<Option<JS<Screen>>>,
@ -225,7 +226,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
let location = Location::new(self, page);
self.location.assign(Some(location));
}
Temporary::new(self.location.get().as_ref().unwrap().clone())
self.location.get().unwrap()
}
fn Console(self) -> Temporary<Console> {
@ -233,7 +234,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
let console = Console::new(&global::Window(self));
self.console.assign(Some(console));
}
Temporary::new(self.console.get().as_ref().unwrap().clone())
self.console.get().unwrap()
}
fn Navigator(self) -> Temporary<Navigator> {
@ -241,7 +242,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
let navigator = Navigator::new(self);
self.navigator.assign(Some(navigator));
}
Temporary::new(self.navigator.get().as_ref().unwrap().clone())
self.navigator.get().unwrap()
}
fn SetTimeout(self, _cx: *mut JSContext, callback: JSVal, timeout: i32) -> i32 {
@ -289,7 +290,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
let performance = Performance::new(self);
self.performance.assign(Some(performance));
}
Temporary::new(self.performance.get().as_ref().unwrap().clone())
self.performance.get().unwrap()
}
fn GetOnclick(self) -> Option<EventHandlerNonNull> {
@ -529,16 +530,16 @@ impl Window {
eventtarget: EventTarget::new_inherited(WindowTypeId),
script_chan: script_chan,
control_chan: control_chan,
console: Cell::new(None),
console: Default::default(),
compositor: Untraceable::new(compositor),
page: page,
location: Cell::new(None),
navigator: Cell::new(None),
location: Default::default(),
navigator: Default::default(),
image_cache_task: image_cache_task,
active_timers: Traceable::new(RefCell::new(HashMap::new())),
next_timer_handle: Traceable::new(Cell::new(0)),
browser_context: Traceable::new(RefCell::new(None)),
performance: Cell::new(None),
performance: Default::default(),
navigationStart: time::get_time().sec as u64,
navigationStartPrecise: time::precise_time_s(),
screen: Cell::new(None),