Browse Source

Feature throw `Error` object (#1465)

* feature `Context::throw_error`

* Fix doc
pull/1470/head
Halid Odat 3 years ago committed by GitHub
parent
commit
44202ce697
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      boa/src/context.rs

24
boa/src/context.rs

@ -358,6 +358,30 @@ impl Context {
self.realm.global_object.clone() self.realm.global_object.clone()
} }
/// Constructs a `Error` with the specified message.
#[inline]
pub fn construct_error<M>(&mut self, message: M) -> JsValue
where
M: Into<Box<str>>,
{
// Runs a `new Error(message)`.
New::from(Call::new(
Identifier::from("Error"),
vec![Const::from(message.into()).into()],
))
.run(self)
.expect("Into<String> used as message")
}
/// Throws a `Error` with the specified message.
#[inline]
pub fn throw_error<M>(&mut self, message: M) -> Result<JsValue>
where
M: Into<Box<str>>,
{
Err(self.construct_error(message))
}
/// Constructs a `RangeError` with the specified message. /// Constructs a `RangeError` with the specified message.
#[inline] #[inline]
pub fn construct_range_error<M>(&mut self, message: M) -> JsValue pub fn construct_range_error<M>(&mut self, message: M) -> JsValue

Loading…
Cancel
Save