mirror of https://github.com/boa-dev/boa.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
581 B
22 lines
581 B
#![allow(unused, unused_tuple_struct_fields)] |
|
|
|
use boa_engine::{value::TryFromJs, Context, JsNativeError, JsResult, JsValue}; |
|
|
|
#[derive(TryFromJs)] |
|
struct TestStruct { |
|
inner: bool, |
|
#[boa(from_js_with = "lossy_float")] |
|
my_int: i16, |
|
} |
|
|
|
fn main() {} |
|
|
|
fn lossy_float(value: &JsValue, _context: &mut Context) -> JsResult<i16> { |
|
match value { |
|
JsValue::Rational(r) => Ok(r.round() as i16), |
|
JsValue::Integer(i) => Ok(*i as i16), |
|
_ => Err(JsNativeError::typ() |
|
.with_message("cannot convert value to an i16") |
|
.into()), |
|
} |
|
}
|
|
|