From 6b79d57920a6f91e2fa4f9464e2c46b93ae3486d Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 7 Apr 2015 13:35:28 +0200 Subject: [PATCH] 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. --- .../dom/bindings/codegen/CodegenRust.py | 23 +++++-------------- components/script/dom/bindings/conversions.rs | 6 ++++- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index b828ccb74bd..adebf601568 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -887,23 +887,12 @@ 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" - " Ok(v) => v,\n" - " Err(_) => { %s }\n" - "}" % exceptionCode) + #XXXjdm support conversionBehavior here + template = ( + "match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n" + " Ok(v) => v,\n" + " Err(_) => { %s }\n" + "}" % exceptionCode) if defaultValue is not None: if isinstance(defaultValue, IDLNullValue): diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index f027b8b8504..eb6d7d60680 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -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> 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(()) + }, } } }