Browse Source

[NaN] handle NaN token as identifier (#475)

pull/479/head
croraf 5 years ago committed by GitHub
parent
commit
5a45ab532e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      boa/src/builtins/array/tests.rs
  2. 2
      boa/src/builtins/mod.rs
  3. 11
      boa/src/builtins/nan/mod.rs
  4. 10
      boa/src/builtins/nan/tests.rs
  5. 1
      boa/src/syntax/lexer/mod.rs
  6. 13
      boa/src/syntax/lexer/tests.rs

11
boa/src/builtins/array/tests.rs

@ -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!(

2
boa/src/builtins/mod.rs

@ -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;
@ -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);

11
boa/src/builtins/nan/mod.rs

@ -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
boa/src/builtins/nan/tests.rs

@ -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
boa/src/syntax/lexer/mod.rs

@ -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)

13
boa/src/syntax/lexer/tests.rs

@ -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(

Loading…
Cancel
Save