Use Runtime in Window.

This commit is contained in:
Ms2ger 2015-05-10 15:55:05 +02:00
parent ddf6cf6a16
commit 4ed94629a2
2 changed files with 15 additions and 15 deletions

View file

@ -51,7 +51,7 @@ use js::jsapi::JS_EvaluateUCScript;
use js::jsapi::JSContext; use js::jsapi::JSContext;
use js::jsapi::{JS_GC, JS_GetRuntime}; use js::jsapi::{JS_GC, JS_GetRuntime};
use js::jsval::{JSVal, UndefinedValue}; use js::jsval::{JSVal, UndefinedValue};
use js::rust::{Cx, with_compartment}; use js::rust::{Runtime, with_compartment};
use url::{Url, UrlParser}; use url::{Url, UrlParser};
use libc; use libc;
@ -133,8 +133,8 @@ pub struct Window {
/// Global static data related to the DOM. /// Global static data related to the DOM.
dom_static: GlobalStaticData, dom_static: GlobalStaticData,
/// The JavaScript context. /// The JavaScript runtime.
js_context: DOMRefCell<Option<Rc<Cx>>>, js_runtime: DOMRefCell<Option<Runtime>>,
/// A handle for communicating messages to the layout task. /// A handle for communicating messages to the layout task.
layout_chan: LayoutChan, layout_chan: LayoutChan,
@ -170,15 +170,15 @@ pub struct Window {
impl Window { impl Window {
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub fn clear_js_context_for_script_deallocation(&self) { pub fn clear_js_runtime_for_script_deallocation(&self) {
unsafe { unsafe {
*self.js_context.borrow_for_script_deallocation() = None; *self.js_runtime.borrow_for_script_deallocation() = None;
*self.browser_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_runtime.borrow().as_ref().unwrap().cx()
} }
pub fn script_chan(&self) -> Box<ScriptChan+Send> { pub fn script_chan(&self) -> Box<ScriptChan+Send> {
@ -486,7 +486,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
} }
pub trait WindowHelpers { pub trait WindowHelpers {
fn clear_js_context(self); fn clear_js_runtime(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);
@ -559,11 +559,11 @@ impl<'a, T: Reflectable> ScriptHelpers for JSRef<'a, T> {
} }
impl<'a> WindowHelpers for JSRef<'a, Window> { impl<'a> WindowHelpers for JSRef<'a, Window> {
fn clear_js_context(self) { fn clear_js_runtime(self) {
let document = self.Document().root(); let document = self.Document().root();
NodeCast::from_ref(document.r()).teardown(); NodeCast::from_ref(document.r()).teardown();
*self.js_context.borrow_mut() = None; *self.js_runtime.borrow_mut() = None;
*self.browser_context.borrow_mut() = None; *self.browser_context.borrow_mut() = None;
} }
@ -883,7 +883,7 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
} }
impl Window { impl Window {
pub fn new(js_context: Rc<Cx>, pub fn new(runtime: Runtime,
page: Rc<Page>, page: Rc<Page>,
script_chan: Box<ScriptChan+Send>, script_chan: Box<ScriptChan+Send>,
image_cache_chan: ImageCacheChan, image_cache_chan: ImageCacheChan,
@ -929,7 +929,7 @@ impl Window {
id: id, id: id,
parent_info: parent_info, parent_info: parent_info,
dom_static: GlobalStaticData::new(), dom_static: GlobalStaticData::new(),
js_context: DOMRefCell::new(Some(js_context.clone())), js_runtime: DOMRefCell::new(Some(runtime.clone())),
resource_task: resource_task, resource_task: resource_task,
storage_task: storage_task, storage_task: storage_task,
constellation_chan: constellation_chan, constellation_chan: constellation_chan,
@ -949,7 +949,7 @@ impl Window {
devtools_wants_updates: Cell::new(false), devtools_wants_updates: Cell::new(false),
}; };
WindowBinding::Wrap(js_context.ptr, win) WindowBinding::Wrap(runtime.cx(), win)
} }
} }

View file

@ -346,7 +346,7 @@ impl<'a> Drop for ScriptMemoryFailsafe<'a> {
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_for_script_deallocation(); let window = page.window_for_script_deallocation();
(*window.unsafe_get()).clear_js_context_for_script_deallocation(); (*window.unsafe_get()).clear_js_runtime_for_script_deallocation();
} }
} }
} }
@ -1117,7 +1117,7 @@ impl ScriptTask {
let mut page_remover = AutoPageRemover::new(self, page_to_remove); let mut page_remover = AutoPageRemover::new(self, page_to_remove);
// Create the window and document objects. // Create the window and document objects.
let window = Window::new(self.js_runtime.cx.clone(), let window = Window::new(self.js_runtime.clone(),
page.clone(), page.clone(),
self.chan.clone(), self.chan.clone(),
self.image_cache_channel.clone(), self.image_cache_channel.clone(),
@ -1493,7 +1493,7 @@ fn shut_down_layout(page_tree: &Rc<Page>, exit_type: PipelineExitType) {
// Drop our references to the JSContext and DOM objects. // Drop our references to the JSContext and DOM objects.
for page in page_tree.iter() { for page in page_tree.iter() {
let window = page.window().root(); let window = page.window().root();
window.r().clear_js_context(); window.r().clear_js_runtime();
// Sever the connection between the global and the DOM tree // Sever the connection between the global and the DOM tree
page.set_frame(None); page.set_frame(None);
} }