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

Fix undefined constant expression evaluation #645

Merged
merged 3 commits into from
Aug 19, 2020
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
4 changes: 3 additions & 1 deletion boa/src/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ impl Executable for Node {
Node::Const(Const::Num(num)) => Ok(Value::rational(num)),
Node::Const(Const::Int(num)) => Ok(Value::integer(num)),
Node::Const(Const::BigInt(ref num)) => Ok(Value::from(num.clone())),
Node::Const(Const::Undefined) => Ok(Value::Undefined),
// we can't move String from Const into value, because const is a garbage collected value
// Which means Drop() get's called on Const, but str will be gone at that point.
// Do Const values need to be garbage collected? We no longer need them once we've generated Values
Expand Down Expand Up @@ -410,7 +411,8 @@ impl Executable for Node {
}
Node::Try(ref try_node) => try_node.run(interpreter),
Node::Break(ref break_node) => break_node.run(interpreter),
ref i => unimplemented!("{:?}", i),
Node::ConditionalOp(_) => unimplemented!("ConditionalOp"),
Node::Continue(_) => unimplemented!("Continue"),
}
}
}
16 changes: 15 additions & 1 deletion boa/src/exec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,9 @@ mod in_operator {
let bar_obj = bar_val.as_object().unwrap();
let foo_val = forward_val(&mut engine, "Foo").unwrap();
let foo_obj = foo_val.as_object().unwrap();
assert!(bar_obj.prototype().strict_equals(&foo_obj.get_field("prototype").unwrap()));
assert!(bar_obj
.prototype()
.strict_equals(&foo_obj.get_field("prototype").unwrap()));
}
}

Expand Down Expand Up @@ -1220,3 +1222,15 @@ fn test_result_of_empty_block() {
let scenario = "{}";
assert_eq!(&exec(scenario), "undefined");
}

#[test]
fn test_undefined_constant() {
let scenario = "undefined";
assert_eq!(&exec(scenario), "undefined");
}

#[test]
fn test_undefined_type() {
let scenario = "typeof undefined";
assert_eq!(&exec(scenario), "\"undefined\"");
}