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

[Merged by Bors] - refactor: fix construct_error functions #1703

Closed
wants to merge 1 commit into from
Closed
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
104 changes: 61 additions & 43 deletions boa/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ use crate::{
realm::Realm,
syntax::{
ast::{
node::{
statement_list::RcStatementList, Call, FormalParameter, Identifier, New,
StatementList,
},
Const, Node,
node::{statement_list::RcStatementList, FormalParameter, StatementList},
Node,
},
Parser,
},
Expand Down Expand Up @@ -548,12 +545,11 @@ impl Context {
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)
crate::builtins::error::Error::constructor(
&self.standard_objects().error_object().constructor().into(),
&[message.into().into()],
self,
)
.expect("Into<String> used as message")
}

Expand All @@ -572,12 +568,15 @@ impl Context {
where
M: Into<Box<str>>,
{
// Runs a `new RangeError(message)`.
New::from(Call::new(
Identifier::from("RangeError"),
vec![Const::from(message.into()).into()],
))
.run(self)
crate::builtins::error::RangeError::constructor(
&self
.standard_objects()
.range_error_object()
.constructor()
.into(),
&[message.into().into()],
self,
)
.expect("Into<String> used as message")
}

Expand All @@ -596,12 +595,15 @@ impl Context {
where
M: Into<Box<str>>,
{
// Runs a `new TypeError(message)`.
New::from(Call::new(
Identifier::from("TypeError"),
vec![Const::from(message.into()).into()],
))
.run(self)
crate::builtins::error::TypeError::constructor(
&self
.standard_objects()
.type_error_object()
.constructor()
.into(),
&[message.into().into()],
self,
)
.expect("Into<String> used as message")
}

Expand All @@ -620,11 +622,15 @@ impl Context {
where
M: Into<Box<str>>,
{
New::from(Call::new(
Identifier::from("ReferenceError"),
vec![Const::from(message.into()).into()],
))
.run(self)
crate::builtins::error::ReferenceError::constructor(
&self
.standard_objects()
.reference_error_object()
.constructor()
.into(),
&[message.into().into()],
self,
)
.expect("Into<String> used as message")
}

Expand All @@ -643,11 +649,15 @@ impl Context {
where
M: Into<Box<str>>,
{
New::from(Call::new(
Identifier::from("SyntaxError"),
vec![Const::from(message.into()).into()],
))
.run(self)
crate::builtins::error::SyntaxError::constructor(
&self
.standard_objects()
.syntax_error_object()
.constructor()
.into(),
&[message.into().into()],
self,
)
.expect("Into<String> used as message")
}

Expand All @@ -665,11 +675,15 @@ impl Context {
where
M: Into<Box<str>>,
{
New::from(Call::new(
Identifier::from("EvalError"),
vec![Const::from(message.into()).into()],
))
.run(self)
crate::builtins::error::EvalError::constructor(
&self
.standard_objects()
.eval_error_object()
.constructor()
.into(),
&[message.into().into()],
self,
)
.expect("Into<String> used as message")
}

Expand All @@ -678,11 +692,15 @@ impl Context {
where
M: Into<Box<str>>,
{
New::from(Call::new(
Identifier::from("URIError"),
vec![Const::from(message.into()).into()],
))
.run(self)
crate::builtins::error::UriError::constructor(
&self
.standard_objects()
.uri_error_object()
.constructor()
.into(),
&[message.into().into()],
self,
)
.expect("Into<String> used as message")
}

Expand Down