Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Dec 3, 2023
1 parent 6ce28dc commit a56cecf
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 59 deletions.
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/error/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
};
use boa_profiler::Profiler;

use super::{Error, ErrorKind};
use super::{Error, ErrorObject};

#[derive(Debug, Clone, Copy)]
pub(crate) struct AggregateError;
Expand Down Expand Up @@ -85,7 +85,7 @@ impl BuiltInConstructor for AggregateError {
let o = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
prototype,
ErrorKind::Aggregate,
ErrorObject::Aggregate,
);

// 3. If message is not undefined, then
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/error/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
};
use boa_profiler::Profiler;

use super::{Error, ErrorKind};
use super::{Error, ErrorObject};

/// JavaScript `EvalError` implementation.
#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -84,7 +84,7 @@ impl BuiltInConstructor for EvalError {
let o = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
prototype,
ErrorKind::Eval,
ErrorObject::Eval,
);

// 3. If message is not undefined, then
Expand Down
7 changes: 4 additions & 3 deletions boa_engine/src/builtins/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) use self::uri::UriError;

use super::{BuiltInBuilder, BuiltInConstructor, IntrinsicObject};

/// The kind of a `NativeError` object, per the [ECMAScript spec][spec].
/// A `NativeError` object, per the [ECMAScript spec][spec].
///
/// This is used internally to convert between [`JsObject`] and
/// [`JsNativeError`] correctly, but it can also be used to manually create `Error`
Expand All @@ -59,7 +59,8 @@ use super::{BuiltInBuilder, BuiltInConstructor, IntrinsicObject};
/// [spec]: https://tc39.es/ecma262/#sec-error-objects
#[derive(Debug, Copy, Clone, Eq, PartialEq, Trace, Finalize, JsData)]
#[boa_gc(empty_trace)]
pub enum ErrorKind {
#[non_exhaustive]
pub enum ErrorObject {
/// The `AggregateError` object type.
///
/// More information:
Expand Down Expand Up @@ -180,7 +181,7 @@ impl BuiltInConstructor for Error {
let o = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
prototype,
ErrorKind::Error,
ErrorObject::Error,
);

// 3. If message is not undefined, then
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/error/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
};
use boa_profiler::Profiler;

use super::{Error, ErrorKind};
use super::{Error, ErrorObject};

/// JavaScript `RangeError` implementation.
#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -82,7 +82,7 @@ impl BuiltInConstructor for RangeError {
let o = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
prototype,
ErrorKind::Range,
ErrorObject::Range,
);

// 3. If message is not undefined, then
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/error/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
};
use boa_profiler::Profiler;

use super::{Error, ErrorKind};
use super::{Error, ErrorObject};

#[derive(Debug, Clone, Copy)]
pub(crate) struct ReferenceError;
Expand Down Expand Up @@ -84,7 +84,7 @@ impl BuiltInConstructor for ReferenceError {
let o = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
prototype,
ErrorKind::Reference,
ErrorObject::Reference,
);

// 3. If message is not undefined, then
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/error/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
};
use boa_profiler::Profiler;

use super::{Error, ErrorKind};
use super::{Error, ErrorObject};

/// JavaScript `SyntaxError` implementation.
#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -87,7 +87,7 @@ impl BuiltInConstructor for SyntaxError {
let o = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
prototype,
ErrorKind::Syntax,
ErrorObject::Syntax,
);

// 3. If message is not undefined, then
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/error/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
};
use boa_profiler::Profiler;

use super::{Error, ErrorKind};
use super::{Error, ErrorObject};

/// JavaScript `TypeError` implementation.
#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -90,7 +90,7 @@ impl BuiltInConstructor for TypeError {
let o = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
prototype,
ErrorKind::Type,
ErrorObject::Type,
);

// 3. If message is not undefined, then
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/error/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
};
use boa_profiler::Profiler;

use super::{Error, ErrorKind};
use super::{Error, ErrorObject};

/// JavaScript `URIError` implementation.
#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -83,7 +83,7 @@ impl BuiltInConstructor for UriError {
let o = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
prototype,
ErrorKind::Uri,
ErrorObject::Uri,
);

// 3. If message is not undefined, then
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use std::ops::Deref;

use super::{
error::ErrorKind, Array, BuiltInBuilder, BuiltInConstructor, Date, IntrinsicObject, RegExp,
error::ErrorObject, Array, BuiltInBuilder, BuiltInConstructor, Date, IntrinsicObject, RegExp,
};
use crate::{
builtins::{map, BuiltInObject},
Expand Down Expand Up @@ -845,7 +845,7 @@ impl OrdinaryObject {
} else if o.is_callable() {
// 7. Else if O has a [[Call]] internal method, let builtinTag be "Function".
utf16!("Function")
} else if o.is::<ErrorKind>() {
} else if o.is::<ErrorObject>() {
// 8. Else if O has an [[ErrorData]] internal slot, let builtinTag be "Error".
utf16!("Error")
} else if o.is::<bool>() {
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
//! # class::{Class, ClassBuilder},
//! # Context, JsResult, JsValue,
//! # JsArgs, Source, JsObject, js_string,
//! # JsNativeError,
//! # JsNativeError, JsData,
//! # };
//! # use boa_gc::{Finalize, Trace};
//! #
//! // Can also be a struct containing `Trace` types.
//! #[derive(Debug, Trace, Finalize)]
//! #[derive(Debug, Trace, Finalize, JsData)]
//! enum Animal {
//! Cat,
//! Dog,
Expand Down
64 changes: 34 additions & 30 deletions boa_engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{error, fmt};

use crate::{
builtins::{error::ErrorKind, Array},
builtins::{error::ErrorObject, Array},
js_string,
object::JsObject,
property::PropertyDescriptor,
Expand Down Expand Up @@ -182,12 +182,13 @@ impl JsError {
///
/// ```rust
/// # 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_val = error.to_opaque(context);
///
/// assert!(error_val.as_object().unwrap().borrow().is_error());
/// assert!(error_val.as_object().unwrap().is::<ErrorObject>());
/// ```
pub fn to_opaque(&self, context: &mut Context) -> JsValue {
match &self.inner {
Expand Down Expand Up @@ -242,7 +243,7 @@ impl JsError {
.as_object()
.ok_or_else(|| TryNativeError::NotAnErrorObject(val.clone()))?;
let error = *obj
.downcast_ref::<ErrorKind>()
.downcast_ref::<ErrorObject>()
.ok_or_else(|| TryNativeError::NotAnErrorObject(val.clone()))?;

let try_get_property = |key: JsString, name, context: &mut Context| {
Expand Down Expand Up @@ -275,14 +276,14 @@ impl JsError {
let cause = try_get_property(js_string!("cause"), "cause", context)?;

let kind = match error {
ErrorKind::Error => JsNativeErrorKind::Error,
ErrorKind::Eval => JsNativeErrorKind::Eval,
ErrorKind::Type => JsNativeErrorKind::Type,
ErrorKind::Range => JsNativeErrorKind::Range,
ErrorKind::Reference => JsNativeErrorKind::Reference,
ErrorKind::Syntax => JsNativeErrorKind::Syntax,
ErrorKind::Uri => JsNativeErrorKind::Uri,
ErrorKind::Aggregate => {
ErrorObject::Error => JsNativeErrorKind::Error,
ErrorObject::Eval => JsNativeErrorKind::Eval,
ErrorObject::Type => JsNativeErrorKind::Type,
ErrorObject::Range => JsNativeErrorKind::Range,
ErrorObject::Reference => JsNativeErrorKind::Reference,
ErrorObject::Syntax => JsNativeErrorKind::Syntax,
ErrorObject::Uri => JsNativeErrorKind::Uri,
ErrorObject::Aggregate => {
let errors = obj.get(utf16!("errors"), context).map_err(|e| {
TryNativeError::InaccessibleProperty {
property: "errors",
Expand Down Expand Up @@ -892,12 +893,13 @@ impl JsNativeError {
///
/// ```rust
/// # use boa_engine::{Context, JsError, JsNativeError, js_string};
/// # use boa_engine::builtins::error::ErrorObject;
/// let context = &mut Context::default();
///
/// let error = JsNativeError::error().with_message("error!");
/// let error_obj = error.to_opaque(context);
///
/// assert!(error_obj.borrow().is_error());
/// assert!(error_obj.is::<ErrorObject>());
/// assert_eq!(
/// error_obj.get(js_string!("message"), context).unwrap(),
/// js_string!("error!").into()
Expand All @@ -922,20 +924,22 @@ impl JsNativeError {
let (prototype, tag) = match kind {
JsNativeErrorKind::Aggregate(_) => (
constructors.aggregate_error().prototype(),
ErrorKind::Aggregate,
ErrorObject::Aggregate,
),
JsNativeErrorKind::Error => (constructors.error().prototype(), ErrorKind::Error),
JsNativeErrorKind::Eval => (constructors.eval_error().prototype(), ErrorKind::Eval),
JsNativeErrorKind::Range => (constructors.range_error().prototype(), ErrorKind::Range),
JsNativeErrorKind::Error => (constructors.error().prototype(), ErrorObject::Error),
JsNativeErrorKind::Eval => (constructors.eval_error().prototype(), ErrorObject::Eval),
JsNativeErrorKind::Range => {
(constructors.range_error().prototype(), ErrorObject::Range)
}
JsNativeErrorKind::Reference => (
constructors.reference_error().prototype(),
ErrorKind::Reference,
ErrorObject::Reference,
),
JsNativeErrorKind::Syntax => {
(constructors.syntax_error().prototype(), ErrorKind::Syntax)
(constructors.syntax_error().prototype(), ErrorObject::Syntax)
}
JsNativeErrorKind::Type => (constructors.type_error().prototype(), ErrorKind::Type),
JsNativeErrorKind::Uri => (constructors.uri_error().prototype(), ErrorKind::Uri),
JsNativeErrorKind::Type => (constructors.type_error().prototype(), ErrorObject::Type),
JsNativeErrorKind::Uri => (constructors.uri_error().prototype(), ErrorObject::Uri),
#[cfg(feature = "fuzz")]
JsNativeErrorKind::NoInstructionsRemain => {
unreachable!(
Expand Down Expand Up @@ -1140,18 +1144,18 @@ impl JsNativeErrorKind {
}
}

impl PartialEq<ErrorKind> for JsNativeErrorKind {
fn eq(&self, other: &ErrorKind) -> bool {
impl PartialEq<ErrorObject> for JsNativeErrorKind {
fn eq(&self, other: &ErrorObject) -> bool {
matches!(
(self, other),
(Self::Aggregate(_), ErrorKind::Aggregate)
| (Self::Error, ErrorKind::Error)
| (Self::Eval, ErrorKind::Eval)
| (Self::Range, ErrorKind::Range)
| (Self::Reference, ErrorKind::Reference)
| (Self::Syntax, ErrorKind::Syntax)
| (Self::Type, ErrorKind::Type)
| (Self::Uri, ErrorKind::Uri)
(Self::Aggregate(_), ErrorObject::Aggregate)
| (Self::Error, ErrorObject::Error)
| (Self::Eval, ErrorObject::Eval)
| (Self::Range, ErrorObject::Range)
| (Self::Reference, ErrorObject::Reference)
| (Self::Syntax, ErrorObject::Syntax)
| (Self::Type, ErrorObject::Type)
| (Self::Uri, ErrorObject::Uri)
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/object/builtins/jsmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl JsMap {
/// // `some_object` can be any JavaScript `Map` object.
/// let some_object = JsObject::from_proto_and_data(
/// context.intrinsics().constructors().map().prototype(),
/// ObjectData::map(OrderedMap::new()),
/// OrderedMap::<JsValue>::new(),
/// );
///
/// // Create `JsMap` object with incoming object.
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/object/jsobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ impl JsObject {
/// Creates a new object with the provided prototype and object data.
///
/// This is equivalent to calling the specification's abstract operation [`OrdinaryObjectCreate`],
/// with the difference that the `additionalInternalSlotsList` parameter is automatically set by
/// the [`ObjectData`] provided.
/// with the difference that the `additionalInternalSlotsList` parameter is determined by
/// the provided `data`.
///
/// [`OrdinaryObjectCreate`]: https://tc39.es/ecma262/#sec-ordinaryobjectcreate
pub fn from_proto_and_data<O: Into<Option<Self>>, T: NativeObject>(
Expand Down Expand Up @@ -151,8 +151,8 @@ impl JsObject {
/// Creates a new object with the provided prototype and object data.
///
/// This is equivalent to calling the specification's abstract operation [`OrdinaryObjectCreate`],
/// with the difference that the `additionalInternalSlotsList` parameter is automatically set by
/// the [`ObjectData`] provided.
/// with the difference that the `additionalInternalSlotsList` parameter is determined by
/// the provided `data`.
///
/// [`OrdinaryObjectCreate`]: https://tc39.es/ecma262/#sec-ordinaryobjectcreate
pub(crate) fn from_proto_and_data_with_shared_shape<O: Into<Option<Self>>, T: NativeObject>(
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/value/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::Cow;

use crate::{
builtins::{
error::ErrorKind, map::ordered_map::OrderedMap, promise::PromiseState,
error::ErrorObject, map::ordered_map::OrderedMap, promise::PromiseState,
set::ordered_set::OrderedSet, Array, Promise,
},
property::PropertyDescriptor,
Expand Down Expand Up @@ -193,7 +193,7 @@ pub(crate) fn log_string_from(x: &JsValue, print_internals: bool, print_children
} else {
format!("Set({size})")
}
} else if v_bor.is::<ErrorKind>() {
} else if v_bor.is::<ErrorObject>() {
drop(v_bor);
let name: Cow<'static, str> = v
.get_property(&utf16!("name").into())
Expand Down
2 changes: 1 addition & 1 deletion boa_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub(crate) mod test {
},
AssertNativeError {
source: Cow<'static, str>,
kind: builtins::error::ErrorKind,
kind: builtins::error::ErrorObject,
message: &'static str,
},
AssertContext {
Expand Down

0 comments on commit a56cecf

Please sign in to comment.