diff --git a/core/engine/src/context/hooks.rs b/core/engine/src/context/hooks.rs index 3ddc0bc2a3..eeaf5e643d 100644 --- a/core/engine/src/context/hooks.rs +++ b/core/engine/src/context/hooks.rs @@ -45,8 +45,7 @@ use time::util::local_offset; /// } /// } /// -/// let context = -/// &mut ContextBuilder::new().host_hooks(&Hooks).build().unwrap(); +/// let context = &mut ContextBuilder::new().host_hooks(&Hooks).build().unwrap(); /// let result = context.eval(Source::from_bytes(r#"eval("let a = 5")"#)); /// assert_eq!( /// result.unwrap_err().to_string(), diff --git a/core/engine/src/context/mod.rs b/core/engine/src/context/mod.rs index ff8c391a1a..f5f43a0ed7 100644 --- a/core/engine/src/context/mod.rs +++ b/core/engine/src/context/mod.rs @@ -220,11 +220,7 @@ impl Context { /// let mut context = Context::default(); /// /// context - /// .register_global_property( - /// js_str!("myPrimitiveProperty"), - /// 10, - /// Attribute::all(), - /// ) + /// .register_global_property(js_str!("myPrimitiveProperty"), 10, Attribute::all()) /// .expect("property shouldn't exist"); /// /// let object = ObjectInitializer::new(&mut context) @@ -232,11 +228,7 @@ impl Context { /// .property(js_str!("y"), 1, Attribute::all()) /// .build(); /// context - /// .register_global_property( - /// js_str!("myObjectProperty"), - /// object, - /// Attribute::all(), - /// ) + /// .register_global_property(js_str!("myObjectProperty"), object, Attribute::all()) /// .expect("property shouldn't exist"); /// ``` pub fn register_global_property( diff --git a/core/engine/src/error.rs b/core/engine/src/error.rs index 44adccd7f8..4ad9c62293 100644 --- a/core/engine/src/error.rs +++ b/core/engine/src/error.rs @@ -34,7 +34,10 @@ use thiserror::Error; /// let cause = JsError::from_opaque(js_str!("error!").into()); /// /// assert!(cause.as_opaque().is_some()); -/// assert_eq!(cause.as_opaque().unwrap(), &JsValue::from(js_str!("error!"))); +/// assert_eq!( +/// cause.as_opaque().unwrap(), +/// &JsValue::from(js_str!("error!")) +/// ); /// /// let native_error: JsError = JsNativeError::typ() /// .with_message("invalid type!") @@ -170,8 +173,7 @@ impl JsError { /// # use boa_engine::{Context, JsError, JsNativeError}; /// # use boa_engine::builtins::error::ErrorObject; /// let context = &mut Context::default(); - /// let error: JsError = - /// JsNativeError::eval().with_message("invalid script").into(); + /// let error: JsError = JsNativeError::eval().with_message("invalid script").into(); /// let error_val = error.to_opaque(context); /// /// assert!(error_val.as_object().unwrap().is::()); @@ -346,8 +348,7 @@ impl JsError { /// /// ```rust /// # use boa_engine::{JsError, JsNativeError, JsValue}; - /// let error: JsError = - /// JsNativeError::error().with_message("Unknown error").into(); + /// let error: JsError = JsNativeError::error().with_message("Unknown error").into(); /// /// assert!(error.as_native().is_some()); /// diff --git a/core/engine/src/object/builtins/jsdataview.rs b/core/engine/src/object/builtins/jsdataview.rs index fdcf05b375..b5157155b3 100644 --- a/core/engine/src/object/builtins/jsdataview.rs +++ b/core/engine/src/object/builtins/jsdataview.rs @@ -23,8 +23,7 @@ use std::ops::Deref; /// let array_buffer = JsArrayBuffer::new(4, context)?; /// /// // Create a new Dataview from pre-existing ArrayBuffer -/// let data_view = -/// JsDataView::from_js_array_buffer(array_buffer, None, None, context)?; +/// let data_view = JsDataView::from_js_array_buffer(array_buffer, None, None, context)?; /// /// # Ok(()) /// # } diff --git a/core/engine/src/object/builtins/jsdate.rs b/core/engine/src/object/builtins/jsdate.rs index c647ac5704..cadf65877a 100644 --- a/core/engine/src/object/builtins/jsdate.rs +++ b/core/engine/src/object/builtins/jsdate.rs @@ -14,9 +14,7 @@ use time::{format_description::well_known::Rfc3339, OffsetDateTime}; /// Create a `JsDate` object and set date to December 4 1995 /// /// ``` -/// use boa_engine::{ -/// js_str, object::builtins::JsDate, Context, JsResult, JsValue, -/// }; +/// use boa_engine::{js_str, object::builtins::JsDate, Context, JsResult, JsValue}; /// /// fn main() -> JsResult<()> { /// // JS mutable Context diff --git a/core/engine/src/object/builtins/jsmap.rs b/core/engine/src/object/builtins/jsmap.rs index d34868c56e..196907d027 100644 --- a/core/engine/src/object/builtins/jsmap.rs +++ b/core/engine/src/object/builtins/jsmap.rs @@ -111,10 +111,7 @@ impl JsMap { /// let js_array = JsArray::new(context); /// /// // Create a `[key, value]` pair of JsValues and add it to the `JsArray` as a `JsArray` - /// let vec_one: Vec = vec![ - /// js_str!("first-key").into(), - /// js_str!("first-value").into() - /// ]; + /// let vec_one: Vec = vec![js_str!("first-key").into(), js_str!("first-value").into()]; /// js_array.push(JsArray::from_iter(vec_one, context), context)?; /// /// // Create a `JsMap` from the `JsArray` using it's iterable property. @@ -232,10 +229,7 @@ impl JsMap { /// js_map.set(js_str!("foo"), js_str!("bar"), context)?; /// js_map.set(2, 4, context)?; /// - /// assert_eq!( - /// js_map.get(js_str!("foo"), context)?, - /// js_str!("bar").into() - /// ); + /// assert_eq!(js_map.get(js_str!("foo"), context)?, js_str!("bar").into()); /// assert_eq!(js_map.get(2, context)?, 4.into()); /// # Ok(()) /// # } @@ -296,10 +290,7 @@ impl JsMap { /// js_map.delete(js_str!("foo"), context)?; /// /// assert_eq!(js_map.get_size(context)?, 1.into()); - /// assert_eq!( - /// js_map.get(js_str!("foo"), context)?, - /// JsValue::undefined() - /// ); + /// assert_eq!(js_map.get(js_str!("foo"), context)?, JsValue::undefined()); /// # Ok(()) /// # } /// ``` diff --git a/core/engine/src/object/builtins/jspromise.rs b/core/engine/src/object/builtins/jspromise.rs index 7f610f670d..9d3358c4bf 100644 --- a/core/engine/src/object/builtins/jspromise.rs +++ b/core/engine/src/object/builtins/jspromise.rs @@ -34,20 +34,14 @@ use boa_gc::{Finalize, Gc, GcRefCell, Trace}; /// # fn main() -> Result<(), Box> { /// let context = &mut Context::default(); /// -/// context.register_global_property( -/// js_str!("finally"), -/// false, -/// Attribute::all(), -/// ); +/// context.register_global_property(js_str!("finally"), false, Attribute::all()); /// /// let promise = JsPromise::new( /// |resolvers, context| { /// let result = js_str!("hello world!").into(); -/// resolvers.resolve.call( -/// &JsValue::undefined(), -/// &[result], -/// context, -/// )?; +/// resolvers +/// .resolve +/// .call(&JsValue::undefined(), &[result], context)?; /// Ok(JsValue::undefined()) /// }, /// context, @@ -57,8 +51,7 @@ use boa_gc::{Finalize, Gc, GcRefCell, Trace}; /// .then( /// Some( /// NativeFunction::from_fn_ptr(|_, args, _| { -/// Err(JsError::from_opaque(args.get_or_undefined(0).clone()) -/// .into()) +/// Err(JsError::from_opaque(args.get_or_undefined(0).clone()).into()) /// }) /// .to_js_function(context.realm()), /// ), @@ -66,10 +59,8 @@ use boa_gc::{Finalize, Gc, GcRefCell, Trace}; /// context, /// ) /// .catch( -/// NativeFunction::from_fn_ptr(|_, args, _| { -/// Ok(args.get_or_undefined(0).clone()) -/// }) -/// .to_js_function(context.realm()), +/// NativeFunction::from_fn_ptr(|_, args, _| Ok(args.get_or_undefined(0).clone())) +/// .to_js_function(context.realm()), /// context, /// ) /// .finally( @@ -140,11 +131,9 @@ impl JsPromise { /// let promise = JsPromise::new( /// |resolvers, context| { /// let result = js_string!("hello world").into(); - /// resolvers.resolve.call( - /// &JsValue::undefined(), - /// &[result], - /// context, - /// )?; + /// resolvers + /// .resolve + /// .call(&JsValue::undefined(), &[result], context)?; /// Ok(JsValue::undefined()) /// }, /// context, @@ -379,10 +368,7 @@ impl JsPromise { /// # }; /// let context = &mut Context::default(); /// - /// let promise = JsPromise::reject( - /// JsError::from_opaque(js_string!("oops!").into()), - /// context, - /// ); + /// let promise = JsPromise::reject(JsError::from_opaque(js_string!("oops!").into()), context); /// /// assert_eq!( /// promise.state(), @@ -467,11 +453,9 @@ impl JsPromise { /// /// let promise = JsPromise::new( /// |resolvers, context| { - /// resolvers.resolve.call( - /// &JsValue::undefined(), - /// &[255.255.into()], - /// context, - /// )?; + /// resolvers + /// .resolve + /// .call(&JsValue::undefined(), &[255.255.into()], context)?; /// Ok(JsValue::undefined()) /// }, /// context, @@ -534,11 +518,9 @@ impl JsPromise { /// |resolvers, context| { /// let error = JsNativeError::typ().with_message("thrown"); /// let error = error.to_opaque(context); - /// resolvers.reject.call( - /// &JsValue::undefined(), - /// &[error.into()], - /// context, - /// )?; + /// resolvers + /// .reject + /// .call(&JsValue::undefined(), &[error.into()], context)?; /// Ok(JsValue::undefined()) /// }, /// context, @@ -592,21 +574,15 @@ impl JsPromise { /// # fn main() -> Result<(), Box> { /// let context = &mut Context::default(); /// - /// context.register_global_property( - /// js_string!("finally"), - /// false, - /// Attribute::all(), - /// )?; + /// context.register_global_property(js_string!("finally"), false, Attribute::all())?; /// /// let promise = JsPromise::new( /// |resolvers, context| { /// let error = JsNativeError::typ().with_message("thrown"); /// let error = error.to_opaque(context); - /// resolvers.reject.call( - /// &JsValue::undefined(), - /// &[error.into()], - /// context, - /// )?; + /// resolvers + /// .reject + /// .call(&JsValue::undefined(), &[error.into()], context)?; /// Ok(JsValue::undefined()) /// }, /// context, diff --git a/core/engine/src/object/datatypes.rs b/core/engine/src/object/datatypes.rs index 9b892bb07e..4bf28fe4ae 100644 --- a/core/engine/src/object/datatypes.rs +++ b/core/engine/src/object/datatypes.rs @@ -33,8 +33,7 @@ use super::internal_methods::{InternalObjectMethods, ORDINARY_INTERNAL_METHODS}; /// counter: usize, /// } /// -/// let object = -/// JsObject::from_proto_and_data(None, CustomStruct { counter: 5 }); +/// let object = JsObject::from_proto_and_data(None, CustomStruct { counter: 5 }); /// /// assert_eq!(object.downcast_ref::().unwrap().counter, 5); /// ``` diff --git a/core/engine/src/value/conversions/convert.rs b/core/engine/src/value/conversions/convert.rs index 397afa434f..ea92b23943 100644 --- a/core/engine/src/value/conversions/convert.rs +++ b/core/engine/src/value/conversions/convert.rs @@ -31,9 +31,12 @@ 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 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(); +/// 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!(conv0, false); /// assert_eq!(conv5, true); diff --git a/core/interop/src/lib.rs b/core/interop/src/lib.rs index 54cfc27d54..a15ab16c1b 100644 --- a/core/interop/src/lib.rs +++ b/core/interop/src/lib.rs @@ -58,7 +58,13 @@ impl + Clone> IntoJsModule fo /// # let mut context = Context::default(); /// let f = |a: i32, b: i32| a + b; /// let f = unsafe { f.into_js_function_unsafe(&mut context) }; -/// let result = f.call(&JsValue::undefined(), &[JsValue::from(1), JsValue::from(2)], &mut context).unwrap(); +/// let result = f +/// .call( +/// &JsValue::undefined(), +/// &[JsValue::from(1), JsValue::from(2)], +/// &mut context, +/// ) +/// .unwrap(); /// assert_eq!(result, JsValue::new(3)); /// ``` /// @@ -79,8 +85,10 @@ impl + Clone> IntoJsModule fo /// move |a: i32| *x.borrow_mut() += a /// }; /// let f = unsafe { f.into_js_function_unsafe(&mut context) }; -/// f.call(&JsValue::undefined(), &[JsValue::from(1)], &mut context).unwrap(); -/// f.call(&JsValue::undefined(), &[JsValue::from(4)], &mut context).unwrap(); +/// f.call(&JsValue::undefined(), &[JsValue::from(1)], &mut context) +/// .unwrap(); +/// f.call(&JsValue::undefined(), &[JsValue::from(4)], &mut context) +/// .unwrap(); /// assert_eq!(*x.borrow(), 5); /// ``` pub trait UnsafeIntoJsFunction: private::IntoJsFunctionSealed { @@ -103,11 +111,13 @@ pub trait UnsafeIntoJsFunction: private::IntoJsFunctionSealed: private::IntoJsFunctionSealed + Copy { @@ -155,14 +165,19 @@ impl<'a, T: TryFromJs> TryFromJsArgument<'a> for T { /// # use boa_interop::{IntoJsFunctionCopied, JsRest}; /// # let mut context = Context::default(); /// let sums = (|args: JsRest, context: &mut Context| -> i32 { -/// args.iter().map(|i| i.try_js_into::(context).unwrap()).sum::() -/// }).into_js_function_copied(&mut context); +/// args.iter() +/// .map(|i| i.try_js_into::(context).unwrap()) +/// .sum::() +/// }) +/// .into_js_function_copied(&mut context); /// -/// let result = sums.call( -/// &JsValue::undefined(), -/// &[JsValue::from(1), JsValue::from(2), JsValue::from(3)], -/// &mut context -/// ).unwrap(); +/// let result = sums +/// .call( +/// &JsValue::undefined(), +/// &[JsValue::from(1), JsValue::from(2), JsValue::from(3)], +/// &mut context, +/// ) +/// .unwrap(); /// assert_eq!(result, JsValue::new(6)); /// ``` #[derive(Debug, Clone)] @@ -224,15 +239,22 @@ impl<'a> IntoIterator for JsRest<'a> { /// # use boa_engine::{Context, JsValue}; /// # use boa_interop::{IntoJsFunctionCopied, JsAll}; /// # let mut context = Context::default(); -/// let sums = (|args: JsAll, context: &mut Context| -> i32 { -/// args.iter().sum() -/// }).into_js_function_copied(&mut context); +/// let sums = (|args: JsAll, context: &mut Context| -> i32 { args.iter().sum() }) +/// .into_js_function_copied(&mut context); /// -/// let result = sums.call( -/// &JsValue::undefined(), -/// &[JsValue::from(1), JsValue::from(2), JsValue::from(3), JsValue::Boolean(true), JsValue::from(4)], -/// &mut context -/// ).unwrap(); +/// let result = sums +/// .call( +/// &JsValue::undefined(), +/// &[ +/// JsValue::from(1), +/// JsValue::from(2), +/// JsValue::from(3), +/// JsValue::Boolean(true), +/// JsValue::from(4), +/// ], +/// &mut context, +/// ) +/// .unwrap(); /// assert_eq!(result, JsValue::new(6)); /// ``` #[derive(Debug, Clone)] @@ -316,20 +338,22 @@ impl<'a, T: TryFromJs> TryFromJsArgument<'a> for JsThis { /// For example, /// ``` /// # use boa_engine::{Context, Finalize, JsData, JsValue, Trace}; -/// use boa_interop::{IntoJsFunctionCopied, ContextData}; +/// use boa_interop::{ContextData, IntoJsFunctionCopied}; /// /// #[derive(Clone, Debug, Finalize, JsData, Trace)] /// struct CustomHostDefinedStruct { -/// #[unsafe_ignore_trace] -/// pub counter: usize, +/// #[unsafe_ignore_trace] +/// pub counter: usize, /// } /// let mut context = Context::default(); /// context.insert_data(CustomHostDefinedStruct { counter: 123 }); -/// let f = (|ContextData(host): ContextData| { -/// host.counter + 1 -/// }).into_js_function_copied(&mut context); +/// let f = (|ContextData(host): ContextData| host.counter + 1) +/// .into_js_function_copied(&mut context); /// -/// assert_eq!(f.call(&JsValue::undefined(), &[], &mut context), Ok(JsValue::new(124))); +/// assert_eq!( +/// f.call(&JsValue::undefined(), &[], &mut context), +/// Ok(JsValue::new(124)) +/// ); /// ``` #[derive(Debug, Clone)] pub struct ContextData(pub T); diff --git a/core/runtime/src/lib.rs b/core/runtime/src/lib.rs index 16d0da9752..f25a0ba6e9 100644 --- a/core/runtime/src/lib.rs +++ b/core/runtime/src/lib.rs @@ -6,7 +6,7 @@ //! 1. Add **boa_runtime** as a dependency to your project along with **boa_engine**. //! //! ``` -//! use boa_engine::{ Context, Source, property::Attribute, js_string }; +//! use boa_engine::{js_string, property::Attribute, Context, Source}; //! use boa_runtime::Console; //! //! // Create the context.