Browse Source

unassigned var is undefined (#125)

* Unassigned variables are set to `undefined` not `null`

Fixes #113

* Rust tests for `var x` and `let x` default to undefined

* CHANGELOG for issue #113 fix + add tests/js/test.js to gitignore.
pull/133/head
Elijah Caine M. Voigt 5 years ago committed by Jason Williams
parent
commit
d798566377
  1. 9
      .gitignore
  2. 5
      CHANGELOG.md
  3. 33
      src/lib/exec.rs
  4. 4
      tests/js/test.js

9
.gitignore vendored

@ -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
.vscode/settings.json
# tests/js/test.js is used for testing changes locally
test/js/test.js

5
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.

33
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);
}
}

4
tests/js/test.js

@ -1,2 +1,6 @@
///
// Use this file to test your changes to boa.
///
let a = Boolean(0);
typeof a;

Loading…
Cancel
Save