mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Use *mut T for the T* pointers in SpiderMonkey.
This commit is contained in:
parent
3e4b2c1c7b
commit
d5cb4377ef
18 changed files with 294 additions and 308 deletions
|
@ -2,13 +2,12 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::trace::trace_object;
|
||||
use dom::bindings::utils::Reflectable;
|
||||
use js::jsapi::{JSContext, JSObject, JS_WrapObject, JS_ObjectIsCallable};
|
||||
use js::jsapi::{JS_GetProperty, JSTracer, JS_CallTracer};
|
||||
use js::jsapi::{JS_GetProperty, JSTracer};
|
||||
use js::jsval::{JSVal, UndefinedValue};
|
||||
use js::JSTRACE_OBJECT;
|
||||
|
||||
use libc;
|
||||
use std::cast;
|
||||
use std::ptr;
|
||||
|
||||
|
@ -27,45 +26,40 @@ pub enum ExceptionHandling {
|
|||
|
||||
#[deriving(Clone,Eq)]
|
||||
pub struct CallbackInterface {
|
||||
pub callback: *JSObject
|
||||
pub callback: *mut JSObject
|
||||
}
|
||||
|
||||
impl<S: Encoder<E>, E> Encodable<S, E> for CallbackInterface {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
unsafe {
|
||||
let tracer: *mut JSTracer = cast::transmute(s);
|
||||
"callback".to_c_str().with_ref(|name| {
|
||||
(*tracer).debugPrinter = ptr::null();
|
||||
(*tracer).debugPrintIndex = -1;
|
||||
(*tracer).debugPrintArg = name as *libc::c_void;
|
||||
JS_CallTracer(tracer as *JSTracer, self.callback, JSTRACE_OBJECT as u32);
|
||||
});
|
||||
};
|
||||
trace_object(tracer, "callback", self.callback);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CallbackContainer {
|
||||
fn callback(&self) -> *JSObject;
|
||||
fn callback(&self) -> *mut JSObject;
|
||||
}
|
||||
|
||||
impl CallbackContainer for CallbackInterface {
|
||||
fn callback(&self) -> *JSObject {
|
||||
fn callback(&self) -> *mut JSObject {
|
||||
self.callback
|
||||
}
|
||||
}
|
||||
|
||||
impl CallbackInterface {
|
||||
pub fn new(callback: *JSObject) -> CallbackInterface {
|
||||
pub fn new(callback: *mut JSObject) -> CallbackInterface {
|
||||
CallbackInterface {
|
||||
callback: callback
|
||||
}
|
||||
}
|
||||
|
||||
pub fn GetCallableProperty(&self, cx: *JSContext, name: &str) -> Result<JSVal, ()> {
|
||||
pub fn GetCallableProperty(&self, cx: *mut JSContext, name: &str) -> Result<JSVal, ()> {
|
||||
let mut callable = UndefinedValue();
|
||||
unsafe {
|
||||
if name.to_c_str().with_ref(|name| JS_GetProperty(cx, self.callback, name, &mut callable as *mut JSVal as *JSVal)) == 0 {
|
||||
if name.to_c_str().with_ref(|name| JS_GetProperty(cx, self.callback, name, &mut callable)) == 0 {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
|
@ -79,19 +73,19 @@ impl CallbackInterface {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn GetJSObjectFromCallback<T: CallbackContainer>(callback: &T) -> *JSObject {
|
||||
pub fn GetJSObjectFromCallback<T: CallbackContainer>(callback: &T) -> *mut JSObject {
|
||||
callback.callback()
|
||||
}
|
||||
|
||||
pub fn WrapCallThisObject<T: 'static + CallbackContainer + Reflectable>(cx: *JSContext,
|
||||
_scope: *JSObject,
|
||||
p: Box<T>) -> *JSObject {
|
||||
let obj = GetJSObjectFromCallback(p);
|
||||
pub fn WrapCallThisObject<T: 'static + CallbackContainer + Reflectable>(cx: *mut JSContext,
|
||||
_scope: *mut JSObject,
|
||||
p: Box<T>) -> *mut JSObject {
|
||||
let mut obj = GetJSObjectFromCallback(p);
|
||||
assert!(obj.is_not_null());
|
||||
|
||||
unsafe {
|
||||
if JS_WrapObject(cx, &obj) == 0 {
|
||||
return ptr::null();
|
||||
if JS_WrapObject(cx, &mut obj) == 0 {
|
||||
return ptr::mut_null();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,19 +93,19 @@ pub fn WrapCallThisObject<T: 'static + CallbackContainer + Reflectable>(cx: *JSC
|
|||
}
|
||||
|
||||
pub struct CallSetup {
|
||||
pub cx: *JSContext,
|
||||
pub cx: *mut JSContext,
|
||||
pub handling: ExceptionHandling
|
||||
}
|
||||
|
||||
impl CallSetup {
|
||||
pub fn new(cx: *JSContext, handling: ExceptionHandling) -> CallSetup {
|
||||
pub fn new(cx: *mut JSContext, handling: ExceptionHandling) -> CallSetup {
|
||||
CallSetup {
|
||||
cx: cx,
|
||||
handling: handling
|
||||
}
|
||||
}
|
||||
|
||||
pub fn GetContext(&self) -> *JSContext {
|
||||
pub fn GetContext(&self) -> *mut JSContext {
|
||||
self.cx
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue