Skip to content

Commit

Permalink
Format code snippets in docs (#3317)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 authored Sep 27, 2023
1 parent a23335b commit ae41479
Show file tree
Hide file tree
Showing 25 changed files with 162 additions and 87 deletions.
1 change: 0 additions & 1 deletion boa_ast/src/statement/switch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Switch node.
//!
use crate::{
expression::Expression,
statement::Statement,
Expand Down
1 change: 0 additions & 1 deletion boa_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! A ECMAScript REPL implementation based on boa_engine.
//!
#![doc = include_str!("../ABOUT.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/boa-dev/boa/main/assets/logo.svg",
Expand Down
13 changes: 8 additions & 5 deletions boa_engine/src/context/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ use super::intrinsics::Intrinsics;
/// ```
/// use boa_engine::{
/// context::{Context, ContextBuilder, HostHooks},
/// JsNativeError,
/// JsResult,
/// realm::Realm,
/// Source
/// JsNativeError, JsResult, Source,
/// };
///
/// struct Hooks;
Expand All @@ -36,13 +34,18 @@ use super::intrinsics::Intrinsics;
/// _realm: Realm,
/// context: &mut Context<'_>,
/// ) -> JsResult<()> {
/// Err(JsNativeError::typ().with_message("eval calls not available").into())
/// Err(JsNativeError::typ()
/// .with_message("eval calls not available")
/// .into())
/// }
/// }
/// let hooks: &dyn HostHooks = &Hooks; // Can have additional state.
/// 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(), "TypeError: eval calls not available");
/// assert_eq!(
/// result.unwrap_err().to_string(),
/// "TypeError: eval calls not available"
/// );
/// ```
///
/// [`Host Hooks`]: https://tc39.es/ecma262/#sec-host-hooks-summary
Expand Down
3 changes: 1 addition & 2 deletions boa_engine/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ use crate::vm::RuntimeLimits;
/// use boa_engine::{
/// object::ObjectInitializer,
/// property::{Attribute, PropertyDescriptor},
/// Context,
/// Source
/// Context, Source,
/// };
///
/// let script = r#"
Expand Down
6 changes: 4 additions & 2 deletions boa_engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ impl JsError {
/// ```rust
/// # use boa_engine::{Context, JsError, JsNativeError};
/// 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().borrow().is_error());
Expand Down Expand Up @@ -345,7 +346,8 @@ 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
5 changes: 4 additions & 1 deletion boa_engine/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ pub trait JobQueue {
/// can be done by passing a reference to it to the [`ContextBuilder`]:
///
/// ```
/// use boa_engine::{context::ContextBuilder, job::{JobQueue, IdleJobQueue}};
/// use boa_engine::{
/// context::ContextBuilder,
/// job::{IdleJobQueue, JobQueue},
/// };
///
/// let queue: &dyn JobQueue = &IdleJobQueue;
/// let context = ContextBuilder::new().job_queue(queue).build();
Expand Down
1 change: 0 additions & 1 deletion boa_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
//!
//! [ecma-402]: https://tc39.es/ecma402
//! [examples]: https://github.com/boa-dev/boa/tree/main/boa_examples
//!
#![doc = include_str!("../ABOUT.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/boa-dev/boa/main/assets/logo.svg",
Expand Down
10 changes: 8 additions & 2 deletions boa_engine/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,10 @@ impl Module {
/// # use boa_engine::module::{ModuleLoader, SimpleModuleLoader};
/// let loader = &SimpleModuleLoader::new(Path::new(".")).unwrap();
/// let dyn_loader: &dyn ModuleLoader = loader;
/// let mut context = &mut Context::builder().module_loader(dyn_loader).build().unwrap();
/// let mut context = &mut Context::builder()
/// .module_loader(dyn_loader)
/// .build()
/// .unwrap();
///
/// let source = Source::from_bytes("1 + 3");
///
Expand All @@ -640,7 +643,10 @@ impl Module {
///
/// context.run_jobs();
///
/// assert_eq!(promise.state().unwrap(), PromiseState::Fulfilled(JsValue::undefined()));
/// assert_eq!(
/// promise.state().unwrap(),
/// PromiseState::Fulfilled(JsValue::undefined())
/// );
/// ```
#[allow(dropping_copy_types)]
#[inline]
Expand Down
3 changes: 2 additions & 1 deletion boa_engine/src/object/builtins/jsdataview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ 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
17 changes: 10 additions & 7 deletions boa_engine/src/object/builtins/jsdate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ use crate::{
/// Create a `JsDate` object and set date to December 4 1995
///
/// ```
/// use boa_engine::{object::builtins::JsDate, Context, JsValue, JsResult};
/// use boa_engine::{object::builtins::JsDate, Context, JsResult, JsValue};
///
/// fn main() -> JsResult<()> {
/// // JS mutable Context
/// let context = &mut Context::default();
/// // JS mutable Context
/// let context = &mut Context::default();
///
/// let date = JsDate::new(context);
/// let date = JsDate::new(context);
///
/// date.set_full_year(&[1995.into(), 11.into(), 4.into()], context)?;
/// date.set_full_year(&[1995.into(), 11.into(), 4.into()], context)?;
///
/// assert_eq!(date.to_date_string(context)?, JsValue::from("Mon Dec 04 1995"));
/// assert_eq!(
/// date.to_date_string(context)?,
/// JsValue::from("Mon Dec 04 1995")
/// );
///
/// Ok(())
/// Ok(())
/// }
/// ```
#[derive(Debug, Clone, Trace, Finalize)]
Expand Down
Loading

0 comments on commit ae41479

Please sign in to comment.