diff --git a/.gitignore b/.gitignore index b7bb3b00d4d..6241b9fa41d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,10 @@ .idea/ *.iml +# Vim +.*.swp +.*.swo + # Build target dist @@ -9,4 +13,7 @@ dist node_modules .DS_Store yarn-error.log -.vscode/settings.json \ No newline at end of file +.vscode/settings.json + +# tests/js/test.js is used for testing changes locally +test/js/test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 7056115e1ec..a26f0a5996e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ Feature enhancements: - [FEATURE #119](https://github.com/jasonwilliams/boa/issues/119): Introduce realm struct to hold realm context and global object +Bug fixes: + +- [BUG #113](https://github.com/jasonwilliams/boa/issues/113): + Unassigned variables have default of undefined (@pop) + # 0.4.0 (2019-09-25) v0.4.0 brings quite a big release. The biggest feature to land is the support of regular expressions. diff --git a/src/lib/exec.rs b/src/lib/exec.rs index e391bd48972..ceb7d9e07e0 100644 --- a/src/lib/exec.rs +++ b/src/lib/exec.rs @@ -389,7 +389,7 @@ impl Executor for Interpreter { let (name, value) = var.clone(); let val = match value { Some(v) => self.run(&v)?, - None => Gc::new(ValueData::Null), + None => Gc::new(ValueData::Undefined), }; self.realm .environment @@ -403,7 +403,7 @@ impl Executor for Interpreter { let (name, value) = var.clone(); let val = match value { Some(v) => self.run(&v)?, - None => Gc::new(ValueData::Null), + None => Gc::new(ValueData::Undefined), }; self.realm .environment @@ -630,3 +630,32 @@ impl Interpreter { } } } + +#[cfg(test)] +mod tests { + use crate::exec; + + #[test] + fn empty_let_decl_undefined() { + let scenario = r#" + let a; + a == undefined; + "#; + + let pass = String::from("true"); + + assert_eq!(exec(scenario), pass); + } + + #[test] + fn empty_var_decl_undefined() { + let scenario = r#" + let b; + b == undefined; + "#; + + let pass = String::from("true"); + + assert_eq!(exec(scenario), pass); + } +} diff --git a/tests/js/test.js b/tests/js/test.js index c990b090bbf..ae107b0f1eb 100644 --- a/tests/js/test.js +++ b/tests/js/test.js @@ -1,2 +1,6 @@ +/// +// Use this file to test your changes to boa. +/// + let a = Boolean(0); typeof a;