Use Cell/RefCell for interior mutability of NodeList, Performance, TestBinding, and ValidityState.

This commit is contained in:
Tetsuharu OHZEKI 2014-05-28 12:44:46 +09:00
parent 2215e2ca80
commit aaa8c838d2
3 changed files with 12 additions and 9 deletions

View file

@ -7,7 +7,6 @@ use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::performancetiming::{PerformanceTiming, PerformanceTimingMethods}; use dom::performancetiming::{PerformanceTiming, PerformanceTimingMethods};
use dom::window::Window; use dom::window::Window;
use time; use time;
pub type DOMHighResTimeStamp = f64; pub type DOMHighResTimeStamp = f64;
@ -20,9 +19,10 @@ pub struct Performance {
impl Performance { impl Performance {
fn new_inherited(window: &JSRef<Window>) -> Performance { fn new_inherited(window: &JSRef<Window>) -> Performance {
let timing = PerformanceTiming::new(window).root().root_ref().unrooted();
Performance { Performance {
reflector_: Reflector::new(), reflector_: Reflector::new(),
timing: PerformanceTiming::new(window).root().root_ref().unrooted(), timing: timing,
} }
} }

View file

@ -15,10 +15,12 @@ use servo_util::str::DOMString;
use js::jsapi::JSContext; use js::jsapi::JSContext;
use js::jsval::{JSVal, NullValue}; use js::jsval::{JSVal, NullValue};
use std::cell::Cell;
#[deriving(Encodable)] #[deriving(Encodable)]
pub struct TestBinding { pub struct TestBinding {
pub reflector: Reflector, pub reflector: Reflector,
pub window: JS<Window>, pub window: Cell<JS<Window>>,
} }
pub trait TestBindingMethods { pub trait TestBindingMethods {
@ -243,19 +245,19 @@ pub trait TestBindingMethods {
impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
fn InterfaceAttribute(&self) -> Temporary<Blob> { fn InterfaceAttribute(&self) -> Temporary<Blob> {
let window = self.window.root(); let window = self.window.get().root();
Blob::new(&*window) Blob::new(&*window)
} }
fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>> { fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>> {
let window = self.window.root(); let window = self.window.get().root();
Some(Blob::new(&*window)) Some(Blob::new(&*window))
} }
fn ReceiveInterface(&self) -> Temporary<Blob> { fn ReceiveInterface(&self) -> Temporary<Blob> {
let window = self.window.root(); let window = self.window.get().root();
Blob::new(&*window) Blob::new(&*window)
} }
fn ReceiveNullableInterface(&self) -> Option<Temporary<Blob>> { fn ReceiveNullableInterface(&self) -> Option<Temporary<Blob>> {
let window = self.window.root(); let window = self.window.get().root();
Some(Blob::new(&*window)) Some(Blob::new(&*window))
} }
} }

View file

@ -6,11 +6,12 @@ use dom::bindings::codegen::BindingDeclarations::ValidityStateBinding;
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window; use dom::window::Window;
use std::cell::Cell;
#[deriving(Encodable)] #[deriving(Encodable)]
pub struct ValidityState { pub struct ValidityState {
pub reflector_: Reflector, pub reflector_: Reflector,
pub window: JS<Window>, pub window: Cell<JS<Window>>,
pub state: u8, pub state: u8,
} }
@ -18,7 +19,7 @@ impl ValidityState {
pub fn new_inherited(window: &JSRef<Window>) -> ValidityState { pub fn new_inherited(window: &JSRef<Window>) -> ValidityState {
ValidityState { ValidityState {
reflector_: Reflector::new(), reflector_: Reflector::new(),
window: window.unrooted(), window: Cell::new(window.unrooted()),
state: 0, state: 0,
} }
} }