Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unassigned var is undefined #125

Merged
merged 3 commits into from
Oct 3, 2019
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
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;