Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions boa/src/builtins/array/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,11 @@ fn fill() {
String::from("4,2,3")
);

// TODO: uncomment when NaN support is added
// forward(&mut engine, "a = [1, 2, 3];");
// assert_eq!(
// forward(&mut engine, "a.fill(4, NaN, NaN).join()"),
// String::from("1,2,3")
// );
forward(&mut engine, "a = [1, 2, 3];");
assert_eq!(
forward(&mut engine, "a.fill(4, NaN, NaN).join()"),
String::from("1,2,3")
);

forward(&mut engine, "a = [1, 2, 3];");
assert_eq!(
Expand Down
2 changes: 2 additions & 0 deletions boa/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod error;
pub mod function;
pub mod json;
pub mod math;
pub mod nan;
pub mod number;
pub mod object;
pub mod property;
Expand Down Expand Up @@ -36,6 +37,7 @@ pub fn init(global: &Value) {
Boolean::init(global);
json::init(global);
math::init(global);
nan::init(global);
Number::init(global);
object::init(global);
function::init(global);
Expand Down
11 changes: 11 additions & 0 deletions boa/src/builtins/nan/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[cfg(test)]
mod tests;

use crate::{builtins::value::Value, BoaProfiler};

/// Initialize the `NaN` property on the global object.
#[inline]
pub fn init(global: &Value) {
let _timer = BoaProfiler::global().start_event("NaN", "init");
global.set_field("NaN", Value::from(f64::NAN));
}
10 changes: 10 additions & 0 deletions boa/src/builtins/nan/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::exec;

#[test]
fn nan_exists_on_global_object_and_evaluates_to_nan_value() {
let scenario = r#"
NaN;
"#;

assert_eq!(&exec(scenario), "NaN");
}
1 change: 0 additions & 1 deletion boa/src/syntax/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ impl<'a> Lexer<'a> {
"true" => TokenKind::BooleanLiteral(true),
"false" => TokenKind::BooleanLiteral(false),
"null" => TokenKind::NullLiteral,
"NaN" => TokenKind::NumericLiteral(NumericLiteral::Rational(f64::NAN)),
slice => {
if let Ok(keyword) = FromStr::from_str(slice) {
TokenKind::Keyword(keyword)
Expand Down
13 changes: 0 additions & 13 deletions boa/src/syntax/lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,19 +387,6 @@ fn check_decrement_advances_lexer_2_places() {
);
}

#[test]
fn check_nan() {
let mut lexer = Lexer::new("let a = NaN;");
lexer.lex().expect("failed to lex");

match lexer.tokens[3].kind {
TokenKind::NumericLiteral(NumericLiteral::Rational(a)) => {
assert!(a.is_nan());
}
ref other => panic!("Incorrect token kind found for NaN: {}", other),
}
}

#[test]
fn numbers() {
let mut lexer = Lexer::new(
Expand Down