Skip to content

Commit

Permalink
unassigned var is undefined (#125)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
pop authored and jasonwilliams committed Oct 3, 2019
1 parent 1c3fea4 commit d798566
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
.idea/
*.iml

# Vim
.*.swp
.*.swo

# Build
target
dist
**/*.rs.bk
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 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 31 additions & 2 deletions src/lib/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 changes: 4 additions & 0 deletions tests/js/test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
///
// Use this file to test your changes to boa.
///

let a = Boolean(0);
typeof a;

0 comments on commit d798566

Please sign in to comment.