forked from boa-dev/boa
-
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.
add Infinity gloabal property (boa-dev#480)
- Loading branch information
1 parent
df13272
commit 5c324a9
Showing
3 changed files
with
46 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//! This module implements the global `Infinity` property. | ||
//! | ||
//! The global `Infinity` is a property of the global object. In other words, | ||
//! it is a variable in global scope. | ||
//! | ||
//! More information: | ||
//! - [MDN documentation][mdn] | ||
//! - [ECMAScript reference][spec] | ||
//! | ||
//! [spec]: https://tc39.es/ecma262/#sec-value-properties-of-the-global-object-infinity | ||
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity | ||
#[cfg(test)] | ||
mod tests; | ||
|
||
use crate::{builtins::value::Value, BoaProfiler}; | ||
|
||
/// JavaScript global `Infinity` property. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub(crate) struct Infinity; | ||
|
||
impl Infinity { | ||
/// The binding name of the property. | ||
pub(crate) const NAME: &'static str = "Infinity"; | ||
|
||
/// Initialize the `NaN` property on the global object. | ||
#[inline] | ||
pub(crate) fn init(_: &Value) -> (&str, Value) { | ||
let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); | ||
|
||
(Self::NAME, Value::from(f64::INFINITY)) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use crate::exec; | ||
|
||
#[test] | ||
fn infinity_exists_on_global_object_and_evaluates_to_infinity_value() { | ||
let scenario = r#" | ||
Infinity; | ||
"#; | ||
|
||
assert_eq!(&exec(scenario), "Infinity"); | ||
} |
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