mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Introduce Finite<T: Float> for restricted values defined in WebIDL.
This commit is contained in:
parent
2bf2c0020b
commit
f7fd34c0aa
5 changed files with 114 additions and 30 deletions
|
@ -17,9 +17,9 @@
|
|||
//! | long long | `i64` |
|
||||
//! | unsigned long long | `u64` |
|
||||
//! | unrestricted float | `f32` |
|
||||
//! | float | `f32` |
|
||||
//! | float | `Finite<f32>` |
|
||||
//! | unrestricted double | `f64` |
|
||||
//! | double | `f64` |
|
||||
//! | double | `Finite<f64>` |
|
||||
//! | DOMString | `DOMString` |
|
||||
//! | USVString | `USVString` |
|
||||
//! | ByteString | `ByteString` |
|
||||
|
@ -34,6 +34,7 @@
|
|||
|
||||
use dom::bindings::codegen::PrototypeList;
|
||||
use dom::bindings::js::{JSRef, Root, Unrooted};
|
||||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::str::{ByteString, USVString};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, DOMClass};
|
||||
use util::str::DOMString;
|
||||
|
@ -256,6 +257,24 @@ impl FromJSValConvertible for f32 {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToJSValConvertible for Finite<f32> {
|
||||
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||
let value = self.clone().unwrap();
|
||||
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 {
|
||||
|
@ -271,6 +290,25 @@ impl FromJSValConvertible for f64 {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToJSValConvertible for Finite<f64> {
|
||||
#[inline]
|
||||
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||
let value = self.clone().unwrap();
|
||||
value.to_jsval(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromJSValConvertible for Finite<f64> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
impl ToJSValConvertible for str {
|
||||
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||
unsafe {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue