diff options
author | Josh Matthews <josh@joshmatthews.net> | 2016-05-10 12:15:59 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2016-05-11 08:34:50 -0400 |
commit | a85e659b29ec105fe25a90d70c0ba0427e5185a9 (patch) | |
tree | 41e61b5ba12c26bf34327782290db29873d5e81e /components/script/dom/browsingcontext.rs | |
parent | 6123ce8649db984404bfa6e2fbafc08b0856d199 (diff) | |
download | servo-a85e659b29ec105fe25a90d70c0ba0427e5185a9.tar.gz servo-a85e659b29ec105fe25a90d70c0ba0427e5185a9.zip |
Ensure that the fields of BrowsingContext are traced and the Rust object is freed when the reflector is finalized.
Diffstat (limited to 'components/script/dom/browsingcontext.rs')
-rw-r--r-- | components/script/dom/browsingcontext.rs | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/components/script/dom/browsingcontext.rs b/components/script/dom/browsingcontext.rs index b314bce603d..f4f15cdf7c7 100644 --- a/components/script/dom/browsingcontext.rs +++ b/components/script/dom/browsingcontext.rs @@ -7,6 +7,7 @@ use dom::bindings::conversions::{ToJSValConvertible, root_from_handleobject}; use dom::bindings::js::{JS, Root, RootedReference}; use dom::bindings::proxyhandler::{fill_property_descriptor, get_property_descriptor}; use dom::bindings::reflector::{Reflectable, Reflector}; +use dom::bindings::trace::JSTraceable; use dom::bindings::utils::WindowProxyHandler; use dom::bindings::utils::get_array_index_from_id; use dom::document::Document; @@ -14,10 +15,10 @@ use dom::element::Element; use dom::window::Window; use js::JSCLASS_IS_GLOBAL; use js::glue::{CreateWrapperProxyHandler, ProxyTraps, NewWindowProxy}; -use js::glue::{GetProxyPrivate, SetProxyExtra}; +use js::glue::{GetProxyPrivate, SetProxyExtra, GetProxyExtra}; use js::jsapi::{Handle, HandleId, HandleObject, HandleValue, JSAutoCompartment, JSAutoRequest}; use js::jsapi::{JSContext, JSPROP_READONLY, JSErrNum, JSObject, PropertyDescriptor, JS_DefinePropertyById}; -use js::jsapi::{JS_ForwardGetPropertyTo, JS_ForwardSetPropertyTo, JS_GetClass}; +use js::jsapi::{JS_ForwardGetPropertyTo, JS_ForwardSetPropertyTo, JS_GetClass, JSTracer, FreeOp}; use js::jsapi::{JS_GetOwnPropertyDescriptorById, JS_HasPropertyById, MutableHandle}; use js::jsapi::{MutableHandleValue, ObjectOpResult, RootedObject, RootedValue}; use js::jsval::{UndefinedValue, PrivateValue}; @@ -261,14 +262,32 @@ static PROXY_HANDLER: ProxyTraps = ProxyTraps { fun_toString: None, boxedValue_unbox: None, defaultValue: None, - trace: None, - finalize: None, + trace: Some(trace), + finalize: Some(finalize), objectMoved: None, isCallable: None, isConstructor: None, }; #[allow(unsafe_code)] +unsafe extern fn finalize(_fop: *mut FreeOp, obj: *mut JSObject) { + let this = GetProxyExtra(obj, 0).to_private() as *mut BrowsingContext; + assert!(!this.is_null()); + let _ = Box::from_raw(this); + debug!("BrowsingContext finalize: {:p}", this); +} + +#[allow(unsafe_code)] +unsafe extern fn trace(trc: *mut JSTracer, obj: *mut JSObject) { + let this = GetProxyExtra(obj, 0).to_private() as *const BrowsingContext; + if this.is_null() { + // GC during obj creation + return; + } + (*this).trace(trc); +} + +#[allow(unsafe_code)] pub fn new_window_proxy_handler() -> WindowProxyHandler { unsafe { WindowProxyHandler(CreateWrapperProxyHandler(&PROXY_HANDLER)) |