Struct boa_engine::error::JsNativeError
source · pub struct JsNativeError {
pub kind: JsNativeErrorKind,
/* private fields */
}
Expand description
Native representation of an ideal Error
object from Javascript.
This representation is more space efficient than its JsObject
equivalent,
since it doesn’t need to create a whole new JsObject
to be instantiated.
Prefer using this over JsError
when you don’t need to throw
plain JsValue
s as errors, or when you need to inspect the error type
of a JsError
.
§Examples
let native_error = JsNativeError::uri().with_message("cannot decode uri");
match native_error.kind {
JsNativeErrorKind::Uri => { /* handle URI error*/ }
_ => unreachable!(),
}
assert_eq!(native_error.message(), "cannot decode uri");
Fields§
§kind: JsNativeErrorKind
The kind of native error (e.g. TypeError
, SyntaxError
, etc.)
Implementations§
source§impl JsNativeError
impl JsNativeError
sourcepub fn aggregate(errors: Vec<JsError>) -> Self
pub fn aggregate(errors: Vec<JsError>) -> Self
Creates a new JsNativeError
of kind AggregateError
from a list of JsError
s, with
empty message
and undefined cause
.
§Examples
let inner_errors = vec![
JsNativeError::typ().into(),
JsNativeError::syntax().into()
];
let error = JsNativeError::aggregate(inner_errors);
assert!(matches!(
error.kind,
JsNativeErrorKind::Aggregate(ref errors) if errors.len() == 2
));
sourcepub const fn is_aggregate(&self) -> bool
pub const fn is_aggregate(&self) -> bool
Check if it’s a JsNativeErrorKind::Aggregate
.
sourcepub fn error() -> Self
pub fn error() -> Self
Creates a new JsNativeError
of kind Error
, with empty message
and undefined cause
.
§Examples
let error = JsNativeError::error();
assert!(matches!(error.kind, JsNativeErrorKind::Error));
sourcepub const fn is_error(&self) -> bool
pub const fn is_error(&self) -> bool
Check if it’s a JsNativeErrorKind::Error
.
sourcepub fn eval() -> Self
pub fn eval() -> Self
Creates a new JsNativeError
of kind EvalError
, with empty message
and undefined cause
.
§Examples
let error = JsNativeError::eval();
assert!(matches!(error.kind, JsNativeErrorKind::Eval));
sourcepub const fn is_eval(&self) -> bool
pub const fn is_eval(&self) -> bool
Check if it’s a JsNativeErrorKind::Eval
.
sourcepub fn range() -> Self
pub fn range() -> Self
Creates a new JsNativeError
of kind RangeError
, with empty message
and undefined cause
.
§Examples
let error = JsNativeError::range();
assert!(matches!(error.kind, JsNativeErrorKind::Range));
sourcepub const fn is_range(&self) -> bool
pub const fn is_range(&self) -> bool
Check if it’s a JsNativeErrorKind::Range
.
sourcepub fn reference() -> Self
pub fn reference() -> Self
Creates a new JsNativeError
of kind ReferenceError
, with empty message
and undefined cause
.
§Examples
let error = JsNativeError::reference();
assert!(matches!(error.kind, JsNativeErrorKind::Reference));
sourcepub const fn is_reference(&self) -> bool
pub const fn is_reference(&self) -> bool
Check if it’s a JsNativeErrorKind::Reference
.
sourcepub fn syntax() -> Self
pub fn syntax() -> Self
Creates a new JsNativeError
of kind SyntaxError
, with empty message
and undefined cause
.
§Examples
let error = JsNativeError::syntax();
assert!(matches!(error.kind, JsNativeErrorKind::Syntax));
sourcepub const fn is_syntax(&self) -> bool
pub const fn is_syntax(&self) -> bool
Check if it’s a JsNativeErrorKind::Syntax
.
sourcepub fn typ() -> Self
pub fn typ() -> Self
Creates a new JsNativeError
of kind TypeError
, with empty message
and undefined cause
.
§Examples
let error = JsNativeError::typ();
assert!(matches!(error.kind, JsNativeErrorKind::Type));
sourcepub const fn is_type(&self) -> bool
pub const fn is_type(&self) -> bool
Check if it’s a JsNativeErrorKind::Type
.
sourcepub fn uri() -> Self
pub fn uri() -> Self
Creates a new JsNativeError
of kind UriError
, with empty message
and undefined cause
.
§Examples
let error = JsNativeError::uri();
assert!(matches!(error.kind, JsNativeErrorKind::Uri));
sourcepub const fn is_uri(&self) -> bool
pub const fn is_uri(&self) -> bool
Check if it’s a JsNativeErrorKind::Uri
.
sourcepub fn runtime_limit() -> Self
pub fn runtime_limit() -> Self
Creates a new JsNativeError
that indicates that the context exceeded the runtime limits.
sourcepub const fn is_runtime_limit(&self) -> bool
pub const fn is_runtime_limit(&self) -> bool
Check if it’s a JsNativeErrorKind::RuntimeLimit
.
sourcepub fn with_message<S>(self, message: S) -> Self
pub fn with_message<S>(self, message: S) -> Self
Sets the message of this error.
§Examples
let error = JsNativeError::range().with_message("number too large");
assert_eq!(error.message(), "number too large");
sourcepub fn with_cause<V>(self, cause: V) -> Self
pub fn with_cause<V>(self, cause: V) -> Self
Sets the cause of this error.
§Examples
let cause = JsNativeError::syntax();
let error = JsNativeError::error().with_cause(cause);
assert!(error.cause().unwrap().as_native().is_some());
sourcepub const fn message(&self) -> &str
pub const fn message(&self) -> &str
Gets the message
of this error.
This is equivalent to the NativeError.prototype.message
property.
§Examples
let error = JsNativeError::range().with_message("number too large");
assert_eq!(error.message(), "number too large");
sourcepub fn cause(&self) -> Option<&JsError>
pub fn cause(&self) -> Option<&JsError>
Gets the cause
of this error.
This is equivalent to the NativeError.prototype.cause
property.
§Examples
let cause = JsNativeError::syntax();
let error = JsNativeError::error().with_cause(cause);
assert!(error.cause().unwrap().as_native().is_some());
sourcepub fn to_opaque(&self, context: &mut Context) -> JsObject
pub fn to_opaque(&self, context: &mut Context) -> JsObject
Converts this native error to its opaque representation as a JsObject
.
§Examples
let context = &mut Context::default();
let error = JsNativeError::error().with_message("error!");
let error_obj = error.to_opaque(context);
assert!(error_obj.is::<ErrorObject>());
assert_eq!(
error_obj.get(js_string!("message"), context).unwrap(),
js_string!("error!").into()
)
§Panics
If converting a JsNativeErrorKind::RuntimeLimit
to an opaque object.
Trait Implementations§
source§impl Clone for JsNativeError
impl Clone for JsNativeError
source§fn clone(&self) -> JsNativeError
fn clone(&self) -> JsNativeError
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for JsNativeError
impl Debug for JsNativeError
source§impl Display for JsNativeError
impl Display for JsNativeError
source§impl Error for JsNativeError
impl Error for JsNativeError
source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
source§impl From<Error> for JsNativeError
impl From<Error> for JsNativeError
source§impl From<JsNativeError> for JsError
impl From<JsNativeError> for JsError
source§fn from(error: JsNativeError) -> Self
fn from(error: JsNativeError) -> Self
source§impl PartialEq for JsNativeError
impl PartialEq for JsNativeError
source§fn eq(&self, other: &JsNativeError) -> bool
fn eq(&self, other: &JsNativeError) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Trace for JsNativeError
impl Trace for JsNativeError
source§unsafe fn trace_non_roots(&self)
unsafe fn trace_non_roots(&self)
source§fn run_finalizer(&self)
fn run_finalizer(&self)
Finalize::finalize
on this object and all
contained subobjects.impl Eq for JsNativeError
impl StructuralPartialEq for JsNativeError
Auto Trait Implementations§
impl !RefUnwindSafe for JsNativeError
impl !Send for JsNativeError
impl !Sync for JsNativeError
impl Unpin for JsNativeError
impl !UnwindSafe for JsNativeError
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.