Skip to main content

boa/builtins/infinity/
mod.rs

1//! This module implements the global `Infinity` property.
2//!
3//! The global property `Infinity` is a numeric value representing infinity.
4//!
5//! More information:
6//!  - [MDN documentation][mdn]
7//!  - [ECMAScript reference][spec]
8//!
9//! [spec]: https://tc39.es/ecma262/#sec-value-properties-of-the-global-object-infinity
10//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity
11
12#[cfg(test)]
13mod tests;
14
15use crate::{builtins::BuiltIn, property::Attribute, BoaProfiler, Context, JsValue};
16
17/// JavaScript global `Infinity` property.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
19pub(crate) struct Infinity;
20
21impl BuiltIn for Infinity {
22    const NAME: &'static str = "Infinity";
23
24    fn attribute() -> Attribute {
25        Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT
26    }
27
28    fn init(_: &mut Context) -> (&'static str, JsValue, Attribute) {
29        let _timer = BoaProfiler::global().start_event(Self::NAME, "init");
30
31        (Self::NAME, f64::INFINITY.into(), Self::attribute())
32    }
33}