mirror of https://github.com/boa-dev/boa.git
Anirudh Konduru
5 years ago
committed by
GitHub
3 changed files with 54 additions and 0 deletions
@ -0,0 +1,32 @@
|
||||
//! This module implements the global `Infinity` property.
|
||||
//!
|
||||
//! The global property `Infinity` is a numeric value representing infinity.
|
||||
//!
|
||||
//! 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 `Infinity` 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)) |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
use crate::exec; |
||||
|
||||
#[test] |
||||
fn infinity_exists_on_global_object_and_evaluates_to_infinity_value() { |
||||
let scenario = r#" |
||||
Infinity; |
||||
"#; |
||||
|
||||
assert_eq!(&exec(scenario), "Infinity"); |
||||
} |
||||
|
||||
#[test] |
||||
fn infinity_exists_and_equals_to_number_positive_infinity_value() { |
||||
let scenario = r#" |
||||
Number.POSITIVE_INFINITY === Infinity; |
||||
"#; |
||||
|
||||
assert_eq!(&exec(scenario), "true"); |
||||
} |
Loading…
Reference in new issue