auto merge of #4792 : Manishearth/servo/old_impl, r=Ms2ger

This commit is contained in:
bors-servo 2015-01-31 04:27:49 -07:00
commit 83e196c4c6
5 changed files with 47 additions and 34 deletions

View file

@ -3016,7 +3016,7 @@ class CGUnionConversionStruct(CGThing):
post="\n}")
return CGWrapper(
CGIndenter(method),
pre="impl FromJSValConvertible<()> for %s {\n" % self.type,
pre="impl FromJSValConvertible for %s {\ntype Config = ();\n" % self.type,
post="\n}")
def try_method(self, t):

View file

@ -49,12 +49,13 @@ pub trait ToJSValConvertible {
}
/// A trait to convert `JSVal`s to Rust types.
pub trait FromJSValConvertible<T> {
pub trait FromJSValConvertible {
type Config;
/// Convert `val` to type `Self`.
/// Optional configuration of type `T` can be passed as the `option`
/// argument.
/// If it returns `Err(())`, a JSAPI exception is pending.
fn from_jsval(cx: *mut JSContext, val: JSVal, option: T) -> Result<Self, ()>;
fn from_jsval(cx: *mut JSContext, val: JSVal, option: Self::Config) -> Result<Self, ()>;
}
@ -92,7 +93,8 @@ impl ToJSValConvertible for bool {
}
}
impl FromJSValConvertible<()> for bool {
impl FromJSValConvertible for bool {
type Config = ();
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)
@ -105,7 +107,8 @@ impl ToJSValConvertible for i8 {
}
}
impl FromJSValConvertible<()> for i8 {
impl FromJSValConvertible for i8 {
type Config = ();
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)
@ -118,7 +121,8 @@ impl ToJSValConvertible for u8 {
}
}
impl FromJSValConvertible<()> for u8 {
impl FromJSValConvertible for u8 {
type Config = ();
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)
@ -131,7 +135,8 @@ impl ToJSValConvertible for i16 {
}
}
impl FromJSValConvertible<()> for i16 {
impl FromJSValConvertible for i16 {
type Config = ();
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)
@ -144,7 +149,8 @@ impl ToJSValConvertible for u16 {
}
}
impl FromJSValConvertible<()> for u16 {
impl FromJSValConvertible for u16 {
type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u16, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToUint16) }
}
@ -156,7 +162,8 @@ impl ToJSValConvertible for i32 {
}
}
impl FromJSValConvertible<()> for i32 {
impl FromJSValConvertible for i32 {
type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i32, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) }
}
@ -168,7 +175,8 @@ impl ToJSValConvertible for u32 {
}
}
impl FromJSValConvertible<()> for u32 {
impl FromJSValConvertible for u32 {
type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u32, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToECMAUint32) }
}
@ -182,7 +190,8 @@ impl ToJSValConvertible for i64 {
}
}
impl FromJSValConvertible<()> for i64 {
impl FromJSValConvertible for i64 {
type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i64, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToInt64) }
}
@ -196,7 +205,8 @@ impl ToJSValConvertible for u64 {
}
}
impl FromJSValConvertible<()> for u64 {
impl FromJSValConvertible for u64 {
type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u64, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToUint64) }
}
@ -210,7 +220,8 @@ impl ToJSValConvertible for f32 {
}
}
impl FromJSValConvertible<()> for f32 {
impl FromJSValConvertible for f32 {
type Config = ();
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)
@ -225,7 +236,8 @@ impl ToJSValConvertible for f64 {
}
}
impl FromJSValConvertible<()> for f64 {
impl FromJSValConvertible for f64 {
type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<f64, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToNumber) }
}
@ -285,7 +297,8 @@ pub fn jsid_to_str(cx: *mut JSContext, id: jsid) -> DOMString {
}
}
impl FromJSValConvertible<StringificationBehavior> for DOMString {
impl FromJSValConvertible for DOMString {
type Config = StringificationBehavior;
fn from_jsval(cx: *mut JSContext, value: JSVal,
null_behavior: StringificationBehavior)
-> Result<DOMString, ()> {
@ -317,7 +330,8 @@ impl ToJSValConvertible for ByteString {
}
}
impl FromJSValConvertible<()> for ByteString {
impl FromJSValConvertible for ByteString {
type Config = ();
fn from_jsval(cx: *mut JSContext, value: JSVal, _option: ()) -> Result<ByteString, ()> {
unsafe {
let string = JS_ValueToString(cx, value);
@ -462,7 +476,8 @@ pub fn unwrap_jsmanaged<T>(mut obj: *mut JSObject) -> Result<JS<T>, ()>
}
}
impl<T: Reflectable+IDLInterface> FromJSValConvertible<()> for JS<T> {
impl<T: Reflectable+IDLInterface> FromJSValConvertible for JS<T> {
type Config = ();
fn from_jsval(_cx: *mut JSContext, value: JSVal, _option: ()) -> Result<JS<T>, ()> {
if !value.is_object() {
return Err(());
@ -498,8 +513,8 @@ impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> {
}
}
#[old_impl_check]
impl<X: default::Default, T: FromJSValConvertible<X>> FromJSValConvertible<()> for Option<T> {
impl<X: default::Default, T: FromJSValConvertible<Config=X>> FromJSValConvertible for Option<T> {
type Config = ();
fn from_jsval(cx: *mut JSContext, value: JSVal, _: ()) -> Result<Option<T>, ()> {
if value.is_null_or_undefined() {
Ok(None)

View file

@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![feature(unsafe_destructor, plugin, box_syntax, int_uint)]
#![feature(old_impl_check)]
#![deny(unsafe_blocks)]
#![deny(unused_imports)]

View file

@ -5,7 +5,6 @@
#![feature(unsafe_destructor)]
#![feature(plugin)]
#![feature(int_uint)]
#![feature(old_impl_check)]
#![feature(box_syntax)]
#![deny(unused_imports)]

View file

@ -9,12 +9,14 @@ use std::num;
use std::num::Int;
/// An index type to be used by a `Range`
pub trait RangeIndex<T>: Int + fmt::Show {
fn new(x: T) -> Self;
fn get(self) -> T;
pub trait RangeIndex: Int + fmt::Show {
type Index;
fn new(x: Self::Index) -> Self;
fn get(self) -> Self::Index;
}
impl RangeIndex<int> for int {
impl RangeIndex for int {
type Index = int;
#[inline]
fn new(x: int) -> int { x }
@ -37,7 +39,8 @@ macro_rules! int_range_index {
}
}
impl RangeIndex<$T> for $Self {
impl RangeIndex for $Self {
type Index = $T;
#[inline]
fn new(x: $T) -> $Self {
$Self(x)
@ -191,8 +194,7 @@ pub struct Range<I> {
length: I,
}
#[old_impl_check]
impl<I: RangeIndex<T>, T> fmt::Show for Range<I> {
impl<I: RangeIndex> fmt::Show for Range<I> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{:?} .. {:?})", self.begin(), self.end())
}
@ -203,11 +205,11 @@ pub struct EachIndex<T, I> {
it: iter::Range<T>,
}
pub fn each_index<T: Int, I: RangeIndex<T>>(start: I, stop: I) -> EachIndex<T, I> {
pub fn each_index<T: Int, I: RangeIndex<Index=T>>(start: I, stop: I) -> EachIndex<T, I> {
EachIndex { it: iter::range(start.get(), stop.get()) }
}
impl<T: Int, I: RangeIndex<T>> Iterator for EachIndex<T, I> {
impl<T: Int, I: RangeIndex<Index=T>> Iterator for EachIndex<T, I> {
type Item = I;
#[inline]
@ -221,8 +223,7 @@ impl<T: Int, I: RangeIndex<T>> Iterator for EachIndex<T, I> {
}
}
#[old_impl_check]
impl<I: RangeIndex<T>, T> Range<I> {
impl<I: RangeIndex> Range<I> {
/// Create a new range from beginning and length offsets. This could be
/// denoted as `[begin, begin + length)`.
///
@ -359,8 +360,7 @@ impl<I: RangeIndex<T>, T> Range<I> {
}
/// Methods for `Range`s with indices based on integer values
#[old_impl_check]
impl<T: Int, I: RangeIndex<T>> Range<I> {
impl<T: Int, I: RangeIndex<Index=T>> Range<I> {
/// Returns an iterater that increments over `[begin, end)`.
#[inline]
pub fn each_index(&self) -> EachIndex<T, I> {