When converting a non-finite float, throw the TypeError from the FromJSValConvertible implementation.

This removes some unnecessary custom code in the codegen and makes this
implementation follow the convention of having thrown an exception when
returning Err() from FromJSValConvertible.
This commit is contained in:
Ms2ger 2015-04-07 13:35:28 +02:00
parent e3683c8598
commit 6b79d57920
2 changed files with 11 additions and 18 deletions

View file

@ -887,17 +887,6 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.nullable():
declType = CGWrapper(declType, pre="Option<", post=">")
template = ""
if type.isFloat() and not type.isUnrestricted():
template = (
"match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
" Ok(v) => v,\n"
" Err(_) => {\n"
" throw_type_error(cx, \"this argument is not a finite floating-point value\");\n"
" %s\n"
" }\n"
"}" % exceptionCode)
else:
#XXXjdm support conversionBehavior here
template = (
"match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"

View file

@ -33,6 +33,7 @@
//! | union types | `T` |
use dom::bindings::codegen::PrototypeList;
use dom::bindings::error::throw_type_error;
use dom::bindings::js::{JSRef, Root, Unrooted};
use dom::bindings::num::Finite;
use dom::bindings::str::{ByteString, USVString};
@ -288,7 +289,10 @@ impl<T: Float + FromJSValConvertible<Config=()>> FromJSValConvertible for Finite
let result = try!(FromJSValConvertible::from_jsval(cx, value, option));
match Finite::new(result) {
Some(v) => Ok(v),
None => Err(()),
None => {
throw_type_error(cx, "this argument is not a finite floating-point value");
Err(())
},
}
}
}