mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #5543 - jagtalon:jag/slashdot, r=jdm
Partially fixes #5504. Props to @ehegnes and @jdm for the help!
This commit is contained in:
commit
184d214e26
2 changed files with 20 additions and 7 deletions
|
@ -50,6 +50,7 @@
|
||||||
//! `Option<Root<T>>` easy
|
//! `Option<Root<T>>` easy
|
||||||
|
|
||||||
use dom::bindings::trace::JSTraceable;
|
use dom::bindings::trace::JSTraceable;
|
||||||
|
use dom::bindings::trace::RootedVec;
|
||||||
use dom::bindings::utils::{Reflector, Reflectable};
|
use dom::bindings::utils::{Reflector, Reflectable};
|
||||||
use dom::node::Node;
|
use dom::node::Node;
|
||||||
use js::jsapi::JSObject;
|
use js::jsapi::JSObject;
|
||||||
|
@ -57,11 +58,11 @@ use js::jsval::JSVal;
|
||||||
use layout_interface::TrustedNodeAddress;
|
use layout_interface::TrustedNodeAddress;
|
||||||
use script_task::STACK_ROOTS;
|
use script_task::STACK_ROOTS;
|
||||||
|
|
||||||
use util::smallvec::{SmallVec, SmallVec32};
|
|
||||||
|
|
||||||
use core::nonzero::NonZero;
|
use core::nonzero::NonZero;
|
||||||
|
use libc;
|
||||||
use std::cell::{Cell, UnsafeCell};
|
use std::cell::{Cell, UnsafeCell};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
use std::intrinsics::return_address;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
@ -610,7 +611,7 @@ impl<T: Assignable<U>, U: Reflectable> TemporaryPushable<T> for Vec<JS<U>> {
|
||||||
/// See also [*Exact Stack Rooting - Storing a GCPointer on the CStack*]
|
/// See also [*Exact Stack Rooting - Storing a GCPointer on the CStack*]
|
||||||
/// (https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Internals/GC/Exact_Stack_Rooting).
|
/// (https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Internals/GC/Exact_Stack_Rooting).
|
||||||
pub struct RootCollection {
|
pub struct RootCollection {
|
||||||
roots: UnsafeCell<SmallVec32<*mut JSObject>>,
|
roots: UnsafeCell<RootedVec<*mut JSObject>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A pointer to a RootCollection, for use in global variables.
|
/// A pointer to a RootCollection, for use in global variables.
|
||||||
|
@ -621,8 +622,12 @@ impl Copy for RootCollectionPtr {}
|
||||||
impl RootCollection {
|
impl RootCollection {
|
||||||
/// Create an empty collection of roots
|
/// Create an empty collection of roots
|
||||||
pub fn new() -> RootCollection {
|
pub fn new() -> RootCollection {
|
||||||
|
let addr = unsafe {
|
||||||
|
return_address() as *const libc::c_void
|
||||||
|
};
|
||||||
|
|
||||||
RootCollection {
|
RootCollection {
|
||||||
roots: UnsafeCell::new(SmallVec32::new()),
|
roots: UnsafeCell::new(RootedVec::new_with_destination_address(addr)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -632,7 +637,6 @@ impl RootCollection {
|
||||||
let roots = self.roots.get();
|
let roots = self.roots.get();
|
||||||
(*roots).push(untracked_js_ptr);
|
(*roots).push(untracked_js_ptr);
|
||||||
debug!(" rooting {:?}", untracked_js_ptr);
|
debug!(" rooting {:?}", untracked_js_ptr);
|
||||||
assert!(!(*roots).spilled());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -389,12 +389,21 @@ impl<T: VecRootableType> RootedVec<T> {
|
||||||
/// Create a vector of items of type T that is rooted for
|
/// Create a vector of items of type T that is rooted for
|
||||||
/// the lifetime of this struct
|
/// the lifetime of this struct
|
||||||
pub fn new() -> RootedVec<T> {
|
pub fn new() -> RootedVec<T> {
|
||||||
|
let addr = unsafe {
|
||||||
|
return_address() as *const libc::c_void
|
||||||
|
};
|
||||||
|
|
||||||
|
RootedVec::new_with_destination_address(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a vector of items of type T. This constructor is specific
|
||||||
|
/// for RootCollection.
|
||||||
|
pub fn new_with_destination_address(addr: *const libc::c_void) -> RootedVec<T> {
|
||||||
unsafe {
|
unsafe {
|
||||||
RootedCollectionSet::add::<T>(&*(return_address() as *const _));
|
RootedCollectionSet::add::<T>(&*(addr as *const _));
|
||||||
}
|
}
|
||||||
RootedVec::<T> { v: vec!() }
|
RootedVec::<T> { v: vec!() }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe_destructor]
|
#[unsafe_destructor]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue