Skip to content

Commit

Permalink
format code in comments (#3902)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwilliams authored Jul 8, 2024
1 parent 841104e commit 6a6fa6a
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 115 deletions.
3 changes: 1 addition & 2 deletions core/engine/src/context/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
12 changes: 2 additions & 10 deletions core/engine/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,15 @@ 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)
/// .property(js_str!("x"), 0, Attribute::all())
/// .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<K, V>(
Expand Down
11 changes: 6 additions & 5 deletions core/engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down Expand Up @@ -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::<ErrorObject>());
Expand Down Expand Up @@ -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());
///
Expand Down
3 changes: 1 addition & 2 deletions core/engine/src/object/builtins/jsdataview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
/// # }
Expand Down
4 changes: 1 addition & 3 deletions core/engine/src/object/builtins/jsdate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 3 additions & 12 deletions core/engine/src/object/builtins/jsmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsValue> = vec![
/// js_str!("first-key").into(),
/// js_str!("first-value").into()
/// ];
/// let vec_one: Vec<JsValue> = 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.
Expand Down Expand Up @@ -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(())
/// # }
Expand Down Expand Up @@ -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(())
/// # }
/// ```
Expand Down
66 changes: 21 additions & 45 deletions core/engine/src/object/builtins/jspromise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,14 @@ use boa_gc::{Finalize, Gc, GcRefCell, Trace};
/// # fn main() -> Result<(), Box<dyn Error>> {
/// 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,
Expand All @@ -57,19 +51,16 @@ 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()),
/// ),
/// None,
/// 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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -592,21 +574,15 @@ impl JsPromise {
/// # fn main() -> Result<(), Box<dyn Error>> {
/// 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,
Expand Down
3 changes: 1 addition & 2 deletions core/engine/src/object/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<CustomStruct>().unwrap().counter, 5);
/// ```
Expand Down
9 changes: 6 additions & 3 deletions core/engine/src/value/conversions/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> = Convert::try_from_js(&JsValue::Integer(0), &mut context).unwrap();
/// let Convert(conv5): Convert<bool> = Convert::try_from_js(&JsValue::Integer(5), &mut context).unwrap();
/// let Convert(conv_nan): Convert<bool> = Convert::try_from_js(&JsValue::Rational(f64::NAN), &mut context).unwrap();
/// let Convert(conv0): Convert<bool> =
/// Convert::try_from_js(&JsValue::Integer(0), &mut context).unwrap();
/// let Convert(conv5): Convert<bool> =
/// Convert::try_from_js(&JsValue::Integer(5), &mut context).unwrap();
/// let Convert(conv_nan): Convert<bool> =
/// Convert::try_from_js(&JsValue::Rational(f64::NAN), &mut context).unwrap();
///
/// assert_eq!(conv0, false);
/// assert_eq!(conv5, true);
Expand Down
Loading

0 comments on commit 6a6fa6a

Please sign in to comment.