boa/builtins/nan/
mod.rs

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