Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature throw Error object #1465

Merged
merged 2 commits into from
Aug 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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