mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Introduce trait WeakReferenceable
This allows to take weak references of JS-managed DOM objects.
This commit is contained in:
parent
12f6ba29a7
commit
72c67efe96
10 changed files with 268 additions and 5 deletions
|
@ -15,7 +15,9 @@ use dom::bindings::js::Root;
|
|||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::bindings::str::{ByteString, USVString};
|
||||
use dom::bindings::weakref::MutableWeakRef;
|
||||
use dom::blob::Blob;
|
||||
use dom::url::URL;
|
||||
use js::jsapi::{HandleValue, JSContext, JSObject};
|
||||
use js::jsval::{JSVal, NullValue};
|
||||
use std::borrow::ToOwned;
|
||||
|
@ -26,12 +28,14 @@ use util::str::DOMString;
|
|||
#[dom_struct]
|
||||
pub struct TestBinding {
|
||||
reflector_: Reflector,
|
||||
url: MutableWeakRef<URL>,
|
||||
}
|
||||
|
||||
impl TestBinding {
|
||||
fn new_inherited() -> TestBinding {
|
||||
TestBinding {
|
||||
reflector_: Reflector::new(),
|
||||
url: MutableWeakRef::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,6 +146,12 @@ impl TestBindingMethods for TestBinding {
|
|||
Some(Blob::new(global_root_from_reflector(self).r(), None, ""))
|
||||
}
|
||||
fn SetInterfaceAttributeNullable(&self, _: Option<&Blob>) {}
|
||||
fn GetInterfaceAttributeWeak(&self) -> Option<Root<URL>> {
|
||||
self.url.root()
|
||||
}
|
||||
fn SetInterfaceAttributeWeak(&self, url: Option<&URL>) {
|
||||
self.url.set(url);
|
||||
}
|
||||
fn GetObjectAttributeNullable(&self, _: *mut JSContext) -> *mut JSObject { ptr::null_mut() }
|
||||
fn SetObjectAttributeNullable(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue