-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, we simply had an exception enum ("TypeError" only). This is incorrect, as all sorts of values can be thrown.
- Loading branch information
1 parent
76b41b7
commit a707d84
Showing
4 changed files
with
27 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
use crate::Value; | ||
|
||
/// <https://262.ecma-international.org/14.0/#sec-completion-record-specification-type> | ||
pub type ThrowCompletionOr<T> = Result<T, Exception>; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub enum Exception { | ||
TypeError, | ||
#[derive(Clone, Debug)] | ||
pub struct Exception { | ||
value: Value, | ||
} | ||
|
||
impl Exception { | ||
#[must_use] | ||
pub const fn new(value: Value) -> Self { | ||
Self { value } | ||
} | ||
|
||
#[must_use] | ||
pub fn type_error() -> Self { | ||
// FIXME: This should be a "typeerror" object, but we don't | ||
// really support objects yet | ||
Self { | ||
value: "TypeError".to_string().into(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters