mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Merge the To/FromJSValConvertible implementations for Finite<T>.
This commit is contained in:
parent
58a8cfda52
commit
e3683c8598
1 changed files with 10 additions and 26 deletions
|
@ -58,6 +58,7 @@ use libc;
|
|||
use std::borrow::ToOwned;
|
||||
use std::default;
|
||||
use std::marker::MarkerTrait;
|
||||
use std::num::Float;
|
||||
use std::slice;
|
||||
|
||||
/// A trait to retrieve the constants necessary to check if a `JSObject`
|
||||
|
@ -257,24 +258,6 @@ impl FromJSValConvertible for f32 {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToJSValConvertible for Finite<f32> {
|
||||
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||
let value = **self;
|
||||
value.to_jsval(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromJSValConvertible for Finite<f32> {
|
||||
type Config = ();
|
||||
fn from_jsval(cx: *mut JSContext, val: JSVal, option: ()) -> Result<Finite<f32>, ()> {
|
||||
let result = FromJSValConvertible::from_jsval(cx, val, option);
|
||||
let result = result.and_then(|v| {
|
||||
Finite::<f32>::new(v).ok_or(())
|
||||
});
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl ToJSValConvertible for f64 {
|
||||
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||
unsafe {
|
||||
|
@ -290,7 +273,7 @@ impl FromJSValConvertible for f64 {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToJSValConvertible for Finite<f64> {
|
||||
impl<T: Float + ToJSValConvertible> ToJSValConvertible for Finite<T> {
|
||||
#[inline]
|
||||
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||
let value = **self;
|
||||
|
@ -298,14 +281,15 @@ impl ToJSValConvertible for Finite<f64> {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromJSValConvertible for Finite<f64> {
|
||||
impl<T: Float + FromJSValConvertible<Config=()>> FromJSValConvertible for Finite<T> {
|
||||
type Config = ();
|
||||
fn from_jsval(cx: *mut JSContext, val: JSVal, option: ()) -> Result<Finite<f64>, ()> {
|
||||
let result = FromJSValConvertible::from_jsval(cx, val, option);
|
||||
let result = result.and_then(|v| {
|
||||
Finite::<f64>::new(v).ok_or(())
|
||||
});
|
||||
result
|
||||
|
||||
fn from_jsval(cx: *mut JSContext, value: JSVal, option: ()) -> Result<Finite<T>, ()> {
|
||||
let result = try!(FromJSValConvertible::from_jsval(cx, value, option));
|
||||
match Finite::new(result) {
|
||||
Some(v) => Ok(v),
|
||||
None => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue