mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
auto merge of #5327 : Ms2ger/servo/memory-explosion, r=Ms2ger
This commit is contained in:
commit
5ce7d8accf
3 changed files with 18 additions and 12 deletions
|
@ -91,6 +91,12 @@ impl<T: Reflectable> Unrooted<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new unrooted value from a `Temporary<T>`.
|
||||||
|
#[allow(unrooted_must_root)]
|
||||||
|
pub fn from_temporary(ptr: Temporary<T>) -> Unrooted<T> {
|
||||||
|
Unrooted::from_js(ptr.inner)
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the `Reflector` for this pointer.
|
/// Get the `Reflector` for this pointer.
|
||||||
pub fn reflector<'a>(&'a self) -> &'a Reflector {
|
pub fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -155,6 +155,14 @@ pub struct Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
pub fn clear_js_context_for_script_deallocation(&self) {
|
||||||
|
unsafe {
|
||||||
|
*self.js_context.borrow_for_script_deallocation() = None;
|
||||||
|
*self.browser_context.borrow_for_script_deallocation() = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_cx(&self) -> *mut JSContext {
|
pub fn get_cx(&self) -> *mut JSContext {
|
||||||
self.js_context.borrow().as_ref().unwrap().ptr
|
self.js_context.borrow().as_ref().unwrap().ptr
|
||||||
}
|
}
|
||||||
|
@ -425,7 +433,6 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
|
||||||
|
|
||||||
pub trait WindowHelpers {
|
pub trait WindowHelpers {
|
||||||
fn clear_js_context(self);
|
fn clear_js_context(self);
|
||||||
fn clear_js_context_for_script_deallocation(self);
|
|
||||||
fn init_browser_context(self, doc: JSRef<Document>, frame_element: Option<JSRef<Element>>);
|
fn init_browser_context(self, doc: JSRef<Document>, frame_element: Option<JSRef<Element>>);
|
||||||
fn load_url(self, href: DOMString);
|
fn load_url(self, href: DOMString);
|
||||||
fn handle_fire_timer(self, timer_id: TimerId);
|
fn handle_fire_timer(self, timer_id: TimerId);
|
||||||
|
@ -499,14 +506,6 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
|
||||||
*self.browser_context.borrow_mut() = None;
|
*self.browser_context.borrow_mut() = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn clear_js_context_for_script_deallocation(self) {
|
|
||||||
unsafe {
|
|
||||||
*self.js_context.borrow_for_script_deallocation() = None;
|
|
||||||
*self.browser_context.borrow_for_script_deallocation() = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reflows the page if it's possible to do so and the page is dirty. This method will wait
|
/// Reflows the page if it's possible to do so and the page is dirty. This method will wait
|
||||||
/// for the layout thread to complete (but see the `TODO` below). If there is no window size
|
/// for the layout thread to complete (but see the `TODO` below). If there is no window size
|
||||||
/// yet, the page is presumed invisible and no reflow is performed.
|
/// yet, the page is presumed invisible and no reflow is performed.
|
||||||
|
|
|
@ -25,7 +25,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, HTMLIFr
|
||||||
use dom::bindings::conversions::FromJSValConvertible;
|
use dom::bindings::conversions::FromJSValConvertible;
|
||||||
use dom::bindings::conversions::StringificationBehavior;
|
use dom::bindings::conversions::StringificationBehavior;
|
||||||
use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable, RootedReference};
|
use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable, RootedReference};
|
||||||
use dom::bindings::js::{RootCollection, RootCollectionPtr};
|
use dom::bindings::js::{RootCollection, RootCollectionPtr, Unrooted};
|
||||||
use dom::bindings::refcounted::{LiveDOMReferences, Trusted, TrustedReference};
|
use dom::bindings::refcounted::{LiveDOMReferences, Trusted, TrustedReference};
|
||||||
use dom::bindings::structuredclone::StructuredCloneData;
|
use dom::bindings::structuredclone::StructuredCloneData;
|
||||||
use dom::bindings::trace::JSTraceable;
|
use dom::bindings::trace::JSTraceable;
|
||||||
|
@ -303,14 +303,15 @@ impl<'a> ScriptMemoryFailsafe<'a> {
|
||||||
|
|
||||||
#[unsafe_destructor]
|
#[unsafe_destructor]
|
||||||
impl<'a> Drop for ScriptMemoryFailsafe<'a> {
|
impl<'a> Drop for ScriptMemoryFailsafe<'a> {
|
||||||
|
#[allow(unrooted_must_root)]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
match self.owner {
|
match self.owner {
|
||||||
Some(owner) => {
|
Some(owner) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
let page = owner.page.borrow_for_script_deallocation();
|
let page = owner.page.borrow_for_script_deallocation();
|
||||||
for page in page.iter() {
|
for page in page.iter() {
|
||||||
let window = page.window().root();
|
let window = Unrooted::from_temporary(page.window());
|
||||||
window.r().clear_js_context_for_script_deallocation();
|
(*window.unsafe_get()).clear_js_context_for_script_deallocation();
|
||||||
}
|
}
|
||||||
*owner.js_context.borrow_for_script_deallocation() = None;
|
*owner.js_context.borrow_for_script_deallocation() = None;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue