From c55f37a4757695c1543d556021340875bf39d9af Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Wed, 3 Apr 2024 17:27:32 -0700 Subject: [PATCH 1/6] Add TryFromJs for more types --- .../src/value/conversions/try_from_js.rs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/core/engine/src/value/conversions/try_from_js.rs b/core/engine/src/value/conversions/try_from_js.rs index 07d0fadeb7f..a4b5a465606 100644 --- a/core/engine/src/value/conversions/try_from_js.rs +++ b/core/engine/src/value/conversions/try_from_js.rs @@ -2,7 +2,7 @@ use num_bigint::BigInt; -use crate::{js_string, Context, JsBigInt, JsNativeError, JsResult, JsValue}; +use crate::{js_string, Context, JsBigInt, JsNativeError, JsObject, JsResult, JsString, JsValue}; /// This trait adds a fallible and efficient conversions from a [`JsValue`] to Rust types. pub trait TryFromJs: Sized { @@ -47,6 +47,17 @@ impl TryFromJs for String { } } +impl TryFromJs for JsString { + fn try_from_js(value: &JsValue, _context: &mut Context) -> JsResult { + match value { + JsValue::String(s) => Ok(s.clone()), + _ => Err(JsNativeError::typ() + .with_message("cannot convert value to a String") + .into()), + } + } +} + impl TryFromJs for Option where T: TryFromJs, @@ -91,6 +102,17 @@ where } } +impl TryFromJs for JsObject { + fn try_from_js(value: &JsValue, _context: &mut Context) -> JsResult { + match value { + JsValue::Object(o) => Ok(o.clone()), + _ => Err(JsNativeError::typ() + .with_message("cannot convert value to a Object") + .into()), + } + } +} + impl TryFromJs for JsBigInt { fn try_from_js(value: &JsValue, _context: &mut Context) -> JsResult { match value { From 4c3536c0ec3f94dcbc1942227f6a40a5c9aba028 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Wed, 3 Apr 2024 18:40:17 -0700 Subject: [PATCH 2/6] Add a new type Coerce<> to coerce values This can be used to transform values in to coerced versions by using the type system and TryFromJs. --- core/engine/src/value/conversions/coerce.rs | 109 ++++++++++++++++++++ core/engine/src/value/conversions/mod.rs | 2 + core/engine/src/value/mod.rs | 3 + 3 files changed, 114 insertions(+) create mode 100644 core/engine/src/value/conversions/coerce.rs diff --git a/core/engine/src/value/conversions/coerce.rs b/core/engine/src/value/conversions/coerce.rs new file mode 100644 index 00000000000..89d6cb7ab19 --- /dev/null +++ b/core/engine/src/value/conversions/coerce.rs @@ -0,0 +1,109 @@ +//! Types and functions for applying Coercing rules to [`JsValue`] when +//! converting. + +use crate::value::TryFromJs; +use crate::{Context, JsResult, JsValue}; +use boa_engine::JsNativeError; + +/// A wrapper type that allows coercing a `JsValue` to a specific type. +/// This is useful when you want to coerce a `JsValue` to a Rust type. +/// +/// # Example +/// ``` +/// # use boa_engine::{Context, js_string, JsValue}; +/// # use boa_engine::value::{Coerce, TryFromJs}; +/// # let mut context = Context::default(); +/// let value = JsValue::from(js_string!("42")); +/// let Coerce(coerced): Coerce = Coerce::try_from_js(&value, &mut context).unwrap(); +/// +/// assert_eq!(coerced, 42); +/// ``` +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Coerce(pub T); + +impl From for Coerce { + fn from(value: T) -> Self { + Self(value) + } +} + +macro_rules! decl_coerce_to_int { + ($($ty:ty),*) => { + $( + impl TryFromJs for Coerce<$ty> { + fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { + value.to_numeric_number(context).and_then(|num| { + if num.is_finite() { + if num >= f64::from(<$ty>::MAX) { + Err(JsNativeError::typ() + .with_message("cannot coerce value to integer, it is too large") + .into()) + } else if num <= f64::from(<$ty>::MIN) { + Err(JsNativeError::typ() + .with_message("cannot coerce value to integer, it is too small") + .into()) + // Only round if it differs from the next integer by an epsilon + } else if num.abs().fract() >= (1.0 - f64::EPSILON) { + Ok(Coerce(num.round() as $ty)) + } else { + Ok(Coerce(num as $ty)) + } + } else if num.is_nan() { + Err(JsNativeError::typ() + .with_message("cannot coerce NaN to integer") + .into()) + } else if num.is_infinite() { + Err(JsNativeError::typ() + .with_message("cannot coerce Infinity to integer") + .into()) + } else { + Err(JsNativeError::typ() + .with_message("cannot coerce non-finite number to integer") + .into()) + } + }) + } + } + )* + }; +} + +decl_coerce_to_int!(i8, i16, i32, u8, u16, u32); + +macro_rules! decl_coerce_to_float { + ($($ty:ty),*) => { + $( + impl TryFromJs for Coerce<$ty> { + fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { + value.to_numeric_number(context).and_then(|num| Ok(Coerce(<$ty>::try_from(num).map_err(|_| { + JsNativeError::typ() + .with_message("cannot coerce value to float") + })?))) + } + } + )* + }; +} + +decl_coerce_to_float!(f64); + +impl TryFromJs for Coerce { + fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { + value + .to_string(context) + .and_then(|s| s.to_std_string().map_err(|_| JsNativeError::typ().into())) + .map(Coerce) + } +} + +impl TryFromJs for Coerce { + fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { + value.to_string(context).map(Coerce) + } +} + +impl TryFromJs for Coerce { + fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { + Ok(Self(value.to_boolean())) + } +} diff --git a/core/engine/src/value/conversions/mod.rs b/core/engine/src/value/conversions/mod.rs index 0b2d02035dc..1a2be260a8d 100644 --- a/core/engine/src/value/conversions/mod.rs +++ b/core/engine/src/value/conversions/mod.rs @@ -7,6 +7,8 @@ use super::{JsBigInt, JsObject, JsString, JsSymbol, JsValue, Profiler}; mod serde_json; pub(super) mod try_from_js; +pub(super) mod coerce; + impl From for JsValue { fn from(value: JsString) -> Self { let _timer = Profiler::global().start_event("From", "value"); diff --git a/core/engine/src/value/mod.rs b/core/engine/src/value/mod.rs index a38c9fd8bba..2bbdba4a8aa 100644 --- a/core/engine/src/value/mod.rs +++ b/core/engine/src/value/mod.rs @@ -45,6 +45,9 @@ pub use self::{ #[doc(inline)] pub use boa_macros::TryFromJs; +#[doc(inline)] +pub use conversions::coerce::Coerce; + pub(crate) use self::conversions::IntoOrUndefined; static TWO_E_64: Lazy = Lazy::new(|| { From a5caeb953a3a2f9a613975e77f6c1a3f1dc356b2 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Wed, 3 Apr 2024 21:43:04 -0700 Subject: [PATCH 3/6] Fix build error --- core/engine/src/value/conversions/coerce.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/engine/src/value/conversions/coerce.rs b/core/engine/src/value/conversions/coerce.rs index 89d6cb7ab19..3fb6444d3df 100644 --- a/core/engine/src/value/conversions/coerce.rs +++ b/core/engine/src/value/conversions/coerce.rs @@ -2,7 +2,7 @@ //! converting. use crate::value::TryFromJs; -use crate::{Context, JsResult, JsValue}; +use crate::{Context, JsResult, JsString, JsValue}; use boa_engine::JsNativeError; /// A wrapper type that allows coercing a `JsValue` to a specific type. @@ -103,7 +103,7 @@ impl TryFromJs for Coerce { } impl TryFromJs for Coerce { - fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { + fn try_from_js(value: &JsValue, _context: &mut Context) -> JsResult { Ok(Self(value.to_boolean())) } } From cf2337336f63a2cea21228d6922952cab7301d15 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Thu, 4 Apr 2024 16:25:05 -0700 Subject: [PATCH 4/6] Rename Coerce<> to Convert<> --- core/engine/src/value/conversions/coerce.rs | 49 ++++++++++++++------ core/engine/src/value/mod.rs | 51 +++++++++++---------- 2 files changed, 60 insertions(+), 40 deletions(-) diff --git a/core/engine/src/value/conversions/coerce.rs b/core/engine/src/value/conversions/coerce.rs index 3fb6444d3df..a9fe95b55ef 100644 --- a/core/engine/src/value/conversions/coerce.rs +++ b/core/engine/src/value/conversions/coerce.rs @@ -1,27 +1,46 @@ //! Types and functions for applying Coercing rules to [`JsValue`] when //! converting. +use boa_engine::JsNativeError; + use crate::value::TryFromJs; use crate::{Context, JsResult, JsString, JsValue}; -use boa_engine::JsNativeError; /// A wrapper type that allows coercing a `JsValue` to a specific type. /// This is useful when you want to coerce a `JsValue` to a Rust type. /// /// # Example +/// Convert a string to number. /// ``` /// # use boa_engine::{Context, js_string, JsValue}; -/// # use boa_engine::value::{Coerce, TryFromJs}; +/// # use boa_engine::value::{Convert, TryFromJs}; /// # let mut context = Context::default(); /// let value = JsValue::from(js_string!("42")); -/// let Coerce(coerced): Coerce = Coerce::try_from_js(&value, &mut context).unwrap(); +/// let Convert(coerced): Convert = Convert::try_from_js(&value, &mut context).unwrap(); /// /// assert_eq!(coerced, 42); /// ``` +/// +/// Convert a number to a bool. +/// ``` +/// # use boa_engine::{Context, js_string, JsValue}; +/// # use boa_engine::value::{Convert, TryFromJs}; +/// # let mut context = Context::default(); +/// let value0 = JsValue::Integer(0); +/// let value1 = JsValue::Integer(1); +/// let value_nan = JsValue::Rational(f64::NAN); +/// let Convert(coerced0): Convert = Convert::try_from_js(&value0, &mut context).unwrap(); +/// let Convert(coerced1): Convert = Convert::try_from_js(&value1, &mut context).unwrap(); +/// let Convert(coerced_nan): Convert = Convert::try_from_js(&value_nan, &mut context).unwrap(); +/// +/// assert_eq!(coerced0, false); +/// assert_eq!(coerced1, true); +/// assert_eq!(coerced_nan, false); +/// ``` #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct Coerce(pub T); +pub struct Convert(pub T); -impl From for Coerce { +impl From for Convert { fn from(value: T) -> Self { Self(value) } @@ -30,7 +49,7 @@ impl From for Coerce { macro_rules! decl_coerce_to_int { ($($ty:ty),*) => { $( - impl TryFromJs for Coerce<$ty> { + impl TryFromJs for Convert<$ty> { fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { value.to_numeric_number(context).and_then(|num| { if num.is_finite() { @@ -44,9 +63,9 @@ macro_rules! decl_coerce_to_int { .into()) // Only round if it differs from the next integer by an epsilon } else if num.abs().fract() >= (1.0 - f64::EPSILON) { - Ok(Coerce(num.round() as $ty)) + Ok(Convert(num.round() as $ty)) } else { - Ok(Coerce(num as $ty)) + Ok(Convert(num as $ty)) } } else if num.is_nan() { Err(JsNativeError::typ() @@ -73,9 +92,9 @@ decl_coerce_to_int!(i8, i16, i32, u8, u16, u32); macro_rules! decl_coerce_to_float { ($($ty:ty),*) => { $( - impl TryFromJs for Coerce<$ty> { + impl TryFromJs for Convert<$ty> { fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { - value.to_numeric_number(context).and_then(|num| Ok(Coerce(<$ty>::try_from(num).map_err(|_| { + value.to_numeric_number(context).and_then(|num| Ok(Convert(<$ty>::try_from(num).map_err(|_| { JsNativeError::typ() .with_message("cannot coerce value to float") })?))) @@ -87,22 +106,22 @@ macro_rules! decl_coerce_to_float { decl_coerce_to_float!(f64); -impl TryFromJs for Coerce { +impl TryFromJs for Convert { fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { value .to_string(context) .and_then(|s| s.to_std_string().map_err(|_| JsNativeError::typ().into())) - .map(Coerce) + .map(Convert) } } -impl TryFromJs for Coerce { +impl TryFromJs for Convert { fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { - value.to_string(context).map(Coerce) + value.to_string(context).map(Convert) } } -impl TryFromJs for Coerce { +impl TryFromJs for Convert { fn try_from_js(value: &JsValue, _context: &mut Context) -> JsResult { Ok(Self(value.to_boolean())) } diff --git a/core/engine/src/value/mod.rs b/core/engine/src/value/mod.rs index 2bbdba4a8aa..fffb3bc2b24 100644 --- a/core/engine/src/value/mod.rs +++ b/core/engine/src/value/mod.rs @@ -2,16 +2,23 @@ //! //! Javascript values, utility methods and conversion between Javascript values and Rust values. -mod conversions; -pub(crate) mod display; -mod equality; -mod hash; -mod integer; -mod operations; -mod r#type; +use std::{ + collections::HashSet, + fmt::{self, Display}, + ops::Sub, +}; -#[cfg(test)] -mod tests; +use num_bigint::BigInt; +use num_integer::Integer; +use num_traits::{ToPrimitive, Zero}; +use once_cell::sync::Lazy; + +use boa_gc::{custom_trace, Finalize, Trace}; +#[doc(inline)] +pub use boa_macros::TryFromJs; +use boa_profiler::Profiler; +#[doc(inline)] +pub use conversions::coerce::Convert; use crate::{ builtins::{ @@ -25,30 +32,24 @@ use crate::{ symbol::JsSymbol, Context, JsBigInt, JsResult, JsString, }; -use boa_gc::{custom_trace, Finalize, Trace}; -use boa_profiler::Profiler; -use num_bigint::BigInt; -use num_integer::Integer; -use num_traits::{ToPrimitive, Zero}; -use once_cell::sync::Lazy; -use std::{ - collections::HashSet, - fmt::{self, Display}, - ops::Sub, -}; +pub(crate) use self::conversions::IntoOrUndefined; #[doc(inline)] pub use self::{ conversions::try_from_js::TryFromJs, display::ValueDisplay, integer::IntegerOrInfinity, operations::*, r#type::Type, }; -#[doc(inline)] -pub use boa_macros::TryFromJs; -#[doc(inline)] -pub use conversions::coerce::Coerce; +mod conversions; +pub(crate) mod display; +mod equality; +mod hash; +mod integer; +mod operations; +mod r#type; -pub(crate) use self::conversions::IntoOrUndefined; +#[cfg(test)] +mod tests; static TWO_E_64: Lazy = Lazy::new(|| { const TWO_E_64: u128 = 2u128.pow(64); From baa860c48bd473d6576f9b2cf907497d18feb57e Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Mon, 8 Apr 2024 20:08:46 -0700 Subject: [PATCH 5/6] replace missed coerce to Convert --- .../conversions/{coerce.rs => convert.rs} | 54 ++++++++++--------- core/engine/src/value/conversions/mod.rs | 2 +- core/engine/src/value/mod.rs | 12 ++--- 3 files changed, 35 insertions(+), 33 deletions(-) rename core/engine/src/value/conversions/{coerce.rs => convert.rs} (65%) diff --git a/core/engine/src/value/conversions/coerce.rs b/core/engine/src/value/conversions/convert.rs similarity index 65% rename from core/engine/src/value/conversions/coerce.rs rename to core/engine/src/value/conversions/convert.rs index a9fe95b55ef..2e13195ef33 100644 --- a/core/engine/src/value/conversions/coerce.rs +++ b/core/engine/src/value/conversions/convert.rs @@ -1,13 +1,18 @@ -//! Types and functions for applying Coercing rules to [`JsValue`] when -//! converting. +//! Types and functions for applying JavaScript Convert rules to [`JsValue`] when +//! converting. See https://262.ecma-international.org/5.1/#sec-9 (Section 9) for +//! conversion rules of JavaScript types. +//! +//! Some conversions are not specified in the spec (e.g. integer conversions), +//! and we apply rules that make sense (e.g. converting to Number and rounding +//! if necessary). use boa_engine::JsNativeError; -use crate::value::TryFromJs; use crate::{Context, JsResult, JsString, JsValue}; +use crate::value::TryFromJs; -/// A wrapper type that allows coercing a `JsValue` to a specific type. -/// This is useful when you want to coerce a `JsValue` to a Rust type. +/// A wrapper type that allows converting a `JsValue` to a specific type. +/// This is useful when you want to convert a `JsValue` to a Rust type. /// /// # Example /// Convert a string to number. @@ -16,9 +21,9 @@ use crate::{Context, JsResult, JsString, JsValue}; /// # use boa_engine::value::{Convert, TryFromJs}; /// # let mut context = Context::default(); /// let value = JsValue::from(js_string!("42")); -/// let Convert(coerced): Convert = Convert::try_from_js(&value, &mut context).unwrap(); +/// let Convert(converted): Convert = Convert::try_from_js(&value, &mut context).unwrap(); /// -/// assert_eq!(coerced, 42); +/// assert_eq!(converted, 42); /// ``` /// /// Convert a number to a bool. @@ -26,16 +31,13 @@ use crate::{Context, JsResult, JsString, JsValue}; /// # use boa_engine::{Context, js_string, JsValue}; /// # use boa_engine::value::{Convert, TryFromJs}; /// # let mut context = Context::default(); -/// let value0 = JsValue::Integer(0); -/// let value1 = JsValue::Integer(1); -/// let value_nan = JsValue::Rational(f64::NAN); -/// let Convert(coerced0): Convert = Convert::try_from_js(&value0, &mut context).unwrap(); -/// let Convert(coerced1): Convert = Convert::try_from_js(&value1, &mut context).unwrap(); -/// let Convert(coerced_nan): Convert = Convert::try_from_js(&value_nan, &mut context).unwrap(); +/// let Convert(conv0): Convert = Convert::try_from_js(&JsValue::Integer(0), &mut context).unwrap(); +/// let Convert(conv5): Convert = Convert::try_from_js(&JsValue::Integer(5), &mut context).unwrap(); +/// let Convert(conv_nan): Convert = Convert::try_from_js(&JsValue::Rational(f64::NAN), &mut context).unwrap(); /// -/// assert_eq!(coerced0, false); -/// assert_eq!(coerced1, true); -/// assert_eq!(coerced_nan, false); +/// assert_eq!(conv0, false); +/// assert_eq!(conv5, true); +/// assert_eq!(conv_nan, false); /// ``` #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Convert(pub T); @@ -46,7 +48,7 @@ impl From for Convert { } } -macro_rules! decl_coerce_to_int { +macro_rules! decl_convert_to_int { ($($ty:ty),*) => { $( impl TryFromJs for Convert<$ty> { @@ -55,11 +57,11 @@ macro_rules! decl_coerce_to_int { if num.is_finite() { if num >= f64::from(<$ty>::MAX) { Err(JsNativeError::typ() - .with_message("cannot coerce value to integer, it is too large") + .with_message("cannot convert value to integer, it is too large") .into()) } else if num <= f64::from(<$ty>::MIN) { Err(JsNativeError::typ() - .with_message("cannot coerce value to integer, it is too small") + .with_message("cannot convert value to integer, it is too small") .into()) // Only round if it differs from the next integer by an epsilon } else if num.abs().fract() >= (1.0 - f64::EPSILON) { @@ -69,15 +71,15 @@ macro_rules! decl_coerce_to_int { } } else if num.is_nan() { Err(JsNativeError::typ() - .with_message("cannot coerce NaN to integer") + .with_message("cannot convert NaN to integer") .into()) } else if num.is_infinite() { Err(JsNativeError::typ() - .with_message("cannot coerce Infinity to integer") + .with_message("cannot convert Infinity to integer") .into()) } else { Err(JsNativeError::typ() - .with_message("cannot coerce non-finite number to integer") + .with_message("cannot convert non-finite number to integer") .into()) } }) @@ -87,16 +89,16 @@ macro_rules! decl_coerce_to_int { }; } -decl_coerce_to_int!(i8, i16, i32, u8, u16, u32); +decl_convert_to_int!(i8, i16, i32, u8, u16, u32); -macro_rules! decl_coerce_to_float { +macro_rules! decl_convert_to_float { ($($ty:ty),*) => { $( impl TryFromJs for Convert<$ty> { fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { value.to_numeric_number(context).and_then(|num| Ok(Convert(<$ty>::try_from(num).map_err(|_| { JsNativeError::typ() - .with_message("cannot coerce value to float") + .with_message("cannot convert value to float") })?))) } } @@ -104,7 +106,7 @@ macro_rules! decl_coerce_to_float { }; } -decl_coerce_to_float!(f64); +decl_convert_to_float!(f64); impl TryFromJs for Convert { fn try_from_js(value: &JsValue, context: &mut Context) -> JsResult { diff --git a/core/engine/src/value/conversions/mod.rs b/core/engine/src/value/conversions/mod.rs index 1a2be260a8d..6d68ea075e6 100644 --- a/core/engine/src/value/conversions/mod.rs +++ b/core/engine/src/value/conversions/mod.rs @@ -7,7 +7,7 @@ use super::{JsBigInt, JsObject, JsString, JsSymbol, JsValue, Profiler}; mod serde_json; pub(super) mod try_from_js; -pub(super) mod coerce; +pub(super) mod convert; impl From for JsValue { fn from(value: JsString) -> Self { diff --git a/core/engine/src/value/mod.rs b/core/engine/src/value/mod.rs index fffb3bc2b24..3712481d82a 100644 --- a/core/engine/src/value/mod.rs +++ b/core/engine/src/value/mod.rs @@ -18,27 +18,27 @@ use boa_gc::{custom_trace, Finalize, Trace}; pub use boa_macros::TryFromJs; use boa_profiler::Profiler; #[doc(inline)] -pub use conversions::coerce::Convert; +pub use conversions::convert::Convert; use crate::{ builtins::{ number::{f64_to_int32, f64_to_uint32}, Number, Promise, }, + Context, error::JsNativeError, js_string, - object::JsObject, - property::{PropertyDescriptor, PropertyKey}, - symbol::JsSymbol, - Context, JsBigInt, JsResult, JsString, + JsBigInt, + JsResult, + JsString, object::JsObject, property::{PropertyDescriptor, PropertyKey}, symbol::JsSymbol, }; -pub(crate) use self::conversions::IntoOrUndefined; #[doc(inline)] pub use self::{ conversions::try_from_js::TryFromJs, display::ValueDisplay, integer::IntegerOrInfinity, operations::*, r#type::Type, }; +pub(crate) use self::conversions::IntoOrUndefined; mod conversions; pub(crate) mod display; From 645b5e5eaadca1b244b03ab2428da6a0369dd724 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Mon, 8 Apr 2024 20:15:31 -0700 Subject: [PATCH 6/6] cargo fmt and clippy --- core/engine/src/value/conversions/convert.rs | 4 ++-- core/engine/src/value/mod.rs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/engine/src/value/conversions/convert.rs b/core/engine/src/value/conversions/convert.rs index 2e13195ef33..397afa434f2 100644 --- a/core/engine/src/value/conversions/convert.rs +++ b/core/engine/src/value/conversions/convert.rs @@ -1,5 +1,5 @@ //! Types and functions for applying JavaScript Convert rules to [`JsValue`] when -//! converting. See https://262.ecma-international.org/5.1/#sec-9 (Section 9) for +//! converting. See (Section 9) for //! conversion rules of JavaScript types. //! //! Some conversions are not specified in the spec (e.g. integer conversions), @@ -8,8 +8,8 @@ use boa_engine::JsNativeError; -use crate::{Context, JsResult, JsString, JsValue}; use crate::value::TryFromJs; +use crate::{Context, JsResult, JsString, JsValue}; /// A wrapper type that allows converting a `JsValue` to a specific type. /// This is useful when you want to convert a `JsValue` to a Rust type. diff --git a/core/engine/src/value/mod.rs b/core/engine/src/value/mod.rs index 3712481d82a..6678e294d63 100644 --- a/core/engine/src/value/mod.rs +++ b/core/engine/src/value/mod.rs @@ -25,20 +25,20 @@ use crate::{ number::{f64_to_int32, f64_to_uint32}, Number, Promise, }, - Context, error::JsNativeError, js_string, - JsBigInt, - JsResult, - JsString, object::JsObject, property::{PropertyDescriptor, PropertyKey}, symbol::JsSymbol, + object::JsObject, + property::{PropertyDescriptor, PropertyKey}, + symbol::JsSymbol, + Context, JsBigInt, JsResult, JsString, }; +pub(crate) use self::conversions::IntoOrUndefined; #[doc(inline)] pub use self::{ conversions::try_from_js::TryFromJs, display::ValueDisplay, integer::IntegerOrInfinity, operations::*, r#type::Type, }; -pub(crate) use self::conversions::IntoOrUndefined; mod conversions; pub(crate) mod display;