From a6e0acd74314940c6ab179d098a7619512f5a9fa Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 3 Aug 2014 13:59:22 +0200 Subject: [PATCH] Revert . The Servo changes to move the script task to a native task are not progressing as fast as hoped, so these changes should be temporarily reverted. --- linkhack.rs | 2 -- rust.rs | 41 ++++++++++++++++------------------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/linkhack.rs b/linkhack.rs index 307fb7a7f..4e74e7d87 100644 --- a/linkhack.rs +++ b/linkhack.rs @@ -6,14 +6,12 @@ #[cfg(target_os = "linux")] #[link(name = "pthread")] -#[link(name = "nspr4")] #[link(name = "js_static", kind = "static")] #[link(name = "stdc++")] #[link(name = "z")] extern { } #[cfg(target_os = "macos")] -#[link(name = "nspr4")] #[link(name = "js_static", kind = "static")] #[link(name = "stdc++")] #[link(name = "z")] diff --git a/rust.rs b/rust.rs index 01079c0cd..7a48fdf0e 100644 --- a/rust.rs +++ b/rust.rs @@ -6,7 +6,9 @@ use libc::types::os::arch::c95::{size_t, c_uint}; use libc::c_char; +use std::cmp; use std::rc; +use std::rt::Runtime; use jsapi::*; use jsval::{JSVal, NullValue}; use default_stacksize; @@ -16,6 +18,7 @@ use JSOPTION_METHODJIT; use JSOPTION_TYPE_INFERENCE; use ERR; use std::str::raw::from_c_str; +use green::task::GreenTask; // ___________________________________________________________________________ // friendly Rustic API to runtimes @@ -53,9 +56,22 @@ impl RtUtils for rc::Rc { } } +extern fn gc_callback(rt: *mut JSRuntime, _status: JSGCStatus) { + use std::rt::local::Local; + use std::rt::task::Task; + unsafe { + let mut task = Local::borrow(None::); + let green_task: Box = task.maybe_take_runtime().unwrap(); + let (start, end) = green_task.stack_bounds(); + JS_SetNativeStackBounds(rt, cmp::min(start, end), cmp::max(start, end)); + task.put_runtime(green_task); + } +} + pub fn rt() -> rt { unsafe { let runtime = JS_Init(default_heapsize); + JS_SetGCCallback(runtime, Some(gc_callback)); return new_runtime(runtime); } } @@ -157,7 +173,6 @@ pub extern fn reportError(_cx: *mut JSContext, msg: *const c_char, report: *mut pub fn with_compartment(cx: *mut JSContext, object: *mut JSObject, cb: || -> R) -> R { unsafe { - let _ar = JSAutoRequest::new(cx); let call = JS_EnterCrossCompartmentCall(cx, object); let result = cb(); JS_LeaveCrossCompartmentCall(call); @@ -165,30 +180,6 @@ pub fn with_compartment(cx: *mut JSContext, object: *mut JSObject, cb: || -> } } - -pub struct JSAutoRequest { - cx: *mut JSContext, -} - -impl JSAutoRequest { - pub fn new(cx: *mut JSContext) -> JSAutoRequest { - unsafe { - JS_BeginRequest(cx); - } - JSAutoRequest { - cx: cx, - } - } -} - -impl Drop for JSAutoRequest { - fn drop(&mut self) { - unsafe { - JS_EndRequest(self.cx); - } - } -} - #[cfg(test)] pub mod test { use super::rt;