diff --git a/global.rs b/global.rs index b78f54413..b41a5f4ec 100644 --- a/global.rs +++ b/global.rs @@ -16,7 +16,6 @@ use std::libc::{c_uint, c_void}; use std::str::raw::from_c_str; use std::cast::transmute; use std::ptr::null; -use std::ptr; use jsapi; use jsapi::{JSClass, JSContext, JSFunctionSpec, JSBool, JSNativeWrapper}; use jsapi::{JS_EncodeString, JS_free, JS_ValueToBoolean, JS_ValueToString}; @@ -105,7 +104,7 @@ pub extern fn debug(cx: *JSContext, argc: c_uint, vp: *mut JSVal) -> JSBool { unsafe { let argv = JS_ARGV(cx, &*vp); for i in range(0, argc as int) { - let jsstr = JS_ValueToString(cx, *ptr::offset(argv, i)); + let jsstr = JS_ValueToString(cx, *argv.offset(i)); debug!("{:s}", jsval_to_rust_str(cx, jsstr)); } JS_SET_RVAL(cx, &*vp, UndefinedValue()); @@ -128,7 +127,7 @@ pub extern fn assert(cx: *JSContext, argc: c_uint, vp: *mut JSVal) -> JSBool { let argument = match argc { 0 => UndefinedValue(), - _ => *ptr::offset(argv, 0) + _ => *argv.offset(0) }; let result = 0; diff --git a/js.rc b/js.rc index ff1095590..9e71b117f 100644 --- a/js.rc +++ b/js.rc @@ -7,14 +7,14 @@ #[feature(globs, managed_boxes)]; -#[allow(non_uppercase_statics)]; +#[allow(non_uppercase_statics, non_camel_case_types)]; -extern mod extra; -extern mod green; +extern crate extra; +extern crate green; +extern crate serialize; use std::libc; use std::cast; -use std::ptr; use std::ptr::null; use std::result::{Result, Ok, Err}; use std::libc::c_uint; @@ -115,7 +115,7 @@ pub fn result_obj(o: jsobj) -> Result { #[inline(always)] pub unsafe fn JS_ARGV(_cx: *JSContext, vp: *JSVal) -> *JSVal { - ptr::offset(vp, 2) + vp.offset(2) } pub unsafe fn JS_SET_RVAL(_cx: *JSContext, vp: *JSVal, v: JSVal) { @@ -126,10 +126,10 @@ pub unsafe fn JS_SET_RVAL(_cx: *JSContext, vp: *JSVal, v: JSVal) { #[inline(alwyas)] pub unsafe fn JS_THIS_OBJECT(cx: *JSContext, vp: *mut JSVal) -> *JSObject { let r = - if (*ptr::offset(&*vp, 1)).is_primitive() { + if (*(vp.offset(1))).is_primitive() { JS_ComputeThis(cx, &*vp) } else { - *ptr::offset(&*vp, 1) + *(vp.offset(1)) }; r.to_object_or_null() } @@ -142,8 +142,8 @@ pub unsafe fn JS_CALLEE(_cx: *JSContext, vp: *JSVal) -> JSVal { // This is a duplication of the shadow stuff from jsfriendapi.h. Here // there be dragons! mod shadow { + use std::cast; use std::libc; - use std::ptr; use jsapi::{JSObject, JSClass, jsid}; use jsval::JSVal; @@ -178,7 +178,8 @@ mod shadow { #[inline(always)] pub unsafe fn fixedSlots(&self) -> *JSVal { - (ptr::offset(ptr::to_unsafe_ptr(&self), 1)) as *JSVal + let x: *JSVal = cast::transmute(&self); + (x.offset(1)) as *JSVal } // Like slotRef, but just returns the value, not a reference @@ -187,9 +188,9 @@ mod shadow { unsafe { let nfixed : libc::size_t = self.numFixedSlots(); if slot < nfixed { - return *ptr::offset(self.fixedSlots(), slot as int) + return *self.fixedSlots().offset(slot as int) } - return *ptr::offset(self.slots, (slot - nfixed) as int) + return *self.slots.offset((slot - nfixed) as int) } } } diff --git a/jsapi.rs b/jsapi.rs index 3643ab4f3..c2e88c5e1 100644 --- a/jsapi.rs +++ b/jsapi.rs @@ -4,7 +4,7 @@ /* automatically generated by rust-bindgen */ -#[allow(non_uppercase_statics)]; +#[allow(non_uppercase_statics, non_camel_case_types)]; use std::libc::*; use jsfriendapi::JSJitInfo; diff --git a/rust.rs b/rust.rs index 29175b3bb..80a3423ee 100644 --- a/rust.rs +++ b/rust.rs @@ -5,9 +5,10 @@ #[doc = "Rust wrappers around the raw JS apis"]; use std::libc::types::os::arch::c95::{size_t, c_uint}; -use std::libc::{c_char, uintptr_t}; -use std::num; +use std::libc::c_char; +use std::cmp; use std::rc; +use std::rt::Runtime; use jsapi::*; use jsval::{JSVal, NullValue}; use default_stacksize; @@ -16,7 +17,6 @@ use JSOPTION_VAROBJFIX; use JSOPTION_METHODJIT; use JSOPTION_TYPE_INFERENCE; use ERR; -use std::ptr; use std::ptr::null; use result; use result_obj; @@ -67,10 +67,11 @@ extern fn gc_callback(rt: *JSRuntime, _status: JSGCStatus) { unsafe { let mut task = Local::borrow(None::); let green_task: ~GreenTask = task.get().maybe_take_runtime().unwrap(); - let c = green_task.coroutine.get_ref(); - let start = c.current_stack_segment.start() as uintptr_t; - let end = c.current_stack_segment.end() as uintptr_t; - JS_SetNativeStackBounds(rt, num::min(start, end), num::max(start, end)); + let (start, end) = green_task.stack_bounds(); + // libgreen adds a guard page to the stack which causes SpiderMonkey to + // to choke, so we need to skip over that. + let start = start + ::std::os::page_size(); + JS_SetNativeStackBounds(rt, cmp::min(start, end), cmp::max(start, end)); task.get().put_runtime(green_task); } } @@ -130,7 +131,7 @@ impl CxUtils for rc::Rc { result(JS_InitStandardClasses(ptr, globobj)).and_then(|_ok| { Ok(rc::Rc::new(Compartment { cx: self.clone(), - global_obj: self.rooted_obj(globobj), + global_obj: globobj, })) }) } @@ -139,7 +140,7 @@ impl CxUtils for rc::Rc { fn new_compartment_with_global(&self, global: *JSObject) -> Result,()> { Ok(rc::Rc::new(Compartment { cx: self.clone(), - global_obj: self.rooted_obj(global), + global_obj: global, })) } } @@ -175,17 +176,17 @@ impl Cx { } } - pub fn evaluate_script(&self, glob: jsobj, script: ~str, filename: ~str, line_num: uint) + pub fn evaluate_script(&self, glob: *JSObject, script: ~str, filename: ~str, line_num: uint) -> Result<(),()> { let script_utf16 = script.to_utf16(); filename.to_c_str().with_ref(|filename_cstr| { let rval: JSVal = NullValue(); debug!("Evaluating script from {:s} with content {}", filename, script); unsafe { - if ERR == JS_EvaluateUCScript(self.ptr, glob.borrow().ptr, + if ERR == JS_EvaluateUCScript(self.ptr, glob, script_utf16.as_ptr(), script_utf16.len() as c_uint, filename_cstr, line_num as c_uint, - ptr::to_unsafe_ptr(&rval)) { + &rval) { debug!("...err!"); Err(()) } else { @@ -230,21 +231,21 @@ pub extern fn reportError(_cx: *JSContext, msg: *c_char, report: *JSErrorReport) pub struct Compartment { cx: rc::Rc, - global_obj: jsobj, + global_obj: *JSObject, } impl Compartment { pub fn define_functions(&self, specvec: &'static [JSFunctionSpec]) -> Result<(),()> { unsafe { result(JS_DefineFunctions(self.cx.borrow().ptr, - self.global_obj.borrow().ptr, + self.global_obj, specvec.as_ptr())) } } pub fn define_properties(&self, specvec: &'static [JSPropertySpec]) -> Result<(),()> { unsafe { result(JS_DefineProperties(self.cx.borrow().ptr, - self.global_obj.borrow().ptr, + self.global_obj, specvec.as_ptr())) } } @@ -257,7 +258,7 @@ impl Compartment { unsafe { name.to_c_str().with_ref(|name| { result(JS_DefineProperty(self.cx.borrow().ptr, - self.global_obj.borrow().ptr, + self.global_obj, name, value, Some(getter), @@ -290,7 +291,7 @@ pub struct jsobj_rsrc { impl Drop for jsobj_rsrc { fn drop(&mut self) { unsafe { - JS_RemoveObjectRoot(self.cxptr, ptr::to_unsafe_ptr(&self.ptr)); + JS_RemoveObjectRoot(self.cxptr, &self.ptr); } } } @@ -324,6 +325,7 @@ impl to_jsstr for ~str { #[cfg(test)] pub mod test { use super::rt; + use super::{CxUtils, RtUtils}; use super::super::global; use super::super::jsapi::{JS_GC, JS_GetRuntime}; @@ -339,7 +341,7 @@ pub mod test { comp.borrow().define_functions(global::DEBUG_FNS); let s = ~"debug(22);"; - cx.borrow().evaluate_script(comp.borrow().global_obj.clone(), s, ~"test", 1u) + cx.borrow().evaluate_script(comp.borrow().global_obj, s, ~"test", 1u) }); } diff --git a/trace.rs b/trace.rs index e2ecd72db..3706cbfe4 100644 --- a/trace.rs +++ b/trace.rs @@ -4,7 +4,7 @@ use jsapi::JSTracer; -use extra::serialize::Encoder; +use serialize::Encoder; impl Encoder for JSTracer { fn emit_nil(&mut self) {}