aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/conversions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/script/dom/bindings/conversions.rs')
-rw-r--r--src/components/script/dom/bindings/conversions.rs84
1 files changed, 42 insertions, 42 deletions
diff --git a/src/components/script/dom/bindings/conversions.rs b/src/components/script/dom/bindings/conversions.rs
index bcbf088ef41..11e937bd261 100644
--- a/src/components/script/dom/bindings/conversions.rs
+++ b/src/components/script/dom/bindings/conversions.rs
@@ -34,24 +34,24 @@ pub trait IDLInterface {
}
pub trait ToJSValConvertible {
- fn to_jsval(&self, cx: *JSContext) -> JSVal;
+ fn to_jsval(&self, cx: *mut JSContext) -> JSVal;
}
pub trait FromJSValConvertible<T> {
- fn from_jsval(cx: *JSContext, val: JSVal, option: T) -> Result<Self, ()>;
+ fn from_jsval(cx: *mut JSContext, val: JSVal, option: T) -> Result<Self, ()>;
}
impl ToJSValConvertible for () {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
UndefinedValue()
}
}
impl ToJSValConvertible for JSVal {
- fn to_jsval(&self, cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
let mut value = *self;
- if unsafe { JS_WrapValue(cx, &mut value as *mut JSVal as *JSVal) } == 0 {
+ if unsafe { JS_WrapValue(cx, &mut value) } == 0 {
fail!("JS_WrapValue failed.");
}
value
@@ -59,10 +59,10 @@ impl ToJSValConvertible for JSVal {
}
unsafe fn convert_from_jsval<T: Default>(
- cx: *JSContext, value: JSVal,
- convert_fn: extern "C" unsafe fn(*JSContext, JSVal, *T) -> JSBool) -> Result<T, ()> {
+ cx: *mut JSContext, value: JSVal,
+ convert_fn: extern "C" unsafe fn(*mut JSContext, JSVal, *mut T) -> JSBool) -> Result<T, ()> {
let mut ret = Default::default();
- if convert_fn(cx, value, &mut ret as *mut T as *T) == 0 {
+ if convert_fn(cx, value, &mut ret) == 0 {
Err(())
} else {
Ok(ret)
@@ -71,95 +71,95 @@ unsafe fn convert_from_jsval<T: Default>(
impl ToJSValConvertible for bool {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
BooleanValue(*self)
}
}
impl FromJSValConvertible<()> for bool {
- fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<bool, ()> {
+ fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<bool, ()> {
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToBoolean) };
result.map(|b| b != 0)
}
}
impl ToJSValConvertible for i8 {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
Int32Value(*self as i32)
}
}
impl FromJSValConvertible<()> for i8 {
- fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<i8, ()> {
+ fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i8, ()> {
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
result.map(|v| v as i8)
}
}
impl ToJSValConvertible for u8 {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
Int32Value(*self as i32)
}
}
impl FromJSValConvertible<()> for u8 {
- fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<u8, ()> {
+ fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u8, ()> {
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
result.map(|v| v as u8)
}
}
impl ToJSValConvertible for i16 {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
Int32Value(*self as i32)
}
}
impl FromJSValConvertible<()> for i16 {
- fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<i16, ()> {
+ fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i16, ()> {
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
result.map(|v| v as i16)
}
}
impl ToJSValConvertible for u16 {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
Int32Value(*self as i32)
}
}
impl FromJSValConvertible<()> for u16 {
- fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<u16, ()> {
+ fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u16, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToUint16) }
}
}
impl ToJSValConvertible for i32 {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
Int32Value(*self)
}
}
impl FromJSValConvertible<()> for i32 {
- fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<i32, ()> {
+ fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i32, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) }
}
}
impl ToJSValConvertible for u32 {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
UInt32Value(*self)
}
}
impl FromJSValConvertible<()> for u32 {
- fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<u32, ()> {
+ fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u32, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToECMAUint32) }
}
}
impl ToJSValConvertible for i64 {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
unsafe {
RUST_JS_NumberValue(*self as f64)
}
@@ -167,13 +167,13 @@ impl ToJSValConvertible for i64 {
}
impl FromJSValConvertible<()> for i64 {
- fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<i64, ()> {
+ fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i64, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToInt64) }
}
}
impl ToJSValConvertible for u64 {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
unsafe {
RUST_JS_NumberValue(*self as f64)
}
@@ -181,13 +181,13 @@ impl ToJSValConvertible for u64 {
}
impl FromJSValConvertible<()> for u64 {
- fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<u64, ()> {
+ fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u64, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToUint64) }
}
}
impl ToJSValConvertible for f32 {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
unsafe {
RUST_JS_NumberValue(*self as f64)
}
@@ -195,14 +195,14 @@ impl ToJSValConvertible for f32 {
}
impl FromJSValConvertible<()> for f32 {
- fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<f32, ()> {
+ fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<f32, ()> {
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToNumber) };
result.map(|f| f as f32)
}
}
impl ToJSValConvertible for f64 {
- fn to_jsval(&self, _cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
unsafe {
RUST_JS_NumberValue(*self)
}
@@ -210,13 +210,13 @@ impl ToJSValConvertible for f64 {
}
impl FromJSValConvertible<()> for f64 {
- fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<f64, ()> {
+ fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<f64, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToNumber) }
}
}
impl ToJSValConvertible for DOMString {
- fn to_jsval(&self, cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
unsafe {
let string_utf16 = self.to_utf16();
let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr(), string_utf16.len() as libc::size_t);
@@ -241,7 +241,7 @@ impl Default for StringificationBehavior {
}
impl FromJSValConvertible<StringificationBehavior> for DOMString {
- fn from_jsval(cx: *JSContext, value: JSVal, nullBehavior: StringificationBehavior) -> Result<DOMString, ()> {
+ fn from_jsval(cx: *mut JSContext, value: JSVal, nullBehavior: StringificationBehavior) -> Result<DOMString, ()> {
if nullBehavior == Empty && value.is_null() {
Ok("".to_owned())
} else {
@@ -257,7 +257,7 @@ impl FromJSValConvertible<StringificationBehavior> for DOMString {
}
impl ToJSValConvertible for ByteString {
- fn to_jsval(&self, cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
unsafe {
let slice = self.as_slice();
let jsstr = JS_NewStringCopyN(cx, slice.as_ptr() as *libc::c_char,
@@ -271,7 +271,7 @@ impl ToJSValConvertible for ByteString {
}
impl FromJSValConvertible<()> for ByteString {
- fn from_jsval(cx: *JSContext, value: JSVal, _option: ()) -> Result<ByteString, ()> {
+ fn from_jsval(cx: *mut JSContext, value: JSVal, _option: ()) -> Result<ByteString, ()> {
unsafe {
let string = JS_ValueToString(cx, value);
if string.is_null() {
@@ -280,7 +280,7 @@ impl FromJSValConvertible<()> for ByteString {
}
let mut length = 0;
- let chars = JS_GetStringCharsAndLength(cx, string, &mut length as *mut _ as *_);
+ let chars = JS_GetStringCharsAndLength(cx, string, &mut length);
slice::raw::buf_as_slice(chars, length as uint, |char_vec| {
if char_vec.iter().any(|&c| c > 0xFF) {
// XXX Throw
@@ -294,11 +294,11 @@ impl FromJSValConvertible<()> for ByteString {
}
impl ToJSValConvertible for Reflector {
- fn to_jsval(&self, cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
let obj = self.get_jsobject();
assert!(obj.is_not_null());
let mut value = ObjectValue(unsafe { &*obj });
- if unsafe { JS_WrapValue(cx, &mut value as *mut JSVal as *JSVal) } == 0 {
+ if unsafe { JS_WrapValue(cx, &mut value) } == 0 {
fail!("JS_WrapValue failed.");
}
value
@@ -306,7 +306,7 @@ impl ToJSValConvertible for Reflector {
}
impl<T: Reflectable+IDLInterface> FromJSValConvertible<()> for JS<T> {
- fn from_jsval(_cx: *JSContext, value: JSVal, _option: ()) -> Result<JS<T>, ()> {
+ fn from_jsval(_cx: *mut JSContext, value: JSVal, _option: ()) -> Result<JS<T>, ()> {
if !value.is_object() {
return Err(());
}
@@ -317,19 +317,19 @@ impl<T: Reflectable+IDLInterface> FromJSValConvertible<()> for JS<T> {
}
impl<'a, 'b, T: Reflectable> ToJSValConvertible for Root<'a, 'b, T> {
- fn to_jsval(&self, cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
self.reflector().to_jsval(cx)
}
}
impl<'a, T: Reflectable> ToJSValConvertible for JSRef<'a, T> {
- fn to_jsval(&self, cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
self.reflector().to_jsval(cx)
}
}
impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> {
- fn to_jsval(&self, cx: *JSContext) -> JSVal {
+ fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
match self {
&Some(ref value) => value.to_jsval(cx),
&None => NullValue(),
@@ -338,7 +338,7 @@ impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> {
}
impl<X: Default, T: FromJSValConvertible<X>> FromJSValConvertible<()> for Option<T> {
- fn from_jsval(cx: *JSContext, value: JSVal, _: ()) -> Result<Option<T>, ()> {
+ fn from_jsval(cx: *mut JSContext, value: JSVal, _: ()) -> Result<Option<T>, ()> {
if value.is_null_or_undefined() {
Ok(None)
} else {