Remove all root collections.

This commit is contained in:
Josh Matthews 2014-04-17 23:26:42 -04:00
parent aaf0a61194
commit 7b3e6d1f21
35 changed files with 329 additions and 475 deletions

View file

@ -903,10 +903,10 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
if type and 'JS<' in type:
if dealWithOptional or 'Option<' in type:
rootBody = """let ${simpleDeclName} = ${declName}.as_ref().map(|inner| {
inner.root(&roots) //second root code
inner.root() //second root code
});"""
else:
rootBody = "let ${simpleDeclName} = ${declName}.root(&roots); //third root code"
rootBody = "let ${simpleDeclName} = ${declName}.root(); //third root code"
result.append(CGGeneric(string.Template(rootBody).substitute(replacements)))
result.append(CGGeneric(""))
@ -1799,7 +1799,7 @@ class CGAbstractMethod(CGThing):
def _returnType(self):
return (" -> %s" % self.returnType) if self.returnType != "void" else ""
def _unsafe_open(self):
return "\n unsafe {\n let roots = RootCollection::new();\n" if self.unsafe else ""
return "\n unsafe {\n" if self.unsafe else ""
def _unsafe_close(self):
return "\n }\n" if self.unsafe else ""
@ -2247,7 +2247,7 @@ class CGCallGenerator(CGThing):
self.cgRoot.append(CGGeneric("result = result_fallible.unwrap();"))
if typeRetValNeedsRooting(returnType):
self.cgRoot.append(CGGeneric("let result = result.root(&roots);"))
self.cgRoot.append(CGGeneric("let result = result.root();"))
def define(self):
return self.cgRoot.define()
@ -2498,7 +2498,7 @@ class CGSpecializedMethod(CGAbstractExternMethod):
self.descriptor, self.method),
pre=extraPre +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n").define()
" let mut this = this.root();\n").define()
class CGGenericGetter(CGAbstractBindingMethod):
"""
@ -2552,7 +2552,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
self.descriptor, self.attr)),
pre=extraPre +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n").define()
" let mut this = this.root();\n").define()
class CGGenericSetter(CGAbstractBindingMethod):
"""
@ -2606,7 +2606,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
self.descriptor, self.attr)),
pre=extraPre +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n").define()
" let mut this = this.root();\n").define()
class CGMemberJITInfo(CGThing):
@ -3531,7 +3531,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
" let index = index.unwrap();\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n" +
" let mut this = this.root();\n" +
CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define() + "\n" +
"}\n")
@ -3578,7 +3578,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
" let name = Some(jsid_to_str(cx, id));\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n" +
" let mut this = this.root();\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "\n" +
"}\n")
else:
@ -3623,7 +3623,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
" let index = index.unwrap();\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n" +
" let mut this = this.root();\n" +
CGIndenter(CGProxyIndexedSetter(self.descriptor)).define() +
" return 1;\n" +
"}\n")
@ -3641,7 +3641,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
" let name = Some(jsid_to_str(cx, id));\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n" +
" let mut this = this.root();\n" +
CGIndenter(CGProxyNamedSetter(self.descriptor)).define() + "\n" +
"}\n")
elif self.descriptor.operations['NamedGetter']:
@ -3649,7 +3649,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
" let name = Some(jsid_to_str(cx, id));\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n" +
" let mut this = this.root();\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() +
" if (found) {\n"
" return 0;\n" +
@ -3676,7 +3676,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
" let index = index.unwrap();\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n" +
" let mut this = this.root();\n" +
CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" +
" *bp = found as JSBool;\n" +
" return 1;\n" +
@ -3690,7 +3690,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
" let name = Some(jsid_to_str(cx, id));\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n" +
" let mut this = this.root();\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" +
" *bp = found as JSBool;\n"
" return 1;\n"
@ -3744,7 +3744,7 @@ if expando.is_not_null() {
" let index = index.unwrap();\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n" +
" let mut this = this.root();\n" +
CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define())
getIndexedOrExpando += """
// Even if we don't have this index, we don't forward the
@ -3762,7 +3762,7 @@ if expando.is_not_null() {
" let name = Some(jsid_to_str(cx, id));\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = JS::from_raw(this);\n" +
" let mut this = this.root(&roots);\n" +
" let mut this = this.root();\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() +
"}\n") % (self.descriptor.concreteType)
else:
@ -3879,9 +3879,8 @@ class CGClassConstructHook(CGAbstractExternMethod):
def generate_code(self):
preamble = """
let roots = RootCollection::new();
let global = global_object_for_js_object(JS_CALLEE(cx, &*vp).to_object());
let global = global.root(&roots);
let global = global.root();
let obj = global.reflector().get_jsobject();
"""
nativeName = MakeNativeName(self._ctor.identifier.name)
@ -4123,7 +4122,6 @@ class CGDictionary(CGThing):
return string.Template(
"impl ${selfName} {\n"
" pub fn new(cx: *JSContext, val: JSVal) -> Result<${selfName}, ()> {\n"
" let roots = RootCollection::new();\n" # XXXjdm need to root dict members outside of Init
" let object = if val.is_null_or_undefined() {\n"
" ptr::null()\n"
" } else if val.is_object() {\n"
@ -4323,7 +4321,7 @@ class CGBindingRoot(CGThing):
'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}',
'dom::types::*',
'dom::bindings',
'dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary, OptionalRootable}',
'dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalRootable}',
'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}',
'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}',
'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}',

View file

@ -54,7 +54,7 @@ impl<T: Reflectable> Temporary<T> {
}
/// Root this unrooted value.
pub fn root<'a, 'b>(self, _collection: &'a RootCollection) -> Root<'a, 'b, T> {
pub fn root<'a, 'b>(self) -> Root<'a, 'b, T> {
local_data::get(StackRoots, |opt| {
let collection = opt.unwrap();
unsafe {
@ -119,8 +119,13 @@ impl<T: Reflectable> JS<T> {
}
/// Root this JS-owned value to prevent its collection as garbage.
pub fn root<'a, 'b>(&self, collection: &'a RootCollection) -> Root<'a, 'b, T> {
collection.new_root(self)
pub fn root<'a, 'b>(&self) -> Root<'a, 'b, T> {
local_data::get(StackRoots, |opt| {
let collection = opt.unwrap();
unsafe {
(**collection).new_root(self)
}
})
}
}
@ -214,32 +219,32 @@ impl<T: Assignable<U>, U: Reflectable> OptionalAssignable<T> for Option<JS<U>> {
}
pub trait OptionalRootable<T> {
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>>;
fn root<'a, 'b>(self) -> Option<Root<'a, 'b, T>>;
}
impl<T: Reflectable> OptionalRootable<T> for Option<Temporary<T>> {
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>> {
self.map(|inner| inner.root(roots))
fn root<'a, 'b>(self) -> Option<Root<'a, 'b, T>> {
self.map(|inner| inner.root())
}
}
pub trait OptionalRootedRootable<T> {
fn root<'a, 'b>(&self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>>;
fn root<'a, 'b>(&self) -> Option<Root<'a, 'b, T>>;
}
impl<T: Reflectable> OptionalRootedRootable<T> for Option<JS<T>> {
fn root<'a, 'b>(&self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>> {
self.as_ref().map(|inner| inner.root(roots))
fn root<'a, 'b>(&self) -> Option<Root<'a, 'b, T>> {
self.as_ref().map(|inner| inner.root())
}
}
pub trait ResultRootable<T,U> {
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result<Root<'a, 'b, T>, U>;
fn root<'a, 'b>(self) -> Result<Root<'a, 'b, T>, U>;
}
impl<T: Reflectable, U> ResultRootable<T, U> for Result<Temporary<T>, U> {
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result<Root<'a, 'b, T>, U> {
self.map(|inner| inner.root(roots))
fn root<'a, 'b>(self) -> Result<Root<'a, 'b, T>, U> {
self.map(|inner| inner.root())
}
}

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::PrototypeList;
use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH;
use dom::bindings::conversions::{FromJSValConvertible, IDLInterface};
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, Root};
use dom::bindings::js::{JS, JSRef, Temporary, Root};
use dom::bindings::trace::Untraceable;
use dom::browsercontext;
use dom::window;
@ -606,7 +606,6 @@ pub extern fn wrap_for_same_compartment(cx: *JSContext, obj: *JSObject) -> *JSOb
pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject {
unsafe {
let roots = RootCollection::new();
debug!("outerizing");
let obj = *obj.unnamed;
let win: Root<window::Window> =
@ -614,7 +613,7 @@ pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject
IDLInterface::get_prototype_id(None::<window::Window>),
IDLInterface::get_prototype_depth(None::<window::Window>))
.unwrap()
.root(&roots);
.root();
win.deref().browser_context.get_ref().window_proxy()
}
}
@ -631,8 +630,7 @@ pub fn global_object_for_js_object(obj: *JSObject) -> JS<window::Window> {
}
fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
let roots = RootCollection::new();
let win = global_object_for_js_object(obj).root(&roots);
let win = global_object_for_js_object(obj).root();
let js_info = win.get().page().js_info();
match *js_info {
Some(ref info) => info.js_context.deref().deref().ptr,