Skip to content

Commit

Permalink
Merge 7a78396 into 62ad20c
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored Aug 12, 2021
2 parents 62ad20c + 7a78396 commit 75bde16
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions boa/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,30 @@ impl Context {
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.
#[inline]
pub fn construct_range_error<M>(&mut self, message: M) -> JsValue
Expand Down

0 comments on commit 75bde16

Please sign in to comment.